markdown : BUG : Errors in \n in return
markdown : BUG : Error if code section starting at the top of text markdown : All the actual phpunit tests are good git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1505 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
46
markdown.php
46
markdown.php
@@ -44,8 +44,9 @@ class markdown
|
||||
|
||||
$res = $this->paragraph ($mark);
|
||||
|
||||
$res = str_replace ("\n<p></p>", "", $res);
|
||||
$res = str_replace ("<p></p>", "", $res);
|
||||
$res = str_replace ("<p>\n</p>", "", $res);
|
||||
$res = str_replace ("<p>\n</p>\n", "", $res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
@@ -74,7 +75,7 @@ class markdown
|
||||
|
||||
// CODE : `code` -> <code>
|
||||
$search[] = "/\\n?\`((\\n|.)+)\`/Um";
|
||||
$replace[] = " <code>\\1</code>";
|
||||
$replace[] = "<code>\\1</code>";
|
||||
|
||||
// LINKS
|
||||
// [Google Site](http://google.fr/ "With help bubble")
|
||||
@@ -85,8 +86,10 @@ class markdown
|
||||
// Automatics links :
|
||||
// <http://dominique.fournier38.fr>
|
||||
// <dominique@fournier38.fr>
|
||||
$search[] = "#<(https?://.+)>#"; $replace[] = "<a href='\\1'>\\1</a>";
|
||||
$search[] = "#<(.+@.+)>#"; $replace[] = "<a href='mailto:\\1'>\\1</a>";
|
||||
$search[] = "#<(https?://.+)>#";
|
||||
$replace[] = "<a href='\\1'>\\1</a>";
|
||||
$search[] = "#<(.+@.+)>#";
|
||||
$replace[] = "<a href='mailto://\\1'>\\1</a>";
|
||||
// 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[] = "</p>\n<h6>\\1</h6>\n<p>";
|
||||
$replace[] = "</p><h6>\\1</h6><p>";
|
||||
// ##### Title5
|
||||
$search[] = "/^##### (.+)( +#*)$/Um";
|
||||
$replace[] = "</p>\n<h5>\\1</h5>\n<p>";
|
||||
$replace[] = "</p><h5>\\1</h5><p>";
|
||||
// #### Title4
|
||||
$search[] = "/^#### (.+)( +#*)$/Um";
|
||||
$replace[] = "</p>\n<h4>\\1</h4>\n<p>";
|
||||
$replace[] = "</p><h4>\\1</h4><p>";
|
||||
// ### Title3
|
||||
$search[] = "/^### (.+)( +#*)$/Um";
|
||||
$replace[] = "</p>\n<h3>\\1</h3>\n<p>";
|
||||
$replace[] = "</p><h3>\\1</h3><p>";
|
||||
// ## Title2
|
||||
$search[] = "/^## (.+)( +#*)$/Um";
|
||||
$replace[] = "</p>\n<h2>\\1</h2>\n<p>";
|
||||
$replace[] = "</p><h2>\\1</h2><p>";
|
||||
// # Title1
|
||||
$search[] = "/^# (.+)( +#*)$/Um";
|
||||
$replace[] = "</p>\n<h1>\\1</h1>\n<p>";
|
||||
$replace[] = "</p><h1>\\1</h1><p>";
|
||||
// End of line with double space : <br/>
|
||||
$search[] = "/( )$/Um"; $replace[] = "<br/>";
|
||||
|
||||
@@ -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 <Li> : closing");
|
||||
$this->debugMKD ("</li>");
|
||||
$res .= "</li>";
|
||||
$res .= "</li>\n";
|
||||
array_pop ($htmlStack);
|
||||
}
|
||||
|
||||
@@ -205,7 +207,7 @@ class markdown
|
||||
{
|
||||
$this->debugMKD ("DEB2 : Pending <Li> : closing");
|
||||
$this->debugMKD ("</li>");
|
||||
$res .= "\n</li>";
|
||||
$res .= "</li>";
|
||||
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</$type>");
|
||||
$res .= "</$type>\n";
|
||||
$res .= "</$type>";
|
||||
if (($i+1) < count ($htmlStack) && $type !== "code")
|
||||
$res .= "\n";
|
||||
}
|
||||
|
||||
$this->debugMKD ("TimeInit=".($timeInit*1000)."ms");
|
||||
|
||||
Reference in New Issue
Block a user