Repository: raphlinus/pulldown-cmark (rust)

Issue:
[fuzz result] wrong indentation calc after blank list item
Events from pulldown-cmark:

```rust
"-\n\n    *\n" -> [
  Start(List(None))
    Start(Item)
    End(Item)
  End(List(false))
  Start(List(None))
    Start(Item)
    End(Item)
  End(List(false))
]
```

Events from pandoc:

```rust
"-\n\n    *\n" -> [
  Start(List(None))
    Start(Item)
    End(Item)
  End(List(false))
  Start(CodeBlock(Fenced(Borrowed(""))))
    Text(Boxed("*"))
  End(CodeBlock)
]
```

<details>

Events from commonmark.js:

```rust
"-\n\n    *\n" -> [
  Start(List(None))
    Start(Item)
    End(Item)
  End(List(false))
  Start(CodeBlock(Fenced(Borrowed(""))))
    Text(Boxed("*"))
  End(CodeBlock)
]
```

AST from [pandoc](https://pandoc.org/try/?params=%7B%22text%22%3A%22-%5Cn%5Cn%20%20%20%20%2A%5Cn%22%2C%22to%22%3A%22json%22%2C%22from%22%3A%22commonmark%22%7D):

```text
Pandoc {
    meta: {},
    blocks: [
        BulletList(
            [
                [],
            ],
        ),
        CodeBlock(
            Attr(
                "",
                [],
                [],
            ),
            "*",
        ),
    ],
}
```


Pull request:
Do not subtract list item indent if it has more than one blank line
In this situation, the item cannot contain any nested blocks, so it should not be subtracted from the line start.

Fixes #751 

Patch:
diff --git a/specs/regression.txt b/specs/regression.txt
index 01318d3..95856fa 100644
--- a/specs/regression.txt
+++ b/specs/regression.txt
@@ -1510,3 +1510,55 @@ _*xx-_-
 <p><em>*__-</em>-</p>
 <p><em>*xx-</em>-</p>
 ````````````````````````````````
+
+ISSUE 751
+
+```````````````````````````````` example
+-
+
+→-
+
+
+- x
+
+→-
+.
+<ul>
+<li></li>
+</ul>
+<pre><code>-
+</code></pre>
+<ul>
+<li>
+<p>x</p>
+<ul>
+<li></li>
+</ul>
+</li>
+</ul>
+````````````````````````````````
+
+```````````````````````````````` example
+-
+
+    -
+
+
+- x
+
+    -
+.
+<ul>
+<li></li>
+</ul>
+<pre><code>-
+</code></pre>
+<ul>
+<li>
+<p>x</p>
+<ul>
+<li></li>
+</ul>
+</li>
+</ul>
+````````````````````````````````
diff --git a/src/firstpass.rs b/src/firstpass.rs
index a638a84..82b36a4 100644
--- a/src/firstpass.rs
+++ b/src/firstpass.rs
@@ -149,8 +149,16 @@ impl<'a, 'b> FirstPass<'a, 'b> {
 
         if let Some(n) = scan_blank_line(&bytes[ix..]) {
             if let Some(node_ix) = self.tree.peek_up() {
-                match self.tree[node_ix].item.body {
+                match &mut self.tree[node_ix].item.body {
                     ItemBody::BlockQuote => (),
+                    ItemBody::ListItem(indent) if self.begin_list_item.is_some() => {
+                        self.last_line_blank = true;
+                        // This is a blank list item.
+                        // While the list itself can be continued no matter how many blank lines
+                        // there are between this one and the next one, it cannot nest anything
+                        // else, so its indentation should not be subtracted from the line start.
+                        *indent = 0;
+                    },
                     _ => {
                         self.last_line_blank = true;
                     }


Test patch:
diff --git a/tests/suite/regression.rs b/tests/suite/regression.rs
index dd95415..dce6df2 100644
--- a/tests/suite/regression.rs
+++ b/tests/suite/regression.rs
@@ -1782,3 +1782,61 @@ _*xx-_-
 
     test_markdown_html(original, expected, false, false, false);
 }
+
+#[test]
+fn regression_test_117() {
+    let original = r##"-
+
+	-
+
+
+- x
+
+	-
+"##;
+    let expected = r##"<ul>
+<li></li>
+</ul>
+<pre><code>-
+</code></pre>
+<ul>
+<li>
+<p>x</p>
+<ul>
+<li></li>
+</ul>
+</li>
+</ul>
+"##;
+
+    test_markdown_html(original, expected, false, false, false);
+}
+
+#[test]
+fn regression_test_118() {
+    let original = r##"-
+
+    -
+
+
+- x
+
+    -
+"##;
+    let expected = r##"<ul>
+<li></li>
+</ul>
+<pre><code>-
+</code></pre>
+<ul>
+<li>
+<p>x</p>
+<ul>
+<li></li>
+</ul>
+</li>
+</ul>
+"##;
+
+    test_markdown_html(original, expected, false, false, false);
+}