api #

a strict markdown dialect built for streaming, Svelte authoring, docs websites, and untrusted content

26 modules · 100 declarations

Modules
#

Mdz
#

Mdz.svelte view source

accepts children

import Mdz from '@fuzdev/mdz/Mdz.svelte';

content

type string

inline?

type boolean
optional default false

whitespace?

Sets white-space on the wrapper. When omitted, whitespace collapses like standard markdown — single newlines render as soft breaks. Use pre-line to render every newline as a line break.

optional

base?

type string
optional

intersects

SvelteHTMLElements['div'],SvelteHTMLElements['span']

mdz_base_context
#

mdz_contexts.ts view source

{ get: (error_message?: string | undefined) => () => string | undefined; get_maybe: () => (() => string | undefined) | undefined; set: (value: () => string | undefined) => () => string | undefined; } import {mdz_base_context} from '@fuzdev/mdz/mdz_contexts.js';

Context for providing a base path getter for resolving relative links in mdz content. Set to a getter (e.g., () => base) so changes to the base prop are reflected without needing an effect. When the getter returns a path like '/docs/usage/', relative paths like ./grammar resolve to /docs/usage/grammar before rendering. When not set, relative paths use raw hrefs (browser resolves them).

mdz_code_context
#

mdz_contexts.ts view source

{ get: (error_message?: string | undefined) => () => MdzCodeComponent | undefined; get_maybe: () => (() => MdzCodeComponent | undefined) | undefined; set: (value: () => MdzCodeComponent | undefined) => () => MdzCodeComponent | undefined; } import {mdz_code_context} from '@fuzdev/mdz/mdz_contexts.js';

Context for overriding how inline `` code `` spans render, via a getter function. When not set, inline code renders as a plain <code> element.

mdz_codeblock_context
#

mdz_contexts.ts view source

{ get: (error_message?: string | undefined) => () => MdzCodeblockComponent | undefined; get_maybe: () => (() => MdzCodeblockComponent | undefined) | undefined; set: (value: () => MdzCodeblockComponent | undefined) => () => MdzCodeblockComponent | undefined; } import {mdz_codeblock_context} from '@fuzdev/mdz/mdz_contexts.js';

Context for overriding how fenced code blocks render, via a getter function. When not set, code blocks render as a plain <pre><code> element.

mdz_components_context
#

mdz_contexts.ts view source

{ get: (error_message?: string | undefined) => () => MdzComponents | undefined; get_maybe: () => (() => MdzComponents | undefined) | undefined; set: (value: () => MdzComponents | undefined) => () => MdzComponents | undefined; } import {mdz_components_context} from '@fuzdev/mdz/mdz_contexts.js';

Context for providing custom mdz components via a getter function. Set to a getter (e.g., () => components) so changes are reflected reactively.

mdz_elements_context
#

mdz_contexts.ts view source

{ get: (error_message?: string | undefined) => () => MdzElements | undefined; get_maybe: () => (() => MdzElements | undefined) | undefined; set: (value: () => MdzElements | undefined) => () => MdzElements | undefined; } import {mdz_elements_context} from '@fuzdev/mdz/mdz_contexts.js';

Context for providing allowed HTML elements via a getter function. Set to a getter (e.g., () => elements) so changes are reflected reactively. By default, no HTML elements are allowed.

mdz_extract_single_tag
#

mdz_helpers.ts view source

(nodes: MdzNode[]): MdzNodeElement | MdzNodeComponent | null import {mdz_extract_single_tag} from '@fuzdev/mdz/mdz_helpers.js';

Extracts a single tag (component or element) if it's the only non-whitespace content.

nodes

type MdzNode[]

returns

MdzNodeElement | MdzNodeComponent | null

the tag node if paragraph wrapping should be skipped (MDX convention), or null if the content should be wrapped in a paragraph

mdz_from_tsdoc
#

tsdoc_mdz.ts view source

(content: string): string import {mdz_from_tsdoc} from '@fuzdev/mdz/tsdoc_mdz.js';

Convert raw TSDoc @see content to mdz format for rendering.

