mdz_to_svelte.ts

Converts parsed MdzNode arrays to Svelte markup strings.

Used by the svelte_preprocess_mdz preprocessor to expand static <Mdz content="..."> usages into pre-rendered Svelte markup at build time. The output for each node type matches what MdzNodeView.svelte renders at runtime, so precompiled and runtime rendering are identical.

view source

Declarations
#

3 declarations

mdz_to_svelte
#

mdz_to_svelte.ts view source

(nodes: MdzNode[], options: MdzToSvelteOptions): MdzToSvelteResult import {mdz_to_svelte} from '@fuzdev/mdz/mdz_to_svelte.js';

Converts an array of MdzNode to a Svelte markup string.

Each node type produces output matching what MdzNodeView.svelte renders at runtime. Collects required imports and flags unconfigured component/element references.

nodes

parsed mdz nodes to render

type MdzNode[]

options

rendering configuration matching the runtime context surface

returns

MdzToSvelteResult

MdzToSvelteOptions
#

mdz_to_svelte.ts view source

MdzToSvelteOptions import type {MdzToSvelteOptions} from '@fuzdev/mdz/mdz_to_svelte.js';

Options for mdz_to_svelte.

components

Component name to import path mapping (e.g., {Alert: '$lib/Alert.svelte'}). If content references a component not in this map, has_unconfigured_tags is set.

type Record<string, string>

elements

Allowed HTML elements (e.g., {aside: true, details: true}). Values are boolean placeholders for future per-element configuration, mirroring the runtime MdzElements registry. If content references an element not in this record, has_unconfigured_tags is set.

type Record<string, boolean>

base?

Base path for resolving relative links (e.g., '/docs/usage/'). When provided, relative references (./, ../) are resolved to absolute paths and passed through resolve(). Trailing slash recommended.

type string

code_component_import?

Import path for the inline code component (receives reference). When omitted, inline code renders as a plain <code> element — matching MdzNodeView.svelte's runtime default, so precompiled and runtime output stay identical per configuration.

type string

codeblock_component_import?

Import path for the codeblock component (receives lang and content). When omitted, code blocks render as a plain <pre><code> element — matching MdzNodeView.svelte's runtime default.

type string

MdzToSvelteResult
#

mdz_to_svelte.ts view source

MdzToSvelteResult import type {MdzToSvelteResult} from '@fuzdev/mdz/mdz_to_svelte.js';

Result of converting MdzNode arrays to Svelte markup.

markup

Generated Svelte markup string.

type string

imports

Required imports: Map<local_name, {path, kind}>.

type Map<string, {path: string; kind: 'default' | 'named'}>

has_unconfigured_tags

Whether content references unconfigured Component or Element tags.

type boolean

Depends on
#

Imported by
#