Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ static cmark_node *finalize(cmark_parser *parser, cmark_node *b) {
{
has_content = resolve_reference_link_definitions(parser);
if (!has_content) {
// remove blank node (former reference def)
// remove blank node (former reference def), but if it was the
// opening line of a list item, remember that the item did have
// real content, since parent->first_child is about to go back
// to NULL along with this node.
if (parent && S_type(parent) == CMARK_NODE_ITEM)
parent->flags |= CMARK_NODE__ITEM_HAD_CONTENT;
cmark_node_free(b);
} else {
b->len = node_content->size;
Expand Down Expand Up @@ -805,10 +810,17 @@ static bool parse_node_item_prefix(cmark_parser *parser, cmark_chunk *input,
container->as.list.padding,
true);
res = true;
} else if (parser->blank && container->first_child != NULL) {
// if container->first_child is NULL, then the opening line
// of the list item was blank after the list marker; in this
// case, we are done with the list item.
} else if (parser->blank &&
(container->first_child != NULL ||
(container->flags & CMARK_NODE__ITEM_HAD_CONTENT))) {
// if container->first_child is NULL and the item never had any
// other content either, then the opening line of the list item
// was blank after the list marker; in this case, we are done with
// the list item. CMARK_NODE__ITEM_HAD_CONTENT covers the case
// where the item's only line so far was a link reference
// definition: its paragraph gets freed once the reference
// resolves, leaving first_child NULL again even though the
// opening line was not blank.
S_advance_offset(parser, input, parser->first_nonspace - parser->offset,
false);
res = true;
Expand Down
1 change: 1 addition & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum cmark_node__internal_flags {
CMARK_NODE__LAST_LINE_BLANK = (1 << 1),
CMARK_NODE__LAST_LINE_CHECKED = (1 << 2),
CMARK_NODE__LIST_LAST_LINE_BLANK = (1 << 3),
CMARK_NODE__ITEM_HAD_CONTENT = (1 << 4),
};

struct cmark_node {
Expand Down
16 changes: 16 additions & 0 deletions test/regression.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,19 @@ break, not a paragraph.
<hr />
<p><a href="/url">foo</a></p>
````````````````````````````````

Issue #618: a blank line inside a list item that has only trailing
spaces (fewer than the item's own indent) should not evict a later
indented line from the item, the same as a fully empty blank line or
one padded out to the item's indent width would.

```````````````````````````````` example
- [r]:x


l
.
<ul>
<li>l</li>
</ul>
````````````````````````````````
Expand Down
Loading