tfrere's picture
tfrere HF Staff
fix(publisher): render math server-side via KaTeX
d062662
Raw
History Blame Contribute Delete
2.68 kB
/**
* Ordered registry of DOM transformers applied during `postProcess()`.
*
* Order matters:
* 1. Accordion — must run early so nested content is moved before other
* transformers query it.
* 2. Citation — inline markers must be resolved before bibliography
* anchors are attached, so the `#ref-<key>` hrefs align.
* 3. Bibliography — consumes the ordered keys produced by the citation step.
* 4. Mermaid — must run BEFORE `highlightCode`: it converts
* `<div data-component="mermaid">` into `<pre class="mermaid">`,
* and the highlighter explicitly skips `pre.mermaid`. If
* this ran after, the highlighter would try to syntax-color
* the mermaid source.
* 5. HighlightCode — runs Shiki over every remaining `<pre><code>`.
* 6. HtmlEmbed — independent; converts placeholder divs into iframes.
* 7. IframeEmbed — independent; converts placeholder divs pointing at a
* remote URL into a standard `<figure><iframe src=...>`.
* 8. HfUser — independent; converts atomic placeholder divs into
* Hugging Face user profile cards.
* 9. Math — renders the empty `data-type="inline-math"/"block-math"`
* placeholders into static KaTeX HTML. Runs before
* Footnote so math inside a footnote is captured rendered.
* 10. Footnote — runs last so collected texts include those inside every
* other transformed block (tables, callouts, accordions...).
*/
import type { Transformer } from "./types.js";
import { accordionTransformer } from "./accordion.js";
import { citationTransformer } from "./citation.js";
import { bibliographyTransformer } from "./bibliography.js";
import { mermaidTransformer } from "./mermaid.js";
import { highlightCodeTransformer } from "./highlight-code.js";
import { htmlEmbedTransformer } from "./html-embed.js";
import { iframeEmbedTransformer } from "./iframe-embed.js";
import { hfUserTransformer } from "./hf-user.js";
import { mathTransformer } from "./math.js";
import { footnoteTransformer } from "./footnote.js";
export const transformers: Transformer[] = [
accordionTransformer,
citationTransformer,
bibliographyTransformer,
mermaidTransformer,
highlightCodeTransformer,
htmlEmbedTransformer,
iframeEmbedTransformer,
hfUserTransformer,
mathTransformer,
footnoteTransformer,
];
export type { Transformer, TransformContext } from "./types.js";
export { buildEmbedSrcdoc } from "./html-embed.js";