@@ -250,6 +250,7 @@ abstract class ListSyntax extends BlockSyntax {
250
250
final anyEmptyLines = _removeTrailingEmptyLines (items);
251
251
var anyEmptyLinesBetweenBlocks = false ;
252
252
var containsTaskList = false ;
253
+ const taskListClass = 'task-list-item' ;
253
254
254
255
for (final item in items) {
255
256
Element ? checkboxToInsert;
@@ -267,7 +268,7 @@ abstract class ListSyntax extends BlockSyntax {
267
268
final itemElement = checkboxToInsert == null
268
269
? Element ('li' , children)
269
270
: (Element ('li' , [checkboxToInsert, ...children])
270
- ..attributes['class' ] = 'task-list-item' );
271
+ ..attributes['class' ] = taskListClass );
271
272
272
273
itemNodes.add (itemElement);
273
274
anyEmptyLinesBetweenBlocks =
@@ -282,14 +283,24 @@ abstract class ListSyntax extends BlockSyntax {
282
283
// We must post-process the list items, converting any top-level paragraph
283
284
// elements to just text elements.
284
285
for (final item in itemNodes) {
286
+ final isTaskList = item.attributes['class' ] == taskListClass;
285
287
final children = item.children;
286
288
if (children != null ) {
289
+ Node ? lastNode;
287
290
for (var i = 0 ; i < children.length; i++ ) {
288
291
final child = children[i];
289
292
if (child is Element && child.tag == 'p' ) {
290
- children.removeAt (i);
291
- children.insertAll (i, child.children! );
293
+ final childContent = child.children! ;
294
+ if (lastNode is Element && ! isTaskList) {
295
+ childContent.insert (0 , Text ('\n ' ));
296
+ }
297
+
298
+ children
299
+ ..removeAt (i)
300
+ ..insertAll (i, childContent);
292
301
}
302
+
303
+ lastNode = child;
293
304
}
294
305
}
295
306
}
0 commit comments