fix: re-fence code spans with inner backticks in MarkdownRenderer#457
Closed
sarathfrancis90 wants to merge 1 commit into
Closed
fix: re-fence code spans with inner backticks in MarkdownRenderer#457sarathfrancis90 wants to merge 1 commit into
sarathfrancis90 wants to merge 1 commit into
Conversation
MarkdownRenderer.codespan always wrapped the content in a single backtick, so reformatting any code span that contained a backtick (or was padded with spaces) changed its meaning on re-parse, e.g. ``a`b`` became `a`b`. Fence with one more backtick than the longest inner run, and pad with a space when the content starts or ends with a backtick so it survives the code-span space-stripping rule.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #457 +/- ##
==========================================
+ Coverage 91.01% 91.03% +0.01%
==========================================
Files 34 34
Lines 3395 3401 +6
Branches 670 672 +2
==========================================
+ Hits 3090 3096 +6
Misses 184 184
Partials 121 121
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Owner
|
Is it the same as #450 ? |
Contributor
Author
|
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.



While reformatting Markdown with
MarkdownRendererI noticed inline code spans get mangled when their content contains a backtick.codespanalways wraps the content in a single backtick, soab`` `` comes back as ``aband re-parses to `<code>a</code>binstead of<code>ab. The same thing happens to content padded with spaces (``x`` drops a space on each side) and to a lone backtick (`` ``turns into a code fence).I changed
codespanto fence with one more backtick than the longest run inside the content, and to pad with a space when the content starts or ends with a backtick so it survives the code-span space-stripping rule on re-parse.Added round-trip cases to
TestMarkdownRendererRoundTrip. Verified withpytest,mypy --strict srcandmypy src tests; I also fuzzed random code spans through reformat then HTML against the originals and they match.