From 8d16811efff8bc78baa81b15abd31214876c6a7a Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 12 May 2014 12:55:55 +0000 Subject: [PATCH] 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 --- markdown.php | 56 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/markdown.php b/markdown.php index 32e0b1b..6c2fec8 100644 --- a/markdown.php +++ b/markdown.php @@ -19,6 +19,7 @@ class markdown @param string $mark Message in markdown syntax to display */ public function html ($mark) { + unlink ("/tmp/debug"); $res = ""; $mark = htmlentities ($mark, ENT_QUOTES); @@ -47,7 +48,8 @@ class markdown return the html */ private function paragraph ($mark) { -$timeStart = microtime (TRUE); + $timeStart = microtime (TRUE); + $timeregex = 0; // Initialization of convertions $search = array (); $replace = array (); @@ -173,20 +175,23 @@ $timeStart = microtime (TRUE); array_pop ($htmlStack); } + // Remove last \n to put closing tag at the end of line + $res = substr ($res, 0, -1); $oldType = array_pop ($typeStack); if ($oldType === "code") { - debugMKD (str_repeat (" ", end ($indentStack)).""); - $res .= str_repeat (" ", end ($indentStack))."\n"; + debugMKD (""); + $res .= "\n"; array_pop ($htmlStack); + array_pop ($indentStack); } else { debugMKD (str_repeat (" ", end ($indentStack)).""); $res .= str_repeat (" ", end ($indentStack))."\n"; } - array_pop ($htmlStack); array_pop ($indentStack); + array_pop ($htmlStack); if ($type === "ol" || $type === "ul") { debugMKD ("DEB2 : Pending
  • : 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)); if (end ($htmlStack) === "li") @@ -218,16 +223,25 @@ $timeStart = microtime (TRUE); if ($type !== end ($typeStack)) { debugMKD ("DEB2 : Continuous Block but type change"); - $oldType = array_pop ($typeStack); - debugMKD (str_repeat (" ", end ($indentStack)).""); - $res .= "\n".str_repeat (" ", end ($indentStack)).""; - array_pop ($htmlStack); + if (end ($typeStack) !== FALSE) + { + // Remove last \n to put closing tag at the end of line + $res = substr ($res, 0, -1); + $oldType = array_pop ($typeStack); + debugMKD (str_repeat (" ", end ($indentStack)).""); + $res .= str_repeat (" ", end ($indentStack)).""; + array_pop ($indentStack); + array_pop ($htmlStack); + } - debugMKD (str_repeat (" ", end ($indentStack))."<$type>"); - $res .= "\n".str_repeat (" ", end ($indentStack))."<$type>"; - $htmlStack[] = $type; - array_push ($indentStack, $indent); - array_push ($typeStack, $type); + if ($type !== "") + { + debugMKD (str_repeat (" ", end ($indentStack))."<$type>"); + $res .= "\n".str_repeat (" ", end ($indentStack))."<$type>"; + $htmlStack[] = $type; + array_push ($indentStack, $indent); + array_push ($typeStack, $type); + } } if ($type === "ol" || $type === "ul") @@ -259,9 +273,12 @@ $timeStart = microtime (TRUE); if (end ($typeStack)) { 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); debugMKD (str_repeat (" ", end ($indentStack)).""); $res .= str_repeat (" ", end ($indentStack)).""; + array_pop ($indentStack); array_pop ($htmlStack); } $typetmp = "pre>"); $res .= "\n".str_repeat (" ", end ($indentStack)).""; 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 ($type !== "code") {