showdown
showdown copied to clipboard
List with an empty item becomes nested
- one
-
- three
is being rendered as a nested list:
<li>one</li>
<li>
<ul>
<li>three</li>
</ul>
</li>
instead of three li
s with the middle one being empty.
Here is the example in the GFM spec: https://github.github.com/gfm/#example-252
Related: #375
Shwodown doesn't currently support empty list items, but will probably support in version 2.0
As a workaround until there's a supported fix, I've implemented the following extension to remove any empty list items:
export const removeEmptyListItems = () => {
return [{
type: "lang",
regex: /( {0,3}([*+-]|\d+[.])[ \t]+)(?![^\n]+?)/gm,
replace: "",
}]
};
This will trim something like this
1.
2. two
3.
to
2. two
EDIT: Here's another option if preserving the empty list item is the intention without screwing up styles
export const emptyListItems = () => {
return [{
type: "lang",
filter: function(text) {
return text.replace(/( {0,3}([*+-]|\d+[.])[ \t]+)(?![^\n]+?)/gm, "$& ");;
}
}]
};