Nested Markdown list renders as code block in one renderer, nested list in another
0 reputation · 09 Jul 2023, 06:16 UTC
0 reputation · 09 Jul 2023, 06:16 UTC
I maintain documentation that must render correctly in more than one Markdown toolchain, and nested lists are the sticking point. The same source — a - a item with a - b child indented two spaces — can produce a nested ul, a flattened continuation paragraph, or an indented pre/code block depending on the renderer, with no error reported in any of them.
My understanding is that CommonMark measures a list item's content column relative to its marker (so two-space nesting works), while renderers following older Markdown.pl conventions, such as Python-Markdown's default behavior, historically expect four-space indentation. GFM builds on CommonMark, so GitHub-style renderers accept the two-space form. I also assume tabs are unreliable here because tab-stop handling differs across parsers.
What I cannot resolve is a portable authoring rule I can enforce across contributors without knowing every downstream renderer, and how much I can trust a parser that merely claims "CommonMark conformance" when spec revisions (the 0.27–0.31 line) have tightened list rules over time.
Is four-space indentation of nested items actually sufficient and safe across CommonMark, GFM, and Markdown.pl-style renderers, or are there documented cases where it still diverges?
When a pinned parser and a current parser both claim CommonMark conformance, what is the practical way to confirm which list-indentation behavior my toolchain implements — is comparing output in a reference dingus or Babelmark considered authoritative?
32275 reputation · 09 Jul 2023, 09:39 UTC
Four‑space indentation of a nested list item is sufficient and safe across CommonMark (spec 0.27+), GitHub Flavored Markdown (GFM), and legacy Markdown.pl‑style renderers. It will produce a nested ul in all of them and will not be mistaken for a code block or flattened paragraph.
CommonMark defines the content column of a list item as the column after the marker plus any optional spaces. A nested list is recognised when its marker starts at least two spaces after the parent marker. Therefore both two‑space and four‑space indentation satisfy the rule. Older Markdown.pl implementations, however, historically required four spaces (or a tab) to start a new list level; with fewer than four spaces the inner marker was treated as plain text, often resulting in a flattened paragraph or, if the line began with a backtick, an unintended code block. GFM follows CommonMark, so it accepts both two‑space and four‑space forms.
Use exactly four spaces (no tabs) before the marker of any nested list item. This satisfies the strictest legacy rule while remaining well within the CommonMark/GFM minimum.
- a
- b
- c
- d
cmark)github-markdown)markdown.markdown)- b and - c should appear as nested <ul> items, not as plain text or inside a <pre><code> block.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.