@fuzdev/mdz 0.1.0 → 0.2.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/README.md +4 -0
- package/dist/MdzNodeView.svelte +30 -1
- package/dist/MdzNodeView.svelte.d.ts.map +1 -1
- package/dist/MdzStreamNodeView.svelte +31 -0
- package/dist/MdzStreamNodeView.svelte.d.ts.map +1 -1
- package/dist/context_helpers.d.ts +1 -1
- package/dist/mdz.d.ts +53 -2
- package/dist/mdz.d.ts.map +1 -1
- package/dist/mdz.js +29 -1
- package/dist/mdz_helpers.d.ts +35 -1
- package/dist/mdz_helpers.d.ts.map +1 -1
- package/dist/mdz_helpers.js +120 -0
- package/dist/mdz_lexer.d.ts +35 -1
- package/dist/mdz_lexer.d.ts.map +1 -1
- package/dist/mdz_lexer.js +211 -2
- package/dist/mdz_opcodes.d.ts +6 -1
- package/dist/mdz_opcodes.d.ts.map +1 -1
- package/dist/mdz_opcodes_to_nodes.d.ts.map +1 -1
- package/dist/mdz_opcodes_to_nodes.js +26 -0
- package/dist/mdz_stream_parser.d.ts.map +1 -1
- package/dist/mdz_stream_parser.js +20 -1
- package/dist/mdz_stream_parser_list.d.ts.map +1 -1
- package/dist/mdz_stream_parser_list.js +22 -1
- package/dist/mdz_stream_parser_state.d.ts +12 -0
- package/dist/mdz_stream_parser_state.d.ts.map +1 -1
- package/dist/mdz_stream_parser_state.js +1 -0
- package/dist/mdz_stream_parser_table.d.ts +72 -0
- package/dist/mdz_stream_parser_table.d.ts.map +1 -0
- package/dist/mdz_stream_parser_table.js +351 -0
- package/dist/mdz_stream_state.svelte.d.ts +5 -0
- package/dist/mdz_stream_state.svelte.d.ts.map +1 -1
- package/dist/mdz_stream_state.svelte.js +8 -0
- package/dist/mdz_to_svelte.d.ts.map +1 -1
- package/dist/mdz_to_svelte.js +37 -3
- package/dist/mdz_token_parser.d.ts +16 -0
- package/dist/mdz_token_parser.d.ts.map +1 -1
- package/dist/mdz_token_parser.js +101 -2
- package/dist/svelte_preprocess_mdz.js +2 -2
- package/package.json +8 -8
- package/src/lib/context_helpers.ts +1 -1
- package/src/lib/mdz.ts +70 -3
- package/src/lib/mdz_contexts.ts +1 -1
- package/src/lib/mdz_helpers.ts +125 -1
- package/src/lib/mdz_lexer.ts +262 -3
- package/src/lib/mdz_opcodes.ts +10 -1
- package/src/lib/mdz_opcodes_to_nodes.ts +37 -3
- package/src/lib/mdz_stream_parser.ts +26 -9
- package/src/lib/mdz_stream_parser_block.ts +2 -2
- package/src/lib/mdz_stream_parser_inline.ts +4 -4
- package/src/lib/mdz_stream_parser_link.ts +3 -3
- package/src/lib/mdz_stream_parser_list.ts +24 -2
- package/src/lib/mdz_stream_parser_state.ts +12 -2
- package/src/lib/mdz_stream_parser_table.ts +409 -0
- package/src/lib/mdz_stream_parser_text.ts +2 -2
- package/src/lib/mdz_stream_parser_url.ts +2 -2
- package/src/lib/mdz_stream_state.svelte.ts +8 -1
- package/src/lib/mdz_to_svelte.ts +39 -5
- package/src/lib/mdz_token_parser.ts +122 -5
- package/src/lib/svelte_preprocess_mdz.ts +4 -4
- package/src/lib/tsdoc_mdz.ts +1 -1
|
@@ -18,16 +18,19 @@ import type {
|
|
|
18
18
|
MdzNodeList,
|
|
19
19
|
MdzNodeListItem,
|
|
20
20
|
MdzNodeBlockquote,
|
|
21
|
+
MdzNodeTable,
|
|
22
|
+
MdzNodeTableRow,
|
|
23
|
+
MdzNodeTableCell,
|
|
21
24
|
MdzNodeElement,
|
|
22
25
|
MdzNodeComponent,
|
|
23
|
-
} from './mdz.
|
|
26
|
+
} from './mdz.ts';
|
|
24
27
|
import {
|
|
25
28
|
has_non_whitespace,
|
|
26
29
|
mdz_extract_single_tag,
|
|
27
30
|
mdz_heading_id,
|
|
28
31
|
mdz_merge_adjacent_text,
|
|
29
32
|
mdz_push_merging_text,
|
|
30
|
-
} from './mdz_helpers.
|
|
33
|
+
} from './mdz_helpers.ts';
|
|
31
34
|
import {
|
|
32
35
|
type MdzToken,
|
|
33
36
|
type MdzTokenHeadingStart,
|
|
@@ -38,7 +41,10 @@ import {
|
|
|
38
41
|
type MdzTokenTagSelfClose,
|
|
39
42
|
type MdzTokenListOpen,
|
|
40
43
|
type MdzTokenListItemOpen,
|
|
41
|
-
|
|
44
|
+
type MdzTokenTableOpen,
|
|
45
|
+
type MdzTokenTableRowOpen,
|
|
46
|
+
type MdzTokenTableCellOpen,
|
|
47
|
+
} from './mdz_lexer.ts';
|
|
42
48
|
|
|
43
49
|
/**
|
|
44
50
|
* Builds an `MdzNode[]` tree from a lexed `MdzToken[]` stream.
|
|
@@ -52,10 +58,38 @@ export class MdzTokenParser {
|
|
|
52
58
|
this.#tokens = tokens;
|
|
53
59
|
}
|
|
54
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Rebind to a new token stream and rewind, so one parser instance can be
|
|
63
|
+
* reused across inputs — the streaming table path reuses one across a row's
|
|
64
|
+
* cells via `MdzTableCellParser`.
|
|
65
|
+
*
|
|
66
|
+
* @nodocs
|
|
67
|
+
*/
|
|
68
|
+
reset(tokens: Array<MdzToken>): void {
|
|
69
|
+
this.#tokens = tokens;
|
|
70
|
+
this.#index = 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
55
73
|
parse(): Array<MdzNode> {
|
|
56
74
|
return this.#parse_block_stream(false);
|
|
57
75
|
}
|
|
58
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Parse the entire token stream as a single inline run — used for table
|
|
79
|
+
* cells, whose tokens come from `MdzLexer.lex_table_cell`. Adjacent text
|
|
80
|
+
* merges as it accumulates, matching `#parse_table_cell`.
|
|
81
|
+
*
|
|
82
|
+
* @nodocs
|
|
83
|
+
*/
|
|
84
|
+
parse_inline_run(): Array<MdzNode> {
|
|
85
|
+
const children: Array<MdzNode> = [];
|
|
86
|
+
while (this.#index < this.#tokens.length) {
|
|
87
|
+
const node = this.#parse_inline();
|
|
88
|
+
if (node) mdz_push_merging_text(children, node);
|
|
89
|
+
}
|
|
90
|
+
return children;
|
|
91
|
+
}
|
|
92
|
+
|
|
59
93
|
/**
|
|
60
94
|
* Parse a run of block-level tokens into nodes — the document root, or a
|
|
61
95
|
* blockquote's contents (a quote's content is a mini-document, so both
|
|
@@ -118,6 +152,13 @@ export class MdzTokenParser {
|
|
|
118
152
|
continue;
|
|
119
153
|
}
|
|
120
154
|
|
|
155
|
+
if (token.type === 'table_open') {
|
|
156
|
+
const flushed = this.#flush_paragraph(paragraph_children, true);
|
|
157
|
+
if (flushed) nodes.push(flushed);
|
|
158
|
+
nodes.push(this.#parse_table());
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
|
|
121
162
|
if (token.type === 'paragraph_break') {
|
|
122
163
|
const flushed = this.#flush_paragraph(paragraph_children, true);
|
|
123
164
|
if (flushed) nodes.push(flushed);
|
|
@@ -147,6 +188,74 @@ export class MdzTokenParser {
|
|
|
147
188
|
return {type: 'Blockquote', children, start: open.start, end};
|
|
148
189
|
}
|
|
149
190
|
|
|
191
|
+
#parse_table(): MdzNodeTable {
|
|
192
|
+
const open = this.#tokens[this.#index]! as MdzTokenTableOpen;
|
|
193
|
+
this.#index++;
|
|
194
|
+
|
|
195
|
+
const rows: Array<MdzNodeTableRow> = [];
|
|
196
|
+
|
|
197
|
+
while (this.#index < this.#tokens.length) {
|
|
198
|
+
const t = this.#tokens[this.#index]!;
|
|
199
|
+
if (t.type === 'table_row_open') {
|
|
200
|
+
rows.push(this.#parse_table_row());
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (t.type === 'table_close') {
|
|
204
|
+
this.#index++;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
this.#index++; // skip anything unexpected (defensive)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const end = rows.length > 0 ? rows[rows.length - 1]!.end : open.end;
|
|
211
|
+
return {type: 'Table', align: open.align, children: rows, start: open.start, end};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
#parse_table_row(): MdzNodeTableRow {
|
|
215
|
+
const open = this.#tokens[this.#index]! as MdzTokenTableRowOpen;
|
|
216
|
+
const header = open.header;
|
|
217
|
+
this.#index++;
|
|
218
|
+
|
|
219
|
+
const cells: Array<MdzNodeTableCell> = [];
|
|
220
|
+
|
|
221
|
+
while (this.#index < this.#tokens.length) {
|
|
222
|
+
const t = this.#tokens[this.#index]!;
|
|
223
|
+
if (t.type === 'table_cell_open') {
|
|
224
|
+
cells.push(this.#parse_table_cell());
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (t.type === 'table_row_close') {
|
|
228
|
+
this.#index++;
|
|
229
|
+
return {type: 'TableRow', header, children: cells, start: open.start, end: t.end};
|
|
230
|
+
}
|
|
231
|
+
this.#index++; // skip anything unexpected (defensive)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const end = cells.length > 0 ? cells[cells.length - 1]!.end : open.end;
|
|
235
|
+
return {type: 'TableRow', header, children: cells, start: open.start, end};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
#parse_table_cell(): MdzNodeTableCell {
|
|
239
|
+
const open = this.#tokens[this.#index]! as MdzTokenTableCellOpen;
|
|
240
|
+
const start = open.start;
|
|
241
|
+
this.#index++;
|
|
242
|
+
|
|
243
|
+
const children: Array<MdzNode> = [];
|
|
244
|
+
|
|
245
|
+
while (this.#index < this.#tokens.length) {
|
|
246
|
+
const t = this.#tokens[this.#index]!;
|
|
247
|
+
if (t.type === 'table_cell_close') {
|
|
248
|
+
this.#index++;
|
|
249
|
+
return {type: 'TableCell', children, start, end: t.end};
|
|
250
|
+
}
|
|
251
|
+
const node = this.#parse_inline();
|
|
252
|
+
if (node) mdz_push_merging_text(children, node);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const end = children.length > 0 ? children[children.length - 1]!.end : open.end;
|
|
256
|
+
return {type: 'TableCell', children, start, end};
|
|
257
|
+
}
|
|
258
|
+
|
|
150
259
|
#parse_heading(): MdzNodeHeading {
|
|
151
260
|
const token = this.#tokens[this.#index]! as MdzTokenHeadingStart;
|
|
152
261
|
const start = token.start;
|
|
@@ -238,6 +347,12 @@ export class MdzTokenParser {
|
|
|
238
347
|
children.push(this.#parse_blockquote());
|
|
239
348
|
continue;
|
|
240
349
|
}
|
|
350
|
+
if (t.type === 'table_open') {
|
|
351
|
+
flush();
|
|
352
|
+
in_paragraph = false;
|
|
353
|
+
children.push(this.#parse_table());
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
241
356
|
if (t.type === 'codeblock') {
|
|
242
357
|
flush();
|
|
243
358
|
in_paragraph = false;
|
|
@@ -382,7 +497,8 @@ export class MdzTokenParser {
|
|
|
382
497
|
t.type === 'codeblock' ||
|
|
383
498
|
t.type === 'list_open' ||
|
|
384
499
|
t.type === 'list_item_close' ||
|
|
385
|
-
t.type === 'blockquote_open'
|
|
500
|
+
t.type === 'blockquote_open' ||
|
|
501
|
+
t.type === 'table_open'
|
|
386
502
|
) {
|
|
387
503
|
break;
|
|
388
504
|
}
|
|
@@ -430,7 +546,8 @@ export class MdzTokenParser {
|
|
|
430
546
|
t.type === 'codeblock' ||
|
|
431
547
|
t.type === 'list_open' ||
|
|
432
548
|
t.type === 'list_item_close' ||
|
|
433
|
-
t.type === 'blockquote_open'
|
|
549
|
+
t.type === 'blockquote_open' ||
|
|
550
|
+
t.type === 'table_open'
|
|
434
551
|
) {
|
|
435
552
|
break;
|
|
436
553
|
}
|
|
@@ -18,7 +18,7 @@ import type {ImportDeclaration, VariableDeclaration} from 'estree';
|
|
|
18
18
|
import {parse, type PreprocessorGroup, type AST} from 'svelte/compiler';
|
|
19
19
|
import MagicString from 'magic-string';
|
|
20
20
|
import {walk} from 'zimmerframe';
|
|
21
|
-
import {should_exclude_path} from '@fuzdev/fuz_util/path.
|
|
21
|
+
import {should_exclude_path} from '@fuzdev/fuz_util/path.ts';
|
|
22
22
|
import {
|
|
23
23
|
find_attribute,
|
|
24
24
|
extract_static_string,
|
|
@@ -34,10 +34,10 @@ import {
|
|
|
34
34
|
handle_preprocess_error,
|
|
35
35
|
type PreprocessImportInfo,
|
|
36
36
|
type ResolvedComponentImport,
|
|
37
|
-
} from '@fuzdev/fuz_util/svelte_preprocess_helpers.
|
|
37
|
+
} from '@fuzdev/fuz_util/svelte_preprocess_helpers.ts';
|
|
38
38
|
|
|
39
|
-
import {mdz_parse} from './mdz.
|
|
40
|
-
import {mdz_to_svelte} from './mdz_to_svelte.
|
|
39
|
+
import {mdz_parse} from './mdz.ts';
|
|
40
|
+
import {mdz_to_svelte} from './mdz_to_svelte.ts';
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* An estree `ImportDeclaration` augmented with Svelte's position data.
|
package/src/lib/tsdoc_mdz.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import {mdz_is_url} from './mdz_helpers.
|
|
11
|
+
import {mdz_is_url} from './mdz_helpers.ts';
|
|
12
12
|
|
|
13
13
|
/** Format a reference as mdz: URLs pass through, identifiers get backticks. */
|
|
14
14
|
const format_reference = (ref: string): string => (mdz_is_url(ref) ? ref : `\`${ref}\``);
|