showdown
showdown copied to clipboard
an issue about sublists rendering
The version I use is 1.6.4
, I set disableForced4SpacesIndentedSublists
to true
, and I use '2 spaces' as indentation of sublists, the markdown code is
- zzzz
- xxxx
- cccc
but the HTML i got is:
<ul>
<li>zzzz
<ul>
<li>xxxx</li>
<li>cccc</li>
</ul>
</li>
</ul>
In the html above, xxxx
and cccc
are sibling nodes.
So is it a bug or just a misuse ?
It's a bug:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
marked compiler:
<ul>
<li>1
<ul>
<li>2
<ul>
<li>3
<ul>
<li>4
<ul>
<li>5
<ul>
<li>6
<ul>
<li>7
<ul>
<li>8
<ul>
<li>8</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
showdown compiler:
<ul>
<li>1
<ul>
<li>2</li>
<li>3
<ul>
<li>4</li>
<li>5
<ul>
<li>6</li>
<li>7
<ul>
<li>8</li>
<li>9</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
Well, the original spec states that, in lists, sub-blocks must be indented 4 spaces (a sub-list is a sub-block). But that was miss implemented in showdown's original version. The rule we used was that sub-lists required 3 spaces indentation.
We fixed the bug but created the option disableForced4SpacesIndentedSublists
for backward compatibility for people upgrading versions. The option is not meant to be used in "production" and we can't really fix it as it would defeat the purpose of backwards compatibility.
Check the demo:
@tivie I think lots of people are using just 2 spaces for nested lists on GitHub readmes for example.
I'm fine with using disableForced4SpacesIndentedSublists
because this is exactly what I want and this is the behavior that works in every website or implementation that I can think of.
But the problem with this option is that it's not consistent:
- ul
- ul - using 2 spaces indents properly
- ul - should use 3 or 4 spaces to indent properly
- ul - should use 4 spaces to indent properly
- ul - again 4 spaces, and so on
I think there can be just another option, like enable2SpacesIndentedSublists
.
I will have a look and think in a way of making this work with 2 spaces and not break past behavior.
Meanwhile, check the comparison of implementations
2 space indentation is quite useful for many people like me I'm coding with 2 space indentation and I also want markdown to be 2 space too
This issue is quite complex because how other sub blocks behave. For instance, it becomes quite problematic with sublists which have a code sub-block:
input
- this is indented 1 space
- this is indented 4 spaces
code needs 10 spaces indentation. Why?
- this is indented 5 spaces
code needs 11 spaces indentation. Why?
- this is indented 6 spaces
code needs 12 spaces indentation
- this is indented 7 spaces (why is it level 2)
code needs 13 spaces indentation
- this is indented 8 spaces (why is it still level 2)
code needs 14 spaces indentation
- this is indented 9 spaces (why is it still level 2)
code needs 15 spaces indentation
result
- this is indented 1 space
-
this is indented 4 spaces
code needs 10 spaces indentation. Why?
-
this is indented 5 spaces
code needs 11 spaces indentation. Why?
-
this is indented 6 spaces
code needs 12 spaces indentation
- this is indented 7 spaces (why is it level 2) code needs 13 spaces indentation - this is indented 8 spaces (why is it still level 2) code needs 14 spaces indentation - this is indented 9 spaces (why is it still level 2) code needs 15 spaces indentation
-
As you see, even github gets this wrong. Showdown, on the other hand, always behaves consistently (when disableForced4SpacesIndentedSublists
is off). (see the demo)
That being said, I have a partial fix, but still haven't had the time to properly address all the issues regarding this.
I would say 2 spaces is becoming the norm, despite was is supported or not. In the wild, there are a lot of projects (if not most, that I see) using 2 space indentation in their editors and markdown files. Another driving need for this is the wide adoption of Prettier in the community. It formatts markdown files too, often normalizing indentation from 3/4 to 2.
I would call this a need. Is there anything I can do to help? I would love to flip that disableForced4SpacesIndentedSublists
switch and have all be well in the world :)
This is broken for us too, the following:
- foo
- bar
- baz
- qux
gets rendered as:
![screen shot 2019-01-30 at 02 32 08](https://user-images.githubusercontent.com/1812093/51952053-40c58b00-2437-11e9-881f-a2d4a9d484b9.png)
@tivie I'd like to submit a PR for this, would it be considered? If so, can you point me at the right section of the code? I'm not very familiar with the codebase.