Repository navigation
Conversation
Port markdown-it #1074 (released in 14.2.0): block content is trimmed with ASCII whitespace only, so Unicode spaces such as U+00A0 and U+3000, which are content per CommonMark, are no longer dropped from headings, setext headings and paragraphs.
This branch has not been deployed
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.
Port of markdown-it #1074 (released in markdown-it 14.2.0): non-ASCII whitespace at the edges of block content is content, not trimming.
What is wrong
The block rules (
heading,lheading,paragraph) trim withmdTrim, whose character set includes U+00A0 and the U+2000-U+200A and U+3000 space characters. CommonMark only treats ASCII whitespace as trimmable there, so"# h\u00a0"currently renders as<h1>h</h1>, while markdown-it 15.0.3 renders<h1>h\u00a0</h1>. The same loss happens in setext headings and paragraphs.Fix
Add the upstream ASCII-only
asciiTrimtomarkdown_it/common/utils.pyand use it in those three block rules.mdTrimis left in place where upstream fully trims (table cells, fence info strings), so this PR does not change those behaviours.Tests
tests/test_port/test_whitespace.pyfor U+00A0 and U+3000 preserved in headings and paragraphs, plus the upstream-#1074 fixture case.Evidence on base
d504583with the new tests applied and the four source files reverted:pytest tests/test_port/test_whitespace.py -q->3 failed, 15 passed:test_non_ascii_whitespace_is_preserved_in_blocks[\xa0],[\u3000]andtest_non_ascii_trim_matches_upstream_fixture.18 passed; fullpytest tests -q->1160 passed, 33 skipped;ruff check/ruff format --checkclean;mypy->Success: no issues found in 66 source files.Signed-off-by: simpleqt 2015900818@qq.com