transform.ts

Source

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

9 symbols 3 functions 5 interfaces 1 modules 8 parameters 42 members 3 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[], filePath: string, _options: ResolvedOptions): stringGenerates the JavaScript module code.

Generates the JavaScript module code.

Signature

function generateModuleCode(html: string, frontmatter: Record<string, unknown>, toc: TocEntry[], filePath: string, _options: ResolvedOptions): string

View source

Parameters

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
attributesoptional { enabled?: boolean }
autolinkUrlsoptional boolean
Linkify bare URLs while rendering.
Default true
baseUrloptional string
Base URL for absolute link conversion (e.g., "/" or "/docs/").
Default "/"
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"
codeImportsoptional { enabled?: boolean; rootDir?: string }
editThisPageoptional { enabled?: boolean; repoUrl?: string; branch?: string; rootDir?: string; label?: string }
emojiShortcodesoptional { enabled?: boolean; custom?: 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
sanitizeoptional JsSanitizeOptions
sourcePathoptional string
Source file path for relative link resolution.
Used to determine if the current file is an index file.
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
tocMaxDepthoptional number
Maximum heading depth for table of contents.
Headings deeper than this level are excluded from TOC.
Default 3
interfaceNapiBindingsNAPI bindings for Rust-based Markdown processing. Provides access to compiled R…

NAPI bindings for Rust-based Markdown processing.

Provides access to compiled Rust functions for high-performance Markdown parsing and rendering operations.

Signature

interface NapiBindings

View source

Members

Properties
NameTypeDescription
generateOgImageSvg (data: OgImageData, config?: OgImageConfig) => string
Generates an OG image as SVG.
  • data OG image data (title, description, etc.)
  • config Optional OG image configuration — optional
Returns SVG string
lintCodeBlocks (source: string, options?: JsCodeBlockLintOptions) => JsCodeBlockDiagnostic[]
  • source
  • options optional
mergeHighlightedCodeBlocks (originalHtml: string, highlightedHtml: string) => string
Restores code block metadata after JavaScript-side syntax highlighting.
  • originalHtml HTML before syntax highlighting
  • highlightedHtml HTML after Shiki highlighting
Returns Highlighted HTML with original code block metadata reapplied
parseAndRender (source: string, options?: { gfm?: boolean }) => { html: string; errors: string[] }
Simple Markdown parser and renderer in one step.
Faster for simple use cases but lacks advanced features.
  • source Raw Markdown content
  • options Parser configuration (GFM flag) — optional
  • options.gfm? optional
Returns Rendered HTML and parsing errors
sanitizeHtml (html: string, options?: JsSanitizeOptions) => string
  • html
  • options optional
transform (source: string, options?: JsTransformOptions) => { html: string; frontmatter: string; toc: Array<{ depth: number; text: string; slug: string; children?: TocEntry[] }>; errors: string[] }
Full-featured Markdown transformation pipeline.
Handles frontmatter extraction, TOC generation, and advanced parsing.
  • source Raw Markdown content (may include frontmatter)
  • options Comprehensive transformation options — optional
Returns Transformed result with HTML, metadata, and TOC
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
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
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
  • 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
);