@fuzdev/mdz 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/Mdz.svelte +39 -0
- package/dist/Mdz.svelte.d.ts +17 -0
- package/dist/Mdz.svelte.d.ts.map +1 -0
- package/dist/MdzNodeView.svelte +140 -0
- package/dist/MdzNodeView.svelte.d.ts +9 -0
- package/dist/MdzNodeView.svelte.d.ts.map +1 -0
- package/dist/MdzPrecompiled.svelte +33 -0
- package/dist/MdzPrecompiled.svelte.d.ts +17 -0
- package/dist/MdzPrecompiled.svelte.d.ts.map +1 -0
- package/dist/MdzRoot.svelte +40 -0
- package/dist/MdzRoot.svelte.d.ts +14 -0
- package/dist/MdzRoot.svelte.d.ts.map +1 -0
- package/dist/MdzStream.svelte +37 -0
- package/dist/MdzStream.svelte.d.ts +18 -0
- package/dist/MdzStream.svelte.d.ts.map +1 -0
- package/dist/MdzStreamNodeView.svelte +150 -0
- package/dist/MdzStreamNodeView.svelte.d.ts +9 -0
- package/dist/MdzStreamNodeView.svelte.d.ts.map +1 -0
- package/dist/context_helpers.d.ts +23 -0
- package/dist/context_helpers.d.ts.map +1 -0
- package/dist/context_helpers.js +19 -0
- package/dist/mdz.d.ts +152 -0
- package/dist/mdz.d.ts.map +1 -0
- package/dist/mdz.js +61 -0
- package/dist/mdz_contexts.d.ts +106 -0
- package/dist/mdz_contexts.d.ts.map +1 -0
- package/dist/mdz_contexts.js +42 -0
- package/dist/mdz_helpers.d.ts +321 -0
- package/dist/mdz_helpers.d.ts.map +1 -0
- package/dist/mdz_helpers.js +668 -0
- package/dist/mdz_lexer.d.ts +123 -0
- package/dist/mdz_lexer.d.ts.map +1 -0
- package/dist/mdz_lexer.js +1405 -0
- package/dist/mdz_opcodes.d.ts +193 -0
- package/dist/mdz_opcodes.d.ts.map +1 -0
- package/dist/mdz_opcodes.js +14 -0
- package/dist/mdz_opcodes_to_nodes.d.ts +26 -0
- package/dist/mdz_opcodes_to_nodes.d.ts.map +1 -0
- package/dist/mdz_opcodes_to_nodes.js +410 -0
- package/dist/mdz_stream_parser.d.ts +109 -0
- package/dist/mdz_stream_parser.d.ts.map +1 -0
- package/dist/mdz_stream_parser.js +699 -0
- package/dist/mdz_stream_parser_block.d.ts +99 -0
- package/dist/mdz_stream_parser_block.d.ts.map +1 -0
- package/dist/mdz_stream_parser_block.js +437 -0
- package/dist/mdz_stream_parser_inline.d.ts +98 -0
- package/dist/mdz_stream_parser_inline.d.ts.map +1 -0
- package/dist/mdz_stream_parser_inline.js +481 -0
- package/dist/mdz_stream_parser_link.d.ts +29 -0
- package/dist/mdz_stream_parser_link.d.ts.map +1 -0
- package/dist/mdz_stream_parser_link.js +227 -0
- package/dist/mdz_stream_parser_list.d.ts +106 -0
- package/dist/mdz_stream_parser_list.d.ts.map +1 -0
- package/dist/mdz_stream_parser_list.js +438 -0
- package/dist/mdz_stream_parser_state.d.ts +476 -0
- package/dist/mdz_stream_parser_state.d.ts.map +1 -0
- package/dist/mdz_stream_parser_state.js +651 -0
- package/dist/mdz_stream_parser_text.d.ts +25 -0
- package/dist/mdz_stream_parser_text.d.ts.map +1 -0
- package/dist/mdz_stream_parser_text.js +67 -0
- package/dist/mdz_stream_parser_url.d.ts +76 -0
- package/dist/mdz_stream_parser_url.d.ts.map +1 -0
- package/dist/mdz_stream_parser_url.js +328 -0
- package/dist/mdz_stream_state.svelte.d.ts +53 -0
- package/dist/mdz_stream_state.svelte.d.ts.map +1 -0
- package/dist/mdz_stream_state.svelte.js +360 -0
- package/dist/mdz_to_svelte.d.ts +71 -0
- package/dist/mdz_to_svelte.d.ts.map +1 -0
- package/dist/mdz_to_svelte.js +127 -0
- package/dist/mdz_token_parser.d.ts +20 -0
- package/dist/mdz_token_parser.d.ts.map +1 -0
- package/dist/mdz_token_parser.js +449 -0
- package/dist/svelte_preprocess_mdz.d.ts +80 -0
- package/dist/svelte_preprocess_mdz.d.ts.map +1 -0
- package/dist/svelte_preprocess_mdz.js +543 -0
- package/dist/tsdoc_mdz.d.ts +45 -0
- package/dist/tsdoc_mdz.d.ts.map +1 -0
- package/dist/tsdoc_mdz.js +88 -0
- package/package.json +131 -0
- package/src/lib/context_helpers.ts +52 -0
- package/src/lib/mdz.ts +190 -0
- package/src/lib/mdz_contexts.ts +99 -0
- package/src/lib/mdz_helpers.ts +727 -0
- package/src/lib/mdz_lexer.ts +1761 -0
- package/src/lib/mdz_opcodes.ts +227 -0
- package/src/lib/mdz_opcodes_to_nodes.ts +470 -0
- package/src/lib/mdz_stream_parser.ts +766 -0
- package/src/lib/mdz_stream_parser_block.ts +490 -0
- package/src/lib/mdz_stream_parser_inline.ts +527 -0
- package/src/lib/mdz_stream_parser_link.ts +283 -0
- package/src/lib/mdz_stream_parser_list.ts +525 -0
- package/src/lib/mdz_stream_parser_state.ts +957 -0
- package/src/lib/mdz_stream_parser_text.ts +95 -0
- package/src/lib/mdz_stream_parser_url.ts +386 -0
- package/src/lib/mdz_stream_state.svelte.ts +383 -0
- package/src/lib/mdz_to_svelte.ts +213 -0
- package/src/lib/mdz_token_parser.ts +544 -0
- package/src/lib/svelte_preprocess_mdz.ts +777 -0
- package/src/lib/tsdoc_mdz.ts +97 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming parser state and low-level operations.
|
|
3
|
+
*
|
|
4
|
+
* Free functions take a `MdzStreamParserState` first parameter so handlers can
|
|
5
|
+
* live in separate sibling modules — JS private (`#`) fields can't cross
|
|
6
|
+
* module boundaries.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { MdzNodeTypeContainer, MdzNodeId, MdzOpcode } from './mdz_opcodes.js';
|
|
11
|
+
/**
|
|
12
|
+
* Tri-state result for `try_*` parser handlers.
|
|
13
|
+
* - `'consumed'`: input matched and the parser advanced
|
|
14
|
+
* - `'need_more'`: input is potentially valid but more bytes are required to decide
|
|
15
|
+
* - `'not_match'`: input definitely doesn't match — caller falls through to the next handler
|
|
16
|
+
*
|
|
17
|
+
* @nodocs
|
|
18
|
+
*/
|
|
19
|
+
export type TryResult = 'consumed' | 'need_more' | 'not_match';
|
|
20
|
+
/** @nodocs */
|
|
21
|
+
export interface StackEntry {
|
|
22
|
+
id: MdzNodeId;
|
|
23
|
+
node_type: MdzNodeTypeContainer;
|
|
24
|
+
/**
|
|
25
|
+
* The opening delimiter text, used as `replacement_text` on revert.
|
|
26
|
+
* Empty for the block frames (`Paragraph`, `Heading`), which are never
|
|
27
|
+
* reverted — every inline open is optimistic (speculative, reverted if not
|
|
28
|
+
* closed), so the revert loops don't need a per-entry flag.
|
|
29
|
+
*/
|
|
30
|
+
delimiter: string;
|
|
31
|
+
/** Tag name for Element/Component entries, `undefined` for all others. */
|
|
32
|
+
tag_name: string | undefined;
|
|
33
|
+
/** Whether any child content has been emitted inside this container. */
|
|
34
|
+
has_children: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether any non-whitespace text or non-text child has been emitted
|
|
37
|
+
* inside this container. Only tracked for `Paragraph` entries to detect
|
|
38
|
+
* whitespace-only paragraphs that should be dropped at close.
|
|
39
|
+
*/
|
|
40
|
+
has_non_whitespace_content: boolean;
|
|
41
|
+
/** Global byte offset of the opening delimiter. */
|
|
42
|
+
start: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Memo entry for `buffer_index_of`, in **global** byte coordinates (see
|
|
46
|
+
* `MdzStreamParserState.base_offset`). Global coordinates make the memo
|
|
47
|
+
* immune to front-compaction: content at a global offset never changes once
|
|
48
|
+
* fed, so a found result stays valid forever and a not-found result stays
|
|
49
|
+
* valid for the byte range it scanned (`searched_to`).
|
|
50
|
+
*
|
|
51
|
+
* @nodocs
|
|
52
|
+
*/
|
|
53
|
+
export interface BufferSearchMemo {
|
|
54
|
+
/** Global byte offset the memoized scan started from. */
|
|
55
|
+
from: number;
|
|
56
|
+
/** Global byte offset of the found occurrence, or `-1` when not found. */
|
|
57
|
+
result: number;
|
|
58
|
+
/** Global byte offset of the buffer end when the scan ran — the extent a `-1` result covers. */
|
|
59
|
+
searched_to: number;
|
|
60
|
+
}
|
|
61
|
+
/** @nodocs */
|
|
62
|
+
export interface CodeblockState {
|
|
63
|
+
id: MdzNodeId;
|
|
64
|
+
backtick_count: number;
|
|
65
|
+
text_id: MdzNodeId | null;
|
|
66
|
+
/**
|
|
67
|
+
* The opener line's indent — 0 for top-level fences, the marker-relative
|
|
68
|
+
* line indent for in-item fences. Closers match at any indent <= this,
|
|
69
|
+
* and content lines strip `min(fence_indent, line_indent)`.
|
|
70
|
+
*/
|
|
71
|
+
fence_indent: number;
|
|
72
|
+
/** Global byte offset of the opening fence. */
|
|
73
|
+
start: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* An open list level — the column of its markers, mirroring the sync lexer's stack.
|
|
77
|
+
*
|
|
78
|
+
* @nodocs
|
|
79
|
+
*/
|
|
80
|
+
export interface MdzListLevel {
|
|
81
|
+
indent: number;
|
|
82
|
+
ordered: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* An open blockquote — the streaming analogue of the sync lexer's quote
|
|
86
|
+
* sub-lex. A quote's content is a mini-document behind the per-line prefix,
|
|
87
|
+
* so the quote owns a **nested parser state**: the outer parser strips one
|
|
88
|
+
* prefix level per line and feeds the remainder (including each line's
|
|
89
|
+
* terminating newline) to `inner`, whose opcodes pass through with positions
|
|
90
|
+
* remapped to source offsets. Nesting recurses — `inner` opens its own quote
|
|
91
|
+
* for deeper prefixes — so the outer parser tracks at most one quote
|
|
92
|
+
* directly. The id counter is shared (`inner.next_id` seeds from the outer's
|
|
93
|
+
* and syncs back at close), so pass-through opcodes need no id remapping.
|
|
94
|
+
*
|
|
95
|
+
* @nodocs
|
|
96
|
+
*/
|
|
97
|
+
export interface MdzBlockquoteState {
|
|
98
|
+
/** The Blockquote frame's node id. */
|
|
99
|
+
id: MdzNodeId;
|
|
100
|
+
/** The nested parser state for the quote's content document. */
|
|
101
|
+
inner: MdzStreamParserState;
|
|
102
|
+
/**
|
|
103
|
+
* Affine segments mapping inner-document offsets to global source
|
|
104
|
+
* offsets — one per quote line; the line's content and terminating
|
|
105
|
+
* newline are contiguous in both coordinate spaces.
|
|
106
|
+
*/
|
|
107
|
+
segments: Array<{
|
|
108
|
+
inner_start: number;
|
|
109
|
+
source_start: number;
|
|
110
|
+
}>;
|
|
111
|
+
/** Total bytes fed to the inner document so far. */
|
|
112
|
+
inner_len: number;
|
|
113
|
+
/**
|
|
114
|
+
* Inner-coordinate end of each live text node, tracked so forwarded
|
|
115
|
+
* `append_text` opcodes can carry explicit remapped `end`s — an implied
|
|
116
|
+
* extend-by-content-length is wrong across the prefix gap at line
|
|
117
|
+
* boundaries.
|
|
118
|
+
*/
|
|
119
|
+
text_inner_ends: Map<MdzNodeId, number>;
|
|
120
|
+
/** The attach item's marker indent for in-item quotes; -1 at top level. */
|
|
121
|
+
item_indent: number;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Counts of open inline containers by type, letting `find_open` answer the
|
|
125
|
+
* common "nothing open" case in O(1) instead of walking a stack that can grow
|
|
126
|
+
* arbitrarily deep with unclosed optimistic tags (tag-dense single-paragraph
|
|
127
|
+
* input leaks one `<Tag>` frame per line). Only the types `find_open` is
|
|
128
|
+
* queried with are counted. The counts are run-scoped for free: every run
|
|
129
|
+
* frame below the current one sealed by reverting its inlines (decrementing
|
|
130
|
+
* their counts), so all counted entries sit above the innermost run boundary
|
|
131
|
+
* (Paragraph, Heading, or ListItem).
|
|
132
|
+
*
|
|
133
|
+
* @nodocs
|
|
134
|
+
*/
|
|
135
|
+
export interface OpenInlineCounts {
|
|
136
|
+
Bold: number;
|
|
137
|
+
Italic: number;
|
|
138
|
+
Strikethrough: number;
|
|
139
|
+
Link: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Pending auto-link URL/path state for text-first rendering.
|
|
143
|
+
* When set, URL chars flow as visible text. On terminator, a `wrap` opcode
|
|
144
|
+
* retroactively wraps the text node in a Link.
|
|
145
|
+
*
|
|
146
|
+
* For URLs, `confirmed` starts false during speculative prefix matching
|
|
147
|
+
* (chars stream as text while we verify `https://` or `http://`).
|
|
148
|
+
* For paths, `confirmed` starts true (prefix already validated by hold).
|
|
149
|
+
*
|
|
150
|
+
* @nodocs
|
|
151
|
+
*/
|
|
152
|
+
export interface PendingUrl {
|
|
153
|
+
url_text: string;
|
|
154
|
+
start: number;
|
|
155
|
+
link_type: 'external' | 'internal';
|
|
156
|
+
/** Whether the URL/path prefix has been fully confirmed. */
|
|
157
|
+
confirmed: boolean;
|
|
158
|
+
/** Prefix match tracking — only used when `!confirmed`. */
|
|
159
|
+
viable_https: boolean;
|
|
160
|
+
viable_http: boolean;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Mutable state for the streaming parser. One instance per `MdzStreamParser`.
|
|
164
|
+
* Handlers in sibling modules take this as their first parameter — the streaming
|
|
165
|
+
* parser uses free functions, not class methods, so state crosses module
|
|
166
|
+
* boundaries.
|
|
167
|
+
*
|
|
168
|
+
* @nodocs
|
|
169
|
+
*/
|
|
170
|
+
export interface MdzStreamParserState {
|
|
171
|
+
buffer: string;
|
|
172
|
+
pos: number;
|
|
173
|
+
opcodes: Array<MdzOpcode>;
|
|
174
|
+
next_id: MdzNodeId;
|
|
175
|
+
stack: Array<StackEntry>;
|
|
176
|
+
column: number;
|
|
177
|
+
prev_char: number;
|
|
178
|
+
active_text_id: MdzNodeId | null;
|
|
179
|
+
accumulated_text: string;
|
|
180
|
+
accumulated_text_start: number;
|
|
181
|
+
/**
|
|
182
|
+
* Global byte offset just past the accumulated text's source span. Equals
|
|
183
|
+
* `accumulated_text_start + accumulated_text.length` except when list
|
|
184
|
+
* continuation lines strip structural indent — content is then shorter
|
|
185
|
+
* than its source span, and flushes carry this so consumers keep
|
|
186
|
+
* source-accurate node `end`s.
|
|
187
|
+
*/
|
|
188
|
+
accumulated_text_end: number;
|
|
189
|
+
codeblock: CodeblockState | null;
|
|
190
|
+
/**
|
|
191
|
+
* Open list levels, deepest last — the streaming analogue of the sync
|
|
192
|
+
* lexer's level stack in `#tokenize_list`. Non-empty exactly while
|
|
193
|
+
* List/ListItem frames are on `stack`; newlines then route to the list
|
|
194
|
+
* line classifier instead of the top-level paragraph-break scan.
|
|
195
|
+
*/
|
|
196
|
+
list_levels: Array<MdzListLevel>;
|
|
197
|
+
/**
|
|
198
|
+
* The open blockquote, or null. While set, all input routes through the
|
|
199
|
+
* quote (prefix stripping + nested-parser feeding) — see `MdzBlockquoteState`.
|
|
200
|
+
*/
|
|
201
|
+
blockquote: MdzBlockquoteState | null;
|
|
202
|
+
/**
|
|
203
|
+
* Whether the innermost open ListItem's first inline run is current.
|
|
204
|
+
* Content then flows directly into the ListItem frame — the sync AST
|
|
205
|
+
* keeps an item's first run as direct children — so `ensure_paragraph`
|
|
206
|
+
* is suppressed. Cleared when the run ends (blank line, dedent, block
|
|
207
|
+
* child); later runs in the item open `Paragraph` block children.
|
|
208
|
+
*/
|
|
209
|
+
in_list_item_run: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Source end (just past the marker chars) of the most recently opened
|
|
212
|
+
* empty list item — the close opcode's `end` when an item closes
|
|
213
|
+
* childless, mirroring the sync parser's `open.end` fallback. One slot
|
|
214
|
+
* suffices: only empty items can close childless, and at most one can be
|
|
215
|
+
* open untouched (anything emitted after it opened becomes its child;
|
|
216
|
+
* a sibling closes it before the next empty item opens).
|
|
217
|
+
*/
|
|
218
|
+
last_empty_item_end: number;
|
|
219
|
+
/** Global byte offset of the start of `buffer`. */
|
|
220
|
+
base_offset: number;
|
|
221
|
+
/**
|
|
222
|
+
* Per-needle search memo for `buffer_index_of`, keyed by needle.
|
|
223
|
+
* Created lazily — only `code_search_limit`'s cold path uses it, and the
|
|
224
|
+
* per-parser `Map` allocation is measurable on tiny inputs.
|
|
225
|
+
*/
|
|
226
|
+
search_memo: Map<string, BufferSearchMemo> | null;
|
|
227
|
+
/** Open-container counts for `find_open`'s O(1) "nothing open" early exit. */
|
|
228
|
+
open_counts: OpenInlineCounts;
|
|
229
|
+
/** Whether we're inside a heading (newline ends it). */
|
|
230
|
+
in_heading: boolean;
|
|
231
|
+
/** Whether we're inside an optimistic inline Code container. */
|
|
232
|
+
in_code: boolean;
|
|
233
|
+
/** Cached flag: whether a Paragraph is open on the stack. */
|
|
234
|
+
in_paragraph: boolean;
|
|
235
|
+
pending_url: PendingUrl | null;
|
|
236
|
+
/**
|
|
237
|
+
* Stack of text segments for heading ID computation.
|
|
238
|
+
* Each open container inside a heading pushes a new segment.
|
|
239
|
+
* On close: pop and append to parent (children's text is part of heading).
|
|
240
|
+
* On revert: pop, prepend replacement_text, append to parent
|
|
241
|
+
* (document order: delimiter text comes before children's text).
|
|
242
|
+
*/
|
|
243
|
+
heading_text_parts: Array<string>;
|
|
244
|
+
/**
|
|
245
|
+
* When true, absorb the blank region (newlines and whitespace-only lines)
|
|
246
|
+
* at the current position before normal processing. Set after block-element
|
|
247
|
+
* closes (codeblock, heading, HR) and paragraph breaks; stays set across
|
|
248
|
+
* chunks until a content line arrives — needed for char-by-char streaming
|
|
249
|
+
* where post-block blanks arrive in later chunks. Consumed by
|
|
250
|
+
* `skip_blank_region` in `mdz_stream_parser.ts`.
|
|
251
|
+
*/
|
|
252
|
+
skip_blank_lines: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* Stack index of the innermost open `Paragraph`, or `-1` when none.
|
|
255
|
+
* Lets `mark_paragraph_non_whitespace` skip the stack walk that runs on
|
|
256
|
+
* every non-whitespace emit. Updated only on Paragraph push/pop (block
|
|
257
|
+
* boundaries — only one of `Paragraph`/`Heading` can be on the stack
|
|
258
|
+
* at a time, so the cache is stable across inline pushes/pops).
|
|
259
|
+
*/
|
|
260
|
+
paragraph_stack_idx: number;
|
|
261
|
+
/**
|
|
262
|
+
* Id of the most-recent `text`/`append_text` emission, used by
|
|
263
|
+
* `trim_trailing_newline` to target the right opcode after `take_opcodes()`
|
|
264
|
+
* has drained the queue. `null` after a structural emit (open/close/revert)
|
|
265
|
+
* sealed the prior text run.
|
|
266
|
+
*/
|
|
267
|
+
last_text_id: MdzNodeId | null;
|
|
268
|
+
/** Whether the most recent text emission's content ended in `'\n'`. */
|
|
269
|
+
last_text_ended_with_newline: boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Whether the most recent text emission was a `text` opcode (not
|
|
272
|
+
* `append_text`) with content exactly `'\n'` — trimming the trailing \n
|
|
273
|
+
* would leave the text node empty, so `active_text_id` must be cleared
|
|
274
|
+
* to keep subsequent content from merging into a deleted node.
|
|
275
|
+
*/
|
|
276
|
+
last_text_was_singleton_newline: boolean;
|
|
277
|
+
}
|
|
278
|
+
/** @nodocs */
|
|
279
|
+
export declare const create_state: () => MdzStreamParserState;
|
|
280
|
+
/** @nodocs */
|
|
281
|
+
export declare const alloc_id: (state: MdzStreamParserState) => MdzNodeId;
|
|
282
|
+
/**
|
|
283
|
+
* Push a new container frame onto the stack. Fills the boilerplate fields
|
|
284
|
+
* (`has_children`, `has_non_whitespace_content`) so call sites only spell out
|
|
285
|
+
* what varies per container type. Keeping the object literal in one place
|
|
286
|
+
* also gives V8 a single monomorphic creation site for `StackEntry`.
|
|
287
|
+
*
|
|
288
|
+
* @nodocs
|
|
289
|
+
*/
|
|
290
|
+
export declare const push_stack_entry: (state: MdzStreamParserState, id: MdzNodeId, node_type: MdzNodeTypeContainer, start: number, delimiter?: string, tag_name?: string) => void;
|
|
291
|
+
/**
|
|
292
|
+
* Pop the top stack entry, keeping `open_counts` in sync. All pops of inline
|
|
293
|
+
* containers must go through this — the only direct stack removal elsewhere
|
|
294
|
+
* is `revert_failed_close`'s mid-stack splice, which adjusts the count itself.
|
|
295
|
+
*
|
|
296
|
+
* @mutates `state`
|
|
297
|
+
* @nodocs
|
|
298
|
+
*/
|
|
299
|
+
export declare const pop_stack_entry: (state: MdzStreamParserState) => StackEntry;
|
|
300
|
+
/**
|
|
301
|
+
* Global byte offset for a local buffer position.
|
|
302
|
+
*
|
|
303
|
+
* @nodocs
|
|
304
|
+
*/
|
|
305
|
+
export declare const offset: (state: MdzStreamParserState, pos?: number) => number;
|
|
306
|
+
/**
|
|
307
|
+
* Memoized buffer search for an arbitrary needle, backed by the per-needle
|
|
308
|
+
* `search_memo` map (created on first use). Used for cold-path scans with
|
|
309
|
+
* dynamic needles — the stack-delimiter searches in `code_search_limit`,
|
|
310
|
+
* where unclosed-tag delimiters absent from the rest of the input would
|
|
311
|
+
* otherwise rescan to the buffer end on every backtick candidate.
|
|
312
|
+
*
|
|
313
|
+
* @mutates `state.search_memo`
|
|
314
|
+
* @nodocs
|
|
315
|
+
*/
|
|
316
|
+
export declare const buffer_index_of: (state: MdzStreamParserState, needle: string, from: number) => number;
|
|
317
|
+
/**
|
|
318
|
+
* Emit an opcode into the pending batch (drained by `take_opcodes`),
|
|
319
|
+
* maintaining the `has_children`/non-whitespace bookkeeping on open frames.
|
|
320
|
+
*
|
|
321
|
+
* @nodocs
|
|
322
|
+
*/
|
|
323
|
+
export declare const emit: (state: MdzStreamParserState, op: MdzOpcode) => void;
|
|
324
|
+
/**
|
|
325
|
+
* Accumulate text, tracking the source span (start of the first character, end past the last).
|
|
326
|
+
*
|
|
327
|
+
* @nodocs
|
|
328
|
+
*/
|
|
329
|
+
export declare const accumulate_text: (state: MdzStreamParserState, text: string, start_offset: number) => void;
|
|
330
|
+
/**
|
|
331
|
+
* Extend the accumulated text's source span past content that was stripped
|
|
332
|
+
* from it — a list continuation line's structural indent. The sync parser
|
|
333
|
+
* attributes the stripped region to the preceding text token, so node `end`s
|
|
334
|
+
* stay source-accurate across both pipelines.
|
|
335
|
+
*
|
|
336
|
+
* @mutates `state`
|
|
337
|
+
* @nodocs
|
|
338
|
+
*/
|
|
339
|
+
export declare const extend_accumulated_end: (state: MdzStreamParserState, end: number) => void;
|
|
340
|
+
/**
|
|
341
|
+
* Flush accumulated text as a text or append_text opcode. Opcode `end`s come
|
|
342
|
+
* from the tracked source span, which can outgrow the content length when
|
|
343
|
+
* list continuation lines strip structural indent.
|
|
344
|
+
*
|
|
345
|
+
* @nodocs
|
|
346
|
+
*/
|
|
347
|
+
export declare const flush_text: (state: MdzStreamParserState) => void;
|
|
348
|
+
/**
|
|
349
|
+
* Open a Paragraph frame unless a run frame is already current — an open
|
|
350
|
+
* paragraph or heading, or a list item's first inline run (which flows
|
|
351
|
+
* directly into the ListItem frame, matching the sync AST's direct-children
|
|
352
|
+
* shape).
|
|
353
|
+
*
|
|
354
|
+
* @nodocs
|
|
355
|
+
*/
|
|
356
|
+
export declare const ensure_paragraph: (state: MdzStreamParserState) => void;
|
|
357
|
+
/**
|
|
358
|
+
* Whether a stack frame bounds an inline run — inline pairs never cross a
|
|
359
|
+
* Paragraph, Heading, or ListItem frame (an item's first run is a
|
|
360
|
+
* paragraph-equivalent region; a List frame is never the innermost frame
|
|
361
|
+
* under inline content, so checking it is unnecessary).
|
|
362
|
+
*
|
|
363
|
+
* @nodocs
|
|
364
|
+
*/
|
|
365
|
+
export declare const is_run_boundary: (node_type: MdzNodeTypeContainer) => boolean;
|
|
366
|
+
/**
|
|
367
|
+
* Find the innermost open container of a given type.
|
|
368
|
+
* Returns stack index, or -1 if not found.
|
|
369
|
+
* Does not cross run boundaries (Paragraph, Heading, ListItem).
|
|
370
|
+
*
|
|
371
|
+
* The "nothing open" case is O(1) via `open_counts` — without it, every
|
|
372
|
+
* candidate char in a deep-stack paragraph (unclosed optimistic tags leak
|
|
373
|
+
* one frame per line) walks to the block boundary, going quadratic.
|
|
374
|
+
*
|
|
375
|
+
* @nodocs
|
|
376
|
+
*/
|
|
377
|
+
export declare const find_open: (state: MdzStreamParserState, type: keyof OpenInlineCounts) => number;
|
|
378
|
+
/**
|
|
379
|
+
* Revert all stack entries above the given index. Every inline open is
|
|
380
|
+
* optimistic, so anything above a known frame is revertable by construction.
|
|
381
|
+
*
|
|
382
|
+
* @nodocs
|
|
383
|
+
*/
|
|
384
|
+
export declare const revert_above: (state: MdzStreamParserState, target_idx: number) => void;
|
|
385
|
+
/**
|
|
386
|
+
* Revert an open `Italic` whose first closer candidate failed its boundary
|
|
387
|
+
* check (italic is the only inline with closer-boundary rules). One-shot
|
|
388
|
+
* parsing greedy-rejects the opener at the first invalid closer, so once a
|
|
389
|
+
* failed candidate is seen, the optimistic open is known wrong — reverting
|
|
390
|
+
* immediately (instead of leaving the container open for a later closer)
|
|
391
|
+
* keeps chunked output identical to the one-shot parse.
|
|
392
|
+
*
|
|
393
|
+
* Unlike `revert_above`, this reverts a possibly
|
|
394
|
+
* **mid-stack** entry: containers opened above it (e.g. a Bold inside the
|
|
395
|
+
* failed Italic) stay open — the one-shot parse opens them at top level, and
|
|
396
|
+
* the consumers' revert handlers re-parent them identically (the reverted
|
|
397
|
+
* node is still its parent's last child; see `mdz_opcodes_to_nodes` and
|
|
398
|
+
* `MdzStreamState`).
|
|
399
|
+
*
|
|
400
|
+
* Bypasses `emit` for the opcode push: `emit`'s heading-segment handling
|
|
401
|
+
* assumes the reverted container is the innermost open one, which doesn't
|
|
402
|
+
* hold mid-stack — the segment merge here targets the reverted frame's own
|
|
403
|
+
* segment, keeping the segments of still-open frames above it live.
|
|
404
|
+
*
|
|
405
|
+
* @mutates `state`
|
|
406
|
+
* @nodocs
|
|
407
|
+
*/
|
|
408
|
+
export declare const revert_failed_close: (state: MdzStreamParserState, stack_idx: number) => void;
|
|
409
|
+
/**
|
|
410
|
+
* Trim a trailing newline from paragraph content.
|
|
411
|
+
* Checks unflushed accumulated text first; otherwise emits a `trim_text`
|
|
412
|
+
* opcode targeting the most recent text/append_text via the tracking fields
|
|
413
|
+
* on `state` (which survive `take_opcodes()` drains). The opcode stream
|
|
414
|
+
* stays append-only — no retroactive opcode mutation.
|
|
415
|
+
*
|
|
416
|
+
* @nodocs
|
|
417
|
+
*/
|
|
418
|
+
export declare const trim_trailing_newline: (state: MdzStreamParserState) => void;
|
|
419
|
+
/** @nodocs */
|
|
420
|
+
export declare const close_paragraph: (state: MdzStreamParserState) => void;
|
|
421
|
+
/** @nodocs */
|
|
422
|
+
export declare const close_heading: (state: MdzStreamParserState) => void;
|
|
423
|
+
/**
|
|
424
|
+
* Close a codeblock left open at EOF. Raw mode is absolute — an unclosed
|
|
425
|
+
* fence consumes to EOF as content — so this is a plain close after trimming
|
|
426
|
+
* one trailing newline, matching closed fences' content shape (which
|
|
427
|
+
* excludes the newline before the closer line) and the sync parser's
|
|
428
|
+
* unclosed-fence trim.
|
|
429
|
+
*
|
|
430
|
+
* @nodocs
|
|
431
|
+
*/
|
|
432
|
+
export declare const close_codeblock_at_eof: (state: MdzStreamParserState) => void;
|
|
433
|
+
/**
|
|
434
|
+
* Seal the innermost ListItem's first inline run: flush text and revert the
|
|
435
|
+
* optimistic inlines above the ListItem frame. The item itself stays open —
|
|
436
|
+
* block children (nested lists, paragraphs, code blocks) may follow.
|
|
437
|
+
*
|
|
438
|
+
* @nodocs
|
|
439
|
+
*/
|
|
440
|
+
export declare const seal_list_item_run: (state: MdzStreamParserState) => void;
|
|
441
|
+
/**
|
|
442
|
+
* Close the current inline run inside a list, whichever frame holds it: a
|
|
443
|
+
* `Paragraph` block child closes, an item's first run seals. No-op when no
|
|
444
|
+
* run is current (post-blank, post-block-child).
|
|
445
|
+
*
|
|
446
|
+
* @nodocs
|
|
447
|
+
*/
|
|
448
|
+
export declare const close_list_run: (state: MdzStreamParserState) => void;
|
|
449
|
+
/**
|
|
450
|
+
* Close the deepest open level's current item. The run must already be
|
|
451
|
+
* sealed/closed, leaving the ListItem frame on top of the stack. A childless
|
|
452
|
+
* close means an empty item — its `end` is the marker end recorded at open
|
|
453
|
+
* (the sync parser's `open.end` fallback); otherwise consumers derive the
|
|
454
|
+
* node's `end` from its children, so the offset here is cosmetic.
|
|
455
|
+
*
|
|
456
|
+
* @nodocs
|
|
457
|
+
*/
|
|
458
|
+
export declare const close_list_item: (state: MdzStreamParserState) => void;
|
|
459
|
+
/**
|
|
460
|
+
* Close the deepest open level: its current item, then its list.
|
|
461
|
+
*
|
|
462
|
+
* @nodocs
|
|
463
|
+
*/
|
|
464
|
+
export declare const close_list_level: (state: MdzStreamParserState) => void;
|
|
465
|
+
/**
|
|
466
|
+
* Close every open list level — the whole stack — sealing the item's first
|
|
467
|
+
* run if current. A current `Paragraph` block child must be closed by the
|
|
468
|
+
* caller first (`close_paragraph` in `finish()`, `close_list_run` in the
|
|
469
|
+
* classifier).
|
|
470
|
+
*
|
|
471
|
+
* @nodocs
|
|
472
|
+
*/
|
|
473
|
+
export declare const close_all_list_levels: (state: MdzStreamParserState) => void;
|
|
474
|
+
/** @nodocs */
|
|
475
|
+
export declare const handle_paragraph_break: (state: MdzStreamParserState) => void;
|
|
476
|
+
//# sourceMappingURL=mdz_stream_parser_state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdz_stream_parser_state.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/mdz_stream_parser_state.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,oBAAoB,EAAE,SAAS,EAAE,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAGjF;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC;AAE/D,cAAc;AACd,MAAM,WAAW,UAAU;IAC1B,EAAE,EAAE,SAAS,CAAC;IACd,SAAS,EAAE,oBAAoB,CAAC;IAChC;;;;;OAKG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,wEAAwE;IACxE,YAAY,EAAE,OAAO,CAAC;IACtB;;;;OAIG;IACH,0BAA0B,EAAE,OAAO,CAAC;IACpC,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,gBA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