mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
improve consistency of list item
This commit is contained in:
parent
b257d0ecaa
commit
f5f1706e58
@ -194,16 +194,14 @@ class Parsedown
|
||||
|
||||
case 'li':
|
||||
|
||||
if ($block['indentation'] === $indentation and preg_match('/^'.$block['marker'].'[ ](.*)/', $deindented_line, $matches))
|
||||
if ($block['indentation'] === $indentation and preg_match('/^'.$block['marker'].'[ ]+(.*)/', $deindented_line, $matches))
|
||||
{
|
||||
unset($block['last']);
|
||||
|
||||
$blocks []= $block;
|
||||
|
||||
$block['last'] = true;
|
||||
$block['lines'] = array();
|
||||
|
||||
$block['lines'] []= preg_replace('/^[ ]{0,4}/', '', $matches[1]);
|
||||
$block['lines'] = array($matches[1]);
|
||||
|
||||
unset($block['first']);
|
||||
unset($block['interrupted']);
|
||||
@ -213,7 +211,7 @@ class Parsedown
|
||||
|
||||
if ( ! isset($block['interrupted']))
|
||||
{
|
||||
$line = preg_replace('/^[ ]{0,4}/', '', $line);
|
||||
$line = preg_replace('/^[ ]{0,'.$block['baseline'].'}/', '', $line);
|
||||
|
||||
$block['lines'] []= $line;
|
||||
|
||||
@ -223,7 +221,7 @@ class Parsedown
|
||||
{
|
||||
$block['lines'] []= '';
|
||||
|
||||
$line = preg_replace('/^[ ]{0,4}/', '', $line);
|
||||
$line = preg_replace('/^[ ]{0,'.$block['baseline'].'}/', '', $line);
|
||||
|
||||
$block['lines'] []= $line;
|
||||
|
||||
@ -491,34 +489,40 @@ class Parsedown
|
||||
|
||||
# li
|
||||
|
||||
if (preg_match('/^[*+-][ ](.*)/', $deindented_line, $matches))
|
||||
if (preg_match('/^([*+-][ ]+)(.*)/', $deindented_line, $matches))
|
||||
{
|
||||
$blocks []= $block;
|
||||
|
||||
$baseline = $indentation + strlen($matches[1]);
|
||||
|
||||
$block = array(
|
||||
'type' => 'li',
|
||||
'indentation' => $indentation,
|
||||
'baseline' => $baseline,
|
||||
'marker' => '[*+-]',
|
||||
'first' => true,
|
||||
'last' => true,
|
||||
'lines' => array(),
|
||||
);
|
||||
|
||||
$block['lines'] []= preg_replace('/^[ ]{0,4}/', '', $matches[1]);
|
||||
$block['lines'] []= preg_replace('/^[ ]{0,4}/', '', $matches[2]);
|
||||
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
# list item
|
||||
# li
|
||||
|
||||
if ($deindented_line[0] <= '9' and preg_match('/^\d+[.][ ](.*)/', $deindented_line, $matches))
|
||||
if ($deindented_line[0] <= '9' and preg_match('/^(\d+[.][ ]+)(.*)/', $deindented_line, $matches))
|
||||
{
|
||||
$blocks []= $block;
|
||||
|
||||
$baseline = $indentation + strlen($matches[1]);
|
||||
|
||||
$block = array(
|
||||
'type' => 'li',
|
||||
'indentation' => $indentation,
|
||||
'baseline' => $baseline,
|
||||
'marker' => '\d+[.]',
|
||||
'first' => true,
|
||||
'last' => true,
|
||||
@ -526,7 +530,7 @@ class Parsedown
|
||||
'lines' => array(),
|
||||
);
|
||||
|
||||
$block['lines'] []= preg_replace('/^[ ]{0,4}/', '', $matches[1]);
|
||||
$block['lines'] []= preg_replace('/^[ ]{0,4}/', '', $matches[2]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
18
tests/data/deeply_nested_list.html
Normal file
18
tests/data/deeply_nested_list.html
Normal file
@ -0,0 +1,18 @@
|
||||
<ul>
|
||||
<li>li
|
||||
<ul>
|
||||
<li>li
|
||||
<ul>
|
||||
<li>li
|
||||
<ul>
|
||||
<li>li</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>li</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>li</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>li</li>
|
||||
</ul>
|
7
tests/data/deeply_nested_list.md
Normal file
7
tests/data/deeply_nested_list.md
Normal file
@ -0,0 +1,7 @@
|
||||
- li
|
||||
- li
|
||||
- li
|
||||
- li
|
||||
- li
|
||||
- li
|
||||
- li
|
Loading…
Reference in New Issue
Block a user