1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Support list items starting with a blank line

According to the CommonMark specs ([list items](http://spec.commonmark.org/0.26/#list-items), rule 3), list items starting with a blank line basically behave like as if the \n doesn't exist. Also see example [#241](http://spec.commonmark.org/0.26/#example-241).
This commit is contained in:
Daniel Rudolf 2016-10-13 19:46:29 +02:00
parent 30ff5c6e75
commit 4b3b7df710
No known key found for this signature in database
GPG Key ID: A061F02CD8DE4538

View File

@ -504,8 +504,12 @@ class Parsedown
{ {
list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]{1,9}[.\)]'); list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]{1,9}[.\)]');
if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches)) if (preg_match('/^('.$pattern.'([ ]+|$))(.*)/', $Line['text'], $matches))
{ {
if ($matches[2] === '') {
$matches[1] .= ' ';
}
$Block = array( $Block = array(
'indent' => $Line['indent'], 'indent' => $Line['indent'],
'pattern' => $pattern, 'pattern' => $pattern,
@ -532,9 +536,7 @@ class Parsedown
$Block['li'] = array( $Block['li'] = array(
'name' => 'li', 'name' => 'li',
'handler' => 'li', 'handler' => 'li',
'text' => array( 'text' => !empty($matches[3]) ? array($matches[3]) : array(),
$matches[2],
),
); );
$Block['element']['text'] []= & $Block['li']; $Block['element']['text'] []= & $Block['li'];
@ -545,6 +547,10 @@ class Parsedown
protected function blockListContinue($Line, array $Block) protected function blockListContinue($Line, array $Block)
{ {
if (isset($Block['interrupted']) and empty($Block['li']['text'])) {
return null;
}
if ( if (
$Block['indent'] === $Line['indent'] $Block['indent'] === $Line['indent']
and and