Skip to content

fix(math,lint): keep formulas through Comark's security plugin, and lint display math clean - #449

Merged
vite-hub[bot] merged 6 commits into
mainfrom
fix/math-security-lint
Nov 17, 2026
Merged

vite-hub[bot] merged 6 commits into
mainfrom
fix/math-security-lint

Conversation

@onmax

@onmax onmax commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

With Comark's security plugin, every formula renders as its TeX in monospace. comark-mathml passed the typeset MathML to the renderers in an html prop. security drops every *html prop as a markup sink, so the formula reaches the renderer with only its tex. The getting-started guide recommends security({ allowedTags: [...tags, ...Object.keys(components)] }), so any host that follows it loses its math. Drop runs this setup and hits it.

This PR puts the MathML in the tree as the formula's children. security checks those elements and their attributes like the rest of the document, and comarkUi().tags lists them: Temml's elements, plus KaTeX's span/svg ones when output isn't "mathml". comark-mathml exports them as MATHML_TAGS and KATEX_TAGS for hosts that don't use the preset. The HTML renderer writes the MathML without the indentation Comark adds to elements it doesn't know, so the output matches the old markup. The Vue, React and Svelte components render their children. A formula a document writes itself loses its content, the same way it already lost its html.

In Svelte, a typeset formula carries typeset: true, because @comark/svelte always passes a children snippet. @comark/svelte also creates every element with <svelte:element>, which gives MathML the HTML namespace in the browser. So a formula mounted on the client is parsed again into a MathML copy, shown in place of Svelte's own and kept in sync. Server HTML already parses as MathML. The real fix is an xmlns in @comark/svelte: comarkdown/comark#602. Once that's released, the copy can go.