Handles TSDoc link syntax:

  • |text[text](url) (markdown link, TSDoc canonical form)
  • text[text](url) (TS-lenient space-separated form)
  • ://...https://... (bare URL, auto-linked by mdz)
  • `` → `` identifier `` (code formatting)
  • Bare URLs → returned as-is
  • Bare markdown links ([text](url) ...) → returned as-is
  • Bare identifiers → wrapped in backticks
  • identifier description text → `` identifier description text `` (first token is the reference)

content

raw @see tag content in TSDoc format

type string

returns

string

mdz-formatted string ready for Mdz component

examples

mdz_from_tsdoc('://fuz.dev|API Docs') // → '[API Docs](https://fuz.dev)' mdz_from_tsdoc('') // → '`SomeType`' mdz_from_tsdoc('https://fuz.dev') // → 'https://fuz.dev' mdz_from_tsdoc('[svelte-docinfo](https://github.com/ryanatkn/svelte-docinfo) for the analysis library') // → '[svelte-docinfo](https://github.com/ryanatkn/svelte-docinfo) for the analysis library' mdz_from_tsdoc('tome.ts for the documentation system') // → '`tome.ts` for the documentation system'

mdz_heading_id
#

mdz_helpers.ts view source

(nodes: MdzNode[]): string import {mdz_heading_id} from '@fuzdev/mdz/mdz_helpers.js';

Generates a lowercase slug id for a heading from its child nodes. Follows standard markdown conventions (GitHub, etc.) where heading IDs are lowercased.

nodes

type MdzNode[]

returns

string

mdz_heading_id_from_text
#

mdz_helpers.ts view source

(text: string): string import {mdz_heading_id_from_text} from '@fuzdev/mdz/mdz_helpers.js';

Generates a lowercase slug id for a heading from plain text content. Used by the streaming parser which tracks text content directly rather than building MdzNode[] trees.

text

type string

returns

string

mdz_is_safe_reference
#

mdz_helpers.ts view source

(reference: string): boolean import {mdz_is_safe_reference} from '@fuzdev/mdz/mdz_helpers.js';

reference

type string

returns

boolean

mdz_is_url
#

mdz_helpers.ts view source

(s: string): boolean import {mdz_is_url} from '@fuzdev/mdz/mdz_helpers.js';

s

type string

returns

boolean

mdz_is_void_element
#

mdz_helpers.ts view source

(name: string): boolean import {mdz_is_void_element} from '@fuzdev/mdz/mdz_helpers.js';

Check if an element name is an HTML void element (br, img, hr, ...). Void elements render self-closing; any parsed children are dropped.

name

type string

returns

boolean

mdz_merge_adjacent_text
#

mdz_helpers.ts view source

(nodes: MdzNode[]): MdzNode[] import {mdz_merge_adjacent_text} from '@fuzdev/mdz/mdz_helpers.js';

Return a new array with adjacent Text nodes merged into single nodes. Fast path: returns the original array when no merging is needed.

nodes

type MdzNode[]

returns

MdzNode[]

mdz_opcodes_to_nodes
#

mdz_opcodes_to_nodes.ts view source

(opcodes: MdzOpcode[]): MdzNode[] import {mdz_opcodes_to_nodes} from '@fuzdev/mdz/mdz_opcodes_to_nodes.js';

Convert an array of mdz opcodes to the MdzNode[] tree. Produces output identical to mdz_parse().

opcodes

type MdzOpcode[]

returns

MdzNode[]

mdz_parse
#

mdz.ts view source

(text: string): MdzNode[] import {mdz_parse} from '@fuzdev/mdz/mdz.js';

Parses text to an array of MdzNode.

Two phases: MdzLexer tokenizes the input into a flat MdzToken[] stream, then MdzTokenParser builds the MdzNode[] tree from the tokens.

text

type string

returns

MdzNode[]

mdz_push_merging_text
#

mdz_helpers.ts view source

(dest: MdzNode[], node: MdzNode): void import {mdz_push_merging_text} from '@fuzdev/mdz/mdz_helpers.js';

