transform.ts
9 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[], 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
Parameters
-
htmlstring -
frontmatterRecord<string, unknown> -
tocTocEntry[] -
filePathstring -
_optionsResolvedOptions
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 JsTransformOptions
Members
Properties
| Name | Type | Description |
|---|---|---|
attributesoptional |
{ enabled?: boolean } |
|
autolinksoptional |
boolean |
Enable automatic link conversion (URLs become clickable). Default false |
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 } |
|
convertMdLinksoptional |
boolean |
Convert .md links to .html links for SSG output.Default false |
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 |
wikiLinksoptional |
{ enabled?: boolean; baseUrl?: string } |
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
Members
Properties
| Name | Type | Description |
|---|---|---|
generateOgImageSvg |
(data: OgImageData, config?: OgImageConfig) => string |
Generates an OG image as SVG.
Returns SVG string |
lintCodeBlocks |
(source: string, options?: JsCodeBlockLintOptions) => JsCodeBlockDiagnostic[] |
|
mergeHighlightedCodeBlocks |
(originalHtml: string, highlightedHtml: string) => string |
Restores code block metadata after JavaScript-side syntax 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.
Returns Rendered HTML and parsing errors |
sanitizeHtml |
(html: string, options?: JsSanitizeOptions) => string |
|
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.
Returns Transformed result with HTML, metadata, and TOC |
interfaceOgImageConfigOG image configuration.
OG image configuration.
Signature
export interface OgImageConfig
Members
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 OgImageData
Members
Properties
| Name | Type | Description |
|---|---|---|
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
Members
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 |
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 contentsrender: Client-side render function for dynamic updates
Examples
import { transformMarkdown } from './transform';
const content = await transformMarkdown(
'# Hello\n\nWorld',
'path/to/file.md',
resolvedOptions
);