From 87cb2d4fcfa11e36eaad4e35bb0c6882aebe9e5c Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Tue, 1 Jul 2014 12:27:50 +0000 Subject: [PATCH] markdown allow a good indentation in ul/li. git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1511 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- Tests/markdownTest.php | 46 +++++++++++++++++++++++++++++++++++++++++- markdown.php | 14 ++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/Tests/markdownTest.php b/Tests/markdownTest.php index f9c5319..c26a461 100644 --- a/Tests/markdownTest.php +++ b/Tests/markdownTest.php @@ -177,6 +177,38 @@ class test_markdown extends PHPUnit_Framework_TestCase printf ($md->html ("+ Case1\n+ Case2\n+ Case3"), TRUE); } + public function testUnnumberredMultiline1 () + { + $this->expectOutputString(""); + $md = new markdown (); + printf ($md->html ("* line1 +end +* line2 +end")); + } + + public function testUnnumberedListMultiple1 () + { + $this->expectOutputString(""); + $md = new markdown (); + printf ($md->html ("* line1 +* line2 + * NEW lineA + * NEW lineB +* line3")); + } + // Numbered lists public function testNumbered1 () { @@ -241,10 +273,22 @@ base"); public function testChainCode1 () { - $this->expectOutputString("

 * OK
"); $md = new markdown (); printf ($md->html (" \n * OK")); } + + public function testUnnumberredAndText1 () + { + $this->expectOutputString("

Hi

"); + $md = new markdown (); + printf ($md->html ("Hi +* line1 +* line2 +end")); + } } diff --git a/markdown.php b/markdown.php index ed47d4e..62f0b6d 100644 --- a/markdown.php +++ b/markdown.php @@ -195,6 +195,12 @@ class markdown $res .= "\n"; array_pop ($htmlStack); } + if (strlen ($res) && in_array ($type, array ("ul","ol","p"))) + { + $this->debugMKD ("Add \\n because of new block and not at start"); + $res .= "\n"; + } + // Remove last \n to put closing tag at the end of line $res = substr ($res, 0, -1); @@ -245,7 +251,7 @@ class markdown { $this->debugMKD ("DEB2 : Continuous LI block"); // Suppress \n on last line - $res = substr ($res, 0, -1); +// $res = substr ($res, 0, -1); $type = prev ($htmlStack); $blockLI = true; $lineTxt = " ".$lineTxt; @@ -296,6 +302,12 @@ class markdown continue; } + if (strlen ($res) && in_array ($type, array ("ul","ol","p"))) + { + $this->debugMKD ("Add \\n because of new block"); + $res .= "\n"; + } + if (end ($indentStack)) array_pop ($indentStack); if ($type === "code")