Push a node into a children array, coalescing with the previous Text node. Mutates prev.content and prev.end when both are Text, avoiding array growth and an extra allocation. Callers must own dest and not retain references to the prior last element across the call.

dest

type MdzNode[]

node

type MdzNode

returns

void

mdz_resolve_relative_path
#

mdz_helpers.ts view source

(reference: string, base: string): string import {mdz_resolve_relative_path} from '@fuzdev/mdz/mdz_helpers.js';

Resolves a relative path (./ or ../) against a base path. The base is treated as a directory regardless of trailing slash ('/docs/usage' and '/docs/usage/' behave identically). Handles embedded . and .. segments within the reference (e.g., './a/../b' → navigates up then down). Clamps at root — excess .. segments stop at / rather than escaping.

reference

a relative path starting with ./ or ../

type string

base

An absolute base path (e.g., '/docs/usage/'). Empty string is treated as root.

type string

returns

string

an absolute resolved path (e.g., '/docs/usage/grammar')

mdz_set_context_with_fallback
#

mdz_contexts.ts view source

<T>(context: MdzGetterContext<T>, value_fn: () => T | undefined): void import {mdz_set_context_with_fallback} from '@fuzdev/mdz/mdz_contexts.js';

Set an mdz context to a getter that prefers the local value_fn and falls back to the ancestor's value when value_fn() returns undefined.

Pass value_fn as a getter (not a snapshot) so prop changes remain reactive. The ancestor lookup happens once at component init — that's intentional, it captures the surrounding scope's context at mount time.

context

type MdzGetterContext<T>

value_fn

type () => T | undefined

returns

void

generics

mdz_set_context_with_fallback<T>
T

mdz_text_content
#

mdz_helpers.ts view source

(nodes: MdzNode[]): string import {mdz_text_content} from '@fuzdev/mdz/mdz_helpers.js';

Extracts plain text content from an array of mdz nodes, recursing into children.

nodes

type MdzNode[]

returns

string

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

mdz_trim_url_punctuation
#

mdz_helpers.ts view source

(url: string): string import {mdz_trim_url_punctuation} from '@fuzdev/mdz/mdz_helpers.js';

Trim trailing punctuation from URL/path per RFC 3986 and GFM rules.

  • Trims simple trailing: .,;:!?]
  • Balanced logic for () only (valid in path components)

Note on ]: the mdz parsers (mdz.ts, mdz_stream_parser_url.ts, mdz_lexer.ts) scan URL/path chars through is_valid_path_char, which already rejects ] — so it can never reach this function via parser flow. The ] branch here is for external callers using this helper directly on arbitrary URL-ish input as part of the published @fuzdev/mdz surface.

Optimized to avoid O(n²) string slicing - tracks end index and slices once at the end.

url

type string

returns

string

MdzCodeblockComponent
#

mdz_contexts.ts view source

MdzCodeblockComponent import type {MdzCodeblockComponent} from '@fuzdev/mdz/mdz_contexts.js';

Component that renders a fenced code block. Receives lang and content, matching @fuzdev/fuz_code's Code, so it can be injected directly for syntax highlighting.

MdzCodeComponent
#

mdz_contexts.ts view source

MdzCodeComponent import type {MdzCodeComponent} from '@fuzdev/mdz/mdz_contexts.js';

Component that renders an inline `` code `` span. Receives the raw span content as reference — the prop name matches fuz_ui's DocsLink, so it can be injected directly to auto-link backticked API identifiers.

MdzComponents
#

mdz_contexts.ts view source

MdzComponents import type {MdzComponents} from '@fuzdev/mdz/mdz_contexts.js';

Component registry for custom Svelte components that can be used in mdz content.

For example, registering 'Alert' allows using <Alert>...</Alert> in mdz content.

The Map values are Svelte components.

MdzElements
#

mdz_contexts.ts view source

MdzElements import type {MdzElements} from '@fuzdev/mdz/mdz_contexts.js';

Element registry for HTML elements that can be used in mdz content.

For example, registering 'div' allows using <div>...</div> in mdz content.

The Map values are boolean placeholders for future configuration options.

MdzLexer
#

mdz_lexer.ts view source

