P tags are now corrects
Put the closing tags at end of line to be more readable git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1287 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
56
markdown.php
56
markdown.php
@@ -19,6 +19,7 @@ class markdown
|
|||||||
@param string $mark Message in markdown syntax to display */
|
@param string $mark Message in markdown syntax to display */
|
||||||
public function html ($mark)
|
public function html ($mark)
|
||||||
{
|
{
|
||||||
|
unlink ("/tmp/debug");
|
||||||
$res = "";
|
$res = "";
|
||||||
$mark = htmlentities ($mark, ENT_QUOTES);
|
$mark = htmlentities ($mark, ENT_QUOTES);
|
||||||
|
|
||||||
@@ -47,7 +48,8 @@ class markdown
|
|||||||
return the html */
|
return the html */
|
||||||
private function paragraph ($mark)
|
private function paragraph ($mark)
|
||||||
{
|
{
|
||||||
$timeStart = microtime (TRUE);
|
$timeStart = microtime (TRUE);
|
||||||
|
$timeregex = 0;
|
||||||
// Initialization of convertions
|
// Initialization of convertions
|
||||||
$search = array ();
|
$search = array ();
|
||||||
$replace = array ();
|
$replace = array ();
|
||||||
@@ -173,20 +175,23 @@ $timeStart = microtime (TRUE);
|
|||||||
array_pop ($htmlStack);
|
array_pop ($htmlStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove last \n to put closing tag at the end of line
|
||||||
|
$res = substr ($res, 0, -1);
|
||||||
$oldType = array_pop ($typeStack);
|
$oldType = array_pop ($typeStack);
|
||||||
if ($oldType === "code")
|
if ($oldType === "code")
|
||||||
{
|
{
|
||||||
debugMKD (str_repeat (" ", end ($indentStack))."</code></pre>");
|
debugMKD ("</code></pre>");
|
||||||
$res .= str_repeat (" ", end ($indentStack))."</code></pre>\n";
|
$res .= "</code></pre>\n";
|
||||||
array_pop ($htmlStack);
|
array_pop ($htmlStack);
|
||||||
|
array_pop ($indentStack);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debugMKD (str_repeat (" ", end ($indentStack))."</$oldType>");
|
debugMKD (str_repeat (" ", end ($indentStack))."</$oldType>");
|
||||||
$res .= str_repeat (" ", end ($indentStack))."</$oldType>\n";
|
$res .= str_repeat (" ", end ($indentStack))."</$oldType>\n";
|
||||||
}
|
}
|
||||||
array_pop ($htmlStack);
|
|
||||||
array_pop ($indentStack);
|
array_pop ($indentStack);
|
||||||
|
array_pop ($htmlStack);
|
||||||
if ($type === "ol" || $type === "ul")
|
if ($type === "ol" || $type === "ul")
|
||||||
{
|
{
|
||||||
debugMKD ("DEB2 : Pending <Li> : closing");
|
debugMKD ("DEB2 : Pending <Li> : closing");
|
||||||
@@ -204,7 +209,7 @@ $timeStart = microtime (TRUE);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($indent == end ($indentStack) && $type !== "" && end ($typeStack))
|
if ($indent == end ($indentStack))
|
||||||
{
|
{
|
||||||
debugMKD ("DEB1 : Continuous block $type/".end ($typeStack));
|
debugMKD ("DEB1 : Continuous block $type/".end ($typeStack));
|
||||||
if (end ($htmlStack) === "li")
|
if (end ($htmlStack) === "li")
|
||||||
@@ -218,16 +223,25 @@ $timeStart = microtime (TRUE);
|
|||||||
if ($type !== end ($typeStack))
|
if ($type !== end ($typeStack))
|
||||||
{
|
{
|
||||||
debugMKD ("DEB2 : Continuous Block but type change");
|
debugMKD ("DEB2 : Continuous Block but type change");
|
||||||
$oldType = array_pop ($typeStack);
|
if (end ($typeStack) !== FALSE)
|
||||||
debugMKD (str_repeat (" ", end ($indentStack))."</$oldType>");
|
{
|
||||||
$res .= "\n".str_repeat (" ", end ($indentStack))."</$oldType>";
|
// Remove last \n to put closing tag at the end of line
|
||||||
array_pop ($htmlStack);
|
$res = substr ($res, 0, -1);
|
||||||
|
$oldType = array_pop ($typeStack);
|
||||||
|
debugMKD (str_repeat (" ", end ($indentStack))."</$oldType>");
|
||||||
|
$res .= str_repeat (" ", end ($indentStack))."</$oldType>";
|
||||||
|
array_pop ($indentStack);
|
||||||
|
array_pop ($htmlStack);
|
||||||
|
}
|
||||||
|
|
||||||
debugMKD (str_repeat (" ", end ($indentStack))."<$type>");
|
if ($type !== "")
|
||||||
$res .= "\n".str_repeat (" ", end ($indentStack))."<$type>";
|
{
|
||||||
$htmlStack[] = $type;
|
debugMKD (str_repeat (" ", end ($indentStack))."<$type>");
|
||||||
array_push ($indentStack, $indent);
|
$res .= "\n".str_repeat (" ", end ($indentStack))."<$type>";
|
||||||
array_push ($typeStack, $type);
|
$htmlStack[] = $type;
|
||||||
|
array_push ($indentStack, $indent);
|
||||||
|
array_push ($typeStack, $type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type === "ol" || $type === "ul")
|
if ($type === "ol" || $type === "ul")
|
||||||
@@ -259,9 +273,12 @@ $timeStart = microtime (TRUE);
|
|||||||
if (end ($typeStack))
|
if (end ($typeStack))
|
||||||
{
|
{
|
||||||
debugMKD ("DEB2 : CODE : Close older HTML");
|
debugMKD ("DEB2 : CODE : Close older HTML");
|
||||||
|
// Remove last \n to put closing tag at the end of line
|
||||||
|
$res = substr ($res, 0, -1);
|
||||||
$oldType = array_pop ($typeStack);
|
$oldType = array_pop ($typeStack);
|
||||||
debugMKD (str_repeat (" ", end ($indentStack))."</$oldType>");
|
debugMKD (str_repeat (" ", end ($indentStack))."</$oldType>");
|
||||||
$res .= str_repeat (" ", end ($indentStack))."</$oldType>";
|
$res .= str_repeat (" ", end ($indentStack))."</$oldType>";
|
||||||
|
array_pop ($indentStack);
|
||||||
array_pop ($htmlStack);
|
array_pop ($htmlStack);
|
||||||
}
|
}
|
||||||
$typetmp = "pre><code";
|
$typetmp = "pre><code";
|
||||||
@@ -290,21 +307,14 @@ $timeStart = microtime (TRUE);
|
|||||||
if ($type === "" && end ($indentStack))
|
if ($type === "" && end ($indentStack))
|
||||||
{
|
{
|
||||||
debugMKD ("DEB2 : Empty type");
|
debugMKD ("DEB2 : Empty type");
|
||||||
|
// Remove last \n to put closing tag at the end of line
|
||||||
|
$res = substr ($res, 0, -1);
|
||||||
$oldType = array_pop ($typeStack);
|
$oldType = array_pop ($typeStack);
|
||||||
debugMKD (str_repeat (" ", end ($indentStack))."</$oldType>");
|
debugMKD (str_repeat (" ", end ($indentStack))."</$oldType>");
|
||||||
$res .= "\n".str_repeat (" ", end ($indentStack))."</$oldType>";
|
$res .= "\n".str_repeat (" ", end ($indentStack))."</$oldType>";
|
||||||
array_pop ($htmlStack);
|
array_pop ($htmlStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
// New paragraphs
|
|
||||||
/* if ($type === "p")
|
|
||||||
{
|
|
||||||
debugMKD ("DEB1 : Starting a new paragraph");
|
|
||||||
debugMKD (str_repeat (" ", $indent)."<$type>");
|
|
||||||
$res .= "\n".str_repeat (" ", $indent)."<$type>";
|
|
||||||
array_push ($typeStack, $type);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// If code, there is no emphasis, email, and other convertions
|
// If code, there is no emphasis, email, and other convertions
|
||||||
if ($type !== "code")
|
if ($type !== "code")
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user