TomCrypto / lanius

Markdown Viewer
Other
4 stars 1 forks source link

List elements should try to respect paragraph spacing #5

Open TomCrypto opened 9 years ago

TomCrypto commented 9 years ago

At the moment lanius renders the two markdown fragments below identically:

- item1
- item2
-item1

-item2

The expected behaviour, indeed followed by most markdown renderers, is to render the first fragment as two list items close to one another:

and render the second fragment as two list items separated by some spacing:

Internally the two fragments are parsed into HTML as follows:

<ul>
<li>item1</li>
<li>item2</li>
</ul>
<ul>
<li>
<p>item1</p>
</li>
<li>
<p>item2</p>
</li>
</ul>

The simplest way would probably be to get li to emit an extra blank line if its last child is a paragraph, but a long-term solution would be to rework spacing between sibling elements (at the moment we insert empty lines based on some arbitrary and frankly rather broken heuristics). HTML doesn't seem so well-behaved when you look at it that closely so it's a bit tricky getting all the cases right, but I think it can be done.

TomCrypto commented 9 years ago

After some thought I feel the most logical way to tackle this is to have the ul and ol elements emit an empty line after an li element if that element contains at least one non-inline element such as p. Thinking about #6 though, whether to do this should probably be left up to the theme, perhaps the renderer should simply advise that there should not be spacing between such and such elements.

It all depends if the renderer should decide how individual blocks are rendered relative to one another and the theme only handles how to render the contents of the blocks themselves or if we want something more complex.