Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loose lists #475

Merged
merged 3 commits into from Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 20 additions & 2 deletions Parsedown.php
Expand Up @@ -515,10 +515,10 @@ protected function blockList($Line)
),
);

if($name === 'ol')
if($name === 'ol')
{
$listStart = stristr($matches[0], '.', true);

if($listStart !== '1')
{
$Block['element']['attributes'] = array('start' => $listStart);
Expand Down Expand Up @@ -547,6 +547,8 @@ protected function blockListContinue($Line, array $Block)
{
$Block['li']['text'] []= '';

$Block['loose'] = true;

unset($Block['interrupted']);
}

Expand Down Expand Up @@ -595,6 +597,22 @@ protected function blockListContinue($Line, array $Block)
}
}

protected function blockListComplete(array $Block)
{
if (isset($Block['loose']))
{
foreach ($Block['element']['text'] as &$li)
{
if (end($li['text']) !== '')
{
$li['text'] []= '';
}
}
}

return $Block;
}

#
# Quote

Expand Down
10 changes: 10 additions & 0 deletions test/data/multiline_lists.html
@@ -0,0 +1,10 @@
<ol>
<li>
<p>One
First body copy</p>
</li>
<li>
<p>Two
Last body copy</p>
</li>
</ol>
5 changes: 5 additions & 0 deletions test/data/multiline_lists.md
@@ -0,0 +1,5 @@
1. One
First body copy

2. Two
Last body copy
4 changes: 3 additions & 1 deletion test/data/paragraph_list.html
Expand Up @@ -8,5 +8,7 @@
<li>
<p>li</p>
</li>
<li>li</li>
<li>
<p>li</p>
</li>
</ul>
8 changes: 6 additions & 2 deletions test/data/sparse_dense_list.html
Expand Up @@ -2,6 +2,10 @@
<li>
<p>li</p>
</li>
<li>li</li>
<li>li</li>
<li>
<p>li</p>
</li>
<li>
<p>li</p>
</li>
</ul>
4 changes: 3 additions & 1 deletion test/data/sparse_list.html
Expand Up @@ -2,7 +2,9 @@
<li>
<p>li</p>
</li>
<li>li</li>
<li>
<p>li</p>
</li>
</ul>
<hr />
<ul>
Expand Down