transform.ts
11 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.
Reference
fnbuildTocTree(entries: TocEntry[]): TocEntry[]Builds nested TOC tree from flat list.
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.
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.
Parameters
-
htmlstring -
frontmatterRecord -
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.
Parameters
-
dataOgImageDataOG image data (title, description, etc.)
-
configOgImageConfigOptional OG image configuration — optional
Returns
Promise
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.
fnloadNapiBindings(): Promise<NapiBindings | null>Lazily loads and caches NAPI bindings. This function uses lazy loading to defer…
Lazily loads and caches NAPI bindings. This function uses lazy loading to defer the import of NAPI bindings until they're actually needed. The bindings are loaded only once and cached for subsequent uses. If loading fails (e.g., bindings not built), the failure is cached to avoid repeated load attempts.
Performance Considerations
The first call to this function may have a slight performance penalty due to module loading. Subsequent calls use the cached result and are essentially zero-cost.
Error Handling
If NAPI bindings are not available (not built, wrong architecture, etc.), this function returns null. The caller should handle this gracefully or provide fallback behavior.
Returns
Promise
Promise resolving to NAPI bindings or null if unavailable
Examples
// Simple check with fallback
const napi = await loadNapiBindings();
if (!napi) {
console.warn('NAPI bindings not available, using fallback');
return fallbackRender(content);
}
// Use Rust implementation
const result = napi.transform(content, { gfm: true });
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.
interfaceOgImageConfigOG image configuration.
OG image configuration.
interfaceOgImageDataOG image data for generating social media preview images.
OG image data for generating social media preview images.
fnparseFrontmatter(source: string): { content: string; frontmatter: Record<string, unknown>; }Parses YAML frontmatter from Markdown content. Uses proper YAML parser for full…
Parses YAML frontmatter from Markdown content. Uses proper YAML parser for full nested object support.
Parameters
-
sourcestring
Returns
{ ... }
interfaceSsgTransformOptionsSSG-specific transform options.
SSG-specific transform options.