Markdown : Add space between the lines when a paragraph continues

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1795 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-09-03 13:34:28 +00:00
parent 54d2616b1c
commit 20d4c4ec57
2 changed files with 15 additions and 7 deletions

View File

@@ -316,4 +316,11 @@ end"));
$md = new markdown (); $md = new markdown ();
printf ($md->html ("line1\nline2\n")); printf ($md->html ("line1\nline2\n"));
} }
public function testCarriageReturn2 ()
{
$this->expectOutputString("<p>line1<br/>line2</p>");
$md = new markdown ();
printf ($md->html ("line1 \nline2\n"));
}
} }

View File

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