satorigear 0.0.8 → 0.0.9

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.
Files changed (3) hide show
  1. package/README.md +12 -12
  2. package/dist/index.mjs +888 -1157
  3. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -2,8 +2,8 @@ import { decodeString } from "micromark-util-decode-string";
2
2
  import { htmlBlockNames, htmlRawNames } from "micromark-util-html-tag-name";
3
3
  //#region src/block/lines.ts
4
4
  var BlockLines = class BlockLines {
5
- #fieldLength = 0;
6
5
  #fields;
6
+ #length = 0;
7
7
  #locatorField = 0;
8
8
  #relativeStart = Infinity;
9
9
  #sourceLength;
@@ -16,10 +16,19 @@ var BlockLines = class BlockLines {
16
16
  const sourceLength = source.length;
17
17
  if (start > 0 || limit < sourceLength) source = source.slice(start, limit);
18
18
  const lines = new BlockLines(sourceLength, Math.min(source.length + 15 >>> 4, 16384));
19
- lines.#fieldLength = BlockLines.#scan(source, lines);
19
+ lines.#length = BlockLines.#scan(source, lines);
20
20
  if (start !== 0) lines.#shiftPositions(0, start);
21
21
  return lines;
22
22
  }
23
+ scan(source) {
24
+ this.#sourceLength = source.length;
25
+ this.#locatorField = 0;
26
+ this.#relativeStart = Infinity;
27
+ const lineCapacity = Math.min(source.length + 15 >>> 4, 16384);
28
+ this.#ensureCapacity(lineCapacity * 4);
29
+ this.#length = BlockLines.#scan(source, this);
30
+ return this;
31
+ }
23
32
  static #scan(source, lines) {
24
33
  const limit = source.length;
25
34
  let start = 0;
@@ -42,16 +51,16 @@ var BlockLines = class BlockLines {
42
51
  lines.#ensureCapacity(field + 4);
43
52
  fields = lines.#fields;
44
53
  }
45
- fields[field + 0] = start;
46
- fields[field + 1] = end;
47
- fields[field + 2] = next;
48
- field += 4;
54
+ fields[field++] = start;
55
+ fields[field++] = end;
56
+ fields[field++] = next;
57
+ fields[field++] = 0;
49
58
  start = next;
50
59
  }
51
- return field;
60
+ return field / 4;
52
61
  }
53
62
  get length() {
54
- return this.#fieldLength / 4;
63
+ return this.#length;
55
64
  }
