diff --git a/Parsedown.php b/Parsedown.php index 1e2840d..520cb77 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -78,7 +78,7 @@ class Parsedown # ~ $text = preg_replace('/\n\s*\n/', "\n\n", $text); - $text = trim($text, "\n "); + $text = trim($text, "\n"); $lines = explode("\n", $text); @@ -210,10 +210,15 @@ class Parsedown goto paragraph; } - # Code + # Code Block if ($line[0] === ' ' and preg_match('/^[ ]{4}(.*)/', $line, $matches)) { + if (trim($line) === '') + { + continue; + } + if ($element['type'] === 'code') { if (isset($element['interrupted'])) @@ -279,6 +284,11 @@ class Parsedown $pure_line = $line[0] !== ' ' ? $line : ltrim($line); + if ($pure_line === '') + { + continue; + } + # Link Reference if ($pure_line[0] === '[' and preg_match('/^\[(.+?)\]:[ ]*([^ ]+)/', $pure_line, $matches)) diff --git a/tests/data/whitespace.html b/tests/data/whitespace.html new file mode 100644 index 0000000..bc5cd2a --- /dev/null +++ b/tests/data/whitespace.html @@ -0,0 +1 @@ +
This text starts with a line that consists of 4 spaces and it ends with one. This is a code block to make sure that leading spaces don't get trimmed.
\ No newline at end of file diff --git a/tests/data/whitespace.md b/tests/data/whitespace.md new file mode 100644 index 0000000..5f53a54 --- /dev/null +++ b/tests/data/whitespace.md @@ -0,0 +1,5 @@ + + + This text starts with a line that consists of 4 spaces and it ends with one. This is a code block to make sure that leading spaces don't get trimmed. + + \ No newline at end of file