Skip to content

transform.ts#

View Markdown

Source

12 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.

12 symbols 5 functions 5 interfaces 1 variables 1 modules 21 parameters 66 members 5 returns 1 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[]

View source

Parameters

  • content string

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): string

View source

Parameters

  • html string
  • frontmatter Record<string, unknown>
  • toc TocEntry[]
  • imports MdxImport[]
  • exports string[]
  • components string[]
  • crossReferences CrossReferenceEntry[]
  • citations CitationReference[]
  • bibliography BibliographyEntry[]
  • filePath string

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>

View source

Parameters

  • data OgImageData

    OG image data (title, description, etc.)

  • config OgImageConfig

    Optional 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 JsTransformOptions

View source

Members

Properties
NameTypeDescription
abbreviationsoptional { enabled?: boolean; terms?: Record<string, string>; firstUseOnly?: boolean }
attributesoptional { enabled?: boolean }
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 }> }
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
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 }
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
interfaceNapiTransformResultWhat the native transform entry points return.

What the native transform entry points return.

Signature

interface NapiTransformResult

View source

Members

Properties
NameTypeDescription
components string[]
errors string[]
exports string[]
frontmatter string
html string
imports MdxImport[]
toc Array<{ depth: number; text: string; slug: string; children?: TocEntry[] }>
interfaceOgImageConfigOG image configuration.

OG image configuration.

Signature

export interface OgImageConfig

View source

Members

Properties
NameTypeDescription
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 OgImageData

View source

Members

Properties
NameTypeDescription
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>

View source

Parameters

Returns

Promise<NapiTransformResult>
interfaceSsgTransformOptionsSSG-specific transform options.

SSG-specific transform options.

Signature

export interface SsgTransformOptions

View source

Members

Properties
NameTypeDescription
baseUrloptional string
Base URL for absolute link conversion
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:

  1. Parsing: Uses Rust-based parser via NAPI bindings for high performance
  2. Rendering: Converts parsed AST to semantic HTML
  3. Enhancement: Applies syntax highlighting, Mermaid diagram rendering, etc.
  4. Code Generation: Generates JavaScript/TypeScript module code

The generated modules export:

  • html: Rendered HTML content
  • frontmatter: Parsed YAML metadata
  • toc: Hierarchical table of contents
  • imports: MDX import statements from the AST
  • exports: MDX export names from the AST
  • components: Unique JSX component names from the AST
  • render: Client-side render function for dynamic updates

View source

Examples

Example 1
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-/

View source

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): void

View source

Parameters

Returns

void