56
65
  start(index) {
57
66
  return this.#position(this.#fields[index * 4 + 0]);
@@ -86,7 +95,7 @@ var BlockLines = class BlockLines {
86
95
  return this.#lineEndingsNormalized || !value.includes("\r") ? value : value.replace(/\r\n|\r/g, "\n");
87
96
  }
88
97
  locationAt(offset) {
89
- const fieldLength = this.#fieldLength;
98
+ const fieldLength = this.#length * 4;
90
99
  if (fieldLength === 0) return {
91
100
  line: 1,
92
101
  column: 1,
@@ -124,7 +133,7 @@ var BlockLines = class BlockLines {
124
133
  return this.#sourceLength > 0;
125
134
  }
126
135
  push(start, end, next, prefixColumns = 0, lazy = false) {
127
- const field = this.#fieldLength;
136
+ const field = this.#length * 4;
128
137
  let fields = this.#fields;
129
138
  if (field >= fields.length) {
130
139
  this.#ensureCapacity(field + 4);
@@ -135,7 +144,7 @@ var BlockLines = class BlockLines {
135
144
  fields[field + 1] = end;
136
145
  fields[field + 2] = next;
137
146
  fields[field + 3] = state;
138
- this.#fieldLength += 4;
147
+ this.#length++;
139
148
  }
140
149
  pushFrom(lines, index, start = lines.start(index), prefixColumns = lines.prefixColumns(index), lazy = lines.lazy(index)) {
141
150
  this.push(start, lines.end(index), lines.next(index), prefixColumns, lazy);
@@ -155,13 +164,9 @@ var BlockLines = class BlockLines {
155
164
  if (consumed < columns) return -1;
156
165
  const contentOffset = offset;
157
166
  const prefixColumns = consumed - columns;
158
- while (offset < end) {
159
- const code = source.charCodeAt(offset);
160
- if (code !== 32 && code !== 9) {
161
- this.pushFrom(lines, index, contentOffset, prefixColumns);
162
- return 1;
163
- }
164
- offset++;
167
+ if (skipLineWhitespace(source, offset, end) < end) {
168
+ this.pushFrom(lines, index, contentOffset, prefixColumns);
169
+ return 1;
165
170
  }
166
171
  return 0;
167
172
  }
@@ -171,7 +176,7 @@ var BlockLines = class BlockLines {
171
176
  resetFrom(lines, index, start = lines.start(index), prefixColumns = lines.prefixColumns(index), lazy = lines.lazy(index)) {
172
177
  const end = lines.end(index);
173
178
  const next = lines.next(index);
174
- this.#fieldLength = 0;
179
+ this.#length = 0;
175
180
  this.#relativeStart = Infinity;
176
181
  this.push(start, end, next, prefixColumns, lazy);
177
182
  }
@@ -180,7 +185,7 @@ var BlockLines = class BlockLines {
180
185
  const fieldStart = start * 4;
181
186
  const fieldEnd = end * 4;
182
187
  result.#fields = this.#fields.slice(fieldStart, fieldEnd);
183
- result.#fieldLength = fieldEnd - fieldStart;
188
+ result.#length = end - start;
184
189
  result.#lineEndingsNormalized = this.#lineEndingsNormalized;
185
190
  if (this.#relativeStart < end) result.#relativeStart = Math.max(0, this.#relativeStart - start);
186
191
  return result;
@@ -205,8 +210,8 @@ var BlockLines = class BlockLines {
205
210
  return next;
206
211
  }
207
212
  pop() {
208
- if (this.#fieldLength > 0) {
209
- this.#fieldLength -= 4;
213
+ if (this.#length > 0) {
214
+ this.#length--;
210
215
  if (this.#relativeStart >= this.length) this.#relativeStart = Infinity;
211
216
  }
212
217
  }
@@ -238,11 +243,11 @@ var BlockLines = class BlockLines {
238
243
  if (start >= end) return;
239
244
  const sourceStart = start * 4;
240
245
  const sourceEnd = end * 4;
241
- const targetStart = this.#fieldLength;
246
+ const targetStart = this.#length * 4;
242
247
  const targetEnd = targetStart + sourceEnd - sourceStart;
243
248
  this.#ensureCapacity(targetEnd);
244
249
  this.#fields.set(lines.#fields.subarray(sourceStart, sourceEnd), targetStart);
245
- this.#fieldLength = targetEnd;
250
+ this.#length += end - start;
246
251
  }
247
252
  #ensureCapacity(fieldLength) {
248
253
  const fields = this.#fields;
@@ -259,7 +264,7 @@ var BlockLines = class BlockLines {
259
264
  }
260
265
  #shiftPositions(start, delta) {
261
266
  const fields = this.#fields;
262
- const fieldLength = this.#fieldLength;
267
+ const fieldLength = this.#length * 4;
263
268
  for (let field = start * 4; field < fieldLength; field += 4) {
264
269
  fields[field + 0] += delta;
265
270
  fields[field + 1] += delta;
@@ -288,12 +293,17 @@ function lineIndentOffset(source, lines, index) {
288
293
  const code = source.charCodeAt(offset);
289
294
  return code === 32 || code === 9 ? -1 : offset;
290
295
  }
291
- function isBlank(source, lines, index) {
292
- for (let offset = lines.start(index), end = lines.end(index); offset < end; offset++) {
293
- const code = source.charCodeAt(offset);
294
- if (code !== 32 && code !== 9) return false;
296
+ function isBlankLine(source, lines, index) {
297
+ const end = lines.end(index);
298
+ return skipLineWhitespace(source, lines.start(index), end) === end;
299
+ }
300
+ function skipLineWhitespace(source, start, end) {
301
+ while (start < end) {
302
+ const code = source.charCodeAt(start);
303
+ if (code !== 32 && code !== 9) break;
304
+ start++;
295
305
  }
296
- return true;
306
+ return start;
297
307
  }
298
308
  function physicalColumnAt(source, offset) {
299
309
  let start = offset;
@@ -328,17 +338,6 @@ function logicalLine(source, lines, index) {
328
338
  }
329
339
  return result + source.slice(offset, lines.next(index));
330
340
  }
331
- function removeIndent(value, columns) {
332
- let offset = 0;
333
- let consumed = 0;
334
- while (offset < value.length && consumed < columns) {
335
- if (value[offset] === " ") consumed++;
336
- else if (value[offset] === " ") consumed += 4 - consumed % 4;
337
- else break;
338
- offset++;
339
- }
340
- return " ".repeat(Math.max(0, consumed - columns)) + value.slice(offset);
341
- }
342
341
  //#endregion
343
342
  //#region src/primitives.ts
344
343
  const emptyArray = [];
@@ -355,17 +354,14 @@ function copyMetadata(target, source, start, end, targetStart) {
355
354
  var BlockTokenStream = class {
356
355
  #definitionCounts;
357
356
  #definitionMembershipChanges;
358
- #fieldLength;
359
- #fields;
357
+ #fieldLength = 0;
358
+ #fields = new Int32Array();
360
359
  #groupField = -1;
361
360
  #metadata;
362
361
  #opens = [];
363
- #relativeStart;
362
+ #relativeStart = Infinity;
364
363
  #sourceLength;
365
364
  constructor(sourceLength = 0) {
366
- this.#fieldLength = 0;
367
- this.#fields = new Int32Array();
368
- this.#relativeStart = Number.POSITIVE_INFINITY;
369
365
  this.#sourceLength = sourceLength;
370
366
  }
371
367
  reset(sourceLength) {
@@ -375,7 +371,7 @@ var BlockTokenStream = class {
375
371
  this.#groupField = -1;
376
372
  this.#metadata = void 0;
377
373
  this.#opens.length = 0;
378
- this.#relativeStart = Number.POSITIVE_INFINITY;
374
+ this.#relativeStart = Infinity;
379
375
  this.#sourceLength = sourceLength;
380
376
  }
381
377
  get length() {
@@ -391,42 +387,39 @@ var BlockTokenStream = class {
391
387
  return !!this.#definitionCounts?.size;
392
388
  }
393
389
  push(kind, start, end, meta, role) {
390
+ const encodedRole = role ?? kind;
394
391
  const field = this.#fieldLength;
395
392
  this.#ensureCapacity(field + 4);
396
393
  this.#fields[field + 0] = kind;
397
394
  this.#fields[field + 1] = start;
398
395
  this.#fields[field + 2] = end;
399
- this.#fields[field + 3] = 0;
396
+ this.#fields[field + 3] = encodedRole < 64 ? 0 : this.#indexToken(field, encodedRole);
400
397
  this.#fieldLength += 4;
401
398
  if (meta) {
402
399
  this.#metadata ??= [];
403
- this.#metadata[this.length - 1] = meta;
400
+ this.#metadata[field / 4] = meta;
404
401
  const definitionKey = meta.definitionKey;
405
402
  if (definitionKey !== void 0) this.#updateDefinitionCount(definitionKey, 1, false);
406
403
  }
407
- const encodedRole = role ?? kind;
408
- if (encodedRole >= 64) this.#indexToken(field, encodedRole);
409
404
  }
410
405
  #indexToken(field, encodedRole) {
411
406
  if (encodedRole < 192) {
412
407
  this.#opens.push(field);
413
- return;
408
+ return 0;
414
409
  }
415
410
  if (encodedRole < 256) {
416
411
  const open = this.#opens.pop();
417
412
  this.#fields[open + 3] = (field - open) / 4 + 1;
418
- return;
419
- }
420
- if (encodedRole < 320) {
421
- this.#fields[field + 3] = 1;
422
- return;
413
+ return 0;
423
414
  }
424
- const group = this.#groupField;
415
+ if (encodedRole < 320) return 1;
425
416
  const previous = field - 4;
426
- if (group < 0 || previous < 0 || this.#fields[previous + 0] < 320) {
427
- this.#groupField = field;
428
- this.#fields[field + 3] = 1;
429
- } else this.#fields[group + 3]++;
417
+ if (this.#groupField >= 0 && this.#fields[previous + 0] >= 320) {
418
+ this.#fields[this.#groupField + 3]++;
419
+ return 0;
420
+ }
421
+ this.#groupField = field;
422
+ return 1;
430
423
  }
431
424
  nodeLength(index) {
432
425
  return this.#fields[index * 4 + 3];
@@ -524,7 +517,7 @@ var BlockTokenStream = class {
524
517
  this.#metadata = metadata.length > 0 ? metadata : void 0;
525
518
  }
526
519
  const newSuffixStart = start + replacementLength;
527
- this.#relativeStart = newSuffixStart < this.length ? newSuffixStart : Number.POSITIVE_INFINITY;
520
+ this.#relativeStart = newSuffixStart < this.length ? newSuffixStart : Infinity;
528
521
  this.#sourceLength = replacement.#sourceLength;
529
522
  return change;
530
523
  }
@@ -624,40 +617,6 @@ function appendLogicalToken(out, kind, source, lines, start, end, value) {
624
617
  }
625
618
  //#endregion
626
619
  //#region src/block/scanner.ts
627
- function scanBlock(profile, context, source, lines, start, contentOffset, out) {
628
- const starts = profile.starts[contentOffset < 0 ? -1 : source.charCodeAt(contentOffset)];
629
- if (starts) for (const resolve of starts) {
630
- const end = resolve(source, lines, start, contentOffset, out, context);
631
- if (end !== void 0) return end;
632
- }
633
- for (const fallback of profile.fallbacks) {
634
- const fallbackEnd = fallback(source, lines, start, contentOffset, out, context);
635
- if (fallbackEnd !== void 0) return fallbackEnd;
636
- }
637
- throw new Error("Syntax profile did not provide a block fallback");
638
- }
639
- function scanBlockLines(profile, context, source, lines, out, visit) {
640
- for (let index = 0; index < lines.length;) {
641
- let contentOffset = lines.start(index);
642
- const lineEnd = lines.end(index);
643
- let columns = lines.prefixColumns(index);
644
- while (contentOffset < lineEnd) {
645
- const code = source.charCodeAt(contentOffset);
646
- if (code !== 32 && code !== 9) break;
647
- columns += code === 32 ? 1 : 4 - columns % 4;
648
- contentOffset++;
649
- }
650
- if (contentOffset === lineEnd) {
651
- index++;
652
- continue;
653
- }
654
- if (columns > 3) contentOffset = -1;
655
- const lineStart = index;
656
- const tokenStart = out.length;
657
- index = scanBlock(profile, context, source, lines, index, contentOffset, out);
658
- if (visit(lineStart, index, tokenStart, out.length)) return;
659
- }
660
- }
661
620
  function sameShiftedBlock(previous, record, next, tokenStart, tokenEnd, delta) {
662
621
  const length = previous.nodeLength(record.tokenStart);
663
622
  if (length !== tokenEnd - tokenStart) return false;
@@ -665,6 +624,8 @@ function sameShiftedBlock(previous, record, next, tokenStart, tokenEnd, delta) {
665
624
  return true;
666
625
  }
667
626
  var BlockScanContext = class {
627
+ #lineViewDepth = 0;
628
+ #lineViews = [];
668
629
  #lookaheadEnd = 0;
669
630
  #profile;
670
631
  #unwrappedLine = new BlockLines();
@@ -701,14 +662,44 @@ var BlockScanContext = class {
701
662
  this.#lookaheadEnd = 0;
702
663
  return end;
703
664
  }
665
+ createLineView(lines, index, start, prefixColumns) {
666
+ const depth = this.#lineViewDepth++;
667
+ const view = this.#lineViews[depth] ??= new BlockLines();
668
+ view.resetFrom(lines, index, start, prefixColumns);
669
+ return view;
670
+ }
671
+ scanBlockLines(source, lines, out, visit) {
672
+ const profile = this.#profile;
673
+ for (let index = 0; index < lines.length;) {
674
+ let contentOffset = lines.start(index);
675
+ const lineEnd = lines.end(index);
676
+ let columns = lines.prefixColumns(index);
677
+ while (contentOffset < lineEnd) {
678
+ const code = source.charCodeAt(contentOffset);
679
+ if (code !== 32 && code !== 9) break;
680
+ columns += code === 32 ? 1 : 4 - columns % 4;
681
+ contentOffset++;
682
+ }
683
+ if (contentOffset === lineEnd) {
684
+ index++;
685
+ continue;
686
+ }
687
+ if (columns > 3) contentOffset = -1;
688
+ const lineStart = index;
689
+ const tokenStart = out.length;
690
+ index = profile.dispatch(source, lines, index, contentOffset, out, this);
691
+ if (visit(lineStart, index, tokenStart, out.length)) return;
692
+ }
693
+ }
704
694
  scanLines(source, lines, out) {
705
695
  let blankSeparated = false;
706
696
  let previousContentEnd = -1;
707
- scanBlockLines(this.#profile, this, source, lines, out, (lineStart, lineEnd) => {
697
+ this.scanBlockLines(source, lines, out, (lineStart, lineEnd) => {
708
698
  blankSeparated ||= previousContentEnd >= 0 && lineStart > previousContentEnd;
709
699
  previousContentEnd = lineEnd;
710
- while (previousContentEnd > lineStart && isBlank(source, lines, previousContentEnd - 1)) previousContentEnd--;
700
+ while (previousContentEnd > lineStart && isBlankLine(source, lines, previousContentEnd - 1)) previousContentEnd--;
711
701
  });
702
+ if (lines === this.#lineViews[this.#lineViewDepth - 1]) this.#lineViewDepth--;
712
703
  return blankSeparated;
713
704
  }
714
705
  startsInterruptingBlock(source, lines, index, contentOffset = lineIndentOffset(source, lines, index)) {
@@ -721,26 +712,23 @@ var BlockScanContext = class {
721
712
  };
722
713
  var BlockScanner = class {
723
714
  #context;
724
- #lines;
725
- #profile;
726
- #records;
727
- #tokens;
715
+ #lines = new BlockLines();
716
+ #records = [];
717
+ #tokens = new BlockTokenStream();
718
+ builds;
728
719
  constructor(profile) {
729
720
  this.#context = new BlockScanContext(profile);
730
- this.#profile = profile;
731
- this.#lines = new BlockLines();
732
- this.#records = [];
733
- this.#tokens = new BlockTokenStream();
721
+ this.builds = profile.builds;
734
722
  }
735
723
  scan(source) {
736
- const lines = BlockLines.from(source);
724
+ const lines = this.#lines.scan(source);
737
725
  const tokens = this.#tokens;
738
726
  tokens.reset(source.length);
739
727
  const records = this.#records;
740
728
  const context = this.#context;
741
729
  let recordIndex = 0;
742
730
  context.resetLookahead();
743
- scanBlockLines(this.#profile, context, source, lines, tokens, (lineStart, lineEnd, tokenStart) => {
731
+ context.scanBlockLines(source, lines, tokens, (lineStart, lineEnd, tokenStart) => {
744
732
  const end = lines.next(lineEnd - 1);
745
733
  const dependencyEnd = Math.max(end, context.consumeLookahead());
746
734
  const record = records[recordIndex++];
@@ -757,7 +745,6 @@ var BlockScanner = class {
757
745
  });
758
746
  });
759
747
  records.length = recordIndex;
760
- this.#lines = lines;
761
748
  }
762
749
  get tokens() {
763
750
  return this.#tokens;
@@ -765,10 +752,6 @@ var BlockScanner = class {
765
752
  get records() {
766
753
  return this.#records;
767
754
  }
768
- ruleOf(tokenStart) {
769
- const kind = this.#tokens.kind(tokenStart);
770
- return this.#profile.rules[kind];
771
- }
772
755
  locator() {
773
756
  return this.#lines.locator();
774
757
  }
@@ -797,7 +780,7 @@ var BlockScanner = class {
797
780
  const scanLines = nextLines.slice(scanLineStart, scanLineEnd);
798
781
  let convergenceIndex = affectedIndex;
799
782
  context.resetLookahead();
800
- scanBlockLines(this.#profile, context, nextSource, scanLines, replacement, (lineStart, lineEnd, tokenStart, tokenEnd) => {
783
+ context.scanBlockLines(nextSource, scanLines, replacement, (lineStart, lineEnd, tokenStart, tokenEnd) => {
801
784
  const blockStart = scanLines.start(lineStart);
802
785
  const blockEnd = scanLines.next(lineEnd - 1);
803
786
  const observedEnd = context.consumeLookahead();
@@ -865,7 +848,7 @@ var BlockScanner = class {
865
848
  function blockEnd(tokenStart, context) {
866
849
  const tokens = context.structure.tokens;
867
850
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
868
- return tokens.nodeLength(close) === 0 ? tokens.end(close) : tokens.contentEnd(context.source, close);
851
+ return close === tokenStart ? tokens.contentEnd(context.source, close) : tokens.end(close);
869
852
  }
870
853
  function leafBlockPosition(tokenStart, context) {
871
854
  const tokens = context.structure.tokens;
@@ -879,16 +862,21 @@ function fencedBlockPosition(tokenStart, block, context) {
879
862
  return context.locator.positionAt(tokens.start(tokenStart) + block.markerOffset, positionEnd);
880
863
  }
881
864
  function buildBlockNode(tokenStart, context) {
882
- return context.structure.ruleOf(tokenStart).build(tokenStart, context);
865
+ const kind = context.structure.tokens.kind(tokenStart);
866
+ return context.structure.builds[kind](tokenStart, context);
883
867
  }
884
868
  function buildBlockChildren(tokenStart, context) {
885
- const structure = context.structure;
886
- const tokens = structure.tokens;
869
+ const builds = context.structure.builds;
870
+ const tokens = context.structure.tokens;
887
871
  const children = [];
888
872
  const tokenEnd = tokenStart + tokens.nodeLength(tokenStart) - 1;
889
873
  for (let child = tokenStart + 1; child < tokenEnd;) {
890
874
  const length = tokens.nodeLength(child);
891
- if (length > 0 && structure.ruleOf(child).block) children.push(buildBlockNode(child, context));
875
+ if (length > 0) {
876
+ const kind = tokens.kind(child);
877
+ const role = kind & 448;
878
+ if (role === 64 || role === 256) children.push(builds[kind](child, context));
879
+ }
892
880
  child += length || 1;
893
881
  }
894
882
  return children;
@@ -909,30 +897,34 @@ var SourceView = class {
909
897
  #offset = 0;
910
898
  #segments;
911
899
  text;
912
- constructor(source, startOrRanges, end) {
913
- if (typeof startOrRanges === "number") {
914
- this.#offset = startOrRanges;
915
- this.text = source.slice(startOrRanges, end);
900
+ constructor(source, tokens, tokenStart, nodeLength) {
901
+ let token = tokenStart + 1;
902
+ const firstStart = tokens.start(token);
903
+ const tokenEnd = tokenStart + nodeLength;
904
+ let segmentStart = firstStart;
905
+ let end = tokens.end(token++);
906
+ let parts;
907
+ let segments;
908
+ let viewEnd = 0;
909
+ while (token < tokenEnd && tokens.kind(token) === 1) {
910
+ const start = tokens.start(token);
911
+ if (start !== end) {
912
+ (parts ??= []).push(source.slice(segmentStart, end));
913
+ (segments ??= []).push(segmentStart - viewEnd, viewEnd += end - segmentStart);
914
+ segmentStart = start;
915
+ }
916
+ end = tokens.end(token);
917
+ token++;
918
+ }
919
+ if (parts && segments) {
920
+ parts.push(source.slice(segmentStart, end));
921
+ segments.push(segmentStart - viewEnd, viewEnd + end - segmentStart);
922
+ this.#segments = segments;
923
+ this.text = parts.join("");
916
924
  return;
917
925
  }
918
- const ranges = startOrRanges;
919
- const parts = [];
920
- let viewOffset = 0;
921
- let segmentCount = 0;
922
- for (let read = 0; read < ranges.length; read += 2) {
923
- const start = ranges[read];
924
- const end = ranges[read + 1];
925
- if (start === end) continue;
926
- const write = segmentCount * 2;
927
- ranges[write] = start - viewOffset;
928
- viewOffset += end - start;
929
- parts.push(source.slice(start, end));
930
- ranges[write + 1] = viewOffset;
931
- segmentCount++;
932
- }
933
- ranges.length = segmentCount * 2;
934
- this.#segments = ranges;
935
- this.text = parts.join("");
926
+ this.#offset = firstStart;
927
+ this.text = source.slice(firstStart, end);
936
928
  }
937
929
  mapOffset(offset) {
938
930
  const segments = this.#segments;
@@ -1055,11 +1047,10 @@ var InlineRegionState = class {
1055
1047
  for (let token = tokenStart; token < tokenEnd; token++) {
1056
1048
  const nodeLength = tokens.nodeLength(token);
1057
1049
  if (nodeLength === 0) continue;
1058
- if (structure.ruleOf(token).inlineContent) {
1059
- const inlineView = inlineViewOf(source, tokens, token, nodeLength);
1060
- if (inlineView) bindings.push({
1050
+ if (tokens.kind(token) & 32) {
1051
+ if (tokens.kind(token + 1) === 1) bindings.push({
1061
1052
  tokenStart: token,
1062
- view: inlineView
1053
+ view: new SourceView(source, tokens, token, nodeLength)
1063
1054
  });
1064
1055
  token += nodeLength - 1;
1065
1056
  }
@@ -1127,40 +1118,6 @@ var InlineRegionCursor = class {
1127
1118
  return region;
1128
1119
  }
1129
1120
  };
1130
- function resolveInlineRegion(source, profile, tokens, tokenStart) {
1131
- const view = inlineViewOf(source, tokens, tokenStart, tokens.nodeLength(tokenStart));
1132
- if (!view) return;
1133
- const text = view.text;
1134
- return {
1135
- tokenStart,
1136
- tokens: profile.resolve(text, profile.tokenize(text), tokens),
1137
- view
1138
- };
1139
- }
1140
- function inlineViewOf(source, tokens, tokenStart, nodeLength) {
1141
- let firstStart = -1;
1142
- let firstEnd = -1;
1143
- let ranges;
1144
- const tokenEnd = tokenStart + nodeLength;
1145
- for (let token = tokenStart + 1; token < tokenEnd; token++) {
1146
- if (tokens.kind(token) !== 1) continue;
1147
- const start = tokens.start(token);
1148
- const end = tokens.end(token);
1149
- if (firstStart < 0) {
1150
- firstStart = start;
1151
- firstEnd = end;
1152
- } else if (start === firstEnd) {
1153
- firstEnd = end;
1154
- if (ranges) ranges[ranges.length - 1] = end;
1155
- } else {
1156
- ranges ??= [firstStart, firstEnd];
1157
- ranges.push(start, end);
1158
- firstEnd = end;
1159
- }
1160
- }
1161
- if (ranges) return new SourceView(source, ranges);
1162
- if (firstStart >= 0) return new SourceView(source, firstStart, firstEnd);
1163
- }
1164
1121
  //#endregion
1165
1122
  //#region src/document.ts
1166
1123
  function applyEdits(source, edits) {
@@ -1325,15 +1282,50 @@ var DocumentImpl = class {
1325
1282
  };
1326
1283
  //#endregion
1327
1284
  //#region src/block/profile.ts
1285
+ function generateBlockDispatch(starts, fallbacks) {
1286
+ try {
1287
+ const resolvers = [];
1288
+ const call = (resolve) => {
1289
+ return `e=r${resolvers.push(resolve) - 1}(s,l,i,o,t,c);if(e!==void 0)return e;`;
1290
+ };
1291
+ let cases = "";
1292
+ for (const code in starts) cases += `case ${code}:${starts[code].map(call).join("")}break;`;
1293
+ const source = [
1294
+ `return(s,l,i,o,t,c)=>{`,
1295
+ `let e;switch(o<0?-1:s.charCodeAt(o)){${cases}}`,
1296
+ ...fallbacks.map(call),
1297
+ `throw new Error("Syntax profile did not provide a block fallback")}`
1298
+ ].join("");
1299
+ const names = resolvers.map((resolver, index) => `r${index}`);
1300
+ return Function(...names, source)(...resolvers);
1301
+ } catch {
1302
+ return (source, lines, start, contentOffset, out, context) => {
1303
+ const resolvers = starts[contentOffset < 0 ? -1 : source.charCodeAt(contentOffset)];
1304
+ if (resolvers) for (const resolve of resolvers) {
1305
+ const end = resolve(source, lines, start, contentOffset, out, context);
1306
+ if (end !== void 0) return end;
1307
+ }
1308
+ for (const fallback of fallbacks) {
1309
+ const end = fallback(source, lines, start, contentOffset, out, context);
1310
+ if (end !== void 0) return end;
1311
+ }
1312
+ throw new Error("Syntax profile did not provide a block fallback");
1313
+ };
1314
+ }
1315
+ }
1328
1316
  function compileBlockProfile(features) {
1317
+ const builds = [];
1329
1318
  const decorators = [];
1330
1319
  const fallbacks = [];
1331
1320
  const interrupts = [];
1332
1321
  const lazyContinuationUnwrappers = [];
1333
- const ruleByBlockRule = [];
1334
- const rules = [];
1335
1322
  const starts = [];
1336
1323
  for (const feature of features) {
1324
+ if (feature.builds) for (const registration of feature.builds) {
1325
+ const token = registration.token;
1326
+ const tokens = typeof token === "number" ? [token] : token;
1327
+ for (const token of tokens) builds[token] = registration.build;
1328
+ }
1337
1329
  if (feature.decorators) decorators.push(...feature.decorators);
1338
1330
  if (feature.fallbacks) fallbacks.push(...feature.fallbacks);
1339
1331
  if (feature.starts) for (const registration of feature.starts) {
@@ -1343,30 +1335,21 @@ function compileBlockProfile(features) {
1343
1335
  if (registration.interrupt) (interrupts[code] ??= []).push(registration.interrupt);
1344
1336
  }
1345
1337
  }
1346
- if (feature.rules) for (const registration of feature.rules) {
1347
- const syntax = registration.syntax;
1348
- const tokens = typeof syntax.token === "number" ? [syntax.token] : syntax.token;
1349
- const rule = {
1350
- block: syntax.kind === "block" || syntax.kind === "leaf",
1351
- inlineContent: registration.inlineContent === true,
1352
- build: registration.build
1353
- };
1354
- ruleByBlockRule[registration.rule] = rule;
1355
- for (const token of tokens) rules[token] = rule;
1356
- }
1357
1338
  }
1358
1339
  for (const registration of decorators) {
1359
- const rule = ruleByBlockRule[registration.rule];
1360
- const build = rule?.build;
1361
- if (!build) throw new Error(`Cannot decorate unknown block rule ${registration.rule}`);
1362
- rule.build = registration.decorate(build);
1340
+ const token = registration.token;
1341
+ const tokens = typeof token === "number" ? [token] : token;
1342
+ for (const token of tokens) {
1343
+ const build = builds[token];
1344
+ if (!build) throw new Error(`Cannot decorate unknown block token ${token}`);
1345
+ builds[token] = registration.decorate(build);
1346
+ }
1363
1347
  }
1364
1348
  return {
1365
- fallbacks,
1349
+ builds,
1350
+ dispatch: generateBlockDispatch(starts, fallbacks),
1366
1351
  interrupts,
1367
- lazyContinuationUnwrappers,
1368
- rules,
1369
- starts
1352
+ lazyContinuationUnwrappers
1370
1353
  };
1371
1354
  }
1372
1355
  //#endregion
@@ -1385,17 +1368,12 @@ function inlineMarkerRunEnd(source, start) {
1385
1368
  function tokenize(source, textBoundary, scannerByCode) {
1386
1369
  const tokens = [];
1387
1370
  const end = source.length;
1388
- let lineStart = 0;
1389
1371
  let offset = 0;
1390
- while (offset < end) {
1391
- if (lineStart >= 0) {
1392
- let content = offset;
1393
- while (source.charCodeAt(content) === 32) content++;
1394
- if (content === end) break;
1395
- offset = content;
1396
- if (lineStart > 0) tokens.push(67, offset, offset, lineStart);
1397
- lineStart = -1;
1398
- }
1372
+ while (source.charCodeAt(offset) === 32) offset++;
1373
+ for (; offset < end;) {
1374
+ textBoundary.lastIndex = offset;
1375
+ if (!textBoundary.test(source)) break;
1376
+ offset = textBoundary.lastIndex - 1;
1399
1377
  const code = source.charCodeAt(offset);
1400
1378
  if (code === 10 || code === 13) {
1401
1379
  if (source.charCodeAt(offset - 1) === 32 && source.charCodeAt(offset - 2) === 32) {
@@ -1403,15 +1381,15 @@ function tokenize(source, textBoundary, scannerByCode) {
1403
1381
  while (source.charCodeAt(spaces - 1) === 32) spaces--;
1404
1382
  tokens.push(128, spaces, offset, 0);
1405
1383
  }
1406
- offset++;
1384
+ const endingStart = offset++;
1407
1385
  if (code === 13 && source.charCodeAt(offset) === 10) offset++;
1408
- lineStart = offset;
1386
+ const lineStart = offset;
1387
+ while (source.charCodeAt(offset) === 32) offset++;
1388
+ tokens.push(67, endingStart, offset, lineStart);
1409
1389
  continue;
1410
1390
  }
1411
1391
  const scannedEnd = scannerByCode[code]?.(source, offset, tokens) ?? offset;
1412
1392
  offset = scannedEnd > offset ? scannedEnd : offset + 1;
1413
- textBoundary.lastIndex = offset;
1414
- offset = textBoundary.test(source) ? textBoundary.lastIndex - 1 : end;
1415
1393
  }
1416
1394
  return tokens;
1417
1395
  }
@@ -1422,21 +1400,19 @@ function generateInlineTokenizer(boundaryCodes, textBoundary, scannerByCode) {
1422
1400
  const names = boundaryCodes.map((code, index) => `scan${index}`);
1423
1401
  const source = [
1424
1402
  `return source=>{`,
1425
- `const tokens=[],end=source.length;let lineStart=0,offset=0;`,
1426
- `while(offset<end){`,
1427
- `if(lineStart>=0){let content=offset;while(source.charCodeAt(content)===32)content++;`,
1428
- `if(content===end)break;offset=content;`,
1429
- `if(lineStart>0)tokens.push(67,offset,offset,lineStart);lineStart=-1}`,
1403
+ `const tokens=[],end=source.length;let offset=0;`,
1404
+ `while(source.charCodeAt(offset)===32)offset++;for(;offset<end;){`,
1405
+ `textBoundary.lastIndex=offset;if(!textBoundary.test(source))break;offset=textBoundary.lastIndex-1;`,
1430
1406
  `const code=source.charCodeAt(offset);`,
1431
1407
  `if(code===10||code===13){`,
1432
1408
  `if(source.charCodeAt(offset-1)===32&&source.charCodeAt(offset-2)===32){`,
1433
1409
  `let spaces=offset-2;while(source.charCodeAt(spaces-1)===32)spaces--;`,
1434
1410
  `tokens.push(128,spaces,offset,0)}`,
1435
- `offset++;if(code===13&&source.charCodeAt(offset)===10)offset++;`,
1436
- `lineStart=offset;continue}`,
1411
+ `const endingStart=offset++;if(code===13&&source.charCodeAt(offset)===10)offset++;`,
1412
+ `const lineStart=offset;while(source.charCodeAt(offset)===32)offset++;`,
1413
+ `tokens.push(67,endingStart,offset,lineStart);continue}`,
1437
1414
  `let scannedEnd;switch(code){${boundaryCodes.map((code, index) => `case ${code}:scannedEnd=scan${index}(source,offset,tokens);break;`).join("")}default:scannedEnd=offset}`,
1438
- `offset=scannedEnd>offset?scannedEnd:offset+1;textBoundary.lastIndex=offset;`,
1439
- `offset=textBoundary.test(source)?textBoundary.lastIndex-1:end}`,
1415
+ `offset=scannedEnd>offset?scannedEnd:offset+1}`,
1440
1416
  `return tokens}`
1441
1417
  ].join("");
1442
1418
  tokenizerFactories.set(key, factory = Function("textBoundary", ...names, source));
@@ -1470,20 +1446,16 @@ function compileInlineProfile(features, compileInlineResolver) {
1470
1446
  const delimiters = [];
1471
1447
  const scanRules = [];
1472
1448
  for (const feature of features) {
1473
- if (feature.scan) scanRules.push(...feature.scan);
1449
+ if (feature.scans) scanRules.push(...feature.scans);
1474
1450
  if (feature.delimiters) delimiters.push(...feature.delimiters);
1475
- const build = feature.build;
1451
+ const build = feature.builds;
1476
1452
  if (!build) continue;
1477
1453
  for (const rule of build) switch (rule.kind) {
1478
1454
  case "decorate":
1479
1455
  buildByKind[rule.token] = rule.apply;
1480
1456
  break;
1481
1457
  case "leaf":
1482
- buildByKind[rule.token] = rule.build;
1483
- break;
1484
1458
  case "text":
1485
- buildByKind[rule.token] = rule.build;
1486
- break;
1487
1459
  case "pair": buildByKind[rule.token] = rule.build;
1488
1460
  }
1489
1461
  }
@@ -1494,6 +1466,37 @@ function compileInlineProfile(features, compileInlineResolver) {
1494
1466
  };
1495
1467
  }
1496
1468
  //#endregion
1469
+ //#region src/profile/features/attributes/block.ts
1470
+ const blockDecorators = [{
1471
+ token: [65, 66],
1472
+ decorate(build) {
1473
+ return (tokenStart, context) => {
1474
+ const result = build(tokenStart, context);
1475
+ if (!result.spread) for (const item of result.children) {
1476
+ const paragraph = !item.spread && item.children.length === 1 && item.children[0].type === "paragraph" ? item.children[0] : void 0;
1477
+ if (paragraph?.attributes) {
1478
+ item.attributes = paragraph.attributes;
1479
+ delete paragraph.attributes;
1480
+ }
1481
+ }
1482
+ return result;
1483
+ };
1484
+ }
1485
+ }, {
1486
+ token: 64,
1487
+ decorate(build) {
1488
+ return (tokenStart, context) => {
1489
+ const result = build(tokenStart, context);
1490
+ const paragraph = result.children.length === 1 && result.children[0].type === "paragraph" ? result.children[0] : void 0;
1491
+ if (paragraph?.attributes) {
1492
+ result.attributes = paragraph.attributes;
1493
+ delete paragraph.attributes;
1494
+ }
1495
+ return result;
1496
+ };
1497
+ }
1498
+ }];
1499
+ //#endregion
1497
1500
  //#region src/inline/tokens.ts
1498
1501
  function inlineTokenCount(tokens) {
1499
1502
  return tokens.length / 4;
@@ -1518,8 +1521,8 @@ function rewriteInlineTokenTail(tokens, kind, end) {
1518
1521
  tokens[offset + 0] = kind;
1519
1522
  tokens[offset + 2] = end;
1520
1523
  }
1521
- function inlineTokenText(source, tokens, index) {
1522
- return source.slice(inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index));
1524
+ function inlineTokenText(source, tokens, index, startPadding = 0, endPadding = startPadding) {
1525
+ return source.slice(inlineTokenStart(tokens, index) + startPadding, inlineTokenEnd(tokens, index) - endPadding);
1523
1526
  }
1524
1527
  function appendInlineToken(target, kind, start, end, data = 0) {
1525
1528
  target.push(kind, start, end, data);
@@ -1529,60 +1532,50 @@ function copyInlineToken(target, tokens, index) {
1529
1532
  target.push(tokens[offset], tokens[offset + 1], tokens[offset + 2], tokens[offset + 3]);
1530
1533
  }
1531
1534
  //#endregion
1532
- //#region src/profile/features/attributes/syntax.ts
1533
- const brackets = {
1534
- "[": "]",
1535
- "{": "}",
1536
- "(": ")"
1537
- };
1538
- function isAsciiLetter(character) {
1539
- if (!character) return false;
1540
- const code = character.charCodeAt(0);
1535
+ //#region src/profile/utils.ts
1536
+ const inlineColonBoundary = /[ \t\n\r\p{sc=Han}\p{sc=Hira}\p{sc=Kana}\p{sc=Hang}\p{P}]/u;
1537
+ function isAsciiLetter(code) {
1541
1538
  return code >= 65 && code <= 90 || code >= 97 && code <= 122;
1542
1539
  }
1543
- function isAsciiDigit(character) {
1544
- if (!character) return false;
1545
- const code = character.charCodeAt(0);
1540
+ function isAsciiDigit(code) {
1546
1541
  return code >= 48 && code <= 57;
1547
1542
  }
1548
- function isHorizontalWhitespace(character) {
1549
- return character === " " || character === " ";
1543
+ function isMarkdownWhitespace(code) {
1544
+ return code === 9 || code === 10 || code === 13 || code === 32;
1550
1545
  }
1551
- function componentNameEnd(source, start, block) {
1552
- if (!isAsciiLetter(source[start]) && source[start] !== "$") return;
1553
- let end = start + 1;
1554
- while (end < source.length) {
1555
- const character = source[end];
1556
- if (!isAsciiLetter(character) && !isAsciiDigit(character) && character !== "$" && character !== "_" && character !== "-" && (!block || character !== ".")) break;
1557
- end++;
1558
- }
1559
- return end;
1546
+ function hasInlineColonBoundary(source, start) {
1547
+ if (start <= 0) return true;
1548
+ const previous = source[start - 1];
1549
+ return previous !== ":" && inlineColonBoundary.test(previous);
1560
1550
  }
1561
- function normalizeComponentName(value) {
1562
- const parts = [];
1563
- let part = "";
1564
- let previousUpper;
1565
- for (const character of value) {
1566
- if (character === "-" || character === "_" || character === "/" || character === ".") {
1567
- if (part) {
1568
- parts.push(part);
1569
- part = "";
1551
+ function semanticText(value) {
1552
+ return value.includes("\\") || value.includes("&") ? decodeString(value) : value;
1553
+ }
1554
+ function normalizeAssociationLabel(label) {
1555
+ scan: {
1556
+ let hasUppercase = false;
1557
+ for (let index = 0; index < label.length; index++) {
1558
+ const code = label.charCodeAt(index);
1559
+ if (code === 32) {
1560
+ if (index === 0 || index + 1 === label.length || label.charCodeAt(index + 1) === 32) break scan;
1561
+ continue;
1570
1562
  }
1571
- previousUpper = void 0;
1572
- continue;
1563
+ if (code < 32 || code > 126) break scan;
1564
+ if (code >= 65 && code <= 90) hasUppercase = true;
1573
1565
  }
1574
- const upper = isAsciiLetter(character) ? character === character.toUpperCase() : void 0;
1575
- if (previousUpper === false && upper === true) {
1576
- parts.push(part);
1577
- part = character;
1578
- } else if (previousUpper === true && upper === false && part.length > 1) {
1579
- parts.push(part.slice(0, -1));
1580
- part = part.at(-1) + character;
1581
- } else part += character;
1582
- previousUpper = upper;
1566
+ return hasUppercase ? label.toLowerCase() : label;
1583
1567
  }
1584
- if (part) parts.push(part);
1585
- return parts.map((value) => value.toLowerCase()).join("-");
1568
+ return label.trim().replace(/[ \t\r\n]+/g, " ").toLowerCase().toUpperCase().toLowerCase();
1569
+ }
1570
+ //#endregion
1571
+ //#region src/profile/features/attributes/shared.ts
1572
+ const brackets = {
1573
+ "[": "]",
1574
+ "{": "}",
1575
+ "(": ")"
1576
+ };
1577
+ function isHorizontalWhitespace(character) {
1578
+ return character === " " || character === " ";
1586
1579
  }
1587
1580
  function assignAttribute(attributes, name, value) {
1588
1581
  if (name === "class" && typeof value === "string" && typeof attributes.class === "string") attributes.class += ` ${value}`;
@@ -1591,46 +1584,39 @@ function assignAttribute(attributes, name, value) {
1591
1584
  function mergeAttributes(target, source) {
1592
1585
  for (const key in source) assignAttribute(target, key, source[key]);
1593
1586
  }
1594
- function closingBracket(source, start, limit = source.length) {
1595
- if (source[start] !== "[") return;
1596
- let depth = 0;
1597
- for (let offset = start + 1; offset < limit; offset++) if (source[offset] === "\\" && offset + 1 < limit) offset++;
1598
- else if (source[offset] === "[") depth++;
1599
- else if (source[offset] === "]") {
1600
- if (depth === 0) return offset;
1601
- depth--;
1602
- }
1603
- }
1604
1587
  function scanAttributes(source, start, attributes, limit = source.length) {
1605
1588
  if (source[start] !== "{" || source[start + 1] === "{") return;
1606
1589
  let offset = start + 1;
1607
- const readUntil = (stops) => {
1608
- const valueStart = offset;
1609
- while (offset < limit && source[offset] !== "\n" && source[offset] !== "\r" && !stops.includes(source[offset])) if (source[offset] === "\\" && offset + 1 < limit) offset += 2;
1610
- else offset++;
1611
- return source.slice(valueStart, offset);
1590
+ const scanUntil = (stops) => {
1591
+ while (offset < limit) {
1592
+ const character = source[offset];
1593
+ if (character === "\n" || character === "\r" || stops.includes(character)) break;
1594
+ offset += character === "\\" && offset + 1 < limit ? 2 : 1;
1595
+ }
1612
1596
  };
1613
- const readQuoted = (quote) => {
1614
- const valueStart = ++offset;
1615
- while (offset < limit && source[offset] !== "\n" && source[offset] !== "\r" && source[offset] !== quote) offset += source[offset] === "\\" && offset + 1 < limit ? 2 : 1;
1616
- if (source[offset] !== quote) return;
1617
- const value = source.slice(valueStart, offset);
1597
+ const scanQuoted = (quote) => {
1618
1598
  offset++;
1619
- return value;
1599
+ while (offset < limit) {
1600
+ const character = source[offset];
1601
+ if (character === "\n" || character === "\r" || character === quote) break;
1602
+ offset += character === "\\" && offset + 1 < limit ? 2 : 1;
1603
+ }
1604
+ if (source[offset] !== quote) return false;
1605
+ offset++;
1606
+ return true;
1620
1607
  };
1621
- const readBracketed = (close) => {
1622
- const valueStart = offset;
1608
+ const scanBracketed = (close) => {
1623
1609
  const stack = [close];
1624
1610
  offset++;
1625
1611
  while (offset < limit && stack.length > 0) {
1626
1612
  const character = source[offset];
1627
- if (character === "\n" || character === "\r") return;
1613
+ if (character === "\n" || character === "\r") return false;
1628
1614
  if (character === "\\" && offset + 1 < limit) {
1629
1615
  offset += 2;
1630
1616
  continue;
1631
1617
  }
1632
1618
  if (character === "\"" || character === "'" || character === "`") {
1633
- if (readQuoted(character) === void 0) return;
1619
+ if (!scanQuoted(character)) return false;
1634
1620
  continue;
1635
1621
  }
1636
1622
  const nestedClose = brackets[character];
@@ -1638,7 +1624,7 @@ function scanAttributes(source, start, attributes, limit = source.length) {
1638
1624
  else if (character === stack.at(-1)) stack.pop();
1639
1625
  offset++;
1640
1626
  }
1641
- return stack.length === 0 ? source.slice(valueStart, offset) : void 0;
1627
+ return stack.length === 0;
1642
1628
  };
1643
1629
  while (offset < limit) {
1644
1630
  while (isHorizontalWhitespace(source[offset])) offset++;
@@ -1646,31 +1632,49 @@ function scanAttributes(source, start, attributes, limit = source.length) {
1646
1632
  const marker = source[offset];
1647
1633
  if (marker === "." || marker === "#") {
1648
1634
  offset++;
1649
- const value = readUntil(" #.}");
1650
- if (!value) return;
1651
- if (attributes) assignAttribute(attributes, marker === "." ? "class" : "id", value);
1635
+ const valueStart = offset;
1636
+ scanUntil(" #.}");
1637
+ if (offset === valueStart) return;
1638
+ if (attributes) assignAttribute(attributes, marker === "." ? "class" : "id", source.slice(valueStart, offset));
1652
1639
  continue;
1653
1640
  }
1654
1641
  const nameStart = offset;
1655
- if (source[offset] === ":") offset++;
1656
- if (!isAsciiLetter(source[offset]) && source[offset] !== "_") return;
1642
+ if (source.charCodeAt(offset) === 58) offset++;
1643
+ let code = source.charCodeAt(offset);
1644
+ if (!isAsciiLetter(code) && code !== 95) return;
1657
1645
  offset++;
1658
- while (isAsciiLetter(source[offset]) || isAsciiDigit(source[offset]) || source[offset] === "_" || source[offset] === "-") offset++;
1659
- const rawName = source.slice(nameStart, offset);
1646
+ while (true) {
1647
+ code = source.charCodeAt(offset);
1648
+ if (!isAsciiLetter(code) && !isAsciiDigit(code) && code !== 95 && code !== 45) break;
1649
+ offset++;
1650
+ }
1651
+ const nameEnd = offset;
1660
1652
  while (isHorizontalWhitespace(source[offset])) offset++;
1661
1653
  if (source[offset] !== "=") {
1662
- if (attributes) assignAttribute(attributes, rawName.startsWith(":") ? rawName : `:${rawName}`, "true");
1654
+ if (attributes) {
1655
+ const name = source.slice(nameStart, nameEnd);
1656
+ assignAttribute(attributes, source.charCodeAt(nameStart) === 58 ? name : `:${name}`, "true");
1657
+ }
1663
1658
  continue;
1664
1659
  }
1665
1660
  offset++;
1666
1661
  while (isHorizontalWhitespace(source[offset])) offset++;
1667
1662
  const character = source[offset];
1668
- let value;
1669
- if (character === "\"" || character === "'" || character === "`") value = readQuoted(character);
1670
- else if (brackets[character]) value = readBracketed(brackets[character]);
1671
- else value = readUntil(" }");
1672
- if (value === void 0 || value === "" && character !== "\"" && character !== "'" && character !== "`") return;
1673
- if (attributes) assignAttribute(attributes, rawName, value);
1663
+ let valueStart = offset;
1664
+ let valueEnd;
1665
+ if (character === "\"" || character === "'" || character === "`") {
1666
+ if (!scanQuoted(character)) return;
1667
+ valueStart++;
1668
+ valueEnd = offset - 1;
1669
+ } else if (brackets[character]) {
1670
+ if (!scanBracketed(brackets[character])) return;
1671
+ valueEnd = offset;
1672
+ } else {
1673
+ scanUntil(" }");
1674
+ valueEnd = offset;
1675
+ if (valueEnd === valueStart) return;
1676
+ }
1677
+ if (attributes) assignAttribute(attributes, source.slice(nameStart, nameEnd), source.slice(valueStart, valueEnd));
1674
1678
  }
1675
1679
  }
1676
1680
  function attributesEnd(source, start, limit = source.length) {
@@ -1678,37 +1682,11 @@ function attributesEnd(source, start, limit = source.length) {
1678
1682
  }
1679
1683
  function parseAttributes(source, start) {
1680
1684
  const attributes = {};
1681
- const end = scanAttributes(source, start, attributes);
1682
- return end === void 0 ? void 0 : {
1683
- attributes,
1684
- end
1685
- };
1685
+ scanAttributes(source, start, attributes);
1686
+ return attributes;
1686
1687
  }
1687
1688
  //#endregion
1688
- //#region src/profile/features/attributes/index.ts
1689
- const decorateList = (build) => (tokenStart, context) => {
1690
- const result = build(tokenStart, context);
1691
- if (!result.spread) for (const item of result.children) {
1692
- const paragraph = !item.spread && item.children.length === 1 && item.children[0].type === "paragraph" ? item.children[0] : void 0;
1693
- if (paragraph?.attributes) {
1694
- item.attributes = paragraph.attributes;
1695
- delete paragraph.attributes;
1696
- }
1697
- }
1698
- return result;
1699
- };
1700
- const decorateBlockquote = (build) => (tokenStart, context) => {
1701
- const result = build(tokenStart, context);
1702
- const paragraph = result.children.length === 1 && result.children[0].type === "paragraph" ? result.children[0] : void 0;
1703
- if (paragraph?.attributes) {
1704
- result.attributes = paragraph.attributes;
1705
- delete paragraph.attributes;
1706
- }
1707
- return result;
1708
- };
1709
- function isMarkdownWhitespace(code) {
1710
- return code === 9 || code === 10 || code === 13 || code === 32;
1711
- }
1689
+ //#region src/profile/features/attributes/inline.ts
1712
1690
  function hasVisibleText(source, start, end) {
1713
1691
  for (let offset = start; offset < end; offset++) if (!isMarkdownWhitespace(source.charCodeAt(offset))) return true;
1714
1692
  return false;
@@ -1716,72 +1694,60 @@ function hasVisibleText(source, start, end) {
1716
1694
  function attributeEndAt(source, start) {
1717
1695
  return source[start + 1] === "{" || source[start - 1] === "{" || source[start - 1] === "$" ? void 0 : attributesEnd(source, start);
1718
1696
  }
1719
- function scanAttribute(source, start, tokens) {
1720
- const end = attributeEndAt(source, start);
1721
- if (end === void 0) return -1;
1722
- if (tokens.length === 0 && !hasVisibleText(source, 0, start)) {
1723
- let textEnd = end;
1724
- while (true) {
1725
- let next = textEnd;
1726
- while (source.charCodeAt(next) === 9 || source.charCodeAt(next) === 32) next++;
1727
- const nextEnd = source.charCodeAt(next) === 123 ? attributeEndAt(source, next) : void 0;
1728
- if (nextEnd === void 0) break;
1729
- textEnd = nextEnd;
1730
- }
1731
- return textEnd;
1732
- }
1733
- const previous = inlineTokenCount(tokens) - 1;
1734
- const previousEnd = previous >= 0 ? inlineTokenEnd(tokens, previous) : 0;
1735
- if (previousEnd < start && (previous >= 0 && inlineTokenKind(tokens, previous) === 256 || hasVisibleText(source, previousEnd, start))) appendInlineToken(tokens, 64, previousEnd, start);
1736
- appendInlineToken(tokens, 256, start, end, start > 0 && isMarkdownWhitespace(source.charCodeAt(start - 1)) ? 1 : 0);
1737
- let next = end;
1738
- while (isMarkdownWhitespace(source.charCodeAt(next))) next++;
1739
- if (next === source.length) for (let index = inlineTokenCount(tokens) - 1; index >= 0; index--) {
1740
- const kind = inlineTokenKind(tokens, index);
1741
- if (kind === 64 && !hasVisibleText(source, inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index))) continue;
1742
- if (kind !== 256) break;
1743
- setInlineTokenData(tokens, index, inlineTokenData(tokens, index) | 2);
1744
- }
1745
- return end;
1746
- }
1697
+ //#endregion
1698
+ //#region src/profile/features/attributes/index.ts
1747
1699
  const feature$18 = {
1748
- block: { decorators: [
1749
- {
1750
- rule: 6,
1751
- decorate: decorateList
1752
- },
1753
- {
1754
- rule: 7,
1755
- decorate: decorateList
1756
- },
1757
- {
1758
- rule: 1,
1759
- decorate: decorateBlockquote
1760
- }
1761
- ] },
1700
+ block: { decorators: blockDecorators },
1762
1701
  inline: {
1763
- scan: [{
1702
+ scans: [{
1764
1703
  marker: 123,
1765
- scan: scanAttribute
1704
+ scan(source, start, tokens) {
1705
+ const end = attributeEndAt(source, start);
1706
+ if (end === void 0) return -1;
1707
+ if (tokens.length === 0 && !hasVisibleText(source, 0, start)) {
1708
+ let textEnd = end;
1709
+ while (true) {
1710
+ let next = textEnd;
1711
+ while (source.charCodeAt(next) === 9 || source.charCodeAt(next) === 32) next++;
1712
+ const nextEnd = source.charCodeAt(next) === 123 ? attributeEndAt(source, next) : void 0;
1713
+ if (nextEnd === void 0) break;
1714
+ textEnd = nextEnd;
1715
+ }
1716
+ return textEnd;
1717
+ }
1718
+ const previous = inlineTokenCount(tokens) - 1;
1719
+ const previousEnd = previous >= 0 ? inlineTokenEnd(tokens, previous) : 0;
1720
+ if (previousEnd < start && (previous >= 0 && inlineTokenKind(tokens, previous) === 256 || hasVisibleText(source, previousEnd, start))) appendInlineToken(tokens, 64, previousEnd, start);
1721
+ appendInlineToken(tokens, 256, start, end, start > 0 && isMarkdownWhitespace(source.charCodeAt(start - 1)) ? 1 : 0);
1722
+ let next = end;
1723
+ while (isMarkdownWhitespace(source.charCodeAt(next))) next++;
1724
+ if (next === source.length) for (let index = inlineTokenCount(tokens) - 1; index >= 0; index--) {
1725
+ const kind = inlineTokenKind(tokens, index);
1726
+ if (kind === 64 && !hasVisibleText(source, inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index))) continue;
1727
+ if (kind !== 256) break;
1728
+ setInlineTokenData(tokens, index, inlineTokenData(tokens, index) | 2);
1729
+ }
1730
+ return end;
1731
+ }
1766
1732
  }],
1767
- build: [{
1733
+ builds: [{
1768
1734
  kind: "decorate",
1769
1735
  token: 256,
1770
1736
  apply(tokenIndex, sourceSpan, context, target) {
1771
1737
  const previous = target.children.at(-1);
1738
+ if (!previous) return false;
1772
1739
  const parsed = parseAttributes(context.view.text, inlineTokenStart(context.tokens, tokenIndex));
1773
- if (!previous || !parsed) return false;
1774
1740
  const flags = inlineTokenData(context.tokens, tokenIndex);
1775
1741
  const terminal = Boolean(flags & 2);
1776
1742
  const detached = Boolean(flags & 1);
1777
1743
  if (terminal && (detached || previous.type === "text" || target.attributes !== void 0)) {
1778
- if (target.attributes) mergeAttributes(target.attributes, parsed.attributes);
1779
- else target.attributes = parsed.attributes;
1744
+ if (target.attributes) mergeAttributes(target.attributes, parsed);
1745
+ else target.attributes = parsed;
1780
1746
  return true;
1781
1747
  }
1782
1748
  const attributes = previous.attributes;
1783
- if (attributes) mergeAttributes(attributes, parsed.attributes);
1784
- else previous.attributes = parsed.attributes;
1749
+ if (attributes) mergeAttributes(attributes, parsed);
1750
+ else previous.attributes = parsed;
1785
1751
  previous.position.end = context.locator.locationAt(sourceSpan.end);
1786
1752
  return true;
1787
1753
  }
@@ -1791,7 +1757,7 @@ const feature$18 = {
1791
1757
  //#endregion
1792
1758
  //#region src/profile/features/binding.ts
1793
1759
  const feature$17 = { inline: {
1794
- scan: [{
1760
+ scans: [{
1795
1761
  marker: 123,
1796
1762
  scan(source, start, tokens) {
1797
1763
  if (source.charCodeAt(start + 1) !== 123) return -1;
@@ -1805,7 +1771,7 @@ const feature$17 = { inline: {
1805
1771
  return end;
1806
1772
  }
1807
1773
  }],
1808
- build: [{
1774
+ builds: [{
1809
1775
  kind: "leaf",
1810
1776
  token: 135,
1811
1777
  build(tokenIndex, sourceSpan, context) {
@@ -1845,12 +1811,8 @@ function blockQuoteOffset(source, lines, index, markerOffset) {
1845
1811
  };
1846
1812
  }
1847
1813
  const feature$16 = { block: {
1848
- rules: [{
1849
- rule: 1,
1850
- syntax: {
1851
- kind: "block",
1852
- token: 64
1853
- },
1814
+ builds: [{
1815
+ token: 64,
1854
1816
  build(tokenStart, context) {
1855
1817
  const tokens = context.structure.tokens;
1856
1818
  const start = context.locator.locationAt(tokens.start(tokenStart));
@@ -1876,18 +1838,19 @@ const feature$16 = { block: {
1876
1838
  return true;
1877
1839
  },
1878
1840
  start(source, lines, start, contentOffset, out, context) {
1879
- const quoteLines = new BlockLines();
1880
- let index = start;
1881
- let lazyParagraph = false;
1841
+ const firstMarker = blockQuoteOffset(source, lines, start, contentOffset);
1842
+ const quoteLines = context.createLineView(lines, start, firstMarker.offset, firstMarker.prefixColumns);
1843
+ let index = start + 1;
1844
+ let lazyParagraph = context.endsWithParagraphLeaf(source, quoteLines, 0);
1882
1845
  for (; index < lines.length; index++) {
1883
- const markerOffset = index === start ? contentOffset : lineIndentOffset(source, lines, index);
1846
+ const markerOffset = lineIndentOffset(source, lines, index);
1884
1847
  const marker = blockQuoteOffset(source, lines, index, markerOffset);
1885
1848
  if (marker) {
1886
1849
  quoteLines.pushFrom(lines, index, marker.offset, marker.prefixColumns);
1887
1850
  lazyParagraph = context.endsWithParagraphLeaf(source, quoteLines, quoteLines.length - 1);
1888
1851
  continue;
1889
1852
  }
1890
- if (!lazyParagraph || isBlank(source, lines, index) || !lines.lazy(index) && context.startsInterruptingBlock(source, lines, index, markerOffset)) break;
1853
+ if (!lazyParagraph || markerOffset < 0 && isBlankLine(source, lines, index) || !lines.lazy(index) && context.startsInterruptingBlock(source, lines, index, markerOffset)) break;
1891
1854
  quoteLines.pushLazy(lines, index);
1892
1855
  }
1893
1856
  out.push(64, contentOffset, contentOffset + 1);
@@ -1913,12 +1876,8 @@ function isThematicBreak(source, lines, index, contentOffset) {
1913
1876
  }
1914
1877
  const feature$15 = {
1915
1878
  block: {
1916
- rules: [{
1917
- rule: 0,
1918
- syntax: {
1919
- kind: "leaf",
1920
- token: 256
1921
- },
1879
+ builds: [{
1880
+ token: 256,
1922
1881
  build(tokenStart, context) {
1923
1882
  return {
1924
1883
  type: "thematicBreak",
@@ -1942,7 +1901,7 @@ const feature$15 = {
1942
1901
  }
1943
1902
  }]
1944
1903
  },
1945
- inline: { build: [{
1904
+ inline: { builds: [{
1946
1905
  kind: "leaf",
1947
1906
  token: 128,
1948
1907
  build(tokenIndex, sourceSpan) {
@@ -1951,12 +1910,6 @@ const feature$15 = {
1951
1910
  position: sourceSpan
1952
1911
  };
1953
1912
  }
1954
- }, {
1955
- kind: "text",
1956
- token: 67,
1957
- build() {
1958
- return "\n";
1959
- }
1960
1913
  }] }
1961
1914
  };
1962
1915
  //#endregion
@@ -1994,13 +1947,11 @@ function closesFence(source, lines, index, fence) {
1994
1947
  while (source.charCodeAt(offset) === fence.marker) offset++;
1995
1948
  if (offset < markerEnd) return false;
1996
1949
  const lineEnd = lines.end(index);
1997
- while (offset < lineEnd && (source[offset] === " " || source[offset] === " ")) offset++;
1998
- return offset === lineEnd;
1950
+ return skipLineWhitespace(source, offset, lineEnd) === lineEnd;
1999
1951
  }
2000
1952
  function fencedBlock(source, lines, index, end, fence, closed) {
2001
- let infoStart = fence.offset + fence.length;
2002
1953
  const lineEnd = lines.end(index);
2003
- while (infoStart < lineEnd && (source[infoStart] === " " || source[infoStart] === " ")) infoStart++;
1954
+ const infoStart = skipLineWhitespace(source, fence.offset + fence.length, lineEnd);
2004
1955
  let content;
2005
1956
  if (lines.physicallyContiguous()) {
2006
1957
  const contentStart = lines.next(index);
@@ -2055,64 +2006,6 @@ function sourceColumnFenceContent(source, block) {
2055
2006
  return content;
2056
2007
  }
2057
2008
  //#endregion
2058
- //#region src/profile/features/text.ts
2059
- const entity = /&(?:#x[0-9A-F]{1,6}|#\d{1,7}|[A-Z][A-Z0-9]{0,30});/iy;
2060
- function isAsciiPunctuation(code) {
2061
- return code >= 33 && code <= 47 || code >= 58 && code <= 64 || code >= 91 && code <= 96 || code >= 123 && code <= 126;
2062
- }
2063
- function semanticText(value) {
2064
- return value.includes("\\") || value.includes("&") ? decodeString(value) : value;
2065
- }
2066
- const buildInlineText = (tokenIndex, context) => {
2067
- return inlineTokenText(context.view.text, context.tokens, tokenIndex);
2068
- };
2069
- const buildDecodedInlineText = (tokenIndex, context) => {
2070
- return semanticText(inlineTokenText(context.view.text, context.tokens, tokenIndex));
2071
- };
2072
- const feature$14 = { inline: {
2073
- scan: [{
2074
- marker: 38,
2075
- scan(source, start, tokens) {
2076
- const matchEnd = matchInlinePatternEnd(entity, source, start);
2077
- if (matchEnd < 0) return start + 1;
2078
- appendInlineToken(tokens, 66, start, matchEnd);
2079
- return matchEnd;
2080
- }
2081
- }, {
2082
- marker: 92,
2083
- scan(source, start, tokens) {
2084
- const next = source.charCodeAt(start + 1);
2085
- if (next === 10 || next === 13) {
2086
- appendInlineToken(tokens, 128, start, start + 1);
2087
- return start + 1;
2088
- }
2089
- if (isAsciiPunctuation(next)) {
2090
- const end = start + 2;
2091
- appendInlineToken(tokens, 65, start, end);
2092
- return end;
2093
- }
2094
- return start + (next === 32 || next === 9 ? 2 : 1);
2095
- }
2096
- }],
2097
- build: [
2098
- {
2099
- kind: "text",
2100
- token: 64,
2101
- build: buildInlineText
2102
- },
2103
- {
2104
- kind: "text",
2105
- token: 65,
2106
- build: buildDecodedInlineText
2107
- },
2108
- {
2109
- kind: "text",
2110
- token: 66,
2111
- build: buildDecodedInlineText
2112
- }
2113
- ]
2114
- } };
2115
- //#endregion
2116
2009
  //#region src/profile/features/code.ts
2117
2010
  const codeFenceRule = {
2118
2011
  alternateMarker: 126,
@@ -2123,18 +2016,13 @@ const codeFenceRule = {
2123
2016
  function codeFenceAt(source, lines, index, markerOffset) {
2124
2017
  return fenceAt$1(source, lines, index, codeFenceRule, markerOffset);
2125
2018
  }
2126
- const feature$13 = {
2019
+ const feature$14 = {
2127
2020
  block: {
2128
- rules: [{
2129
- rule: 8,
2130
- syntax: {
2131
- kind: "leaf",
2132
- token: 257
2133
- },
2021
+ builds: [{
2022
+ token: 257,
2134
2023
  build(tokenStart, context) {
2135
2024
  const tokens = context.structure.tokens;
2136
2025
  const block = tokens.value(tokenStart);
2137
- if (!block) throw new Error("FencedCodeBlock token has no fence metadata");
2138
2026
  const source = context.locator.normalizeLineEndings(block.content ?? tokens.text(context.source, tokenStart));
2139
2027
  const rawInfo = semanticText(block.info);
2140
2028
  const langEnd = rawInfo.search(/[ \t]/);
@@ -2149,22 +2037,16 @@ const feature$13 = {
2149
2037
  };
2150
2038
  }
2151
2039
  }, {
2152
- rule: 9,
2153
- syntax: {
2154
- kind: "leaf",
2155
- token: 258
2156
- },
2040
+ token: 258,
2157
2041
  build(tokenStart, context) {
2158
2042
  const tokens = context.structure.tokens;
2159
2043
  const offset = tokens.start(tokenStart);
2160
2044
  const contentLength = tokens.value(tokenStart);
2161
- const lines = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart)).split("\n").map((line) => removeIndent(line, 4));
2162
- while (lines.length && /^[ \t]*$/.test(lines[lines.length - 1])) lines.pop();
2163
2045
  return {
2164
2046
  type: "code",
2165
2047
  lang: null,
2166
2048
  meta: null,
2167
- value: lines.join("\n"),
2049
+ value: context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart)).replace(/^(?: {0,3}\t| {4}| {1,3}$)/gm, "").replace(/\n(?:[ \t]*\n)*[ \t]*$/, ""),
2168
2050
  position: context.locator.positionAt(offset, offset + contentLength)
2169
2051
  };
2170
2052
  }
@@ -2175,7 +2057,7 @@ const feature$13 = {
2175
2057
  let end = start + 1;
2176
2058
  while (end < lines.length && lineIndentOffset(source, lines, end) < 0) end++;
2177
2059
  let contentEnd = end;
2178
- while (contentEnd > start && isBlank(source, lines, contentEnd - 1)) contentEnd--;
2060
+ while (contentEnd > start && isBlankLine(source, lines, contentEnd - 1)) contentEnd--;
2179
2061
  const contentLength = lines.end(contentEnd - 1) - lines.start(start);
2180
2062
  appendLogicalToken(out, 258, source, lines, start, end, contentLength);
2181
2063
  return end;
@@ -2198,7 +2080,7 @@ const feature$13 = {
2198
2080
  }]
2199
2081
  },
2200
2082
  inline: {
2201
- scan: [{
2083
+ scans: [{
2202
2084
  marker: 96,
2203
2085
  scan(source, start, tokens) {
2204
2086
  if (source.charCodeAt(start - 1) === 96) return start + 1;
@@ -2218,17 +2100,16 @@ const feature$13 = {
2218
2100
  return start + 1;
2219
2101
  }
2220
2102
  }],
2221
- build: [{
2103
+ builds: [{
2222
2104
  kind: "leaf",
2223
2105
  token: 129,
2224
2106
  build: (tokenIndex, sourceSpan, context) => {
2225
- const text = inlineTokenText(context.view.text, context.tokens, tokenIndex);
2226
2107
  const markerLength = inlineTokenData(context.tokens, tokenIndex);
2227
- let value = context.locator.normalizeLineEndings(text.slice(markerLength, -markerLength));
2108
+ let value = context.locator.normalizeLineEndings(inlineTokenText(context.view.text, context.tokens, tokenIndex, markerLength));
2228
2109
  if (/^[ \n]/.test(value) && /[ \n]$/.test(value) && /[^ \n]/.test(value)) value = value.slice(1, -1);
2229
2110
  return {
2230
2111
  type: "inlineCode",
2231
- value: context.blockRule === 17 ? value.replace(/\\\|/g, "|") : value,
2112
+ value: context.tableCell ? value.replace(/\\\|/g, "|") : value,
2232
2113
  position: sourceSpan
2233
2114
  };
2234
2115
  }
@@ -2246,9 +2127,6 @@ function createInlineOutput(children, cursor) {
2246
2127
  trailingSpaces: 0
2247
2128
  };
2248
2129
  }
2249
- function lineEndingStart(source, lineStart) {
2250
- return source.charCodeAt(lineStart - 1) === 10 && source.charCodeAt(lineStart - 2) === 13 ? lineStart - 2 : lineStart - 1;
2251
- }
2252
2130
  function trimTrailingText(output) {
2253
2131
  const text = output.lastText;
2254
2132
  const removed = text ? output.trailingSpaces : 0;
@@ -2295,43 +2173,43 @@ function finishText(output, context) {
2295
2173
  function appendGap(output, context, start, end) {
2296
2174
  appendText(output, context.view.text.slice(start, end), context.view.mapOffset(start), context.view.mapEnd(end), context);
2297
2175
  }
2298
- function appendToken(output, context, tokenIndex, viewStart, viewEnd, build, textToken, syntaxNewline) {
2299
- const cursor = output.cursor;
2300
- if (!syntaxNewline) {
2301
- if (viewStart > cursor) appendGap(output, context, cursor, viewStart);
2302
- } else {
2303
- const viewLineStart = inlineTokenData(context.tokens, tokenIndex);
2304
- const viewLineEndingStart = lineEndingStart(context.view.text, viewLineStart);
2305
- if (viewStart > cursor) {
2306
- if (viewLineEndingStart > cursor) appendGap(output, context, cursor, viewLineEndingStart);
2307
- }
2308
- const previous = output.children.at(-1);
2309
- if (previous?.type === "break") {
2310
- previous.position.end = context.locator.locationAt(context.view.mapOffset(viewLineStart - 1) + 1);
2311
- return;
2312
- }
2313
- viewStart = viewLineEndingStart;
2314
- trimTrailingText(output);
2315
- }
2316
- const sourceStart = context.view.mapOffset(viewStart);
2317
- const sourceEnd = viewStart === viewEnd ? sourceStart : context.view.mapEnd(viewEnd);
2318
- if (textToken) appendText(output, build(tokenIndex, context), sourceStart, sourceEnd, context);
2319
- else {
2320
- finishText(output, context);
2321
- output.children.push(build(tokenIndex, context.locator.positionAt(sourceStart, sourceEnd), context));
2322
- output.lastText = void 0;
2323
- }
2176
+ function appendLeafToken(output, context, token, start, end, build) {
2177
+ if (start > output.cursor) appendGap(output, context, output.cursor, start);
2178
+ const sourceStart = context.view.mapOffset(start);
2179
+ const sourceEnd = start === end ? sourceStart : context.view.mapEnd(end);
2180
+ finishText(output, context);
2181
+ output.children.push(build(token, context.locator.positionAt(sourceStart, sourceEnd), context));
2182
+ output.lastText = void 0;
2324
2183
  }
2325
2184
  function appendRange(startToken, endToken, profile, context, output, closeKind = 0) {
2326
2185
  let index = startToken;
2327
2186
  while (index < endToken) {
2328
2187
  const kind = inlineTokenKind(context.tokens, index);
2188
+ if (kind === 67) {
2189
+ const endingStart = inlineTokenStart(context.tokens, index);
2190
+ const lineStart = inlineTokenData(context.tokens, index);
2191
+ const contentStart = inlineTokenEnd(context.tokens, index);
2192
+ if (endingStart > output.cursor) appendGap(output, context, output.cursor, endingStart);
2193
+ const previous = output.children.at(-1);
2194
+ if (previous?.type === "break") previous.position.end = context.locator.locationAt(context.view.mapOffset(lineStart - 1) + 1);
2195
+ else {
2196
+ trimTrailingText(output);
2197
+ appendText(output, "\n", context.view.mapOffset(endingStart), context.view.mapEnd(contentStart), context);
2198
+ }
2199
+ output.cursor = contentStart;
2200
+ index++;
2201
+ continue;
2202
+ }
2329
2203
  if (kind === closeKind) break;
2330
2204
  const build = profile.buildByKind[kind];
2331
2205
  const childStart = inlineTokenStart(context.tokens, index);
2332
2206
  if (kind < 192) {
2333
2207
  const childEnd = inlineTokenEnd(context.tokens, index);
2334
- appendToken(output, context, index, childStart, childEnd, build, kind < 128, kind === 67);
2208
+ if (kind < 128) {
2209
+ if (childStart > output.cursor) appendGap(output, context, output.cursor, childStart);
2210
+ const sourceStart = context.view.mapOffset(childStart);
2211
+ appendText(output, build(index, context), sourceStart, childStart === childEnd ? sourceStart : context.view.mapEnd(childEnd), context);
2212
+ } else appendLeafToken(output, context, index, childStart, childEnd, build);
2335
2213
  output.cursor = childEnd;
2336
2214
  index++;
2337
2215
  continue;
@@ -2379,17 +2257,27 @@ function appendSemantic(openToken, endToken, profile, context, output, build, cl
2379
2257
  output.cursor = childEnd;
2380
2258
  return closeToken + 1;
2381
2259
  }
2382
- function buildInlineFragment(tokenStart, blockRule, context) {
2383
- const region = context.cursor ? context.cursor.take(tokenStart) : resolveInlineRegion(context.source, context.profile, context.structure.tokens, tokenStart);
2384
- if (!region) return { children: [] };
2385
- const { tokens, view } = region;
2260
+ function buildInlineFragment(tokenStart, tableCell, context) {
2261
+ let tokens;
2262
+ let view;
2263
+ if (context.cursor) {
2264
+ const region = context.cursor.take(tokenStart);
2265
+ if (!region) return { children: [] };
2266
+ tokens = region.tokens;
2267
+ view = region.view;
2268
+ } else {
2269
+ const blockTokens = context.structure.tokens;
2270
+ if (blockTokens.kind(tokenStart + 1) !== 1) return { children: [] };
2271
+ view = new SourceView(context.source, blockTokens, tokenStart, blockTokens.nodeLength(tokenStart));
2272
+ tokens = context.profile.resolve(view.text, context.profile.tokenize(view.text), blockTokens);
2273
+ }
2386
2274
  const inlineContext = context.inlineContext ??= {
2387
- blockRule,
2388
2275
  locator: context.locator,
2276
+ tableCell,
2389
2277
  tokens,
2390
2278
  view
2391
2279
  };
2392
- inlineContext.blockRule = blockRule;
2280
+ inlineContext.tableCell = tableCell;
2393
2281
  inlineContext.tokens = tokens;
2394
2282
  inlineContext.view = view;
2395
2283
  const result = createInlineOutput([], 0);
@@ -2410,32 +2298,26 @@ function buildInlineFragment(tokenStart, blockRule, context) {
2410
2298
  function frontmatterFenceAt(source, lines, index, marker) {
2411
2299
  const start = lines.start(index);
2412
2300
  if (source[start] !== marker || source[start + 1] !== marker || source[start + 2] !== marker) return false;
2413
- for (let offset = start + 3, end = lines.end(index); offset < end; offset++) if (source[offset] !== " " && source[offset] !== " ") return false;
2414
- return true;
2301
+ const end = lines.end(index);
2302
+ return skipLineWhitespace(source, start + 3, end) === end;
2415
2303
  }
2416
- const buildFrontmatter = (tokenStart, context) => {
2304
+ const buildYamlBlock = (tokenStart, context) => {
2417
2305
  const tokens = context.structure.tokens;
2418
2306
  const text = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
2419
2307
  const contentStart = text.indexOf("\n") + 1;
2420
2308
  const closingEnd = text.endsWith("\n") ? text.length - 1 : text.length;
2421
2309
  const closingStart = text.lastIndexOf("\n", closingEnd - 1) + 1;
2422
- let value = text.slice(contentStart, closingStart);
2423
- if (value.endsWith("\n")) value = value.slice(0, -1);
2424
2310
  return {
2425
2311
  type: "yaml",
2426
- value,
2312
+ value: text.slice(contentStart, Math.max(contentStart, closingStart - 1)),
2427
2313
  position: leafBlockPosition(tokenStart, context)
2428
2314
  };
2429
2315
  };
2430
- function feature$12(marker) {
2316
+ function feature$13(marker) {
2431
2317
  return { block: {
2432
- rules: [{
2433
- rule: 13,
2434
- syntax: {
2435
- kind: "leaf",
2436
- token: 260
2437
- },
2438
- build: buildFrontmatter
2318
+ builds: [{
2319
+ token: 260,
2320
+ build: buildYamlBlock
2439
2321
  }],
2440
2322
  starts: [{
2441
2323
  codes: [marker.charCodeAt(0)],
@@ -2451,10 +2333,49 @@ function feature$12(marker) {
2451
2333
  } };
2452
2334
  }
2453
2335
  //#endregion
2336
+ //#region src/profile/features/component/shared.ts
2337
+ function componentNameEnd(source, start, block) {
2338
+ let code = source.charCodeAt(start);
2339
+ if (!isAsciiLetter(code) && code !== 36) return;
2340
+ let end = start + 1;
2341
+ while (end < source.length) {
2342
+ code = source.charCodeAt(end);
2343
+ if (!isAsciiLetter(code) && !isAsciiDigit(code) && code !== 36 && code !== 95 && code !== 45 && (!block || code !== 46)) break;
2344
+ end++;
2345
+ }
2346
+ return end;
2347
+ }
2348
+ function normalizeComponentName(value) {
2349
+ let result = "";
2350
+ let partLength = 0;
2351
+ let previousUpper;
2352
+ for (let index = 0; index < value.length; index++) {
2353
+ const character = value[index];
2354
+ const code = value.charCodeAt(index);
2355
+ if (code === 45 || code === 95 || code === 47 || code === 46) {
2356
+ partLength = 0;
2357
+ previousUpper = void 0;
2358
+ continue;
2359
+ }
2360
+ const upper = isAsciiLetter(code) ? code <= 90 : void 0;
2361
+ const next = value.charCodeAt(index + 1);
2362
+ if (result && (partLength === 0 || upper === true && (previousUpper === false || next >= 97 && next <= 122))) result += "-";
2363
+ result += character;
2364
+ partLength++;
2365
+ previousUpper = upper;
2366
+ }
2367
+ return result.toLowerCase();
2368
+ }
2369
+ //#endregion
2454
2370
  //#region src/profile/features/component/block.ts
2455
- function skipSpaces(source, offset, end) {
2456
- while (offset < end && (source[offset] === " " || source[offset] === " ")) offset++;
2457
- return offset;
2371
+ function closingBracket(source, start, limit) {
2372
+ let depth = 0;
2373
+ for (let offset = start + 1; offset < limit; offset++) if (source[offset] === "\\" && offset + 1 < limit) offset++;
2374
+ else if (source[offset] === "[") depth++;
2375
+ else if (source[offset] === "]") {
2376
+ if (depth === 0) return offset;
2377
+ depth--;
2378
+ }
2458
2379
  }
2459
2380
  function lineValue(source, lines, index) {
2460
2381
  const offset = lineIndentOffset(source, lines, index);
@@ -2479,7 +2400,7 @@ function slotOpeningAt(source, lines, index, contentOffset) {
2479
2400
  const nameEnd = componentNameEnd(source, contentOffset + 1, true);
2480
2401
  const lineEnd = lines.end(index);
2481
2402
  if (nameEnd === void 0 || nameEnd > lineEnd) return;
2482
- let offset = skipSpaces(source, nameEnd, lineEnd);
2403
+ let offset = skipLineWhitespace(source, nameEnd, lineEnd);
2483
2404
  let attributesStart;
2484
2405
  let parsedAttributesEnd;
2485
2406
  if (source[offset] === "{") {
@@ -2488,7 +2409,7 @@ function slotOpeningAt(source, lines, index, contentOffset) {
2488
2409
  attributesStart = offset;
2489
2410
  offset = parsedAttributesEnd;
2490
2411
  }
2491
- if (skipSpaces(source, offset, lineEnd) !== lineEnd) return;
2412
+ if (skipLineWhitespace(source, offset, lineEnd) !== lineEnd) return;
2492
2413
  return {
2493
2414
  attributesEnd: parsedAttributesEnd,
2494
2415
  attributesStart,
@@ -2502,10 +2423,10 @@ function blockOpeningAt(source, lines, index, contentOffset, shorthand) {
2502
2423
  const fenceSize = offset - contentOffset;
2503
2424
  if (shorthand ? fenceSize !== 1 : fenceSize < 2) return;
2504
2425
  const lineEnd = lines.end(index);
2505
- if (!shorthand) offset = skipSpaces(source, offset, lineEnd);
2426
+ if (!shorthand) offset = skipLineWhitespace(source, offset, lineEnd);
2506
2427
  const nameEnd = componentNameEnd(source, offset, true);
2507
2428
  if (nameEnd === void 0 || nameEnd > lineEnd) return;
2508
- offset = skipSpaces(source, nameEnd, lineEnd);
2429
+ offset = skipLineWhitespace(source, nameEnd, lineEnd);
2509
2430
  let labelStart;
2510
2431
  let labelEnd;
2511
2432
  if (source[offset] === "[") {
@@ -2513,7 +2434,7 @@ function blockOpeningAt(source, lines, index, contentOffset, shorthand) {
2513
2434
  if (close === void 0) return;
2514
2435
  labelStart = offset;
2515
2436
  labelEnd = close + 1;
2516
- offset = skipSpaces(source, labelEnd, lineEnd);
2437
+ offset = skipLineWhitespace(source, labelEnd, lineEnd);
2517
2438
  }
2518
2439
  let attributesStart;
2519
2440
  let parsedAttributesEnd;
@@ -2523,7 +2444,7 @@ function blockOpeningAt(source, lines, index, contentOffset, shorthand) {
2523
2444
  attributesStart = offset;
2524
2445
  offset = parsedAttributesEnd;
2525
2446
  }
2526
- if (skipSpaces(source, offset, lineEnd) !== lineEnd) return;
2447
+ if (skipLineWhitespace(source, offset, lineEnd) !== lineEnd) return;
2527
2448
  return {
2528
2449
  attributesEnd: parsedAttributesEnd,
2529
2450
  attributesStart,
@@ -2537,7 +2458,7 @@ function fenceAt(source, lines, index, size, contentOffset) {
2537
2458
  let offset = contentOffset;
2538
2459
  while (source[offset] === ":") offset++;
2539
2460
  const lineEnd = lines.end(index);
2540
- if (offset - contentOffset !== size || skipSpaces(source, offset, lineEnd) !== lineEnd) return;
2461
+ if (offset - contentOffset !== size || skipLineWhitespace(source, offset, lineEnd) !== lineEnd) return;
2541
2462
  return contentOffset;
2542
2463
  }
2543
2464
  function blockClose(source, lines, start, opening) {
@@ -2584,10 +2505,6 @@ function nextSlot(source, lines, start, end) {
2584
2505
  if (nested) index = blockClose(source, lines, index, nested)?.index ?? index;
2585
2506
  }
2586
2507
  }
2587
- function emitSlotOpening(opening, out) {
2588
- out.push(75, opening.offset, opening.nameEnd);
2589
- if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(3, opening.attributesStart, opening.attributesEnd);
2590
- }
2591
2508
  function emitComponentBody(source, lines, start, end, closingOffset, out, context) {
2592
2509
  let cursor = start;
2593
2510
  const yamlEnd = cursor < end ? yamlPropsEnd(source, lines, cursor, end) : void 0;
@@ -2604,7 +2521,9 @@ function emitComponentBody(source, lines, start, end, closingOffset, out, contex
2604
2521
  while (slot) {
2605
2522
  const following = nextSlot(source, lines, slot.index + 1, end);
2606
2523
  const next = following?.index ?? end;
2607
- emitSlotOpening(slot.opening, out);
2524
+ const opening = slot.opening;
2525
+ out.push(71, opening.offset, opening.nameEnd);
2526
+ if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(3, opening.attributesStart, opening.attributesEnd);
2608
2527
  context.scanLines(source, lines.slice(slot.index + 1, next), out);
2609
2528
  const slotEnd = following ? following.opening.offset : closingOffset;
2610
2529
  out.push(204, slotEnd, slotEnd);
@@ -2612,9 +2531,9 @@ function emitComponentBody(source, lines, start, end, closingOffset, out, contex
2612
2531
  }
2613
2532
  }
2614
2533
  function emitOpening(contentOffset, opening, out) {
2615
- out.push(74, contentOffset, opening.nameEnd);
2534
+ out.push(70, contentOffset, opening.nameEnd);
2616
2535
  if (opening.labelStart !== void 0 && opening.labelEnd !== void 0) {
2617
- out.push(133, opening.labelStart, opening.labelStart + 1);
2536
+ out.push(161, opening.labelStart, opening.labelStart + 1);
2618
2537
  if (opening.labelEnd > opening.labelStart + 2) out.push(1, opening.labelStart + 1, opening.labelEnd - 1);
2619
2538
  out.push(203, opening.labelEnd - 1, opening.labelEnd);
2620
2539
  }
@@ -2626,7 +2545,7 @@ const buildBlockLabel = (tokenStart, context) => {
2626
2545
  const start = context.locator.locationAt(tokens.start(tokenStart));
2627
2546
  return {
2628
2547
  type: "paragraph",
2629
- children: buildInlineFragment(tokenStart, 20, context).children,
2548
+ children: buildInlineFragment(tokenStart, false, context).children,
2630
2549
  position: {
2631
2550
  start,
2632
2551
  end: context.locator.locationAt(tokens.end(close))
@@ -2654,47 +2573,29 @@ function createBlockStart(shorthand) {
2654
2573
  return closing.index + 1;
2655
2574
  };
2656
2575
  }
2657
- const blockRules$2 = [
2658
- {
2659
- rule: 21,
2660
- syntax: {
2661
- kind: "leaf",
2662
- token: 262
2663
- },
2664
- build: buildFrontmatter
2665
- },
2576
+ const blockBuilds$2 = [
2666
2577
  {
2667
- rule: 20,
2668
- syntax: {
2669
- kind: "frame",
2670
- token: 133
2671
- },
2672
- inlineContent: true,
2673
- build: buildBlockLabel
2578
+ token: 262,
2579
+ build: buildYamlBlock
2674
2580
  },
2675
2581
  {
2676
- rule: 19,
2677
- syntax: {
2678
- kind: "block",
2679
- token: 74
2680
- },
2582
+ token: 70,
2681
2583
  build(tokenStart, context) {
2682
2584
  const tokens = context.structure.tokens;
2683
2585
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
2684
2586
  let openingToken = tokenStart + 1;
2685
- const label = tokens.kind(openingToken) === 133 ? openingToken : void 0;
2587
+ const label = tokens.kind(openingToken) === 161 ? openingToken : void 0;
2686
2588
  if (label !== void 0) openingToken += tokens.nodeLength(label);
2687
2589
  const attributesToken = tokens.kind(openingToken) === 3 ? openingToken++ : void 0;
2688
2590
  const parsed = attributesToken !== void 0 ? parseAttributes(context.source, tokens.start(attributesToken)) : void 0;
2689
2591
  const start = context.locator.locationAt(tokens.start(tokenStart));
2690
- const children = [];
2691
- if (label) children.push(buildBlockNode(label, context));
2692
- children.push(...buildBlockChildren(tokenStart, context));
2592
+ let children = buildBlockChildren(tokenStart, context);
2593
+ if (label) children = [buildBlockLabel(label, context), ...children];
2693
2594
  const opening = tokens.text(context.source, tokenStart);
2694
2595
  return {
2695
2596
  type: "blockComponent",
2696
2597
  name: normalizeComponentName(opening.slice(opening.lastIndexOf(":") + 1).trim()),
2697
- attributes: parsed?.attributes ?? {},
2598
+ attributes: parsed ?? {},
2698
2599
  position: {
2699
2600
  start,
2700
2601
  end: context.locator.locationAt(tokens.end(close))
@@ -2704,11 +2605,7 @@ const blockRules$2 = [
2704
2605
  }
2705
2606
  },
2706
2607
  {
2707
- rule: 22,
2708
- syntax: {
2709
- kind: "block",
2710
- token: 75
2711
- },
2608
+ token: 71,
2712
2609
  build(tokenStart, context) {
2713
2610
  const tokens = context.structure.tokens;
2714
2611
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
@@ -2720,7 +2617,7 @@ const blockRules$2 = [
2720
2617
  type: "blockComponent",
2721
2618
  name: "template",
2722
2619
  attributes: {
2723
- ...parsed?.attributes,
2620
+ ...parsed,
2724
2621
  name: normalizeComponentName(tokens.text(context.source, tokenStart).slice(1).trim())
2725
2622
  },
2726
2623
  children,
@@ -2744,16 +2641,10 @@ const blockStarts$2 = [{
2744
2641
  }];
2745
2642
  //#endregion
2746
2643
  //#region src/profile/features/component/inline.ts
2747
- const allowedPrevious = /[ \t\n\r\p{sc=Han}\p{sc=Hira}\p{sc=Kana}\p{sc=Hang}\p{P}]/u;
2748
- function canStartInlineColon(source, start) {
2749
- if (start <= 0) return true;
2750
- const previous = source[start - 1];
2751
- return previous !== ":" && allowedPrevious.test(previous);
2752
- }
2753
2644
  const inlineScans = [{
2754
2645
  marker: 58,
2755
2646
  scan(source, start, tokens) {
2756
- const end = canStartInlineColon(source, start) ? componentNameEnd(source, start + 1, false) : void 0;
2647
+ const end = hasInlineColonBoundary(source, start) ? componentNameEnd(source, start + 1, false) : void 0;
2757
2648
  if (end === void 0) return -1;
2758
2649
  appendInlineToken(tokens, 137, start, end);
2759
2650
  return end;
@@ -2771,14 +2662,14 @@ const buildInlineComponent = (open, close, sourceSpan, children, context) => {
2771
2662
  };
2772
2663
  //#endregion
2773
2664
  //#region src/profile/features/component/index.ts
2774
- const feature$11 = {
2665
+ const feature$12 = {
2775
2666
  block: {
2776
- rules: blockRules$2,
2667
+ builds: blockBuilds$2,
2777
2668
  starts: blockStarts$2
2778
2669
  },
2779
2670
  inline: {
2780
- scan: inlineScans,
2781
- build: [
2671
+ scans: inlineScans,
2672
+ builds: [
2782
2673
  {
2783
2674
  kind: "leaf",
2784
2675
  token: 137,
@@ -2810,13 +2701,13 @@ const feature$11 = {
2810
2701
  //#endregion
2811
2702
  //#region src/profile/features/emoji/index.ts
2812
2703
  function isShortcodeCharacter(code) {
2813
- return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 43 || code === 45 || code === 95;
2704
+ return isAsciiLetter(code) || isAsciiDigit(code) || code === 43 || code === 45 || code === 95;
2814
2705
  }
2815
- const feature$10 = { inline: {
2816
- scan: [{
2706
+ const feature$11 = { inline: {
2707
+ scans: [{
2817
2708
  marker: 58,
2818
2709
  scan(source, start, tokens) {
2819
- if (!canStartInlineColon(source, start)) return -1;
2710
+ if (!hasInlineColonBoundary(source, start)) return -1;
2820
2711
  let end = start + 1;
2821
2712
  while (isShortcodeCharacter(source.charCodeAt(end))) end++;
2822
2713
  if (end === start + 1 || source.charCodeAt(end) !== 58) return -1;
@@ -2825,7 +2716,7 @@ const feature$10 = { inline: {
2825
2716
  return end;
2826
2717
  }
2827
2718
  }],
2828
- build: [{
2719
+ builds: [{
2829
2720
  kind: "leaf",
2830
2721
  token: 136,
2831
2722
  build(tokenIndex, sourceSpan, context) {
@@ -2838,29 +2729,8 @@ const feature$10 = { inline: {
2838
2729
  }]
2839
2730
  } };
2840
2731
  //#endregion
2841
- //#region src/profile/utils.ts
2842
- function normalizeAssociationLabel(label) {
2843
- scan: {
2844
- let hasUppercase = false;
2845
- for (let index = 0; index < label.length; index++) {
2846
- const code = label.charCodeAt(index);
2847
- if (code === 32) {
2848
- if (index === 0 || index + 1 === label.length || label.charCodeAt(index + 1) === 32) break scan;
2849
- continue;
2850
- }
2851
- if (code < 32 || code > 126) break scan;
2852
- if (code >= 65 && code <= 90) hasUppercase = true;
2853
- }
2854
- return hasUppercase ? label.toLowerCase() : label;
2855
- }
2856
- return label.trim().replace(/[ \t\r\n]+/g, " ").toLowerCase().toUpperCase().toLowerCase();
2857
- }
2858
- //#endregion
2859
2732
  //#region src/profile/features/footnote/shared.ts
2860
2733
  const footnoteDefinitionPrefix = "footnote\0";
2861
- function isLabelWhitespace(code) {
2862
- return code === 32 || code === 9 || code === 10 || code === 13;
2863
- }
2864
2734
  function footnoteLabelAt(source, start, limit) {
2865
2735
  if (source.charCodeAt(start) !== 91 || source.charCodeAt(start + 1) !== 94) return;
2866
2736
  const labelStart = start + 2;
@@ -2868,9 +2738,9 @@ function footnoteLabelAt(source, start, limit) {
2868
2738
  let length = 0;
2869
2739
  while (offset < limit) {
2870
2740
  const code = source.charCodeAt(offset);
2871
- if (isLabelWhitespace(code)) return;
2741
+ if (isMarkdownWhitespace(code)) return;
2872
2742
  if (code === 92 && offset + 1 < limit) {
2873
- if (isLabelWhitespace(source.charCodeAt(offset + 1))) return;
2743
+ if (isMarkdownWhitespace(source.charCodeAt(offset + 1))) return;
2874
2744
  offset += 2;
2875
2745
  length += 2;
2876
2746
  } else if (code === 93) {
@@ -2898,36 +2768,22 @@ function definitionAt(source, lines, index, markerStart) {
2898
2768
  const label = footnoteLabelAt(source, markerStart, lineEnd);
2899
2769
  if (!label || source.charCodeAt(label.end) !== 58) return;
2900
2770
  const markerEnd = label.end + 1;
2901
- let contentOffset = markerEnd;
2902
- while (contentOffset < lineEnd) {
2903
- const code = source.charCodeAt(contentOffset);
2904
- if (code !== 32 && code !== 9) break;
2905
- contentOffset++;
2906
- }
2771
+ const contentOffset = skipLineWhitespace(source, markerEnd, lineEnd);
2907
2772
  return {
2908
2773
  ...label,
2909
2774
  contentOffset,
2910
2775
  markerEnd
2911
2776
  };
2912
2777
  }
2913
- function definitionFields(tokens, token) {
2914
- const fields = tokens.value(token);
2915
- if (tokens.kind(token) !== 72 || !fields) throw new Error("Expected FootnoteDefinitionOpen token to contain parsed fields");
2916
- return fields;
2917
- }
2918
2778
  //#endregion
2919
2779
  //#region src/profile/features/footnote/index.ts
2920
- const feature$9 = {
2780
+ const feature$10 = {
2921
2781
  block: {
2922
- rules: [{
2923
- rule: 12,
2924
- syntax: {
2925
- kind: "block",
2926
- token: 72
2927
- },
2782
+ builds: [{
2783
+ token: 68,
2928
2784
  build(tokenStart, context) {
2929
2785
  const tokens = context.structure.tokens;
2930
- const fields = definitionFields(tokens, tokenStart);
2786
+ const fields = tokens.value(tokenStart);
2931
2787
  const start = context.locator.locationAt(tokens.start(tokenStart));
2932
2788
  const children = buildBlockChildren(tokenStart, context);
2933
2789
  return {
@@ -2956,8 +2812,7 @@ const feature$9 = {
2956
2812
  start(source, lines, start, contentOffset, out, context) {
2957
2813
  const match = definitionAt(source, lines, start, contentOffset);
2958
2814
  if (!match) return;
2959
- const definitionLines = new BlockLines();
2960
- definitionLines.pushFrom(lines, start, match.contentOffset, 0);
2815
+ const definitionLines = context.createLineView(lines, start, match.contentOffset, 0);
2961
2816
  let index = start + 1;
2962
2817
  let lazyParagraph = context.endsWithParagraphLeaf(source, definitionLines, 0);
2963
2818
  while (index < lines.length) {
@@ -2977,8 +2832,8 @@ const feature$9 = {
2977
2832
  definitionLines.pushLazy(lines, index);
2978
2833
  index++;
2979
2834
  }
2980
- while (definitionLines.length > 0 && isBlank(source, definitionLines, definitionLines.length - 1)) definitionLines.pop();
2981
- out.push(72, contentOffset, match.markerEnd, {
2835
+ while (definitionLines.length > 0 && isBlankLine(source, definitionLines, definitionLines.length - 1)) definitionLines.pop();
2836
+ out.push(68, contentOffset, match.markerEnd, {
2982
2837
  definitionKey: match.definitionKey,
2983
2838
  value: {
2984
2839
  label: match.label,
@@ -2992,11 +2847,11 @@ const feature$9 = {
2992
2847
  }
2993
2848
  }]
2994
2849
  },
2995
- inline: { build: [{
2850
+ inline: { builds: [{
2996
2851
  kind: "leaf",
2997
2852
  token: 133,
2998
2853
  build(tokenIndex, sourceSpan, context) {
2999
- const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(2, -1);
2854
+ const label = inlineTokenText(context.view.text, context.tokens, tokenIndex, 2, 1);
3000
2855
  return {
3001
2856
  type: "footnoteReference",
3002
2857
  identifier: normalizeAssociationLabel(label),
@@ -3007,6 +2862,61 @@ const feature$9 = {
3007
2862
  }] }
3008
2863
  };
3009
2864
  //#endregion
2865
+ //#region src/profile/features/text.ts
2866
+ const entity = /&(?:#x[0-9A-F]{1,6}|#\d{1,7}|[A-Z][A-Z0-9]{0,30});/iy;
2867
+ function isAsciiPunctuation(code) {
2868
+ return code >= 33 && code <= 47 || code >= 58 && code <= 64 || code >= 91 && code <= 96 || code >= 123 && code <= 126;
2869
+ }
2870
+ const buildInlineText = (tokenIndex, context) => {
2871
+ return inlineTokenText(context.view.text, context.tokens, tokenIndex);
2872
+ };
2873
+ const buildDecodedInlineText = (tokenIndex, context) => {
2874
+ return semanticText(inlineTokenText(context.view.text, context.tokens, tokenIndex));
2875
+ };
2876
+ const feature$9 = { inline: {
2877
+ scans: [{
2878
+ marker: 38,
2879
+ scan(source, start, tokens) {
2880
+ const matchEnd = matchInlinePatternEnd(entity, source, start);
2881
+ if (matchEnd < 0) return start + 1;
2882
+ appendInlineToken(tokens, 66, start, matchEnd);
2883
+ return matchEnd;
2884
+ }
2885
+ }, {
2886
+ marker: 92,
2887
+ scan(source, start, tokens) {
2888
+ const next = source.charCodeAt(start + 1);
2889
+ if (next === 10 || next === 13) {
2890
+ appendInlineToken(tokens, 128, start, start + 1);
2891
+ return start + 1;
2892
+ }
2893
+ if (isAsciiPunctuation(next)) {
2894
+ const end = start + 2;
2895
+ appendInlineToken(tokens, 65, start, end);
2896
+ return end;
2897
+ }
2898
+ return start + (next === 32 || next === 9 ? 2 : 1);
2899
+ }
2900
+ }],
2901
+ builds: [
2902
+ {
2903
+ kind: "text",
2904
+ token: 64,
2905
+ build: buildInlineText
2906
+ },
2907
+ {
2908
+ kind: "text",
2909
+ token: 65,
2910
+ build: buildDecodedInlineText
2911
+ },
2912
+ {
2913
+ kind: "text",
2914
+ token: 66,
2915
+ build: buildDecodedInlineText
2916
+ }
2917
+ ]
2918
+ } };
2919
+ //#endregion
3010
2920
  //#region src/profile/features/formatting.ts
3011
2921
  const scanFormatting = (source, start, tokens) => {
3012
2922
  const code = source.charCodeAt(start);
@@ -3095,9 +3005,9 @@ function feature$8(strikethroughOptions) {
3095
3005
  });
3096
3006
  }
3097
3007
  return { inline: {
3098
- scan: scans,
3008
+ scans,
3099
3009
  delimiters,
3100
- build: builds
3010
+ builds
3101
3011
  } };
3102
3012
  }
3103
3013
  //#endregion
@@ -3124,8 +3034,7 @@ function atxAt(source, lines, index, markerOffset) {
3124
3034
  const lineEnd = lines.end(index);
3125
3035
  while (markerEnd < lineEnd && markerEnd - markerOffset < 6 && source[markerEnd] === "#") markerEnd++;
3126
3036
  if (markerEnd < lineEnd && source[markerEnd] !== " " && source[markerEnd] !== " ") return;
3127
- let contentOffset = markerEnd;
3128
- while (contentOffset < lineEnd && (source[contentOffset] === " " || source[contentOffset] === " ")) contentOffset++;
3037
+ const contentOffset = skipLineWhitespace(source, markerEnd, lineEnd);
3129
3038
  let contentEnd = lineEnd;
3130
3039
  while (contentEnd > contentOffset && (source[contentEnd - 1] === " " || source[contentEnd - 1] === " ")) contentEnd--;
3131
3040
  let closer = contentEnd;
@@ -3141,27 +3050,21 @@ function atxAt(source, lines, index, markerOffset) {
3141
3050
  };
3142
3051
  }
3143
3052
  function setextMarkerAt(source, lines, index, markerOffset) {
3144
- if (markerOffset < 0) return;
3145
3053
  const marker = source[markerOffset];
3146
3054
  if (marker !== "=" && marker !== "-") return;
3147
3055
  const lineEnd = lines.end(index);
3148
3056
  let offset = markerOffset + 1;
3149
3057
  while (offset < lineEnd && source[offset] === marker) offset++;
3150
- while (offset < lineEnd && (source[offset] === " " || source[offset] === " ")) offset++;
3058
+ offset = skipLineWhitespace(source, offset, lineEnd);
3151
3059
  return offset === lineEnd ? marker : void 0;
3152
3060
  }
3153
3061
  const feature$7 = { block: {
3154
- rules: [{
3155
- rule: 2,
3156
- syntax: {
3157
- kind: "block",
3158
- token: 65
3159
- },
3160
- inlineContent: true,
3062
+ builds: [{
3063
+ token: 96,
3161
3064
  build(tokenStart, context) {
3162
3065
  const tokens = context.structure.tokens;
3163
3066
  const start = context.locator.locationAt(tokens.start(tokenStart));
3164
- const inline = buildInlineFragment(tokenStart, 2, context);
3067
+ const inline = buildInlineFragment(tokenStart, false, context);
3165
3068
  const result = {
3166
3069
  type: "heading",
3167
3070
  depth: tokens.end(tokenStart) - tokens.start(tokenStart),
@@ -3175,19 +3078,14 @@ const feature$7 = { block: {
3175
3078
  return result;
3176
3079
  }
3177
3080
  }, {
3178
- rule: 3,
3179
- syntax: {
3180
- kind: "block",
3181
- token: [66, 67]
3182
- },
3183
- inlineContent: true,
3081
+ token: [97, 98],
3184
3082
  build(tokenStart, context) {
3185
3083
  const tokens = context.structure.tokens;
3186
- const inline = buildInlineFragment(tokenStart, 3, context);
3084
+ const inline = buildInlineFragment(tokenStart, false, context);
3187
3085
  const children = inline.children;
3188
3086
  const result = {
3189
3087
  type: "heading",
3190
- depth: tokens.kind(tokenStart) === 66 ? 1 : 2,
3088
+ depth: tokens.kind(tokenStart) === 97 ? 1 : 2,
3191
3089
  children,
3192
3090
  position: {
3193
3091
  start: firstChildStart(children),
@@ -3206,7 +3104,7 @@ const feature$7 = { block: {
3206
3104
  start(source, lines, start, contentOffset, out) {
3207
3105
  const atx = atxAt(source, lines, start, contentOffset);
3208
3106
  if (!atx) return;
3209
- out.push(65, contentOffset, atx.markerEnd);
3107
+ out.push(96, contentOffset, atx.markerEnd);
3210
3108
  if (atx.contentEnd > atx.contentOffset) out.push(1, atx.contentOffset, atx.contentEnd);
3211
3109
  const lineEnd = lines.end(start);
3212
3110
  out.push(193, lineEnd, lineEnd);
@@ -3224,27 +3122,30 @@ const autolink = /<(?:[A-Z][A-Z0-9+.\-]{1,31}:[^ \t\n\r<>]+|[\w!#$%&'*+\-/=?^`{|
3224
3122
  const inlineHtml = /<[A-Za-z][A-Za-z0-9-]*(?:[ \t\n\r]+[A-Za-z_:][\w.:-]*(?:[ \t\n\r]*=[ \t\n\r]*(?:[^ \t\n\r"'=<>`]+|'[^']*'|"[^"]*"))?)*[ \t\n\r]*\/?>|<\/[A-Za-z][A-Za-z0-9-]*[ \t\n\r]*>|<\?[\s\S]*?\?>|<![A-Z][\s\S]*?>|<!\[CDATA\[[\s\S]*?\]\]>/y;
3225
3123
  function htmlStartAt(source, lines, index, contentOffset) {
3226
3124
  const body = source.slice(contentOffset, lines.end(index));
3125
+ switch (body.charCodeAt(1)) {
3126
+ case 63: return {
3127
+ interruptParagraph: true,
3128
+ terminator: "?>"
3129
+ };
3130
+ case 33:
3131
+ if (body.startsWith("<!--")) return {
3132
+ interruptParagraph: true,
3133
+ terminator: "-->"
3134
+ };
3135
+ if (body.startsWith("<![CDATA[")) return {
3136
+ interruptParagraph: true,
3137
+ terminator: "]]>"
3138
+ };
3139
+ if (/[A-Z]/.test(body[2] ?? "")) return {
3140
+ interruptParagraph: true,
3141
+ terminator: ">"
3142
+ };
3143
+ }
3227
3144
  const lower = body.toLowerCase();
3228
3145
  for (const tag of htmlRawNames) if (lower.startsWith(`<${tag}`) && (lower.length === tag.length + 1 || /[ \t>]/.test(lower[tag.length + 1]))) return {
3229
3146
  interruptParagraph: true,
3230
3147
  terminator: `</${tag}>`
3231
3148
  };
3232
- if (body.startsWith("<!--")) return {
3233
- interruptParagraph: true,
3234
- terminator: "-->"
3235
- };
3236
- if (body.startsWith("<?")) return {
3237
- interruptParagraph: true,
3238
- terminator: "?>"
3239
- };
3240
- if (body.startsWith("<![CDATA[")) return {
3241
- interruptParagraph: true,
3242
- terminator: "]]>"
3243
- };
3244
- if (body.startsWith("<!") && /[A-Z]/.test(body[2] ?? "")) return {
3245
- interruptParagraph: true,
3246
- terminator: ">"
3247
- };
3248
3149
  const tag = /^<\/?([a-z][a-z0-9-]*)(?=[ \t\n\r/>]|$)/i.exec(body)?.[1].toLowerCase();
3249
3150
  if (tag && htmlBlockTags.has(tag)) return { interruptParagraph: true };
3250
3151
  if (completeHtmlTag.test(body)) return { interruptParagraph: false };
@@ -3258,18 +3159,13 @@ const buildInlineHtml = (tokenIndex, sourceSpan, context) => {
3258
3159
  };
3259
3160
  const feature$6 = {
3260
3161
  block: {
3261
- rules: [{
3262
- rule: 10,
3263
- syntax: {
3264
- kind: "leaf",
3265
- token: 259
3266
- },
3162
+ builds: [{
3163
+ token: 259,
3267
3164
  build(tokenStart, context) {
3268
3165
  const tokens = context.structure.tokens;
3269
3166
  const offset = tokens.start(tokenStart);
3270
3167
  const end = tokens.end(tokenStart);
3271
3168
  const unterminated = tokens.value(tokenStart);
3272
- if (tokens.kind(tokenStart) !== 259 || unterminated === void 0) throw new Error("HTML block lacks termination state");
3273
3169
  let html = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
3274
3170
  if (!unterminated && html.endsWith("\n")) html = html.slice(0, -1);
3275
3171
  return {
@@ -3287,20 +3183,23 @@ const feature$6 = {
3287
3183
  start(source, lines, start, contentOffset, out) {
3288
3184
  const htmlStart = htmlStartAt(source, lines, start, contentOffset);
3289
3185
  if (!htmlStart) return;
3290
- let end = start + 1;
3186
+ let end = start;
3291
3187
  let unterminated = false;
3292
- if (htmlStart.terminator && !source.slice(lines.start(start), lines.end(start)).toLowerCase().includes(htmlStart.terminator)) {
3188
+ if (htmlStart.terminator) {
3293
3189
  while (end < lines.length && !source.slice(lines.start(end), lines.end(end)).toLowerCase().includes(htmlStart.terminator)) end++;
3294
- if (end < lines.length) end++;
3295
- else unterminated = true;
3296
- } else if (!htmlStart.terminator) while (end < lines.length && !isBlank(source, lines, end)) end++;
3190
+ if (end === lines.length) unterminated = true;
3191
+ else end++;
3192
+ } else {
3193
+ end++;
3194
+ while (end < lines.length && !isBlankLine(source, lines, end)) end++;
3195
+ }
3297
3196
  appendLogicalToken(out, 259, source, lines, start, end, unterminated);
3298
3197
  return end;
3299
3198
  }
3300
3199
  }]
3301
3200
  },
3302
3201
  inline: {
3303
- scan: [{
3202
+ scans: [{
3304
3203
  marker: 60,
3305
3204
  scan(source, start, tokens) {
3306
3205
  let end = matchInlinePatternEnd(htmlComment, source, start);
@@ -3318,7 +3217,7 @@ const feature$6 = {
3318
3217
  return end;
3319
3218
  }
3320
3219
  }],
3321
- build: [{
3220
+ builds: [{
3322
3221
  kind: "leaf",
3323
3222
  token: 131,
3324
3223
  build: buildInlineHtml
@@ -3334,8 +3233,7 @@ const feature$6 = {
3334
3233
  function skipWhitespace(source, start) {
3335
3234
  let end = start;
3336
3235
  while (end < source.length) {
3337
- const code = source.charCodeAt(end);
3338
- if (code !== 9 && code !== 10 && code !== 13 && code !== 32) break;
3236
+ if (!isMarkdownWhitespace(source.charCodeAt(end))) break;
3339
3237
  end++;
3340
3238
  }
3341
3239
  return end;
@@ -3376,7 +3274,7 @@ function linkDestinationEnd(source, start) {
3376
3274
  end++;
3377
3275
  continue;
3378
3276
  }
3379
- if (isLinkWhitespace(code)) break;
3277
+ if (isMarkdownWhitespace(code)) break;
3380
3278
  consumed = true;
3381
3279
  end++;
3382
3280
  }
@@ -3422,16 +3320,13 @@ function scanLinkTail(source, start, tokens) {
3422
3320
  appendInlineToken(tokens, 73, start, end, destinationEnd - start);
3423
3321
  return end;
3424
3322
  }
3425
- function isLinkWhitespace(code) {
3426
- return code === 9 || code === 10 || code === 13 || code === 32;
3427
- }
3428
3323
  function resourceAt(source, tokens, tokenIndex) {
3429
3324
  const tokenStart = inlineTokenStart(tokens, tokenIndex);
3430
3325
  const tokenEnd = inlineTokenEnd(tokens, tokenIndex);
3431
3326
  let start = tokenStart + 2;
3432
3327
  let end = tokenEnd - 1;
3433
- while (start < end && isLinkWhitespace(source.charCodeAt(start))) start++;
3434
- while (end > start && isLinkWhitespace(source.charCodeAt(end - 1))) end--;
3328
+ while (start < end && isMarkdownWhitespace(source.charCodeAt(start))) start++;
3329
+ while (end > start && isMarkdownWhitespace(source.charCodeAt(end - 1))) end--;
3435
3330
  if (start === end) return {
3436
3331
  url: "",
3437
3332
  title: null
@@ -3444,7 +3339,7 @@ function resourceAt(source, tokens, tokenIndex) {
3444
3339
  destinationEnd--;
3445
3340
  }
3446
3341
  start = resourceEnd;
3447
- while (start < end && isLinkWhitespace(source.charCodeAt(start))) start++;
3342
+ while (start < end && isMarkdownWhitespace(source.charCodeAt(start))) start++;
3448
3343
  return {
3449
3344
  url: semanticText(source.slice(destinationStart, destinationEnd)),
3450
3345
  title: start < end ? semanticText(source.slice(start + 1, end - 1)) : null
@@ -3452,10 +3347,8 @@ function resourceAt(source, tokens, tokenIndex) {
3452
3347
  }
3453
3348
  function reference(close, syntaxStart, syntaxEnd, context, image) {
3454
3349
  const closeText = inlineTokenText(context.view.text, context.tokens, close);
3455
- const text = context.view.text.slice(syntaxStart, syntaxEnd);
3456
- const content = text.slice(image ? 2 : 1, text.length - closeText.length);
3457
3350
  const full = closeText.startsWith("][") && closeText !== "][]";
3458
- const labelSource = full ? closeText.slice(2, -1) : content;
3351
+ const labelSource = full ? closeText.slice(2, -1) : context.view.text.slice(syntaxStart + (image ? 2 : 1), syntaxEnd - closeText.length);
3459
3352
  return {
3460
3353
  identifier: normalizeAssociationLabel(labelSource),
3461
3354
  label: semanticText(labelSource),
@@ -3507,7 +3400,7 @@ const buildInlineReferenceImage = createBuildMedia("image", "reference");
3507
3400
  const buildInlineLink = createBuildMedia("link", "direct");
3508
3401
  const buildInlineReferenceLink = createBuildMedia("link", "reference");
3509
3402
  const feature$5 = { inline: {
3510
- scan: [
3403
+ scans: [
3511
3404
  {
3512
3405
  marker: 33,
3513
3406
  scan(source, start, tokens) {
@@ -3535,7 +3428,7 @@ const feature$5 = { inline: {
3535
3428
  }
3536
3429
  }
3537
3430
  ],
3538
- build: [
3431
+ builds: [
3539
3432
  {
3540
3433
  kind: "pair",
3541
3434
  token: 198,
@@ -3560,7 +3453,7 @@ const feature$5 = { inline: {
3560
3453
  kind: "leaf",
3561
3454
  token: 132,
3562
3455
  build(tokenIndex, sourceSpan, context) {
3563
- const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(1, -1);
3456
+ const label = inlineTokenText(context.view.text, context.tokens, tokenIndex, 1);
3564
3457
  return {
3565
3458
  type: "link",
3566
3459
  url: label.includes(":") ? label : `mailto:${label}`,
@@ -3609,95 +3502,68 @@ const feature$5 = { inline: {
3609
3502
  } };
3610
3503
  //#endregion
3611
3504
  //#region src/profile/features/list.ts
3612
- function listMarkerPadding(source, lines, index, markerEnd, markerColumn) {
3613
- const lineEnd = lines.end(index);
3614
- if (markerEnd === lineEnd) return {
3615
- offset: markerEnd,
3616
- columns: 1,
3617
- hasContent: false,
3618
- prefixColumns: 0
3619
- };
3620
- let offset = markerEnd;
3621
- let column = markerColumn;
3622
- while (offset < lineEnd) {
3623
- const code = source.charCodeAt(offset);
3624
- if (code === 32) column++;
3625
- else if (code === 9) column += 4 - column % 4;
3626
- else break;
3627
- offset++;
3628
- }
3629
- const hasContent = offset < lineEnd;
3630
- const whitespaceColumns = column - markerColumn;
3631
- if (hasContent && whitespaceColumns <= 4) return {
3632
- offset,
3633
- columns: whitespaceColumns,
3634
- hasContent: true,
3635
- prefixColumns: 0
3636
- };
3637
- const firstPaddingColumns = source.charCodeAt(markerEnd) === 9 ? 4 - markerColumn % 4 : 1;
3638
- return {
3639
- offset: markerEnd + 1,
3640
- columns: 1,
3641
- hasContent,
3642
- prefixColumns: firstPaddingColumns - 1
3643
- };
3644
- }
3645
3505
  function listMarkerAt(source, lines, index, contentOffset) {
3646
3506
  if (contentOffset < 0) return;
3647
3507
  const indent = lines.prefixColumns(index) + contentOffset - lines.start(index);
3648
3508
  const marker = source.charCodeAt(contentOffset);
3649
- const markerEnd = contentOffset + 1;
3650
3509
  const lineEnd = lines.end(index);
3510
+ let delimiter;
3511
+ let markerEnd = contentOffset + 1;
3512
+ let startNumber = 0;
3651
3513
  if (marker === 45 || marker === 43 || marker === 42) {
3652
3514
  const following = source.charCodeAt(markerEnd);
3653
3515
  if (markerEnd !== lineEnd && following !== 32 && following !== 9 || isThematicBreak(source, lines, index, contentOffset)) return;
3654
- const padding = listMarkerPadding(source, lines, index, markerEnd, indent + 1);
3655
- return {
3656
- kind: "unordered",
3657
- indent,
3658
- offset: contentOffset,
3659
- end: markerEnd,
3660
- hasContent: padding.hasContent,
3661
- contentOffset: padding.offset,
3662
- contentIndent: indent + 1 + padding.columns,
3663
- contentPrefixColumns: padding.prefixColumns,
3664
- delimiter: String.fromCharCode(marker)
3665
- };
3516
+ delimiter = marker;
3517
+ } else {
3518
+ if (marker < 48 || marker > 57) return;
3519
+ let orderedEnd = contentOffset;
3520
+ while (orderedEnd < lineEnd && orderedEnd - contentOffset < 9) {
3521
+ const digit = source.charCodeAt(orderedEnd) - 48;
3522
+ if (digit < 0 || digit > 9) break;
3523
+ startNumber = startNumber * 10 + digit;
3524
+ orderedEnd++;
3525
+ }
3526
+ delimiter = source.charCodeAt(orderedEnd);
3527
+ if (delimiter !== 46 && delimiter !== 41) return;
3528
+ if (orderedEnd + 1 < lineEnd) {
3529
+ const code = source.charCodeAt(orderedEnd + 1);
3530
+ if (code !== 32 && code !== 9) return;
3531
+ }
3532
+ markerEnd = orderedEnd + 1;
3533
+ }
3534
+ const markerColumn = indent + markerEnd - contentOffset;
3535
+ let contentIndent = markerColumn + 1;
3536
+ let contentStart = markerEnd;
3537
+ let hasContent = false;
3538
+ let prefixColumns = 0;
3539
+ if (markerEnd < lineEnd) {
3540
+ let column = markerColumn;
3541
+ while (contentStart < lineEnd) {
3542
+ const code = source.charCodeAt(contentStart);
3543
+ if (code === 32) column++;
3544
+ else if (code === 9) column += 4 - column % 4;
3545
+ else break;
3546
+ contentStart++;
3547
+ }
3548
+ hasContent = contentStart < lineEnd;
3549
+ if (hasContent && column - markerColumn <= 4) contentIndent = column;
3550
+ else {
3551
+ const firstPaddingColumns = source.charCodeAt(markerEnd) === 9 ? 4 - markerColumn % 4 : 1;
3552
+ contentStart = markerEnd + 1;
3553
+ prefixColumns = firstPaddingColumns - 1;
3554
+ }
3666
3555
  }
3667
- if (marker < 48 || marker > 57) return;
3668
- let startNumber = 0;
3669
- let orderedEnd = contentOffset;
3670
- while (orderedEnd < lineEnd && orderedEnd - contentOffset < 9) {
3671
- const digit = source.charCodeAt(orderedEnd) - 48;
3672
- if (digit < 0 || digit > 9) break;
3673
- startNumber = startNumber * 10 + digit;
3674
- orderedEnd++;
3675
- }
3676
- const delimiter = source[orderedEnd];
3677
- if (delimiter !== "." && delimiter !== ")") return;
3678
- if (orderedEnd + 1 < lineEnd) {
3679
- const code = source.charCodeAt(orderedEnd + 1);
3680
- if (code !== 32 && code !== 9) return;
3681
- }
3682
- orderedEnd++;
3683
- const markerWidth = orderedEnd - contentOffset;
3684
- const padding = listMarkerPadding(source, lines, index, orderedEnd, indent + markerWidth);
3685
3556
  return {
3686
- kind: "ordered",
3687
- indent,
3688
3557
  offset: contentOffset,
3689
- end: orderedEnd,
3690
- hasContent: padding.hasContent,
3691
- contentOffset: padding.offset,
3692
- contentIndent: indent + markerWidth + padding.columns,
3693
- contentPrefixColumns: padding.prefixColumns,
3558
+ end: markerEnd,
3559
+ hasContent,
3560
+ contentOffset: contentStart,
3561
+ contentIndent,
3562
+ contentPrefixColumns: prefixColumns,
3694
3563
  delimiter,
3695
3564
  startNumber
3696
3565
  };
3697
3566
  }
3698
- function sameList(a, b) {
3699
- return a.kind === b.kind && a.delimiter === b.delimiter;
3700
- }
3701
3567
  function isTaskListWhitespace(code) {
3702
3568
  return code === 32 || code >= 9 && code <= 13;
3703
3569
  }
@@ -3745,10 +3611,9 @@ const buildListItem = (tokenStart, context) => {
3745
3611
  function createBuildList(ordered) {
3746
3612
  return (tokenStart, context) => {
3747
3613
  const tokens = context.structure.tokens;
3748
- const start = context.locator.locationAt(tokens.start(tokenStart));
3749
3614
  const items = [];
3750
3615
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
3751
- for (let child = tokenStart + 1; child < close; child += tokens.nodeLength(child)) items.push(buildBlockNode(child, context));
3616
+ for (let child = tokenStart + 1; child < close; child += tokens.nodeLength(child)) items.push(buildListItem(child, context));
3752
3617
  return {
3753
3618
  type: "list",
3754
3619
  ordered,
@@ -3756,8 +3621,8 @@ function createBuildList(ordered) {
3756
3621
  spread: tokens.value(close) === true,
3757
3622
  children: items,
3758
3623
  position: {
3759
- start,
3760
- end: lastChildEnd(items) ?? context.locator.locationAt(tokens.end(tokenStart))
3624
+ start: firstChildStart(items),
3625
+ end: lastChildEnd(items)
3761
3626
  }
3762
3627
  };
3763
3628
  };
@@ -3765,22 +3630,21 @@ function createBuildList(ordered) {
3765
3630
  const listStart = (source, lines, start, contentOffset, out, context) => {
3766
3631
  let marker = listMarkerAt(source, lines, start, contentOffset);
3767
3632
  if (!marker) return;
3768
- const listMarker = marker;
3769
- const kind = listMarker.kind;
3770
- const listOpen = kind === "ordered" ? 70 : 69;
3771
- const listClose = kind === "ordered" ? 196 : 195;
3772
- out.push(listOpen, listMarker.offset, listMarker.end, kind === "ordered" ? { value: listMarker.startNumber } : void 0);
3633
+ const delimiter = marker.delimiter;
3634
+ const ordered = delimiter === 46 || delimiter === 41;
3635
+ const listOpen = ordered ? 66 : 65;
3636
+ const listClose = ordered ? 196 : 195;
3637
+ out.push(listOpen, marker.offset, marker.end, ordered ? { value: marker.startNumber } : void 0);
3773
3638
  let index = start;
3774
- let listEnd = listMarker.end;
3639
+ let listEnd = marker.end;
3775
3640
  let listSpread = false;
3776
3641
  let trailingBlank = false;
3777
- while (marker && sameList(marker, listMarker)) {
3642
+ while (marker?.delimiter === delimiter) {
3778
3643
  let sibling;
3779
3644
  listSpread ||= trailingBlank;
3780
3645
  trailingBlank = false;
3781
3646
  out.push(128, marker.offset, marker.end);
3782
- const itemLines = new BlockLines();
3783
- itemLines.pushFrom(lines, index, marker.contentOffset, marker.contentPrefixColumns);
3647
+ const itemLines = context.createLineView(lines, index, marker.contentOffset, marker.contentPrefixColumns);
3784
3648
  let hasContent = marker.hasContent;
3785
3649
  let paragraphLeaf = hasContent ? 2 : 0;
3786
3650
  index++;
@@ -3806,13 +3670,14 @@ const listStart = (source, lines, start, contentOffset, out, context) => {
3806
3670
  index++;
3807
3671
  continue;
3808
3672
  }
3809
- const candidate = listMarkerAt(source, lines, index, lineIndentOffset(source, lines, index));
3673
+ const contentOffset = lineIndentOffset(source, lines, index);
3674
+ const candidate = listMarkerAt(source, lines, index, contentOffset);
3810
3675
  if (candidate) {
3811
3676
  sibling = candidate;
3812
3677
  break;
3813
3678
  }
3814
3679
  if (paragraphLeaf === 2) paragraphLeaf = context.endsWithParagraphLeaf(source, itemLines, itemLines.length - 1) ? 1 : 0;
3815
- if (paragraphLeaf === 0 || context.startsInterruptingBlock(source, lines, index)) break;
3680
+ if (paragraphLeaf === 0 || context.startsInterruptingBlock(source, lines, index, contentOffset)) break;
3816
3681
  itemLines.pushLazy(lines, index);
3817
3682
  index++;
3818
3683
  }
@@ -3831,11 +3696,11 @@ const taskListStart = (source, lines, start, contentOffset, out, context) => {
3831
3696
  for (let item = listToken + 1; item < out.length - 1; item += out.nodeLength(item)) {
3832
3697
  let paragraph = item + 1;
3833
3698
  let contentKind = out.kind(paragraph);
3834
- while (contentKind === 71 || contentKind === 2 || contentKind === 198) {
3699
+ while (contentKind === 67 || contentKind === 2 || contentKind === 198) {
3835
3700
  paragraph++;
3836
3701
  contentKind = out.kind(paragraph);
3837
3702
  }
3838
- if (contentKind !== 68) continue;
3703
+ if (contentKind !== 99) continue;
3839
3704
  const firstChunk = paragraph + 1;
3840
3705
  const marker = taskListMarkerAt(source, out.start(firstChunk), out.end(firstChunk));
3841
3706
  if (!marker || !hasTaskListContent(source, out, firstChunk, marker.contentStart)) continue;
@@ -3846,36 +3711,13 @@ const taskListStart = (source, lines, start, contentOffset, out, context) => {
3846
3711
  };
3847
3712
  function feature$4(taskList = false) {
3848
3713
  return { block: {
3849
- rules: [
3850
- {
3851
- rule: 5,
3852
- syntax: {
3853
- kind: "frame",
3854
- token: [
3855
- 128,
3856
- 129,
3857
- 130
3858
- ]
3859
- },
3860
- build: buildListItem
3861
- },
3862
- {
3863
- rule: 6,
3864
- syntax: {
3865
- kind: "block",
3866
- token: 69
3867
- },
3868
- build: createBuildList(false)
3869
- },
3870
- {
3871
- rule: 7,
3872
- syntax: {
3873
- kind: "block",
3874
- token: 70
3875
- },
3876
- build: createBuildList(true)
3877
- }
3878
- ],
3714
+ builds: [{
3715
+ token: 65,
3716
+ build: createBuildList(false)
3717
+ }, {
3718
+ token: 66,
3719
+ build: createBuildList(true)
3720
+ }],
3879
3721
  starts: [{
3880
3722
  codes: [
3881
3723
  42,
@@ -3900,7 +3742,7 @@ function feature$4(taskList = false) {
3900
3742
  },
3901
3743
  interrupt(source, lines, index, contentOffset) {
3902
3744
  const marker = listMarkerAt(source, lines, index, contentOffset);
3903
- return marker?.hasContent === true && (marker.kind === "unordered" || marker.kind === "ordered" && marker.startNumber === 1);
3745
+ return marker?.hasContent === true && (marker.startNumber === 1 || marker.delimiter !== 46 && marker.delimiter !== 41);
3904
3746
  },
3905
3747
  start: taskList ? taskListStart : listStart
3906
3748
  }]
@@ -3913,16 +3755,11 @@ const mathFenceRule = {
3913
3755
  marker: 36,
3914
3756
  minimumLength: 2
3915
3757
  };
3916
- const blockRules = [{
3917
- rule: 14,
3918
- syntax: {
3919
- kind: "leaf",
3920
- token: 261
3921
- },
3758
+ const blockBuilds = [{
3759
+ token: 261,
3922
3760
  build(tokenStart, context) {
3923
3761
  const tokens = context.structure.tokens;
3924
3762
  const block = tokens.value(tokenStart);
3925
- if (!block) throw new Error("Math block lacks fence metadata");
3926
3763
  const value = block.content ?? tokens.text(context.source, tokenStart);
3927
3764
  return {
3928
3765
  type: "math",
@@ -3982,7 +3819,7 @@ const inlineBuilds = [{
3982
3819
  token: 134,
3983
3820
  build(tokenIndex, sourceSpan, context) {
3984
3821
  const markerLength = inlineTokenData(context.tokens, tokenIndex);
3985
- let value = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(markerLength, -markerLength);
3822
+ let value = inlineTokenText(context.view.text, context.tokens, tokenIndex, markerLength);
3986
3823
  const startPadding = value.startsWith("\r\n") ? 2 : /^[ \r\n]/.test(value) ? 1 : 0;
3987
3824
  const endPadding = value.endsWith("\r\n") ? 2 : /[ \r\n]$/.test(value) ? 1 : 0;
3988
3825
  if (startPadding > 0 && endPadding > 0 && /[^ \r\n]/.test(value)) value = value.slice(startPadding, -endPadding);
@@ -3999,12 +3836,12 @@ function feature$3(options) {
3999
3836
  const singleDollarTextMath = typeof options !== "object" || options.singleDollarTextMath !== false;
4000
3837
  return {
4001
3838
  block: {
4002
- rules: blockRules,
3839
+ builds: blockBuilds,
4003
3840
  starts: blockStarts
4004
3841
  },
4005
3842
  inline: {
4006
- scan: [createMathScanRule(singleDollarTextMath)],
4007
- build: inlineBuilds
3843
+ scans: [createMathScanRule(singleDollarTextMath)],
3844
+ builds: inlineBuilds
4008
3845
  }
4009
3846
  };
4010
3847
  }
@@ -4014,26 +3851,26 @@ const feature$2 = { block: {
4014
3851
  fallbacks: [(source, lines, start, contentOffset, out, context) => {
4015
3852
  const openToken = out.length;
4016
3853
  const offset = lines.start(start);
4017
- out.push(68, offset, offset);
3854
+ out.push(99, offset, offset);
4018
3855
  let chunkOffset = contentOffset;
4019
3856
  let index = start + 1;
4020
3857
  while (index < lines.length) {
4021
- const lineOffset = lines.lazy(index) ? -1 : lineIndentOffset(source, lines, index);
4022
- if (lineOffset < 0) {
4023
- if (isBlank(source, lines, index)) break;
4024
- } else {
4025
- const setext = setextMarkerAt(source, lines, index, lineOffset);
3858
+ const lineEnd = lines.end(index);
3859
+ const contentStart = skipLineWhitespace(source, lines.start(index), lineEnd);
3860
+ if (contentStart === lineEnd) break;
3861
+ const chunkStart = indentOffset(source, lines, index);
3862
+ if (!lines.lazy(index) && chunkStart === contentStart) {
3863
+ const setext = setextMarkerAt(source, lines, index, contentStart);
4026
3864
  if (setext) {
4027
- out.setKind(openToken, setext === "=" ? 66 : 67);
3865
+ out.setKind(openToken, setext === "=" ? 97 : 98);
4028
3866
  out.push(1, chunkOffset, lines.end(index - 1));
4029
- const lineEnd = lines.end(index);
4030
3867
  out.push(193, lineEnd, lineEnd);
4031
3868
  return index + 1;
4032
3869
  }
4033
- if (context.startsInterruptingBlock(source, lines, index, lineOffset)) break;
3870
+ if (context.startsInterruptingBlock(source, lines, index, contentStart)) break;
4034
3871
  }
4035
3872
  out.push(1, chunkOffset, lines.next(index - 1));
4036
- chunkOffset = lineOffset < 0 ? indentOffset(source, lines, index) : lineOffset;
3873
+ chunkOffset = chunkStart;
4037
3874
  index++;
4038
3875
  }
4039
3876
  const close = lines.end(index - 1);
@@ -4041,15 +3878,10 @@ const feature$2 = { block: {
4041
3878
  out.push(194, close, close);
4042
3879
  return index;
4043
3880
  }],
4044
- rules: [{
4045
- rule: 4,
4046
- syntax: {
4047
- kind: "block",
4048
- token: 68
4049
- },
4050
- inlineContent: true,
3881
+ builds: [{
3882
+ token: 99,
4051
3883
  build(tokenStart, context) {
4052
- const inline = buildInlineFragment(tokenStart, 4, context);
3884
+ const inline = buildInlineFragment(tokenStart, false, context);
4053
3885
  const result = {
4054
3886
  type: "paragraph",
4055
3887
  children: inline.children,
@@ -4065,11 +3897,6 @@ const feature$2 = { block: {
4065
3897
  } };
4066
3898
  //#endregion
4067
3899
  //#region src/profile/features/reference.ts
4068
- function linkDefinitionFields(tokens, token) {
4069
- const fields = tokens.value(token);
4070
- if (tokens.kind(token) !== 71 || !fields) throw new Error("Expected LinkDefinitionOpen token to contain parsed fields");
4071
- return fields;
4072
- }
4073
3900
  function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
4074
3901
  let offset = contentOffset + 1;
4075
3902
  const labelClose = source.indexOf("]", offset);
@@ -4106,7 +3933,7 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
4106
3933
  }
4107
3934
  const nextLine = lineIndex + 1;
4108
3935
  lookaheadEnd = nextLine < lines.length ? lines.end(nextLine) : lines.next(lineIndex);
4109
- if (nextLine >= lines.length || isBlank(source, lines, nextLine)) break parseDefinition;
3936
+ if (nextLine >= lines.length || isBlankLine(source, lines, nextLine)) break parseDefinition;
4110
3937
  if (++labelLength > 999) break parseDefinition;
4111
3938
  label += source.slice(labelStart, lines.next(lineIndex));
4112
3939
  lineIndex++;
@@ -4116,19 +3943,16 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
4116
3943
  label += source.slice(labelStart, offset);
4117
3944
  if (!labelHasContent) break parseDefinition;
4118
3945
  offset += 2;
4119
- const skipSpaces = (lineEnd) => {
4120
- while (offset < lineEnd && (source[offset] === " " || source[offset] === " ")) offset++;
4121
- };
4122
3946
  let lineEnd = lines.end(lineIndex);
4123
- skipSpaces(lineEnd);
3947
+ offset = skipLineWhitespace(source, offset, lineEnd);
4124
3948
  if (offset === lineEnd) {
4125
3949
  const nextLine = lineIndex + 1;
4126
3950
  lookaheadEnd = nextLine < lines.length ? lines.end(nextLine) : lines.next(lineIndex);
4127
- if (nextLine >= lines.length || isBlank(source, lines, nextLine)) break parseDefinition;
3951
+ if (nextLine >= lines.length || isBlankLine(source, lines, nextLine)) break parseDefinition;
4128
3952
  lineIndex++;
4129
3953
  offset = lines.start(lineIndex);
4130
3954
  lineEnd = lines.end(lineIndex);
4131
- skipSpaces(lineEnd);
3955
+ offset = skipLineWhitespace(source, offset, lineEnd);
4132
3956
  }
4133
3957
  let destination;
4134
3958
  if (source[offset] === "<") {
@@ -4162,14 +3986,14 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
4162
3986
  }
4163
3987
  const destinationLine = lineIndex;
4164
3988
  if (offset < lineEnd && source[offset] !== " " && source[offset] !== " ") break parseDefinition;
4165
- skipSpaces(lineEnd);
3989
+ offset = skipLineWhitespace(source, offset, lineEnd);
4166
3990
  let titleOnNextLine = false;
4167
3991
  if (offset === lineEnd && lineIndex + 1 < lines.length) {
4168
3992
  lookaheadEnd = lines.end(lineIndex + 1);
4169
3993
  lineIndex++;
4170
3994
  offset = lines.start(lineIndex);
4171
3995
  lineEnd = lines.end(lineIndex);
4172
- skipSpaces(lineEnd);
3996
+ offset = skipLineWhitespace(source, offset, lineEnd);
4173
3997
  titleOnNextLine = true;
4174
3998
  }
4175
3999
  const closer = source[offset] === "(" ? ")" : source[offset] === "\"" || source[offset] === "'" ? source[offset] : void 0;
@@ -4206,14 +4030,14 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
4206
4030
  if (closed) break;
4207
4031
  const nextLine = lineIndex + 1;
4208
4032
  lookaheadEnd = nextLine < lines.length ? lines.end(nextLine) : lines.next(lineIndex);
4209
- if (nextLine >= lines.length || isBlank(source, lines, nextLine)) break;
4033
+ if (nextLine >= lines.length || isBlankLine(source, lines, nextLine)) break;
4210
4034
  title += source.slice(titleStart, lines.next(lineIndex));
4211
4035
  lineIndex++;
4212
4036
  offset = lines.start(lineIndex);
4213
4037
  titleStart = offset;
4214
4038
  }
4215
4039
  if (closed) {
4216
- skipSpaces(lineEnd);
4040
+ offset = skipLineWhitespace(source, offset, lineEnd);
4217
4041
  if (offset === lineEnd) {
4218
4042
  fields.title = title;
4219
4043
  return {
@@ -4234,20 +4058,14 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
4234
4058
  if (lookaheadEnd >= 0) context.retainLookahead(lookaheadEnd);
4235
4059
  }
4236
4060
  const feature$1 = { block: {
4237
- rules: [{
4238
- rule: 11,
4239
- syntax: {
4240
- kind: "block",
4241
- token: 71
4242
- },
4061
+ builds: [{
4062
+ token: 67,
4243
4063
  build(tokenStart, context) {
4244
4064
  const tokens = context.structure.tokens;
4245
- const fields = linkDefinitionFields(tokens, tokenStart);
4246
- const definitionKey = tokens.definitionKey(tokenStart);
4247
- if (definitionKey === void 0) throw new Error("Expected LinkDefinitionOpen token to contain a definition key");
4065
+ const fields = tokens.value(tokenStart);
4248
4066
  return {
4249
4067
  type: "definition",
4250
- identifier: definitionKey,
4068
+ identifier: tokens.definitionKey(tokenStart),
4251
4069
  label: semanticText(fields.label),
4252
4070
  url: semanticText(fields.destination),
4253
4071
  title: fields.title === void 0 ? null : semanticText(fields.title),
@@ -4260,7 +4078,7 @@ const feature$1 = { block: {
4260
4078
  start(source, lines, start, contentOffset, out, context) {
4261
4079
  const definition = linkDefinitionAt(source, lines, start, contentOffset, context);
4262
4080
  if (!definition) return;
4263
- out.push(71, contentOffset, contentOffset, {
4081
+ out.push(67, contentOffset, contentOffset, {
4264
4082
  definitionKey: definition.definitionKey,
4265
4083
  value: definition.fields
4266
4084
  });
@@ -4277,11 +4095,7 @@ const feature$1 = { block: {
4277
4095
  //#endregion
4278
4096
  //#region src/profile/features/table.ts
4279
4097
  function appendTableCell(cells, source, start, contentStart, contentEnd) {
4280
- while (contentStart < contentEnd) {
4281
- const code = source.charCodeAt(contentStart);
4282
- if (code !== 32 && code !== 9) break;
4283
- contentStart++;
4284
- }
4098
+ contentStart = skipLineWhitespace(source, contentStart, contentEnd);
4285
4099
  while (contentEnd > contentStart) {
4286
4100
  const code = source.charCodeAt(contentEnd - 1);
4287
4101
  if (code !== 32 && code !== 9) break;
@@ -4356,7 +4170,7 @@ function emitTableRow(lines, index, cells, out) {
4356
4170
  out.push(131, cells[0], cells[0]);
4357
4171
  for (let cell = 0; cell < cells.length; cell += 3) {
4358
4172
  const start = cells[cell];
4359
- out.push(132, start, start);
4173
+ out.push(160, start, start);
4360
4174
  out.push(1, cells[cell + 1], cells[cell + 2], void 0, 192);
4361
4175
  }
4362
4176
  const lineEnd = lines.end(index);
@@ -4367,7 +4181,7 @@ const buildTableCell = (tokenStart, context) => {
4367
4181
  const start = context.locator.locationAt(tokens.start(tokenStart));
4368
4182
  return {
4369
4183
  type: "tableCell",
4370
- children: buildInlineFragment(tokenStart, 17, context).children,
4184
+ children: buildInlineFragment(tokenStart, true, context).children,
4371
4185
  position: {
4372
4186
  start,
4373
4187
  end: context.locator.locationAt(tokens.start(tokenStart + tokens.nodeLength(tokenStart)))
@@ -4379,7 +4193,7 @@ const buildTableRow = (tokenStart, context) => {
4379
4193
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
4380
4194
  const start = context.locator.locationAt(tokens.start(tokenStart));
4381
4195
  const children = [];
4382
- for (let cell = tokenStart + 1; cell < close; cell += tokens.nodeLength(cell)) children.push(buildBlockNode(cell, context));
4196
+ for (let cell = tokenStart + 1; cell < close; cell += tokens.nodeLength(cell)) children.push(buildTableCell(cell, context));
4383
4197
  return {
4384
4198
  type: "tableRow",
4385
4199
  children,
@@ -4409,7 +4223,7 @@ const feature = { block: {
4409
4223
  if (!delimiter) return;
4410
4224
  const header = tableCellsAt(source, lines, start, true, contentOffset);
4411
4225
  if (header?.length !== delimiter.length) return;
4412
- out.push(73, header[0], header[0]);
4226
+ out.push(69, header[0], header[0]);
4413
4227
  emitTableRow(lines, start, header, out);
4414
4228
  const delimiterEnd = lines.end(delimiterLine);
4415
4229
  for (let cell = 0; cell < delimiter.length; cell += 3) out.push(delimiter[cell + 1], delimiter[cell], delimiter[cell + 3] ?? delimiterEnd);
@@ -4426,62 +4240,27 @@ const feature = { block: {
4426
4240
  out.push(200, tableEnd, tableEnd);
4427
4241
  return end;
4428
4242
  }],
4429
- rules: [
4430
- {
4431
- rule: 17,
4432
- syntax: {
4433
- kind: "frame",
4434
- token: 132
4435
- },
4436
- inlineContent: true,
4437
- build: buildTableCell
4438
- },
4439
- {
4440
- rule: 16,
4441
- syntax: {
4442
- kind: "frame",
4443
- token: 131
4444
- },
4445
- build: buildTableRow
4446
- },
4447
- {
4448
- rule: 18,
4449
- syntax: {
4450
- kind: "group",
4451
- token: [
4452
- 320,
4453
- 321,
4454
- 322,
4455
- 323
4456
- ]
4457
- }
4458
- },
4459
- {
4460
- rule: 15,
4461
- syntax: {
4462
- kind: "block",
4463
- token: 73
4464
- },
4465
- build(tokenStart, context) {
4466
- const tokens = context.structure.tokens;
4467
- const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
4468
- const start = context.locator.locationAt(tokens.start(tokenStart));
4469
- const header = tokenStart + 1;
4470
- const delimiter = header + tokens.nodeLength(header);
4471
- const rows = [buildBlockNode(header, context)];
4472
- for (let row = delimiter + tokens.nodeLength(delimiter); row < close; row += tokens.nodeLength(row)) rows.push(buildBlockNode(row, context));
4473
- return {
4474
- type: "table",
4475
- align: tableAlignment(delimiter, context),
4476
- children: rows,
4477
- position: {
4478
- start,
4479
- end: context.locator.locationAt(tokens.start(close))
4480
- }
4481
- };
4482
- }
4243
+ builds: [{
4244
+ token: 69,
4245
+ build(tokenStart, context) {
4246
+ const tokens = context.structure.tokens;
4247
+ const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
4248
+ const start = context.locator.locationAt(tokens.start(tokenStart));
4249
+ const header = tokenStart + 1;
4250
+ const delimiter = header + tokens.nodeLength(header);
4251
+ const rows = [buildTableRow(header, context)];
4252
+ for (let row = delimiter + tokens.nodeLength(delimiter); row < close; row += tokens.nodeLength(row)) rows.push(buildTableRow(row, context));
4253
+ return {
4254
+ type: "table",
4255
+ align: tableAlignment(delimiter, context),
4256
+ children: rows,
4257
+ position: {
4258
+ start,
4259
+ end: context.locator.locationAt(tokens.start(close))
4260
+ }
4261
+ };
4483
4262
  }
4484
- ]
4263
+ }]
4485
4264
  } };
4486
4265
  //#endregion
4487
4266
  //#region src/inline/delimiter.ts
@@ -4523,19 +4302,13 @@ function unlinkRun(runs, runIndex) {
4523
4302
  if (run.previous >= 0) runs[run.previous].next = run.next;
4524
4303
  if (run.next >= 0) runs[run.next].previous = run.previous;
4525
4304
  }
4526
- function addReplacement(replacements, tokenIndex, replacement) {
4527
- const tokenReplacements = replacements[tokenIndex];
4528
- if (tokenReplacements) tokenReplacements.push(replacement);
4529
- else replacements[tokenIndex] = [replacement];
4530
- }
4531
- function matchDelimiterRuns(runs, first, replacements) {
4305
+ function resolveDelimiterScope(runs, first, replacements = []) {
4532
4306
  const openersBottom = [];
4533
4307
  let current = first;
4534
4308
  while (current >= 0) {
4535
4309
  const closer = runs[current];
4536
4310
  const next = closer.next;
4537
4311
  if (!(closer.state & 2)) {
4538
- if ((closer.state & 3) === 0) unlinkRun(runs, current);
4539
4312
  current = next;
4540
4313
  continue;
4541
4314
  }
@@ -4560,12 +4333,12 @@ function matchDelimiterRuns(runs, first, replacements) {
4560
4333
  const closeStart = closer.start;
4561
4334
  const closeEnd = closeStart + use;
4562
4335
  const pair = use === 2 ? closer.config.double : closer.config.single;
4563
- addReplacement(replacements, opener.tokenIndex, {
4336
+ (replacements[opener.tokenIndex] ??= []).push({
4564
4337
  offset: openStart,
4565
4338
  end: openEnd,
4566
4339
  kind: pair.open
4567
4340
  });
4568
- addReplacement(replacements, closer.tokenIndex, {
4341
+ (replacements[closer.tokenIndex] ??= []).push({
4569
4342
  offset: closeStart,
4570
4343
  end: closeEnd,
4571
4344
  kind: pair.close
@@ -4581,16 +4354,15 @@ function matchDelimiterRuns(runs, first, replacements) {
4581
4354
  current = next;
4582
4355
  }
4583
4356
  }
4357
+ return replacements;
4584
4358
  }
4585
- function delimiterRunAt(source, tokens, tokenIndex, configByKind) {
4586
- const config = configByKind[inlineTokenKind(tokens, tokenIndex)];
4587
- if (!config) return;
4359
+ function delimiterRunAt(source, tokens, tokenIndex, config) {
4588
4360
  const offset = inlineTokenStart(tokens, tokenIndex);
4589
4361
  const end = inlineTokenEnd(tokens, tokenIndex);
4590
4362
  const length = end - offset;
4591
4363
  if (config.bits & 2 && (length > 2 || (length === 1 ? !config.single : !config.double))) return;
4592
4364
  const delimiterFlanking = flanking(source, offset, end, config);
4593
- if (config.bits & 1 || delimiterFlanking !== 0) return {
4365
+ if (delimiterFlanking !== 0) return {
4594
4366
  tokenIndex,
4595
4367
  config,
4596
4368
  start: offset,
@@ -4600,11 +4372,6 @@ function delimiterRunAt(source, tokens, tokenIndex, configByKind) {
4600
4372
  state: delimiterFlanking | length % 3 << 2
4601
4373
  };
4602
4374
  }
4603
- function resolveDelimiterMatches(runs) {
4604
- const replacements = [];
4605
- for (let runIndex = runs.length - 1; runIndex >= 0; runIndex--) if (runs[runIndex].previous < 0) matchDelimiterRuns(runs, runIndex, replacements);
4606
- return replacements;
4607
- }
4608
4375
  function appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements) {
4609
4376
  const matched = replacements[tokenIndex];
4610
4377
  if (!matched) {
@@ -4636,41 +4403,27 @@ function compileDelimiterConfigs(delimiterConfigs) {
4636
4403
  //#endregion
4637
4404
  //#region src/profile/resolve.ts
4638
4405
  const frameHeaderSize = 1;
4639
- const noBracketFrames = Object.freeze([0]);
4640
- const delimiterOnlyFrames = Object.freeze([2]);
4406
+ const noBracketFrames = [0];
4641
4407
  const noDelimiterReplacements = [];
4642
- function frameClaim(frames, frame) {
4643
- return frames[frame + 5] & 7;
4644
- }
4645
4408
  function setFrameState(frames, frame, state) {
4646
4409
  frames[frame + 5] = state;
4647
- frames[0] |= 4;
4410
+ frames[0] = 1;
4648
4411
  }
4649
- function rewriteLinkCandidates(frames, candidates, start) {
4650
- let write = start;
4651
- for (let read = start; read < candidates.length; read++) {
4652
- const candidate = candidates[read];
4412
+ function rewriteLinkCandidates(frames, top, bottom) {
4413
+ let candidate = top;
4414
+ top = bottom;
4415
+ while (candidate !== bottom) {
4416
+ const next = frames[candidate + 3];
4653
4417
  const state = frames[candidate + 5];
4654
- if ((state & 7) === 3 && !(state & 8)) frames[candidate + 5] = 0;
4418
+ if (state === 3) frames[candidate + 5] = 0;
4655
4419
  else {
4656
4420
  frames[candidate + 5] = state | 16;
4657
- candidates[write++] = candidate;
4421
+ frames[candidate + 3] = top;
4422
+ top = candidate;
4658
4423
  }
4424
+ candidate = next;
4659
4425
  }
4660
- candidates.length = write;
4661
- }
4662
- function allocateFrame(frames, openToken, parent, candidateStart) {
4663
- const frame = frames.length;
4664
- frames.push(openToken, -1, candidateStart, -1, parent, 0, 0);
4665
- return frame;
4666
- }
4667
- function isImageFrame(tokens, frames, frame) {
4668
- return inlineTokenKind(tokens, frames[frame + 0]) === 71;
4669
- }
4670
- function hasAdjacentComponent(tokens, frames, frame) {
4671
- const openToken = frames[frame + 0];
4672
- const componentToken = openToken - 1;
4673
- return componentToken >= 0 && inlineTokenKind(tokens, componentToken) === 137 && inlineTokenEnd(tokens, componentToken) === inlineTokenStart(tokens, openToken);
4426
+ return top;
4674
4427
  }
4675
4428
  function referenceLabelEnd(source, start) {
4676
4429
  if (source.charCodeAt(start) !== 91) return -1;
@@ -4687,7 +4440,7 @@ function referenceLabelEnd(source, start) {
4687
4440
  hasContent = true;
4688
4441
  offset += 2;
4689
4442
  } else {
4690
- hasContent ||= code !== 9 && code !== 10 && code !== 13 && code !== 32;
4443
+ hasContent ||= !isMarkdownWhitespace(code);
4691
4444
  offset++;
4692
4445
  }
4693
4446
  characters++;
@@ -4699,7 +4452,7 @@ function acceptsShortcutLabel(source, start, end) {
4699
4452
  let characters = 0;
4700
4453
  for (let offset = start; offset < end; offset++) {
4701
4454
  const code = source.charCodeAt(offset);
4702
- hasContent ||= code !== 9 && code !== 10 && code !== 13 && code !== 32;
4455
+ hasContent ||= !isMarkdownWhitespace(code);
4703
4456
  if (code >= 55296 && code <= 56319 && offset + 1 < end) {
4704
4457
  const trailing = source.charCodeAt(offset + 1);
4705
4458
  if (trailing >= 56320 && trailing <= 57343) offset++;
@@ -4708,60 +4461,60 @@ function acceptsShortcutLabel(source, start, end) {
4708
4461
  }
4709
4462
  return hasContent;
4710
4463
  }
4711
- function analyzeBrackets(source, tokens, delimiterByKind, definitions, options) {
4712
- let hasDelimiter = false;
4464
+ function analyzeBrackets(source, tokens, definitions, options) {
4713
4465
  let frames;
4714
- let candidates;
4466
+ let candidateTop = -1;
4715
4467
  let stackTop = -1;
4716
4468
  const count = inlineTokenCount(tokens);
4717
4469
  for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
4718
4470
  const kind = inlineTokenKind(tokens, tokenIndex);
4719
- if (delimiterByKind[kind]) hasDelimiter = true;
4720
- if (kind === 72 || kind === 71) {
4721
- frames ??= [1];
4722
- stackTop = allocateFrame(frames, tokenIndex, stackTop, candidates?.length ?? 0);
4471
+ if (kind >= 71 && kind <= 72) {
4472
+ const arena = frames ??= [0];
4473
+ const frame = arena.length;
4474
+ arena.push(tokenIndex, -1, candidateTop, -1, stackTop, kind === 71 ? 8 : 0);
4475
+ stackTop = frame;
4723
4476
  continue;
4724
4477
  }
4725
- if (kind !== 74 && kind !== 73) continue;
4478
+ if (kind < 73 || kind > 74) continue;
4726
4479
  if (stackTop < 0) continue;
4727
4480
  const frame = stackTop;
4728
4481
  const arena = frames;
4729
4482
  stackTop = arena[frame + 4];
4730
4483
  arena[frame + 1] = tokenIndex;
4731
- const image = isImageFrame(tokens, arena, frame);
4484
+ const image = (arena[frame + 5] & 8) !== 0;
4732
4485
  if (options.footnote && kind === 74) {
4733
4486
  const openToken = arena[frame + 0];
4734
4487
  const label = footnoteLabelAt(source, inlineTokenStart(tokens, openToken) + (image ? 1 : 0), source.length);
4735
4488
  if (label && label.end === inlineTokenEnd(tokens, tokenIndex) && definitions.hasDefinition(label.definitionKey)) {
4736
4489
  setFrameState(arena, frame, 1);
4737
- if (candidates) candidates.length = arena[frame + 2];
4490
+ candidateTop = arena[frame + 2];
4738
4491
  continue;
4739
4492
  }
4740
4493
  }
4741
4494
  if (!options.component || image) continue;
4742
- if (kind === 73) {
4743
- if (candidates) rewriteLinkCandidates(arena, candidates, arena[frame + 2]);
4744
- }
4745
- if (hasAdjacentComponent(tokens, arena, frame)) {
4495
+ if (kind === 73) candidateTop = rewriteLinkCandidates(arena, candidateTop, arena[frame + 2]);
4496
+ const openToken = arena[frame + 0];
4497
+ const componentToken = openToken - 1;
4498
+ if (componentToken >= 0 && inlineTokenKind(tokens, componentToken) === 137 && inlineTokenEnd(tokens, componentToken) === inlineTokenStart(tokens, openToken)) {
4746
4499
  setFrameState(arena, frame, 2);
4747
- (candidates ??= []).push(frame);
4500
+ arena[frame + 3] = candidateTop;
4501
+ candidateTop = frame;
4748
4502
  continue;
4749
4503
  }
4750
- const close = inlineTokenStart(tokens, tokenIndex);
4751
- const trailing = source.charCodeAt(close + 1);
4504
+ const suffixStart = inlineTokenStart(tokens, tokenIndex) + 1;
4505
+ const trailing = source.charCodeAt(suffixStart);
4752
4506
  if (trailing === 40 || trailing === 91) continue;
4753
- const attributesStart = close + 1;
4754
- setFrameState(arena, frame, 3 | (source.charCodeAt(attributesStart) === 123 && attributesEnd(source, attributesStart) !== void 0 ? 8 : 0));
4755
- (candidates ??= []).push(frame);
4507
+ setFrameState(arena, frame, trailing === 123 && attributesEnd(source, suffixStart) !== void 0 ? 4 : 3);
4508
+ arena[frame + 3] = candidateTop;
4509
+ candidateTop = frame;
4756
4510
  }
4757
- if (frames) {
4758
- frames[0] |= hasDelimiter ? 2 : 0;
4759
- return frames;
4760
- }
4761
- return hasDelimiter ? delimiterOnlyFrames : noBracketFrames;
4511
+ return frames ?? noBracketFrames;
4762
4512
  }
4763
- function resolveReferences(source, tokens, frames, definitions) {
4764
- const hasDefinitions = definitions.hasDefinitions();
4513
+ function resolvePairedSyntax(source, tokens, frames, definitions, delimiterByKind) {
4514
+ const hasDefinitions = frames.length > frameHeaderSize && definitions.hasDefinitions();
4515
+ let runs;
4516
+ let runCount = 0;
4517
+ let replacements;
4765
4518
  let rawTop = -1;
4766
4519
  let logicalTop = -1;
4767
4520
  let frameCursor = frameHeaderSize;
@@ -4779,48 +4532,69 @@ function resolveReferences(source, tokens, frames, definitions) {
4779
4532
  consumeFrames = false;
4780
4533
  }
4781
4534
  const consuming = consumedEnd >= 0;
4782
- if (kind === 72 || kind === 71) {
4535
+ const delimiter = delimiterByKind[kind];
4536
+ if (!consuming && delimiter) {
4537
+ const run = delimiterRunAt(source, tokens, tokenIndex, delimiter);
4538
+ if (run) {
4539
+ const arena = runs ??= [];
4540
+ const runIndex = runCount++;
4541
+ if (runIndex > 0) {
4542
+ run.previous = runIndex - 1;
4543
+ arena[runIndex - 1].next = runIndex;
4544
+ }
4545
+ arena[runIndex] = run;
4546
+ }
4547
+ }
4548
+ if (kind >= 71 && kind <= 72) {
4783
4549
  const frame = frameCursor;
4784
- frameCursor += 7;
4550
+ frameCursor += 6;
4785
4551
  rawTop = frame;
4786
4552
  if (consuming) {
4787
- if (consumeFrames) setFrameState(frames, frame, 6);
4553
+ if (consumeFrames) setFrameState(frames, frame, 7);
4788
4554
  continue;
4789
4555
  }
4790
- const claim = frameClaim(frames, frame);
4556
+ frames[frame + 2] = runCount;
4557
+ const state = frames[frame + 5];
4558
+ const claim = state & 7;
4791
4559
  if (claim === 1) {
4792
4560
  const closeToken = frames[frame + 1];
4793
4561
  consumedEnd = inlineTokenEnd(tokens, closeToken);
4794
4562
  continue;
4795
4563
  }
4796
- if (claim === 2 || claim === 3) {
4797
- if (frames[frame + 5] & 16) literalDepth++;
4564
+ if (claim >= 2 && claim <= 4) {
4565
+ if (state & 16) literalDepth++;
4566
+ continue;
4567
+ }
4568
+ if (literalDepth > 0 && !(kind === 71)) {
4569
+ frames[frame + 5] = state | 32;
4798
4570
  continue;
4799
4571
  }
4800
- if (literalDepth > 0 && !(kind === 71)) continue;
4801
4572
  frames[frame + 3] = logicalTop;
4802
4573
  logicalTop = frame;
4803
4574
  lastVisibleOpener = tokenIndex;
4804
4575
  continue;
4805
4576
  }
4806
- if (kind !== 74 && kind !== 73) continue;
4577
+ if (kind < 73 || kind > 74) continue;
4807
4578
  const rawFrame = rawTop;
4808
4579
  if (rawFrame >= 0) rawTop = frames[rawFrame + 4];
4809
4580
  if (consuming) {
4810
- if (consumeFrames && rawFrame >= 0) setFrameState(frames, rawFrame, 6);
4581
+ if (consumeFrames && rawFrame >= 0) setFrameState(frames, rawFrame, 7);
4811
4582
  continue;
4812
4583
  }
4813
- const rawClaim = rawFrame < 0 ? 0 : frameClaim(frames, rawFrame);
4814
- if (!(rawClaim === 1 || rawClaim === 2 || rawClaim === 3) && (literalDepth <= 0 || rawFrame < 0 || isImageFrame(tokens, frames, rawFrame))) {
4584
+ const rawState = rawFrame < 0 ? 0 : frames[rawFrame + 5];
4585
+ const rawClaim = rawState & 7;
4586
+ let runStart = rawClaim >= 1 && rawClaim <= 4 ? frames[rawFrame + 2] : -1;
4587
+ if (runStart < 0 && (literalDepth <= 0 || rawFrame < 0 || (rawState & 8) !== 0)) {
4815
4588
  const frame = logicalTop;
4816
4589
  if (frame >= 0) logicalTop = frames[frame + 3];
4817
4590
  if (frame >= 0 && (kind === 73 || hasDefinitions)) {
4818
4591
  const openToken = frames[frame + 0];
4819
- const image = isImageFrame(tokens, frames, frame);
4592
+ const image = (frames[frame + 5] & 8) !== 0;
4820
4593
  if (image || openToken + 1 >= inactiveBefore) {
4821
4594
  const contentStart = inlineTokenEnd(tokens, openToken);
4822
4595
  const contentEnd = tokenStart;
4823
- let closeEnd = inlineTokenEnd(tokens, tokenIndex);
4596
+ const tokenEnd = inlineTokenEnd(tokens, tokenIndex);
4597
+ let closeEnd = tokenEnd;
4824
4598
  let reference = false;
4825
4599
  let matched = kind === 73;
4826
4600
  if (!matched) {
@@ -4838,11 +4612,12 @@ function resolveReferences(source, tokens, frames, definitions) {
4838
4612
  }
4839
4613
  }
4840
4614
  if (matched) {
4841
- setFrameState(frames, frame, reference ? 5 : 4);
4615
+ setFrameState(frames, frame, (reference ? 6 : 5) | (image ? 8 : 0));
4842
4616
  frames[frame + 1] = tokenIndex;
4843
- frames[frame + 6] = closeEnd;
4844
- if (!image) inactiveBefore = Math.max(inactiveBefore, openToken + 1);
4845
- if (closeEnd > inlineTokenEnd(tokens, tokenIndex)) {
4617
+ runStart = frames[frame + 2];
4618
+ frames[frame + 2] = closeEnd;
4619
+ if (!image) inactiveBefore = openToken + 1;
4620
+ if (closeEnd > tokenEnd) {
4846
4621
  consumedEnd = closeEnd;
4847
4622
  consumeFrames = true;
4848
4623
  }
@@ -4850,84 +4625,45 @@ function resolveReferences(source, tokens, frames, definitions) {
4850
4625
  }
4851
4626
  }
4852
4627
  }
4853
- if (rawFrame >= 0 && frames[rawFrame + 5] & 16) literalDepth--;
4854
- }
4855
- }
4856
- function assignDelimiterScopes(source, tokens, frames, delimiterByKind) {
4857
- const workspace = frames;
4858
- let runs;
4859
- let activeTop = -1;
4860
- let rootLastRun = -1;
4861
- let frameCursor = frameHeaderSize;
4862
- let skipEnd = -1;
4863
- const count = inlineTokenCount(tokens);
4864
- for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
4865
- while (activeTop >= 0 && frames[activeTop + 1] === tokenIndex) {
4866
- const frame = activeTop;
4867
- activeTop = frames[frame + 2];
4868
- const resolvedEnd = frames[frame + 6];
4869
- if (resolvedEnd > inlineTokenEnd(tokens, tokenIndex)) skipEnd = resolvedEnd;
4870
- }
4871
- const kind = inlineTokenKind(tokens, tokenIndex);
4872
- const tokenStart = inlineTokenStart(tokens, tokenIndex);
4873
- if (skipEnd >= 0 && tokenStart >= skipEnd) skipEnd = -1;
4874
- if (kind === 72 || kind === 71) {
4875
- const frame = frameCursor;
4876
- frameCursor += 7;
4877
- const claim = frameClaim(frames, frame);
4878
- if (claim === 1) {
4879
- skipEnd = inlineTokenEnd(tokens, frames[frame + 1]);
4880
- continue;
4881
- }
4882
- if (claim === 3 || claim === 4 || claim === 5 || claim === 2 && inlineTokenEnd(tokens, frames[frame + 0]) < inlineTokenStart(tokens, frames[frame + 1])) {
4883
- workspace[frame + 2] = activeTop;
4884
- activeTop = frame;
4885
- workspace[frame + 3] = -1;
4886
- }
4887
- }
4888
- if (skipEnd < 0) {
4889
- const run = delimiterRunAt(source, tokens, tokenIndex, delimiterByKind);
4890
- if (run) {
4891
- const runIndex = runs?.length ?? 0;
4892
- const previous = activeTop < 0 ? rootLastRun : frames[activeTop + 3];
4893
- if (previous >= 0) {
4894
- run.previous = previous;
4895
- runs[previous].next = runIndex;
4896
- }
4897
- if (activeTop < 0) rootLastRun = runIndex;
4898
- else workspace[activeTop + 3] = runIndex;
4899
- (runs ??= []).push(run);
4628
+ if (rawState & 16) literalDepth--;
4629
+ if (runStart >= 0 && runCount > runStart) {
4630
+ if (runStart > 0) {
4631
+ runs[runStart].previous = -1;
4632
+ runs[runStart - 1].next = -1;
4900
4633
  }
4634
+ replacements = resolveDelimiterScope(runs, runStart, replacements);
4635
+ runCount = runStart;
4901
4636
  }
4902
4637
  }
4903
- return runs;
4638
+ if (runCount > 0) replacements = resolveDelimiterScope(runs, 0, replacements);
4639
+ return replacements;
4904
4640
  }
4905
4641
  function appendReferenceBoundary(result, tokens, frames, frame, close) {
4906
4642
  const token = frames[frame + (close ? 1 : 0)];
4907
- const kind = (frameClaim(frames, frame) === 5 ? 202 : 198) + (isImageFrame(tokens, frames, frame) ? 2 : 0) + (close ? 1 : 0);
4908
- const end = close ? frames[frame + 6] : inlineTokenEnd(tokens, token);
4643
+ const state = frames[frame + 5];
4644
+ const kind = ((state & 7) === 6 ? 202 : 198) + (state & 8 ? 2 : 0) + (close ? 1 : 0);
4645
+ const end = close ? frames[frame + 2] : inlineTokenEnd(tokens, token);
4909
4646
  appendInlineToken(result, kind, inlineTokenStart(tokens, token), end, inlineTokenData(tokens, token));
4910
4647
  return end;
4911
4648
  }
4912
4649
  function emitResolvedTokens(tokens, frames, replacements) {
4913
- const workspace = frames;
4914
4650
  const result = [];
4915
4651
  let rawTop = -1;
4916
4652
  let referenceTop = -1;
4917
4653
  let frameCursor = frameHeaderSize;
4918
4654
  let skipEnd = -1;
4919
- let literalDepth = 0;
4920
4655
  const count = inlineTokenCount(tokens);
4921
4656
  for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
4922
4657
  const kind = inlineTokenKind(tokens, tokenIndex);
4923
4658
  const tokenStart = inlineTokenStart(tokens, tokenIndex);
4924
4659
  if (skipEnd >= 0 && tokenStart >= skipEnd) skipEnd = -1;
4925
4660
  const skipping = skipEnd >= 0;
4926
- if (kind === 72 || kind === 71) {
4661
+ if (kind >= 71 && kind <= 72) {
4927
4662
  const frame = frameCursor;
4928
- frameCursor += 7;
4663
+ frameCursor += 6;
4929
4664
  rawTop = frame;
4930
- const claim = frameClaim(frames, frame);
4665
+ const state = frames[frame + 5];
4666
+ const claim = state & 7;
4931
4667
  if (!skipping) {
4932
4668
  if (claim === 1) {
4933
4669
  const closeToken = frames[frame + 1];
@@ -4936,19 +4672,19 @@ function emitResolvedTokens(tokens, frames, replacements) {
4936
4672
  appendInlineToken(result, 133, start, skipEnd);
4937
4673
  } else if (claim === 2) {
4938
4674
  const closeToken = frames[frame + 1];
4939
- if (inlineTokenEnd(tokens, tokenIndex) < inlineTokenStart(tokens, closeToken)) rewriteInlineTokenTail(result, 208, inlineTokenEnd(tokens, tokenIndex));
4940
- } else if (claim === 3) appendInlineToken(result, 206, inlineTokenStart(tokens, tokenIndex), inlineTokenEnd(tokens, tokenIndex));
4941
- else if (claim === 4 || claim === 5) {
4675
+ const openEnd = inlineTokenEnd(tokens, tokenIndex);
4676
+ if (openEnd < inlineTokenStart(tokens, closeToken)) rewriteInlineTokenTail(result, 208, openEnd);
4677
+ } else if (claim >= 3 && claim <= 4) appendInlineToken(result, 206, inlineTokenStart(tokens, tokenIndex), inlineTokenEnd(tokens, tokenIndex));
4678
+ else if (claim === 5 || claim === 6) {
4942
4679
  appendReferenceBoundary(result, tokens, frames, frame, false);
4943
- workspace[frame + 3] = referenceTop;
4680
+ frames[frame + 3] = referenceTop;
4944
4681
  referenceTop = frame;
4945
- } else if (claim === 6) skipEnd = inlineTokenEnd(tokens, frames[frame + 1]);
4946
- else if (!(literalDepth > 0 && kind !== 71)) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
4682
+ } else if (claim === 7) skipEnd = inlineTokenEnd(tokens, frames[frame + 1]);
4683
+ else if (!(state & 32)) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
4947
4684
  }
4948
- if (frames[frame + 5] & 16) literalDepth++;
4949
4685
  continue;
4950
4686
  }
4951
- if (kind === 74 || kind === 73) {
4687
+ if (kind >= 73 && kind <= 74) {
4952
4688
  const rawFrame = rawTop;
4953
4689
  if (rawFrame >= 0) rawTop = frames[rawFrame + 4];
4954
4690
  const referenceFrame = referenceTop;
@@ -4958,20 +4694,15 @@ function emitResolvedTokens(tokens, frames, replacements) {
4958
4694
  referenceTop = frames[referenceFrame + 3];
4959
4695
  skipEnd = appendReferenceBoundary(result, tokens, frames, referenceFrame, true);
4960
4696
  } else if (rawFrame >= 0) {
4961
- const claim = frameClaim(frames, rawFrame);
4697
+ const state = frames[rawFrame + 5];
4698
+ const claim = state & 7;
4962
4699
  if (claim === 2) {
4963
4700
  const openToken = frames[rawFrame + 0];
4964
4701
  if (inlineTokenEnd(tokens, openToken) < tokenStart) appendInlineToken(result, 209, tokenStart, tokenStart + 1);
4965
- } else if (claim === 3) appendInlineToken(result, 207, tokenStart, tokenStart + 1);
4966
- else if (claim === 0 || claim === 4 || claim === 5) {
4967
- const image = isImageFrame(tokens, frames, rawFrame);
4968
- if (literalDepth === 0 || image) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
4969
- } else if (claim === 6) {
4970
- if (literalDepth === 0 || isImageFrame(tokens, frames, rawFrame)) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
4971
- }
4702
+ } else if (claim >= 3 && claim <= 4) appendInlineToken(result, 207, tokenStart, tokenStart + 1);
4703
+ else if (claim !== 1 && !(state & 32)) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
4972
4704
  } else appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
4973
4705
  }
4974
- if (rawFrame >= 0 && frames[rawFrame + 5] & 16) literalDepth--;
4975
4706
  continue;
4976
4707
  }
4977
4708
  if (!skipping) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
@@ -4982,15 +4713,15 @@ function compileInlineResolver(options) {
4982
4713
  return (delimiterConfigs) => {
4983
4714
  const delimiterByKind = compileDelimiterConfigs(delimiterConfigs);
4984
4715
  return (source, tokens, definitions) => {
4985
- const frames = analyzeBrackets(source, tokens, delimiterByKind, definitions, options);
4986
- const flags = frames[0];
4987
- if (flags & 1) resolveReferences(source, tokens, frames, definitions);
4988
- let replacements = noDelimiterReplacements;
4989
- if (flags & 2) {
4990
- const runs = assignDelimiterScopes(source, tokens, frames, delimiterByKind);
4991
- if (runs) replacements = resolveDelimiterMatches(runs);
4716
+ let tokenIndex = inlineTokenCount(tokens) - 1;
4717
+ for (; tokenIndex >= 0; tokenIndex--) {
4718
+ const kind = inlineTokenKind(tokens, tokenIndex);
4719
+ if (kind >= 68 && kind <= 74) break;
4992
4720
  }
4993
- return frames[0] & 4 || replacements.length > 0 ? emitResolvedTokens(tokens, frames, replacements) : tokens;
4721
+ if (tokenIndex < 0) return tokens;
4722
+ const frames = analyzeBrackets(source, tokens, definitions, options);
4723
+ const replacements = resolvePairedSyntax(source, tokens, frames, definitions, delimiterByKind) ?? noDelimiterReplacements;
4724
+ return frames[0] & 1 || replacements.length > 0 ? emitResolvedTokens(tokens, frames, replacements) : tokens;
4994
4725
  };
4995
4726
  };
4996
4727
  }
@@ -5002,18 +4733,18 @@ function compileProfile(options = {}) {
5002
4733
  feature$15,
5003
4734
  feature$16,
5004
4735
  feature$4(options.taskList),
5005
- feature$13,
4736
+ feature$14,
5006
4737
  feature$6
5007
4738
  ];
5008
- if (options.footnote) features.push(feature$9);
5009
- if (options.frontmatter) features.unshift(feature$12(typeof options.frontmatter === "object" ? options.frontmatter.marker : "-"));
4739
+ if (options.footnote) features.push(feature$10);
4740
+ if (options.frontmatter) features.unshift(feature$13(typeof options.frontmatter === "object" ? options.frontmatter.marker : "-"));
5010
4741
  if (options.table) features.push(feature);
5011
4742
  if (options.math) features.push(feature$3(options.math));
5012
- features.push(feature$2, feature$14, feature$8(options.strikethrough), feature$5);
4743
+ features.push(feature$2, feature$9, feature$8(options.strikethrough), feature$5);
5013
4744
  if (options.attributes) features.push(feature$18);
5014
4745
  if (options.binding) features.push(feature$17);
5015
- if (options.emoji) features.push(feature$10);
5016
- if (options.component) features.push(feature$11);
4746
+ if (options.emoji) features.push(feature$11);
4747
+ if (options.component) features.push(feature$12);
5017
4748
  features.push(feature$1);
5018
4749
  const blockFeatures = [];
5019
4750
  const inlineFeatures = [];