Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit 340c76f

Browse files
authored
Fix #601: checkbox list separated with blank lines (#602)
* Fix #586: encode image tag's src attribute * Fix #601: checkbox list separated with blank lines
1 parent 7463999 commit 340c76f

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/src/block_syntaxes/list_syntax.dart

+12-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ abstract class ListSyntax extends BlockSyntax {
268268
final children = itemParser.parseLines(parentSyntax: this);
269269
final itemElement = checkboxToInsert == null
270270
? Element('li', children)
271-
: (Element('li', [checkboxToInsert, ...children])
271+
: (Element('li', _addCheckbox(children, checkboxToInsert))
272272
..attributes['class'] = taskListClass);
273273

274274
itemNodes.add(itemElement);
@@ -318,6 +318,17 @@ abstract class ListSyntax extends BlockSyntax {
318318
return listElement;
319319
}
320320

321+
List<Node> _addCheckbox(List<Node> children, Element checkbox) {
322+
if (children.isNotEmpty) {
323+
final firstChild = children.first;
324+
if (firstChild is Element && firstChild.tag == 'p') {
325+
firstChild.children!.insert(0, checkbox);
326+
return children;
327+
}
328+
}
329+
return [checkbox, ...children];
330+
}
331+
321332
void _removeLeadingEmptyLine(ListItem item) {
322333
if (item.lines.isNotEmpty && item.lines.first.isBlankLine) {
323334
item.lines.removeAt(0);

test/extensions/unordered_list_with_checkboxes.unit

+18
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,22 @@
6262
<pre><code>[ ] five
6363
</code></pre>
6464
</li>
65+
</ul>
66+
>>> checkbox list separated with blank lines
67+
- [ ] A
68+
69+
- [ ] B
70+
71+
- [ ]
72+
<<<
73+
<ul class="contains-task-list">
74+
<li class="task-list-item">
75+
<p><input type="checkbox"></input>A</p>
76+
</li>
77+
<li class="task-list-item">
78+
<p><input type="checkbox"></input>B</p>
79+
</li>
80+
<li>
81+
<p>[ ]</p>
82+
</li>
6583
</ul>

0 commit comments

Comments
 (0)