From 47d8a1382be420881c9f236519f1c8927fc9fda7 Mon Sep 17 00:00:00 2001 From: Emanuil Rusev Date: Thu, 26 Dec 2013 23:43:25 +0200 Subject: [PATCH] implement automatic line breaks as an option --- Parsedown.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 2466077..b5014b1 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -33,6 +33,19 @@ class Parsedown private static $instances = array(); + # + # Setters + # + + private $break_marker = " \n"; + + function set_breaks_enabled($breaks_enabled) + { + $this->break_marker = $breaks_enabled ? "\n" : " \n"; + + return $this; + } + # # Fields # @@ -658,7 +671,7 @@ class Parsedown '_' => '/^_(.*?)__(.+?)__(.*?)_/s', ); - private function parse_span_elements($text, $markers = array(" \n", '![', '&', '*', '<', '[', '_', '`', 'http', '~~')) + private function parse_span_elements($text, $markers = array('![', '&', '*', '<', '[', '_', '`', 'http', '~~')) { if (isset($text[2]) === false or $markers === array()) { @@ -717,14 +730,6 @@ class Parsedown switch ($closest_marker) { - case " \n": - - $markup .= '
'; - - $offset = 2; - - break; - case '![': case '[': @@ -979,6 +984,8 @@ class Parsedown $markers[$closest_marker_index] = $closest_marker; } + $markup = str_replace($this->break_marker, '
'."\n", $markup); + return $markup; } } \ No newline at end of file