markdown allow a good indentation in ul/li.

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1511 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-07-01 12:27:50 +00:00
parent 386f490481
commit 87cb2d4fcf
2 changed files with 58 additions and 2 deletions

View File

@@ -177,6 +177,38 @@ class test_markdown extends PHPUnit_Framework_TestCase
printf ($md->html ("+ Case1\n+ Case2\n+ Case3"), TRUE); printf ($md->html ("+ Case1\n+ Case2\n+ Case3"), TRUE);
} }
public function testUnnumberredMultiline1 ()
{
$this->expectOutputString("<ul>
<li>line1 end </li>
<li>line2 end</li>
</ul>");
$md = new markdown ();
printf ($md->html ("* line1
end
* line2
end"));
}
public function testUnnumberedListMultiple1 ()
{
$this->expectOutputString("<ul>
<li>line1</li>
<li>line2
<ul>
<li>NEW lineA</li>
<li>NEW lineB</li>
</ul></li>
<li>line3</li>
</ul>");
$md = new markdown ();
printf ($md->html ("* line1
* line2
* NEW lineA
* NEW lineB
* line3"));
}
// Numbered lists // Numbered lists
public function testNumbered1 () public function testNumbered1 ()
{ {
@@ -241,10 +273,22 @@ base</code></pre>");
public function testChainCode1 () public function testChainCode1 ()
{ {
$this->expectOutputString(" <pre><code> $this->expectOutputString(" <pre><code>
* OK</code></pre>"); * OK</code></pre>");
$md = new markdown (); $md = new markdown ();
printf ($md->html (" \n * OK")); printf ($md->html (" \n * OK"));
} }
public function testUnnumberredAndText1 ()
{
$this->expectOutputString("<p>Hi</p><ul>
<li>line1</li>
<li>line2 end</li>
</ul>");
$md = new markdown ();
printf ($md->html ("Hi
* line1
* line2
end"));
}
} }

View File

@@ -195,6 +195,12 @@ class markdown
$res .= "</li>\n"; $res .= "</li>\n";
array_pop ($htmlStack); 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 // Remove last \n to put closing tag at the end of line
$res = substr ($res, 0, -1); $res = substr ($res, 0, -1);
@@ -245,7 +251,7 @@ class markdown
{ {
$this->debugMKD ("DEB2 : Continuous LI block"); $this->debugMKD ("DEB2 : Continuous LI block");
// Suppress \n on last line // Suppress \n on last line
$res = substr ($res, 0, -1); // $res = substr ($res, 0, -1);
$type = prev ($htmlStack); $type = prev ($htmlStack);
$blockLI = true; $blockLI = true;
$lineTxt = " ".$lineTxt; $lineTxt = " ".$lineTxt;
@@ -296,6 +302,12 @@ class markdown
continue; continue;
} }
if (strlen ($res) && in_array ($type, array ("ul","ol","p")))
{
$this->debugMKD ("Add \\n because of new block");
$res .= "\n";
}
if (end ($indentStack)) if (end ($indentStack))
array_pop ($indentStack); array_pop ($indentStack);
if ($type === "code") if ($type === "code")