Handle subsequent list items which aren't indented sufficiently

Subsequent list items which aren't indented sufficiently are treated as part of the original list, see CommonMark spec example [#256](http://spec.commonmark.org/0.26/#example-256).
This commit is contained in:
Daniel Rudolf 2016-10-13 20:44:02 +02:00
parent a9e1163c85
commit a3836b1853
No known key found for this signature in database
GPG Key ID: A061F02CD8DE4538
1 changed files with 6 additions and 5 deletions

View File

@ -562,8 +562,10 @@ class Parsedown
return null; return null;
} }
$requiredIndent = ($Block['indent'] + strlen($Block['data']['marker']));
if ( if (
$Block['indent'] === $Line['indent'] $Line['indent'] < $requiredIndent
and and
( (
( (
@ -589,6 +591,8 @@ class Parsedown
$text = isset($matches[1]) ? $matches[1] : ''; $text = isset($matches[1]) ? $matches[1] : '';
$Block['indent'] = $Line['indent'];
$Block['li'] = array( $Block['li'] = array(
'name' => 'li', 'name' => 'li',
'handler' => 'li', 'handler' => 'li',
@ -601,7 +605,7 @@ class Parsedown
return $Block; return $Block;
} }
elseif ($Block['indent'] === $Line['indent'] and $this->blockList($Line)) elseif ($Line['indent'] < $requiredIndent and $this->blockList($Line))
{ {
return null; return null;
} }
@ -611,8 +615,6 @@ class Parsedown
return $Block; return $Block;
} }
$requiredIndent = ($Block['indent'] + strlen($Block['data']['marker']));
if ($Line['indent'] >= $requiredIndent) if ($Line['indent'] >= $requiredIndent)
{ {
if (isset($Block['interrupted'])) if (isset($Block['interrupted']))
@ -631,7 +633,6 @@ class Parsedown
if ( ! isset($Block['interrupted'])) if ( ! isset($Block['interrupted']))
{ {
// TODO: force multi-line paragraph, this must not parse any new block
$text = preg_replace('/^[ ]{0,'.$requiredIndent.'}/', '', $Line['body']); $text = preg_replace('/^[ ]{0,'.$requiredIndent.'}/', '', $Line['body']);
$Block['li']['text'] []= $text; $Block['li']['text'] []= $text;