Skip to content

fix(tocObj): extract semantic math text - #448

Open
stevenjoezhang wants to merge 1 commit into
masterfrom
agent/fix-katex-toc-text
Open

fix(tocObj): extract semantic math text#448
stevenjoezhang wants to merge 1 commit into
masterfrom
agent/fix-katex-toc-text

Conversation

@stevenjoezhang

Copy link
Copy Markdown
Member

check list

  • Add test cases for the changes.
  • Passed the CI test.

Description

Fixes duplicate or incorrect TOC text when headings contain math rendered by KaTeX or other MathML-based renderers.

KaTeX outputs both an accessible MathML representation and a visual HTML representation. DomUtils.textContent() concatenated both branches, causing formulas to appear multiple times in generated TOC entries.

This change adds semantic text extraction that:

  • ignores elements marked with aria-hidden="true" or hidden
  • prefers the TeX annotation inside MathML <semantics>
  • falls back to the presentation MathML branch when no TeX annotation exists
  • preserves the existing permalink filtering behavior

No additional math-rendering dependency is introduced.

Additional information

To test:

  • npm test (260 passing)
  • npm run eslint
  • Hexo integration test with the patched local hexo-util on Node.js 24 (1278 passing, 5 pending)
  • Verified a KaTeX heading such as Energy E=mc^2 appears only once in the generated TOC

Fixes #447

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TOC helper with Katex not works well

1 participant