import {MdzLexer} from '@fuzdev/mdz/mdz_lexer.js';

Tokenizes mdz input into a flat MdzToken stream for MdzTokenParser.

The lexer owns all structural decisions — block boundaries, list level stacks, blockquote prefix stripping (sub-lexing quote content as a mini-document with positions remapped to source offsets), and inline delimiter pairing bounded by #max_search_index — so the token parser only assembles the tree.

constructor

type new (text: string): MdzLexer

text

type string

tokenize

type (): MdzToken[]

returns MdzToken[]

MdzNode
#

MdzNodeBase
#

mdz.ts view source

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

type

type string

start

type number

end

type number

MdzNodeBlockquote
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'Blockquote'

children

Block children — a quote's content is a mini-document, so anything that can appear at the top level can appear here (Paragraph | Heading | Hr | List | Codeblock | Blockquote).

type Array<MdzNode>

MdzNodeBold
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'Bold'

children

type Array<MdzNode>

MdzNodeCode
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'Code'

content

The code content (identifier/module name).

type string

MdzNodeCodeblock
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'Codeblock'

lang

Language hint, if provided.

type string | null

content

Raw code content.

type string

MdzNodeComponent
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'Component'

name

Svelte component name (e.g. Alert, Card).

type string

children

type Array<MdzNode>

MdzNodeElement
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'Element'

name

HTML element name (e.g. div, span, aside).

type string

children

type Array<MdzNode>

MdzNodeHeading
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'Heading'

level

type 1 | 2 | 3 | 4 | 5 | 6

id

Slugified heading text for fragment links.

type string

children

Inline formatting allowed.

type Array<MdzNode>

MdzNodeHr
#

MdzNodeId
#

mdz_opcodes.ts view source

number import type {MdzNodeId} from '@fuzdev/mdz/mdz_opcodes.js';

Unique monotonic identifier for each node created by the parser. IDs are never reused within a parser instance.

MdzNodeItalic
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'Italic'

children

type Array<MdzNode>

MdzNodeLink
#

MdzNodeList
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'List'

ordered

type boolean

start_number?

First item's authored number (ordered only) — the <ol start> attribute.

type number

children

type Array<MdzNodeListItem>

MdzNodeListItem
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'ListItem'

number?

Authored number (ordered only); the renderer ignores it, tooling and the future formatter use it.

type number

children

Inline run first, then block children (Paragraph | List | Codeblock | Blockquote).

type Array<MdzNode>

MdzNodeParagraph
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'Paragraph'

children

type Array<MdzNode>

MdzNodeStrikethrough
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'Strikethrough'

children

type Array<MdzNode>

MdzNodeText
#

mdz.ts view source

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

inheritance

extends: MdzNodeBase

type

type 'Text'

content

type string

MdzNodeType
#

mdz_opcodes.ts view source

MdzNodeType import type {MdzNodeType} from '@fuzdev/mdz/mdz_opcodes.js';

All node types that can appear in the mdz tree.

MdzNodeTypeContainer
#

mdz_opcodes.ts view source

MdzNodeTypeContainer import type {MdzNodeTypeContainer} from '@fuzdev/mdz/mdz_opcodes.js';

Node types that can be opened as containers.

Code appears here *and* in MdzNodeTypeText: inline code resolved within one chunk emits as a single text opcode, while a backtick with no closer visible yet opens an optimistic Code container whose content streams as text children (collapsed back to content by consumers at close).

MdzNodeTypeText
#

MdzNodeTypeVoid
#

mdz_opcodes.ts view source

"Hr" import type {MdzNodeTypeVoid} from '@fuzdev/mdz/mdz_opcodes.js';

Node types for self-contained leaf elements.

MdzNodeView
#

MdzOpcode
#

mdz_opcodes.ts view source

MdzOpcode import type {MdzOpcode} from '@fuzdev/mdz/mdz_opcodes.js';

Discriminated union of all mdz opcodes.

MdzOpcodeAppendText
#

mdz_opcodes.ts view source

MdzOpcodeAppendText import type {MdzOpcodeAppendText} from '@fuzdev/mdz/mdz_opcodes.js';

