Skip to content

Commit

Permalink
Fix #601: checkbox list separated with blank lines (#602)
Browse files Browse the repository at this point in the history
* Fix #586: encode image tag's src attribute

* Fix #601: checkbox list separated with blank lines
  • Loading branch information
tomyeh authored May 22, 2024
1 parent 7463999 commit 340c76f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/src/block_syntaxes/list_syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ abstract class ListSyntax extends BlockSyntax {
final children = itemParser.parseLines(parentSyntax: this);
final itemElement = checkboxToInsert == null
? Element('li', children)
: (Element('li', [checkboxToInsert, ...children])
: (Element('li', _addCheckbox(children, checkboxToInsert))
..attributes['class'] = taskListClass);

itemNodes.add(itemElement);
Expand Down Expand Up @@ -318,6 +318,17 @@ abstract class ListSyntax extends BlockSyntax {
return listElement;
}

List<Node> _addCheckbox(List<Node> children, Element checkbox) {
if (children.isNotEmpty) {
final firstChild = children.first;
if (firstChild is Element && firstChild.tag == 'p') {
firstChild.children!.insert(0, checkbox);
return children;
}
}
return [checkbox, ...children];
}

void _removeLeadingEmptyLine(ListItem item) {
if (item.lines.isNotEmpty && item.lines.first.isBlankLine) {
item.lines.removeAt(0);
Expand Down
18 changes: 18 additions & 0 deletions test/extensions/unordered_list_with_checkboxes.unit
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,22 @@
<pre><code>[ ] five
</code></pre>
</li>
</ul>
>>> checkbox list separated with blank lines
- [ ] A

- [ ] B

- [ ]
<<<
<ul class="contains-task-list">
<li class="task-list-item">
<p><input type="checkbox"></input>A</p>
</li>
<li class="task-list-item">
<p><input type="checkbox"></input>B</p>
</li>
<li>
<p>[ ]</p>
</li>
</ul>

0 comments on commit 340c76f

Please sign in to comment.