Repository navigation
Conversation
Docstring fragments (parameter, return and raise descriptions) are HTML
strings that the Docstring component renders with {@html}, so the
{@html "…"} tag that renderKatex wrapped math in was shown as text, with
its quotes escaped again. Fragments now get the plain KaTeX HTML.
docstring.js rewrites `}}` to `}‌}` in parameter descriptions, so any
`}}` in their math (e.g. \frac{1}{\sqrt{r}}) made KaTeX fail the build:
renderKatex restores it before rendering.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Math in docstring parameter and return descriptions renders as literal text instead of math. For example, on
AnyFlowTransformer3DModel, thegate_valueparameter shows the text{@html "<span class="\"katex\">followed by raw KaTeX markup with broken attributes likeclass="\"mord" mathnormal\". Thesampleparameter onFlowMapEulerDiscreteScheduleris broken the same way. Both come from:math:in diffusers docstrings, which doc-builder converts to\\(…\\);$…$breaks the same way.Cause
renderKatexinkit/preprocessors/mdsvex/index.jswraps every rendered formula in a Svelte{@html "…"}tag. That's right for the doc body of a page, which is Svelte markup. Butdocstring.jsrenders each docstring section as a separate mdsvex fragment, and the result is an HTML string thatDocstring.sveltedisplays with{@html description}. The nested{@htmltag is never evaluated: the browser shows it as text and parses the JSON-escaped quotes inside it as attribute values.Fix
DOCSTRING_FRAGMENT_MARKER,renderKatexreturns the plain KaTeX HTML. Page bodies still get{@html …}.docstring.jsrewrites}}as}‌}in parameter descriptions. That made KaTeX fail on any}}in parameter math, e.g.$\frac{1}{\sqrt{r}}$, and the error stops the build.renderKatexnow restores}}before rendering.Verification
mix_embeddingssample covers$…$and:math:in parameter descriptions, the}}case, and math in a return description. No existing line ofpage.htmlchanges, including the body math oflegacy_function. With main, the sample renders the same broken markup as the diffusers page; on this branch it's KaTeX.mdsvex/index.test.js, one for page-body math and one for fragment math. The fragment test fails on main.perplexity.md, on a synthetic page with every math form ($…$,\\(…\\),$$…$$, braces, math in a table), and on the full snapshot page. The output is byte-identical.parseRenderedParamsListre-serializes the KaTeX HTML. For\frac{1}{\sqrt{r}}, the result is identical to KaTeX's own output except that the zero-width space comes back as​, which the browser decodes to the same character. The SVG of\sqrtis kept.npm testpasses (12/12), as dopytest tests/test_docstring_snapshots.py, ruff and prettier. The 3 ESLint errors inmdsvex/index.jsare already on main.Once diffusers' docs rebuild, these blocks become translatable: #903 keeps them in English until then.
🤖 Generated with Claude Code