Append content to an existing text node. Streaming optimization — avoids creating a new node per chunk during plain text runs.

type

type 'append_text'

id

type MdzNodeId

content

type string

end?

Byte offset immediately after the appended content in the full input. When absent, consumers extend the node's end by content.length; present when the two differ — list continuation lines strip structural indent from content, so the source span outgrows the content length.

type number

MdzOpcodeClose
#

mdz_opcodes.ts view source

MdzOpcodeClose import type {MdzOpcodeClose} from '@fuzdev/mdz/mdz_opcodes.js';

Close a previously opened container node. Carries deferred metadata that wasn't known at open time.

type

type 'close'

id

type MdzNodeId

end

Byte offset in the full input immediately after the closing delimiter.

type number

reference?

Link URL/path, resolved when ](url) completes.

type string

link_type?

Link type, resolved alongside reference.

type 'external' | 'internal'

heading_id?

Heading slug, computed from full heading content.

type string

discard?

If true, consumer drops this node and its descendants from the tree. Used for whitespace-only paragraphs that match nothing in mdz_parse's output — the streaming parser emits open/text speculatively, then retroactively drops the empty wrapper at close.

type boolean

MdzOpcodeOpen
#

mdz_opcodes.ts view source

MdzOpcodeOpen import type {MdzOpcodeOpen} from '@fuzdev/mdz/mdz_opcodes.js';

Open a container node. The renderer starts a new element/wrapper. Children are subsequent opcodes until the matching close.

type

type 'open'

id

type MdzNodeId

node_type

type MdzNodeTypeContainer

start

Byte offset in the full input where the opening delimiter begins.

type number

level?

Heading level (1-6). Present when node_type is 'Heading'.

type 1 | 2 | 3 | 4 | 5 | 6

name?

Tag name. Present when node_type is 'Element' or 'Component'.

type string

lang?

Language hint. Present when node_type is 'Codeblock'.

type string | null

ordered?

Whether the list is ordered. Present when node_type is 'List'.

type boolean

start_number?

First item's authored number — the <ol start> attribute. Present for ordered 'List'.

type number

number?

Authored item number. Present when node_type is 'ListItem' in an ordered list.

type number

MdzOpcodeRevert
#

mdz_opcodes.ts view source

MdzOpcodeRevert import type {MdzOpcodeRevert} from '@fuzdev/mdz/mdz_opcodes.js';

Undo an optimistic open. Removes the container wrapper, inserts replacement_text as literal text at the container's position, and re-parents the container's children to the grandparent.

Only inline containers revert — block structure (paragraphs, headings, codeblocks, lists, blockquotes) is decided from bounded input before opening, so block opens are never speculative.

type

type 'revert'

id

type MdzNodeId

replacement_text

The delimiter text to emit as literal content (e.g., "**", "[", "<Tag>").

type string

start

Byte offset of the original opening delimiter in the full input.

type number

MdzOpcodeText
#

mdz_opcodes.ts view source

MdzOpcodeText import type {MdzOpcodeText} from '@fuzdev/mdz/mdz_opcodes.js';

Create a leaf text or code node. The parent is implicit — the innermost open container on the renderer's stack.

type

type 'text'

id

type MdzNodeId

content

type string

text_type

type MdzNodeTypeText

start

Byte offset where this node begins (for Code, the opening backtick).

type number

end

Byte offset immediately after this node ends (for Code, after the closing backtick).

type number

MdzOpcodeTrimText
#

mdz_opcodes.ts view source

MdzOpcodeTrimText import type {MdzOpcodeTrimText} from '@fuzdev/mdz/mdz_opcodes.js';

Trim count characters from the end of an existing text node. If trimming empties the node, the consumer removes it from its parent.

Used by paragraph/codeblock close to drop the trailing newline that separates inline content from the block boundary. Emitted instead of retroactively mutating the prior text/append_text opcode, so the opcode stream is append-only.

type

type 'trim_text'

id

type MdzNodeId

count

type number

MdzOpcodeVoid
#

mdz_opcodes.ts view source

MdzOpcodeVoid import type {MdzOpcodeVoid} from '@fuzdev/mdz/mdz_opcodes.js';

