mdz_stream_parser_block.ts

Block-element handlers for the streaming mdz parser.

Each try_* returns {@link TryResult} so the orchestrator in {@link ./mdz_stream_parser.ts} can fall through or wait for more input.

Declarations
#

9 declarations

view source

emit_codeblock_text
#

mdz_stream_parser_block.ts view source

(state: MdzStreamParserState, cb: CodeblockState, content: string, content_start: number): void import {emit_codeblock_text} from '@fuzdev/fuz_ui/mdz_stream_parser_block.js';

Emit codeblock content as text (first chunk) or append_text (subsequent chunks), updating cb.text_id on first emit. content_start is the local buffer position where the content slice began — only used to compute the global byte offset for the first text opcode.

state

cb

content

type string

content_start

type number

returns

void

find_closing_fence
#

mdz_stream_parser_block.ts view source

(state: MdzStreamParserState, start: number, backtick_count: number): "found" | "not_found" | "invalid" import {find_closing_fence} from '@fuzdev/fuz_ui/mdz_stream_parser_block.js';

Scan buffer from start for a valid closing fence with backtick_count backticks. Used as a fallback when the current paragraph has prior content (to avoid splitting the paragraph on revert). Returns 'found' if a valid closing fence exists, 'not_found' if the buffer ends before we can determine, 'invalid' if we can see the full remaining content and there's no valid closing fence.

state

start

type number

backtick_count

type number

returns

"found" | "not_found" | "invalid"

match_codeblock_close
#

mdz_stream_parser_block.ts view source

(state: MdzStreamParserState, backtick_count: number, forced?: boolean): number import {match_codeblock_close} from '@fuzdev/fuz_ui/mdz_stream_parser_block.js';

Check if the buffer at current position has a codeblock closing fence. Returns the position after the fence (including trailing newline) on success, -1 when definitely not a fence, or -2 when more input is needed to decide.

When forced is true, EOF after the fence counts as a valid terminator (matches mdz_parse's handling of code blocks at end of input).

state

backtick_count

type number

forced

type boolean
default false

returns

number

process_codeblock
#

mdz_stream_parser_block.ts view source

(state: MdzStreamParserState): boolean import {process_codeblock} from '@fuzdev/fuz_ui/mdz_stream_parser_block.js';

Process bytes while in codeblock mode. Returns true if processing should continue, false if more input needed.

state

returns

boolean

process_codeblock_forced
#

mdz_stream_parser_block.ts view source

(state: MdzStreamParserState): void import {process_codeblock_forced} from '@fuzdev/fuz_ui/mdz_stream_parser_block.js';

Drain the remaining buffer as codeblock content at EOF, looking for a closing fence whose terminator is EOF rather than \n. Matches mdz_parse's #match_code_block, which allows a fence at the end of the document.

If a fence is found, the codeblock closes normally. Otherwise the remaining buffer becomes content and close_codeblock_at_eof (in state.ts) handles the revert-and-wrap dance after process completes.

state

returns

void

revert_empty_codeblock
#

mdz_stream_parser_block.ts view source

(state: MdzStreamParserState, cb: CodeblockState): boolean import {revert_empty_codeblock} from '@fuzdev/fuz_ui/mdz_stream_parser_block.js';

Revert an empty codeblock (closing fence found but no content was emitted). Wraps the opening fence delimiter in a new paragraph and accumulates the closing fence text for normal paragraph processing.

state

cb

returns

boolean

try_codeblock_open
#

mdz_stream_parser_block.ts view source

(state: MdzStreamParserState): TryResult import {try_codeblock_open} from '@fuzdev/fuz_ui/mdz_stream_parser_block.js';

Try to open a code block at column 0.

Opens the codeblock optimistically when possible. When the current paragraph has no prior content, opens immediately on \\\lang\n` without lookahead, enabling streaming. When the paragraph has content (text before the fence on a prior line), falls back to lookahead via find_closing_fence to avoid splitting the paragraph on revert.

state

returns

TryResult

try_heading
#

mdz_stream_parser_block.ts view source

(state: MdzStreamParserState): TryResult import {try_heading} from '@fuzdev/fuz_ui/mdz_stream_parser_block.js';

Try to parse a heading at column 0. Returns true if consumed, false if needs more input, null if definitely not a heading.

state

returns

TryResult

try_hr
#

mdz_stream_parser_block.ts view source

(state: MdzStreamParserState, forced?: boolean): TryResult import {try_hr} from '@fuzdev/fuz_ui/mdz_stream_parser_block.js';

Try to parse a horizontal rule at column 0. Returns true if consumed, false if needs more input, null if definitely not an HR. When forced is true, treats buffer end as EOF (no more input coming).

state

forced

type boolean
default false

returns

TryResult

Depends on
#

Imported by
#