diff --git a/Parsedown.php b/Parsedown.php index 186896c..f6662d6 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -63,6 +63,15 @@ class Parsedown protected $breaksEnabled; + function setLiteralBreaks($literalBreaks) + { + $this->literalBreaks = $literalBreaks; + + return $this; + } + + protected $literalBreaks; + function setMarkupEscaped($markupEscaped) { $this->markupEscaped = $markupEscaped; @@ -167,7 +176,7 @@ class Parsedown foreach ($lines as $line) { - if (chop($line) === '') + if ( ! $this->literalBreaks and chop($line) === '') { if (isset($CurrentBlock)) { @@ -230,7 +239,15 @@ class Parsedown # ~ - $marker = $text[0]; + if (isset($text[0])) + { + $marker = $text[0]; + } + elseif ($this->literalBreaks) + { + $marker = '\n'; + $text = ' '; + } # ~ diff --git a/test/ParsedownTest.php b/test/ParsedownTest.php index bf40317..d92e4fc 100755 --- a/test/ParsedownTest.php +++ b/test/ParsedownTest.php @@ -52,6 +52,7 @@ class ParsedownTest extends TestCase $this->Parsedown->setSafeMode(substr($test, 0, 3) === 'xss'); $this->Parsedown->setStrictMode(substr($test, 0, 6) === 'strict'); + $this->Parsedown->setLiteralBreaks(substr($test, 0, 14) === 'literal_breaks'); $actualMarkup = $this->Parsedown->text($markdown); diff --git a/test/data/literal_breaks.html b/test/data/literal_breaks.html new file mode 100644 index 0000000..bf9e273 --- /dev/null +++ b/test/data/literal_breaks.html @@ -0,0 +1,6 @@ +

first line +
+
+
+
+sixth line

\ No newline at end of file diff --git a/test/data/literal_breaks.md b/test/data/literal_breaks.md new file mode 100644 index 0000000..2b95a92 --- /dev/null +++ b/test/data/literal_breaks.md @@ -0,0 +1,6 @@ +first line + + + + +sixth line \ No newline at end of file