Repository navigation
fix(kit): escape curly braces in markdown link & image URLs - #812
Merged
coyotte508 merged 1 commit intoAug 4, 2026
Merged
Conversation
A link's URL lives on the mdast node's `url` property, not in a child
text node, so the existing `onText` visitor never escapes curly braces
inside it. mdsvex then emits the raw braces into the `href`/`src`
attribute of the generated Svelte component, where Svelte 5 interprets
`{...}` as an expression. During prerendering this throws
`ReferenceError: <name> is not defined` and fails the whole doc build —
e.g. for URLs containing OpenAPI path params like:
[overview endpoint](https://huggingface-openapi.hf.space/#tag/users/GET/api/users/{username}/overview)
Escape `{` as `&huggingface#123;` in link/image `url` and `title` inside the doc
body, mirroring what `onText` does for text nodes. The doc-body check
uses marker offsets rather than the stateful `isWithinDocBody()`,
because that state machine only works for visitors that run before the
END marker's text node is visited (link/image passes run after the text
pass has already flipped the state off).
coyotte508
added a commit
to huggingface/hub-docs
that referenced
this pull request
Aug 4, 2026
doc-builder's mdsvex preprocessor doesn't escape curly braces inside
link URLs (only in text nodes), so Svelte 5 treats {username} in the
href as an expression and prerendering fails with
'ReferenceError: username is not defined'.
Upstream fix: huggingface/doc-builder#812
Member
Author
|
Ref: #812 |
coyotte508
added a commit
to huggingface/hub-docs
that referenced
this pull request
Aug 4, 2026
* Document API access to user hardware items The user overview endpoint now returns a hardwareItems array, and /oauth/userinfo includes a hardwareItems claim with the profile scope, for users whose hardware is public. * Apply suggestion from @coyotte508 * Percent-encode {username} in OpenAPI link to unbreak doc build doc-builder's mdsvex preprocessor doesn't escape curly braces inside link URLs (only in text nodes), so Svelte 5 treats {username} in the href as an expression and prerendering fails with 'ReferenceError: username is not defined'. Upstream fix: huggingface/doc-builder#812 * Apply suggestion from @coyotte508 --------- Co-authored-by: huggingface-doc-bot <doc-bot@huggingface.co>
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
A markdown link whose URL contains curly braces — e.g. OpenAPI-style path params:
fails the whole HTML doc build (
doc-builder build ... --html) at SvelteKit prerender time with:Hit in practice by a hub-docs PR linking to an OpenAPI endpoint with a
{username}path parameter.Root cause
In
kit/preprocessors/mdsvex/index.js, thetreeVisitorremark plugin escapes{→{intextnodes (onText) and in raw-HTML text children (onHtml) so Svelte doesn't interpret braces as expression tags. But a link's URL is stored on the mdastlink/imagenode'surlproperty, not in a child text node — so it is never escaped. mdsvex emits the raw braces into the generatedhref/srcattribute, Svelte 5 compiles{username}into${$.stringify(username)}in the SSR output, and prerendering (adapter-static) throws.Fix
Escape
{as{in link/imageurlandtitleinside the doc body, mirroringonText. The rendered output is byte-identical from the browser's perspective ({resolves back to{in the attribute value), and the compiled component becomes a static string again.Note on the doc-body check:
isWithinDocBody()'s module-level state machine only works for visitor passes that run before theHF_DOC_BODY_ENDtext node has been visited — thetextpass flips the state off at the end of the document, so any later pass (like a newlinkpass) would see "outside body" for every node. Instead, the marker offsets are located up front and node positions compared against them.Verified
Ran the actual
mdsvexPreprocess+svelte.compile(generate: "server")pipeline on a doc page containing the failing link:${$.stringify(username)}→ReferenceErrorat prerenderhref="...api/users/{username}/overview"verbatimprettier --checkpasses