Repository navigation
fix(muya): keep an inline raw HTML tag's id intact - #5416
Merged
Merged
Conversation
The inline raw HTML renderer put the tag's id into the snabbdom selector (`a.mu-inline-rule.mu-raw-html#<id>`). The selector parser used by snabbdom-to-html ends an id at any character outside [A-Za-z0-9_:-], so `<a id="v1.2">` rendered as `id="v1"` with a stray `2` class, and ids with `/`, `#` or a space were truncated the same way. A `[link](#v1.2)` then found nothing with getElementById and did not scroll. Set the id through `attrs`, as the footnote reference now does (marktext#5285), so it is written verbatim and escaped.
Member
|
Please open bug issue before submit a FIX PR. |
Closed
1 task done
Contributor
Author
|
Fair point, a ticket gives the bug a place to live on its own. I opened #5419 with the bug report form and linked it from this PR's description with Before filing it, I re-ran the regression test against the current Found by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5. |
Reference marktext#5419 in the describe title instead, like the sibling specs. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Fixes #5419
Summary
I wrote
<a id="v1.2"></a>in a paragraph and a[see below](#v1.2)link elsewhere, and clicking the link did nothing. The rendered anchor was<a id="v1" class="mu-inline-rule mu-raw-html 2">.The inline raw HTML renderer (
packages/muya/src/inlineRenderer/renderer/htmlTag.ts) appended the tag's id to the snabbdom selector,a.mu-inline-rule.mu-raw-html#<id>. That string goes throughtoHTML, and snabbdom-to-html's selector parser (parse-sel) ends an id at any character outside[A-Za-z0-9_:-]. Sov1.2became idv1plus a2class, and ids with/,#or a space were cut the same way.SCROLL_TO_ANCHORfalls back togetElementById(anchorSlug)for non-heading targets, so it no longer found the element.The fix sets the id through
data.attrs, the same move #5285 made for footnote reference ids. snabbdom-to-html writes anattrs.idover the selector's id and escapes it, so the value comes out verbatim. The tag's classes still go through the selector, so nothing else changes.Type of change
Test plan
packages/muya/src/inlineRenderer/__tests__/rawHtmlId.spec.tsboots a Muya under jsdom and checks the rendered element. The cases are idsv1.2,api/usage,a#bandnote 1(each kept verbatim and found bygetElementById), no stray class from the id, and an"in an id that stays inside the attribute.On
developat 5734f01, with only the test applied, all 6 cases fail (for exampleexpected 'v1' to be 'v1.2'). With the fix they pass. The full muya suite gives 1791 passed and 1 failed. The failure istableChessboard.spec.ts > is exported from the package entrypoint, which fails the same way without this change and passes when run alone.tsc --noEmit -p packages/muya/tsconfig.jsonand eslint on the two files are clean.Notes for reviewers [optional]
Class names go through the same parser, so a class like
w-1/2is still truncated. I left that out on purpose: snabbdom-to-html's class module doesn't escapedata.classkeys, so moving classes there would need its own handling.By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.
Found by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5.