It also fixes comark-linter. It counted the block that comark-mathml makes from $$ and math fences as an authored component. A host that lints with its own component list, as Drop does before publishing, rejected display math as ::comark-mathml-2` is not a known component. The linter now checks a block only when its line writes :name.

The new tests fail on main and pass here, including e2e/math-svelte.e2e.ts, which mounts and updates a doc in Chromium. The math, lint and ui suites, tsrs --noEmit, and doctor for both packages pass.

Drop moves onto this build in vite-hub/drop#218. Evidence from Drop: https://drop.vitehub.dev/d/ytyz8f3ce9sw/before-after

Breaking for anyone who reads a formula's html attribute directly, since it's no longer set.

🤖 Generated with Claude Code

onmax and others added 2 commits November 17, 2026 10:17
…int display math clean

comark-mathml carried each formula's MathML in an `html` prop. Comark's security plugin removes every
`*html` prop as a markup sink, so with `security({ allowedTags })`, the setup the docs recommend, every
formula fell back to its TeX. The MathML now reaches the renderers as the formula's children, elements
that security checks one by one, and `comarkUi().tags` lists them. A formula a document writes itself
loses its content, as its `html` already did.

comark-linter counted the block comark-mathml makes from `$$` and math fences as an authored component,
so a host that lints with its components refused display math as `::comark-mathml-2`. Only a block whose
line writes `:name` is checked now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-17T09:19:03.929196Z
We couldn’t complete this review. Comment @codex review to try again.
6a84713 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@pkg-pr-new

pkg-pr-new Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

comark-annotate

pnpm add https://pkg.pr.new/comark-annotate@449

comark-badge

pnpm add https://pkg.pr.new/comark-badge@449

comark-bundle

pnpm add https://pkg.pr.new/comark-bundle@449

comark-cards

pnpm add https://pkg.pr.new/comark-cards@449

comark-carousel

pnpm add https://pkg.pr.new/comark-carousel@449

comark-cast

pnpm add https://pkg.pr.new/comark-cast@449

comark-charts

pnpm add https://pkg.pr.new/comark-charts@449

comark-chat

pnpm add https://pkg.pr.new/comark-chat@449

comark-chips

pnpm add https://pkg.pr.new/comark-chips@449

comark-cjk

pnpm add https://pkg.pr.new/comark-cjk@449

comark-code

pnpm add https://pkg.pr.new/comark-code@449

comark-code-notes

pnpm add https://pkg.pr.new/comark-code-notes@449

comark-colors

pnpm add https://pkg.pr.new/comark-colors@449

comark-comments

pnpm add https://pkg.pr.new/comark-comments@449

comark-critic

pnpm add https://pkg.pr.new/comark-critic@449

comark-deflist

pnpm add https://pkg.pr.new/comark-deflist@449

comark-details

pnpm add https://pkg.pr.new/comark-details@449

comark-diagrams

pnpm add https://pkg.pr.new/comark-diagrams@449

comark-diff

pnpm add https://pkg.pr.new/comark-diff@449

comark-embed

pnpm add https://pkg.pr.new/comark-embed@449

comark-fields

pnpm add https://pkg.pr.new/comark-fields@449

comark-figure

pnpm add https://pkg.pr.new/comark-figure@449

comark-file-tree

pnpm add https://pkg.pr.new/comark-file-tree@449

comark-footnotes

pnpm add https://pkg.pr.new/comark-footnotes@449

comark-git-graph

pnpm add https://pkg.pr.new/comark-git-graph@449

comark-github

pnpm add https://pkg.pr.new/comark-github@449

comark-icon

pnpm add https://pkg.pr.new/comark-icon@449

comark-include

pnpm add https://pkg.pr.new/comark-include@449

comark-keys

pnpm add https://pkg.pr.new/comark-keys@449

comark-links

pnpm add https://pkg.pr.new/comark-links@449

comark-linter

pnpm add https://pkg.pr.new/comark-linter@449

comark-magic-move

pnpm add https://pkg.pr.new/comark-magic-move@449

comark-mark

pnpm add https://pkg.pr.new/comark-mark@449

markdown-it-to-comark

pnpm add https://pkg.pr.new/markdown-it-to-comark@449

marked-to-comark

pnpm add https://pkg.pr.new/marked-to-comark@449

comark-mathml

pnpm add https://pkg.pr.new/comark-mathml@449

comark-media

pnpm add https://pkg.pr.new/comark-media@449

comark-metrics

pnpm add https://pkg.pr.new/comark-metrics@449

migrate-to-comark

pnpm add https://pkg.pr.new/migrate-to-comark@449

comark-outline

pnpm add https://pkg.pr.new/comark-outline@449

comark-properties

pnpm add https://pkg.pr.new/comark-properties@449

comark-qr

pnpm add https://pkg.pr.new/comark-qr@449

comark-quiz

pnpm add https://pkg.pr.new/comark-quiz@449

comark-reading-time

pnpm add https://pkg.pr.new/comark-reading-time@449

remark-to-comark

pnpm add https://pkg.pr.new/remark-to-comark@449

comark-sources

pnpm add https://pkg.pr.new/comark-sources@449

comark-steps

pnpm add https://pkg.pr.new/comark-steps@449

comark-table

pnpm add https://pkg.pr.new/comark-table@449

comark-tabs

pnpm add https://pkg.pr.new/comark-tabs@449

comark-tests

pnpm add https://pkg.pr.new/comark-tests@449

comark-time

pnpm add https://pkg.pr.new/comark-time@449

comark-ui

pnpm add https://pkg.pr.new/comark-ui@449

comark-xref

pnpm add https://pkg.pr.new/comark-xref@449

comark-zoom

pnpm add https://pkg.pr.new/comark-zoom@449

commit: c883574

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The security fix works for the covered formulas, but the new rendering path breaks Svelte client math and its TeX fallback, and the lint filter skips authored PascalCase components. Two additional round-trip defects affect formula content.

Reviewed changes across both commits, including the math AST conversion, all renderer entries, security allowlists, and component linting.

  • Formula representation: Typeset markup moves from html into child nodes, with authored formula content rejected.
  • Rendering and security: HTML serializes those children without added whitespace; Vue, React, and Svelte render them as children, and the preset exposes the required element allowlists.
  • Component linting: Source matching excludes plugin-generated blocks from unknown-component diagnostics.
  • Coverage and documentation: Added math/security and lint regressions, updated framework parity handling, and documented standalone allowlist registration.

Validation: the workspace build, TypeScript check, math/lint/UI suites, Doctor examples, and math/lint package Doctor checks pass. Focused public-interface reproductions expose the findings below; Svelte client namespace checks used instrumented DOM creation rather than visual browser testing.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol(xhigh) | 𝕏

Comment thread packages/math/src/svelte/Formula.svelte Resolved
Comment thread packages/math/src/svelte/Formula.svelte Resolved
Comment thread packages/lint/src/index.ts Resolved
Comment thread packages/math/src/html.ts Resolved
Comment thread packages/math/src/markup.ts Resolved
@vite-hub

vite-hub Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor
Session Status Started Duration
Pending Completed Not started —
View session Last seen running 2026-11-17T10:30:35.805Z 0s
View session Cancelled 2026-11-17T10:25:52.018Z 1m 53s
View session Cancelled 2026-11-17T09:40:19.940Z 14m 10s

Latest result

Pull request merged.

Final answers

Session

Pull request merged.

Session

Pass interrupted; current webhook state retained.

Session

Pass interrupted; current webhook state retained.

Session

Pass interrupted; current webhook state retained.

onmax and others added 3 commits November 17, 2026 10:54
…sed components

- Svelte: a typeset formula carries `typeset`, since @comark/svelte always passes a children snippet, so a formula
  that didn't typeset shows its TeX again. @comark/svelte's <svelte:element> gives MathML's tags the HTML namespace in
  the browser, so a formula made there is parsed again into a MathML copy shown in place of Svelte's own.
- The HTML renderer escapes every `&` in a formula's decoded text and its TeX, so `\verb|&lt;|` shows `&lt;`.
- The markup reader takes single-quoted attributes, as Temml writes for `\ref`, and closes only the element that's
  open, so a reference no longer breaks the rest of its formula. `a` joins MATHML_TAGS.
- The linter compares a block with the names its line writes in kebab case, so `::Screnshot` and `:Screnshot[x]`
  are still reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hromium is installed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… too

The copy that fixes the namespace now follows the span with Svelte's render through an effect, so a formula that
starts as TeX and typesets after an update gets it as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Reactive Svelte updates can display a previous formula, and the new browser test fails in the existing CI check job.

Reviewed changes in 24bf309 since the previous Pullfrog review.

  • Normalized authored names: Compared source component names and token names using the same casing normalization while retaining the generated-math exclusion.
  • Preserved formula content: Added strict HTML escaping, single-quoted attribute parsing, matched closing tags, and reference-anchor allowlisting.
  • Reworked Svelte rendering: Added an explicit typeset flag and browser-parsed MathML copies synchronized with a mutation observer.
  • Expanded regression coverage: Added literal-entity, reference, PascalCase-component, Svelte SSR, and Chromium namespace tests.

Validation: workspace build, TypeScript, math/lint/UI suites, and math/lint Doctor checks pass locally after browser installation and dependency preparation. Independent Chromium document-update reproductions expose the stale-formula defect; current-head CI logs confirm the missing-browser failure.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol(xhigh) | 𝕏

Comment thread packages/math/src/svelte/Formula.svelte Resolved
Comment thread packages/math/test/svelte.test.ts Resolved
…MathML

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found; no P0 or P1 findings remain.

Reviewed changes since the previous Pullfrog review at 24bf309, including the additional regression commit that landed during this run.

  • Moved browser coverage: Relocated Chromium checks to the provisioned E2E suite, retained browser-free SSR coverage, and extracted the shared Svelte bundling helper.
  • Bound synchronization to element lifetime: Replaced one-time initialization with a reactive effect that clears stale copied markup, observes replacement elements, and disconnects previous observers.
  • Added reactive regressions: Covered invalid-to-valid updates and valid → invalid → different-valid updates, checking native MathML namespaces and the final visible token.

Validation passed: workspace build, all 25 math tests, the Svelte E2E test, TypeScript, and math Doctor. Independent Chromium checks also passed repeated formula replacement and removal; the SSR test passed with its browser path pointed at an empty location.

Pullfrog  | View workflow run | Using gpt-6.1-sol(xhigh) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found. No P0 or P1 findings remain.

Reviewed changes in the commits since the previous Pullfrog review at 24bf309.

  • Moved browser coverage: Relocated Chromium checks into the existing browser-provisioned E2E pipeline while retaining server-rendering coverage in the unit suite.
  • Fixed reactive MathML synchronization: Bound copied markup, state reset, and observer cleanup to the lifetime of the rendered element using $effect.
  • Added document-update regressions: Covered broken-to-valid namespace preservation and verified that $a$ → broken TeX → $b$ visibly renders the new b.

Validation passed: workspace build, math/lint/UI suites, Chromium E2E coverage including five repeated runs, TypeScript, focused lint, and math/lint Doctor checks.

Pullfrog  | View workflow run | Using gpt-6.1-sol(xhigh) | 𝕏

@vite-hub
vite-hub Bot merged commit bfbfaf8 into main Nov 17, 2026
7 checks passed
@vite-hub
vite-hub Bot deleted the fix/math-security-lint branch November 17, 2026 10:37
@github-actions github-actions Bot mentioned this pull request Nov 17, 2026
vite-hub Bot added a commit to vite-hub/drop that referenced this pull request Nov 17, 2026
* feat: render LaTeX math in Markdown docs

Docs typeset `$…$`, `$$…$$`, and ```math fences as MathML while parsing, through comark-ui's comark-mathml,
which now keeps its formulas through Drop's security allowlist and lints display math clean (onmax/comark-ui#449).
A doc without math loads nothing for it, and Copy as Markdown keeps the LaTeX.

Comments work on and around formulas: a quote's anchor skips text that isn't drawn (an inline block's <style>,
a formula's TeX annotation) and matches a formula as a selection quotes it, with its symbols spaced and in their
italic forms. A bubble at a quote's end inside a formula sits right after its <math>, beside a display formula.

The comark-ui update leaves Kroki fences as code unless drawing is on, so Drop turns it on, as before. The render
cache revision goes up so existing docs render their math.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: run on comark-ui #449 c883574

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(viewer): keep a formula's comment on the formula, and place it past invisible MathML

A quote matched in plain form (NFKC) only lands where its formula-only characters, such as 𝑘, fall in a formula, so
a comment on the k of $k$ no longer moves to the k of "stock" before it. Text under <mphantom>, which a selection
never quotes, is skipped like <annotation>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: vite-hub[bot] <320448255+vite-hub[bot]@users.noreply.github.com>
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.

1 participant