svelte_preprocess_mdz.ts

Svelte preprocessor that compiles static Mdz content to Svelte markup at build time.

Detects Mdz components with static string content props, parses the mdz content, renders each MdzNode to equivalent Svelte markup via mdz_to_svelte, and replaces the Mdz with MdzPrecompiled containing pre-rendered children.

Also handles ternary chains (content={a ? 'x' : b ? 'y' : 'z'}) where all leaf values are statically resolvable strings, emitting {#if a}markup_x{:else if b}markup_y{:else}markup_z{/if} as children of a single MdzPrecompiled.

Truly dynamic content props are left untouched.

view source

Declarations
#

2 declarations

svelte_preprocess_mdz
#

svelte_preprocess_mdz.ts view source

(options?: SveltePreprocessMdzOptions): PreprocessorGroup import {svelte_preprocess_mdz} from '@fuzdev/mdz/svelte_preprocess_mdz.js';

Creates a Svelte preprocessor that compiles static Mdz content at build time.

options

configuration for component/element resolution and file filtering

default {}

returns

PreprocessorGroup

a Svelte PreprocessorGroup for use in svelte.config.js

SveltePreprocessMdzOptions
#

svelte_preprocess_mdz.ts view source

SveltePreprocessMdzOptions import type {SveltePreprocessMdzOptions} from '@fuzdev/mdz/svelte_preprocess_mdz.js';

exclude?

File patterns to exclude.

type Array<string | RegExp>

components?

Component import mapping for mdz content. Key: component name as used in mdz (e.g., 'Alert'). Value: import path (e.g., '$lib/Alert.svelte').

If mdz content references a component not in this map, that Mdz usage is skipped (left as runtime).

type Record<string, string>

elements?

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

type Record<string, boolean>

mdz_component_imports?

Import sources that resolve to the Mdz component. Used to verify that Mdz in templates refers to mdz's Mdz.svelte.

type Array<string>

default ['@fuzdev/mdz/Mdz.svelte']

compiled_component_import?

Import path for the precompiled wrapper component.

type string

default '@fuzdev/mdz/MdzPrecompiled.svelte'

code_component_import?

Import path for the inline code component (receives reference). When omitted, inline code compiles to a plain <code> element, matching Mdz's runtime default. Set e.g. to @fuzdev/fuz_ui/DocsLink.svelte to auto-link backticked identifiers.

type string

codeblock_component_import?

Import path for the codeblock component (receives lang and content). When omitted, code blocks compile to a plain <pre><code> element. Set e.g. to @fuzdev/fuz_code/Code.svelte for syntax highlighting.

type string

on_error?

How to handle errors during mdz parsing or rendering.

type 'log' | 'throw'

default 'throw' in CI, 'log' otherwise

Depends on
#