Skip to content

Skip the leading spaces of a lazy continuation line - #634

Open
yuxi-liu-wired wants to merge 1 commit into
commonmark:masterfrom
yuxi-liu-wired:fix/lazy-line-leading-space
Open

yuxi-liu-wired wants to merge 1 commit into
commonmark:masterfrom
yuxi-liu-wired:fix/lazy-line-leading-space

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown

The leading spaces and tabs of a paragraph line are not part of the paragraph's raw content (spec 4.8, "Paragraphs"), and cmark skips them for a normal continuation line. A lazy continuation line was added from the current offset instead, so its leading whitespace stayed in the content. Mostly that is invisible, since inline parsing strips it again after a soft break, but in a code span the line ending turns into a space and the extra space stays:

> `a
 b`

- `c
 d`

cmark renders <code>a b</code> and <code>c d</code> (two spaces). commonmark.js (and pulldown-cmark) give <code>a b</code> and <code>c d</code>, the same as without the container (`a\n b` gives <code>a b</code> in cmark too).

The fix advances past the leading whitespace before adding the lazy line, as the non-lazy paragraph path already does.

Test: a new example in test/regression.txt, after the indented-continuation (Springfield) example. It fails on master and passes with the change. Spec 652/652, pathological 25/25.

Found by differential fuzzing of pulldown-cmark against cmark, with commonmark.js as tie-breaker.

A paragraph line's leading spaces and tabs are not part of the
paragraph's raw content (spec 4.8), and cmark skips them for a normal
continuation line. A lazy continuation line was added from the current
offset instead, so its leading space stayed in the content. That shows
in a code span, where the line ending becomes a space:

    > `a
     b`

rendered `<code>a  b</code>` (two spaces); commonmark.js gives
`<code>a b</code>`. The same in a list item (`- \`c\n d\``).

Advance past the leading whitespace before adding the lazy line, as the
non-lazy paragraph path does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant