Skip to content

fix(web): preserve math before citation linkification#540

Merged
pancacake merged 1 commit into
HKUDS:devfrom
thakrarsagar:fix/math-citation-rendering
Jun 14, 2026
Merged

fix(web): preserve math before citation linkification#540
pancacake merged 1 commit into
HKUDS:devfrom
thakrarsagar:fix/math-citation-rendering

Conversation

@thakrarsagar

@thakrarsagar thakrarsagar commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a markdown rendering regression where numeric arrays inside LaTeX math were treated as citations before KaTeX rendered them.

The citation normalizer already protected fenced and inline code, but it did not protect math spans. As a result, vectors such as [1, 1, 2] inside \[...\] were rewritten into reference links first. KaTeX then received markdown link syntax inside math and displayed a red parse error instead of the formula.

This change masks display and inline math spans before citation linkification, then restores them afterward. Citation links outside math still behave the same way.

Related Issues

N/A (no existing issue found)

Module(s) Affected

  • agents
  • api
  • config
  • core
  • knowledge
  • logging
  • services
  • tools
  • utils
  • web (Frontend)
  • docs (Documentation)
  • scripts
  • tests
  • Other: ...

Checklist

  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added relevant tests for my changes.
  • I have updated the documentation (if necessary).
  • My changes do not introduce any new security vulnerabilities.

Additional Notes

Root cause: normalizeMarkdownForDisplay() ran citation linkification before math rendering while protecting code spans only. Numeric vectors and weighted expressions are valid math content, but they also match the citation-link pattern.

Validation:

  • npm run test:node — 108 passed
  • npm run build — passed
  • uv run --with pre-commit pre-commit run --files web/lib/markdown-display.ts web/tests/markdown-display.test.ts — passed
  • pre-commit run --all-files was attempted via uv run --with pre-commit pre-commit run --all-files; it failed because hooks reformatted 34 unrelated files already present on the dev base (end-of-file-fixer, ruff-format, and prettier). Those unrelated hook changes were not included in this PR.

@thakrarsagar
thakrarsagar force-pushed the fix/math-citation-rendering branch from a4b7225 to a38a644 Compare June 2, 2026 19:41
@thakrarsagar
thakrarsagar marked this pull request as ready for review June 2, 2026 19:45
@pancacake
pancacake merged commit 2c8a94e into HKUDS:dev Jun 14, 2026
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.

2 participants