transform.ts#
12 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.
Reference#
fnextractImports(content: string): string[]Extracts imports from Markdown content. Supports importing components for inter…
Extracts imports from Markdown content.
Supports importing components for interactive islands.
Signature
export function extractImports(content: string): string[]Parameters
-
contentstring
Returns
string[]
fngenerateModuleCode(html: string, frontmatter: Record<string, unknown>, toc: TocEntry[], imports: MdxImport[], exports: string[], components: string[], crossReferences: CrossReferenceEntry[], citations: CitationReference[], bibliography: BibliographyEntry[], filePath: string): stringGenerates the JavaScript module code. MDX metadata is serialized as JSON. User…
Generates the JavaScript module code.
MDX metadata is serialized as JSON. User import / export source is never emitted as live JavaScript, so transform does not execute module side effects.
Signature
function generateModuleCode(html: string, frontmatter: Record<string, unknown>, toc: TocEntry[], imports: MdxImport[], exports: string[], components: string[], crossReferences: CrossReferenceEntry[], citations: CitationReference[], bibliography: BibliographyEntry[], filePath: string): stringParameters
Returns
string
fngenerateOgImageSvg(data: OgImageData, config?: OgImageConfig): Promise<string | null>Generates an OG image SVG using the Rust-based generator. This function uses th…
Generates an OG image SVG using the Rust-based generator.
This function uses the Rust NAPI bindings to generate SVG-based OG images for social media previews. The SVG can be served directly or converted to PNG/JPEG for broader compatibility.
In the future, custom JS templates can be provided to override the default Rust-based template.
Signature
export async function generateOgImageSvg(data: OgImageData, config?: OgImageConfig): Promise<string | null>Parameters
-
dataOgImageDataOG image data (title, description, etc.)
-
configOgImageConfigOptional OG image configuration — optional
Returns
Promise<string | null>
SVG string or null if NAPI bindings are unavailable
interfaceJsTransformOptionsOptions for Rust-based Markdown transformation. Controls which Markdown extensi…
Options for Rust-based Markdown transformation.
Controls which Markdown extensions and features are enabled during parsing and rendering.
Signature
interface JsTransformOptionsMembers
Properties
| Name | Type | Description |
|---|---|---|
abbreviationsoptional |
{ enabled?: boolean; terms?: Record<string, string>; firstUseOnly?: boolean } |
|
attributesoptional |
{ enabled?: boolean } |
|
autolinksoptional |
boolean |
Enable automatic link conversion (URLs become clickable). Default false |
autolinkUrlsoptional |
boolean |
Linkify bare URLs while rendering. Default true |
badgesoptional |
{ enabled?: boolean } |
|
baseUrloptional |
string |
Base URL for absolute link conversion (e.g., "/" or "/docs/"). Default "/" |
cardsoptional |
{ enabled?: boolean } |
|
cjkEmphasisoptional |
boolean |
|
codeAnnotationDefaultLineNumbersoptional |
boolean |
Enable line numbers for all code blocks by default. Default false |
codeAnnotationMetaKeyoptional |
string |
Fence meta key used to read code annotations. Default "annotate" |
codeAnnotationsoptional |
boolean |
Enable line annotations for code blocks using fence meta. Default false |
codeAnnotationSyntaxoptional |
"attribute" | "vitepress" | "both" |
Code annotation syntax mode. Default "attribute" |
codeGroupsoptional |
{ enabled?: boolean } |
|
codeImportsoptional |
{ enabled?: boolean; rootDir?: string } |
|
conditionalBlocksoptional |
{ enabled?: boolean; values?: Record<string, unknown> } |
|
containersoptional |
{ enabled?: boolean; types?: Record<string, { title?: string; tag?: string }> } |
|
convertMdLinksoptional |
boolean |
Convert .md links to .html links for SSG output.Default false |
dataTablesoptional |
{ enabled?: boolean; rootDir?: string; missing?: "error" | "warn" } |
|
definitionListsoptional |
{ enabled?: boolean } |
|
editThisPageoptional |
{ enabled?: boolean; repoUrl?: string; branch?: string; rootDir?: string; srcDir?: string; provider?: string; urlPattern?: string; label?: string } |
|
emojiShortcodesoptional |
{ enabled?: boolean; custom?: Record<string, string> } |
|
fileTreeoptional |
{ enabled?: boolean; defaultOpen?: boolean; icons?: boolean; iconFolder?: string; iconFolderOpen?: string; iconFile?: string; iconFiles?: Record<string, string> } |
|
footnotesoptional |
boolean |
Enable footnotes syntax ([^1]: definition). Default false |
frontmatteroptional |
boolean |
Parse YAML frontmatter before transforming. Default true |
gfmoptional |
boolean |
Enable GitHub Flavored Markdown extensions. Includes tables, task lists, strikethrough, and autolinks. Default false |
headingPermalinksoptional |
boolean |
Append visible heading permalinks. Default false |
imageGalleriesoptional |
{ enabled?: boolean; lazy?: boolean; missingAlt?: "error" | "warn" | "ignore"; empty?: "error" | "warn" | "ignore" } |
|
imagesoptional |
{ enabled?: boolean; lazy?: boolean } |
|
includesoptional |
{ enabled?: boolean; rootDir?: string } |
|
keyboardKeysoptional |
{ enabled?: boolean; aliases?: Record<string, string>; style?: string } |
|
magicLinksoptional |
{ enabled?: boolean; aliases?: Record<string, { href: string; label?: string; image?: string }>; favicon?: boolean; faviconTemplate?: string; imageOverrides?: Array<{ href?: string; prefix?: string; image: string }> } |
|
mathoptional |
boolean | { enabled?: boolean } |
Opt-in inline and block math.Omitted or false leaves $ literal. true or {} enables defaults;{ enabled: false } disables math.Default false |
mdxoptional |
boolean |
Enable MDX JSX, ESM, and expression nodes. Default false |
notByAioptional |
{ enabled?: boolean; label?: string; href?: string } |
|
partialsoptional |
{ enabled?: boolean; rootDir?: string; root?: string; missing?: string } |
|
sanitizeoptional |
JsSanitizeOptions |
|
semanticFootnotesoptional |
boolean |
Render footnotes as a semantic ordered section with numeric markers. Default false |
sourcePathoptional |
string |
Source file path for relative link resolution. Used to determine if the current file is an index file. |
stepsoptional |
{ enabled?: boolean } |
|
strikethroughoptional |
boolean |
Enable strikethrough syntax (~~text~~). Requires GFM to be enabled. Default false |
tablesoptional |
boolean |
Enable table rendering (GFM extension). Requires GFM to be enabled for full functionality. Default false |
taskListsoptional |
boolean |
Enable task list syntax (- [ ] unchecked, - [x] checked). Default false |
timelinesoptional |
{ enabled?: boolean; ordered?: boolean; invalidDate?: "error" | "warn" | "ignore"; unknownMeta?: "error" | "warn" | "ignore"; empty?: "error" | "warn" | "ignore" } |
|
tocMaxDepthoptional |
number |
Maximum heading depth for table of contents. Headings deeper than this level are excluded from TOC. Default 3 |
wikiLinksoptional |
{ enabled?: boolean; baseUrl?: string } |
interfaceNapiTransformResultWhat the native transform entry points return.
What the native transform entry points return.
Signature
interface NapiTransformResultinterfaceOgImageConfigOG image configuration.
OG image configuration.
Signature
export interface OgImageConfigMembers
Properties
| Name | Type | Description |
|---|---|---|
backgroundColoroptional |
string |
Background color (hex) |
descriptionFontSizeoptional |
number |
Description font size |
heightoptional |
number |
Image height in pixels |
textColoroptional |
string |
Text color (hex) |
titleFontSizeoptional |
number |
Title font size |
widthoptional |
number |
Image width in pixels |
interfaceOgImageDataOG image data for generating social media preview images.
OG image data for generating social media preview images.
Signature
export interface OgImageDataMembers
Properties
| Name | Type | Description |
|---|---|---|
authoroptional |
string |
Author name |
descriptionoptional |
string |
Page description |
siteNameoptional |
string |
Site name |
title |
string |
Page title |
fnrunTransformers(napi: NapiBindings, markdown: string, napiOptions: JsTransformOptions, filePath: string, options: ResolvedOptions, transformers: readonly MarkdownTransformer[]): Promise<NapiTransformResult>Runs the configured transformers over the parsed tree. Markdown never passes th…
Runs the configured transformers over the parsed tree.
Markdown never passes through Vite's transform hook — the native layer reads it directly — so this is the only place user config can reach the AST. The tree is handed over after frontmatter parsing and Markdown feature expansion, and handed back for rendering, HTML postprocessing, and sanitization, so a transformer costs a document nothing else.
A transformer that throws, or returns something that is not a node, is reported and skipped: one bad hook should not take the page down with it.
Signature
async function runTransformers(napi: NapiBindings, markdown: string, napiOptions: JsTransformOptions, filePath: string, options: ResolvedOptions, transformers: readonly MarkdownTransformer[]): Promise<NapiTransformResult>Parameters
-
napiNapiBindings -
markdownstring -
napiOptionsJsTransformOptions -
filePathstring -
optionsResolvedOptions -
transformersreadonly MarkdownTransformer[]
Returns
Promise<NapiTransformResult>
interfaceSsgTransformOptionsSSG-specific transform options.
SSG-specific transform options.
Signature
export interface SsgTransformOptionsMembers
Properties
| Name | Type | Description |
|---|---|---|
baseUrloptional |
string |
Base URL for absolute link conversion |
convertMdLinksoptional |
boolean |
Convert .md links to .html links |
sourcePathoptional |
string |
Source file path for relative link resolution |
srcDiroptional |
string |
Absolute source root, used to place pages inside the repository |
moduletransformMarkdown Transformation Engine This module handles the complete transformation pipeline for Markdown files, converting…
Markdown Transformation Engine
This module handles the complete transformation pipeline for Markdown files, converting raw Markdown content into JavaScript modules that can be imported by web applications. The transformation process includes:
- Parsing: Uses Rust-based parser via NAPI bindings for high performance
- Rendering: Converts parsed AST to semantic HTML
- Enhancement: Applies syntax highlighting, Mermaid diagram rendering, etc.
- Code Generation: Generates JavaScript/TypeScript module code
The generated modules export:
html: Rendered HTML contentfrontmatter: Parsed YAML metadatatoc: Hierarchical table of contentsimports: MDX import statements from the ASTexports: MDX export names from the ASTcomponents: Unique JSX component names from the ASTrender: Client-side render function for dynamic updates
Examples
import { transformMarkdown } from './transform';
const content = await transformMarkdown(
'# Hello\n\nWorld',
'path/to/file.md',
resolvedOptions
);
console.log(content.html); // '<h1>Hello</h1><p>World</p>'
console.log(content.toc); // [{ depth: 1, text: 'Hello', slug: 'hello', children: [] }]variableconst UNHIGHLIGHTED_CODE_BLOCK = /<pre(?![^>]*ox-highlight)[^>]*><code class="language-/A <pre> that names a language but has not been highlighted yet.
A <pre> that names a language but has not been highlighted yet.
Signature
const UNHIGHLIGHTED_CODE_BLOCK = /<pre(?![^>]*ox-highlight)[^>]*><code class="language-/fnwarnMathFailures(failures: MathRenderFailure[], filePath: string): voidReports every run KaTeX refused. Under the default policy the page keeps it…
Reports every run KaTeX refused.
Under the default policy the page keeps its prose, which is the readable outcome but also a silent one — a genuine mistake in a formula would otherwise leave no trace at all.
Signature
function warnMathFailures(failures: MathRenderFailure[], filePath: string): voidParameters
-
failuresMathRenderFailure[] -
filePathstring
Returns
void