{{ message }}
Repository navigation
fix(desktop): keep $ patterns in headings out of the exported TOC - #5742
Merged
Merged
Conversation
exportStyledHTML spliced the generated TOC into the article with a string replacement, so $$, $&, $` and $' in a heading were read as replacement patterns: "US$$" became "US$" and "Bob$'s notes" pulled the rest of the document into the TOC entry. Pass the TOC through a replacer function, as the <body> splice below already does since marktext#5701.
Jocs
approved these changes
Oct 14, 2026
Member
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.

Closes #5741
Summary
When a document with
[TOC]is exported to styled HTML, PDF or print,exportStyledHTMLsplices the generated TOC into the article witharticle.replace(regex, toc). Becausetocis a replacement string,$patterns in heading text are expanded:## Pay in US$$ onlyends up asPay in US$ onlyin the TOC,## A$&BasA<p>[TOC]</p>amp;B, and## Bob$'s notespulls the whole rest of the article into the TOC link, so the body appears twice in the export.The fix passes the TOC through a replacer function (
() => toc) in both branches, the same way the<body>splice at the end of the function already does since #5701.Type of change
Test plan
test/unit/specs/exportHtmlTocDollar.spec.tsboots a real Muya and runs the same steps as the editor'shandleExport:getHtmlToc(muya.getTOC()), thenexportStyledHTML(muya, muya.getMarkdown(), { toc }). It checks the TOC entry for headings containing$$,$',$&and$`. Before the fix all 4 cases fail with the outputs above; after it they pass, andexportHtml.spec.tsstill passes (25/25 across both files). I put the test in its own file because #5732 is editingexportHtml.spec.ts.Found by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5.5.
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.