diff --git a/markdown.php b/markdown.php
index 5402a14..6f50985 100644
--- a/markdown.php
+++ b/markdown.php
@@ -5,7 +5,7 @@
function debugMKD ($msg)
{
- //return;
+ return;
$trace = debug_backtrace();
$back = reset ($trace);
file_put_contents ("/tmp/debug", "[".$back["line"]."] $msg\n", FILE_APPEND);
@@ -23,6 +23,8 @@ class markdown
$search = array ();
$replace = array ();
+ $mark = htmlentities ($mark, ENT_QUOTES);
+
// SEPARATORS : *** --- ___ * * * - - - _ _ _
// Must be placed before EMPHASIS
$search[] = "/\\n^[*_-] ?[*_-] ?[*_-]$/Um";
@@ -38,7 +40,7 @@ class markdown
$search[] = "/\\n?\`((\\n|.)+)\`/Um";
$replace[] = " \\1";
- // LINKS
+ // LINKS
// [Google Site](http://google.fr/ "With help bubble")
$search[] = "(\[(.+)\]\((https?://.+) \"(.+)\"\))";
$replace[] = "\\1";
@@ -80,15 +82,17 @@ class markdown
$replace[] = "
"; // Titre2 // ------ - $search[] = "/\\n^(.+)\\n--+$\\n/Um"; - $replace[] = "
\n"; + $search[] = "/^(.+)\\n--+$\\n/Um"; + $replace[] = "\n
continue until the end of paragraph
+ debugMKD ("DEB1 : Starting a new block");
+ if ($type === "")
+ {
+ debugMKD ("No type : skipped");
+ continue;
+ }
+
if (end ($indentStack))
array_pop ($indentStack);
+ if ($type === "code")
+ {
+ // Code need a pre before code
+ if (end ($typeStack))
+ {
+ debugMKD ("DEB2 : CODE : Close older HTML");
+ $oldType = array_pop ($typeStack);
+ debugMKD (str_repeat (" ", end ($indentStack))."$oldType>");
+ $res .= str_repeat (" ", end ($indentStack))."$oldType>";
+ array_pop ($htmlStack);
+ }
+ $type = "pre>");
+ debugMKD (str_repeat (" ", $indent)."<$type>");
$res .= "\n".str_repeat (" ", $indent)."<$type>";
- $htmlStack[] = $type;
if ($type === "ol" || $type === "ul")
{
debugMKD ("DEB2 : Adding li");
$htmlStack[] = "li";
- debugMKD ( str_repeat (" ", $indent)."");
+ debugMKD (str_repeat (" ", $indent)." ");
$res .= "\n".str_repeat (" ", $indent)." ";
}
}
- debugMKD ("$lineTxt");
- $res .= "$lineTxt";
+ if ($type === "" && end ($indentStack))
+ {
+ debugMKD ("DEB2 : Empty type");
+ $oldType = array_pop ($typeStack);
+ debugMKD (str_repeat (" ", end ($indentStack))."$oldType>");
+ $res .= "\n".str_repeat (" ", end ($indentStack))."$oldType>";
+ array_pop ($htmlStack);
+ }
+ debugMKD ("$lineTxt");
+ $res .= "$lineTxt\n";
}
- debugMKD ( "DEB1 : End of loop");
+ debugMKD ("DEB1 : End of loop");
$htmlStack = array_reverse ($htmlStack);
foreach ($htmlStack as $type)
{
- debugMKD ( "FIN$type>");
+ debugMKD ("FIN$type>");
$res .= "$type>\n";
}
- debugMKD ( "-----------\n");
+ debugMKD ("-----------\n");
return $res;
}
- /** Return the Type of object in the provided line
+ /** Return the Type of object in the provided line
p, ul, ol, code */
private function paragraphType ($line)
{
- $line = ltrim ($line);
if (! isset ($line{0}))
return "";
- if ($line{0} === "*" || $line{0} === "-" || $line{0} === "+")
+ if (preg_match ("/^[ \t]*[+*-] /", $line) === 1)
return "ul";
- if (preg_match ("/^[0-9]+\. /", $line) === 1)
+ if (preg_match ("/^[ \t]*[0-9]+\. /", $line) === 1)
return "ol";
+ if (preg_match ("/^( |\t)+/", $line) === 1)
+ return "code";
return "p";
}
}