Skip to content

Escape \r similarly to \n. - #489

Open
cpovirk wants to merge 1 commit into
commonmark:mainfrom
cpovirk:backslash-r
Open

cpovirk wants to merge 1 commit into
commonmark:mainfrom
cpovirk:backslash-r

Conversation

@cpovirk

@cpovirk cpovirk commented Dec 4, 2026

Copy link
Copy Markdown

For \n, MarkdownWriter and CoreMarkdownNodeRenderer already escape it as 
. This allows literal newlines (decoded from 
) to round-trip instead of turning into line breaks.

\r (which can appear decoded from 
) was not handled the same way. Because CommonMark treats \r as a line ending, inputs like foo

bar or [link](/url "test

") emitted raw \r\r and broke into multiple paragraphs on re-parse.

For `\n`, `MarkdownWriter` and `CoreMarkdownNodeRenderer` already escape it as `&commonmark#10;`. This allows literal newlines (decoded from `&commonmark#10;`) to round-trip instead of turning into line breaks.

`\r` (which can appear decoded from `&commonmark#13;`) was not handled the same way. Because CommonMark treats `\r` as a line ending, inputs like `foo&commonmark#13;&commonmark#13;bar` or `[link](/url "test&commonmark#13;&commonmark#13;")` emitted raw `\r\r` and broke into multiple paragraphs on re-parse.

This branch has not been deployed

No deployments
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