satorigear 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import { decodeString } from "micromark-util-decode-string";
2
2
  import { htmlBlockNames, htmlRawNames } from "micromark-util-html-tag-name";
3
- //#region src/block/lines.ts
3
+ // 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;
@@ -12,14 +12,23 @@ var BlockLines = class BlockLines {
12
12
  this.#sourceLength = sourceLength;
13
13
  this.#fields = new Int32Array(lineCapacity * 4);
14
14
  }
15
- static from(source, start = 0, limit = source.length) {
15
+ static from(source, start, limit) {
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,
@@ -123,8 +132,8 @@ var BlockLines = class BlockLines {
123
132
  physicallyContiguous() {
124
133
  return this.#sourceLength > 0;
125
134
  }
126
- push(start, end, next, prefixColumns = 0, lazy = false) {
127
- const field = this.#fieldLength;
135
+ push(start, end, next, prefixColumns, lazy) {
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,23 +338,10 @@ 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
- //#endregion
343
- //#region src/primitives.ts
341
+ // src/primitives.ts
344
342
  const emptyArray = [];
345
343
  const emptySet = new Set();
346
- //#endregion
347
- //#region src/block/tokens.ts
344
+ // src/block/tokens.ts
348
345
  function copyMetadata(target, source, start, end, targetStart) {
349
346
  end = Math.min(end, source.length);
350
347
  for (let read = start, write = targetStart; read < end; read++, write++) {
@@ -355,17 +352,14 @@ function copyMetadata(target, source, start, end, targetStart) {
355
352
  var BlockTokenStream = class {
356
353
  #definitionCounts;
357
354
  #definitionMembershipChanges;
358
- #fieldLength;
359
- #fields;
355
+ #fieldLength = 0;
356
+ #fields = new Int32Array();
360
357
  #groupField = -1;
361
358
  #metadata;
362
359
  #opens = [];
363
- #relativeStart;
360
+ #relativeStart = Infinity;
364
361
  #sourceLength;
365
362
  constructor(sourceLength = 0) {
366
- this.#fieldLength = 0;
367
- this.#fields = new Int32Array();
368
- this.#relativeStart = Number.POSITIVE_INFINITY;
369
363
  this.#sourceLength = sourceLength;
370
364
  }
371
365
  reset(sourceLength) {
@@ -375,7 +369,7 @@ var BlockTokenStream = class {
375
369
  this.#groupField = -1;
376
370
  this.#metadata = void 0;
377
371
  this.#opens.length = 0;
378
- this.#relativeStart = Number.POSITIVE_INFINITY;
372
+ this.#relativeStart = Infinity;
379
373
  this.#sourceLength = sourceLength;
380
374
  }
381
375
  get length() {
@@ -391,42 +385,39 @@ var BlockTokenStream = class {
391
385
  return !!this.#definitionCounts?.size;
392
386
  }
393
387
  push(kind, start, end, meta, role) {
388
+ const encodedRole = role ?? kind;
394
389
  const field = this.#fieldLength;
395
390
  this.#ensureCapacity(field + 4);
396
391
  this.#fields[field + 0] = kind;
397
392
  this.#fields[field + 1] = start;
398
393
  this.#fields[field + 2] = end;
399
- this.#fields[field + 3] = 0;
394
+ this.#fields[field + 3] = encodedRole < 64 ? 0 : this.#indexToken(field, encodedRole);
400
395
  this.#fieldLength += 4;
401
396
  if (meta) {
402
397
  this.#metadata ??= [];
403
- this.#metadata[this.length - 1] = meta;
398
+ this.#metadata[field / 4] = meta;
404
399
  const definitionKey = meta.definitionKey;
405
400
  if (definitionKey !== void 0) this.#updateDefinitionCount(definitionKey, 1, false);
406
401
  }
407
- const encodedRole = role ?? kind;
408
- if (encodedRole >= 64) this.#indexToken(field, encodedRole);
409
402
  }
410
403
  #indexToken(field, encodedRole) {
411
404
  if (encodedRole < 192) {
412
405
  this.#opens.push(field);
413
- return;
406
+ return 0;
414
407
  }
415
408
  if (encodedRole < 256) {
416
409
  const open = this.#opens.pop();
417
410
  this.#fields[open + 3] = (field - open) / 4 + 1;
418
- return;
419
- }
420
- if (encodedRole < 320) {
421
- this.#fields[field + 3] = 1;
422
- return;
411
+ return 0;
423
412
  }
424
- const group = this.#groupField;
413
+ if (encodedRole < 320) return 1;
425
414
  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]++;
415
+ if (this.#groupField >= 0 && this.#fields[previous + 0] >= 320) {
416
+ this.#fields[this.#groupField + 3]++;
417
+ return 0;
418
+ }
419
+ this.#groupField = field;
420
+ return 1;
430
421
  }
431
422
  nodeLength(index) {
432
423
  return this.#fields[index * 4 + 3];
@@ -524,7 +515,7 @@ var BlockTokenStream = class {
524
515
  this.#metadata = metadata.length > 0 ? metadata : void 0;
525
516
  }
526
517
  const newSuffixStart = start + replacementLength;
527
- this.#relativeStart = newSuffixStart < this.length ? newSuffixStart : Number.POSITIVE_INFINITY;
518
+ this.#relativeStart = newSuffixStart < this.length ? newSuffixStart : Infinity;
528
519
  this.#sourceLength = replacement.#sourceLength;
529
520
  return change;
530
521
  }
@@ -556,9 +547,7 @@ var BlockTokenStream = class {
556
547
  return this.#position(this.#fields[index * 4 + 2]);
557
548
  }
558
549
  contentEnd(source, index) {
559
- const end = this.end(index);
560
- const last = source.charCodeAt(end - 1);
561
- return last === 10 ? end - (source.charCodeAt(end - 2) === 13 ? 2 : 1) : last === 13 ? end - 1 : end;
550
+ return lineContentEnd(source, this.start(index), this.end(index));
562
551
  }
563
552
  text(source, index) {
564
553
  return this.#metadata?.[index]?.text ?? source.slice(this.start(index), this.end(index));
@@ -622,42 +611,7 @@ function appendLogicalToken(out, kind, source, lines, start, end, value) {
622
611
  value
623
612
  });
624
613
  }
625
- //#endregion
626
- //#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
- }
614
+ // src/block/scanner.ts
661
615
  function sameShiftedBlock(previous, record, next, tokenStart, tokenEnd, delta) {
662
616
  const length = previous.nodeLength(record.tokenStart);
663
617
  if (length !== tokenEnd - tokenStart) return false;
@@ -665,6 +619,8 @@ function sameShiftedBlock(previous, record, next, tokenStart, tokenEnd, delta) {
665
619
  return true;
666
620
  }
667
621
  var BlockScanContext = class {
622
+ #lineViewDepth = 0;
623
+ #lineViews = [];
668
624
  #lookaheadEnd = 0;
669
625
  #profile;
670
626
  #unwrappedLine = new BlockLines();
@@ -701,14 +657,44 @@ var BlockScanContext = class {
701
657
  this.#lookaheadEnd = 0;
702
658
  return end;
703
659
  }
660
+ createLineView(lines, index, start, prefixColumns) {
661
+ const depth = this.#lineViewDepth++;
662
+ const view = this.#lineViews[depth] ??= new BlockLines();
663
+ view.resetFrom(lines, index, start, prefixColumns);
664
+ return view;
665
+ }
666
+ scanBlockLines(source, lines, out, visit) {
667
+ const profile = this.#profile;
668
+ for (let index = 0; index < lines.length;) {
669
+ let contentOffset = lines.start(index);
670
+ const lineEnd = lines.end(index);
671
+ let columns = lines.prefixColumns(index);
672
+ while (contentOffset < lineEnd) {
673
+ const code = source.charCodeAt(contentOffset);
674
+ if (code !== 32 && code !== 9) break;
675
+ columns += code === 32 ? 1 : 4 - columns % 4;
676
+ contentOffset++;
677
+ }
678
+ if (contentOffset === lineEnd) {
679
+ index++;
680
+ continue;
681
+ }
682
+ if (columns > 3) contentOffset = -1;
683
+ const lineStart = index;
684
+ const tokenStart = out.length;
685
+ index = profile.dispatch(source, lines, index, contentOffset, out, this);
686
+ if (visit?.(lineStart, index, tokenStart, out.length)) return;
687
+ }
688
+ }
704
689
  scanLines(source, lines, out) {
705
690
  let blankSeparated = false;
706
691
  let previousContentEnd = -1;
707
- scanBlockLines(this.#profile, this, source, lines, out, (lineStart, lineEnd) => {
692
+ this.scanBlockLines(source, lines, out, (lineStart, lineEnd) => {
708
693
  blankSeparated ||= previousContentEnd >= 0 && lineStart > previousContentEnd;
709
694
  previousContentEnd = lineEnd;
710
- while (previousContentEnd > lineStart && isBlank(source, lines, previousContentEnd - 1)) previousContentEnd--;
695
+ while (previousContentEnd > lineStart && isBlankLine(source, lines, previousContentEnd - 1)) previousContentEnd--;
711
696
  });
697
+ if (lines === this.#lineViews[this.#lineViewDepth - 1]) this.#lineViewDepth--;
712
698
  return blankSeparated;
713
699
  }
714
700
  startsInterruptingBlock(source, lines, index, contentOffset = lineIndentOffset(source, lines, index)) {
@@ -721,26 +707,27 @@ var BlockScanContext = class {
721
707
  };
722
708
  var BlockScanner = class {
723
709
  #context;
724
- #lines;
725
- #profile;
726
- #records;
727
- #tokens;
710
+ #lines = new BlockLines();
711
+ #records = [];
712
+ #tokens = new BlockTokenStream();
713
+ builds;
728
714
  constructor(profile) {
729
715
  this.#context = new BlockScanContext(profile);
730
- this.#profile = profile;
731
- this.#lines = new BlockLines();
732
- this.#records = [];
733
- this.#tokens = new BlockTokenStream();
716
+ this.builds = profile.builds;
734
717
  }
735
- scan(source) {
736
- const lines = BlockLines.from(source);
718
+ scan(source, indexed) {
719
+ const lines = this.#lines.scan(source);
720
+ const context = this.#context;
737
721
  const tokens = this.#tokens;
722
+ context.resetLookahead();
738
723
  tokens.reset(source.length);
724
+ if (!indexed) {
725
+ context.scanBlockLines(source, lines, tokens);
726
+ return;
727
+ }
739
728
  const records = this.#records;
740
- const context = this.#context;
741
729
  let recordIndex = 0;
742
- context.resetLookahead();
743
- scanBlockLines(this.#profile, context, source, lines, tokens, (lineStart, lineEnd, tokenStart) => {
730
+ context.scanBlockLines(source, lines, tokens, (lineStart, lineEnd, tokenStart) => {
744
731
  const end = lines.next(lineEnd - 1);
745
732
  const dependencyEnd = Math.max(end, context.consumeLookahead());
746
733
  const record = records[recordIndex++];
@@ -757,7 +744,6 @@ var BlockScanner = class {
757
744
  });
758
745
  });
759
746
  records.length = recordIndex;
760
- this.#lines = lines;
761
747
  }
762
748
  get tokens() {
763
749
  return this.#tokens;
@@ -765,10 +751,6 @@ var BlockScanner = class {
765
751
  get records() {
766
752
  return this.#records;
767
753
  }
768
- ruleOf(tokenStart) {
769
- const kind = this.#tokens.kind(tokenStart);
770
- return this.#profile.rules[kind];
771
- }
772
754
  locator() {
773
755
  return this.#lines.locator();
774
756
  }
@@ -797,7 +779,7 @@ var BlockScanner = class {
797
779
  const scanLines = nextLines.slice(scanLineStart, scanLineEnd);
798
780
  let convergenceIndex = affectedIndex;
799
781
  context.resetLookahead();
800
- scanBlockLines(this.#profile, context, nextSource, scanLines, replacement, (lineStart, lineEnd, tokenStart, tokenEnd) => {
782
+ context.scanBlockLines(nextSource, scanLines, replacement, (lineStart, lineEnd, tokenStart, tokenEnd) => {
801
783
  const blockStart = scanLines.start(lineStart);
802
784
  const blockEnd = scanLines.next(lineEnd - 1);
803
785
  const observedEnd = context.consumeLookahead();
@@ -860,12 +842,11 @@ var BlockScanner = class {
860
842
  };
861
843
  }
862
844
  };
863
- //#endregion
864
- //#region src/fragment/block.ts
845
+ // src/fragment/block.ts
865
846
  function blockEnd(tokenStart, context) {
866
847
  const tokens = context.structure.tokens;
867
848
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
868
- return tokens.nodeLength(close) === 0 ? tokens.end(close) : tokens.contentEnd(context.source, close);
849
+ return close === tokenStart ? tokens.contentEnd(context.source, close) : tokens.end(close);
869
850
  }
870
851
  function leafBlockPosition(tokenStart, context) {
871
852
  const tokens = context.structure.tokens;
@@ -879,22 +860,26 @@ function fencedBlockPosition(tokenStart, block, context) {
879
860
  return context.locator.positionAt(tokens.start(tokenStart) + block.markerOffset, positionEnd);
880
861
  }
881
862
  function buildBlockNode(tokenStart, context) {
882
- return context.structure.ruleOf(tokenStart).build(tokenStart, context);
863
+ const kind = context.structure.tokens.kind(tokenStart);
864
+ return context.structure.builds[kind](tokenStart, context);
883
865
  }
884
866
  function buildBlockChildren(tokenStart, context) {
885
- const structure = context.structure;
886
- const tokens = structure.tokens;
867
+ const builds = context.structure.builds;
868
+ const tokens = context.structure.tokens;
887
869
  const children = [];
888
870
  const tokenEnd = tokenStart + tokens.nodeLength(tokenStart) - 1;
889
871
  for (let child = tokenStart + 1; child < tokenEnd;) {
890
872
  const length = tokens.nodeLength(child);
891
- if (length > 0 && structure.ruleOf(child).block) children.push(buildBlockNode(child, context));
873
+ if (length > 0) {
874
+ const kind = tokens.kind(child);
875
+ const role = kind & 448;
876
+ if (role === 64 || role === 256) children.push(builds[kind](child, context));
877
+ }
892
878
  child += length || 1;
893
879
  }
894
880
  return children;
895
881
  }
896
- //#endregion
897
- //#region src/source-view.ts
882
+ // src/source-view.ts
898
883
  function containingSegment(segments, offset) {
899
884
  let low = 0;
900
885
  let high = segments.length >>> 1;
@@ -909,30 +894,34 @@ var SourceView = class {
909
894
  #offset = 0;
910
895
  #segments;
911
896
  text;
912
- constructor(source, startOrRanges, end) {
913
- if (typeof startOrRanges === "number") {
914
- this.#offset = startOrRanges;
915
- this.text = source.slice(startOrRanges, end);
897
+ constructor(source, tokens, tokenStart, nodeLength) {
898
+ let token = tokenStart + 1;
899
+ const firstStart = tokens.start(token);
900
+ const tokenEnd = tokenStart + nodeLength;
901
+ let segmentStart = firstStart;
902
+ let end = tokens.end(token++);
903
+ let parts;
904
+ let segments;
905
+ let viewEnd = 0;
906
+ while (token < tokenEnd && tokens.kind(token) === 1) {
907
+ const start = tokens.start(token);
908
+ if (start !== end) {
909
+ (parts ??= []).push(source.slice(segmentStart, end));
910
+ (segments ??= []).push(segmentStart - viewEnd, viewEnd += end - segmentStart);
911
+ segmentStart = start;
912
+ }
913
+ end = tokens.end(token);
914
+ token++;
915
+ }
916
+ if (parts && segments) {
917
+ parts.push(source.slice(segmentStart, end));
918
+ segments.push(segmentStart - viewEnd, viewEnd + end - segmentStart);
919
+ this.#segments = segments;
920
+ this.text = parts.join("");
916
921
  return;
917
922
  }
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("");
923
+ this.#offset = firstStart;
924
+ this.text = source.slice(firstStart, end);
936
925
  }
937
926
  mapOffset(offset) {
938
927
  const segments = this.#segments;
@@ -954,8 +943,7 @@ var SourceView = class {
954
943
  for (let index = 0; index < segments.length; index += 2) segments[index] += delta;
955
944
  }
956
945
  };
957
- //#endregion
958
- //#region src/inline/region.ts
946
+ // src/inline/region.ts
959
947
  const definitionAny = Symbol();
960
948
  var TrackedDefinitionLookup = class {
961
949
  definitions;
@@ -1055,11 +1043,10 @@ var InlineRegionState = class {
1055
1043
  for (let token = tokenStart; token < tokenEnd; token++) {
1056
1044
  const nodeLength = tokens.nodeLength(token);
1057
1045
  if (nodeLength === 0) continue;
1058
- if (structure.ruleOf(token).inlineContent) {
1059
- const inlineView = inlineViewOf(source, tokens, token, nodeLength);
1060
- if (inlineView) bindings.push({
1046
+ if (tokens.kind(token) & 32) {
1047
+ if (tokens.kind(token + 1) === 1) bindings.push({
1061
1048
  tokenStart: token,
1062
- view: inlineView
1049
+ view: new SourceView(source, tokens, token, nodeLength)
1063
1050
  });
1064
1051
  token += nodeLength - 1;
1065
1052
  }
@@ -1127,42 +1114,7 @@ var InlineRegionCursor = class {
1127
1114
  return region;
1128
1115
  }
1129
1116
  };
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
- //#endregion
1165
- //#region src/document.ts
1117
+ // src/document.ts
1166
1118
  function applyEdits(source, edits) {
1167
1119
  const parts = [];
1168
1120
  let cursor = 0;
@@ -1212,7 +1164,7 @@ var DocumentImpl = class {
1212
1164
  this.#profile = profile;
1213
1165
  this.#source = source;
1214
1166
  this.#blockScanner = new BlockScanner(profile.block);
1215
- this.#blockScanner.scan(source);
1167
+ this.#blockScanner.scan(source, true);
1216
1168
  this.#regionState = new InlineRegionState(profile.inline, this.#blockScanner);
1217
1169
  this.#updateTree(this.#regionState.update(source));
1218
1170
  }
@@ -1310,9 +1262,9 @@ var DocumentImpl = class {
1310
1262
  source
1311
1263
  };
1312
1264
  const start = locator.locationAt(0);
1313
- const records = blockScanner.records;
1314
- const children = new Array(records.length);
1315
- for (let index = 0; index < records.length; index++) children[index] = buildBlockNode(records[index].tokenStart, context);
1265
+ const tokens = blockScanner.tokens;
1266
+ const children = [];
1267
+ for (let token = 0; token < tokens.length; token += tokens.nodeLength(token)) children.push(buildBlockNode(token, context));
1316
1268
  return {
1317
1269
  type: "root",
1318
1270
  children,
@@ -1323,17 +1275,51 @@ var DocumentImpl = class {
1323
1275
  };
1324
1276
  }
1325
1277
  };
1326
- //#endregion
1327
- //#region src/block/profile.ts
1278
+ // src/block/profile.ts
1279
+ function generateBlockDispatch(starts, fallbacks) {
1280
+ try {
1281
+ const resolvers = [];
1282
+ const call = (resolve) => {
1283
+ return `e=r${resolvers.push(resolve) - 1}(s,l,i,o,t,c);if(e!==void 0)return e;`;
1284
+ };
1285
+ let cases = "";
1286
+ for (const code in starts) cases += `case ${code}:${starts[code].map(call).join("")}break;`;
1287
+ const source = [
1288
+ `return(s,l,i,o,t,c)=>{`,
1289
+ `let e;switch(o<0?-1:s.charCodeAt(o)){${cases}}`,
1290
+ ...fallbacks.map(call),
1291
+ `throw new Error("Syntax profile did not provide a block fallback")}`
1292
+ ].join("");
1293
+ const names = resolvers.map((resolver, index) => `r${index}`);
1294
+ return Function(...names, source)(...resolvers);
1295
+ } catch {
1296
+ return (source, lines, start, contentOffset, out, context) => {
1297
+ const resolvers = starts[contentOffset < 0 ? -1 : source.charCodeAt(contentOffset)];
1298
+ if (resolvers) for (const resolve of resolvers) {
1299
+ const end = resolve(source, lines, start, contentOffset, out, context);
1300
+ if (end !== void 0) return end;
1301
+ }
1302
+ for (const fallback of fallbacks) {
1303
+ const end = fallback(source, lines, start, contentOffset, out, context);
1304
+ if (end !== void 0) return end;
1305
+ }
1306
+ throw new Error("Syntax profile did not provide a block fallback");
1307
+ };
1308
+ }
1309
+ }
1328
1310
  function compileBlockProfile(features) {
1311
+ const builds = [];
1329
1312
  const decorators = [];
1330
1313
  const fallbacks = [];
1331
1314
  const interrupts = [];
1332
1315
  const lazyContinuationUnwrappers = [];
1333
- const ruleByBlockRule = [];
1334
- const rules = [];
1335
1316
  const starts = [];
1336
1317
  for (const feature of features) {
1318
+ if (feature.builds) for (const registration of feature.builds) {
1319
+ const token = registration.token;
1320
+ const tokens = typeof token === "number" ? [token] : token;
1321
+ for (const token of tokens) builds[token] = registration.build;
1322
+ }
1337
1323
  if (feature.decorators) decorators.push(...feature.decorators);
1338
1324
  if (feature.fallbacks) fallbacks.push(...feature.fallbacks);
1339
1325
  if (feature.starts) for (const registration of feature.starts) {
@@ -1343,34 +1329,24 @@ function compileBlockProfile(features) {
1343
1329
  if (registration.interrupt) (interrupts[code] ??= []).push(registration.interrupt);
1344
1330
  }
1345
1331
  }
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
1332
  }
1358
1333
  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);
1334
+ const token = registration.token;
1335
+ const tokens = typeof token === "number" ? [token] : token;
1336
+ for (const token of tokens) {
1337
+ const build = builds[token];
1338
+ if (!build) throw new Error(`Cannot decorate unknown block token ${token}`);
1339
+ builds[token] = registration.decorate(build);
1340
+ }
1363
1341
  }
1364
1342
  return {
1365
- fallbacks,
1343
+ builds,
1344
+ dispatch: generateBlockDispatch(starts, fallbacks),
1366
1345
  interrupts,
1367
- lazyContinuationUnwrappers,
1368
- rules,
1369
- starts
1346
+ lazyContinuationUnwrappers
1370
1347
  };
1371
1348
  }
1372
- //#endregion
1373
- //#region src/inline/lexer.ts
1349
+ // src/inline/lexer.ts
1374
1350
  const tokenizerFactories = new Map();
1375
1351
  function matchInlinePatternEnd(pattern, source, start) {
1376
1352
  pattern.lastIndex = start;
@@ -1385,17 +1361,12 @@ function inlineMarkerRunEnd(source, start) {
1385
1361
  function tokenize(source, textBoundary, scannerByCode) {
1386
1362
  const tokens = [];
1387
1363
  const end = source.length;
1388
- let lineStart = 0;
1389
1364
  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
- }
1365
+ while (source.charCodeAt(offset) === 32) offset++;
1366
+ for (; offset < end;) {
1367
+ textBoundary.lastIndex = offset;
1368
+ if (!textBoundary.test(source)) break;
1369
+ offset = textBoundary.lastIndex - 1;
1399
1370
  const code = source.charCodeAt(offset);
1400
1371
  if (code === 10 || code === 13) {
1401
1372
  if (source.charCodeAt(offset - 1) === 32 && source.charCodeAt(offset - 2) === 32) {
@@ -1403,15 +1374,15 @@ function tokenize(source, textBoundary, scannerByCode) {
1403
1374
  while (source.charCodeAt(spaces - 1) === 32) spaces--;
1404
1375
  tokens.push(128, spaces, offset, 0);
1405
1376
  }
1406
- offset++;
1377
+ const endingStart = offset++;
1407
1378
  if (code === 13 && source.charCodeAt(offset) === 10) offset++;
1408
- lineStart = offset;
1379
+ const lineStart = offset;
1380
+ while (source.charCodeAt(offset) === 32) offset++;
1381
+ tokens.push(67, endingStart, offset, lineStart);
1409
1382
  continue;
1410
1383
  }
1411
1384
  const scannedEnd = scannerByCode[code]?.(source, offset, tokens) ?? offset;
1412
1385
  offset = scannedEnd > offset ? scannedEnd : offset + 1;
1413
- textBoundary.lastIndex = offset;
1414
- offset = textBoundary.test(source) ? textBoundary.lastIndex - 1 : end;
1415
1386
  }
1416
1387
  return tokens;
1417
1388
  }
@@ -1422,21 +1393,19 @@ function generateInlineTokenizer(boundaryCodes, textBoundary, scannerByCode) {
1422
1393
  const names = boundaryCodes.map((code, index) => `scan${index}`);
1423
1394
  const source = [
1424
1395
  `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}`,
1396
+ `const tokens=[],end=source.length;let offset=0;`,
1397
+ `while(source.charCodeAt(offset)===32)offset++;for(;offset<end;){`,
1398
+ `textBoundary.lastIndex=offset;if(!textBoundary.test(source))break;offset=textBoundary.lastIndex-1;`,
1430
1399
  `const code=source.charCodeAt(offset);`,
1431
1400
  `if(code===10||code===13){`,
1432
1401
  `if(source.charCodeAt(offset-1)===32&&source.charCodeAt(offset-2)===32){`,
1433
1402
  `let spaces=offset-2;while(source.charCodeAt(spaces-1)===32)spaces--;`,
1434
1403
  `tokens.push(128,spaces,offset,0)}`,
1435
- `offset++;if(code===13&&source.charCodeAt(offset)===10)offset++;`,
1436
- `lineStart=offset;continue}`,
1404
+ `const endingStart=offset++;if(code===13&&source.charCodeAt(offset)===10)offset++;`,
1405
+ `const lineStart=offset;while(source.charCodeAt(offset)===32)offset++;`,
1406
+ `tokens.push(67,endingStart,offset,lineStart);continue}`,
1437
1407
  `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}`,
1408
+ `offset=scannedEnd>offset?scannedEnd:offset+1}`,
1440
1409
  `return tokens}`
1441
1410
  ].join("");
1442
1411
  tokenizerFactories.set(key, factory = Function("textBoundary", ...names, source));
@@ -1463,38 +1432,62 @@ function compileInlineTokenizer(rules) {
1463
1432
  return (source) => tokenize(source, textBoundary, scannerByCode);
1464
1433
  }
1465
1434
  }
1466
- //#endregion
1467
- //#region src/inline/profile.ts
1435
+ // src/inline/profile.ts
1468
1436
  function compileInlineProfile(features, compileInlineResolver) {
1469
- const buildByKind = [];
1437
+ const builders = [];
1470
1438
  const delimiters = [];
1471
1439
  const scanRules = [];
1472
1440
  for (const feature of features) {
1473
- if (feature.scan) scanRules.push(...feature.scan);
1441
+ if (feature.scans) scanRules.push(...feature.scans);
1474
1442
  if (feature.delimiters) delimiters.push(...feature.delimiters);
1475
- const build = feature.build;
1443
+ const build = feature.builds;
1476
1444
  if (!build) continue;
1477
1445
  for (const rule of build) switch (rule.kind) {
1478
1446
  case "decorate":
1479
- buildByKind[rule.token] = rule.apply;
1447
+ builders[rule.token] = rule.apply;
1480
1448
  break;
1481
1449
  case "leaf":
1482
- buildByKind[rule.token] = rule.build;
1483
- break;
1484
1450
  case "text":
1485
- buildByKind[rule.token] = rule.build;
1486
- break;
1487
- case "pair": buildByKind[rule.token] = rule.build;
1451
+ case "pair": builders[rule.token] = rule.build;
1488
1452
  }
1489
1453
  }
1490
1454
  return {
1491
- buildByKind,
1455
+ builders,
1492
1456
  resolve: compileInlineResolver(delimiters),
1493
1457
  tokenize: compileInlineTokenizer(scanRules)
1494
1458
  };
1495
1459
  }
1496
- //#endregion
1497
- //#region src/inline/tokens.ts
1460
+ // src/profile/features/attributes/block.ts
1461
+ const blockDecorators = [{
1462
+ token: [65, 66],
1463
+ decorate(build) {
1464
+ return (tokenStart, context) => {
1465
+ const result = build(tokenStart, context);
1466
+ if (!result.spread) for (const item of result.children) {
1467
+ const paragraph = !item.spread && item.children.length === 1 && item.children[0].type === "paragraph" ? item.children[0] : void 0;
1468
+ if (paragraph?.attributes) {
1469
+ item.attributes = paragraph.attributes;
1470
+ delete paragraph.attributes;
1471
+ }
1472
+ }
1473
+ return result;
1474
+ };
1475
+ }
1476
+ }, {
1477
+ token: 64,
1478
+ decorate(build) {
1479
+ return (tokenStart, context) => {
1480
+ const result = build(tokenStart, context);
1481
+ const paragraph = result.children.length === 1 && result.children[0].type === "paragraph" ? result.children[0] : void 0;
1482
+ if (paragraph?.attributes) {
1483
+ result.attributes = paragraph.attributes;
1484
+ delete paragraph.attributes;
1485
+ }
1486
+ return result;
1487
+ };
1488
+ }
1489
+ }];
1490
+ // src/inline/tokens.ts
1498
1491
  function inlineTokenCount(tokens) {
1499
1492
  return tokens.length / 4;
1500
1493
  }
@@ -1518,8 +1511,8 @@ function rewriteInlineTokenTail(tokens, kind, end) {
1518
1511
  tokens[offset + 0] = kind;
1519
1512
  tokens[offset + 2] = end;
1520
1513
  }
1521
- function inlineTokenText(source, tokens, index) {
1522
- return source.slice(inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index));
1514
+ function inlineTokenText(source, tokens, index, startPadding = 0, endPadding = startPadding) {
1515
+ return source.slice(inlineTokenStart(tokens, index) + startPadding, inlineTokenEnd(tokens, index) - endPadding);
1523
1516
  }
1524
1517
  function appendInlineToken(target, kind, start, end, data = 0) {
1525
1518
  target.push(kind, start, end, data);
@@ -1528,61 +1521,52 @@ function copyInlineToken(target, tokens, index) {
1528
1521
  const offset = index * 4;
1529
1522
  target.push(tokens[offset], tokens[offset + 1], tokens[offset + 2], tokens[offset + 3]);
1530
1523
  }
1531
- //#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);
1524
+ // src/profile/utils.ts
1525
+ const inlineColonBoundary = /[ \t\n\r\p{sc=Han}\p{sc=Hira}\p{sc=Kana}\p{sc=Hang}\p{P}]/u;
1526
+ function isAsciiDigit(code) {
1527
+ return code >= 48 && code <= 57;
1528
+ }
1529
+ function isAsciiLetter(code) {
1541
1530
  return code >= 65 && code <= 90 || code >= 97 && code <= 122;
1542
1531
  }
1543
- function isAsciiDigit(character) {
1544
- if (!character) return false;
1545
- const code = character.charCodeAt(0);
1546
- return code >= 48 && code <= 57;
1532
+ function isAsciiPunctuation(code) {
1533
+ return code >= 33 && code <= 47 || code >= 58 && code <= 64 || code >= 91 && code <= 96 || code >= 123 && code <= 126;
1547
1534
  }
1548
- function isHorizontalWhitespace(character) {
1549
- return character === " " || character === " ";
1535
+ function isMarkdownWhitespace(code) {
1536
+ return code === 9 || code === 10 || code === 13 || code === 32;
1550
1537
  }
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;
1538
+ function hasInlineColonBoundary(source, start) {
1539
+ if (start <= 0) return true;
1540
+ const previous = source[start - 1];
1541
+ return previous !== ":" && inlineColonBoundary.test(previous);
1560
1542
  }
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 = "";
1543
+ function semanticText(value) {
1544
+ return value.includes("\\") || value.includes("&") ? decodeString(value) : value;
1545
+ }
1546
+ function normalizeIdentifier(identifier) {
1547
+ scan: {
1548
+ let hasUppercase = false;
1549
+ for (let index = 0; index < identifier.length; index++) {
1550
+ const code = identifier.charCodeAt(index);
1551
+ if (code === 32) {
1552
+ if (index === 0 || index + 1 === identifier.length || identifier.charCodeAt(index + 1) === 32) break scan;
1553
+ continue;
1570
1554
  }
1571
- previousUpper = void 0;
1572
- continue;
1555
+ if (code < 32 || code > 126) break scan;
1556
+ if (code >= 65 && code <= 90) hasUppercase = true;
1573
1557
  }
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;
1558
+ return hasUppercase ? identifier.toLowerCase() : identifier;
1583
1559
  }
1584
- if (part) parts.push(part);
1585
- return parts.map((value) => value.toLowerCase()).join("-");
1560
+ return identifier.trim().replace(/[ \t\r\n]+/g, " ").toLowerCase().toUpperCase().toLowerCase();
1561
+ }
1562
+ // src/profile/features/attributes/shared.ts
1563
+ const brackets = {
1564
+ "[": "]",
1565
+ "{": "}",
1566
+ "(": ")"
1567
+ };
1568
+ function isHorizontalWhitespace(character) {
1569
+ return character === " " || character === " ";
1586
1570
  }
1587
1571
  function assignAttribute(attributes, name, value) {
1588
1572
  if (name === "class" && typeof value === "string" && typeof attributes.class === "string") attributes.class += ` ${value}`;
@@ -1591,46 +1575,39 @@ function assignAttribute(attributes, name, value) {
1591
1575
  function mergeAttributes(target, source) {
1592
1576
  for (const key in source) assignAttribute(target, key, source[key]);
1593
1577
  }
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
1578
  function scanAttributes(source, start, attributes, limit = source.length) {
1605
1579
  if (source[start] !== "{" || source[start + 1] === "{") return;
1606
1580
  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);
1581
+ const scanUntil = (stops) => {
1582
+ while (offset < limit) {
1583
+ const character = source[offset];
1584
+ if (character === "\n" || character === "\r" || stops.includes(character)) break;
1585
+ offset += character === "\\" && offset + 1 < limit ? 2 : 1;
1586
+ }
1612
1587
  };
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);
1588
+ const scanQuoted = (quote) => {
1618
1589
  offset++;
1619
- return value;
1590
+ while (offset < limit) {
1591
+ const character = source[offset];
1592
+ if (character === "\n" || character === "\r" || character === quote) break;
1593
+ offset += character === "\\" && offset + 1 < limit ? 2 : 1;
1594
+ }
1595
+ if (source[offset] !== quote) return false;
1596
+ offset++;
1597
+ return true;
1620
1598
  };
1621
- const readBracketed = (close) => {
1622
- const valueStart = offset;
1599
+ const scanBracketed = (close) => {
1623
1600
  const stack = [close];
1624
1601
  offset++;
1625
1602
  while (offset < limit && stack.length > 0) {
1626
1603
  const character = source[offset];
1627
- if (character === "\n" || character === "\r") return;
1604
+ if (character === "\n" || character === "\r") return false;
1628
1605
  if (character === "\\" && offset + 1 < limit) {
1629
1606
  offset += 2;
1630
1607
  continue;
1631
1608
  }
1632
1609
  if (character === "\"" || character === "'" || character === "`") {
1633
- if (readQuoted(character) === void 0) return;
1610
+ if (!scanQuoted(character)) return false;
1634
1611
  continue;
1635
1612
  }
1636
1613
  const nestedClose = brackets[character];
@@ -1638,7 +1615,7 @@ function scanAttributes(source, start, attributes, limit = source.length) {
1638
1615
  else if (character === stack.at(-1)) stack.pop();
1639
1616
  offset++;
1640
1617
  }
1641
- return stack.length === 0 ? source.slice(valueStart, offset) : void 0;
1618
+ return stack.length === 0;
1642
1619
  };
1643
1620
  while (offset < limit) {
1644
1621
  while (isHorizontalWhitespace(source[offset])) offset++;
@@ -1646,31 +1623,49 @@ function scanAttributes(source, start, attributes, limit = source.length) {
1646
1623
  const marker = source[offset];
1647
1624
  if (marker === "." || marker === "#") {
1648
1625
  offset++;
1649
- const value = readUntil(" #.}");
1650
- if (!value) return;
1651
- if (attributes) assignAttribute(attributes, marker === "." ? "class" : "id", value);
1626
+ const valueStart = offset;
1627
+ scanUntil(" #.}");
1628
+ if (offset === valueStart) return;
1629
+ if (attributes) assignAttribute(attributes, marker === "." ? "class" : "id", source.slice(valueStart, offset));
1652
1630
  continue;
1653
1631
  }
1654
1632
  const nameStart = offset;
1655
- if (source[offset] === ":") offset++;
1656
- if (!isAsciiLetter(source[offset]) && source[offset] !== "_") return;
1633
+ if (source.charCodeAt(offset) === 58) offset++;
1634
+ let code = source.charCodeAt(offset);
1635
+ if (!isAsciiLetter(code) && code !== 95) return;
1657
1636
  offset++;
1658
- while (isAsciiLetter(source[offset]) || isAsciiDigit(source[offset]) || source[offset] === "_" || source[offset] === "-") offset++;
1659
- const rawName = source.slice(nameStart, offset);
1637
+ while (true) {
1638
+ code = source.charCodeAt(offset);
1639
+ if (!isAsciiLetter(code) && !isAsciiDigit(code) && code !== 95 && code !== 45) break;
1640
+ offset++;
1641
+ }
1642
+ const nameEnd = offset;
1660
1643
  while (isHorizontalWhitespace(source[offset])) offset++;
1661
1644
  if (source[offset] !== "=") {
1662
- if (attributes) assignAttribute(attributes, rawName.startsWith(":") ? rawName : `:${rawName}`, "true");
1645
+ if (attributes) {
1646
+ const name = source.slice(nameStart, nameEnd);
1647
+ assignAttribute(attributes, source.charCodeAt(nameStart) === 58 ? name : `:${name}`, "true");
1648
+ }
1663
1649
  continue;
1664
1650
  }
1665
1651
  offset++;
1666
1652
  while (isHorizontalWhitespace(source[offset])) offset++;
1667
1653
  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);
1654
+ let valueStart = offset;
1655
+ let valueEnd;
1656
+ if (character === "\"" || character === "'" || character === "`") {
1657
+ if (!scanQuoted(character)) return;
1658
+ valueStart++;
1659
+ valueEnd = offset - 1;
1660
+ } else if (brackets[character]) {
1661
+ if (!scanBracketed(brackets[character])) return;
1662
+ valueEnd = offset;
1663
+ } else {
1664
+ scanUntil(" }");
1665
+ valueEnd = offset;
1666
+ if (valueEnd === valueStart) return;
1667
+ }
1668
+ if (attributes) assignAttribute(attributes, source.slice(nameStart, nameEnd), source.slice(valueStart, valueEnd));
1674
1669
  }
1675
1670
  }
1676
1671
  function attributesEnd(source, start, limit = source.length) {
@@ -1678,37 +1673,10 @@ function attributesEnd(source, start, limit = source.length) {
1678
1673
  }
1679
1674
  function parseAttributes(source, start) {
1680
1675
  const attributes = {};
1681
- const end = scanAttributes(source, start, attributes);
1682
- return end === void 0 ? void 0 : {
1683
- attributes,
1684
- end
1685
- };
1686
- }
1687
- //#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;
1676
+ scanAttributes(source, start, attributes);
1677
+ return attributes;
1711
1678
  }
1679
+ // src/profile/features/attributes/inline.ts
1712
1680
  function hasVisibleText(source, start, end) {
1713
1681
  for (let offset = start; offset < end; offset++) if (!isMarkdownWhitespace(source.charCodeAt(offset))) return true;
1714
1682
  return false;
@@ -1716,82 +1684,68 @@ function hasVisibleText(source, start, end) {
1716
1684
  function attributeEndAt(source, start) {
1717
1685
  return source[start + 1] === "{" || source[start - 1] === "{" || source[start - 1] === "$" ? void 0 : attributesEnd(source, start);
1718
1686
  }
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
- }
1687
+ // src/profile/features/attributes/index.ts
1747
1688
  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
- ] },
1689
+ block: { decorators: blockDecorators },
1762
1690
  inline: {
1763
- scan: [{
1691
+ scans: [{
1764
1692
  marker: 123,
1765
- scan: scanAttribute
1693
+ scan(source, start, tokens) {
1694
+ const end = attributeEndAt(source, start);
1695
+ if (end === void 0) return -1;
1696
+ if (tokens.length === 0 && !hasVisibleText(source, 0, start)) {
1697
+ let textEnd = end;
1698
+ while (true) {
1699
+ let next = textEnd;
1700
+ while (source.charCodeAt(next) === 9 || source.charCodeAt(next) === 32) next++;
1701
+ const nextEnd = source.charCodeAt(next) === 123 ? attributeEndAt(source, next) : void 0;
1702
+ if (nextEnd === void 0) break;
1703
+ textEnd = nextEnd;
1704
+ }
1705
+ return textEnd;
1706
+ }
1707
+ const previous = inlineTokenCount(tokens) - 1;
1708
+ const previousEnd = previous >= 0 ? inlineTokenEnd(tokens, previous) : 0;
1709
+ if (previousEnd < start && (previous >= 0 && inlineTokenKind(tokens, previous) === 256 || hasVisibleText(source, previousEnd, start))) appendInlineToken(tokens, 64, previousEnd, start);
1710
+ appendInlineToken(tokens, 256, start, end, start > 0 && isMarkdownWhitespace(source.charCodeAt(start - 1)) ? 1 : 0);
1711
+ let next = end;
1712
+ while (isMarkdownWhitespace(source.charCodeAt(next))) next++;
1713
+ if (next === source.length) for (let index = inlineTokenCount(tokens) - 1; index >= 0; index--) {
1714
+ const kind = inlineTokenKind(tokens, index);
1715
+ if (kind === 64 && !hasVisibleText(source, inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index))) continue;
1716
+ if (kind !== 256) break;
1717
+ setInlineTokenData(tokens, index, inlineTokenData(tokens, index) | 2);
1718
+ }
1719
+ return end;
1720
+ }
1766
1721
  }],
1767
- build: [{
1722
+ builds: [{
1768
1723
  kind: "decorate",
1769
1724
  token: 256,
1770
1725
  apply(tokenIndex, sourceSpan, context, target) {
1771
1726
  const previous = target.children.at(-1);
1727
+ if (!previous) return false;
1772
1728
  const parsed = parseAttributes(context.view.text, inlineTokenStart(context.tokens, tokenIndex));
1773
- if (!previous || !parsed) return false;
1774
1729
  const flags = inlineTokenData(context.tokens, tokenIndex);
1775
1730
  const terminal = Boolean(flags & 2);
1776
1731
  const detached = Boolean(flags & 1);
1777
1732
  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;
1733
+ if (target.attributes) mergeAttributes(target.attributes, parsed);
1734
+ else target.attributes = parsed;
1780
1735
  return true;
1781
1736
  }
1782
1737
  const attributes = previous.attributes;
1783
- if (attributes) mergeAttributes(attributes, parsed.attributes);
1784
- else previous.attributes = parsed.attributes;
1738
+ if (attributes) mergeAttributes(attributes, parsed);
1739
+ else previous.attributes = parsed;
1785
1740
  previous.position.end = context.locator.locationAt(sourceSpan.end);
1786
1741
  return true;
1787
1742
  }
1788
1743
  }]
1789
1744
  }
1790
1745
  };
1791
- //#endregion
1792
- //#region src/profile/features/binding.ts
1746
+ // src/profile/features/binding.ts
1793
1747
  const feature$17 = { inline: {
1794
- scan: [{
1748
+ scans: [{
1795
1749
  marker: 123,
1796
1750
  scan(source, start, tokens) {
1797
1751
  if (source.charCodeAt(start + 1) !== 123) return -1;
@@ -1805,7 +1759,7 @@ const feature$17 = { inline: {
1805
1759
  return end;
1806
1760
  }
1807
1761
  }],
1808
- build: [{
1762
+ builds: [{
1809
1763
  kind: "leaf",
1810
1764
  token: 135,
1811
1765
  build(tokenIndex, sourceSpan, context) {
@@ -1828,8 +1782,7 @@ const feature$17 = { inline: {
1828
1782
  }
1829
1783
  }]
1830
1784
  } };
1831
- //#endregion
1832
- //#region src/profile/features/blockquote.ts
1785
+ // src/profile/features/blockquote.ts
1833
1786
  function blockQuoteOffset(source, lines, index, markerOffset) {
1834
1787
  if (markerOffset < 0 || source[markerOffset] !== ">") return;
1835
1788
  let offset = markerOffset + 1;
@@ -1845,12 +1798,8 @@ function blockQuoteOffset(source, lines, index, markerOffset) {
1845
1798
  };
1846
1799
  }
1847
1800
  const feature$16 = { block: {
1848
- rules: [{
1849
- rule: 1,
1850
- syntax: {
1851
- kind: "block",
1852
- token: 64
1853
- },
1801
+ builds: [{
1802
+ token: 64,
1854
1803
  build(tokenStart, context) {
1855
1804
  const tokens = context.structure.tokens;
1856
1805
  const start = context.locator.locationAt(tokens.start(tokenStart));
@@ -1876,18 +1825,19 @@ const feature$16 = { block: {
1876
1825
  return true;
1877
1826
  },
1878
1827
  start(source, lines, start, contentOffset, out, context) {
1879
- const quoteLines = new BlockLines();
1880
- let index = start;
1881
- let lazyParagraph = false;
1828
+ const firstMarker = blockQuoteOffset(source, lines, start, contentOffset);
1829
+ const quoteLines = context.createLineView(lines, start, firstMarker.offset, firstMarker.prefixColumns);
1830
+ let index = start + 1;
1831
+ let lazyParagraph = context.endsWithParagraphLeaf(source, quoteLines, 0);
1882
1832
  for (; index < lines.length; index++) {
1883
- const markerOffset = index === start ? contentOffset : lineIndentOffset(source, lines, index);
1833
+ const markerOffset = lineIndentOffset(source, lines, index);
1884
1834
  const marker = blockQuoteOffset(source, lines, index, markerOffset);
1885
1835
  if (marker) {
1886
1836
  quoteLines.pushFrom(lines, index, marker.offset, marker.prefixColumns);
1887
1837
  lazyParagraph = context.endsWithParagraphLeaf(source, quoteLines, quoteLines.length - 1);
1888
1838
  continue;
1889
1839
  }
1890
- if (!lazyParagraph || isBlank(source, lines, index) || !lines.lazy(index) && context.startsInterruptingBlock(source, lines, index, markerOffset)) break;
1840
+ if (!lazyParagraph || markerOffset < 0 && isBlankLine(source, lines, index) || !lines.lazy(index) && context.startsInterruptingBlock(source, lines, index, markerOffset)) break;
1891
1841
  quoteLines.pushLazy(lines, index);
1892
1842
  }
1893
1843
  out.push(64, contentOffset, contentOffset + 1);
@@ -1898,8 +1848,7 @@ const feature$16 = { block: {
1898
1848
  }
1899
1849
  }]
1900
1850
  } };
1901
- //#endregion
1902
- //#region src/profile/features/break.ts
1851
+ // src/profile/features/break.ts
1903
1852
  function isThematicBreak(source, lines, index, contentOffset) {
1904
1853
  const marker = source.charCodeAt(contentOffset);
1905
1854
  if (marker !== 42 && marker !== 45 && marker !== 95) return false;
@@ -1913,12 +1862,8 @@ function isThematicBreak(source, lines, index, contentOffset) {
1913
1862
  }
1914
1863
  const feature$15 = {
1915
1864
  block: {
1916
- rules: [{
1917
- rule: 0,
1918
- syntax: {
1919
- kind: "leaf",
1920
- token: 256
1921
- },
1865
+ builds: [{
1866
+ token: 256,
1922
1867
  build(tokenStart, context) {
1923
1868
  return {
1924
1869
  type: "thematicBreak",
@@ -1942,7 +1887,7 @@ const feature$15 = {
1942
1887
  }
1943
1888
  }]
1944
1889
  },
1945
- inline: { build: [{
1890
+ inline: { builds: [{
1946
1891
  kind: "leaf",
1947
1892
  token: 128,
1948
1893
  build(tokenIndex, sourceSpan) {
@@ -1951,17 +1896,10 @@ const feature$15 = {
1951
1896
  position: sourceSpan
1952
1897
  };
1953
1898
  }
1954
- }, {
1955
- kind: "text",
1956
- token: 67,
1957
- build() {
1958
- return "\n";
1959
- }
1960
1899
  }] }
1961
1900
  };
1962
- //#endregion
1963
- //#region src/block/fence.ts
1964
- function fenceAt$1(source, lines, index, rule, markerOffset) {
1901
+ // src/block/fence.ts
1902
+ function fenceAt(source, lines, index, rule, markerOffset) {
1965
1903
  const marker = source.charCodeAt(markerOffset);
1966
1904
  if (marker !== rule.marker && marker !== rule.alternateMarker) return;
1967
1905
  let offset = markerOffset + 1;
@@ -1994,13 +1932,11 @@ function closesFence(source, lines, index, fence) {
1994
1932
  while (source.charCodeAt(offset) === fence.marker) offset++;
1995
1933
  if (offset < markerEnd) return false;
1996
1934
  const lineEnd = lines.end(index);
1997
- while (offset < lineEnd && (source[offset] === " " || source[offset] === " ")) offset++;
1998
- return offset === lineEnd;
1935
+ return skipLineWhitespace(source, offset, lineEnd) === lineEnd;
1999
1936
  }
2000
1937
  function fencedBlock(source, lines, index, end, fence, closed) {
2001
- let infoStart = fence.offset + fence.length;
2002
1938
  const lineEnd = lines.end(index);
2003
- while (infoStart < lineEnd && (source[infoStart] === " " || source[infoStart] === " ")) infoStart++;
1939
+ const infoStart = skipLineWhitespace(source, fence.offset + fence.length, lineEnd);
2004
1940
  let content;
2005
1941
  if (lines.physicallyContiguous()) {
2006
1942
  const contentStart = lines.next(index);
@@ -2054,66 +1990,7 @@ function sourceColumnFenceContent(source, block) {
2054
1990
  }
2055
1991
  return content;
2056
1992
  }
2057
- //#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
- //#region src/profile/features/code.ts
1993
+ // src/profile/features/code.ts
2117
1994
  const codeFenceRule = {
2118
1995
  alternateMarker: 126,
2119
1996
  forbiddenInfoMarker: 96,
@@ -2121,20 +1998,15 @@ const codeFenceRule = {
2121
1998
  minimumLength: 3
2122
1999
  };
2123
2000
  function codeFenceAt(source, lines, index, markerOffset) {
2124
- return fenceAt$1(source, lines, index, codeFenceRule, markerOffset);
2001
+ return fenceAt(source, lines, index, codeFenceRule, markerOffset);
2125
2002
  }
2126
- const feature$13 = {
2003
+ const feature$14 = {
2127
2004
  block: {
2128
- rules: [{
2129
- rule: 8,
2130
- syntax: {
2131
- kind: "leaf",
2132
- token: 257
2133
- },
2005
+ builds: [{
2006
+ token: 257,
2134
2007
  build(tokenStart, context) {
2135
2008
  const tokens = context.structure.tokens;
2136
2009
  const block = tokens.value(tokenStart);
2137
- if (!block) throw new Error("FencedCodeBlock token has no fence metadata");
2138
2010
  const source = context.locator.normalizeLineEndings(block.content ?? tokens.text(context.source, tokenStart));
2139
2011
  const rawInfo = semanticText(block.info);
2140
2012
  const langEnd = rawInfo.search(/[ \t]/);
@@ -2149,22 +2021,16 @@ const feature$13 = {
2149
2021
  };
2150
2022
  }
2151
2023
  }, {
2152
- rule: 9,
2153
- syntax: {
2154
- kind: "leaf",
2155
- token: 258
2156
- },
2024
+ token: 258,
2157
2025
  build(tokenStart, context) {
2158
2026
  const tokens = context.structure.tokens;
2159
2027
  const offset = tokens.start(tokenStart);
2160
2028
  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
2029
  return {
2164
2030
  type: "code",
2165
2031
  lang: null,
2166
2032
  meta: null,
2167
- value: lines.join("\n"),
2033
+ value: context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart)).replace(/^(?: {0,3}\t| {4}| {1,3}$)/gm, "").replace(/\n(?:[ \t]*\n)*[ \t]*$/, ""),
2168
2034
  position: context.locator.positionAt(offset, offset + contentLength)
2169
2035
  };
2170
2036
  }
@@ -2175,7 +2041,7 @@ const feature$13 = {
2175
2041
  let end = start + 1;
2176
2042
  while (end < lines.length && lineIndentOffset(source, lines, end) < 0) end++;
2177
2043
  let contentEnd = end;
2178
- while (contentEnd > start && isBlank(source, lines, contentEnd - 1)) contentEnd--;
2044
+ while (contentEnd > start && isBlankLine(source, lines, contentEnd - 1)) contentEnd--;
2179
2045
  const contentLength = lines.end(contentEnd - 1) - lines.start(start);
2180
2046
  appendLogicalToken(out, 258, source, lines, start, end, contentLength);
2181
2047
  return end;
@@ -2198,7 +2064,7 @@ const feature$13 = {
2198
2064
  }]
2199
2065
  },
2200
2066
  inline: {
2201
- scan: [{
2067
+ scans: [{
2202
2068
  marker: 96,
2203
2069
  scan(source, start, tokens) {
2204
2070
  if (source.charCodeAt(start - 1) === 96) return start + 1;
@@ -2218,25 +2084,23 @@ const feature$13 = {
2218
2084
  return start + 1;
2219
2085
  }
2220
2086
  }],
2221
- build: [{
2087
+ builds: [{
2222
2088
  kind: "leaf",
2223
2089
  token: 129,
2224
2090
  build: (tokenIndex, sourceSpan, context) => {
2225
- const text = inlineTokenText(context.view.text, context.tokens, tokenIndex);
2226
2091
  const markerLength = inlineTokenData(context.tokens, tokenIndex);
2227
- let value = context.locator.normalizeLineEndings(text.slice(markerLength, -markerLength));
2092
+ let value = context.locator.normalizeLineEndings(inlineTokenText(context.view.text, context.tokens, tokenIndex, markerLength));
2228
2093
  if (/^[ \n]/.test(value) && /[ \n]$/.test(value) && /[^ \n]/.test(value)) value = value.slice(1, -1);
2229
2094
  return {
2230
2095
  type: "inlineCode",
2231
- value: context.blockRule === 17 ? value.replace(/\\\|/g, "|") : value,
2096
+ value: context.tableCell ? value.replace(/\\\|/g, "|") : value,
2232
2097
  position: sourceSpan
2233
2098
  };
2234
2099
  }
2235
2100
  }]
2236
2101
  }
2237
2102
  };
2238
- //#endregion
2239
- //#region src/fragment/inline.ts
2103
+ // src/fragment/inline.ts
2240
2104
  function createInlineOutput(children, cursor) {
2241
2105
  return {
2242
2106
  children,
@@ -2246,9 +2110,6 @@ function createInlineOutput(children, cursor) {
2246
2110
  trailingSpaces: 0
2247
2111
  };
2248
2112
  }
2249
- function lineEndingStart(source, lineStart) {
2250
- return source.charCodeAt(lineStart - 1) === 10 && source.charCodeAt(lineStart - 2) === 13 ? lineStart - 2 : lineStart - 1;
2251
- }
2252
2113
  function trimTrailingText(output) {
2253
2114
  const text = output.lastText;
2254
2115
  const removed = text ? output.trailingSpaces : 0;
@@ -2295,43 +2156,43 @@ function finishText(output, context) {
2295
2156
  function appendGap(output, context, start, end) {
2296
2157
  appendText(output, context.view.text.slice(start, end), context.view.mapOffset(start), context.view.mapEnd(end), context);
2297
2158
  }
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
- }
2159
+ function appendLeaf(output, context, token, start, end, build) {
2160
+ if (start > output.cursor) appendGap(output, context, output.cursor, start);
2161
+ const sourceStart = context.view.mapOffset(start);
2162
+ const sourceEnd = start === end ? sourceStart : context.view.mapEnd(end);
2163
+ finishText(output, context);
2164
+ output.children.push(build(token, context.locator.positionAt(sourceStart, sourceEnd), context));
2165
+ output.lastText = void 0;
2324
2166
  }
2325
2167
  function appendRange(startToken, endToken, profile, context, output, closeKind = 0) {
2326
2168
  let index = startToken;
2327
2169
  while (index < endToken) {
2328
2170
  const kind = inlineTokenKind(context.tokens, index);
2171
+ if (kind === 67) {
2172
+ const endingStart = inlineTokenStart(context.tokens, index);
2173
+ const lineStart = inlineTokenData(context.tokens, index);
2174
+ const contentStart = inlineTokenEnd(context.tokens, index);
2175
+ if (endingStart > output.cursor) appendGap(output, context, output.cursor, endingStart);
2176
+ const previous = output.lastText === void 0 ? output.children.at(-1) : void 0;
2177
+ if (previous?.type === "break") previous.position.end = context.locator.locationAt(context.view.mapOffset(lineStart - 1) + 1);
2178
+ else {
2179
+ trimTrailingText(output);
2180
+ appendText(output, "\n", context.view.mapOffset(endingStart), context.view.mapEnd(contentStart), context);
2181
+ }
2182
+ output.cursor = contentStart;
2183
+ index++;
2184
+ continue;
2185
+ }
2329
2186
  if (kind === closeKind) break;
2330
- const build = profile.buildByKind[kind];
2187
+ const build = profile.builders[kind];
2331
2188
  const childStart = inlineTokenStart(context.tokens, index);
2332
2189
  if (kind < 192) {
2333
2190
  const childEnd = inlineTokenEnd(context.tokens, index);
2334
- appendToken(output, context, index, childStart, childEnd, build, kind < 128, kind === 67);
2191
+ if (kind < 128) {
2192
+ if (childStart > output.cursor) appendGap(output, context, output.cursor, childStart);
2193
+ const sourceStart = context.view.mapOffset(childStart);
2194
+ appendText(output, build(index, context), sourceStart, childStart === childEnd ? sourceStart : context.view.mapEnd(childEnd), context);
2195
+ } else appendLeaf(output, context, index, childStart, childEnd, build);
2335
2196
  output.cursor = childEnd;
2336
2197
  index++;
2337
2198
  continue;
@@ -2339,7 +2200,7 @@ function appendRange(startToken, endToken, profile, context, output, closeKind =
2339
2200
  if (kind < 256) {
2340
2201
  if (childStart > output.cursor) appendGap(output, context, output.cursor, childStart);
2341
2202
  finishText(output, context);
2342
- index = appendSemantic(index, endToken, profile, context, output, build, kind + 1);
2203
+ index = appendPair(index, endToken, profile, context, output, build, kind + 1);
2343
2204
  continue;
2344
2205
  }
2345
2206
  const childEnd = inlineTokenEnd(context.tokens, index);
@@ -2356,14 +2217,12 @@ function appendRange(startToken, endToken, profile, context, output, closeKind =
2356
2217
  }
2357
2218
  index++;
2358
2219
  }
2359
- if (index < endToken) {
2360
- const contentEnd = inlineTokenStart(context.tokens, index);
2361
- if (contentEnd > output.cursor) appendGap(output, context, output.cursor, contentEnd);
2362
- } else if (context.view.text.length > output.cursor) appendGap(output, context, output.cursor, context.view.text.length);
2220
+ const contentEnd = index < endToken ? inlineTokenStart(context.tokens, index) : context.view.text.length;
2221
+ if (contentEnd > output.cursor) appendGap(output, context, output.cursor, contentEnd);
2363
2222
  finishText(output, context);
2364
2223
  return index;
2365
2224
  }
2366
- function appendSemantic(openToken, endToken, profile, context, output, build, closeKind) {
2225
+ function appendPair(openToken, endToken, profile, context, output, build, closeKind) {
2367
2226
  const childStart = inlineTokenStart(context.tokens, openToken);
2368
2227
  const positionStart = context.locator.locationAt(context.view.mapOffset(childStart));
2369
2228
  const children = [];
@@ -2379,17 +2238,27 @@ function appendSemantic(openToken, endToken, profile, context, output, build, cl
2379
2238
  output.cursor = childEnd;
2380
2239
  return closeToken + 1;
2381
2240
  }
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;
2241
+ function buildInlineFragment(tokenStart, tableCell, context) {
2242
+ let tokens;
2243
+ let view;
2244
+ if (context.cursor) {
2245
+ const region = context.cursor.take(tokenStart);
2246
+ if (!region) return { children: [] };
2247
+ tokens = region.tokens;
2248
+ view = region.view;
2249
+ } else {
2250
+ const blockTokens = context.structure.tokens;
2251
+ if (blockTokens.kind(tokenStart + 1) !== 1) return { children: [] };
2252
+ view = new SourceView(context.source, blockTokens, tokenStart, blockTokens.nodeLength(tokenStart));
2253
+ tokens = context.profile.resolve(view.text, context.profile.tokenize(view.text), blockTokens);
2254
+ }
2386
2255
  const inlineContext = context.inlineContext ??= {
2387
- blockRule,
2388
2256
  locator: context.locator,
2257
+ tableCell,
2389
2258
  tokens,
2390
2259
  view
2391
2260
  };
2392
- inlineContext.blockRule = blockRule;
2261
+ inlineContext.tableCell = tableCell;
2393
2262
  inlineContext.tokens = tokens;
2394
2263
  inlineContext.view = view;
2395
2264
  const result = createInlineOutput([], 0);
@@ -2405,37 +2274,30 @@ function buildInlineFragment(tokenStart, blockRule, context) {
2405
2274
  }
2406
2275
  return result;
2407
2276
  }
2408
- //#endregion
2409
- //#region src/profile/features/frontmatter.ts
2277
+ // src/profile/features/frontmatter.ts
2410
2278
  function frontmatterFenceAt(source, lines, index, marker) {
2411
2279
  const start = lines.start(index);
2412
2280
  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;
2281
+ const end = lines.end(index);
2282
+ return skipLineWhitespace(source, start + 3, end) === end;
2415
2283
  }
2416
- const buildFrontmatter = (tokenStart, context) => {
2284
+ const buildYamlBlock = (tokenStart, context) => {
2417
2285
  const tokens = context.structure.tokens;
2418
2286
  const text = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
2419
2287
  const contentStart = text.indexOf("\n") + 1;
2420
2288
  const closingEnd = text.endsWith("\n") ? text.length - 1 : text.length;
2421
2289
  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
2290
  return {
2425
2291
  type: "yaml",
2426
- value,
2292
+ value: text.slice(contentStart, Math.max(contentStart, closingStart - 1)),
2427
2293
  position: leafBlockPosition(tokenStart, context)
2428
2294
  };
2429
2295
  };
2430
- function feature$12(marker) {
2296
+ function feature$13(marker) {
2431
2297
  return { block: {
2432
- rules: [{
2433
- rule: 13,
2434
- syntax: {
2435
- kind: "leaf",
2436
- token: 260
2437
- },
2438
- build: buildFrontmatter
2298
+ builds: [{
2299
+ token: 260,
2300
+ build: buildYamlBlock
2439
2301
  }],
2440
2302
  starts: [{
2441
2303
  codes: [marker.charCodeAt(0)],
@@ -2450,11 +2312,48 @@ function feature$12(marker) {
2450
2312
  }]
2451
2313
  } };
2452
2314
  }
2453
- //#endregion
2454
- //#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;
2315
+ // src/profile/features/component/shared.ts
2316
+ function componentNameEnd(source, start, block) {
2317
+ let code = source.charCodeAt(start);
2318
+ if (!isAsciiLetter(code) && code !== 36) return;
2319
+ let end = start + 1;
2320
+ while (end < source.length) {
2321
+ code = source.charCodeAt(end);
2322
+ if (!isAsciiLetter(code) && !isAsciiDigit(code) && code !== 36 && code !== 95 && code !== 45 && (!block || code !== 46)) break;
2323
+ end++;
2324
+ }
2325
+ return end;
2326
+ }
2327
+ function normalizeComponentName(value) {
2328
+ let result = "";
2329
+ let partLength = 0;
2330
+ let previousUpper;
2331
+ for (let index = 0; index < value.length; index++) {
2332
+ const character = value[index];
2333
+ const code = value.charCodeAt(index);
2334
+ if (code === 45 || code === 95 || code === 47 || code === 46) {
2335
+ partLength = 0;
2336
+ previousUpper = void 0;
2337
+ continue;
2338
+ }
2339
+ const upper = isAsciiLetter(code) ? code <= 90 : void 0;
2340
+ const next = value.charCodeAt(index + 1);
2341
+ if (result && (partLength === 0 || upper === true && (previousUpper === false || next >= 97 && next <= 122))) result += "-";
2342
+ result += character;
2343
+ partLength++;
2344
+ previousUpper = upper;
2345
+ }
2346
+ return result.toLowerCase();
2347
+ }
2348
+ // src/profile/features/component/block.ts
2349
+ function closingBracket(source, start, limit) {
2350
+ let depth = 0;
2351
+ for (let offset = start + 1; offset < limit; offset++) if (source[offset] === "\\" && offset + 1 < limit) offset++;
2352
+ else if (source[offset] === "[") depth++;
2353
+ else if (source[offset] === "]") {
2354
+ if (depth === 0) return offset;
2355
+ depth--;
2356
+ }
2458
2357
  }
2459
2358
  function lineValue(source, lines, index) {
2460
2359
  const offset = lineIndentOffset(source, lines, index);
@@ -2479,7 +2378,7 @@ function slotOpeningAt(source, lines, index, contentOffset) {
2479
2378
  const nameEnd = componentNameEnd(source, contentOffset + 1, true);
2480
2379
  const lineEnd = lines.end(index);
2481
2380
  if (nameEnd === void 0 || nameEnd > lineEnd) return;
2482
- let offset = skipSpaces(source, nameEnd, lineEnd);
2381
+ let offset = skipLineWhitespace(source, nameEnd, lineEnd);
2483
2382
  let attributesStart;
2484
2383
  let parsedAttributesEnd;
2485
2384
  if (source[offset] === "{") {
@@ -2488,7 +2387,7 @@ function slotOpeningAt(source, lines, index, contentOffset) {
2488
2387
  attributesStart = offset;
2489
2388
  offset = parsedAttributesEnd;
2490
2389
  }
2491
- if (skipSpaces(source, offset, lineEnd) !== lineEnd) return;
2390
+ if (skipLineWhitespace(source, offset, lineEnd) !== lineEnd) return;
2492
2391
  return {
2493
2392
  attributesEnd: parsedAttributesEnd,
2494
2393
  attributesStart,
@@ -2502,10 +2401,10 @@ function blockOpeningAt(source, lines, index, contentOffset, shorthand) {
2502
2401
  const fenceSize = offset - contentOffset;
2503
2402
  if (shorthand ? fenceSize !== 1 : fenceSize < 2) return;
2504
2403
  const lineEnd = lines.end(index);
2505
- if (!shorthand) offset = skipSpaces(source, offset, lineEnd);
2404
+ if (!shorthand) offset = skipLineWhitespace(source, offset, lineEnd);
2506
2405
  const nameEnd = componentNameEnd(source, offset, true);
2507
2406
  if (nameEnd === void 0 || nameEnd > lineEnd) return;
2508
- offset = skipSpaces(source, nameEnd, lineEnd);
2407
+ offset = skipLineWhitespace(source, nameEnd, lineEnd);
2509
2408
  let labelStart;
2510
2409
  let labelEnd;
2511
2410
  if (source[offset] === "[") {
@@ -2513,7 +2412,7 @@ function blockOpeningAt(source, lines, index, contentOffset, shorthand) {
2513
2412
  if (close === void 0) return;
2514
2413
  labelStart = offset;
2515
2414
  labelEnd = close + 1;
2516
- offset = skipSpaces(source, labelEnd, lineEnd);
2415
+ offset = skipLineWhitespace(source, labelEnd, lineEnd);
2517
2416
  }
2518
2417
  let attributesStart;
2519
2418
  let parsedAttributesEnd;
@@ -2523,7 +2422,7 @@ function blockOpeningAt(source, lines, index, contentOffset, shorthand) {
2523
2422
  attributesStart = offset;
2524
2423
  offset = parsedAttributesEnd;
2525
2424
  }
2526
- if (skipSpaces(source, offset, lineEnd) !== lineEnd) return;
2425
+ if (skipLineWhitespace(source, offset, lineEnd) !== lineEnd) return;
2527
2426
  return {
2528
2427
  attributesEnd: parsedAttributesEnd,
2529
2428
  attributesStart,
@@ -2533,13 +2432,6 @@ function blockOpeningAt(source, lines, index, contentOffset, shorthand) {
2533
2432
  nameEnd
2534
2433
  };
2535
2434
  }
2536
- function fenceAt(source, lines, index, size, contentOffset) {
2537
- let offset = contentOffset;
2538
- while (source[offset] === ":") offset++;
2539
- const lineEnd = lines.end(index);
2540
- if (offset - contentOffset !== size || skipSpaces(source, offset, lineEnd) !== lineEnd) return;
2541
- return contentOffset;
2542
- }
2543
2435
  function blockClose(source, lines, start, opening) {
2544
2436
  let codeFence;
2545
2437
  let depth = 0;
@@ -2552,11 +2444,12 @@ function blockClose(source, lines, start, opening) {
2552
2444
  if (contentOffset < 0) continue;
2553
2445
  codeFence = codeFenceAt(source, lines, index, contentOffset);
2554
2446
  if (codeFence) continue;
2555
- const closeOffset = fenceAt(source, lines, index, opening.fenceSize, contentOffset);
2556
- if (closeOffset !== void 0) {
2447
+ let markerEnd = contentOffset;
2448
+ while (source[markerEnd] === ":") markerEnd++;
2449
+ if (markerEnd - contentOffset === opening.fenceSize && skipLineWhitespace(source, markerEnd, lines.end(index)) === lines.end(index)) {
2557
2450
  if (depth === 0) return {
2558
2451
  index,
2559
- offset: closeOffset
2452
+ offset: contentOffset
2560
2453
  };
2561
2454
  depth--;
2562
2455
  continue;
@@ -2584,10 +2477,6 @@ function nextSlot(source, lines, start, end) {
2584
2477
  if (nested) index = blockClose(source, lines, index, nested)?.index ?? index;
2585
2478
  }
2586
2479
  }
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
2480
  function emitComponentBody(source, lines, start, end, closingOffset, out, context) {
2592
2481
  let cursor = start;
2593
2482
  const yamlEnd = cursor < end ? yamlPropsEnd(source, lines, cursor, end) : void 0;
@@ -2604,7 +2493,9 @@ function emitComponentBody(source, lines, start, end, closingOffset, out, contex
2604
2493
  while (slot) {
2605
2494
  const following = nextSlot(source, lines, slot.index + 1, end);
2606
2495
  const next = following?.index ?? end;
2607
- emitSlotOpening(slot.opening, out);
2496
+ const opening = slot.opening;
2497
+ out.push(71, opening.offset, opening.nameEnd);
2498
+ if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(3, opening.attributesStart, opening.attributesEnd);
2608
2499
  context.scanLines(source, lines.slice(slot.index + 1, next), out);
2609
2500
  const slotEnd = following ? following.opening.offset : closingOffset;
2610
2501
  out.push(204, slotEnd, slotEnd);
@@ -2612,9 +2503,9 @@ function emitComponentBody(source, lines, start, end, closingOffset, out, contex
2612
2503
  }
2613
2504
  }
2614
2505
  function emitOpening(contentOffset, opening, out) {
2615
- out.push(74, contentOffset, opening.nameEnd);
2506
+ out.push(70, contentOffset, opening.nameEnd);
2616
2507
  if (opening.labelStart !== void 0 && opening.labelEnd !== void 0) {
2617
- out.push(133, opening.labelStart, opening.labelStart + 1);
2508
+ out.push(161, opening.labelStart, opening.labelStart + 1);
2618
2509
  if (opening.labelEnd > opening.labelStart + 2) out.push(1, opening.labelStart + 1, opening.labelEnd - 1);
2619
2510
  out.push(203, opening.labelEnd - 1, opening.labelEnd);
2620
2511
  }
@@ -2626,7 +2517,7 @@ const buildBlockLabel = (tokenStart, context) => {
2626
2517
  const start = context.locator.locationAt(tokens.start(tokenStart));
2627
2518
  return {
2628
2519
  type: "paragraph",
2629
- children: buildInlineFragment(tokenStart, 20, context).children,
2520
+ children: buildInlineFragment(tokenStart, false, context).children,
2630
2521
  position: {
2631
2522
  start,
2632
2523
  end: context.locator.locationAt(tokens.end(close))
@@ -2654,47 +2545,29 @@ function createBlockStart(shorthand) {
2654
2545
  return closing.index + 1;
2655
2546
  };
2656
2547
  }
2657
- const blockRules$2 = [
2658
- {
2659
- rule: 21,
2660
- syntax: {
2661
- kind: "leaf",
2662
- token: 262
2663
- },
2664
- build: buildFrontmatter
2665
- },
2548
+ const blockBuilds$2 = [
2666
2549
  {
2667
- rule: 20,
2668
- syntax: {
2669
- kind: "frame",
2670
- token: 133
2671
- },
2672
- inlineContent: true,
2673
- build: buildBlockLabel
2550
+ token: 262,
2551
+ build: buildYamlBlock
2674
2552
  },
2675
2553
  {
2676
- rule: 19,
2677
- syntax: {
2678
- kind: "block",
2679
- token: 74
2680
- },
2554
+ token: 70,
2681
2555
  build(tokenStart, context) {
2682
2556
  const tokens = context.structure.tokens;
2683
2557
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
2684
2558
  let openingToken = tokenStart + 1;
2685
- const label = tokens.kind(openingToken) === 133 ? openingToken : void 0;
2559
+ const label = tokens.kind(openingToken) === 161 ? openingToken : void 0;
2686
2560
  if (label !== void 0) openingToken += tokens.nodeLength(label);
2687
2561
  const attributesToken = tokens.kind(openingToken) === 3 ? openingToken++ : void 0;
2688
2562
  const parsed = attributesToken !== void 0 ? parseAttributes(context.source, tokens.start(attributesToken)) : void 0;
2689
2563
  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));
2564
+ let children = buildBlockChildren(tokenStart, context);
2565
+ if (label) children = [buildBlockLabel(label, context), ...children];
2693
2566
  const opening = tokens.text(context.source, tokenStart);
2694
2567
  return {
2695
2568
  type: "blockComponent",
2696
2569
  name: normalizeComponentName(opening.slice(opening.lastIndexOf(":") + 1).trim()),
2697
- attributes: parsed?.attributes ?? {},
2570
+ attributes: parsed ?? {},
2698
2571
  position: {
2699
2572
  start,
2700
2573
  end: context.locator.locationAt(tokens.end(close))
@@ -2704,11 +2577,7 @@ const blockRules$2 = [
2704
2577
  }
2705
2578
  },
2706
2579
  {
2707
- rule: 22,
2708
- syntax: {
2709
- kind: "block",
2710
- token: 75
2711
- },
2580
+ token: 71,
2712
2581
  build(tokenStart, context) {
2713
2582
  const tokens = context.structure.tokens;
2714
2583
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
@@ -2720,7 +2589,7 @@ const blockRules$2 = [
2720
2589
  type: "blockComponent",
2721
2590
  name: "template",
2722
2591
  attributes: {
2723
- ...parsed?.attributes,
2592
+ ...parsed,
2724
2593
  name: normalizeComponentName(tokens.text(context.source, tokenStart).slice(1).trim())
2725
2594
  },
2726
2595
  children,
@@ -2742,18 +2611,11 @@ const blockStarts$2 = [{
2742
2611
  codes: [58],
2743
2612
  start: createBlockStart(true)
2744
2613
  }];
2745
- //#endregion
2746
- //#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
- }
2614
+ // src/profile/features/component/inline.ts
2753
2615
  const inlineScans = [{
2754
2616
  marker: 58,
2755
2617
  scan(source, start, tokens) {
2756
- const end = canStartInlineColon(source, start) ? componentNameEnd(source, start + 1, false) : void 0;
2618
+ const end = hasInlineColonBoundary(source, start) ? componentNameEnd(source, start + 1, false) : void 0;
2757
2619
  if (end === void 0) return -1;
2758
2620
  appendInlineToken(tokens, 137, start, end);
2759
2621
  return end;
@@ -2769,16 +2631,15 @@ const buildInlineComponent = (open, close, sourceSpan, children, context) => {
2769
2631
  position: sourceSpan
2770
2632
  };
2771
2633
  };
2772
- //#endregion
2773
- //#region src/profile/features/component/index.ts
2774
- const feature$11 = {
2634
+ // src/profile/features/component/index.ts
2635
+ const feature$12 = {
2775
2636
  block: {
2776
- rules: blockRules$2,
2637
+ builds: blockBuilds$2,
2777
2638
  starts: blockStarts$2
2778
2639
  },
2779
2640
  inline: {
2780
- scan: inlineScans,
2781
- build: [
2641
+ scans: inlineScans,
2642
+ builds: [
2782
2643
  {
2783
2644
  kind: "leaf",
2784
2645
  token: 137,
@@ -2807,16 +2668,15 @@ const feature$11 = {
2807
2668
  ]
2808
2669
  }
2809
2670
  };
2810
- //#endregion
2811
- //#region src/profile/features/emoji/index.ts
2671
+ // src/profile/features/emoji/index.ts
2812
2672
  function isShortcodeCharacter(code) {
2813
- return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 43 || code === 45 || code === 95;
2673
+ return isAsciiLetter(code) || isAsciiDigit(code) || code === 43 || code === 45 || code === 95;
2814
2674
  }
2815
- const feature$10 = { inline: {
2816
- scan: [{
2675
+ const feature$11 = { inline: {
2676
+ scans: [{
2817
2677
  marker: 58,
2818
2678
  scan(source, start, tokens) {
2819
- if (!canStartInlineColon(source, start)) return -1;
2679
+ if (!hasInlineColonBoundary(source, start)) return -1;
2820
2680
  let end = start + 1;
2821
2681
  while (isShortcodeCharacter(source.charCodeAt(end))) end++;
2822
2682
  if (end === start + 1 || source.charCodeAt(end) !== 58) return -1;
@@ -2825,7 +2685,7 @@ const feature$10 = { inline: {
2825
2685
  return end;
2826
2686
  }
2827
2687
  }],
2828
- build: [{
2688
+ builds: [{
2829
2689
  kind: "leaf",
2830
2690
  token: 136,
2831
2691
  build(tokenIndex, sourceSpan, context) {
@@ -2837,30 +2697,8 @@ const feature$10 = { inline: {
2837
2697
  }
2838
2698
  }]
2839
2699
  } };
2840
- //#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
- //#region src/profile/features/footnote/shared.ts
2700
+ // src/profile/features/footnote/shared.ts
2860
2701
  const footnoteDefinitionPrefix = "footnote\0";
2861
- function isLabelWhitespace(code) {
2862
- return code === 32 || code === 9 || code === 10 || code === 13;
2863
- }
2864
2702
  function footnoteLabelAt(source, start, limit) {
2865
2703
  if (source.charCodeAt(start) !== 91 || source.charCodeAt(start + 1) !== 94) return;
2866
2704
  const labelStart = start + 2;
@@ -2868,15 +2706,15 @@ function footnoteLabelAt(source, start, limit) {
2868
2706
  let length = 0;
2869
2707
  while (offset < limit) {
2870
2708
  const code = source.charCodeAt(offset);
2871
- if (isLabelWhitespace(code)) return;
2709
+ if (isMarkdownWhitespace(code)) return;
2872
2710
  if (code === 92 && offset + 1 < limit) {
2873
- if (isLabelWhitespace(source.charCodeAt(offset + 1))) return;
2711
+ if (isMarkdownWhitespace(source.charCodeAt(offset + 1))) return;
2874
2712
  offset += 2;
2875
2713
  length += 2;
2876
2714
  } else if (code === 93) {
2877
2715
  if (length === 0) return;
2878
2716
  const label = source.slice(labelStart, offset);
2879
- const normalizedLabel = normalizeAssociationLabel(label);
2717
+ const normalizedLabel = normalizeIdentifier(label);
2880
2718
  return {
2881
2719
  definitionKey: footnoteDefinitionPrefix + normalizedLabel,
2882
2720
  end: offset + 1,
@@ -2891,43 +2729,27 @@ function footnoteLabelAt(source, start, limit) {
2891
2729
  if (length > 999) return;
2892
2730
  }
2893
2731
  }
2894
- //#endregion
2895
- //#region src/profile/features/footnote/block.ts
2732
+ // src/profile/features/footnote/block.ts
2896
2733
  function definitionAt(source, lines, index, markerStart) {
2897
2734
  const lineEnd = lines.end(index);
2898
2735
  const label = footnoteLabelAt(source, markerStart, lineEnd);
2899
2736
  if (!label || source.charCodeAt(label.end) !== 58) return;
2900
2737
  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
- }
2738
+ const contentOffset = skipLineWhitespace(source, markerEnd, lineEnd);
2907
2739
  return {
2908
2740
  ...label,
2909
2741
  contentOffset,
2910
2742
  markerEnd
2911
2743
  };
2912
2744
  }
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
- //#endregion
2919
- //#region src/profile/features/footnote/index.ts
2920
- const feature$9 = {
2745
+ // src/profile/features/footnote/index.ts
2746
+ const feature$10 = {
2921
2747
  block: {
2922
- rules: [{
2923
- rule: 12,
2924
- syntax: {
2925
- kind: "block",
2926
- token: 72
2927
- },
2748
+ builds: [{
2749
+ token: 68,
2928
2750
  build(tokenStart, context) {
2929
2751
  const tokens = context.structure.tokens;
2930
- const fields = definitionFields(tokens, tokenStart);
2752
+ const fields = tokens.value(tokenStart);
2931
2753
  const start = context.locator.locationAt(tokens.start(tokenStart));
2932
2754
  const children = buildBlockChildren(tokenStart, context);
2933
2755
  return {
@@ -2956,8 +2778,7 @@ const feature$9 = {
2956
2778
  start(source, lines, start, contentOffset, out, context) {
2957
2779
  const match = definitionAt(source, lines, start, contentOffset);
2958
2780
  if (!match) return;
2959
- const definitionLines = new BlockLines();
2960
- definitionLines.pushFrom(lines, start, match.contentOffset, 0);
2781
+ const definitionLines = context.createLineView(lines, start, match.contentOffset, 0);
2961
2782
  let index = start + 1;
2962
2783
  let lazyParagraph = context.endsWithParagraphLeaf(source, definitionLines, 0);
2963
2784
  while (index < lines.length) {
@@ -2977,8 +2798,8 @@ const feature$9 = {
2977
2798
  definitionLines.pushLazy(lines, index);
2978
2799
  index++;
2979
2800
  }
2980
- while (definitionLines.length > 0 && isBlank(source, definitionLines, definitionLines.length - 1)) definitionLines.pop();
2981
- out.push(72, contentOffset, match.markerEnd, {
2801
+ while (definitionLines.length > 0 && isBlankLine(source, definitionLines, definitionLines.length - 1)) definitionLines.pop();
2802
+ out.push(68, contentOffset, match.markerEnd, {
2982
2803
  definitionKey: match.definitionKey,
2983
2804
  value: {
2984
2805
  label: match.label,
@@ -2992,22 +2813,72 @@ const feature$9 = {
2992
2813
  }
2993
2814
  }]
2994
2815
  },
2995
- inline: { build: [{
2816
+ inline: { builds: [{
2996
2817
  kind: "leaf",
2997
2818
  token: 133,
2998
2819
  build(tokenIndex, sourceSpan, context) {
2999
- const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(2, -1);
2820
+ const label = inlineTokenText(context.view.text, context.tokens, tokenIndex, 2, 1);
3000
2821
  return {
3001
2822
  type: "footnoteReference",
3002
- identifier: normalizeAssociationLabel(label),
2823
+ identifier: normalizeIdentifier(label),
3003
2824
  label: semanticText(label),
3004
2825
  position: sourceSpan
3005
2826
  };
3006
2827
  }
3007
2828
  }] }
3008
2829
  };
3009
- //#endregion
3010
- //#region src/profile/features/formatting.ts
2830
+ // src/profile/features/text.ts
2831
+ const entity = /&(?:#x[0-9A-F]{1,6}|#\d{1,7}|[A-Z][A-Z0-9]{0,30});/iy;
2832
+ const buildInlineText = (tokenIndex, context) => {
2833
+ return inlineTokenText(context.view.text, context.tokens, tokenIndex);
2834
+ };
2835
+ const buildDecodedInlineText = (tokenIndex, context) => {
2836
+ return semanticText(inlineTokenText(context.view.text, context.tokens, tokenIndex));
2837
+ };
2838
+ const feature$9 = { inline: {
2839
+ scans: [{
2840
+ marker: 38,
2841
+ scan(source, start, tokens) {
2842
+ const matchEnd = matchInlinePatternEnd(entity, source, start);
2843
+ if (matchEnd < 0) return start + 1;
2844
+ appendInlineToken(tokens, 66, start, matchEnd);
2845
+ return matchEnd;
2846
+ }
2847
+ }, {
2848
+ marker: 92,
2849
+ scan(source, start, tokens) {
2850
+ const next = source.charCodeAt(start + 1);
2851
+ if (next === 10 || next === 13) {
2852
+ appendInlineToken(tokens, 128, start, start + 1);
2853
+ return start + 1;
2854
+ }
2855
+ if (isAsciiPunctuation(next)) {
2856
+ const end = start + 2;
2857
+ appendInlineToken(tokens, 65, start, end);
2858
+ return end;
2859
+ }
2860
+ return start + (next === 32 || next === 9 ? 2 : 1);
2861
+ }
2862
+ }],
2863
+ builds: [
2864
+ {
2865
+ kind: "text",
2866
+ token: 64,
2867
+ build: buildInlineText
2868
+ },
2869
+ {
2870
+ kind: "text",
2871
+ token: 65,
2872
+ build: buildDecodedInlineText
2873
+ },
2874
+ {
2875
+ kind: "text",
2876
+ token: 66,
2877
+ build: buildDecodedInlineText
2878
+ }
2879
+ ]
2880
+ } };
2881
+ // src/profile/features/formatting.ts
3011
2882
  const scanFormatting = (source, start, tokens) => {
3012
2883
  const code = source.charCodeAt(start);
3013
2884
  const end = inlineMarkerRunEnd(source, start);
@@ -3095,13 +2966,12 @@ function feature$8(strikethroughOptions) {
3095
2966
  });
3096
2967
  }
3097
2968
  return { inline: {
3098
- scan: scans,
2969
+ scans,
3099
2970
  delimiters,
3100
- build: builds
2971
+ builds
3101
2972
  } };
3102
2973
  }
3103
- //#endregion
3104
- //#region src/fragment/node.ts
2974
+ // src/fragment/node.ts
3105
2975
  function cloneLocation(location) {
3106
2976
  return {
3107
2977
  line: location.line,
@@ -3117,15 +2987,13 @@ function lastChildEnd(children) {
3117
2987
  const last = children.at(-1);
3118
2988
  return last ? cloneLocation(last.position.end) : void 0;
3119
2989
  }
3120
- //#endregion
3121
- //#region src/profile/features/heading.ts
2990
+ // src/profile/features/heading.ts
3122
2991
  function atxAt(source, lines, index, markerOffset) {
3123
2992
  let markerEnd = markerOffset + 1;
3124
2993
  const lineEnd = lines.end(index);
3125
2994
  while (markerEnd < lineEnd && markerEnd - markerOffset < 6 && source[markerEnd] === "#") markerEnd++;
3126
2995
  if (markerEnd < lineEnd && source[markerEnd] !== " " && source[markerEnd] !== " ") return;
3127
- let contentOffset = markerEnd;
3128
- while (contentOffset < lineEnd && (source[contentOffset] === " " || source[contentOffset] === " ")) contentOffset++;
2996
+ const contentOffset = skipLineWhitespace(source, markerEnd, lineEnd);
3129
2997
  let contentEnd = lineEnd;
3130
2998
  while (contentEnd > contentOffset && (source[contentEnd - 1] === " " || source[contentEnd - 1] === " ")) contentEnd--;
3131
2999
  let closer = contentEnd;
@@ -3141,27 +3009,21 @@ function atxAt(source, lines, index, markerOffset) {
3141
3009
  };
3142
3010
  }
3143
3011
  function setextMarkerAt(source, lines, index, markerOffset) {
3144
- if (markerOffset < 0) return;
3145
3012
  const marker = source[markerOffset];
3146
3013
  if (marker !== "=" && marker !== "-") return;
3147
3014
  const lineEnd = lines.end(index);
3148
3015
  let offset = markerOffset + 1;
3149
3016
  while (offset < lineEnd && source[offset] === marker) offset++;
3150
- while (offset < lineEnd && (source[offset] === " " || source[offset] === " ")) offset++;
3017
+ offset = skipLineWhitespace(source, offset, lineEnd);
3151
3018
  return offset === lineEnd ? marker : void 0;
3152
3019
  }
3153
3020
  const feature$7 = { block: {
3154
- rules: [{
3155
- rule: 2,
3156
- syntax: {
3157
- kind: "block",
3158
- token: 65
3159
- },
3160
- inlineContent: true,
3021
+ builds: [{
3022
+ token: 96,
3161
3023
  build(tokenStart, context) {
3162
3024
  const tokens = context.structure.tokens;
3163
3025
  const start = context.locator.locationAt(tokens.start(tokenStart));
3164
- const inline = buildInlineFragment(tokenStart, 2, context);
3026
+ const inline = buildInlineFragment(tokenStart, false, context);
3165
3027
  const result = {
3166
3028
  type: "heading",
3167
3029
  depth: tokens.end(tokenStart) - tokens.start(tokenStart),
@@ -3175,19 +3037,14 @@ const feature$7 = { block: {
3175
3037
  return result;
3176
3038
  }
3177
3039
  }, {
3178
- rule: 3,
3179
- syntax: {
3180
- kind: "block",
3181
- token: [66, 67]
3182
- },
3183
- inlineContent: true,
3040
+ token: [97, 98],
3184
3041
  build(tokenStart, context) {
3185
3042
  const tokens = context.structure.tokens;
3186
- const inline = buildInlineFragment(tokenStart, 3, context);
3043
+ const inline = buildInlineFragment(tokenStart, false, context);
3187
3044
  const children = inline.children;
3188
3045
  const result = {
3189
3046
  type: "heading",
3190
- depth: tokens.kind(tokenStart) === 66 ? 1 : 2,
3047
+ depth: tokens.kind(tokenStart) === 97 ? 1 : 2,
3191
3048
  children,
3192
3049
  position: {
3193
3050
  start: firstChildStart(children),
@@ -3206,7 +3063,7 @@ const feature$7 = { block: {
3206
3063
  start(source, lines, start, contentOffset, out) {
3207
3064
  const atx = atxAt(source, lines, start, contentOffset);
3208
3065
  if (!atx) return;
3209
- out.push(65, contentOffset, atx.markerEnd);
3066
+ out.push(96, contentOffset, atx.markerEnd);
3210
3067
  if (atx.contentEnd > atx.contentOffset) out.push(1, atx.contentOffset, atx.contentEnd);
3211
3068
  const lineEnd = lines.end(start);
3212
3069
  out.push(193, lineEnd, lineEnd);
@@ -3214,8 +3071,7 @@ const feature$7 = { block: {
3214
3071
  }
3215
3072
  }]
3216
3073
  } };
3217
- //#endregion
3218
- //#region src/profile/features/html.ts
3074
+ // src/profile/features/html.ts
3219
3075
  const htmlBlockTags = new Set(htmlBlockNames);
3220
3076
  const htmlTagName = "[a-z][a-z0-9-]*";
3221
3077
  const completeHtmlTag = new RegExp(`^(?:<${htmlTagName}(?:\\s+[a-z_:][\\w.:-]*(?:\\s*=\\s*(?:[^\\s"'=<>\`]+|'[^']*'|"[^"]*"))?)*\\s*/?>|</${htmlTagName}\\s*>)[ \\t]*$`, "i");
@@ -3224,27 +3080,30 @@ const autolink = /<(?:[A-Z][A-Z0-9+.\-]{1,31}:[^ \t\n\r<>]+|[\w!#$%&'*+\-/=?^`{|
3224
3080
  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
3081
  function htmlStartAt(source, lines, index, contentOffset) {
3226
3082
  const body = source.slice(contentOffset, lines.end(index));
3083
+ switch (body.charCodeAt(1)) {
3084
+ case 63: return {
3085
+ interruptParagraph: true,
3086
+ terminator: "?>"
3087
+ };
3088
+ case 33:
3089
+ if (body.startsWith("<!--")) return {
3090
+ interruptParagraph: true,
3091
+ terminator: "-->"
3092
+ };
3093
+ if (body.startsWith("<![CDATA[")) return {
3094
+ interruptParagraph: true,
3095
+ terminator: "]]>"
3096
+ };
3097
+ if (/[A-Z]/.test(body[2] ?? "")) return {
3098
+ interruptParagraph: true,
3099
+ terminator: ">"
3100
+ };
3101
+ }
3227
3102
  const lower = body.toLowerCase();
3228
3103
  for (const tag of htmlRawNames) if (lower.startsWith(`<${tag}`) && (lower.length === tag.length + 1 || /[ \t>]/.test(lower[tag.length + 1]))) return {
3229
3104
  interruptParagraph: true,
3230
3105
  terminator: `</${tag}>`
3231
3106
  };
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
3107
  const tag = /^<\/?([a-z][a-z0-9-]*)(?=[ \t\n\r/>]|$)/i.exec(body)?.[1].toLowerCase();
3249
3108
  if (tag && htmlBlockTags.has(tag)) return { interruptParagraph: true };
3250
3109
  if (completeHtmlTag.test(body)) return { interruptParagraph: false };
@@ -3258,18 +3117,13 @@ const buildInlineHtml = (tokenIndex, sourceSpan, context) => {
3258
3117
  };
3259
3118
  const feature$6 = {
3260
3119
  block: {
3261
- rules: [{
3262
- rule: 10,
3263
- syntax: {
3264
- kind: "leaf",
3265
- token: 259
3266
- },
3120
+ builds: [{
3121
+ token: 259,
3267
3122
  build(tokenStart, context) {
3268
3123
  const tokens = context.structure.tokens;
3269
3124
  const offset = tokens.start(tokenStart);
3270
3125
  const end = tokens.end(tokenStart);
3271
3126
  const unterminated = tokens.value(tokenStart);
3272
- if (tokens.kind(tokenStart) !== 259 || unterminated === void 0) throw new Error("HTML block lacks termination state");
3273
3127
  let html = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
3274
3128
  if (!unterminated && html.endsWith("\n")) html = html.slice(0, -1);
3275
3129
  return {
@@ -3287,20 +3141,23 @@ const feature$6 = {
3287
3141
  start(source, lines, start, contentOffset, out) {
3288
3142
  const htmlStart = htmlStartAt(source, lines, start, contentOffset);
3289
3143
  if (!htmlStart) return;
3290
- let end = start + 1;
3144
+ let end = start;
3291
3145
  let unterminated = false;
3292
- if (htmlStart.terminator && !source.slice(lines.start(start), lines.end(start)).toLowerCase().includes(htmlStart.terminator)) {
3146
+ if (htmlStart.terminator) {
3293
3147
  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++;
3148
+ if (end === lines.length) unterminated = true;
3149
+ else end++;
3150
+ } else {
3151
+ end++;
3152
+ while (end < lines.length && !isBlankLine(source, lines, end)) end++;
3153
+ }
3297
3154
  appendLogicalToken(out, 259, source, lines, start, end, unterminated);
3298
3155
  return end;
3299
3156
  }
3300
3157
  }]
3301
3158
  },
3302
3159
  inline: {
3303
- scan: [{
3160
+ scans: [{
3304
3161
  marker: 60,
3305
3162
  scan(source, start, tokens) {
3306
3163
  let end = matchInlinePatternEnd(htmlComment, source, start);
@@ -3318,7 +3175,7 @@ const feature$6 = {
3318
3175
  return end;
3319
3176
  }
3320
3177
  }],
3321
- build: [{
3178
+ builds: [{
3322
3179
  kind: "leaf",
3323
3180
  token: 131,
3324
3181
  build: buildInlineHtml
@@ -3329,13 +3186,11 @@ const feature$6 = {
3329
3186
  }]
3330
3187
  }
3331
3188
  };
3332
- //#endregion
3333
- //#region src/profile/features/link.ts
3189
+ // src/profile/features/link.ts
3334
3190
  function skipWhitespace(source, start) {
3335
3191
  let end = start;
3336
3192
  while (end < source.length) {
3337
- const code = source.charCodeAt(end);
3338
- if (code !== 9 && code !== 10 && code !== 13 && code !== 32) break;
3193
+ if (!isMarkdownWhitespace(source.charCodeAt(end))) break;
3339
3194
  end++;
3340
3195
  }
3341
3196
  return end;
@@ -3376,7 +3231,7 @@ function linkDestinationEnd(source, start) {
3376
3231
  end++;
3377
3232
  continue;
3378
3233
  }
3379
- if (isLinkWhitespace(code)) break;
3234
+ if (isMarkdownWhitespace(code)) break;
3380
3235
  consumed = true;
3381
3236
  end++;
3382
3237
  }
@@ -3422,16 +3277,13 @@ function scanLinkTail(source, start, tokens) {
3422
3277
  appendInlineToken(tokens, 73, start, end, destinationEnd - start);
3423
3278
  return end;
3424
3279
  }
3425
- function isLinkWhitespace(code) {
3426
- return code === 9 || code === 10 || code === 13 || code === 32;
3427
- }
3428
3280
  function resourceAt(source, tokens, tokenIndex) {
3429
3281
  const tokenStart = inlineTokenStart(tokens, tokenIndex);
3430
3282
  const tokenEnd = inlineTokenEnd(tokens, tokenIndex);
3431
3283
  let start = tokenStart + 2;
3432
3284
  let end = tokenEnd - 1;
3433
- while (start < end && isLinkWhitespace(source.charCodeAt(start))) start++;
3434
- while (end > start && isLinkWhitespace(source.charCodeAt(end - 1))) end--;
3285
+ while (start < end && isMarkdownWhitespace(source.charCodeAt(start))) start++;
3286
+ while (end > start && isMarkdownWhitespace(source.charCodeAt(end - 1))) end--;
3435
3287
  if (start === end) return {
3436
3288
  url: "",
3437
3289
  title: null
@@ -3444,7 +3296,7 @@ function resourceAt(source, tokens, tokenIndex) {
3444
3296
  destinationEnd--;
3445
3297
  }
3446
3298
  start = resourceEnd;
3447
- while (start < end && isLinkWhitespace(source.charCodeAt(start))) start++;
3299
+ while (start < end && isMarkdownWhitespace(source.charCodeAt(start))) start++;
3448
3300
  return {
3449
3301
  url: semanticText(source.slice(destinationStart, destinationEnd)),
3450
3302
  title: start < end ? semanticText(source.slice(start + 1, end - 1)) : null
@@ -3452,12 +3304,10 @@ function resourceAt(source, tokens, tokenIndex) {
3452
3304
  }
3453
3305
  function reference(close, syntaxStart, syntaxEnd, context, image) {
3454
3306
  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
3307
  const full = closeText.startsWith("][") && closeText !== "][]";
3458
- const labelSource = full ? closeText.slice(2, -1) : content;
3308
+ const labelSource = full ? closeText.slice(2, -1) : context.view.text.slice(syntaxStart + (image ? 2 : 1), syntaxEnd - closeText.length);
3459
3309
  return {
3460
- identifier: normalizeAssociationLabel(labelSource),
3310
+ identifier: normalizeIdentifier(labelSource),
3461
3311
  label: semanticText(labelSource),
3462
3312
  referenceType: full ? "full" : closeText === "][]" ? "collapsed" : "shortcut"
3463
3313
  };
@@ -3507,7 +3357,7 @@ const buildInlineReferenceImage = createBuildMedia("image", "reference");
3507
3357
  const buildInlineLink = createBuildMedia("link", "direct");
3508
3358
  const buildInlineReferenceLink = createBuildMedia("link", "reference");
3509
3359
  const feature$5 = { inline: {
3510
- scan: [
3360
+ scans: [
3511
3361
  {
3512
3362
  marker: 33,
3513
3363
  scan(source, start, tokens) {
@@ -3535,7 +3385,7 @@ const feature$5 = { inline: {
3535
3385
  }
3536
3386
  }
3537
3387
  ],
3538
- build: [
3388
+ builds: [
3539
3389
  {
3540
3390
  kind: "pair",
3541
3391
  token: 198,
@@ -3560,7 +3410,7 @@ const feature$5 = { inline: {
3560
3410
  kind: "leaf",
3561
3411
  token: 132,
3562
3412
  build(tokenIndex, sourceSpan, context) {
3563
- const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(1, -1);
3413
+ const label = inlineTokenText(context.view.text, context.tokens, tokenIndex, 1);
3564
3414
  return {
3565
3415
  type: "link",
3566
3416
  url: label.includes(":") ? label : `mailto:${label}`,
@@ -3607,97 +3457,69 @@ const feature$5 = { inline: {
3607
3457
  }
3608
3458
  ]
3609
3459
  } };
3610
- //#endregion
3611
- //#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
- }
3460
+ // src/profile/features/list.ts
3645
3461
  function listMarkerAt(source, lines, index, contentOffset) {
3646
3462
  if (contentOffset < 0) return;
3647
3463
  const indent = lines.prefixColumns(index) + contentOffset - lines.start(index);
3648
3464
  const marker = source.charCodeAt(contentOffset);
3649
- const markerEnd = contentOffset + 1;
3650
3465
  const lineEnd = lines.end(index);
3466
+ let delimiter;
3467
+ let markerEnd = contentOffset + 1;
3468
+ let startNumber = 0;
3651
3469
  if (marker === 45 || marker === 43 || marker === 42) {
3652
3470
  const following = source.charCodeAt(markerEnd);
3653
3471
  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
- };
3472
+ delimiter = marker;
3473
+ } else {
3474
+ if (marker < 48 || marker > 57) return;
3475
+ let orderedEnd = contentOffset;
3476
+ while (orderedEnd < lineEnd && orderedEnd - contentOffset < 9) {
3477
+ const digit = source.charCodeAt(orderedEnd) - 48;
3478
+ if (digit < 0 || digit > 9) break;
3479
+ startNumber = startNumber * 10 + digit;
3480
+ orderedEnd++;
3481
+ }
3482
+ delimiter = source.charCodeAt(orderedEnd);
3483
+ if (delimiter !== 46 && delimiter !== 41) return;
3484
+ if (orderedEnd + 1 < lineEnd) {
3485
+ const code = source.charCodeAt(orderedEnd + 1);
3486
+ if (code !== 32 && code !== 9) return;
3487
+ }
3488
+ markerEnd = orderedEnd + 1;
3489
+ }
3490
+ const markerColumn = indent + markerEnd - contentOffset;
3491
+ let contentIndent = markerColumn + 1;
3492
+ let contentStart = markerEnd;
3493
+ let hasContent = false;
3494
+ let prefixColumns = 0;
3495
+ if (markerEnd < lineEnd) {
3496
+ let column = markerColumn;
3497
+ while (contentStart < lineEnd) {
3498
+ const code = source.charCodeAt(contentStart);
3499
+ if (code === 32) column++;
3500
+ else if (code === 9) column += 4 - column % 4;
3501
+ else break;
3502
+ contentStart++;
3503
+ }
3504
+ hasContent = contentStart < lineEnd;
3505
+ if (hasContent && column - markerColumn <= 4) contentIndent = column;
3506
+ else {
3507
+ const firstPaddingColumns = source.charCodeAt(markerEnd) === 9 ? 4 - markerColumn % 4 : 1;
3508
+ contentStart = markerEnd + 1;
3509
+ prefixColumns = firstPaddingColumns - 1;
3510
+ }
3666
3511
  }
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
3512
  return {
3686
- kind: "ordered",
3687
- indent,
3688
3513
  offset: contentOffset,
3689
- end: orderedEnd,
3690
- hasContent: padding.hasContent,
3691
- contentOffset: padding.offset,
3692
- contentIndent: indent + markerWidth + padding.columns,
3693
- contentPrefixColumns: padding.prefixColumns,
3514
+ end: markerEnd,
3515
+ hasContent,
3516
+ contentOffset: contentStart,
3517
+ contentIndent,
3518
+ contentPrefixColumns: prefixColumns,
3694
3519
  delimiter,
3695
3520
  startNumber
3696
3521
  };
3697
3522
  }
3698
- function sameList(a, b) {
3699
- return a.kind === b.kind && a.delimiter === b.delimiter;
3700
- }
3701
3523
  function isTaskListWhitespace(code) {
3702
3524
  return code === 32 || code >= 9 && code <= 13;
3703
3525
  }
@@ -3745,10 +3567,9 @@ const buildListItem = (tokenStart, context) => {
3745
3567
  function createBuildList(ordered) {
3746
3568
  return (tokenStart, context) => {
3747
3569
  const tokens = context.structure.tokens;
3748
- const start = context.locator.locationAt(tokens.start(tokenStart));
3749
3570
  const items = [];
3750
3571
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
3751
- for (let child = tokenStart + 1; child < close; child += tokens.nodeLength(child)) items.push(buildBlockNode(child, context));
3572
+ for (let child = tokenStart + 1; child < close; child += tokens.nodeLength(child)) items.push(buildListItem(child, context));
3752
3573
  return {
3753
3574
  type: "list",
3754
3575
  ordered,
@@ -3756,8 +3577,8 @@ function createBuildList(ordered) {
3756
3577
  spread: tokens.value(close) === true,
3757
3578
  children: items,
3758
3579
  position: {
3759
- start,
3760
- end: lastChildEnd(items) ?? context.locator.locationAt(tokens.end(tokenStart))
3580
+ start: firstChildStart(items),
3581
+ end: lastChildEnd(items)
3761
3582
  }
3762
3583
  };
3763
3584
  };
@@ -3765,22 +3586,21 @@ function createBuildList(ordered) {
3765
3586
  const listStart = (source, lines, start, contentOffset, out, context) => {
3766
3587
  let marker = listMarkerAt(source, lines, start, contentOffset);
3767
3588
  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);
3589
+ const delimiter = marker.delimiter;
3590
+ const ordered = delimiter === 46 || delimiter === 41;
3591
+ const listOpen = ordered ? 66 : 65;
3592
+ const listClose = ordered ? 196 : 195;
3593
+ out.push(listOpen, marker.offset, marker.end, ordered ? { value: marker.startNumber } : void 0);
3773
3594
  let index = start;
3774
- let listEnd = listMarker.end;
3595
+ let listEnd = marker.end;
3775
3596
  let listSpread = false;
3776
3597
  let trailingBlank = false;
3777
- while (marker && sameList(marker, listMarker)) {
3598
+ while (marker?.delimiter === delimiter) {
3778
3599
  let sibling;
3779
3600
  listSpread ||= trailingBlank;
3780
3601
  trailingBlank = false;
3781
3602
  out.push(128, marker.offset, marker.end);
3782
- const itemLines = new BlockLines();
3783
- itemLines.pushFrom(lines, index, marker.contentOffset, marker.contentPrefixColumns);
3603
+ const itemLines = context.createLineView(lines, index, marker.contentOffset, marker.contentPrefixColumns);
3784
3604
  let hasContent = marker.hasContent;
3785
3605
  let paragraphLeaf = hasContent ? 2 : 0;
3786
3606
  index++;
@@ -3806,13 +3626,14 @@ const listStart = (source, lines, start, contentOffset, out, context) => {
3806
3626
  index++;
3807
3627
  continue;
3808
3628
  }
3809
- const candidate = listMarkerAt(source, lines, index, lineIndentOffset(source, lines, index));
3629
+ const contentOffset = lineIndentOffset(source, lines, index);
3630
+ const candidate = listMarkerAt(source, lines, index, contentOffset);
3810
3631
  if (candidate) {
3811
3632
  sibling = candidate;
3812
3633
  break;
3813
3634
  }
3814
3635
  if (paragraphLeaf === 2) paragraphLeaf = context.endsWithParagraphLeaf(source, itemLines, itemLines.length - 1) ? 1 : 0;
3815
- if (paragraphLeaf === 0 || context.startsInterruptingBlock(source, lines, index)) break;
3636
+ if (paragraphLeaf === 0 || context.startsInterruptingBlock(source, lines, index, contentOffset)) break;
3816
3637
  itemLines.pushLazy(lines, index);
3817
3638
  index++;
3818
3639
  }
@@ -3831,11 +3652,11 @@ const taskListStart = (source, lines, start, contentOffset, out, context) => {
3831
3652
  for (let item = listToken + 1; item < out.length - 1; item += out.nodeLength(item)) {
3832
3653
  let paragraph = item + 1;
3833
3654
  let contentKind = out.kind(paragraph);
3834
- while (contentKind === 71 || contentKind === 2 || contentKind === 198) {
3655
+ while (contentKind === 67 || contentKind === 2 || contentKind === 198) {
3835
3656
  paragraph++;
3836
3657
  contentKind = out.kind(paragraph);
3837
3658
  }
3838
- if (contentKind !== 68) continue;
3659
+ if (contentKind !== 99) continue;
3839
3660
  const firstChunk = paragraph + 1;
3840
3661
  const marker = taskListMarkerAt(source, out.start(firstChunk), out.end(firstChunk));
3841
3662
  if (!marker || !hasTaskListContent(source, out, firstChunk, marker.contentStart)) continue;
@@ -3846,36 +3667,13 @@ const taskListStart = (source, lines, start, contentOffset, out, context) => {
3846
3667
  };
3847
3668
  function feature$4(taskList = false) {
3848
3669
  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
- ],
3670
+ builds: [{
3671
+ token: 65,
3672
+ build: createBuildList(false)
3673
+ }, {
3674
+ token: 66,
3675
+ build: createBuildList(true)
3676
+ }],
3879
3677
  starts: [{
3880
3678
  codes: [
3881
3679
  42,
@@ -3900,29 +3698,23 @@ function feature$4(taskList = false) {
3900
3698
  },
3901
3699
  interrupt(source, lines, index, contentOffset) {
3902
3700
  const marker = listMarkerAt(source, lines, index, contentOffset);
3903
- return marker?.hasContent === true && (marker.kind === "unordered" || marker.kind === "ordered" && marker.startNumber === 1);
3701
+ return marker?.hasContent === true && (marker.startNumber === 1 || marker.delimiter !== 46 && marker.delimiter !== 41);
3904
3702
  },
3905
3703
  start: taskList ? taskListStart : listStart
3906
3704
  }]
3907
3705
  } };
3908
3706
  }
3909
- //#endregion
3910
- //#region src/profile/features/math/block.ts
3707
+ // src/profile/features/math/block.ts
3911
3708
  const mathFenceRule = {
3912
3709
  forbiddenInfoMarker: 36,
3913
3710
  marker: 36,
3914
3711
  minimumLength: 2
3915
3712
  };
3916
- const blockRules = [{
3917
- rule: 14,
3918
- syntax: {
3919
- kind: "leaf",
3920
- token: 261
3921
- },
3713
+ const blockBuilds = [{
3714
+ token: 261,
3922
3715
  build(tokenStart, context) {
3923
3716
  const tokens = context.structure.tokens;
3924
3717
  const block = tokens.value(tokenStart);
3925
- if (!block) throw new Error("Math block lacks fence metadata");
3926
3718
  const value = block.content ?? tokens.text(context.source, tokenStart);
3927
3719
  return {
3928
3720
  type: "math",
@@ -3935,10 +3727,10 @@ const blockRules = [{
3935
3727
  const blockStarts = [{
3936
3728
  codes: [36],
3937
3729
  interrupt(source, lines, index, contentOffset) {
3938
- return fenceAt$1(source, lines, index, mathFenceRule, contentOffset) !== void 0;
3730
+ return fenceAt(source, lines, index, mathFenceRule, contentOffset) !== void 0;
3939
3731
  },
3940
3732
  start(source, lines, start, contentOffset, out) {
3941
- const fence = fenceAt$1(source, lines, start, mathFenceRule, contentOffset);
3733
+ const fence = fenceAt(source, lines, start, mathFenceRule, contentOffset);
3942
3734
  if (!fence) return;
3943
3735
  let end = start + 1;
3944
3736
  while (end < lines.length && !closesFence(source, lines, end, fence)) end++;
@@ -3948,8 +3740,7 @@ const blockStarts = [{
3948
3740
  return end;
3949
3741
  }
3950
3742
  }];
3951
- //#endregion
3952
- //#region src/profile/features/math/inline.ts
3743
+ // src/profile/features/math/inline.ts
3953
3744
  function createMathScanRule(singleDollarTextMath) {
3954
3745
  const minimum = singleDollarTextMath ? 1 : 2;
3955
3746
  return {
@@ -3982,7 +3773,7 @@ const inlineBuilds = [{
3982
3773
  token: 134,
3983
3774
  build(tokenIndex, sourceSpan, context) {
3984
3775
  const markerLength = inlineTokenData(context.tokens, tokenIndex);
3985
- let value = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(markerLength, -markerLength);
3776
+ let value = inlineTokenText(context.view.text, context.tokens, tokenIndex, markerLength);
3986
3777
  const startPadding = value.startsWith("\r\n") ? 2 : /^[ \r\n]/.test(value) ? 1 : 0;
3987
3778
  const endPadding = value.endsWith("\r\n") ? 2 : /[ \r\n]$/.test(value) ? 1 : 0;
3988
3779
  if (startPadding > 0 && endPadding > 0 && /[^ \r\n]/.test(value)) value = value.slice(startPadding, -endPadding);
@@ -3993,47 +3784,45 @@ const inlineBuilds = [{
3993
3784
  };
3994
3785
  }
3995
3786
  }];
3996
- //#endregion
3997
- //#region src/profile/features/math/index.ts
3787
+ // src/profile/features/math/index.ts
3998
3788
  function feature$3(options) {
3999
3789
  const singleDollarTextMath = typeof options !== "object" || options.singleDollarTextMath !== false;
4000
3790
  return {
4001
3791
  block: {
4002
- rules: blockRules,
3792
+ builds: blockBuilds,
4003
3793
  starts: blockStarts
4004
3794
  },
4005
3795
  inline: {
4006
- scan: [createMathScanRule(singleDollarTextMath)],
4007
- build: inlineBuilds
3796
+ scans: [createMathScanRule(singleDollarTextMath)],
3797
+ builds: inlineBuilds
4008
3798
  }
4009
3799
  };
4010
3800
  }
4011
- //#endregion
4012
- //#region src/profile/features/paragraph.ts
3801
+ // src/profile/features/paragraph.ts
4013
3802
  const feature$2 = { block: {
4014
3803
  fallbacks: [(source, lines, start, contentOffset, out, context) => {
4015
3804
  const openToken = out.length;
4016
3805
  const offset = lines.start(start);
4017
- out.push(68, offset, offset);
3806
+ out.push(99, offset, offset);
4018
3807
  let chunkOffset = contentOffset;
4019
3808
  let index = start + 1;
4020
3809
  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);
3810
+ const lineEnd = lines.end(index);
3811
+ const contentStart = skipLineWhitespace(source, lines.start(index), lineEnd);
3812
+ if (contentStart === lineEnd) break;
3813
+ const chunkStart = indentOffset(source, lines, index);
3814
+ if (!lines.lazy(index) && chunkStart === contentStart) {
3815
+ const setext = setextMarkerAt(source, lines, index, contentStart);
4026
3816
  if (setext) {
4027
- out.setKind(openToken, setext === "=" ? 66 : 67);
3817
+ out.setKind(openToken, setext === "=" ? 97 : 98);
4028
3818
  out.push(1, chunkOffset, lines.end(index - 1));
4029
- const lineEnd = lines.end(index);
4030
3819
  out.push(193, lineEnd, lineEnd);
4031
3820
  return index + 1;
4032
3821
  }
4033
- if (context.startsInterruptingBlock(source, lines, index, lineOffset)) break;
3822
+ if (context.startsInterruptingBlock(source, lines, index, contentStart)) break;
4034
3823
  }
4035
3824
  out.push(1, chunkOffset, lines.next(index - 1));
4036
- chunkOffset = lineOffset < 0 ? indentOffset(source, lines, index) : lineOffset;
3825
+ chunkOffset = chunkStart;
4037
3826
  index++;
4038
3827
  }
4039
3828
  const close = lines.end(index - 1);
@@ -4041,15 +3830,10 @@ const feature$2 = { block: {
4041
3830
  out.push(194, close, close);
4042
3831
  return index;
4043
3832
  }],
4044
- rules: [{
4045
- rule: 4,
4046
- syntax: {
4047
- kind: "block",
4048
- token: 68
4049
- },
4050
- inlineContent: true,
3833
+ builds: [{
3834
+ token: 99,
4051
3835
  build(tokenStart, context) {
4052
- const inline = buildInlineFragment(tokenStart, 4, context);
3836
+ const inline = buildInlineFragment(tokenStart, false, context);
4053
3837
  const result = {
4054
3838
  type: "paragraph",
4055
3839
  children: inline.children,
@@ -4063,13 +3847,7 @@ const feature$2 = { block: {
4063
3847
  }
4064
3848
  }]
4065
3849
  } };
4066
- //#endregion
4067
- //#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
- }
3850
+ // src/profile/features/reference.ts
4073
3851
  function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
4074
3852
  let offset = contentOffset + 1;
4075
3853
  const labelClose = source.indexOf("]", offset);
@@ -4106,7 +3884,7 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
4106
3884
  }
4107
3885
  const nextLine = lineIndex + 1;
4108
3886
  lookaheadEnd = nextLine < lines.length ? lines.end(nextLine) : lines.next(lineIndex);
4109
- if (nextLine >= lines.length || isBlank(source, lines, nextLine)) break parseDefinition;
3887
+ if (nextLine >= lines.length || isBlankLine(source, lines, nextLine)) break parseDefinition;
4110
3888
  if (++labelLength > 999) break parseDefinition;
4111
3889
  label += source.slice(labelStart, lines.next(lineIndex));
4112
3890
  lineIndex++;
@@ -4116,19 +3894,16 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
4116
3894
  label += source.slice(labelStart, offset);
4117
3895
  if (!labelHasContent) break parseDefinition;
4118
3896
  offset += 2;
4119
- const skipSpaces = (lineEnd) => {
4120
- while (offset < lineEnd && (source[offset] === " " || source[offset] === " ")) offset++;
4121
- };
4122
3897
  let lineEnd = lines.end(lineIndex);
4123
- skipSpaces(lineEnd);
3898
+ offset = skipLineWhitespace(source, offset, lineEnd);
4124
3899
  if (offset === lineEnd) {
4125
3900
  const nextLine = lineIndex + 1;
4126
3901
  lookaheadEnd = nextLine < lines.length ? lines.end(nextLine) : lines.next(lineIndex);
4127
- if (nextLine >= lines.length || isBlank(source, lines, nextLine)) break parseDefinition;
3902
+ if (nextLine >= lines.length || isBlankLine(source, lines, nextLine)) break parseDefinition;
4128
3903
  lineIndex++;
4129
3904
  offset = lines.start(lineIndex);
4130
3905
  lineEnd = lines.end(lineIndex);
4131
- skipSpaces(lineEnd);
3906
+ offset = skipLineWhitespace(source, offset, lineEnd);
4132
3907
  }
4133
3908
  let destination;
4134
3909
  if (source[offset] === "<") {
@@ -4162,18 +3937,18 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
4162
3937
  }
4163
3938
  const destinationLine = lineIndex;
4164
3939
  if (offset < lineEnd && source[offset] !== " " && source[offset] !== " ") break parseDefinition;
4165
- skipSpaces(lineEnd);
3940
+ offset = skipLineWhitespace(source, offset, lineEnd);
4166
3941
  let titleOnNextLine = false;
4167
3942
  if (offset === lineEnd && lineIndex + 1 < lines.length) {
4168
3943
  lookaheadEnd = lines.end(lineIndex + 1);
4169
3944
  lineIndex++;
4170
3945
  offset = lines.start(lineIndex);
4171
3946
  lineEnd = lines.end(lineIndex);
4172
- skipSpaces(lineEnd);
3947
+ offset = skipLineWhitespace(source, offset, lineEnd);
4173
3948
  titleOnNextLine = true;
4174
3949
  }
4175
3950
  const closer = source[offset] === "(" ? ")" : source[offset] === "\"" || source[offset] === "'" ? source[offset] : void 0;
4176
- const definitionKey = normalizeAssociationLabel(label);
3951
+ const definitionKey = normalizeIdentifier(label);
4177
3952
  const fields = {
4178
3953
  destination,
4179
3954
  label,
@@ -4206,14 +3981,14 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
4206
3981
  if (closed) break;
4207
3982
  const nextLine = lineIndex + 1;
4208
3983
  lookaheadEnd = nextLine < lines.length ? lines.end(nextLine) : lines.next(lineIndex);
4209
- if (nextLine >= lines.length || isBlank(source, lines, nextLine)) break;
3984
+ if (nextLine >= lines.length || isBlankLine(source, lines, nextLine)) break;
4210
3985
  title += source.slice(titleStart, lines.next(lineIndex));
4211
3986
  lineIndex++;
4212
3987
  offset = lines.start(lineIndex);
4213
3988
  titleStart = offset;
4214
3989
  }
4215
3990
  if (closed) {
4216
- skipSpaces(lineEnd);
3991
+ offset = skipLineWhitespace(source, offset, lineEnd);
4217
3992
  if (offset === lineEnd) {
4218
3993
  fields.title = title;
4219
3994
  return {
@@ -4234,20 +4009,14 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
4234
4009
  if (lookaheadEnd >= 0) context.retainLookahead(lookaheadEnd);
4235
4010
  }
4236
4011
  const feature$1 = { block: {
4237
- rules: [{
4238
- rule: 11,
4239
- syntax: {
4240
- kind: "block",
4241
- token: 71
4242
- },
4012
+ builds: [{
4013
+ token: 67,
4243
4014
  build(tokenStart, context) {
4244
4015
  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");
4016
+ const fields = tokens.value(tokenStart);
4248
4017
  return {
4249
4018
  type: "definition",
4250
- identifier: definitionKey,
4019
+ identifier: tokens.definitionKey(tokenStart),
4251
4020
  label: semanticText(fields.label),
4252
4021
  url: semanticText(fields.destination),
4253
4022
  title: fields.title === void 0 ? null : semanticText(fields.title),
@@ -4260,7 +4029,7 @@ const feature$1 = { block: {
4260
4029
  start(source, lines, start, contentOffset, out, context) {
4261
4030
  const definition = linkDefinitionAt(source, lines, start, contentOffset, context);
4262
4031
  if (!definition) return;
4263
- out.push(71, contentOffset, contentOffset, {
4032
+ out.push(67, contentOffset, contentOffset, {
4264
4033
  definitionKey: definition.definitionKey,
4265
4034
  value: definition.fields
4266
4035
  });
@@ -4274,14 +4043,9 @@ const feature$1 = { block: {
4274
4043
  }
4275
4044
  }]
4276
4045
  } };
4277
- //#endregion
4278
- //#region src/profile/features/table.ts
4046
+ // src/profile/features/table.ts
4279
4047
  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
- }
4048
+ contentStart = skipLineWhitespace(source, contentStart, contentEnd);
4285
4049
  while (contentEnd > contentStart) {
4286
4050
  const code = source.charCodeAt(contentEnd - 1);
4287
4051
  if (code !== 32 && code !== 9) break;
@@ -4291,17 +4055,13 @@ function appendTableCell(cells, source, start, contentStart, contentEnd) {
4291
4055
  }
4292
4056
  function tableCellsAt(source, lines, index, requirePipe, contentOffset) {
4293
4057
  if (contentOffset < 0) return;
4294
- const pipes = [];
4295
- let backslashes = 0;
4296
4058
  const lineEnd = lines.end(index);
4297
- for (let offset = contentOffset; offset < lineEnd; offset++) {
4298
- const code = source.charCodeAt(offset);
4299
- if (code === 92) {
4300
- backslashes++;
4301
- continue;
4302
- }
4303
- if (code === 124 && backslashes % 2 === 0) pipes.push(offset);
4304
- backslashes = 0;
4059
+ const row = source.slice(contentOffset, lineEnd);
4060
+ const pipes = [];
4061
+ for (let pipe = row.indexOf("|"); pipe >= 0; pipe = row.indexOf("|", pipe + 1)) {
4062
+ let escapeStart = pipe;
4063
+ while (escapeStart > 0 && row.charCodeAt(escapeStart - 1) === 92) escapeStart--;
4064
+ if ((pipe - escapeStart) % 2 === 0) pipes.push(contentOffset + pipe);
4305
4065
  }
4306
4066
  if (requirePipe && pipes.length === 0) return;
4307
4067
  let visibleEnd = lineEnd;
@@ -4356,7 +4116,7 @@ function emitTableRow(lines, index, cells, out) {
4356
4116
  out.push(131, cells[0], cells[0]);
4357
4117
  for (let cell = 0; cell < cells.length; cell += 3) {
4358
4118
  const start = cells[cell];
4359
- out.push(132, start, start);
4119
+ out.push(160, start, start);
4360
4120
  out.push(1, cells[cell + 1], cells[cell + 2], void 0, 192);
4361
4121
  }
4362
4122
  const lineEnd = lines.end(index);
@@ -4367,7 +4127,7 @@ const buildTableCell = (tokenStart, context) => {
4367
4127
  const start = context.locator.locationAt(tokens.start(tokenStart));
4368
4128
  return {
4369
4129
  type: "tableCell",
4370
- children: buildInlineFragment(tokenStart, 17, context).children,
4130
+ children: buildInlineFragment(tokenStart, true, context).children,
4371
4131
  position: {
4372
4132
  start,
4373
4133
  end: context.locator.locationAt(tokens.start(tokenStart + tokens.nodeLength(tokenStart)))
@@ -4379,7 +4139,7 @@ const buildTableRow = (tokenStart, context) => {
4379
4139
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
4380
4140
  const start = context.locator.locationAt(tokens.start(tokenStart));
4381
4141
  const children = [];
4382
- for (let cell = tokenStart + 1; cell < close; cell += tokens.nodeLength(cell)) children.push(buildBlockNode(cell, context));
4142
+ for (let cell = tokenStart + 1; cell < close; cell += tokens.nodeLength(cell)) children.push(buildTableCell(cell, context));
4383
4143
  return {
4384
4144
  type: "tableRow",
4385
4145
  children,
@@ -4409,7 +4169,7 @@ const feature = { block: {
4409
4169
  if (!delimiter) return;
4410
4170
  const header = tableCellsAt(source, lines, start, true, contentOffset);
4411
4171
  if (header?.length !== delimiter.length) return;
4412
- out.push(73, header[0], header[0]);
4172
+ out.push(69, header[0], header[0]);
4413
4173
  emitTableRow(lines, start, header, out);
4414
4174
  const delimiterEnd = lines.end(delimiterLine);
4415
4175
  for (let cell = 0; cell < delimiter.length; cell += 3) out.push(delimiter[cell + 1], delimiter[cell], delimiter[cell + 3] ?? delimiterEnd);
@@ -4426,65 +4186,29 @@ const feature = { block: {
4426
4186
  out.push(200, tableEnd, tableEnd);
4427
4187
  return end;
4428
4188
  }],
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
- }
4189
+ builds: [{
4190
+ token: 69,
4191
+ build(tokenStart, context) {
4192
+ const tokens = context.structure.tokens;
4193
+ const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
4194
+ const start = context.locator.locationAt(tokens.start(tokenStart));
4195
+ const header = tokenStart + 1;
4196
+ const delimiter = header + tokens.nodeLength(header);
4197
+ const rows = [buildTableRow(header, context)];
4198
+ for (let row = delimiter + tokens.nodeLength(delimiter); row < close; row += tokens.nodeLength(row)) rows.push(buildTableRow(row, context));
4199
+ return {
4200
+ type: "table",
4201
+ align: tableAlignment(delimiter, context),
4202
+ children: rows,
4203
+ position: {
4204
+ start,
4205
+ end: context.locator.locationAt(tokens.start(close))
4206
+ }
4207
+ };
4483
4208
  }
4484
- ]
4209
+ }]
4485
4210
  } };
4486
- //#endregion
4487
- //#region src/inline/delimiter.ts
4211
+ // src/inline/delimiter.ts
4488
4212
  const whitespace = /\s/u;
4489
4213
  const punctuation = /[\p{P}\p{S}]/u;
4490
4214
  function codePointBefore(source, offset) {
@@ -4499,7 +4223,7 @@ function codePointBefore(source, offset) {
4499
4223
  function delimiterCharacterClass(code) {
4500
4224
  if (code <= 127) {
4501
4225
  if (code === 32 || code >= 9 && code <= 13) return 1;
4502
- return code >= 33 && code <= 47 || code >= 58 && code <= 64 || code >= 91 && code <= 96 || code >= 123 && code <= 126 ? 2 : 0;
4226
+ return isAsciiPunctuation(code) ? 2 : 0;
4503
4227
  }
4504
4228
  const character = String.fromCodePoint(code);
4505
4229
  return whitespace.test(character) ? 1 : punctuation.test(character) ? 2 : 0;
@@ -4523,19 +4247,13 @@ function unlinkRun(runs, runIndex) {
4523
4247
  if (run.previous >= 0) runs[run.previous].next = run.next;
4524
4248
  if (run.next >= 0) runs[run.next].previous = run.previous;
4525
4249
  }
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) {
4250
+ function resolveDelimiterScope(runs, first, replacements = []) {
4532
4251
  const openersBottom = [];
4533
4252
  let current = first;
4534
4253
  while (current >= 0) {
4535
4254
  const closer = runs[current];
4536
4255
  const next = closer.next;
4537
4256
  if (!(closer.state & 2)) {
4538
- if ((closer.state & 3) === 0) unlinkRun(runs, current);
4539
4257
  current = next;
4540
4258
  continue;
4541
4259
  }
@@ -4560,12 +4278,12 @@ function matchDelimiterRuns(runs, first, replacements) {
4560
4278
  const closeStart = closer.start;
4561
4279
  const closeEnd = closeStart + use;
4562
4280
  const pair = use === 2 ? closer.config.double : closer.config.single;
4563
- addReplacement(replacements, opener.tokenIndex, {
4281
+ (replacements[opener.tokenIndex] ??= []).push({
4564
4282
  offset: openStart,
4565
4283
  end: openEnd,
4566
4284
  kind: pair.open
4567
4285
  });
4568
- addReplacement(replacements, closer.tokenIndex, {
4286
+ (replacements[closer.tokenIndex] ??= []).push({
4569
4287
  offset: closeStart,
4570
4288
  end: closeEnd,
4571
4289
  kind: pair.close
@@ -4581,16 +4299,15 @@ function matchDelimiterRuns(runs, first, replacements) {
4581
4299
  current = next;
4582
4300
  }
4583
4301
  }
4302
+ return replacements;
4584
4303
  }
4585
- function delimiterRunAt(source, tokens, tokenIndex, configByKind) {
4586
- const config = configByKind[inlineTokenKind(tokens, tokenIndex)];
4587
- if (!config) return;
4304
+ function delimiterRunAt(source, tokens, tokenIndex, config) {
4588
4305
  const offset = inlineTokenStart(tokens, tokenIndex);
4589
4306
  const end = inlineTokenEnd(tokens, tokenIndex);
4590
4307
  const length = end - offset;
4591
4308
  if (config.bits & 2 && (length > 2 || (length === 1 ? !config.single : !config.double))) return;
4592
4309
  const delimiterFlanking = flanking(source, offset, end, config);
4593
- if (config.bits & 1 || delimiterFlanking !== 0) return {
4310
+ if (delimiterFlanking !== 0) return {
4594
4311
  tokenIndex,
4595
4312
  config,
4596
4313
  start: offset,
@@ -4600,11 +4317,6 @@ function delimiterRunAt(source, tokens, tokenIndex, configByKind) {
4600
4317
  state: delimiterFlanking | length % 3 << 2
4601
4318
  };
4602
4319
  }
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
4320
  function appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements) {
4609
4321
  const matched = replacements[tokenIndex];
4610
4322
  if (!matched) {
@@ -4633,44 +4345,28 @@ function compileDelimiterConfigs(delimiterConfigs) {
4633
4345
  });
4634
4346
  return delimiterByKind;
4635
4347
  }
4636
- //#endregion
4637
- //#region src/profile/resolve.ts
4348
+ // src/profile/resolve.ts
4638
4349
  const frameHeaderSize = 1;
4639
- const noBracketFrames = Object.freeze([0]);
4640
- const delimiterOnlyFrames = Object.freeze([2]);
4641
- const noDelimiterReplacements = [];
4642
- function frameClaim(frames, frame) {
4643
- return frames[frame + 5] & 7;
4644
- }
4350
+ const noBracketFrames = [0];
4645
4351
  function setFrameState(frames, frame, state) {
4646
4352
  frames[frame + 5] = state;
4647
- frames[0] |= 4;
4353
+ frames[0] = 1;
4648
4354
  }
4649
- function rewriteLinkCandidates(frames, candidates, start) {
4650
- let write = start;
4651
- for (let read = start; read < candidates.length; read++) {
4652
- const candidate = candidates[read];
4355
+ function rewriteLinkCandidates(frames, top, bottom) {
4356
+ let candidate = top;
4357
+ top = bottom;
4358
+ while (candidate !== bottom) {
4359
+ const next = frames[candidate + 3];
4653
4360
  const state = frames[candidate + 5];
4654
- if ((state & 7) === 3 && !(state & 8)) frames[candidate + 5] = 0;
4361
+ if (state === 3) frames[candidate + 5] = 0;
4655
4362
  else {
4656
4363
  frames[candidate + 5] = state | 16;
4657
- candidates[write++] = candidate;
4364
+ frames[candidate + 3] = top;
4365
+ top = candidate;
4658
4366
  }
4367
+ candidate = next;
4659
4368
  }
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);
4369
+ return top;
4674
4370
  }
4675
4371
  function referenceLabelEnd(source, start) {
4676
4372
  if (source.charCodeAt(start) !== 91) return -1;
@@ -4687,7 +4383,7 @@ function referenceLabelEnd(source, start) {
4687
4383
  hasContent = true;
4688
4384
  offset += 2;
4689
4385
  } else {
4690
- hasContent ||= code !== 9 && code !== 10 && code !== 13 && code !== 32;
4386
+ hasContent ||= !isMarkdownWhitespace(code);
4691
4387
  offset++;
4692
4388
  }
4693
4389
  characters++;
@@ -4699,7 +4395,7 @@ function acceptsShortcutLabel(source, start, end) {
4699
4395
  let characters = 0;
4700
4396
  for (let offset = start; offset < end; offset++) {
4701
4397
  const code = source.charCodeAt(offset);
4702
- hasContent ||= code !== 9 && code !== 10 && code !== 13 && code !== 32;
4398
+ hasContent ||= !isMarkdownWhitespace(code);
4703
4399
  if (code >= 55296 && code <= 56319 && offset + 1 < end) {
4704
4400
  const trailing = source.charCodeAt(offset + 1);
4705
4401
  if (trailing >= 56320 && trailing <= 57343) offset++;
@@ -4708,60 +4404,60 @@ function acceptsShortcutLabel(source, start, end) {
4708
4404
  }
4709
4405
  return hasContent;
4710
4406
  }
4711
- function analyzeBrackets(source, tokens, delimiterByKind, definitions, options) {
4712
- let hasDelimiter = false;
4407
+ function analyzeBrackets(source, tokens, definitions, options) {
4713
4408
  let frames;
4714
- let candidates;
4409
+ let candidateTop = -1;
4715
4410
  let stackTop = -1;
4716
4411
  const count = inlineTokenCount(tokens);
4717
4412
  for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
4718
4413
  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);
4414
+ if (kind >= 71 && kind <= 72) {
4415
+ const arena = frames ??= [0];
4416
+ const frame = arena.length;
4417
+ arena.push(tokenIndex, -1, candidateTop, -1, stackTop, kind === 71 ? 8 : 0);
4418
+ stackTop = frame;
4723
4419
  continue;
4724
4420
  }
4725
- if (kind !== 74 && kind !== 73) continue;
4421
+ if (kind < 73 || kind > 74) continue;
4726
4422
  if (stackTop < 0) continue;
4727
4423
  const frame = stackTop;
4728
4424
  const arena = frames;
4729
4425
  stackTop = arena[frame + 4];
4730
4426
  arena[frame + 1] = tokenIndex;
4731
- const image = isImageFrame(tokens, arena, frame);
4427
+ const image = (arena[frame + 5] & 8) !== 0;
4732
4428
  if (options.footnote && kind === 74) {
4733
4429
  const openToken = arena[frame + 0];
4734
4430
  const label = footnoteLabelAt(source, inlineTokenStart(tokens, openToken) + (image ? 1 : 0), source.length);
4735
4431
  if (label && label.end === inlineTokenEnd(tokens, tokenIndex) && definitions.hasDefinition(label.definitionKey)) {
4736
4432
  setFrameState(arena, frame, 1);
4737
- if (candidates) candidates.length = arena[frame + 2];
4433
+ candidateTop = arena[frame + 2];
4738
4434
  continue;
4739
4435
  }
4740
4436
  }
4741
4437
  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)) {
4438
+ if (kind === 73) candidateTop = rewriteLinkCandidates(arena, candidateTop, arena[frame + 2]);
4439
+ const openToken = arena[frame + 0];
4440
+ const componentToken = openToken - 1;
4441
+ if (componentToken >= 0 && inlineTokenKind(tokens, componentToken) === 137 && inlineTokenEnd(tokens, componentToken) === inlineTokenStart(tokens, openToken)) {
4746
4442
  setFrameState(arena, frame, 2);
4747
- (candidates ??= []).push(frame);
4443
+ arena[frame + 3] = candidateTop;
4444
+ candidateTop = frame;
4748
4445
  continue;
4749
4446
  }
4750
- const close = inlineTokenStart(tokens, tokenIndex);
4751
- const trailing = source.charCodeAt(close + 1);
4447
+ const suffixStart = inlineTokenStart(tokens, tokenIndex) + 1;
4448
+ const trailing = source.charCodeAt(suffixStart);
4752
4449
  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);
4756
- }
4757
- if (frames) {
4758
- frames[0] |= hasDelimiter ? 2 : 0;
4759
- return frames;
4450
+ setFrameState(arena, frame, trailing === 123 && attributesEnd(source, suffixStart) !== void 0 ? 4 : 3);
4451
+ arena[frame + 3] = candidateTop;
4452
+ candidateTop = frame;
4760
4453
  }
4761
- return hasDelimiter ? delimiterOnlyFrames : noBracketFrames;
4454
+ return frames ?? noBracketFrames;
4762
4455
  }
4763
- function resolveReferences(source, tokens, frames, definitions) {
4764
- const hasDefinitions = definitions.hasDefinitions();
4456
+ function resolvePairedSyntax(source, tokens, frames, definitions, delimiterByKind) {
4457
+ const hasDefinitions = frames.length > frameHeaderSize && definitions.hasDefinitions();
4458
+ let runs;
4459
+ let runCount = 0;
4460
+ let replacements;
4765
4461
  let rawTop = -1;
4766
4462
  let logicalTop = -1;
4767
4463
  let frameCursor = frameHeaderSize;
@@ -4779,70 +4475,92 @@ function resolveReferences(source, tokens, frames, definitions) {
4779
4475
  consumeFrames = false;
4780
4476
  }
4781
4477
  const consuming = consumedEnd >= 0;
4782
- if (kind === 72 || kind === 71) {
4478
+ const delimiter = delimiterByKind[kind];
4479
+ if (!consuming && delimiter) {
4480
+ const run = delimiterRunAt(source, tokens, tokenIndex, delimiter);
4481
+ if (run) {
4482
+ const arena = runs ??= [];
4483
+ const runIndex = runCount++;
4484
+ if (runIndex > 0) {
4485
+ run.previous = runIndex - 1;
4486
+ arena[runIndex - 1].next = runIndex;
4487
+ }
4488
+ arena[runIndex] = run;
4489
+ }
4490
+ }
4491
+ if (kind >= 71 && kind <= 72) {
4783
4492
  const frame = frameCursor;
4784
- frameCursor += 7;
4493
+ frameCursor += 6;
4785
4494
  rawTop = frame;
4786
4495
  if (consuming) {
4787
- if (consumeFrames) setFrameState(frames, frame, 6);
4496
+ if (consumeFrames) setFrameState(frames, frame, 7);
4788
4497
  continue;
4789
4498
  }
4790
- const claim = frameClaim(frames, frame);
4499
+ frames[frame + 2] = runCount;
4500
+ const state = frames[frame + 5];
4501
+ const claim = state & 7;
4791
4502
  if (claim === 1) {
4792
4503
  const closeToken = frames[frame + 1];
4793
4504
  consumedEnd = inlineTokenEnd(tokens, closeToken);
4794
4505
  continue;
4795
4506
  }
4796
- if (claim === 2 || claim === 3) {
4797
- if (frames[frame + 5] & 16) literalDepth++;
4507
+ if (claim >= 2 && claim <= 4) {
4508
+ if (state & 16) literalDepth++;
4509
+ continue;
4510
+ }
4511
+ if (literalDepth > 0 && !(kind === 71)) {
4512
+ frames[frame + 5] = state | 32;
4798
4513
  continue;
4799
4514
  }
4800
- if (literalDepth > 0 && !(kind === 71)) continue;
4801
4515
  frames[frame + 3] = logicalTop;
4802
4516
  logicalTop = frame;
4803
4517
  lastVisibleOpener = tokenIndex;
4804
4518
  continue;
4805
4519
  }
4806
- if (kind !== 74 && kind !== 73) continue;
4520
+ if (kind < 73 || kind > 74) continue;
4807
4521
  const rawFrame = rawTop;
4808
4522
  if (rawFrame >= 0) rawTop = frames[rawFrame + 4];
4809
4523
  if (consuming) {
4810
- if (consumeFrames && rawFrame >= 0) setFrameState(frames, rawFrame, 6);
4524
+ if (consumeFrames && rawFrame >= 0) setFrameState(frames, rawFrame, 7);
4811
4525
  continue;
4812
4526
  }
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))) {
4527
+ const rawState = rawFrame < 0 ? 0 : frames[rawFrame + 5];
4528
+ const rawClaim = rawState & 7;
4529
+ let runStart = rawClaim >= 1 && rawClaim <= 4 ? frames[rawFrame + 2] : -1;
4530
+ if (runStart < 0 && (literalDepth <= 0 || rawFrame < 0 || (rawState & 8) !== 0)) {
4815
4531
  const frame = logicalTop;
4816
4532
  if (frame >= 0) logicalTop = frames[frame + 3];
4817
4533
  if (frame >= 0 && (kind === 73 || hasDefinitions)) {
4818
4534
  const openToken = frames[frame + 0];
4819
- const image = isImageFrame(tokens, frames, frame);
4535
+ const image = (frames[frame + 5] & 8) !== 0;
4820
4536
  if (image || openToken + 1 >= inactiveBefore) {
4821
4537
  const contentStart = inlineTokenEnd(tokens, openToken);
4822
4538
  const contentEnd = tokenStart;
4823
- let closeEnd = inlineTokenEnd(tokens, tokenIndex);
4539
+ const tokenEnd = inlineTokenEnd(tokens, tokenIndex);
4540
+ let closeEnd = tokenEnd;
4824
4541
  let reference = false;
4825
4542
  let matched = kind === 73;
4826
4543
  if (!matched) {
4827
4544
  const labelEnd = referenceLabelEnd(source, closeEnd);
4828
4545
  if (labelEnd > 0) {
4829
4546
  const label = source.slice(closeEnd + 1, labelEnd - 1) || source.slice(contentStart, contentEnd);
4830
- matched = definitions.hasDefinition(normalizeAssociationLabel(label));
4547
+ matched = definitions.hasDefinition(normalizeIdentifier(label));
4831
4548
  if (matched) {
4832
4549
  closeEnd = labelEnd;
4833
4550
  reference = true;
4834
4551
  }
4835
- } else if (lastVisibleOpener <= openToken && acceptsShortcutLabel(source, contentStart, contentEnd) && definitions.hasDefinition(normalizeAssociationLabel(source.slice(contentStart, contentEnd)))) {
4552
+ } else if (lastVisibleOpener <= openToken && acceptsShortcutLabel(source, contentStart, contentEnd) && definitions.hasDefinition(normalizeIdentifier(source.slice(contentStart, contentEnd)))) {
4836
4553
  matched = true;
4837
4554
  reference = true;
4838
4555
  }
4839
4556
  }
4840
4557
  if (matched) {
4841
- setFrameState(frames, frame, reference ? 5 : 4);
4558
+ setFrameState(frames, frame, (reference ? 6 : 5) | (image ? 8 : 0));
4842
4559
  frames[frame + 1] = tokenIndex;
4843
- frames[frame + 6] = closeEnd;
4844
- if (!image) inactiveBefore = Math.max(inactiveBefore, openToken + 1);
4845
- if (closeEnd > inlineTokenEnd(tokens, tokenIndex)) {
4560
+ runStart = frames[frame + 2];
4561
+ frames[frame + 2] = closeEnd;
4562
+ if (!image) inactiveBefore = openToken + 1;
4563
+ if (closeEnd > tokenEnd) {
4846
4564
  consumedEnd = closeEnd;
4847
4565
  consumeFrames = true;
4848
4566
  }
@@ -4850,84 +4568,45 @@ function resolveReferences(source, tokens, frames, definitions) {
4850
4568
  }
4851
4569
  }
4852
4570
  }
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);
4571
+ if (rawState & 16) literalDepth--;
4572
+ if (runStart >= 0 && runCount > runStart) {
4573
+ if (runStart > 0) {
4574
+ runs[runStart].previous = -1;
4575
+ runs[runStart - 1].next = -1;
4900
4576
  }
4577
+ replacements = resolveDelimiterScope(runs, runStart, replacements);
4578
+ runCount = runStart;
4901
4579
  }
4902
4580
  }
4903
- return runs;
4581
+ if (runCount > 0) replacements = resolveDelimiterScope(runs, 0, replacements);
4582
+ return replacements ?? emptyArray;
4904
4583
  }
4905
4584
  function appendReferenceBoundary(result, tokens, frames, frame, close) {
4906
4585
  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);
4586
+ const state = frames[frame + 5];
4587
+ const kind = ((state & 7) === 6 ? 202 : 198) + (state & 8 ? 2 : 0) + (close ? 1 : 0);
4588
+ const end = close ? frames[frame + 2] : inlineTokenEnd(tokens, token);
4909
4589
  appendInlineToken(result, kind, inlineTokenStart(tokens, token), end, inlineTokenData(tokens, token));
4910
4590
  return end;
4911
4591
  }
4912
4592
  function emitResolvedTokens(tokens, frames, replacements) {
4913
- const workspace = frames;
4914
4593
  const result = [];
4915
4594
  let rawTop = -1;
4916
4595
  let referenceTop = -1;
4917
4596
  let frameCursor = frameHeaderSize;
4918
4597
  let skipEnd = -1;
4919
- let literalDepth = 0;
4920
4598
  const count = inlineTokenCount(tokens);
4921
4599
  for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
4922
4600
  const kind = inlineTokenKind(tokens, tokenIndex);
4923
4601
  const tokenStart = inlineTokenStart(tokens, tokenIndex);
4924
4602
  if (skipEnd >= 0 && tokenStart >= skipEnd) skipEnd = -1;
4925
4603
  const skipping = skipEnd >= 0;
4926
- if (kind === 72 || kind === 71) {
4604
+ if (kind >= 71 && kind <= 72) {
4927
4605
  const frame = frameCursor;
4928
- frameCursor += 7;
4606
+ frameCursor += 6;
4929
4607
  rawTop = frame;
4930
- const claim = frameClaim(frames, frame);
4608
+ const state = frames[frame + 5];
4609
+ const claim = state & 7;
4931
4610
  if (!skipping) {
4932
4611
  if (claim === 1) {
4933
4612
  const closeToken = frames[frame + 1];
@@ -4936,19 +4615,19 @@ function emitResolvedTokens(tokens, frames, replacements) {
4936
4615
  appendInlineToken(result, 133, start, skipEnd);
4937
4616
  } else if (claim === 2) {
4938
4617
  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) {
4618
+ const openEnd = inlineTokenEnd(tokens, tokenIndex);
4619
+ if (openEnd < inlineTokenStart(tokens, closeToken)) rewriteInlineTokenTail(result, 208, openEnd);
4620
+ } else if (claim >= 3 && claim <= 4) appendInlineToken(result, 206, inlineTokenStart(tokens, tokenIndex), inlineTokenEnd(tokens, tokenIndex));
4621
+ else if (claim === 5 || claim === 6) {
4942
4622
  appendReferenceBoundary(result, tokens, frames, frame, false);
4943
- workspace[frame + 3] = referenceTop;
4623
+ frames[frame + 3] = referenceTop;
4944
4624
  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);
4625
+ } else if (claim === 7) skipEnd = inlineTokenEnd(tokens, frames[frame + 1]);
4626
+ else if (!(state & 32)) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
4947
4627
  }
4948
- if (frames[frame + 5] & 16) literalDepth++;
4949
4628
  continue;
4950
4629
  }
4951
- if (kind === 74 || kind === 73) {
4630
+ if (kind >= 73 && kind <= 74) {
4952
4631
  const rawFrame = rawTop;
4953
4632
  if (rawFrame >= 0) rawTop = frames[rawFrame + 4];
4954
4633
  const referenceFrame = referenceTop;
@@ -4958,20 +4637,15 @@ function emitResolvedTokens(tokens, frames, replacements) {
4958
4637
  referenceTop = frames[referenceFrame + 3];
4959
4638
  skipEnd = appendReferenceBoundary(result, tokens, frames, referenceFrame, true);
4960
4639
  } else if (rawFrame >= 0) {
4961
- const claim = frameClaim(frames, rawFrame);
4640
+ const state = frames[rawFrame + 5];
4641
+ const claim = state & 7;
4962
4642
  if (claim === 2) {
4963
4643
  const openToken = frames[rawFrame + 0];
4964
4644
  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
- }
4645
+ } else if (claim >= 3 && claim <= 4) appendInlineToken(result, 207, tokenStart, tokenStart + 1);
4646
+ else if (claim !== 1 && !(state & 32)) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
4972
4647
  } else appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
4973
4648
  }
4974
- if (rawFrame >= 0 && frames[rawFrame + 5] & 16) literalDepth--;
4975
4649
  continue;
4976
4650
  }
4977
4651
  if (!skipping) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
@@ -4982,38 +4656,37 @@ function compileInlineResolver(options) {
4982
4656
  return (delimiterConfigs) => {
4983
4657
  const delimiterByKind = compileDelimiterConfigs(delimiterConfigs);
4984
4658
  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);
4659
+ let tokenIndex = inlineTokenCount(tokens) - 1;
4660
+ for (; tokenIndex >= 0; tokenIndex--) {
4661
+ const kind = inlineTokenKind(tokens, tokenIndex);
4662
+ if (kind >= 68 && kind <= 74) break;
4992
4663
  }
4993
- return frames[0] & 4 || replacements.length > 0 ? emitResolvedTokens(tokens, frames, replacements) : tokens;
4664
+ if (tokenIndex < 0) return tokens;
4665
+ const frames = analyzeBrackets(source, tokens, definitions, options);
4666
+ const replacements = resolvePairedSyntax(source, tokens, frames, definitions, delimiterByKind);
4667
+ return frames[0] & 1 || replacements.length > 0 ? emitResolvedTokens(tokens, frames, replacements) : tokens;
4994
4668
  };
4995
4669
  };
4996
4670
  }
4997
- //#endregion
4998
- //#region src/profile/index.ts
4671
+ // src/profile/index.ts
4999
4672
  function compileProfile(options = {}) {
5000
4673
  const features = [
5001
4674
  feature$7,
5002
4675
  feature$15,
5003
4676
  feature$16,
5004
4677
  feature$4(options.taskList),
5005
- feature$13,
4678
+ feature$14,
5006
4679
  feature$6
5007
4680
  ];
5008
- if (options.footnote) features.push(feature$9);
5009
- if (options.frontmatter) features.unshift(feature$12(typeof options.frontmatter === "object" ? options.frontmatter.marker : "-"));
4681
+ if (options.footnote) features.push(feature$10);
4682
+ if (options.frontmatter) features.unshift(feature$13(typeof options.frontmatter === "object" ? options.frontmatter.marker : "-"));
5010
4683
  if (options.table) features.push(feature);
5011
4684
  if (options.math) features.push(feature$3(options.math));
5012
- features.push(feature$2, feature$14, feature$8(options.strikethrough), feature$5);
4685
+ features.push(feature$2, feature$9, feature$8(options.strikethrough), feature$5);
5013
4686
  if (options.attributes) features.push(feature$18);
5014
4687
  if (options.binding) features.push(feature$17);
5015
- if (options.emoji) features.push(feature$10);
5016
- if (options.component) features.push(feature$11);
4688
+ if (options.emoji) features.push(feature$11);
4689
+ if (options.component) features.push(feature$12);
5017
4690
  features.push(feature$1);
5018
4691
  const blockFeatures = [];
5019
4692
  const inlineFeatures = [];
@@ -5029,8 +4702,7 @@ function compileProfile(options = {}) {
5029
4702
  }))
5030
4703
  };
5031
4704
  }
5032
- //#endregion
5033
- //#region src/parser.ts
4705
+ // src/parser.ts
5034
4706
  function createParser(options) {
5035
4707
  const profile = compileProfile(options?.features);
5036
4708
  let blockScanner;
@@ -5039,5 +4711,4 @@ function createParser(options) {
5039
4711
  parse: (source) => DocumentImpl.parse(source, profile, blockScanner ??= new BlockScanner(profile.block))
5040
4712
  };
5041
4713
  }
5042
- //#endregion
5043
- export { createParser };
4714
+ export { createParser, normalizeIdentifier };