B-R8XQ-mdviewer-math-default-and-peer-fallback-coverage
State: promoted/task
MdViewer does not set math, and ObsidianRenderOptions.math is off by
default, so $x^2$ renders as literal source text everywhere a host forgets to
pass renderOptions: { math: true }. Level 0 ruled the default stays opt-in
during PR 8 (#1717): KaTeX is a real
payload, and no consumer renders math today, so defaulting it on would tax every
viewer in the fleet for a feature none of them use.
The ruling leaves a testing gap, which is why this exists.
The gap
Section titled “The gap”PR 8 made katex and mermaid optional peers of @sksizer/obsidian-md. When a
peer is absent the loader warns once and rejects, and the Vue component degrades:
MathBlock renders its LaTeX as <code class="obsmd-math-fallback">,
MermaidBlock renders its fence.
The mermaid half is reachable through the default path — a ```mermaid fence needs no option, so any host that renders one exercises it, and PR 8 verified it in the markdown-ui playground.
The math half is not. Math parsing is opt-in, so through MdViewer’s default
configuration the KaTeX code path never runs at all — neither the success path
nor the new fallback. The fallback is covered only by the package’s own unit
tests (test/vue-fallback.test.ts), never in the configuration every consumer
actually mounts. A regression in the layer’s KaTeX wiring — its stylesheet
resolution, its optional-peer resolution under a file:-wired host — would not
be caught by any consumer.
Decide, then close the gap either way
Section titled “Decide, then close the gap either way”- If math defaults on: measure the cost first (KaTeX is ~261 KB and already ships as a lazy chunk; the question is whether enabling parsing pulls it eagerly for viewers that have no math). The fallback becomes reachable by construction.
- If math stays opt-in: give the layer a test that mounts
MdViewerwithmath: trueagainst an environment withoutkatexand asserts theobsmd-math-fallbackrendering, so the degraded path is pinned at the layer boundary rather than only inside the package.
Either way the acceptance is the same: the optional-peer fallback is exercised
by a test that goes through MdViewer, not only through the renderer package.
Evidence
Section titled “Evidence”PR 8’s playground run (handoffs/08-canvas-augmented/2-report.md, cluster 2):
a fixture note with $x^2$ and a ```mermaid fence rendered through the layer’s
default MdViewer showed the diagram as SVG in both themes and the math as
source text. KaTeX’s stylesheet was confirmed to reach the page (551 .katex
selectors, 21 KaTeX_Main @font-face mentions), so the wiring is present and
simply never asked to render.