Create a self-contained leaf node (e.g., horizontal rule). Inserted as a child of the innermost open container, or at root level.

type

type 'void'

id

type MdzNodeId

node_type

type MdzNodeTypeVoid

start

Byte offset in the full input where this element begins.

type number

end

Byte offset immediately after this element ends.

type number

MdzOpcodeWrap
#

mdz_opcodes.ts view source

MdzOpcodeWrap import type {MdzOpcodeWrap} from '@fuzdev/mdz/mdz_opcodes.js';

Retroactively wrap an existing text node in a container. Used for text-first auto-links: URL/path text streams as plain text, then gets wrapped in a Link when the URL boundary is found.

Specific to text-first auto-detected content — not a general retroactive-container mechanism. Delimiter-paired inlines (bold, italic, strikethrough) use optimistic open + revert instead: their opening delimiter is an explicit open event, and the delimiters are discarded rather than retained as content.

When trim_end is set, trailing characters (punctuation) are trimmed from the target text node and placed in a new sibling Text node after the Link wrapper, identified by trim_id.

type

type 'wrap'

id

ID for the new Link container node.

type MdzNodeId

node_type

Container type to wrap in (always 'Link' for now).

type 'Link'

target_id

ID of the existing text node to wrap.

type MdzNodeId

reference

Resolved URL or path reference.

type string

link_type

Whether the link is external (URL) or internal (path).

type 'external' | 'internal'

start

Byte offset where the URL/path begins.

type number

end

Byte offset immediately after the URL/path (before any trimmed punctuation).

type number

trim_end?

Number of trailing chars to trim from target and place after the link.

type number

trim_id?

ID for the trimmed-text sibling node. Required when trim_end > 0.

type MdzNodeId

MdzPrecompiled
#

MdzPrecompiled.svelte view source

accepts children

import MdzPrecompiled from '@fuzdev/mdz/MdzPrecompiled.svelte';

children

type Snippet<[]>

inline?

type boolean
optional default false

whitespace?

Sets white-space on the wrapper. When omitted, whitespace collapses like standard markdown — single newlines render as soft breaks. Use pre-line to render every newline as a line break.

optional

intersects

SvelteHTMLElements['div'],SvelteHTMLElements['span']

MdzRoot
#

MdzStream
#

MdzStream.svelte view source

accepts children

import MdzStream from '@fuzdev/mdz/MdzStream.svelte';

stream

inline?

type boolean
optional default false

whitespace?

Sets white-space on the wrapper. When omitted, whitespace collapses like standard markdown — single newlines render as soft breaks. Use pre-line to render every newline as a line break.

optional

base?

type string
optional

intersects

SvelteHTMLElements['div'],SvelteHTMLElements['span']

MdzStreamNode
#

mdz_stream_state.svelte.ts view source

import {MdzStreamNode} from '@fuzdev/mdz/mdz_stream_state.svelte.js';

A reactive node in the stream renderer tree. Fields are $state so Svelte re-renders only what changes.

id

type MdzNodeId

type

type MdzNodeType

content

type string

$state

children

type Array<MdzStreamNode>

$state

level?

type 1 | 2 | 3 | 4 | 5 | 6

reference?

type string

$state

link_type?

type 'external' | 'internal'

$state

name?

type string

lang?

type string | null

heading_id?

type string

$state

ordered?

type boolean

start_number?

type number

number?

type number

constructor

type new (id: number, type: MdzNodeType): MdzStreamNode

id

type number

type

MdzStreamNodeView
#

MdzStreamParser
#

mdz_stream_parser.ts view source

import {MdzStreamParser} from '@fuzdev/mdz/mdz_stream_parser.js';

Streaming opcode parser for mdz content. Feed chunks via feed(), retrieve opcodes via take_opcodes(), call finish() at end.

