Skip to content

fix: keep line breaks out of inline code spans - #303

Open
Chandan3456 wants to merge 1 commit into
matthewwithanm:developfrom
Chandan3456:code-span-line-breaks
Open

Chandan3456 wants to merge 1 commit into
matthewwithanm:developfrom
Chandan3456:code-span-line-breaks

Conversation

@Chandan3456

Copy link
Copy Markdown
Contributor

With escape_misc=True:

>>> md('<p>Run <code>ls\n&lt;script&gt;alert(1)&lt;/script&gt;</code> now</p>', escape_misc=True)
'Run `ls\n<script>alert(1)</script>` now'

markdown-it, commonmark.py and mistune all render that as <p>Run ls

followed by a live<script> element. Code text is intentionally left unescaped, but CommonMark parses block structure before inline content, so when the span crosses a line break the next line can start an HTML block, heading (# ) or blockquote (> ) before the closing backtick is seen. Same for and, and for
inside`.

convert_code now turns line breaks into spaces. CommonMark already renders line endings inside a code span as spaces, so spans that parsed correctly before render the same; the <br> expectation in test_code_with_tricky_content changes text but renders identically in all three parsers.

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