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.
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.
14 declarations
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.
MdzNodeType import type {MdzNodeType} from '@fuzdev/mdz/mdz_opcodes.js'; All node types that can appear in the mdz tree.
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 import type {MdzNodeTypeText} from '@fuzdev/mdz/mdz_opcodes.js'; Discriminant for leaf text nodes (see MdzNodeTypeContainer for Code's dual form).
"Hr" import type {MdzNodeTypeVoid} from '@fuzdev/mdz/mdz_opcodes.js'; Node types for self-contained leaf elements.
MdzOpcode import type {MdzOpcode} from '@fuzdev/mdz/mdz_opcodes.js'; Discriminated union of all mdz opcodes.
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.
typetype 'append_text'
idtype MdzNodeId
contenttype 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 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.
typetype 'close'
idtype MdzNodeId
endByte 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 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.
typetype 'open'
idtype MdzNodeId
node_typetype MdzNodeTypeContainer
startByte 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 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.
typetype 'revert'
idtype MdzNodeId
replacement_textThe delimiter text to emit as literal content (e.g., "**", "[", "<Tag>").
type string
startByte offset of the original opening delimiter in the full input.
type number
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.
typetype 'text'
idtype MdzNodeId
contenttype string
text_typetype MdzNodeTypeText
startByte offset where this node begins (for Code, the opening backtick).
type number
endByte offset immediately after this node ends (for Code, after the closing backtick).
type number
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.
typetype 'trim_text'
idtype MdzNodeId
counttype number
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.
typetype 'void'
idtype MdzNodeId
node_typetype MdzNodeTypeVoid
startByte offset in the full input where this element begins.
type number
endByte offset immediately after this element ends.
type number
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.
typetype 'wrap'
idID for the new Link container node.
type MdzNodeId
node_typeContainer type to wrap in (always 'Link' for now).
type 'Link'
target_idID of the existing text node to wrap.
type MdzNodeId
referenceResolved URL or path reference.
type string
link_typeWhether the link is external (URL) or internal (path).
type 'external' | 'internal'
startByte offset where the URL/path begins.
type number
endByte 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