@fuzdev/mdz 0.3.0 → 0.4.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/Mdz.svelte +8 -7
- package/dist/Mdz.svelte.d.ts.map +1 -1
- package/dist/MdzNodeView.svelte +20 -12
- package/dist/MdzNodeView.svelte.d.ts +1 -2
- package/dist/MdzNodeView.svelte.d.ts.map +1 -1
- package/dist/MdzPrecompiled.svelte +3 -3
- package/dist/MdzPrecompiled.svelte.d.ts.map +1 -1
- package/dist/MdzRoot.svelte +3 -3
- package/dist/MdzRoot.svelte.d.ts.map +1 -1
- package/dist/MdzStream.svelte +3 -3
- package/dist/MdzStream.svelte.d.ts.map +1 -1
- package/dist/MdzStreamNodeView.svelte +21 -13
- package/dist/MdzStreamNodeView.svelte.d.ts +1 -2
- package/dist/MdzStreamNodeView.svelte.d.ts.map +1 -1
- package/dist/context_helpers.js +1 -1
- package/dist/mdz_contexts.d.ts.map +1 -1
- package/dist/mdz_debug_work.d.ts.map +1 -1
- package/dist/mdz_helpers.d.ts.map +1 -1
- package/dist/mdz_helpers.js +2 -2
- package/dist/mdz_lexer.d.ts.map +1 -1
- package/dist/mdz_lexer.js +27 -17
- 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 +22 -17
- package/dist/mdz_stream_parser.d.ts.map +1 -1
- package/dist/mdz_stream_parser.js +8 -8
- package/dist/mdz_stream_parser_block.js +5 -5
- package/dist/mdz_stream_parser_inline.js +4 -4
- package/dist/mdz_stream_parser_link.js +3 -3
- package/dist/mdz_stream_parser_list.d.ts.map +1 -1
- package/dist/mdz_stream_parser_list.js +13 -7
- package/dist/mdz_stream_parser_state.d.ts.map +1 -1
- package/dist/mdz_stream_parser_state.js +7 -7
- package/dist/mdz_stream_parser_table.d.ts.map +1 -1
- package/dist/mdz_stream_parser_table.js +8 -8
- package/dist/mdz_stream_parser_text.js +2 -2
- package/dist/mdz_stream_parser_url.js +7 -7
- package/dist/mdz_stream_state.svelte.d.ts.map +1 -1
- package/dist/mdz_to_svelte.d.ts +1 -1
- package/dist/mdz_to_svelte.d.ts.map +1 -1
- package/dist/mdz_token_parser.js +9 -9
- package/dist/svelte_preprocess_mdz.d.ts +2 -2
- package/dist/svelte_preprocess_mdz.d.ts.map +1 -1
- package/dist/svelte_preprocess_mdz.js +11 -11
- package/package.json +24 -39
- package/src/lib/context_helpers.ts +2 -2
- package/src/lib/mdz.ts +2 -2
- package/src/lib/mdz_contexts.ts +5 -5
- package/src/lib/mdz_debug_work.ts +1 -1
- package/src/lib/mdz_helpers.ts +39 -33
- package/src/lib/mdz_lexer.ts +77 -67
- package/src/lib/mdz_opcodes.ts +1 -1
- package/src/lib/mdz_opcodes_to_nodes.ts +35 -30
- package/src/lib/mdz_stream_parser.ts +17 -17
- package/src/lib/mdz_stream_parser_block.ts +14 -14
- package/src/lib/mdz_stream_parser_inline.ts +18 -18
- package/src/lib/mdz_stream_parser_link.ts +13 -13
- package/src/lib/mdz_stream_parser_list.ts +31 -25
- package/src/lib/mdz_stream_parser_state.ts +27 -27
- package/src/lib/mdz_stream_parser_table.ts +31 -31
- package/src/lib/mdz_stream_parser_text.ts +3 -3
- package/src/lib/mdz_stream_parser_url.ts +11 -11
- package/src/lib/mdz_stream_state.svelte.ts +8 -8
- package/src/lib/mdz_to_svelte.ts +16 -16
- package/src/lib/mdz_token_parser.ts +38 -38
- package/src/lib/svelte_preprocess_mdz.ts +62 -58
- package/src/lib/tsdoc_mdz.ts +1 -1
package/src/lib/mdz_lexer.ts
CHANGED
|
@@ -55,11 +55,11 @@ import {
|
|
|
55
55
|
TEXT_CLASS_NEWLINE,
|
|
56
56
|
TEXT_CLASS_STOP,
|
|
57
57
|
TEXT_CLASS_URL,
|
|
58
|
-
TEXT_SCAN_CLASS
|
|
58
|
+
TEXT_SCAN_CLASS
|
|
59
59
|
} from './mdz_helpers.ts';
|
|
60
60
|
|
|
61
|
-
import type {MdzTableAlign} from './mdz.ts';
|
|
62
|
-
import {mdz_debug_work} from './mdz_debug_work.ts';
|
|
61
|
+
import type { MdzTableAlign } from './mdz.ts';
|
|
62
|
+
import { mdz_debug_work } from './mdz_debug_work.ts';
|
|
63
63
|
|
|
64
64
|
//
|
|
65
65
|
// Token types
|
|
@@ -295,8 +295,8 @@ export class MdzLexer {
|
|
|
295
295
|
#index: number = 0;
|
|
296
296
|
#tokens: Array<MdzToken> = [];
|
|
297
297
|
#max_search_index: number = Number.MAX_SAFE_INTEGER;
|
|
298
|
-
#search_memo: Map<string, {from: number; result: number}> = new Map();
|
|
299
|
-
#break_memo: {from: number; result: number} | null = null;
|
|
298
|
+
#search_memo: Map<string, { from: number; result: number }> = new Map();
|
|
299
|
+
#break_memo: { from: number; result: number } | null = null;
|
|
300
300
|
/**
|
|
301
301
|
* Whether `#tokenize_text` is inside a list-item inline run: single
|
|
302
302
|
* newlines are soft breaks whose following structural indent strips from
|
|
@@ -394,7 +394,7 @@ export class MdzLexer {
|
|
|
394
394
|
mdz_debug_work.total += (result === -1 ? this.#text.length : result) - from;
|
|
395
395
|
}
|
|
396
396
|
if (memo === undefined) {
|
|
397
|
-
this.#search_memo.set(needle, {from, result});
|
|
397
|
+
this.#search_memo.set(needle, { from, result });
|
|
398
398
|
} else {
|
|
399
399
|
memo.from = from;
|
|
400
400
|
memo.result = result;
|
|
@@ -421,7 +421,7 @@ export class MdzLexer {
|
|
|
421
421
|
if (this.#is_at_paragraph_break()) {
|
|
422
422
|
const start = this.#index;
|
|
423
423
|
this.#skip_blank_lines();
|
|
424
|
-
this.#tokens.push({type: 'paragraph_break', start, end: this.#index});
|
|
424
|
+
this.#tokens.push({ type: 'paragraph_break', start, end: this.#index });
|
|
425
425
|
continue;
|
|
426
426
|
}
|
|
427
427
|
|
|
@@ -540,7 +540,7 @@ export class MdzLexer {
|
|
|
540
540
|
type: 'heading_start',
|
|
541
541
|
level: hash_count as 1 | 2 | 3 | 4 | 5 | 6,
|
|
542
542
|
start,
|
|
543
|
-
end: this.#index
|
|
543
|
+
end: this.#index // end of "## " prefix
|
|
544
544
|
});
|
|
545
545
|
|
|
546
546
|
// Find end-of-line to bound nested tokenizers (prevents tag scanner from scanning past heading)
|
|
@@ -580,7 +580,7 @@ export class MdzLexer {
|
|
|
580
580
|
this.#max_search_index = saved_max;
|
|
581
581
|
|
|
582
582
|
// Emit heading_end marker so the token parser knows where heading content stops
|
|
583
|
-
this.#tokens.push({type: 'heading_end', start: this.#index, end: this.#index});
|
|
583
|
+
this.#tokens.push({ type: 'heading_end', start: this.#index, end: this.#index });
|
|
584
584
|
|
|
585
585
|
// Skip newlines after heading
|
|
586
586
|
this.#skip_blank_lines();
|
|
@@ -613,7 +613,7 @@ export class MdzLexer {
|
|
|
613
613
|
const start = this.#index;
|
|
614
614
|
this.#index = i; // consume up to but not including newline
|
|
615
615
|
|
|
616
|
-
this.#tokens.push({type: 'hr', start, end: this.#index});
|
|
616
|
+
this.#tokens.push({ type: 'hr', start, end: this.#index });
|
|
617
617
|
|
|
618
618
|
// Skip newlines after HR
|
|
619
619
|
this.#skip_blank_lines();
|
|
@@ -641,7 +641,7 @@ export class MdzLexer {
|
|
|
641
641
|
* Match a quote prefix in the complete sync text — never `'pending'`.
|
|
642
642
|
* See `mdz_match_blockquote_prefix`.
|
|
643
643
|
*/
|
|
644
|
-
#match_blockquote_prefix(i: number): {depth: number; content_start: number} | null {
|
|
644
|
+
#match_blockquote_prefix(i: number): { depth: number; content_start: number } | null {
|
|
645
645
|
const prefix = mdz_match_blockquote_prefix(this.#text, i, true);
|
|
646
646
|
return prefix === 'pending' ? null : prefix;
|
|
647
647
|
}
|
|
@@ -694,7 +694,7 @@ export class MdzLexer {
|
|
|
694
694
|
// quote's content parses exactly like a standalone document (a complete
|
|
695
695
|
// fence opener line on the last quote line opens an empty fence, not text)
|
|
696
696
|
const parts: Array<string> = [];
|
|
697
|
-
const segments: Array<{inner_start: number; source_start: number}> = [];
|
|
697
|
+
const segments: Array<{ inner_start: number; source_start: number }> = [];
|
|
698
698
|
let inner_len = 0;
|
|
699
699
|
let line_first = first;
|
|
700
700
|
let last_line_end = first;
|
|
@@ -702,7 +702,7 @@ export class MdzLexer {
|
|
|
702
702
|
const strip = line_first + mdz_blockquote_strip_width(this.#text, line_first);
|
|
703
703
|
let nl = this.#text.indexOf('\n', line_first);
|
|
704
704
|
if (nl === -1) nl = this.#text.length;
|
|
705
|
-
segments.push({inner_start: inner_len, source_start: strip});
|
|
705
|
+
segments.push({ inner_start: inner_len, source_start: strip });
|
|
706
706
|
const content = this.#text.slice(Math.min(strip, nl), nl < this.#text.length ? nl + 1 : nl);
|
|
707
707
|
parts.push(content);
|
|
708
708
|
inner_len += content.length;
|
|
@@ -727,14 +727,14 @@ export class MdzLexer {
|
|
|
727
727
|
line_first = next_first;
|
|
728
728
|
}
|
|
729
729
|
|
|
730
|
-
this.#tokens.push({type: 'blockquote_open', start: first, end: first});
|
|
730
|
+
this.#tokens.push({ type: 'blockquote_open', start: first, end: first });
|
|
731
731
|
const inner_tokens = new MdzLexer(parts.join('')).tokenize();
|
|
732
732
|
for (const token of inner_tokens) {
|
|
733
733
|
token.start = mdz_remap_segments(segments, token.start);
|
|
734
734
|
token.end = mdz_remap_segments(segments, token.end);
|
|
735
735
|
this.#tokens.push(token);
|
|
736
736
|
}
|
|
737
|
-
this.#tokens.push({type: 'blockquote_close', start: last_line_end, end: last_line_end});
|
|
737
|
+
this.#tokens.push({ type: 'blockquote_close', start: last_line_end, end: last_line_end });
|
|
738
738
|
this.#index = last_line_end;
|
|
739
739
|
}
|
|
740
740
|
|
|
@@ -763,7 +763,7 @@ export class MdzLexer {
|
|
|
763
763
|
if (align === null || align.length !== header_cells.length) return false;
|
|
764
764
|
|
|
765
765
|
// committed — emit the table; the delimiter row is structural (not emitted)
|
|
766
|
-
this.#tokens.push({type: 'table_open', align, start: table_start, end: header_end});
|
|
766
|
+
this.#tokens.push({ type: 'table_open', align, start: table_start, end: header_end });
|
|
767
767
|
this.#emit_table_row(header_cells, true, table_start, header_end);
|
|
768
768
|
|
|
769
769
|
this.#index = delim_end;
|
|
@@ -781,23 +781,23 @@ export class MdzLexer {
|
|
|
781
781
|
table_end = row_end;
|
|
782
782
|
}
|
|
783
783
|
|
|
784
|
-
this.#tokens.push({type: 'table_close', start: table_end, end: table_end});
|
|
784
|
+
this.#tokens.push({ type: 'table_close', start: table_end, end: table_end });
|
|
785
785
|
this.#skip_blank_lines();
|
|
786
786
|
return true;
|
|
787
787
|
}
|
|
788
788
|
|
|
789
789
|
/** Emit one table row's open / cell / close tokens. */
|
|
790
790
|
#emit_table_row(
|
|
791
|
-
cells: Array<{start: number; end: number}>,
|
|
791
|
+
cells: Array<{ start: number; end: number }>,
|
|
792
792
|
header: boolean,
|
|
793
793
|
row_start: number,
|
|
794
|
-
row_end: number
|
|
794
|
+
row_end: number
|
|
795
795
|
): void {
|
|
796
|
-
this.#tokens.push({type: 'table_row_open', header, start: row_start, end: row_start});
|
|
796
|
+
this.#tokens.push({ type: 'table_row_open', header, start: row_start, end: row_start });
|
|
797
797
|
for (const cell of cells) {
|
|
798
798
|
this.#emit_table_cell(cell.start, cell.end);
|
|
799
799
|
}
|
|
800
|
-
this.#tokens.push({type: 'table_row_close', start: row_end, end: row_end});
|
|
800
|
+
this.#tokens.push({ type: 'table_row_close', start: row_end, end: row_end });
|
|
801
801
|
}
|
|
802
802
|
|
|
803
803
|
/**
|
|
@@ -807,9 +807,9 @@ export class MdzLexer {
|
|
|
807
807
|
* stops at that bound and unescapes `\|`.
|
|
808
808
|
*/
|
|
809
809
|
#emit_table_cell(cell_start: number, cell_end: number): void {
|
|
810
|
-
this.#tokens.push({type: 'table_cell_open', start: cell_start, end: cell_start});
|
|
810
|
+
this.#tokens.push({ type: 'table_cell_open', start: cell_start, end: cell_start });
|
|
811
811
|
this.#tokenize_cell_inline(cell_start, cell_end);
|
|
812
|
-
this.#tokens.push({type: 'table_cell_close', start: cell_end, end: cell_end});
|
|
812
|
+
this.#tokens.push({ type: 'table_cell_close', start: cell_end, end: cell_end });
|
|
813
813
|
}
|
|
814
814
|
|
|
815
815
|
/**
|
|
@@ -838,9 +838,9 @@ export class MdzLexer {
|
|
|
838
838
|
*/
|
|
839
839
|
#match_item_table_head(
|
|
840
840
|
first: number,
|
|
841
|
-
marker_indent: number
|
|
841
|
+
marker_indent: number
|
|
842
842
|
): {
|
|
843
|
-
header_cells: Array<{start: number; end: number}>;
|
|
843
|
+
header_cells: Array<{ start: number; end: number }>;
|
|
844
844
|
header_end: number;
|
|
845
845
|
align: Array<MdzTableAlign>;
|
|
846
846
|
delim_end: number;
|
|
@@ -857,7 +857,7 @@ export class MdzLexer {
|
|
|
857
857
|
if (delim_end === -1) delim_end = this.#text.length;
|
|
858
858
|
const align = mdz_parse_table_delimiter(this.#text, dj, delim_end);
|
|
859
859
|
if (align === null || align.length !== header_cells.length) return null;
|
|
860
|
-
return {header_cells, header_end, align, delim_end};
|
|
860
|
+
return { header_cells, header_end, align, delim_end };
|
|
861
861
|
}
|
|
862
862
|
|
|
863
863
|
/** Whether a table opens at `first` as a block child of an item at `marker_indent`. */
|
|
@@ -874,7 +874,12 @@ export class MdzLexer {
|
|
|
874
874
|
*/
|
|
875
875
|
#tokenize_item_table(first: number, marker_indent: number): void {
|
|
876
876
|
const head = this.#match_item_table_head(first, marker_indent)!;
|
|
877
|
-
this.#tokens.push({
|
|
877
|
+
this.#tokens.push({
|
|
878
|
+
type: 'table_open',
|
|
879
|
+
align: head.align,
|
|
880
|
+
start: first,
|
|
881
|
+
end: head.header_end
|
|
882
|
+
});
|
|
878
883
|
this.#emit_table_row(head.header_cells, true, first, head.header_end);
|
|
879
884
|
this.#index = head.delim_end;
|
|
880
885
|
let table_end = head.delim_end;
|
|
@@ -892,7 +897,7 @@ export class MdzLexer {
|
|
|
892
897
|
this.#index = row_end;
|
|
893
898
|
table_end = row_end;
|
|
894
899
|
}
|
|
895
|
-
this.#tokens.push({type: 'table_close', start: table_end, end: table_end});
|
|
900
|
+
this.#tokens.push({ type: 'table_close', start: table_end, end: table_end });
|
|
896
901
|
}
|
|
897
902
|
|
|
898
903
|
// -- List tokenizers --
|
|
@@ -964,7 +969,7 @@ export class MdzLexer {
|
|
|
964
969
|
}
|
|
965
970
|
if (levels[levels.length - 1]!.ordered === marker.ordered) {
|
|
966
971
|
// sibling item
|
|
967
|
-
this.#tokens.push({type: 'list_item_close', start: first, end: first});
|
|
972
|
+
this.#tokens.push({ type: 'list_item_close', start: first, end: first });
|
|
968
973
|
this.#list_item_open(marker);
|
|
969
974
|
} else {
|
|
970
975
|
// marker-type switch: close the list, open a new one at this indent
|
|
@@ -980,13 +985,13 @@ export class MdzLexer {
|
|
|
980
985
|
// empty item: only at an indent exactly matching an open level of
|
|
981
986
|
// the same marker type — anything else degrades below
|
|
982
987
|
const level_idx = levels.findIndex(
|
|
983
|
-
(l) => l.indent === indent && l.ordered === marker.ordered
|
|
988
|
+
(l) => l.indent === indent && l.ordered === marker.ordered
|
|
984
989
|
);
|
|
985
990
|
if (level_idx !== -1) {
|
|
986
991
|
while (levels.length - 1 > level_idx) {
|
|
987
992
|
this.#list_close(levels);
|
|
988
993
|
}
|
|
989
|
-
this.#tokens.push({type: 'list_item_close', start: first, end: first});
|
|
994
|
+
this.#tokens.push({ type: 'list_item_close', start: first, end: first });
|
|
990
995
|
this.#list_item_open(marker);
|
|
991
996
|
// consume the marker and any trailing whitespace, leaving #index
|
|
992
997
|
// at the line's newline (or EOF)
|
|
@@ -1056,7 +1061,7 @@ export class MdzLexer {
|
|
|
1056
1061
|
while (levels.length - 1 > target_idx) {
|
|
1057
1062
|
this.#list_close(levels);
|
|
1058
1063
|
}
|
|
1059
|
-
this.#tokens.push({type: 'paragraph_break', start: line_start, end: line_start});
|
|
1064
|
+
this.#tokens.push({ type: 'paragraph_break', start: line_start, end: line_start });
|
|
1060
1065
|
this.#list_run(levels, first);
|
|
1061
1066
|
continue;
|
|
1062
1067
|
}
|
|
@@ -1091,13 +1096,13 @@ export class MdzLexer {
|
|
|
1091
1096
|
start: i,
|
|
1092
1097
|
marker_end: after,
|
|
1093
1098
|
content_start: after,
|
|
1094
|
-
empty: true
|
|
1099
|
+
empty: true
|
|
1095
1100
|
};
|
|
1096
1101
|
}
|
|
1097
1102
|
if (this.#text.charCodeAt(after) !== SPACE) return null;
|
|
1098
1103
|
const content_start = after + 1;
|
|
1099
1104
|
const empty = this.#rest_is_blank(content_start);
|
|
1100
|
-
return {ordered: false, number: 0, start: i, marker_end: after, content_start, empty};
|
|
1105
|
+
return { ordered: false, number: 0, start: i, marker_end: after, content_start, empty };
|
|
1101
1106
|
}
|
|
1102
1107
|
if (c >= ZERO && c <= NINE) {
|
|
1103
1108
|
let j = i + 1;
|
|
@@ -1119,13 +1124,13 @@ export class MdzLexer {
|
|
|
1119
1124
|
start: i,
|
|
1120
1125
|
marker_end: after,
|
|
1121
1126
|
content_start: after,
|
|
1122
|
-
empty: true
|
|
1127
|
+
empty: true
|
|
1123
1128
|
};
|
|
1124
1129
|
}
|
|
1125
1130
|
if (this.#text.charCodeAt(after) !== SPACE) return null;
|
|
1126
1131
|
const content_start = after + 1;
|
|
1127
1132
|
const empty = this.#rest_is_blank(content_start);
|
|
1128
|
-
return {ordered: true, number, start: i, marker_end: after, content_start, empty};
|
|
1133
|
+
return { ordered: true, number, start: i, marker_end: after, content_start, empty };
|
|
1129
1134
|
}
|
|
1130
1135
|
return null;
|
|
1131
1136
|
}
|
|
@@ -1162,26 +1167,31 @@ export class MdzLexer {
|
|
|
1162
1167
|
type: 'list_open',
|
|
1163
1168
|
ordered: marker.ordered,
|
|
1164
1169
|
start: marker.start,
|
|
1165
|
-
end: marker.start
|
|
1170
|
+
end: marker.start
|
|
1166
1171
|
});
|
|
1167
1172
|
this.#list_item_open(marker);
|
|
1168
|
-
levels.push({indent, ordered: marker.ordered});
|
|
1173
|
+
levels.push({ indent, ordered: marker.ordered });
|
|
1169
1174
|
}
|
|
1170
1175
|
|
|
1171
1176
|
/** Emit a `list_item_open` token for `marker`. */
|
|
1172
1177
|
#list_item_open(marker: MdzListMarker): void {
|
|
1173
1178
|
const end = marker.empty ? marker.marker_end : marker.content_start;
|
|
1174
1179
|
if (marker.ordered) {
|
|
1175
|
-
this.#tokens.push({
|
|
1180
|
+
this.#tokens.push({
|
|
1181
|
+
type: 'list_item_open',
|
|
1182
|
+
number: marker.number,
|
|
1183
|
+
start: marker.start,
|
|
1184
|
+
end
|
|
1185
|
+
});
|
|
1176
1186
|
} else {
|
|
1177
|
-
this.#tokens.push({type: 'list_item_open', start: marker.start, end});
|
|
1187
|
+
this.#tokens.push({ type: 'list_item_open', start: marker.start, end });
|
|
1178
1188
|
}
|
|
1179
1189
|
}
|
|
1180
1190
|
|
|
1181
1191
|
/** Close the deepest open level: its current item, then its list. */
|
|
1182
1192
|
#list_close(levels: Array<MdzListLevel>): void {
|
|
1183
|
-
this.#tokens.push({type: 'list_item_close', start: this.#index, end: this.#index});
|
|
1184
|
-
this.#tokens.push({type: 'list_close', start: this.#index, end: this.#index});
|
|
1193
|
+
this.#tokens.push({ type: 'list_item_close', start: this.#index, end: this.#index });
|
|
1194
|
+
this.#tokens.push({ type: 'list_close', start: this.#index, end: this.#index });
|
|
1185
1195
|
levels.pop();
|
|
1186
1196
|
}
|
|
1187
1197
|
|
|
@@ -1278,8 +1288,8 @@ export class MdzLexer {
|
|
|
1278
1288
|
*/
|
|
1279
1289
|
#match_fence(
|
|
1280
1290
|
first: number,
|
|
1281
|
-
fence_indent: number
|
|
1282
|
-
): {token: MdzTokenCodeblock; end: number} | null {
|
|
1291
|
+
fence_indent: number
|
|
1292
|
+
): { token: MdzTokenCodeblock; end: number } | null {
|
|
1283
1293
|
let i = first;
|
|
1284
1294
|
let backtick_count = 0;
|
|
1285
1295
|
while (i < this.#text.length && this.#text.charCodeAt(i) === BACKTICK) {
|
|
@@ -1336,8 +1346,8 @@ export class MdzLexer {
|
|
|
1336
1346
|
? this.#text.slice(content_start, Math.max(content_start, line_start - 1))
|
|
1337
1347
|
: content_lines.join('\n');
|
|
1338
1348
|
return {
|
|
1339
|
-
token: {type: 'codeblock', lang, content, start: first, end: m},
|
|
1340
|
-
end: m
|
|
1349
|
+
token: { type: 'codeblock', lang, content, start: first, end: m },
|
|
1350
|
+
end: m
|
|
1341
1351
|
};
|
|
1342
1352
|
}
|
|
1343
1353
|
}
|
|
@@ -1347,7 +1357,7 @@ export class MdzLexer {
|
|
|
1347
1357
|
if (fence_indent > 0) {
|
|
1348
1358
|
const line_end = nl === -1 ? this.#text.length : nl;
|
|
1349
1359
|
content_lines.push(
|
|
1350
|
-
this.#text.slice(line_start + Math.min(fence_indent, line_indent), line_end)
|
|
1360
|
+
this.#text.slice(line_start + Math.min(fence_indent, line_indent), line_end)
|
|
1351
1361
|
);
|
|
1352
1362
|
}
|
|
1353
1363
|
if (nl === -1) break;
|
|
@@ -1358,8 +1368,8 @@ export class MdzLexer {
|
|
|
1358
1368
|
let content = fence_indent === 0 ? this.#text.slice(content_start) : content_lines.join('\n');
|
|
1359
1369
|
if (content.endsWith('\n')) content = content.slice(0, -1);
|
|
1360
1370
|
return {
|
|
1361
|
-
token: {type: 'codeblock', lang, content, start: first, end: this.#text.length},
|
|
1362
|
-
end: this.#text.length
|
|
1371
|
+
token: { type: 'codeblock', lang, content, start: first, end: this.#text.length },
|
|
1372
|
+
end: this.#text.length
|
|
1363
1373
|
};
|
|
1364
1374
|
}
|
|
1365
1375
|
|
|
@@ -1453,7 +1463,7 @@ export class MdzLexer {
|
|
|
1453
1463
|
}
|
|
1454
1464
|
|
|
1455
1465
|
this.#index = content_end + 1;
|
|
1456
|
-
this.#tokens.push({type: 'code', content, start, end: this.#index});
|
|
1466
|
+
this.#tokens.push({ type: 'code', content, start, end: this.#index });
|
|
1457
1467
|
}
|
|
1458
1468
|
|
|
1459
1469
|
#tokenize_double_delimiter(delimiter: '**' | '~~', kind: 'bold' | 'strikethrough'): void {
|
|
@@ -1492,7 +1502,7 @@ export class MdzLexer {
|
|
|
1492
1502
|
const open_type = kind === 'bold' ? 'bold_open' : 'strikethrough_open';
|
|
1493
1503
|
const close_type = kind === 'bold' ? 'bold_close' : 'strikethrough_close';
|
|
1494
1504
|
const open_token_index = this.#tokens.length;
|
|
1495
|
-
this.#tokens.push({type: open_type, start, end: this.#index});
|
|
1505
|
+
this.#tokens.push({ type: open_type, start, end: this.#index });
|
|
1496
1506
|
|
|
1497
1507
|
// Set search boundary for nested parsers
|
|
1498
1508
|
const saved_max = this.#max_search_index;
|
|
@@ -1519,11 +1529,11 @@ export class MdzLexer {
|
|
|
1519
1529
|
return;
|
|
1520
1530
|
}
|
|
1521
1531
|
|
|
1522
|
-
this.#tokens.push({type: close_type, start: close_index, end: close_index + 2});
|
|
1532
|
+
this.#tokens.push({ type: close_type, start: close_index, end: close_index + 2 });
|
|
1523
1533
|
this.#index = close_index + 2;
|
|
1524
1534
|
} else {
|
|
1525
1535
|
// Didn't reach closing - convert opening to text
|
|
1526
|
-
this.#tokens[open_token_index] = {type: 'text', content: delimiter, start, end: start + 2};
|
|
1536
|
+
this.#tokens[open_token_index] = { type: 'text', content: delimiter, start, end: start + 2 };
|
|
1527
1537
|
}
|
|
1528
1538
|
}
|
|
1529
1539
|
|
|
@@ -1566,7 +1576,7 @@ export class MdzLexer {
|
|
|
1566
1576
|
// Emit open token
|
|
1567
1577
|
this.#index++;
|
|
1568
1578
|
const open_token_index = this.#tokens.length;
|
|
1569
|
-
this.#tokens.push({type: 'italic_open', start, end: this.#index});
|
|
1579
|
+
this.#tokens.push({ type: 'italic_open', start, end: this.#index });
|
|
1570
1580
|
|
|
1571
1581
|
// Set search boundary for nested parsers
|
|
1572
1582
|
const saved_max = this.#max_search_index;
|
|
@@ -1596,7 +1606,7 @@ export class MdzLexer {
|
|
|
1596
1606
|
this.#tokens.push({
|
|
1597
1607
|
type: 'italic_close',
|
|
1598
1608
|
start: close_index,
|
|
1599
|
-
end: close_index + 1
|
|
1609
|
+
end: close_index + 1
|
|
1600
1610
|
});
|
|
1601
1611
|
this.#index = close_index + 1;
|
|
1602
1612
|
} else {
|
|
@@ -1605,7 +1615,7 @@ export class MdzLexer {
|
|
|
1605
1615
|
type: 'text',
|
|
1606
1616
|
content: '_',
|
|
1607
1617
|
start,
|
|
1608
|
-
end: start + 1
|
|
1618
|
+
end: start + 1
|
|
1609
1619
|
};
|
|
1610
1620
|
}
|
|
1611
1621
|
}
|
|
@@ -1632,7 +1642,7 @@ export class MdzLexer {
|
|
|
1632
1642
|
this.#index++; // consume [ (dispatch guarantees it)
|
|
1633
1643
|
|
|
1634
1644
|
// Emit link_text_open
|
|
1635
|
-
this.#tokens.push({type: 'link_text_open', start, end: this.#index});
|
|
1645
|
+
this.#tokens.push({ type: 'link_text_open', start, end: this.#index });
|
|
1636
1646
|
|
|
1637
1647
|
// Tokenize children until ] — only `]` delimits link text; a bare `)`
|
|
1638
1648
|
// is ordinary content (matching the streaming parser, which has no `)`
|
|
@@ -1657,7 +1667,7 @@ export class MdzLexer {
|
|
|
1657
1667
|
this.#tokens.push({
|
|
1658
1668
|
type: 'link_text_close',
|
|
1659
1669
|
start: bracket_close_start,
|
|
1660
|
-
end: this.#index
|
|
1670
|
+
end: this.#index
|
|
1661
1671
|
});
|
|
1662
1672
|
|
|
1663
1673
|
// Check for (
|
|
@@ -1707,7 +1717,7 @@ export class MdzLexer {
|
|
|
1707
1717
|
reference,
|
|
1708
1718
|
link_type,
|
|
1709
1719
|
start: bracket_close_start + 1, // after ]
|
|
1710
|
-
end: this.#index
|
|
1720
|
+
end: this.#index
|
|
1711
1721
|
});
|
|
1712
1722
|
}
|
|
1713
1723
|
|
|
@@ -1801,7 +1811,7 @@ export class MdzLexer {
|
|
|
1801
1811
|
name: tag_name,
|
|
1802
1812
|
is_component,
|
|
1803
1813
|
start,
|
|
1804
|
-
end: this.#index
|
|
1814
|
+
end: this.#index
|
|
1805
1815
|
});
|
|
1806
1816
|
return;
|
|
1807
1817
|
}
|
|
@@ -1841,7 +1851,7 @@ export class MdzLexer {
|
|
|
1841
1851
|
|
|
1842
1852
|
// Emit tag_open
|
|
1843
1853
|
const open_token_index = this.#tokens.length;
|
|
1844
|
-
this.#tokens.push({type: 'tag_open', name: tag_name, is_component, start, end: this.#index});
|
|
1854
|
+
this.#tokens.push({ type: 'tag_open', name: tag_name, is_component, start, end: this.#index });
|
|
1845
1855
|
|
|
1846
1856
|
// Tokenize children until the closing tag. Each iteration narrows
|
|
1847
1857
|
// `#max_search_index` to the next closer so a child's delimiter scan
|
|
@@ -1860,7 +1870,7 @@ export class MdzLexer {
|
|
|
1860
1870
|
type: 'tag_close',
|
|
1861
1871
|
name: tag_name,
|
|
1862
1872
|
start: close_start,
|
|
1863
|
-
end: this.#index
|
|
1873
|
+
end: this.#index
|
|
1864
1874
|
});
|
|
1865
1875
|
return;
|
|
1866
1876
|
}
|
|
@@ -2016,7 +2026,7 @@ export class MdzLexer {
|
|
|
2016
2026
|
parts === null
|
|
2017
2027
|
? this.#text.slice(start, this.#index)
|
|
2018
2028
|
: parts.join('') + this.#text.slice(part_start, this.#index);
|
|
2019
|
-
this.#tokens.push({type: 'text', content, start, end: this.#index});
|
|
2029
|
+
this.#tokens.push({ type: 'text', content, start, end: this.#index });
|
|
2020
2030
|
}
|
|
2021
2031
|
|
|
2022
2032
|
// -- Auto-link tokenizers --
|
|
@@ -2045,7 +2055,7 @@ export class MdzLexer {
|
|
|
2045
2055
|
reference,
|
|
2046
2056
|
link_type: 'external',
|
|
2047
2057
|
start,
|
|
2048
|
-
end: this.#index
|
|
2058
|
+
end: this.#index
|
|
2049
2059
|
});
|
|
2050
2060
|
}
|
|
2051
2061
|
|
|
@@ -2070,14 +2080,14 @@ export class MdzLexer {
|
|
|
2070
2080
|
reference,
|
|
2071
2081
|
link_type: 'internal',
|
|
2072
2082
|
start,
|
|
2073
|
-
end: this.#index
|
|
2083
|
+
end: this.#index
|
|
2074
2084
|
});
|
|
2075
2085
|
}
|
|
2076
2086
|
|
|
2077
2087
|
// -- Helper methods --
|
|
2078
2088
|
|
|
2079
2089
|
#emit_text(content: string, start: number): void {
|
|
2080
|
-
this.#tokens.push({type: 'text', content, start, end: start + content.length});
|
|
2090
|
+
this.#tokens.push({ type: 'text', content, start, end: start + content.length });
|
|
2081
2091
|
}
|
|
2082
2092
|
|
|
2083
2093
|
#has_paragraph_break_between(from: number, to: number): boolean {
|
|
@@ -2116,7 +2126,7 @@ export class MdzLexer {
|
|
|
2116
2126
|
i = this.#text.indexOf('\n', j);
|
|
2117
2127
|
}
|
|
2118
2128
|
if (memo === null) {
|
|
2119
|
-
this.#break_memo = {from, result};
|
|
2129
|
+
this.#break_memo = { from, result };
|
|
2120
2130
|
} else {
|
|
2121
2131
|
memo.from = from;
|
|
2122
2132
|
memo.result = result;
|