diff --git a/Tests/markdownTest.php b/Tests/markdownTest.php index 259bff7..bb954d8 100644 --- a/Tests/markdownTest.php +++ b/Tests/markdownTest.php @@ -316,4 +316,11 @@ end")); $md = new markdown (); printf ($md->html ("line1\nline2\n")); } + + public function testCarriageReturn2 () + { + $this->expectOutputString("

line1
line2

"); + $md = new markdown (); + printf ($md->html ("line1 \nline2\n")); + } } diff --git a/markdown.php b/markdown.php index 3abb52d..4af06be 100644 --- a/markdown.php +++ b/markdown.php @@ -39,9 +39,11 @@ class markdown $search[] = "/^[*_-] ?[*_-] ?[*_-]$/Um"; $replace[] = "\n
\n"; + // End of line with continuous on second line, without double spaces : add + // space + $search[] = "/^(\w+)\\n(\w+)/m"; $replace[] = "\\1 \\2"; $mark = preg_replace ($search, $replace, $mark); - $res = $this->paragraph ($mark); $res = str_replace ("\n

", "", $res); @@ -60,6 +62,8 @@ class markdown // Initialization of convertions $search = array (); $replace = array (); + + // Titles short // == TITRE1 $search[] = "/^==+ (.+)( ==+)?$/Um"; @@ -120,9 +124,6 @@ class markdown // End of line with double space :
$search[] = "/( )$/Um"; $replace[] = "
"; - // End of line with continuous on second line : add blank - // $search[] = "/(.)\\n([A-Za-z0-9])/Um"; $replace[] = "\\1 \\2"; - // Cleanning the markdown text $mark = str_replace ("\t", " ", $mark); if (trim ($mark) === "") @@ -278,7 +279,7 @@ class markdown if ($type !== "") { $this->debugMKD (str_repeat (" ", end ($indentStack))."<$type>"); - $res .= "".str_repeat (" ", end ($indentStack))."<$type>"; + $res .= str_repeat (" ", end ($indentStack))."<$type>"; $htmlStack[] = $type; array_push ($indentStack, $indent); array_push ($typeStack, $type); @@ -340,7 +341,7 @@ class markdown } array_push ($indentStack, $indent); $this->debugMKD (str_repeat (" ", $indent)."<$typetmp>"); - $res .= "".str_repeat (" ", $indent)."<$typetmp>"; + $res .= str_repeat (" ", $indent)."<$typetmp>"; if ($type === "ol" || $type === "ul") { $this->debugMKD ("DEB2 : Adding li"); @@ -369,7 +370,7 @@ class markdown $timeregex += (microtime (TRUE) - $timetmp); } - $this->debugMKD ("$lineTxt"); + $this->debugMKD (substr ($lineTxt, end ($indentStack)).""); $res .= substr ($lineTxt, end ($indentStack)).""; if ($type === "code") $res .= "\n";