Skip to content

fix hard line break round-trip in commonmark renderer - #639

Merged
jgm merged 1 commit into
commonmark:masterfrom
zayeem06:hardbreak-roundtrip
Oct 14, 2026
Merged

jgm merged 1 commit into
commonmark:masterfrom
zayeem06:hardbreak-roundtrip

Conversation

@zayeem06

Copy link
Copy Markdown
Contributor

The commonmark renderer writes hard line breaks as two trailing spaces, but those are only recognized as a hard break when they follow other text on the line. When a hard break begins a line (a leading \ break, or one right after a soft break) or comes after a space, the spaces are stripped as insignificant trailing whitespace and the break, along with any preceding space, is lost when the output is parsed again. This emits a backslash line break in those positions and keeps the two-space form everywhere else; the new api_test cases cover the three positions and the roundtrip tests exercise it end to end.

@jgm

jgm commented Oct 13, 2026

Copy link
Copy Markdown
Member

I'd prefer just to emit the backslash everywhere for hard breaks.

@zayeem06
zayeem06 force-pushed the hardbreak-roundtrip branch from 7122c72 to 7f2f7f8 Compare October 14, 2026 05:59
@zayeem06

Copy link
Copy Markdown
Contributor Author

Makes sense, that's simpler. Updated it to always emit the backslash break and dropped the positional check; tests still pass.

@jgm
jgm merged commit ee05faf into commonmark:master Oct 14, 2026
15 checks passed
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.

2 participants