diff --git a/markdown.php b/markdown.php index 7997542..c97da2f 100644 --- a/markdown.php +++ b/markdown.php @@ -44,8 +44,9 @@ class markdown $res = $this->paragraph ($mark); + $res = str_replace ("\n

", "", $res); $res = str_replace ("

", "", $res); - $res = str_replace ("

\n

", "", $res); + $res = str_replace ("

\n

\n", "", $res); return $res; } @@ -74,7 +75,7 @@ class markdown // CODE : `code` -> $search[] = "/\\n?\`((\\n|.)+)\`/Um"; - $replace[] = " \\1"; + $replace[] = "\\1"; // LINKS // [Google Site](http://google.fr/ "With help bubble") @@ -85,8 +86,10 @@ class markdown // Automatics links : // // - $search[] = "#<(https?://.+)>#"; $replace[] = "\\1"; - $search[] = "#<(.+@.+)>#"; $replace[] = "\\1"; + $search[] = "#<(https?://.+)>#"; + $replace[] = "\\1"; + $search[] = "#<(.+@.+)>#"; + $replace[] = "\\1"; // TODO : Links by reference : // Voici un petit texte écrit par [Michel Fortin][mf]. // [mf]: http://michelf.ca/ "Mon site web" @@ -95,22 +98,22 @@ class markdown // Titles ATX (Optionnal sharp at the end) // ###### Title6 $search[] = "/^###### (.+)( +#*)$/Um"; - $replace[] = "

\n
\\1
\n

"; + $replace[] = "

\\1

"; // ##### Title5 $search[] = "/^##### (.+)( +#*)$/Um"; - $replace[] = "

\n
\\1
\n

"; + $replace[] = "

\\1

"; // #### Title4 $search[] = "/^#### (.+)( +#*)$/Um"; - $replace[] = "

\n

\\1

\n

"; + $replace[] = "

\\1

"; // ### Title3 $search[] = "/^### (.+)( +#*)$/Um"; - $replace[] = "

\n

\\1

\n

"; + $replace[] = "

\\1

"; // ## Title2 $search[] = "/^## (.+)( +#*)$/Um"; - $replace[] = "

\n

\\1

\n

"; + $replace[] = "

\\1

"; // # Title1 $search[] = "/^# (.+)( +#*)$/Um"; - $replace[] = "

\n

\\1

\n

"; + $replace[] = "

\\1

"; // End of line with double space :
$search[] = "/( )$/Um"; $replace[] = "
"; @@ -119,8 +122,7 @@ class markdown // Cleanning the markdown text $mark = str_replace ("\t", " ", $mark); - $mark = trim ($mark); - if ($mark === "") + if (trim ($mark) === "") return ""; $spacer = " "; @@ -180,7 +182,7 @@ class markdown { $this->debugMKD ("Pending

  • : closing"); $this->debugMKD ("
  • "); - $res .= ""; + $res .= "\n"; array_pop ($htmlStack); } @@ -205,7 +207,7 @@ class markdown { $this->debugMKD ("DEB2 : Pending
  • : closing"); $this->debugMKD ("
  • "); - $res .= "\n"; + $res .= ""; array_pop ($htmlStack); } @@ -256,7 +258,7 @@ class markdown if ($type !== "") { $this->debugMKD (str_repeat (" ", end ($indentStack))."<$type>"); - $res .= "\n".str_repeat (" ", end ($indentStack))."<$type>"; + $res .= "".str_repeat (" ", end ($indentStack))."<$type>"; $htmlStack[] = $type; array_push ($indentStack, $indent); array_push ($typeStack, $type); @@ -313,7 +315,7 @@ class markdown } array_push ($indentStack, $indent); $this->debugMKD (str_repeat (" ", $indent)."<$typetmp>"); - $res .= "\n".str_repeat (" ", $indent)."<$typetmp>"; + $res .= "".str_repeat (" ", $indent)."<$typetmp>"; if ($type === "ol" || $type === "ul") { $this->debugMKD ("DEB2 : Adding li"); @@ -334,7 +336,7 @@ class markdown array_pop ($htmlStack); } - // If code, there is no emphasis, email, and other convertions + // If code, there is no emphasis, email, and other conversions if ($type !== "code") { $timetmp = microtime (TRUE); @@ -343,17 +345,21 @@ class markdown } $this->debugMKD ("$lineTxt"); - $res .= substr ($lineTxt, end ($indentStack))."\n"; + $res .= substr ($lineTxt, end ($indentStack)).""; + if ($type === "code") + $res .= "\n"; } $this->debugMKD ("DEB1 : End of loop"); $htmlStack = array_reverse ($htmlStack); - foreach ($htmlStack as $type) + foreach ($htmlStack as $i=>$type) { if ($type === "code") $res = substr ($res, 0, -1); $this->debugMKD ("FIN"); - $res .= "\n"; + $res .= ""; + if (($i+1) < count ($htmlStack) && $type !== "code") + $res .= "\n"; } $this->debugMKD ("TimeInit=".($timeInit*1000)."ms");