List line spacing is crazy

List line spacing is crazy. When there is an empty line separator to split unordered list in two, Commonmark for some reason adds spacing between more items. Look at the bottom of those two links. First is without empty lines between some (not all) list items. Second is with them.

* 1
* 2
* 3`
  • 1
  • 2
  • 3

* 1
* 2
* 3

* 4
  • 1

  • 2

  • 3

  • 4

This appears to be a bug in Discourse, rather than in CommonMark.

The dingus doesn’t appear to present this issue when a loose list is used.

The issue is still there. Is it what you call a “loose list”? Why it is a feature?*%203%0A%0A*%204*%203%0A*%204

it’s not my term, and I’ve already linked to the part of the spec that defines this behavior, but I’ll add it here anyway:

A list is loose if any of its constituent list items are separated by blank lines, or if any of its constituent list items directly contain two block-level elements with a blank line between them. Otherwise a list is tight. (The difference in HTML output is that paragraphs in a loose list are wrapped in <p> tags, while paragraphs in a tight list are not.)

The spec then goes on to define the exact behavior that the dingus produces.

As for your second question:

I don’t know, I didn’t write the spec, and I only gave this section a cursory glance to point you in the right direction. I would recommend that you invest some of your own time to read it, and then ask questions for further clarification.

This isn’t a CommonMark quirk. All Markdown implementations I know of create a single list with this input:*+3%0A%0A*+4%0A

Currently in CommonMark you can separate two lists with two blank lines (though we may remove that feature). In all Markdown implementations you can use a blank HTML comment to separate two lists.

An alternative spec would disallow a mix of tight and loose list spacing. So, if a list starts out “tight,” then when a blank line is encountered, the list ends and you have a new list. I think I even considered this and we discussed it in the early days, but I don’t recall all of the considerations.

Feel free to discuss this here. The spec isn’t set in stone yet.

1 Like

My biggest complain appears to be about <p> insertion, not about single list. Most of the implementations get this almost right for me:*+3%0A%0A*+4%0A


But commonmark inserts <p> for every element if at least one of the items needs a block. That is the thing I hated about reStructuredText. You have a nice CSS for ul li rule, but everything is ruined when one list item needs more text or code block inserted - then all other list items lose formatting. And this “scope violation” is a bug or misfeature for me.

Mixed tight and loose lists are typographically bad.

Note also that CommonMark is not HTML-centric. We want to support output in LaTeX, for example. In LaTeX there isn’t a clean way to get a mixed tight/loose list. You adjust inter-item spacing for the whole list.

I am not mixing them. Need tight lists only, always, with occasional code sections, pictures etc. If I need different styling, I would use stylesheets, but it is impossible to style output markup when this markup is not consistent.

Why don’t you give an example of a realistic case that you don’t think CommonMark handles well? It is possible, currently, to have tight lists that contain code blocks, pictures, etc.



What do you want the output to look like in the last example? It seems to me that what you want is three separate unordered lists, all “tight.” I don’t think it makes much typographic sense to have a single list in which some items are tight and some loose.

Three consecutive tight lists can be achieved, with current CommonMark, by putting two blank lines (rather than one) between the lists.