fix(MD049,MD037): Preserve inline code inside emphasis during auto-fix#652
Merged
rvben merged 1 commit intoJun 2, 2026
Conversation
Both rules detect emphasis on a copy of the line where inline code spans are masked with equal-length runs of 'X' (and inline math with 'M'), so backtick or dollar contents are not mistaken for emphasis markers. The auto-fix then reused the emphasis content taken from that masked copy, so the placeholder characters leaked into the written file and permanently replaced the original inline code. This corrupts content and affects fix/fmt only, not check. Slice the replacement content from the original line at the span's byte offsets instead. Masking is length-preserving, so the offsets stay valid. - MD049: build emphasis content from the original line in collect_emphasis_from_line rather than the masked copy. - MD037: slice the trimmed content from the original line when building the space-fixed replacement. - Add regression tests for inline code inside emphasized spans in both rules (both directions for MD049), asserting no placeholder leakage.
Owner
|
Thanks @thegeorgeliu, for both the clear bug report in #651 and the fix. Nicely scoped, with good regression tests. Merging now; it'll ship in the next patch release. |
Contributor
Author
|
Happy to contribute @rvben! Thanks for all your great work on rumdl, I've been using it for a while now throughout all my personal and work projects! |
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.
Description
To detect emphasis markers reliably,
MD049andMD037first build a throwaway copy of each line with every inline code span replaced by an equal-length sequence ofXcharacters (and inline math byM). This prevents backtick or dollar contents from being misread as emphasis markers. The auto-fix, however, reused the emphasis text taken from that masked copy, so theX/Mplaceholders leaked into the written file and permanently replaced the original inline code.The fix takes the replacement text from the original line at the span's byte offsets instead. Because masking replaces each span with a sequence of the same byte length, those offsets remain valid against the original line.
Example before this fix (
rumdl fmtwith MD049style = "asterisk"):- _An item withinline codeinside._- *An item with XXXXXXXXXXXXX inside.*After the fix the inline code is preserved:
- *An item withinline codeinside.*. Onlyfmt/--fixwas affected;checkdoes not modify files.MD050(strong style) was not affected.Type of Change
Testing
cargo nextestfor md049/md037/emphasis/reflow/md013/formatter_idempotency, and fullcargo test --lib(5810 passed)rumdl fmton the repro is now lossless and idempotentChecklist
cargo fmt --checkclean; CI clippy gate-D warnings -D clippy::uninlined_format_argsclean)Closes #651