fix: use split('\n') instead of splitlines() in blockquote renderer#581
Open
gaoflow wants to merge 1 commit into
Open
fix: use split('\n') instead of splitlines() in blockquote renderer#581gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
The blockquote renderer used str.splitlines() to split rendered text
into lines, but splitlines() treats Unicode line separators (form feed
\x0c, vertical tab \x0b, file/group/record separators, NEL \x85,
line/paragraph separator) as line breaks.
CommonMark only recognizes \n, \r\n, and \r as line endings. Other
renderers (paragraph, list_item) correctly use split('\n').
When blockquote content contained Unicode whitespace like form feed,
the renderer would split on it and prepend spurious '> ' markers,
creating semantically different output on the first format pass. The
second pass then normalized this, breaking idempotence.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Blockquote rendering in mdformat is non-idempotent when the content
contains Unicode whitespace characters like form feed (
\x0c),vertical tab (
\x0b), or Unicode line separators.f(f(x)) != f(x)— the first format pass produces semanticallydifferent output from the input. The second pass normalizes it.
Minimal reproduction:
Root cause:
blockquote()in_context.pyusestext.splitlines()which splits on Unicode line separators thatCommonMark does not recognize. The other renderers (
paragraph,list_item) correctly usetext.split("\n").Fix (+1/-1):
text.splitlines()→text.split("\n")— bringsblockquote in line with paragraph and list_item.
4282/4282 tests pass (5 skipped pre-existing).
211/211 idempotence fuzz tests pass.
This pull request was prepared with the assistance of AI, under my
direction and review.