tidy-markdown
tidy-markdown copied to clipboard
Nested lists add redundant new lines
I've got a nested list that looks something like
- foo
- bar
- baz
- fizz
- buzz
- qux
This gets formatted into a list that looks like
- foo
- bar
- baz
- fizz
- buzz
- qux
This turns what should be one list with two nested lists in it into two separate lists that contain one nested list each. This means that the list gets annoying breaks in it and doesn't read very nicely. But really, it means that anything processing a document created from this will have two separate lists instead of one which would be incorrect.
When I compile the code samples you give (with marked) I get these:
<ul>
<li>foo</li>
<li>
<p>bar</p>
<ul>
<li>baz</li>
<li>fizz</li>
</ul>
</li>
<li>
<p>buzz</p>
<ul>
<li>qux</li>
</ul>
</li>
</ul>
<ul>
<li>foo</li>
<li>bar
<ul>
<li>baz</li>
<li>fizz</li>
</ul>
</li>
<li>buzz
<ul>
<li>qux</li>
</ul>
</li>
</ul>
...so I can't reproduce the "will have two separate lists instead of one" part. Though the removal of the <p> tags around buzz & bar is a little strange, and I'd love to know why that happens.
As for the line following the end of the list: that's a rule from https://github.com/carrot/markdown-styleguide#lists ... If you have a use-case for changing it, then I'd be happy to look into it.
Well, if it's part of the styleguide, then I guess it doesn't really matter what I think. But I was thinking of stuff like the table of contents in a document.
If stuff gets split up a lot, like having some items being in a row, and others being parts of a separate list, then it might not be nice to parse out into a tree, or might just look strange.
The specific use case I had that brought this up is having a list of steps to take, and I had sublists representing branches in what to do (if this then do these).
I think the issue is that some stylesheets give the <p> a margin-bottom and so the two examples don't end up looking the same in the end.
This was bothering me as well.
Here is the similar issue I've encountered:
$ cat > test1.md
- Foo1
- Foo2
- Bar1
- Bar2
- Foo3
$ tidy-markdown < test1.md
- Foo1
- Foo2
- Bar1
- Bar2
- Foo3
$ tidy-markdown --version
2.0.3
$ markdownfmt < test1.md
- Foo1
- Foo2
- Bar1
- Bar2
- Foo3
$
It seems this does agree with the style guide, but I guess I don't agree with the style guide in that case, since (1) for long nested lists, it looks rather arbitrary to have the extra newlines; and more critically (2) many formatters behave differently after the newlines are added. See below for GitHub's behavior before and after tidying.
I'm currently using markdownfmt instead, which does not insert the extra newlines (though one certainly might argue about the tabs — but that's yet a different issue 😉 ). Thanks!
- Foo1
- Foo2
- Bar1
- Bar2
- Foo
- Foo1
- Foo2
- Bar1
- Bar2
- Foo3