mdz_opcodes.ts

Opcode types for the mdz streaming parser.

Opcodes are serializable rendering instructions emitted by MdzStreamParser. They tell a renderer what to do next — open a container, append text, close it, or revert an optimistic assumption. Target-agnostic: works for HTML, Svelte, PDF, etc.

The parser makes optimistic assumptions about ambiguous syntax (e.g., ** is probably bold) and emits revert opcodes to correct when wrong. This enables true streaming rendering without ever re-parsing.

Declarations
#

14 declarations

view source

MdzContainerNodeType
#

mdz_opcodes.ts view source

MdzContainerNodeType import type {MdzContainerNodeType} from '@fuzdev/fuz_ui/mdz_opcodes.js';

Node types that can be opened as containers.

MdzNodeId
#

mdz_opcodes.ts view source

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

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

MdzNodeType
#

mdz_opcodes.ts view source

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

All node types that can appear in the mdz tree.

MdzOpcode
#

mdz_opcodes.ts view source

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

Discriminated union of all mdz opcodes.

MdzOpcodeAppendText
#

mdz_opcodes.ts view source

MdzOpcodeAppendText import type {MdzOpcodeAppendText} from '@fuzdev/fuz_ui/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

MdzOpcodeClose
#

mdz_opcodes.ts view source

MdzOpcodeClose import type {MdzOpcodeClose} from '@fuzdev/fuz_ui/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/fuz_ui/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 MdzContainerNodeType

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

MdzOpcodeRevert
#

mdz_opcodes.ts view source

MdzOpcodeRevert import type {MdzOpcodeRevert} from '@fuzdev/fuz_ui/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.

When wrap_node_type and wrap_id are set, the replacement text and re-parented children are wrapped in a new container of the given type instead of being placed directly at the grandparent level. The wrapper is pushed onto the consumer's stack (open for future content). This is used for block-level reverts (e.g., codeblock → paragraph) where the grandparent is root and content needs a container.

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

wrap_node_type?

Wrap replacement text and re-parented children in a new container of this type.

type MdzContainerNodeType

wrap_id?

ID for the wrapper node. Required when wrap_node_type is set.

type MdzNodeId

MdzOpcodeText
#

mdz_opcodes.ts view source

MdzOpcodeText import type {MdzOpcodeText} from '@fuzdev/fuz_ui/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 MdzTextNodeType

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/fuz_ui/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/fuz_ui/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 MdzVoidNodeType

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/fuz_ui/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.

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

MdzTextNodeType
#

mdz_opcodes.ts view source

MdzTextNodeType import type {MdzTextNodeType} from '@fuzdev/fuz_ui/mdz_opcodes.js';

Discriminant for leaf text nodes.

MdzVoidNodeType
#

mdz_opcodes.ts view source

"Hr" import type {MdzVoidNodeType} from '@fuzdev/fuz_ui/mdz_opcodes.js';

Node types for self-contained leaf elements.

Imported by
#