Prepend a line ending if the p tag is removed and there is an element before it in a *tight* list (#513)

* Prepend a line ending if the p tag is removed

* Ignore task list
diff --git a/lib/src/block_syntaxes/list_syntax.dart b/lib/src/block_syntaxes/list_syntax.dart
index 77f6791..5ca3451 100644
--- a/lib/src/block_syntaxes/list_syntax.dart
+++ b/lib/src/block_syntaxes/list_syntax.dart
@@ -250,6 +250,7 @@
     final anyEmptyLines = _removeTrailingEmptyLines(items);
     var anyEmptyLinesBetweenBlocks = false;
     var containsTaskList = false;
+    const taskListClass = 'task-list-item';
 
     for (final item in items) {
       Element? checkboxToInsert;
@@ -267,7 +268,7 @@
       final itemElement = checkboxToInsert == null
           ? Element('li', children)
           : (Element('li', [checkboxToInsert, ...children])
-            ..attributes['class'] = 'task-list-item');
+            ..attributes['class'] = taskListClass);
 
       itemNodes.add(itemElement);
       anyEmptyLinesBetweenBlocks =
@@ -282,14 +283,24 @@
       // We must post-process the list items, converting any top-level paragraph
       // elements to just text elements.
       for (final item in itemNodes) {
+        final isTaskList = item.attributes['class'] == taskListClass;
         final children = item.children;
         if (children != null) {
+          Node? lastNode;
           for (var i = 0; i < children.length; i++) {
             final child = children[i];
             if (child is Element && child.tag == 'p') {
-              children.removeAt(i);
-              children.insertAll(i, child.children!);
+              final childContent = child.children!;
+              if (lastNode is Element && !isTaskList) {
+                childContent.insert(0, Text('\n'));
+              }
+
+              children
+                ..removeAt(i)
+                ..insertAll(i, childContent);
             }
+
+            lastNode = child;
           }
         }
       }
diff --git a/test/common_mark/list_items.unit b/test/common_mark/list_items.unit
index b6554e0..46162a9 100644
--- a/test/common_mark/list_items.unit
+++ b/test/common_mark/list_items.unit
@@ -581,5 +581,6 @@
 <h1>Foo</h1>
 </li>
 <li>
-<h2>Bar</h2>baz</li>
+<h2>Bar</h2>
+baz</li>
 </ul>
diff --git a/test/gfm/list_items.unit b/test/gfm/list_items.unit
index bb2cb72..3954af8 100644
--- a/test/gfm/list_items.unit
+++ b/test/gfm/list_items.unit
@@ -581,5 +581,6 @@
 <h1>Foo</h1>
 </li>
 <li>
-<h2>Bar</h2>baz</li>
+<h2>Bar</h2>
+baz</li>
 </ul>
diff --git a/tool/common_mark_stats.json b/tool/common_mark_stats.json
index aee10cd..46a84ed 100644
--- a/tool/common_mark_stats.json
+++ b/tool/common_mark_stats.json
@@ -565,7 +565,7 @@
   "297": "strict",
   "298": "strict",
   "299": "strict",
-  "300": "loose"
+  "300": "strict"
  },
  "Lists": {
   "301": "strict",
diff --git a/tool/common_mark_stats.txt b/tool/common_mark_stats.txt
index 9fcddd0..541bd6a 100644
--- a/tool/common_mark_stats.txt
+++ b/tool/common_mark_stats.txt
@@ -25,4 +25,4 @@
    3 of    3 – 100.0%  Textual content
   19 of   19 – 100.0%  Thematic breaks
  652 of  652 – 100.0%  TOTAL
- 643 of  652 –  98.6%  TOTAL Strict
+ 644 of  652 –  98.8%  TOTAL Strict
diff --git a/tool/gfm_stats.json b/tool/gfm_stats.json
index 1bb291a..e6409e6 100644
--- a/tool/gfm_stats.json
+++ b/tool/gfm_stats.json
@@ -578,7 +578,7 @@
   "275": "strict",
   "276": "strict",
   "277": "strict",
-  "278": "loose"
+  "278": "strict"
  },
  "Lists": {
   "281": "strict",
diff --git a/tool/gfm_stats.txt b/tool/gfm_stats.txt
index f6b4a81..4f0014e 100644
--- a/tool/gfm_stats.txt
+++ b/tool/gfm_stats.txt
@@ -29,4 +29,4 @@
    3 of    3 – 100.0%  Textual content
   19 of   19 – 100.0%  Thematic breaks
  670 of  670 – 100.0%  TOTAL
- 657 of  670 –  98.1%  TOTAL Strict
+ 658 of  670 –  98.2%  TOTAL Strict