The opcode sequence is not deterministic across chunk boundaries — the same input fed in different chunk sizes may produce different text/append_text splits and different optimistic/revert sequences. The final tree (via mdz_opcodes_to_nodes) matches the one-shot result: optimistic opens are corrected by revert opcodes at the first failed closer, at run close (paragraph, heading, or list-item run), or at EOF, and at EOF the delimiter-paired opens (bold/italic/strikethrough) and inline-code candidates are gated on a closer scan of the complete final buffer, so held tails parse like the one-shot parse. The residual divergence classes are:

  • Backtick-adjacent chunking — an inline-code candidate held across chunks can make its text-vs-code decision bounded by a wrongly-optimistic italic (opened before its failed closer was visible), where the one-shot parse greedy-rejects that italic and scans unbounded — `` ___ `` chunked at the italic stays flat text where one-shot parses the code span. Italic is the only wedge (the only delimiter whose one-shot form rejects on a failed first closer); see try_code's hold and code_search_limit.
  • Optimistic inline code unclosed at EOF — a `` ` that opened optimistically consumes its tail as raw code text, so formatting inside it never forms (`` h x **b** z ` stays flat where one-shot parses the bold); the parser never re-parses, so the EOF revert can only flatten it to text.
  • Link/tag opens at EOFfinish() doesn't open links or tags, so a held tail containing complete [text](url) / <Tag>…</Tag> syntax parses flat.
  • Block elements interrupt optimistic inlines — at column 0 a heading/HR/fence/list/blockquote line interrupts the open paragraph even when an optimistic inline container spans it (**a\n# h\nb** parses the heading here; the one-shot parse, knowing the closer exists, swallows the line as bold text). Inherent: the swallow is only correct when a closer eventually arrives, which streaming can't know — interrupting matches the one-shot parse on the no-closer flip side (**a\n# h) and renders blocks promptly.

Lifecycle: one parser instance per stream — feed() any number of times, finish() exactly once, then a final take_opcodes(). There is no reset(); calling feed() or finish() after finish() is undefined. To restart, construct a new parser (and a new consumer — see MdzStreamState).

feed

Feed a chunk of text to the parser. Opcodes are accumulated and retrieved via take_opcodes().

type (chunk: string): void

chunk

type string
returns void

finish

Signal end of input. Resolves all pending state: closes open blocks, reverts unclosed optimistic opens, trims trailing newlines.

Trailing-newline trimming is handled in one place: trim_trailing_newline() called at the top of close_paragraph() and close_codeblock_at_eof(), before either function reverts its inner stack. The trim sees the just-flushed text node's last_text_id (or a still-accumulated \n) and emits a trim_text opcode. Revert opcodes only fire after.

Optimistic-container revert is handled by close_paragraph and close_heading (each reverts everything above its own block frame via revert_above), so no separate revert pass is needed — optimistic containers can only exist inside an open Paragraph or Heading (parser invariant).

type (): void

returns void

take_opcodes

Drain and return all accumulated opcodes. Destructive — empties the internal queue. The returned array is owned by the caller.

type (): MdzOpcode[]

returns MdzOpcode[]

MdzStreamState
#

mdz_stream_state.svelte.ts view source

import {MdzStreamState} from '@fuzdev/mdz/mdz_stream_state.svelte.js';

Reactive state manager for streaming mdz content. Apply opcodes to incrementally build and update the render tree.

Lifecycle: one state instance per stream, paired with one MdzStreamParser. Opcodes must be applied exactly once, in emission order — take_opcodes() batches can be split or concatenated freely, but never reordered, skipped, or replayed. There is no reset(); to restart a stream, construct a new parser and a new state.

root

type Array<MdzStreamNode>

$state

apply

Apply a single opcode.

type (opcode: MdzOpcode): void

opcode

returns void

apply_batch

Apply a batch of opcodes.

type (opcodes: MdzOpcode[]): void

opcodes

type MdzOpcode[]
returns void

MdzToken
#

MdzTokenAutolink
#

MdzTokenBase
#

mdz_lexer.ts view source

MdzTokenBase import type {MdzTokenBase} from '@fuzdev/mdz/mdz_lexer.js';

start

type number

end

type number

MdzTokenBlockquoteClose
#

mdz_lexer.ts view source

MdzTokenBlockquoteClose import type {MdzTokenBlockquoteClose} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'blockquote_close'

MdzTokenBlockquoteOpen
#

mdz_lexer.ts view source

MdzTokenBlockquoteOpen import type {MdzTokenBlockquoteOpen} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'blockquote_open'

MdzTokenBoldClose
#

MdzTokenBoldOpen
#

MdzTokenCode
#

MdzTokenCodeblock
#

mdz_lexer.ts view source

MdzTokenCodeblock import type {MdzTokenCodeblock} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'codeblock'

lang

type string | null

content

type string

MdzTokenHeadingEnd
#

MdzTokenHeadingStart
#

mdz_lexer.ts view source

MdzTokenHeadingStart import type {MdzTokenHeadingStart} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'heading_start'

level

type 1 | 2 | 3 | 4 | 5 | 6

MdzTokenHr
#

MdzTokenItalicClose
#

MdzTokenItalicOpen
#

MdzTokenLinkRef
#

mdz_lexer.ts view source

MdzTokenLinkRef import type {MdzTokenLinkRef} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'link_ref'

reference

type string

link_type

type 'external' | 'internal'

MdzTokenLinkTextClose
#

mdz_lexer.ts view source

MdzTokenLinkTextClose import type {MdzTokenLinkTextClose} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'link_text_close'

MdzTokenLinkTextOpen
#

mdz_lexer.ts view source

MdzTokenLinkTextOpen import type {MdzTokenLinkTextOpen} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'link_text_open'

MdzTokenListClose
#

MdzTokenListItemClose
#

mdz_lexer.ts view source

MdzTokenListItemClose import type {MdzTokenListItemClose} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'list_item_close'

MdzTokenListItemOpen
#

mdz_lexer.ts view source

MdzTokenListItemOpen import type {MdzTokenListItemOpen} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'list_item_open'

number?

Authored number (ordered lists only).

type number

MdzTokenListOpen
#

mdz_lexer.ts view source

MdzTokenListOpen import type {MdzTokenListOpen} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'list_open'

ordered

type boolean

MdzTokenParagraphBreak
#

mdz_lexer.ts view source

MdzTokenParagraphBreak import type {MdzTokenParagraphBreak} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'paragraph_break'

MdzTokenParser
#

mdz_token_parser.ts view source

import {MdzTokenParser} from '@fuzdev/mdz/mdz_token_parser.js';

Builds an MdzNode[] tree from a lexed MdzToken[] stream. Used by mdz_parse, which should be preferred for simple usage.

constructor

type new (tokens: MdzToken[]): MdzTokenParser

tokens

type MdzToken[]

parse

type (): MdzNode[]

returns MdzNode[]

MdzTokenStrikethroughClose
#

mdz_lexer.ts view source

MdzTokenStrikethroughClose import type {MdzTokenStrikethroughClose} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'strikethrough_close'

MdzTokenStrikethroughOpen
#

mdz_lexer.ts view source

MdzTokenStrikethroughOpen import type {MdzTokenStrikethroughOpen} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'strikethrough_open'

MdzTokenTagClose
#

mdz_lexer.ts view source

MdzTokenTagClose import type {MdzTokenTagClose} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'tag_close'

name

type string

MdzTokenTagOpen
#

mdz_lexer.ts view source

MdzTokenTagOpen import type {MdzTokenTagOpen} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'tag_open'

name

type string

is_component

type boolean

MdzTokenTagSelfClose
#

mdz_lexer.ts view source

MdzTokenTagSelfClose import type {MdzTokenTagSelfClose} from '@fuzdev/mdz/mdz_lexer.js';

inheritance

extends: MdzTokenBase

type

type 'tag_self_close'

name

type string

is_component

type boolean

MdzTokenText
#

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

MdzWhitespace
#

mdz_contexts.ts view source

MdzWhitespace import type {MdzWhitespace} from '@fuzdev/mdz/mdz_contexts.js';

CSS white-space values for the whitespace prop on Mdz, MdzStream, and MdzPrecompiled. By default no style is applied, so whitespace collapses like standard markdown — single newlines are soft breaks. pre-line renders every newline as a line break (chat-style input); pre-wrap additionally preserves spaces and tabs.

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