Skip to content

feat: add raw HTML math rendering plugin to Streamdown#464

Merged
chenyme merged 1 commit into
devfrom
latex_html
Jul 10, 2026
Merged

feat: add raw HTML math rendering plugin to Streamdown#464
chenyme merged 1 commit into
devfrom
latex_html

Conversation

@chenyme

@chenyme chenyme commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix LaTeX formulas appearing as raw source inside visual HTML/card layouts.

Math inside raw HTML was not processed by remark-math because raw HTML is parsed later in the rendering pipeline. Add a focused rehype preprocessor that converts $...$ and $$...$$ within raw HTML text into KaTeX-compatible nodes before rehype-raw runs.

Code, preformatted content, scripts, styles, and textareas are excluded. Generated nodes continue through the existing HTML sanitization pipeline.

Change type

  • Bug fix
  • Feature
  • Documentation
  • Refactor
  • Configuration / deployment
  • Security hardening
  • Other

Affected areas

  • Frontend / UI
  • Backend / API
  • Authentication / authorization
  • Conversations / streaming
  • Files / RAG / extraction
  • Model routing / providers
  • MCP / tools
  • Billing / payments
  • Admin console
  • Deployment / Docker / configuration
  • Documentation

Verification

  • cd frontend && pnpm lint
  • cd frontend && pnpm exec tsc --noEmit
  • git diff --check
  • Rendered the reported HTML/LaTeX examples through Streamdown and KaTeX and confirmed that \mathbb, \frac, \nabla, and (P,Q) produce KaTeX output without raw dollar-delimited source.
  • Build was not run because this is a focused frontend rendering fix.

Screenshots, API examples, or logs

Verified with the reported patterns:

<div>
  <ul>
    <li>适用范围:$\mathbb{R}^2$</li>
    <li>核心对象:$(P,Q)$</li>
    <li>联系量:$\frac{\partial Q}{\partial x}-\frac{\partial P}{\partial y}$</li>
    <li>联系量:$\nabla\times\mathbf{F}$</li>
  </ul>
</div>

All formulas are rendered by KaTeX instead of being displayed as raw LaTeX.

Configuration, migration, and compatibility notes

No configuration, API, database, deployment, or migration changes.

Existing raw HTML sanitization remains enabled. The new preprocessing step only creates language-math nodes already supported by the current KaTeX renderer.

Documentation

  • Documentation is not needed for this change.
  • Documentation was updated.
  • Documentation still needs to be updated.

Security and privacy

  • No secrets, tokens, credentials, local config, or personal data are included.
  • User data access remains scoped by authenticated user context unless an admin-only path explicitly requires broader access.
  • Raw HTML and generated math nodes continue through the existing sanitization and hardening pipeline.

Checklist

  • I searched existing issues and pull requests.
  • Changes are focused and do not include unrelated refactors.
  • Tests or static verification were run where practical.
  • User-facing behavior, deployment steps, API contracts, or configuration changes are documented.
  • Generated artifacts are included only when this project explicitly requires them.
  • Caches, build output, .pyc files, .env files, and local storage data are not committed.

@chenyme chenyme self-assigned this Jul 10, 2026
@chenyme chenyme linked an issue Jul 10, 2026 that may be closed by this pull request
3 tasks
@chenyme
chenyme merged commit 4342e68 into dev Jul 10, 2026
10 checks passed
@chenyme
chenyme deleted the latex_html branch July 10, 2026 15:30
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.

[Bug]: 视觉排版后 HTML 内部的数学公式未正确渲染

1 participant