satorigear 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +19 -67
  2. package/dist/index.mjs +784 -831
  3. package/package.json +3 -2
package/dist/index.mjs CHANGED
@@ -1,10 +1,13 @@
1
- import { decodeHTMLStrict } from "entities";
1
+ import { decodeString } from "micromark-util-decode-string";
2
+ import { htmlBlockNames, htmlRawNames } from "micromark-util-html-tag-name";
2
3
  //#region src/block/lines.ts
3
4
  var BlockLines = class BlockLines {
4
5
  #fieldLength = 0;
5
6
  #fields;
7
+ #locatorField = 0;
6
8
  #relativeStart = Infinity;
7
9
  #sourceLength;
10
+ #lineEndingsNormalized = true;
8
11
  constructor(sourceLength = 0, lineCapacity = 4) {
9
12
  this.#sourceLength = sourceLength;
10
13
  this.#fields = new Int32Array(lineCapacity * 4);
@@ -13,7 +16,7 @@ var BlockLines = class BlockLines {
13
16
  const sourceLength = source.length;
14
17
  if (start > 0 || limit < sourceLength) source = source.slice(start, limit);
15
18
  const lines = new BlockLines(sourceLength, Math.min(source.length + 15 >>> 4, 16384));
16
- BlockLines.#scan(source, lines);
19
+ lines.#fieldLength = BlockLines.#scan(source, lines);
17
20
  if (start !== 0) lines.#shiftPositions(0, start);
18
21
  return lines;
19
22
  }
@@ -22,6 +25,7 @@ var BlockLines = class BlockLines {
22
25
  let start = 0;
23
26
  let lineFeed = source.indexOf("\n");
24
27
  let carriageReturn = source.indexOf("\r");
28
+ lines.#lineEndingsNormalized = carriageReturn < 0;
25
29
  let field = 0;
26
30
  let fields = lines.#fields;
27
31
  while (start < limit) {
@@ -44,7 +48,7 @@ var BlockLines = class BlockLines {
44
48
  field += 4;
45
49
  start = next;
46
50
  }
47
- lines.#fieldLength = field;
51
+ return field;
48
52
  }
49
53
  get length() {
50
54
  return this.#fieldLength / 4;
@@ -75,41 +79,45 @@ var BlockLines = class BlockLines {
75
79
  return low;
76
80
  }
77
81
  locator() {
78
- const fields = this.#fields;
82
+ this.#locatorField = 0;
83
+ return this;
84
+ }
85
+ normalizeLineEndings(value) {
86
+ return this.#lineEndingsNormalized || !value.includes("\r") ? value : value.replace(/\r\n|\r/g, "\n");
87
+ }
88
+ locationAt(offset) {
79
89
  const fieldLength = this.#fieldLength;
80
- const sourceLength = this.#sourceLength;
81
- if (fieldLength === 0) return (offset) => ({
90
+ if (fieldLength === 0) return {
82
91
  line: 1,
83
92
  column: 1,
84
93
  offset
85
- });
86
- const positionBase = sourceLength + 1;
87
- const lineCount = fieldLength / 4;
88
- let finalEnd = fields[fieldLength - 4 + 1];
89
- if (finalEnd < 0) finalEnd += positionBase;
90
- const endsInLineEnding = finalEnd < sourceLength;
91
- let field = 0;
92
- let line = 0;
93
- return (offset) => {
94
- if (offset === sourceLength && endsInLineEnding) return {
95
- line: lineCount + 1,
96
- column: 1,
97
- offset
98
- };
99
- while (field + 4 < fieldLength) {
100
- let nextStart = fields[field + 4 + 0];
101
- if (nextStart < 0) nextStart += positionBase;
102
- if (nextStart > offset) break;
103
- field += 4;
104
- line++;
105
- }
106
- let start = fields[field + 0];
107
- if (start < 0) start += positionBase;
108
- return {
109
- line: line + 1,
110
- column: offset - start + 1,
111
- offset
112
- };
94
+ };
95
+ const fields = this.#fields;
96
+ const sourceLength = this.#sourceLength;
97
+ if (offset === sourceLength && this.#position(fields[fieldLength - 4 + 1]) < sourceLength) return {
98
+ line: fieldLength / 4 + 1,
99
+ column: 1,
100
+ offset
101
+ };
102
+ let field = this.#locatorField;
103
+ let start = this.#position(fields[field + 0]);
104
+ while (field + 4 < fieldLength) {
105
+ const nextStart = this.#position(fields[field + 4 + 0]);
106
+ if (nextStart > offset) break;
107
+ field += 4;
108
+ start = nextStart;
109
+ }
110
+ this.#locatorField = field;
111
+ return {
112
+ line: field / 4 + 1,
113
+ column: offset - start + 1,
114
+ offset
115
+ };
116
+ }
117
+ positionAt(start, end) {
118
+ return {
119
+ start: this.locationAt(start),
120
+ end: this.locationAt(end)
113
121
  };
114
122
  }
115
123
  push(start, end, next, prefixColumns = 0, lazy = false) {
@@ -145,6 +153,7 @@ var BlockLines = class BlockLines {
145
153
  const fieldEnd = end * 4;
146
154
  result.#fields = this.#fields.slice(fieldStart, fieldEnd);
147
155
  result.#fieldLength = fieldEnd - fieldStart;
156
+ result.#lineEndingsNormalized = this.#lineEndingsNormalized;
148
157
  if (this.#relativeStart < end) result.#relativeStart = Math.max(0, this.#relativeStart - start);
149
158
  return result;
150
159
  }
@@ -157,12 +166,14 @@ var BlockLines = class BlockLines {
157
166
  if (delta === 0 && changed.length === suffix - prefixEnd) {
158
167
  const next = this.slice();
159
168
  for (let index = 0; index < changed.length; index++) next.#setAbsoluteFrom(prefixEnd + index, changed, index);
169
+ next.#lineEndingsNormalized &&= changed.#lineEndingsNormalized;
160
170
  return next;
161
171
  }
162
172
  const next = new BlockLines(nextSource.length, prefixEnd + changed.length + this.length - suffix);
163
173
  next.#appendAbsoluteRange(this, 0, prefixEnd);
164
174
  next.#appendRawRange(changed, 0, changed.length);
165
175
  next.#appendRelativeRange(this, suffix);
176
+ next.#lineEndingsNormalized = this.#lineEndingsNormalized && changed.#lineEndingsNormalized;
166
177
  return next;
167
178
  }
168
179
  pop() {
@@ -237,18 +248,23 @@ function indentOffset(source, lines, index) {
237
248
  let offset = lines.start(index);
238
249
  const limit = offset + 3 - lines.prefixColumns(index);
239
250
  const end = lines.end(index);
240
- while (offset < end && offset < limit && source[offset] === " ") offset++;
251
+ while (offset < end && offset < limit && source.charCodeAt(offset) === 32) offset++;
241
252
  return offset;
242
253
  }
243
254
  function lineIndentOffset(source, lines, index) {
244
255
  let offset = lines.start(index);
245
256
  const limit = offset + 3 - lines.prefixColumns(index);
246
257
  const end = lines.end(index);
247
- while (offset < end && offset < limit && source[offset] === " ") offset++;
248
- return offset > limit || source[offset] === " " || source[offset] === " " ? -1 : offset;
258
+ while (offset < end && offset < limit && source.charCodeAt(offset) === 32) offset++;
259
+ if (offset > limit) return -1;
260
+ const code = source.charCodeAt(offset);
261
+ return code === 32 || code === 9 ? -1 : offset;
249
262
  }
250
263
  function isBlank(source, lines, index) {
251
- for (let offset = lines.start(index), end = lines.end(index); offset < end; offset++) if (source[offset] !== " " && source[offset] !== " ") return false;
264
+ for (let offset = lines.start(index), end = lines.end(index); offset < end; offset++) {
265
+ const code = source.charCodeAt(offset);
266
+ if (code !== 32 && code !== 9) return false;
267
+ }
252
268
  return true;
253
269
  }
254
270
  function physicalColumnAt(source, offset) {
@@ -299,9 +315,6 @@ function contentAfterColumns(source, lines, index, columns) {
299
315
  prefixColumns: consumed - columns
300
316
  };
301
317
  }
302
- function normalizeLines(value) {
303
- return value.includes("\r") ? value.replace(/\r\n|\r/g, "\n") : value;
304
- }
305
318
  function removeIndent(value, columns) {
306
319
  let offset = 0;
307
320
  let consumed = 0;
@@ -319,7 +332,6 @@ const emptyArray = [];
319
332
  const emptySet = new Set();
320
333
  //#endregion
321
334
  //#region src/block/tokens.ts
322
- const blockTokenStride = 4;
323
335
  var BlockTokenStream = class {
324
336
  #definitionCounts;
325
337
  #definitionMembershipChanges;
@@ -343,7 +355,7 @@ var BlockTokenStream = class {
343
355
  this.#sourceLength = sourceLength;
344
356
  }
345
357
  get length() {
346
- return this.#fieldLength / blockTokenStride;
358
+ return this.#fieldLength / 4;
347
359
  }
348
360
  get sourceLength() {
349
361
  return this.#sourceLength;
@@ -353,12 +365,12 @@ var BlockTokenStream = class {
353
365
  }
354
366
  push(kind, start, end, meta) {
355
367
  const field = this.#fieldLength;
356
- this.#ensureCapacity(field + blockTokenStride);
357
- this.#fields[field] = kind;
368
+ this.#ensureCapacity(field + 4);
369
+ this.#fields[field + 0] = kind;
358
370
  this.#fields[field + 1] = start;
359
371
  this.#fields[field + 2] = end;
360
372
  this.#fields[field + 3] = 0;
361
- this.#fieldLength += blockTokenStride;
373
+ this.#fieldLength += 4;
362
374
  if (meta) {
363
375
  this.#metadata ??= new Map();
364
376
  this.#metadata.set(this.length - 1, meta);
@@ -371,7 +383,7 @@ var BlockTokenStream = class {
371
383
  const fieldLength = this.#fieldLength;
372
384
  const opens = [];
373
385
  let close = 0;
374
- for (let field = 0; field < fieldLength; field += blockTokenStride) {
386
+ for (let field = 0; field < fieldLength; field += 4) {
375
387
  const kind = fields[field];
376
388
  const rule = rules[kind];
377
389
  if (rule && rule.close !== 0) {
@@ -383,24 +395,24 @@ var BlockTokenStream = class {
383
395
  if (rule && !rule.block) {
384
396
  const start = field;
385
397
  do
386
- field += blockTokenStride;
398
+ field += 4;
387
399
  while (field < fieldLength && rules[fields[field]] === rule);
388
- fields[start + 3] = (field - start) / blockTokenStride;
389
- field -= blockTokenStride;
400
+ fields[start + 3] = (field - start) / 4;
401
+ field -= 4;
390
402
  continue;
391
403
  }
392
404
  if (close === kind) {
393
405
  const open = opens.pop();
394
406
  close = fields[open + 3];
395
- fields[open + 3] = (field - open) / blockTokenStride + 1;
407
+ fields[open + 3] = (field - open) / 4 + 1;
396
408
  continue;
397
409
  }
398
410
  if (rule) fields[field + 3] = 1;
399
411
  }
400
- if (opens.length > 0) throw new Error(`Block token stream did not close token ${fields[opens.at(-1)]}`);
412
+ if (close) throw new Error(`Block token stream did not close token ${fields[opens.at(-1)]}`);
401
413
  }
402
414
  nodeLength(index) {
403
- return this.#fields[index * blockTokenStride + 3];
415
+ return this.#fields[index * 4 + 3];
404
416
  }
405
417
  equalsAfterShift(index, next, nextIndex, delta, damageStart, damageEnd) {
406
418
  const start = this.start(index);
@@ -412,7 +424,6 @@ var BlockTokenStream = class {
412
424
  const nextMetadata = next.#metadata?.get(nextIndex);
413
425
  if (metadata !== nextMetadata) {
414
426
  if (metadata?.definitionKey !== nextMetadata?.definitionKey) return false;
415
- if ((metadata?.contentEndOffset ?? end - start) !== (nextMetadata?.contentEndOffset ?? nextEnd - nextStart)) return false;
416
427
  const value = metadata?.value;
417
428
  const nextValue = nextMetadata?.value;
418
429
  if (value !== nextValue && (value === null || typeof value !== "object" || nextValue === null || typeof nextValue !== "object")) return false;
@@ -446,30 +457,30 @@ var BlockTokenStream = class {
446
457
  oldStart
447
458
  };
448
459
  if (this.#relativeStart < end) for (let index = this.#relativeStart; index < end; index++) {
449
- const field = index * blockTokenStride;
460
+ const field = index * 4;
450
461
  this.#fields[field + 1] += this.#sourceLength + 1;
451
462
  this.#fields[field + 2] += this.#sourceLength + 1;
452
463
  }
453
464
  else if (this.#relativeStart > end) {
454
465
  const relativeEnd = Math.min(this.#relativeStart, previousLength);
455
466
  for (let index = end; index < relativeEnd; index++) {
456
- const field = index * blockTokenStride;
467
+ const field = index * 4;
457
468
  this.#fields[field + 1] -= this.#sourceLength + 1;
458
469
  this.#fields[field + 2] -= this.#sourceLength + 1;
459
470
  }
460
471
  }
461
472
  if (end === previousLength) {
462
- const fieldStart = start * blockTokenStride;
473
+ const fieldStart = start * 4;
463
474
  const fieldEnd = fieldStart + replacement.#fieldLength;
464
475
  this.#ensureCapacity(fieldEnd);
465
476
  this.#fields.set(replacement.#fields.subarray(0, replacement.#fieldLength), fieldStart);
466
477
  this.#fieldLength = fieldEnd;
467
478
  } else if (replacementLength === replacedLength) {
468
- const fieldStart = start * blockTokenStride;
479
+ const fieldStart = start * 4;
469
480
  this.#fields.set(replacement.#fields.subarray(0, replacement.#fieldLength), fieldStart);
470
481
  } else {
471
- const fieldStart = start * blockTokenStride;
472
- const oldFieldEnd = end * blockTokenStride;
482
+ const fieldStart = start * 4;
483
+ const oldFieldEnd = end * 4;
473
484
  const newFieldEnd = fieldStart + replacement.#fieldLength;
474
485
  const nextFieldLength = this.#fieldLength + newFieldEnd - oldFieldEnd;
475
486
  this.#ensureCapacity(nextFieldLength);
@@ -501,7 +512,7 @@ var BlockTokenStream = class {
501
512
  return change;
502
513
  }
503
514
  truncate(length) {
504
- this.#fieldLength = length * blockTokenStride;
515
+ this.#fieldLength = length * 4;
505
516
  if (this.#metadata) {
506
517
  for (const [index, value] of this.#metadata) if (index >= length) {
507
518
  this.#updateDefinitionCount(value.definitionKey, -1, false);
@@ -511,23 +522,24 @@ var BlockTokenStream = class {
511
522
  }
512
523
  }
513
524
  kind(index) {
514
- return this.#fields[index * blockTokenStride];
525
+ return this.#fields[index * 4];
515
526
  }
516
527
  setKind(index, kind) {
517
- this.#fields[index * blockTokenStride] = kind;
528
+ this.#fields[index * 4] = kind;
518
529
  }
519
530
  start(index) {
520
- return this.#position(this.#fields[index * blockTokenStride + 1]);
531
+ return this.#position(this.#fields[index * 4 + 1]);
521
532
  }
522
533
  setStart(index, start) {
523
- this.#fields[index * blockTokenStride + 1] = start;
534
+ this.#fields[index * 4 + 1] = start;
524
535
  }
525
536
  end(index) {
526
- return this.#position(this.#fields[index * blockTokenStride + 2]);
537
+ return this.#position(this.#fields[index * 4 + 2]);
527
538
  }
528
- contentEnd(index) {
529
- const offset = this.#metadata?.get(index)?.contentEndOffset;
530
- return offset === void 0 ? this.end(index) : this.start(index) + offset;
539
+ contentEnd(source, index) {
540
+ const end = this.end(index);
541
+ const last = source.charCodeAt(end - 1);
542
+ return last === 10 ? end - (source.charCodeAt(end - 2) === 13 ? 2 : 1) : last === 13 ? end - 1 : end;
531
543
  }
532
544
  text(source, index) {
533
545
  return this.#metadata?.get(index)?.text ?? source.slice(this.start(index), this.end(index));
@@ -567,8 +579,6 @@ function appendLogicalToken(out, kind, source, lines, start, end, value) {
567
579
  const tokenStart = lines.start(start);
568
580
  const lastLine = end - 1;
569
581
  const tokenEnd = lines.next(lastLine);
570
- const contentEnd = lines.end(lastLine);
571
- const contentEndOffset = contentEnd === tokenEnd ? void 0 : contentEnd - tokenStart;
572
582
  const previous = source[tokenStart - 1];
573
583
  let canSliceSource = lines.prefixColumns(start) === 0 && (tokenStart === 0 || previous === "\n" || previous === "\r");
574
584
  let previousLineEnd = lines.next(start);
@@ -585,16 +595,14 @@ function appendLogicalToken(out, kind, source, lines, start, end, value) {
585
595
  for (let index = 0; index < count; index++) logicalLines[index] = logicalLine(source, lines, start + index);
586
596
  text = logicalLines.join("");
587
597
  }
588
- out.push(kind, tokenStart, tokenEnd, contentEndOffset === void 0 && text === void 0 && value === void 0 ? void 0 : {
589
- contentEndOffset,
598
+ out.push(kind, tokenStart, tokenEnd, text === void 0 && value === void 0 ? void 0 : {
590
599
  text,
591
600
  value
592
601
  });
593
602
  }
594
603
  //#endregion
595
604
  //#region src/block/scanner.ts
596
- function scanBlock(profile, context, source, lines, start, out) {
597
- const contentOffset = lineIndentOffset(source, lines, start);
605
+ function scanBlock(profile, context, source, lines, start, contentOffset, out) {
598
606
  const starts = profile.starts[contentOffset < 0 ? -1 : source.charCodeAt(contentOffset)];
599
607
  if (starts) for (const resolve of starts) {
600
608
  const end = resolve(source, lines, start, contentOffset, out, context);
@@ -608,13 +616,23 @@ function scanBlock(profile, context, source, lines, start, out) {
608
616
  }
609
617
  function scanBlockLines(profile, context, source, lines, out, visit) {
610
618
  for (let index = 0; index < lines.length;) {
611
- if (isBlank(source, lines, index)) {
619
+ let contentOffset = lines.start(index);
620
+ const lineEnd = lines.end(index);
621
+ let columns = lines.prefixColumns(index);
622
+ while (contentOffset < lineEnd) {
623
+ const code = source.charCodeAt(contentOffset);
624
+ if (code !== 32 && code !== 9) break;
625
+ columns += code === 32 ? 1 : 4 - columns % 4;
626
+ contentOffset++;
627
+ }
628
+ if (contentOffset === lineEnd) {
612
629
  index++;
613
630
  continue;
614
631
  }
632
+ if (columns > 3) contentOffset = -1;
615
633
  const lineStart = index;
616
634
  const tokenStart = out.length;
617
- index = scanBlock(profile, context, source, lines, index, out);
635
+ index = scanBlock(profile, context, source, lines, index, contentOffset, out);
618
636
  if (visit(lineStart, index, tokenStart, out.length)) return;
619
637
  }
620
638
  }
@@ -822,213 +840,28 @@ var BlockScanner = class {
822
840
  };
823
841
  }
824
842
  };
825
- function inlineTokenCount(tokens) {
826
- return tokens.length / 4;
827
- }
828
- function inlineTokenKind(tokens, index) {
829
- return tokens[index * 4];
830
- }
831
- function inlineTokenStart(tokens, index) {
832
- return tokens[index * 4 + 1];
833
- }
834
- function inlineTokenEnd(tokens, index) {
835
- return tokens[index * 4 + 2];
836
- }
837
- function inlineTokenData(tokens, index) {
838
- return tokens[index * 4 + 3];
839
- }
840
- function setInlineTokenData(tokens, index, data) {
841
- tokens[index * 4 + 3] = data;
842
- }
843
- function inlineTokenText(source, tokens, index) {
844
- return source.slice(inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index));
845
- }
846
- function appendInlineToken(target, kind, start, end, data = 0) {
847
- target.push(kind, start, end, data);
848
- }
849
- function copyInlineToken(target, tokens, index) {
850
- const offset = index * 4;
851
- target.push(tokens[offset], tokens[offset + 1], tokens[offset + 2], tokens[offset + 3]);
852
- }
853
- //#endregion
854
- //#region src/fragment/node.ts
855
- function extendSpan(value, end) {
856
- const node = value;
857
- node.position.end = Math.max(node.position.end, end);
858
- }
859
- function firstChildStart(children) {
860
- const first = children[0];
861
- if (!first) throw new Error("mdast container unexpectedly has no children");
862
- return first.position.start;
863
- }
864
- function lastChildEnd(children, emptyEnd) {
865
- const last = children.at(-1);
866
- return last ? last.position.end : emptyEnd;
867
- }
868
- //#endregion
869
- //#region src/fragment/inline.ts
870
- function lineStart(source, offset) {
871
- while (offset > 0) {
872
- const character = source.charCodeAt(--offset);
873
- if (character === 10 || character === 13) return offset + 1;
874
- }
875
- return 0;
876
- }
877
- function lineEndingStart(source, offset) {
878
- const start = lineStart(source, offset);
879
- if (start === 0) return offset;
880
- return source[start - 1] === "\n" && source[start - 2] === "\r" ? start - 2 : start - 1;
881
- }
882
- function countTrailingSpaces(value) {
883
- let offset = value.length;
884
- while (offset > 0 && (value[offset - 1] === " " || value[offset - 1] === " ")) offset--;
885
- return value.length - offset;
886
- }
887
- function appendText(output, value, span) {
888
- const previous = output.children.at(-1);
889
- if (output.trailingSpaces >= 0) {
890
- const trailingSpaces = countTrailingSpaces(value);
891
- output.trailingSpaces = trailingSpaces === value.length && previous?.type === "text" && !("attributes" in previous) ? output.trailingSpaces + trailingSpaces : trailingSpaces;
892
- }
893
- if (previous?.type === "text" && !("attributes" in previous)) {
894
- previous.value += value;
895
- extendSpan(previous, span.end);
896
- } else output.children.push({
897
- type: "text",
898
- value,
899
- position: span
900
- });
901
- }
902
- function appendChild(output, value) {
903
- if (value.type === "text") appendText(output, value.value, value.position);
904
- else {
905
- output.children.push(value);
906
- if (output.trailingSpaces > 0) output.trailingSpaces = 0;
907
- }
908
- }
909
- function appendGap(output, context, start, end) {
910
- appendText(output, context.view.text.slice(start, end), context.view.mapSpan(start, end));
911
- }
912
- function appendToken(output, context, tokenIndex, value) {
913
- const newline = value.type === "text" && value.value.startsWith("\n");
914
- if (output.gapStart >= 0) {
915
- const gapStart = output.gapStart;
916
- output.gapStart = -1;
917
- const gapEnd = newline ? lineEndingStart(context.view.text, output.gapEnd) : output.gapEnd;
918
- if (gapEnd > gapStart) appendGap(output, context, gapStart, gapEnd);
919
- }
920
- if (newline) {
921
- const viewStart = inlineTokenStart(context.tokens, tokenIndex);
922
- const previous = output.children.at(-1);
923
- if (previous?.type === "break") {
924
- const viewLineStart = lineStart(context.view.text, viewStart);
925
- extendSpan(previous, viewLineStart === 0 ? context.view.mapPoint(0) : context.view.mapPoint(viewLineStart - 1) + 1);
926
- return;
927
- }
928
- value.position.start = context.view.mapPoint(lineEndingStart(context.view.text, viewStart));
929
- if (previous?.type === "text") {
930
- if (output.trailingSpaces < 0) previous.value = previous.value.slice(0, previous.value.length - countTrailingSpaces(previous.value));
931
- else if (output.trailingSpaces > 0) {
932
- previous.value = previous.value.slice(0, -output.trailingSpaces);
933
- output.trailingSpaces = 0;
934
- }
935
- }
936
- }
937
- appendChild(output, value);
938
- }
939
- function appendLeaf(tokenIndex, handle, sourceSpan, output, context) {
940
- const value = handle(tokenIndex, sourceSpan, context, output);
941
- if (typeof value === "boolean") return value;
942
- appendToken(output, context, tokenIndex, value);
943
- return true;
944
- }
945
- function appendRange(startToken, endToken, context, output, closeKind = 0) {
946
- let index = startToken;
947
- while (index < endToken) {
948
- const kind = inlineTokenKind(context.tokens, index);
949
- if (kind === closeKind) break;
950
- const syntaxOffset = kind * 2;
951
- const semanticCloseKind = context.syntaxByKind[syntaxOffset];
952
- const build = context.buildByKind[kind];
953
- const childStart = inlineTokenStart(context.tokens, index);
954
- if (childStart > output.cursor) {
955
- output.gapStart = output.cursor;
956
- output.gapEnd = childStart;
957
- }
958
- if (semanticCloseKind !== void 0) {
959
- index = appendSemantic(index, endToken, output, context, build, semanticCloseKind, context.syntaxByKind[syntaxOffset + 1]);
960
- continue;
961
- }
962
- const childEnd = inlineTokenEnd(context.tokens, index);
963
- if (appendLeaf(index, build, context.view.mapSpan(childStart, childEnd), output, context)) output.cursor = childEnd;
964
- index++;
965
- }
966
- if (index < endToken) {
967
- const contentEnd = inlineTokenStart(context.tokens, index);
968
- if (contentEnd > output.cursor) appendGap(output, context, output.cursor, contentEnd);
969
- } else if (closeKind === 0 && context.view.text.length > output.cursor) appendGap(output, context, output.cursor, context.view.text.length);
970
- return index;
971
- }
972
- function appendSemantic(openToken, endToken, output, context, build, closeKind, contentOpenKind) {
973
- let closeToken = openToken;
974
- let next = openToken + 1;
975
- const children = [];
976
- if (contentOpenKind === 0 || next < endToken && inlineTokenKind(context.tokens, next) === contentOpenKind) {
977
- const childOutput = {
978
- children,
979
- cursor: inlineTokenEnd(context.tokens, contentOpenKind === 0 ? openToken : next++),
980
- gapEnd: -1,
981
- gapStart: -1,
982
- trailingSpaces: output.trailingSpaces < 0 ? -1 : 0
983
- };
984
- closeToken = appendRange(next, endToken, context, childOutput, closeKind);
985
- }
986
- const childStart = inlineTokenStart(context.tokens, openToken);
987
- const childEnd = inlineTokenEnd(context.tokens, closeToken);
988
- appendToken(output, context, openToken, build(openToken, closeToken, context.view.mapSpan(childStart, childEnd), children, context));
989
- output.cursor = childEnd;
990
- return closeToken + 1;
991
- }
992
- function buildInlineFragment(tokenStart, blockRule, context) {
993
- const region = context.cursor.take(tokenStart);
994
- if (!region) return { children: [] };
995
- const { tokens, view } = region;
996
- const inlineContext = {
997
- blockRule,
998
- buildByKind: context.profile.buildByKind,
999
- syntaxByKind: context.profile.syntaxByKind,
1000
- tokens,
1001
- view
1002
- };
1003
- const result = {
1004
- children: [],
1005
- cursor: 0,
1006
- gapEnd: -1,
1007
- gapStart: -1,
1008
- trailingSpaces: tokens.length && (view.text.includes("\n") || view.text.includes("\r")) ? 0 : -1
1009
- };
1010
- appendRange(0, inlineTokenCount(tokens), inlineContext, result);
1011
- const last = result.children.at(-1);
1012
- if (last?.type === "text") {
1013
- const removed = result.trailingSpaces < 0 ? countTrailingSpaces(last.value) : result.trailingSpaces;
1014
- last.value = last.value.slice(0, last.value.length - removed);
1015
- last.position.end -= removed;
1016
- if (!last.value) result.children.pop();
1017
- }
1018
- return result;
1019
- }
1020
843
  //#endregion
1021
844
  //#region src/fragment/block.ts
1022
845
  function blockEnd(tokenStart, context) {
1023
846
  const tokens = context.structure.tokens;
1024
- return tokens.contentEnd(tokenStart + tokens.nodeLength(tokenStart) - 1);
847
+ const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
848
+ return tokens.nodeLength(close) === 0 ? tokens.end(close) : tokens.contentEnd(context.source, close);
1025
849
  }
1026
- const buildBlockNode = (tokenStart, context) => {
1027
- const rule = context.structure.ruleOf(tokenStart);
1028
- const build = rule.build;
1029
- return rule.inlineContent ? build(tokenStart, context, buildInlineFragment(tokenStart, rule.rule, context)) : build(tokenStart, context);
1030
- };
1031
- const buildBlockChildren = (tokenStart, context) => {
850
+ function leafBlockPosition(tokenStart, context) {
851
+ const tokens = context.structure.tokens;
852
+ const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
853
+ return context.locator.positionAt(tokens.start(tokenStart), tokens.contentEnd(context.source, close));
854
+ }
855
+ function fencedBlockPosition(tokenStart, block, context) {
856
+ const tokens = context.structure.tokens;
857
+ const end = tokens.end(tokenStart);
858
+ const positionEnd = block.closed || end < tokens.sourceLength ? blockEnd(tokenStart, context) : end;
859
+ return context.locator.positionAt(tokens.start(tokenStart) + block.markerOffset, positionEnd);
860
+ }
861
+ function buildBlockNode(tokenStart, context) {
862
+ return context.structure.ruleOf(tokenStart).build(tokenStart, context);
863
+ }
864
+ function buildBlockChildren(tokenStart, context) {
1032
865
  const structure = context.structure;
1033
866
  const tokens = structure.tokens;
1034
867
  const children = [];
@@ -1039,82 +872,7 @@ const buildBlockChildren = (tokenStart, context) => {
1039
872
  child += length || 1;
1040
873
  }
1041
874
  return children;
1042
- };
1043
- //#endregion
1044
- //#region src/inline/region.ts
1045
- function hasDefinition(key) {
1046
- (this.dependencies ??= new Set()).add(key);
1047
- return this.definitionContext.hasDefinition(key);
1048
875
  }
1049
- var InlineRegion = class {
1050
- #definitionDependencies;
1051
- #rawTokens;
1052
- #profile;
1053
- #tokens;
1054
- tokenStart;
1055
- view;
1056
- constructor(profile, binding, definitionContext) {
1057
- this.#profile = profile;
1058
- this.tokenStart = binding.tokenStart;
1059
- this.view = binding.view;
1060
- this.#updateTokens(binding.view.text, definitionContext, emptySet);
1061
- }
1062
- get tokens() {
1063
- return this.#tokens;
1064
- }
1065
- update(binding, definitionContext, definitionMembershipChanges) {
1066
- this.#updateTokens(binding.view.text, definitionContext, definitionMembershipChanges);
1067
- this.tokenStart = binding.tokenStart;
1068
- this.view = binding.view;
1069
- return this;
1070
- }
1071
- updateDefinitions(definitionContext, definitionMembershipChanges) {
1072
- return this.#updateTokens(this.view.text, definitionContext, definitionMembershipChanges);
1073
- }
1074
- shift(delta, tokenDelta) {
1075
- this.tokenStart += tokenDelta;
1076
- this.view.shift(delta);
1077
- }
1078
- #dependenciesChanged(definitionMembershipChanges) {
1079
- const dependencies = this.#definitionDependencies;
1080
- if (dependencies.size < definitionMembershipChanges.size) {
1081
- for (const key of dependencies) if (definitionMembershipChanges.has(key)) return true;
1082
- } else for (const key of definitionMembershipChanges) if (dependencies.has(key)) return true;
1083
- return false;
1084
- }
1085
- #updateTokens(source, definitionContext, definitionMembershipChanges) {
1086
- const previousTokens = this.#rawTokens;
1087
- const sourceUnchanged = previousTokens !== void 0 && source === this.view.text;
1088
- if (sourceUnchanged && !this.#dependenciesChanged(definitionMembershipChanges)) return false;
1089
- const context = {
1090
- definitionContext,
1091
- hasDefinition
1092
- };
1093
- const rawTokens = sourceUnchanged ? previousTokens : this.#profile.tokenize(source);
1094
- const tokens = this.#profile.resolve(source, rawTokens, context);
1095
- this.#definitionDependencies = context.dependencies ?? emptySet;
1096
- this.#rawTokens = rawTokens;
1097
- this.#tokens = tokens;
1098
- return true;
1099
- }
1100
- };
1101
- var InlineRegionCursor = class {
1102
- #index = 0;
1103
- #regions;
1104
- constructor(regions = emptyArray) {
1105
- this.#regions = regions;
1106
- }
1107
- reset(regions) {
1108
- this.#index = 0;
1109
- this.#regions = regions;
1110
- }
1111
- take(tokenStart) {
1112
- const region = this.#regions[this.#index];
1113
- if (region?.tokenStart !== tokenStart) return;
1114
- this.#index++;
1115
- return region;
1116
- }
1117
- };
1118
876
  //#endregion
1119
877
  //#region src/source-view.ts
1120
878
  var ContiguousSourceView = class {
@@ -1199,6 +957,115 @@ var SegmentedSourceView = class {
1199
957
  }
1200
958
  };
1201
959
  //#endregion
960
+ //#region src/inline/region.ts
961
+ function hasDefinition(key) {
962
+ (this.dependencies ??= new Set()).add(key);
963
+ return this.definitionContext.hasDefinition(key);
964
+ }
965
+ var InlineRegion = class {
966
+ #definitionDependencies;
967
+ #rawTokens;
968
+ #profile;
969
+ #tokens;
970
+ tokenStart;
971
+ view;
972
+ constructor(profile, binding, definitionContext) {
973
+ this.#profile = profile;
974
+ this.tokenStart = binding.tokenStart;
975
+ this.view = binding.view;
976
+ this.#updateTokens(binding.view.text, definitionContext, emptySet);
977
+ }
978
+ get tokens() {
979
+ return this.#tokens;
980
+ }
981
+ update(binding, definitionContext, definitionMembershipChanges) {
982
+ this.#updateTokens(binding.view.text, definitionContext, definitionMembershipChanges);
983
+ this.tokenStart = binding.tokenStart;
984
+ this.view = binding.view;
985
+ return this;
986
+ }
987
+ updateDefinitions(definitionContext, definitionMembershipChanges) {
988
+ return this.#updateTokens(this.view.text, definitionContext, definitionMembershipChanges);
989
+ }
990
+ shift(delta, tokenDelta) {
991
+ this.tokenStart += tokenDelta;
992
+ this.view.shift(delta);
993
+ }
994
+ #dependenciesChanged(definitionMembershipChanges) {
995
+ const dependencies = this.#definitionDependencies;
996
+ if (dependencies.size < definitionMembershipChanges.size) {
997
+ for (const key of dependencies) if (definitionMembershipChanges.has(key)) return true;
998
+ } else for (const key of definitionMembershipChanges) if (dependencies.has(key)) return true;
999
+ return false;
1000
+ }
1001
+ #updateTokens(source, definitionContext, definitionMembershipChanges) {
1002
+ const previousTokens = this.#rawTokens;
1003
+ const sourceUnchanged = previousTokens !== void 0 && source === this.view.text;
1004
+ if (sourceUnchanged && !this.#dependenciesChanged(definitionMembershipChanges)) return false;
1005
+ const context = {
1006
+ definitionContext,
1007
+ hasDefinition
1008
+ };
1009
+ const rawTokens = sourceUnchanged ? previousTokens : this.#profile.tokenize(source);
1010
+ const tokens = this.#profile.resolve(source, rawTokens, context);
1011
+ this.#definitionDependencies = context.dependencies ?? emptySet;
1012
+ this.#rawTokens = rawTokens;
1013
+ this.#tokens = tokens;
1014
+ return true;
1015
+ }
1016
+ };
1017
+ var InlineRegionCursor = class {
1018
+ #index = 0;
1019
+ #regions;
1020
+ constructor(regions = emptyArray) {
1021
+ this.#regions = regions;
1022
+ }
1023
+ reset(regions) {
1024
+ this.#index = 0;
1025
+ this.#regions = regions;
1026
+ }
1027
+ take(tokenStart) {
1028
+ const region = this.#regions[this.#index];
1029
+ if (region?.tokenStart !== tokenStart) return;
1030
+ this.#index++;
1031
+ return region;
1032
+ }
1033
+ };
1034
+ function resolveInlineRegion(source, profile, tokens, tokenStart) {
1035
+ const view = inlineViewOf(source, tokens, tokenStart, tokens.nodeLength(tokenStart));
1036
+ if (!view) return;
1037
+ const text = view.text;
1038
+ return {
1039
+ tokenStart,
1040
+ tokens: profile.resolve(text, profile.tokenize(text), tokens),
1041
+ view
1042
+ };
1043
+ }
1044
+ function inlineViewOf(source, tokens, tokenStart, nodeLength) {
1045
+ let firstStart = -1;
1046
+ let firstEnd = -1;
1047
+ let ranges;
1048
+ const tokenEnd = tokenStart + nodeLength;
1049
+ for (let token = tokenStart + 1; token < tokenEnd; token++) {
1050
+ if (tokens.kind(token) !== 1) continue;
1051
+ const start = tokens.start(token);
1052
+ const end = tokens.end(token);
1053
+ if (firstStart < 0) {
1054
+ firstStart = start;
1055
+ firstEnd = end;
1056
+ } else if (start === firstEnd) {
1057
+ firstEnd = end;
1058
+ if (ranges) ranges[ranges.length - 1] = end;
1059
+ } else {
1060
+ ranges ??= [firstStart, firstEnd];
1061
+ ranges.push(start, end);
1062
+ firstEnd = end;
1063
+ }
1064
+ }
1065
+ if (ranges) return new SegmentedSourceView(source, ranges);
1066
+ if (firstStart >= 0) return new ContiguousSourceView(source, firstStart, firstEnd);
1067
+ }
1068
+ //#endregion
1202
1069
  //#region src/syntax-state.ts
1203
1070
  var SyntaxState = class {
1204
1071
  #profile;
@@ -1279,65 +1146,17 @@ var SyntaxState = class {
1279
1146
  for (let index = start; index < end; index++) {
1280
1147
  const regions = regionsByBlock[index];
1281
1148
  let changed = false;
1282
- for (const region of regions) if (region.updateDefinitions(tokens, definitionMembershipChanges)) changed = true;
1283
- if (changed) (invalidatedBlocks ??= []).push(index);
1284
- }
1285
- };
1286
- refreshDefinitions(0, stableBlockCount);
1287
- refreshDefinitions(newRecordEnd, regionsByBlock.length);
1288
- }
1289
- this.#regionsByBlock = regionsByBlock;
1290
- return invalidatedBlocks ?? emptyArray;
1291
- }
1292
- };
1293
- function resolveInlineRegions(source, profile, structure) {
1294
- const regions = [];
1295
- const tokens = structure.tokens;
1296
- for (const record of structure.records) {
1297
- const tokenStart = record.tokenStart;
1298
- const tokenEnd = tokenStart + tokens.nodeLength(tokenStart);
1299
- for (let token = tokenStart; token < tokenEnd; token++) {
1300
- const nodeLength = tokens.nodeLength(token);
1301
- if (nodeLength === 0) continue;
1302
- if (structure.ruleOf(token).inlineContent) {
1303
- const inlineView = inlineViewOf(source, tokens, token, nodeLength);
1304
- if (inlineView) {
1305
- const text = inlineView.text;
1306
- regions.push({
1307
- tokenStart: token,
1308
- tokens: profile.resolve(text, profile.tokenize(text), tokens),
1309
- view: inlineView
1310
- });
1311
- }
1312
- token += nodeLength - 1;
1313
- }
1314
- }
1315
- }
1316
- return regions;
1317
- }
1318
- function inlineViewOf(source, tokens, tokenStart, nodeLength) {
1319
- let firstStart = -1;
1320
- let firstEnd = -1;
1321
- let ranges;
1322
- const tokenEnd = tokenStart + nodeLength;
1323
- for (let token = tokenStart + 1; token < tokenEnd; token++) if (tokens.kind(token) === 1) {
1324
- const start = tokens.start(token);
1325
- const end = tokens.end(token);
1326
- if (firstStart < 0) {
1327
- firstStart = start;
1328
- firstEnd = end;
1329
- } else if (start === firstEnd) {
1330
- firstEnd = end;
1331
- if (ranges) ranges[ranges.length - 1] = end;
1332
- } else {
1333
- ranges ??= [firstStart, firstEnd];
1334
- ranges.push(start, end);
1335
- firstEnd = end;
1149
+ for (const region of regions) if (region.updateDefinitions(tokens, definitionMembershipChanges)) changed = true;
1150
+ if (changed) (invalidatedBlocks ??= []).push(index);
1151
+ }
1152
+ };
1153
+ refreshDefinitions(0, stableBlockCount);
1154
+ refreshDefinitions(newRecordEnd, regionsByBlock.length);
1336
1155
  }
1156
+ this.#regionsByBlock = regionsByBlock;
1157
+ return invalidatedBlocks ?? emptyArray;
1337
1158
  }
1338
- if (ranges) return new SegmentedSourceView(source, ranges);
1339
- if (firstStart >= 0) return new ContiguousSourceView(source, firstStart, firstEnd);
1340
- }
1159
+ };
1341
1160
  //#endregion
1342
1161
  //#region src/document.ts
1343
1162
  function applyEdits(source, edits) {
@@ -1361,18 +1180,9 @@ function applyEdits(source, edits) {
1361
1180
  offsetDelta: delta
1362
1181
  };
1363
1182
  }
1364
- function materializeNode(value, locate) {
1365
- const { position, children } = value;
1366
- const result = position;
1367
- result.start = locate(position.start);
1368
- if (children) for (const child of children) materializeNode(child, locate);
1369
- result.end = locate(position.end);
1370
- }
1371
- function buildTreeBlock(record, regions, context, locate) {
1183
+ function buildTreeBlock(record, regions, context) {
1372
1184
  context.cursor.reset(regions);
1373
- const node = buildBlockNode(record.tokenStart, context);
1374
- materializeNode(node, locate);
1375
- return node;
1185
+ return buildBlockNode(record.tokenStart, context);
1376
1186
  }
1377
1187
  function shiftLocation(location, shift) {
1378
1188
  if (location.line === shift.columnLine) location.column += shift.column;
@@ -1423,15 +1233,17 @@ var DocumentImpl = class {
1423
1233
  #updateTree(invalidatedBlocks, change) {
1424
1234
  const records = this.#blockScanner.records;
1425
1235
  const regionsByBlock = this.#syntaxState.regionsByBlock();
1236
+ const locator = this.#blockScanner.locator();
1426
1237
  const context = {
1427
- structure: this.#blockScanner,
1238
+ inlineContext: void 0,
1428
1239
  cursor: new InlineRegionCursor(),
1240
+ locator,
1241
+ structure: this.#blockScanner,
1429
1242
  profile: this.#profile.inline,
1430
1243
  source: this.#source
1431
1244
  };
1432
- const locate = this.#blockScanner.locator();
1433
1245
  const root = this.#tree;
1434
- const start = locate(0);
1246
+ const start = locator.locationAt(0);
1435
1247
  const children = root.children;
1436
1248
  const rebuildStart = change?.stableBlockCount ?? 0;
1437
1249
  const oldRebuildEnd = change?.oldRecordEnd ?? 0;
@@ -1450,19 +1262,19 @@ var DocumentImpl = class {
1450
1262
  let invalidatedIndex = 0;
1451
1263
  while (invalidatedIndex < invalidatedBlocks.length && invalidatedBlocks[invalidatedIndex] < rebuildStart) {
1452
1264
  const index = invalidatedBlocks[invalidatedIndex++];
1453
- children[index] = buildTreeBlock(records[index], regionsByBlock[index], context, locate);
1265
+ children[index] = buildTreeBlock(records[index], regionsByBlock[index], context);
1454
1266
  }
1455
- for (let index = rebuildStart; index < newRebuildEnd; index++) children[index] = buildTreeBlock(records[index], regionsByBlock[index], context, locate);
1267
+ for (let index = rebuildStart; index < newRebuildEnd; index++) children[index] = buildTreeBlock(records[index], regionsByBlock[index], context);
1456
1268
  let positionShift;
1457
1269
  for (let index = newRebuildEnd; index < records.length; index++) {
1458
1270
  if (invalidatedBlocks[invalidatedIndex] === index) {
1459
- children[index] = buildTreeBlock(records[index], regionsByBlock[index], context, locate);
1271
+ children[index] = buildTreeBlock(records[index], regionsByBlock[index], context);
1460
1272
  invalidatedIndex++;
1461
1273
  continue;
1462
1274
  }
1463
1275
  if (!positionShift) {
1464
1276
  const previousStart = children[index].position.start;
1465
- const nextStart = locate(previousStart.offset + suffixOffsetDelta);
1277
+ const nextStart = locator.locationAt(previousStart.offset + suffixOffsetDelta);
1466
1278
  if (nextStart.offset === previousStart.offset && nextStart.line === previousStart.line && nextStart.column === previousStart.column) break;
1467
1279
  positionShift = {
1468
1280
  offset: nextStart.offset - previousStart.offset,
@@ -1475,33 +1287,34 @@ var DocumentImpl = class {
1475
1287
  }
1476
1288
  while (invalidatedIndex < invalidatedBlocks.length) {
1477
1289
  const index = invalidatedBlocks[invalidatedIndex++];
1478
- children[index] = buildTreeBlock(records[index], regionsByBlock[index], context, locate);
1290
+ children[index] = buildTreeBlock(records[index], regionsByBlock[index], context);
1479
1291
  }
1480
1292
  root.position = {
1481
1293
  start,
1482
- end: locate(this.#source.length)
1294
+ end: locator.locationAt(this.#source.length)
1483
1295
  };
1484
1296
  }
1485
1297
  static parse(source, profile, blockScanner) {
1486
1298
  blockScanner.scan(source);
1299
+ const locator = blockScanner.locator();
1487
1300
  const context = {
1301
+ inlineContext: void 0,
1302
+ cursor: void 0,
1303
+ locator,
1488
1304
  structure: blockScanner,
1489
- cursor: new InlineRegionCursor(resolveInlineRegions(source, profile.inline, blockScanner)),
1490
1305
  profile: profile.inline,
1491
1306
  source
1492
1307
  };
1493
- const locate = blockScanner.locator();
1494
- const start = locate(0);
1308
+ const start = locator.locationAt(0);
1309
+ const records = blockScanner.records;
1310
+ const children = new Array(records.length);
1311
+ for (let index = 0; index < records.length; index++) children[index] = buildBlockNode(records[index].tokenStart, context);
1495
1312
  return {
1496
1313
  type: "root",
1497
- children: blockScanner.records.map((block) => {
1498
- const node = buildBlockNode(block.tokenStart, context);
1499
- materializeNode(node, locate);
1500
- return node;
1501
- }),
1314
+ children,
1502
1315
  position: {
1503
1316
  start,
1504
- end: locate(source.length)
1317
+ end: locator.locationAt(source.length)
1505
1318
  }
1506
1319
  };
1507
1320
  }
@@ -1532,7 +1345,6 @@ function compileBlockProfile(features) {
1532
1345
  block: syntax.kind === "block" || syntax.kind === "leaf",
1533
1346
  close: syntax.kind === "block" || syntax.kind === "frame" ? syntax.close : 0,
1534
1347
  inlineContent: registration.inlineContent === true,
1535
- rule: registration.rule,
1536
1348
  build: registration.build
1537
1349
  };
1538
1350
  ruleByBlockRule[registration.rule] = rule;
@@ -1559,6 +1371,7 @@ function compileBlockProfile(features) {
1559
1371
  }
1560
1372
  //#endregion
1561
1373
  //#region src/inline/lexer.ts
1374
+ const scannerDispatchFactories = new Map();
1562
1375
  function matchInlinePatternEnd(pattern, source, start) {
1563
1376
  pattern.lastIndex = start;
1564
1377
  return pattern.test(source) ? pattern.lastIndex : -1;
@@ -1569,37 +1382,19 @@ function inlineMarkerRunEnd(source, start) {
1569
1382
  while (source.charCodeAt(end) === marker) end++;
1570
1383
  return end;
1571
1384
  }
1572
- function tokenize(source, textBoundary, scannerByCode) {
1385
+ function tokenize(source, textBoundary, scanBoundary) {
1573
1386
  const tokens = [];
1574
- let hasContentLine = false;
1387
+ const end = source.length;
1388
+ let lineStart = 0;
1575
1389
  let offset = 0;
1576
- let lineStart = true;
1577
- while (offset < source.length) {
1578
- if (lineStart) {
1390
+ while (offset < end) {
1391
+ if (lineStart >= 0) {
1579
1392
  let content = offset;
1580
1393
  while (source.charCodeAt(content) === 32) content++;
1581
- if (content === source.length) break;
1582
- let code = source.charCodeAt(content);
1583
- if (code === 10 || code === 13) {
1584
- offset = content + 1;
1585
- if (code === 13 && source.charCodeAt(offset) === 10) offset++;
1586
- continue;
1587
- }
1588
- if (code === 9) {
1589
- let blankEnd = content;
1590
- while (source.charCodeAt(blankEnd) === 9 || source.charCodeAt(blankEnd) === 32) blankEnd++;
1591
- code = source.charCodeAt(blankEnd);
1592
- if (blankEnd === source.length || code === 10 || code === 13) {
1593
- offset = blankEnd + (blankEnd < source.length ? 1 : 0);
1594
- if (code === 13 && source.charCodeAt(offset) === 10) offset++;
1595
- continue;
1596
- }
1597
- }
1394
+ if (content === end) break;
1598
1395
  offset = content;
1599
- if (hasContentLine) tokens.push(5, offset, offset, 0);
1600
- hasContentLine = true;
1601
- lineStart = false;
1602
- continue;
1396
+ if (lineStart > 0) tokens.push(5, offset, offset, lineStart);
1397
+ lineStart = -1;
1603
1398
  }
1604
1399
  const code = source.charCodeAt(offset);
1605
1400
  if (code === 10 || code === 13) {
@@ -1610,23 +1405,29 @@ function tokenize(source, textBoundary, scannerByCode) {
1610
1405
  }
1611
1406
  offset++;
1612
1407
  if (code === 13 && source.charCodeAt(offset) === 10) offset++;
1613
- lineStart = true;
1408
+ lineStart = offset;
1614
1409
  continue;
1615
1410
  }
1616
- const scan = scannerByCode[code];
1617
- if (scan) {
1618
- const scannedEnd = scan(source, offset, tokens);
1619
- if (scannedEnd > offset) {
1620
- offset = scannedEnd;
1621
- continue;
1622
- }
1623
- offset++;
1624
- }
1411
+ const scannedEnd = scanBoundary(code, source, offset, tokens);
1412
+ offset = scannedEnd > offset ? scannedEnd : offset + 1;
1625
1413
  textBoundary.lastIndex = offset;
1626
- offset = textBoundary.test(source) ? textBoundary.lastIndex - 1 : source.length;
1414
+ offset = textBoundary.test(source) ? textBoundary.lastIndex - 1 : end;
1627
1415
  }
1628
1416
  return tokens;
1629
1417
  }
1418
+ function compileInlineScannerDispatch(boundaryCodes, scannerByCode) {
1419
+ try {
1420
+ const key = String.fromCharCode(...boundaryCodes);
1421
+ let factory = scannerDispatchFactories.get(key);
1422
+ if (factory === void 0) {
1423
+ const names = boundaryCodes.map((code, index) => `scan${index}`);
1424
+ scannerDispatchFactories.set(key, factory = Function(...names, `return(code,source,start,tokens)=>{switch(code){${boundaryCodes.map((code, index) => `case ${code}:return scan${index}(source,start,tokens);`).join("")}default:return start}}`));
1425
+ }
1426
+ return factory(...boundaryCodes.map((code) => scannerByCode[code]));
1427
+ } catch {
1428
+ return (code, source, start, tokens) => scannerByCode[code]?.(source, start, tokens) ?? start;
1429
+ }
1430
+ }
1630
1431
  function compileInlineTokenizer(rules) {
1631
1432
  const scannerByCode = [];
1632
1433
  const boundaryCodes = [];
@@ -1641,15 +1442,18 @@ function compileInlineTokenizer(rules) {
1641
1442
  }
1642
1443
  const boundaries = String.fromCharCode(...boundaryCodes).replaceAll(/[\\\]-]/g, "\\$&");
1643
1444
  const textBoundary = new RegExp(`${boundaryCodes.length > 9 ? " {2,}[\\n\\r]|" : ""}[\\n\\r${boundaries}]`, "g");
1644
- return (source) => tokenize(source, textBoundary, scannerByCode);
1445
+ const scanBoundary = compileInlineScannerDispatch(boundaryCodes, scannerByCode);
1446
+ return (source) => tokenize(source, textBoundary, scanBoundary);
1645
1447
  }
1646
1448
  //#endregion
1647
1449
  //#region src/inline/profile.ts
1648
- function compileInlineProfile(features, compileResolver) {
1450
+ function compileInlineProfile(features, compileInlineResolver) {
1649
1451
  const buildByKind = [];
1452
+ const decorateByKind = [];
1650
1453
  const delimiters = [];
1651
1454
  const scanRules = [];
1652
1455
  const syntaxByKind = [];
1456
+ const textByKind = [];
1653
1457
  for (const feature of features) {
1654
1458
  if (feature.scan) scanRules.push(...feature.scan);
1655
1459
  if (feature.delimiters) delimiters.push(...feature.delimiters);
@@ -1658,10 +1462,15 @@ function compileInlineProfile(features, compileResolver) {
1658
1462
  for (const rule of build) switch (rule.kind) {
1659
1463
  case "decorate":
1660
1464
  buildByKind[rule.token] = rule.apply;
1465
+ decorateByKind[rule.token] = true;
1661
1466
  break;
1662
1467
  case "leaf":
1663
1468
  buildByKind[rule.token] = rule.build;
1664
1469
  break;
1470
+ case "text":
1471
+ buildByKind[rule.token] = rule.build;
1472
+ textByKind[rule.token] = true;
1473
+ break;
1665
1474
  case "container":
1666
1475
  buildByKind[rule.token] = rule.build;
1667
1476
  syntaxByKind[rule.token * 2] = rule.close;
@@ -1675,12 +1484,44 @@ function compileInlineProfile(features, compileResolver) {
1675
1484
  }
1676
1485
  return {
1677
1486
  buildByKind,
1678
- resolve: compileResolver(delimiters),
1487
+ decorateByKind,
1488
+ resolve: compileInlineResolver(delimiters),
1679
1489
  syntaxByKind,
1490
+ textByKind,
1680
1491
  tokenize: compileInlineTokenizer(scanRules)
1681
1492
  };
1682
1493
  }
1683
1494
  //#endregion
1495
+ //#region src/inline/tokens.ts
1496
+ function inlineTokenCount(tokens) {
1497
+ return tokens.length / 4;
1498
+ }
1499
+ function inlineTokenKind(tokens, index) {
1500
+ return tokens[index * 4 + 0];
1501
+ }
1502
+ function inlineTokenStart(tokens, index) {
1503
+ return tokens[index * 4 + 1];
1504
+ }
1505
+ function inlineTokenEnd(tokens, index) {
1506
+ return tokens[index * 4 + 2];
1507
+ }
1508
+ function inlineTokenData(tokens, index) {
1509
+ return tokens[index * 4 + 3];
1510
+ }
1511
+ function setInlineTokenData(tokens, index, data) {
1512
+ tokens[index * 4 + 3] = data;
1513
+ }
1514
+ function inlineTokenText(source, tokens, index) {
1515
+ return source.slice(inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index));
1516
+ }
1517
+ function appendInlineToken(target, kind, start, end, data = 0) {
1518
+ target.push(kind, start, end, data);
1519
+ }
1520
+ function copyInlineToken(target, tokens, index) {
1521
+ const offset = index * 4;
1522
+ target.push(tokens[offset], tokens[offset + 1], tokens[offset + 2], tokens[offset + 3]);
1523
+ }
1524
+ //#endregion
1684
1525
  //#region src/profile/features/attributes/syntax.ts
1685
1526
  const brackets = {
1686
1527
  "[": "]",
@@ -1838,11 +1679,6 @@ function parseAttributes(source, start) {
1838
1679
  }
1839
1680
  //#endregion
1840
1681
  //#region src/profile/features/attributes/index.ts
1841
- const decorateInlineContainer = (build) => (tokenStart, context, inline) => {
1842
- const result = build(tokenStart, context, inline);
1843
- if (inline?.attributes) result.attributes = inline.attributes;
1844
- return result;
1845
- };
1846
1682
  const decorateList = (build) => (tokenStart, context) => {
1847
1683
  const result = build(tokenStart, context);
1848
1684
  if (!result.spread) for (const item of result.children) {
@@ -1903,18 +1739,6 @@ function scanAttribute(source, start, tokens) {
1903
1739
  }
1904
1740
  const feature$18 = {
1905
1741
  block: { decorators: [
1906
- {
1907
- rule: 4,
1908
- decorate: decorateInlineContainer
1909
- },
1910
- {
1911
- rule: 2,
1912
- decorate: decorateInlineContainer
1913
- },
1914
- {
1915
- rule: 3,
1916
- decorate: decorateInlineContainer
1917
- },
1918
1742
  {
1919
1743
  rule: 6,
1920
1744
  decorate: decorateList
@@ -1948,9 +1772,10 @@ const feature$18 = {
1948
1772
  else target.attributes = parsed.attributes;
1949
1773
  return true;
1950
1774
  }
1951
- if (previous.attributes) mergeAttributes(previous.attributes, parsed.attributes);
1775
+ const attributes = previous.attributes;
1776
+ if (attributes) mergeAttributes(attributes, parsed.attributes);
1952
1777
  else previous.attributes = parsed.attributes;
1953
- extendSpan(previous, sourceSpan.end);
1778
+ previous.position.end = context.locator.locationAt(sourceSpan.end);
1954
1779
  return true;
1955
1780
  }
1956
1781
  }]
@@ -2022,12 +1847,13 @@ const feature$16 = { block: {
2022
1847
  },
2023
1848
  build(tokenStart, context) {
2024
1849
  const tokens = context.structure.tokens;
1850
+ const start = context.locator.locationAt(tokens.start(tokenStart));
2025
1851
  return {
2026
1852
  type: "blockquote",
2027
1853
  children: buildBlockChildren(tokenStart, context),
2028
1854
  position: {
2029
- start: tokens.start(tokenStart),
2030
- end: blockEnd(tokenStart, context)
1855
+ start,
1856
+ end: context.locator.locationAt(blockEnd(tokenStart, context))
2031
1857
  }
2032
1858
  };
2033
1859
  }
@@ -2069,13 +1895,13 @@ const feature$16 = { block: {
2069
1895
  //#endregion
2070
1896
  //#region src/profile/features/break.ts
2071
1897
  function isThematicBreak(source, lines, index, contentOffset) {
2072
- const marker = source[contentOffset];
2073
- if (marker !== "*" && marker !== "-" && marker !== "_") return false;
1898
+ const marker = source.charCodeAt(contentOffset);
1899
+ if (marker !== 42 && marker !== 45 && marker !== 95) return false;
2074
1900
  let count = 0;
2075
1901
  for (let offset = contentOffset, end = lines.end(index); offset < end; offset++) {
2076
- const character = source[offset];
2077
- if (character === marker) count++;
2078
- else if (character !== " " && character !== " ") return false;
1902
+ const code = source.charCodeAt(offset);
1903
+ if (code === marker) count++;
1904
+ else if (code !== 32 && code !== 9) return false;
2079
1905
  }
2080
1906
  return count >= 3;
2081
1907
  }
@@ -2090,10 +1916,7 @@ const feature$15 = {
2090
1916
  build(tokenStart, context) {
2091
1917
  return {
2092
1918
  type: "thematicBreak",
2093
- position: {
2094
- start: context.structure.tokens.start(tokenStart),
2095
- end: blockEnd(tokenStart, context)
2096
- }
1919
+ position: leafBlockPosition(tokenStart, context)
2097
1920
  };
2098
1921
  }
2099
1922
  }],
@@ -2123,14 +1946,10 @@ const feature$15 = {
2123
1946
  };
2124
1947
  }
2125
1948
  }, {
2126
- kind: "leaf",
1949
+ kind: "text",
2127
1950
  token: 5,
2128
- build(tokenIndex, sourceSpan) {
2129
- return {
2130
- type: "text",
2131
- value: "\n",
2132
- position: sourceSpan
2133
- };
1951
+ build() {
1952
+ return "\n";
2134
1953
  }
2135
1954
  }] }
2136
1955
  };
@@ -2183,65 +2002,54 @@ function fencedBlock(source, lines, index, fence, closed) {
2183
2002
  markerOffset: fence.offset - lines.start(index)
2184
2003
  };
2185
2004
  }
2186
- function fencedBlockContent(source, block, mode) {
2187
- let contentStart;
2188
- let contentEnd = source.length;
2189
- if (mode === 0) {
2190
- contentStart = source.indexOf("\n") + 1;
2191
- if (!contentStart) return "";
2192
- if (block.closed) contentEnd = source.lastIndexOf("\n", source.length - 2) + 1;
2193
- } else {
2194
- contentStart = 0;
2195
- while (contentStart < source.length && source[contentStart] !== "\n" && source[contentStart] !== "\r") contentStart++;
2196
- if (contentStart < source.length) contentStart += source[contentStart] === "\r" && source[contentStart + 1] === "\n" ? 2 : 1;
2197
- if (block.closed) {
2198
- contentEnd = lineContentEnd(source, contentStart, contentEnd);
2199
- while (contentEnd > contentStart && source[contentEnd - 1] !== "\n" && source[contentEnd - 1] !== "\r") contentEnd--;
2200
- }
2201
- }
2202
- const end = lineContentEnd(source, contentStart, contentEnd);
2203
- if (!block.indent) return source.slice(contentStart, end);
2204
- const chunks = [];
2205
- let lineStart = contentStart;
2206
- while (lineStart < end) {
2207
- const lf = source.indexOf("\n", lineStart);
2208
- const cr = source.indexOf("\r", lineStart);
2209
- let next = Math.min(lf < 0 ? end : lf, cr < 0 ? end : cr, end);
2210
- if (next < end) next += source[next] === "\r" && source[next + 1] === "\n" ? 2 : 1;
2211
- if (mode === 1) chunks.push(removeIndent(source.slice(lineStart, next), block.indent));
2212
- else {
2213
- let start = lineStart;
2214
- while (start - lineStart < block.indent && source.charCodeAt(start) === 32) start++;
2215
- chunks.push(source.slice(start, next));
2216
- }
2217
- lineStart = next;
2218
- }
2219
- return chunks.join("");
2005
+ const fenceSpaceIndent = [
2006
+ /^(?<![\u2028\u2029]) /gm,
2007
+ /^(?<![\u2028\u2029]) {1,2}/gm,
2008
+ /^(?<![\u2028\u2029]) {1,3}/gm
2009
+ ];
2010
+ const sourceColumnFenceTabIndent = [
2011
+ /^(?<![\u2028\u2029])\t/gm,
2012
+ /^(?<![\u2028\u2029]) ?\t/gm,
2013
+ /^(?<![\u2028\u2029]) {0,2}\t/gm
2014
+ ];
2015
+ function normalizedFenceContent(source, block) {
2016
+ const contentStart = source.indexOf("\n") + 1;
2017
+ if (!contentStart) return "";
2018
+ const end = lineContentEnd(source, contentStart, block.closed ? source.lastIndexOf("\n", source.length - 2) + 1 : source.length);
2019
+ const content = source.slice(contentStart, end);
2020
+ return block.indent ? content.replace(fenceSpaceIndent[block.indent - 1], "") : content;
2021
+ }
2022
+ function sourceColumnFenceContent(source, block) {
2023
+ let contentStart = 0;
2024
+ while (contentStart < source.length && source[contentStart] !== "\n" && source[contentStart] !== "\r") contentStart++;
2025
+ if (contentStart < source.length) contentStart += source[contentStart] === "\r" && source[contentStart + 1] === "\n" ? 2 : 1;
2026
+ let limit = source.length;
2027
+ if (block.closed) {
2028
+ limit = lineContentEnd(source, contentStart, limit);
2029
+ while (limit > contentStart && source[limit - 1] !== "\n" && source[limit - 1] !== "\r") limit--;
2030
+ }
2031
+ const end = lineContentEnd(source, contentStart, limit);
2032
+ let content = source.slice(contentStart, end);
2033
+ if (block.indent) {
2034
+ if (content.includes(" ")) content = content.replace(sourceColumnFenceTabIndent[block.indent - 1], " ");
2035
+ content = content.replace(fenceSpaceIndent[block.indent - 1], "");
2036
+ }
2037
+ return content;
2220
2038
  }
2221
2039
  //#endregion
2222
2040
  //#region src/profile/features/text.ts
2223
- const semanticCharacter = /\\([!"#$%&'()*+,./:;<=>?@[\\\]^_`{|}~-])|&(?:#x[\da-f]{1,6}|#\d{1,7}|[a-z][\da-z]{1,31});/gi;
2224
2041
  const entity = /&(?:#x[0-9A-F]{1,6}|#\d{1,7}|[A-Z][A-Z0-9]{0,30});/iy;
2225
2042
  function isAsciiPunctuation(code) {
2226
2043
  return code >= 33 && code <= 47 || code >= 58 && code <= 64 || code >= 91 && code <= 96 || code >= 123 && code <= 126;
2227
2044
  }
2228
2045
  function semanticText(value) {
2229
- if (!value.includes("\\") && !value.includes("&")) return value;
2230
- return value.replace(semanticCharacter, (match, escaped) => escaped ?? decodeHTMLStrict(match));
2046
+ return value.includes("\\") || value.includes("&") ? decodeString(value) : value;
2231
2047
  }
2232
- const buildInlineText = (tokenIndex, sourceSpan, context) => {
2233
- return {
2234
- type: "text",
2235
- value: inlineTokenText(context.view.text, context.tokens, tokenIndex),
2236
- position: sourceSpan
2237
- };
2048
+ const buildInlineText = (tokenIndex, context) => {
2049
+ return inlineTokenText(context.view.text, context.tokens, tokenIndex);
2238
2050
  };
2239
- const buildDecodedInlineText = (tokenIndex, sourceSpan, context) => {
2240
- return {
2241
- type: "text",
2242
- value: semanticText(inlineTokenText(context.view.text, context.tokens, tokenIndex)),
2243
- position: sourceSpan
2244
- };
2051
+ const buildDecodedInlineText = (tokenIndex, context) => {
2052
+ return semanticText(inlineTokenText(context.view.text, context.tokens, tokenIndex));
2245
2053
  };
2246
2054
  const feature$14 = { inline: {
2247
2055
  scan: [{
@@ -2270,17 +2078,17 @@ const feature$14 = { inline: {
2270
2078
  }],
2271
2079
  build: [
2272
2080
  {
2273
- kind: "leaf",
2081
+ kind: "text",
2274
2082
  token: 1,
2275
2083
  build: buildInlineText
2276
2084
  },
2277
2085
  {
2278
- kind: "leaf",
2086
+ kind: "text",
2279
2087
  token: 2,
2280
2088
  build: buildDecodedInlineText
2281
2089
  },
2282
2090
  {
2283
- kind: "leaf",
2091
+ kind: "text",
2284
2092
  token: 3,
2285
2093
  build: buildDecodedInlineText
2286
2094
  }
@@ -2306,10 +2114,9 @@ const feature$13 = {
2306
2114
  token: 19
2307
2115
  },
2308
2116
  build(tokenStart, context) {
2309
- const offset = context.structure.tokens.start(tokenStart);
2310
- const end = context.structure.tokens.end(tokenStart);
2311
- const source = normalizeLines(context.structure.tokens.text(context.source, tokenStart));
2312
- const block = context.structure.tokens.value(tokenStart);
2117
+ const tokens = context.structure.tokens;
2118
+ const source = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
2119
+ const block = tokens.value(tokenStart);
2313
2120
  if (!block) throw new Error("FencedCodeBlock token has no fence metadata");
2314
2121
  const rawInfo = semanticText(block.info);
2315
2122
  const langEnd = rawInfo.search(/[ \t]/);
@@ -2319,11 +2126,8 @@ const feature$13 = {
2319
2126
  type: "code",
2320
2127
  lang,
2321
2128
  meta: metaStart < 0 ? null : rawInfo.slice(langEnd + metaStart),
2322
- value: fencedBlockContent(source, block, 0),
2323
- position: {
2324
- start: offset + block.markerOffset,
2325
- end: block.closed || end < context.structure.tokens.sourceLength ? blockEnd(tokenStart, context) : end
2326
- }
2129
+ value: normalizedFenceContent(source, block),
2130
+ position: fencedBlockPosition(tokenStart, block, context)
2327
2131
  };
2328
2132
  }
2329
2133
  }, {
@@ -2336,17 +2140,14 @@ const feature$13 = {
2336
2140
  const tokens = context.structure.tokens;
2337
2141
  const offset = tokens.start(tokenStart);
2338
2142
  const contentLength = tokens.value(tokenStart);
2339
- const lines = normalizeLines(tokens.text(context.source, tokenStart)).split("\n").map((line) => removeIndent(line, 4));
2143
+ const lines = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart)).split("\n").map((line) => removeIndent(line, 4));
2340
2144
  while (lines.length && /^[ \t]*$/.test(lines[lines.length - 1])) lines.pop();
2341
2145
  return {
2342
2146
  type: "code",
2343
2147
  lang: null,
2344
2148
  meta: null,
2345
2149
  value: lines.join("\n"),
2346
- position: {
2347
- start: offset,
2348
- end: offset + contentLength
2349
- }
2150
+ position: context.locator.positionAt(offset, offset + contentLength)
2350
2151
  };
2351
2152
  }
2352
2153
  }],
@@ -2385,23 +2186,18 @@ const feature$13 = {
2385
2186
  if (source.charCodeAt(start - 1) === 96) return start + 1;
2386
2187
  const openEnd = inlineMarkerRunEnd(source, start);
2387
2188
  const markerLength = openEnd - start;
2388
- let end = -1;
2389
2189
  let offset = openEnd;
2390
2190
  while (offset < source.length) {
2391
- if (source.charCodeAt(offset) !== 96) {
2392
- offset++;
2393
- continue;
2394
- }
2191
+ offset = source.indexOf("`", offset);
2192
+ if (offset < 0) break;
2395
2193
  const closeEnd = inlineMarkerRunEnd(source, offset);
2396
2194
  if (closeEnd - offset === markerLength) {
2397
- end = closeEnd;
2398
- break;
2195
+ appendInlineToken(tokens, 6, start, closeEnd, markerLength);
2196
+ return closeEnd;
2399
2197
  }
2400
2198
  offset = closeEnd;
2401
2199
  }
2402
- if (end < 0) return start + 1;
2403
- appendInlineToken(tokens, 6, start, end, markerLength);
2404
- return end;
2200
+ return start + 1;
2405
2201
  }
2406
2202
  }],
2407
2203
  build: [{
@@ -2410,7 +2206,7 @@ const feature$13 = {
2410
2206
  build: (tokenIndex, sourceSpan, context) => {
2411
2207
  const text = inlineTokenText(context.view.text, context.tokens, tokenIndex);
2412
2208
  const markerLength = inlineTokenData(context.tokens, tokenIndex);
2413
- let value = normalizeLines(text.slice(markerLength, -markerLength));
2209
+ let value = context.locator.normalizeLineEndings(text.slice(markerLength, -markerLength));
2414
2210
  if (/^[ \n]/.test(value) && /[ \n]$/.test(value) && /[^ \n]/.test(value)) value = value.slice(1, -1);
2415
2211
  return {
2416
2212
  type: "inlineCode",
@@ -2422,6 +2218,178 @@ const feature$13 = {
2422
2218
  }
2423
2219
  };
2424
2220
  //#endregion
2221
+ //#region src/fragment/inline.ts
2222
+ function createInlineOutput(children, cursor) {
2223
+ return {
2224
+ children,
2225
+ cursor,
2226
+ lastText: void 0,
2227
+ textEnd: -1,
2228
+ trailingSpaces: 0
2229
+ };
2230
+ }
2231
+ function lineEndingStart(source, lineStart) {
2232
+ return source.charCodeAt(lineStart - 1) === 10 && source.charCodeAt(lineStart - 2) === 13 ? lineStart - 2 : lineStart - 1;
2233
+ }
2234
+ function trimTrailingText(output) {
2235
+ const text = output.lastText;
2236
+ const removed = text ? output.trailingSpaces : 0;
2237
+ if (removed > 0) {
2238
+ text.value = text.value.slice(0, -removed);
2239
+ output.trailingSpaces = 0;
2240
+ }
2241
+ return removed;
2242
+ }
2243
+ function appendText(output, value, start, end, context) {
2244
+ const previousText = output.lastText;
2245
+ const mergeForward = previousText !== void 0 && !("attributes" in previousText);
2246
+ let offset = value.length;
2247
+ while (offset > 0) {
2248
+ const code = value.charCodeAt(offset - 1);
2249
+ if (code !== 32 && code !== 9) break;
2250
+ offset--;
2251
+ }
2252
+ const trailingSpaces = value.length - offset;
2253
+ output.trailingSpaces = trailingSpaces === value.length && mergeForward ? output.trailingSpaces + trailingSpaces : trailingSpaces;
2254
+ if (mergeForward) previousText.value += value;
2255
+ else {
2256
+ const startLocation = context.locator.locationAt(start);
2257
+ const text = {
2258
+ type: "text",
2259
+ value,
2260
+ position: {
2261
+ start: startLocation,
2262
+ end: startLocation
2263
+ }
2264
+ };
2265
+ output.children.push(text);
2266
+ output.lastText = text;
2267
+ }
2268
+ output.textEnd = end;
2269
+ }
2270
+ function finishText(output, context) {
2271
+ const end = output.textEnd;
2272
+ if (end >= 0) {
2273
+ output.lastText.position.end = context.locator.locationAt(end);
2274
+ output.textEnd = -1;
2275
+ }
2276
+ }
2277
+ function appendGap(output, context, start, end) {
2278
+ const value = context.view.text.slice(start, end);
2279
+ const sourceSpan = context.view.mapSpan(start, end);
2280
+ appendText(output, value, sourceSpan.start, sourceSpan.end, context);
2281
+ }
2282
+ function appendToken(output, context, tokenIndex, viewStart, viewEnd, build, textToken, syntaxNewline) {
2283
+ const cursor = output.cursor;
2284
+ if (!syntaxNewline) {
2285
+ if (viewStart > cursor) appendGap(output, context, cursor, viewStart);
2286
+ } else {
2287
+ const viewLineStart = inlineTokenData(context.tokens, tokenIndex);
2288
+ const viewLineEndingStart = lineEndingStart(context.view.text, viewLineStart);
2289
+ if (viewStart > cursor) {
2290
+ if (viewLineEndingStart > cursor) appendGap(output, context, cursor, viewLineEndingStart);
2291
+ }
2292
+ const previous = output.children.at(-1);
2293
+ if (previous?.type === "break") {
2294
+ previous.position.end = context.locator.locationAt(context.view.mapPoint(viewLineStart - 1) + 1);
2295
+ return;
2296
+ }
2297
+ viewStart = viewLineEndingStart;
2298
+ trimTrailingText(output);
2299
+ }
2300
+ const sourceSpan = context.view.mapSpan(viewStart, viewEnd);
2301
+ if (textToken) appendText(output, build(tokenIndex, context), sourceSpan.start, sourceSpan.end, context);
2302
+ else {
2303
+ finishText(output, context);
2304
+ output.children.push(build(tokenIndex, context.locator.positionAt(sourceSpan.start, sourceSpan.end), context));
2305
+ output.lastText = void 0;
2306
+ }
2307
+ }
2308
+ function appendRange(startToken, endToken, profile, context, output, closeKind = 0) {
2309
+ let index = startToken;
2310
+ while (index < endToken) {
2311
+ const kind = inlineTokenKind(context.tokens, index);
2312
+ if (kind === closeKind) break;
2313
+ const syntaxOffset = kind * 2;
2314
+ const semanticCloseKind = profile.syntaxByKind[syntaxOffset];
2315
+ const build = profile.buildByKind[kind];
2316
+ const childStart = inlineTokenStart(context.tokens, index);
2317
+ if (semanticCloseKind !== void 0) {
2318
+ if (childStart > output.cursor) appendGap(output, context, output.cursor, childStart);
2319
+ finishText(output, context);
2320
+ index = appendSemantic(index, endToken, profile, context, output, build, semanticCloseKind, profile.syntaxByKind[syntaxOffset + 1]);
2321
+ continue;
2322
+ }
2323
+ const childEnd = inlineTokenEnd(context.tokens, index);
2324
+ if (profile.decorateByKind[kind]) {
2325
+ finishText(output, context);
2326
+ const sourceSpan = context.view.mapSpan(childStart, childEnd);
2327
+ if (build(index, sourceSpan, context, output)) {
2328
+ const previous = output.children.at(-1);
2329
+ output.lastText = previous?.type === "text" ? previous : void 0;
2330
+ output.cursor = childEnd;
2331
+ }
2332
+ } else {
2333
+ appendToken(output, context, index, childStart, childEnd, build, profile.textByKind[kind], kind === 5);
2334
+ output.cursor = childEnd;
2335
+ }
2336
+ index++;
2337
+ }
2338
+ if (index < endToken) {
2339
+ const contentEnd = inlineTokenStart(context.tokens, index);
2340
+ if (contentEnd > output.cursor) appendGap(output, context, output.cursor, contentEnd);
2341
+ } else if (context.view.text.length > output.cursor) appendGap(output, context, output.cursor, context.view.text.length);
2342
+ finishText(output, context);
2343
+ return index;
2344
+ }
2345
+ function appendSemantic(openToken, endToken, profile, context, output, build, closeKind, contentOpenKind) {
2346
+ const childStart = inlineTokenStart(context.tokens, openToken);
2347
+ const positionStart = context.locator.locationAt(context.view.mapPoint(childStart));
2348
+ let closeToken = openToken;
2349
+ let next = openToken + 1;
2350
+ const children = [];
2351
+ if (contentOpenKind === 0 || next < endToken && inlineTokenKind(context.tokens, next) === contentOpenKind) {
2352
+ const childOutput = createInlineOutput(children, inlineTokenEnd(context.tokens, contentOpenKind === 0 ? openToken : next++));
2353
+ closeToken = appendRange(next, endToken, profile, context, childOutput, closeKind);
2354
+ }
2355
+ const childEnd = inlineTokenEnd(context.tokens, closeToken);
2356
+ const sourceSpan = context.view.mapSpan(childStart, childEnd);
2357
+ const value = build(openToken, closeToken, {
2358
+ start: positionStart,
2359
+ end: context.locator.locationAt(sourceSpan.end)
2360
+ }, children, context);
2361
+ output.children.push(value);
2362
+ output.lastText = void 0;
2363
+ output.cursor = childEnd;
2364
+ return closeToken + 1;
2365
+ }
2366
+ function buildInlineFragment(tokenStart, blockRule, context) {
2367
+ const region = context.cursor ? context.cursor.take(tokenStart) : resolveInlineRegion(context.source, context.profile, context.structure.tokens, tokenStart);
2368
+ if (!region) return { children: [] };
2369
+ const { tokens, view } = region;
2370
+ const inlineContext = context.inlineContext ??= {
2371
+ blockRule,
2372
+ locator: context.locator,
2373
+ tokens,
2374
+ view
2375
+ };
2376
+ inlineContext.blockRule = blockRule;
2377
+ inlineContext.tokens = tokens;
2378
+ inlineContext.view = view;
2379
+ const result = createInlineOutput([], 0);
2380
+ appendRange(0, inlineTokenCount(tokens), context.profile, inlineContext, result);
2381
+ const last = result.lastText;
2382
+ if (last) {
2383
+ const removed = trimTrailingText(result);
2384
+ if (removed > 0) {
2385
+ last.position.end.offset -= removed;
2386
+ last.position.end.column -= removed;
2387
+ }
2388
+ if (!last.value) result.children.pop();
2389
+ }
2390
+ return result;
2391
+ }
2392
+ //#endregion
2425
2393
  //#region src/profile/features/frontmatter.ts
2426
2394
  function frontmatterFenceAt(source, lines, index, marker) {
2427
2395
  const start = lines.start(index);
@@ -2431,7 +2399,7 @@ function frontmatterFenceAt(source, lines, index, marker) {
2431
2399
  }
2432
2400
  const buildFrontmatter = (tokenStart, context) => {
2433
2401
  const tokens = context.structure.tokens;
2434
- const text = normalizeLines(tokens.text(context.source, tokenStart));
2402
+ const text = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
2435
2403
  const contentStart = text.indexOf("\n") + 1;
2436
2404
  const closingEnd = text.endsWith("\n") ? text.length - 1 : text.length;
2437
2405
  const closingStart = text.lastIndexOf("\n", closingEnd - 1) + 1;
@@ -2440,10 +2408,7 @@ const buildFrontmatter = (tokenStart, context) => {
2440
2408
  return {
2441
2409
  type: "yaml",
2442
2410
  value,
2443
- position: {
2444
- start: tokens.start(tokenStart),
2445
- end: blockEnd(tokenStart, context)
2446
- }
2411
+ position: leafBlockPosition(tokenStart, context)
2447
2412
  };
2448
2413
  };
2449
2414
  function feature$12(marker) {
@@ -2639,15 +2604,16 @@ function emitOpening(contentOffset, opening, out) {
2639
2604
  }
2640
2605
  if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(42, opening.attributesStart, opening.attributesEnd);
2641
2606
  }
2642
- const buildBlockLabel = (tokenStart, context, inline) => {
2607
+ const buildBlockLabel = (tokenStart, context) => {
2643
2608
  const tokens = context.structure.tokens;
2644
2609
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
2610
+ const start = context.locator.locationAt(tokens.start(tokenStart));
2645
2611
  return {
2646
2612
  type: "paragraph",
2647
- children: inline.children,
2613
+ children: buildInlineFragment(tokenStart, 20, context).children,
2648
2614
  position: {
2649
- start: tokens.start(tokenStart),
2650
- end: tokens.end(close)
2615
+ start,
2616
+ end: context.locator.locationAt(tokens.end(close))
2651
2617
  }
2652
2618
  };
2653
2619
  };
@@ -2706,8 +2672,9 @@ const blockRules$2 = [
2706
2672
  if (label !== void 0) openingToken += tokens.nodeLength(label);
2707
2673
  const attributesToken = tokens.kind(openingToken) === 42 ? openingToken++ : void 0;
2708
2674
  const parsed = attributesToken !== void 0 ? parseAttributes(context.source, tokens.start(attributesToken)) : void 0;
2675
+ const start = context.locator.locationAt(tokens.start(tokenStart));
2709
2676
  const children = [];
2710
- if (label) children.push(buildBlockLabel(label, context, buildInlineFragment(label, 20, context)));
2677
+ if (label) children.push(buildBlockNode(label, context));
2711
2678
  children.push(...buildBlockChildren(tokenStart, context));
2712
2679
  const opening = tokens.text(context.source, tokenStart);
2713
2680
  return {
@@ -2715,8 +2682,8 @@ const blockRules$2 = [
2715
2682
  name: normalizeComponentName(opening.slice(opening.lastIndexOf(":") + 1).trim()),
2716
2683
  attributes: parsed?.attributes ?? {},
2717
2684
  position: {
2718
- start: tokens.start(tokenStart),
2719
- end: tokens.end(close)
2685
+ start,
2686
+ end: context.locator.locationAt(tokens.end(close))
2720
2687
  },
2721
2688
  children
2722
2689
  };
@@ -2734,6 +2701,7 @@ const blockRules$2 = [
2734
2701
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
2735
2702
  const attributesToken = tokens.kind(tokenStart + 1) === 42 ? tokenStart + 1 : void 0;
2736
2703
  const parsed = attributesToken !== void 0 ? parseAttributes(context.source, tokens.start(attributesToken)) : void 0;
2704
+ const start = context.locator.locationAt(tokens.start(tokenStart));
2737
2705
  const children = buildBlockChildren(tokenStart, context);
2738
2706
  return {
2739
2707
  type: "blockComponent",
@@ -2744,8 +2712,8 @@ const blockRules$2 = [
2744
2712
  },
2745
2713
  children,
2746
2714
  position: {
2747
- start: tokens.start(tokenStart),
2748
- end: tokens.end(close)
2715
+ start,
2716
+ end: context.locator.locationAt(tokens.end(close))
2749
2717
  }
2750
2718
  };
2751
2719
  }
@@ -2853,7 +2821,7 @@ const feature$10 = { inline: {
2853
2821
  //#region src/profile/utils.ts
2854
2822
  function normalizeAssociationLabel(label) {
2855
2823
  scan: {
2856
- let hasLowercase = false;
2824
+ let hasUppercase = false;
2857
2825
  for (let index = 0; index < label.length; index++) {
2858
2826
  const code = label.charCodeAt(index);
2859
2827
  if (code === 32) {
@@ -2861,29 +2829,31 @@ function normalizeAssociationLabel(label) {
2861
2829
  continue;
2862
2830
  }
2863
2831
  if (code < 32 || code > 126) break scan;
2864
- if (code >= 97 && code <= 122) hasLowercase = true;
2832
+ if (code >= 65 && code <= 90) hasUppercase = true;
2865
2833
  }
2866
- return hasLowercase ? label.toUpperCase() : label;
2834
+ return hasUppercase ? label.toLowerCase() : label;
2867
2835
  }
2868
- return label.trim().replace(/[ \t\r\n]+/g, " ").toLowerCase().toUpperCase();
2836
+ return label.trim().replace(/[ \t\r\n]+/g, " ").toLowerCase().toUpperCase().toLowerCase();
2869
2837
  }
2870
2838
  //#endregion
2871
2839
  //#region src/profile/features/footnote/shared.ts
2872
2840
  const footnoteDefinitionPrefix = "footnote\0";
2841
+ function isLabelWhitespace(code) {
2842
+ return code === 32 || code === 9 || code === 10 || code === 13;
2843
+ }
2873
2844
  function footnoteLabelAt(source, start, limit) {
2874
- if (source[start] !== "[" || source[start + 1] !== "^") return;
2845
+ if (source.charCodeAt(start) !== 91 || source.charCodeAt(start + 1) !== 94) return;
2875
2846
  const labelStart = start + 2;
2876
2847
  let offset = labelStart;
2877
2848
  let length = 0;
2878
2849
  while (offset < limit) {
2879
- const character = source[offset];
2880
- if (character === " " || character === " " || character === "\n" || character === "\r") return;
2881
- if (character === "\\" && offset + 1 < limit) {
2882
- const escaped = source[offset + 1];
2883
- if (escaped === " " || escaped === " " || escaped === "\n" || escaped === "\r") return;
2850
+ const code = source.charCodeAt(offset);
2851
+ if (isLabelWhitespace(code)) return;
2852
+ if (code === 92 && offset + 1 < limit) {
2853
+ if (isLabelWhitespace(source.charCodeAt(offset + 1))) return;
2884
2854
  offset += 2;
2885
2855
  length += 2;
2886
- } else if (character === "]") {
2856
+ } else if (code === 93) {
2887
2857
  if (length === 0) return;
2888
2858
  const label = source.slice(labelStart, offset);
2889
2859
  const normalizedLabel = normalizeAssociationLabel(label);
@@ -2894,7 +2864,7 @@ function footnoteLabelAt(source, start, limit) {
2894
2864
  normalizedLabel
2895
2865
  };
2896
2866
  } else {
2897
- if (character === "[") return;
2867
+ if (code === 91) return;
2898
2868
  offset++;
2899
2869
  length++;
2900
2870
  }
@@ -2906,10 +2876,14 @@ function footnoteLabelAt(source, start, limit) {
2906
2876
  function definitionAt(source, lines, index, markerStart) {
2907
2877
  const lineEnd = lines.end(index);
2908
2878
  const label = footnoteLabelAt(source, markerStart, lineEnd);
2909
- if (!label || source[label.end] !== ":") return;
2879
+ if (!label || source.charCodeAt(label.end) !== 58) return;
2910
2880
  const markerEnd = label.end + 1;
2911
2881
  let contentOffset = markerEnd;
2912
- while (contentOffset < lineEnd && (source[contentOffset] === " " || source[contentOffset] === " ")) contentOffset++;
2882
+ while (contentOffset < lineEnd) {
2883
+ const code = source.charCodeAt(contentOffset);
2884
+ if (code !== 32 && code !== 9) break;
2885
+ contentOffset++;
2886
+ }
2913
2887
  return {
2914
2888
  ...label,
2915
2889
  contentOffset,
@@ -2933,15 +2907,18 @@ const feature$9 = {
2933
2907
  close: 26
2934
2908
  },
2935
2909
  build(tokenStart, context) {
2936
- const fields = definitionFields(context.structure.tokens, tokenStart);
2910
+ const tokens = context.structure.tokens;
2911
+ const fields = definitionFields(tokens, tokenStart);
2912
+ const start = context.locator.locationAt(tokens.start(tokenStart));
2913
+ const children = buildBlockChildren(tokenStart, context);
2937
2914
  return {
2938
2915
  type: "footnoteDefinition",
2939
- identifier: fields.normalizedLabel.toLowerCase(),
2916
+ identifier: fields.normalizedLabel,
2940
2917
  label: semanticText(fields.label),
2941
- children: buildBlockChildren(tokenStart, context),
2918
+ children,
2942
2919
  position: {
2943
- start: context.structure.tokens.start(tokenStart),
2944
- end: blockEnd(tokenStart, context)
2920
+ start,
2921
+ end: context.locator.locationAt(blockEnd(tokenStart, context))
2945
2922
  }
2946
2923
  };
2947
2924
  }
@@ -3004,7 +2981,7 @@ const feature$9 = {
3004
2981
  const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(2, -1);
3005
2982
  return {
3006
2983
  type: "footnoteReference",
3007
- identifier: normalizeAssociationLabel(label).toLowerCase(),
2984
+ identifier: normalizeAssociationLabel(label),
3008
2985
  label: semanticText(label),
3009
2986
  position: sourceSpan
3010
2987
  };
@@ -3063,12 +3040,12 @@ const strikethroughDelimiter = {
3063
3040
  function feature$8(strikethroughOptions) {
3064
3041
  const builds = [
3065
3042
  {
3066
- kind: "leaf",
3043
+ kind: "text",
3067
3044
  token: 10,
3068
3045
  build: buildInlineText
3069
3046
  },
3070
3047
  {
3071
- kind: "leaf",
3048
+ kind: "text",
3072
3049
  token: 11,
3073
3050
  build: buildInlineText
3074
3051
  },
@@ -3085,7 +3062,7 @@ function feature$8(strikethroughOptions) {
3085
3062
  }];
3086
3063
  if (strikethroughOptions) {
3087
3064
  builds.push({
3088
- kind: "leaf",
3065
+ kind: "text",
3089
3066
  token: 12,
3090
3067
  build: buildInlineText
3091
3068
  }, deletePair);
@@ -3105,6 +3082,23 @@ function feature$8(strikethroughOptions) {
3105
3082
  } };
3106
3083
  }
3107
3084
  //#endregion
3085
+ //#region src/fragment/node.ts
3086
+ function cloneLocation(location) {
3087
+ return {
3088
+ line: location.line,
3089
+ column: location.column,
3090
+ offset: location.offset
3091
+ };
3092
+ }
3093
+ function firstChildStart(children) {
3094
+ const first = children[0];
3095
+ return cloneLocation(first.position.start);
3096
+ }
3097
+ function lastChildEnd(children) {
3098
+ const last = children.at(-1);
3099
+ return last ? cloneLocation(last.position.end) : void 0;
3100
+ }
3101
+ //#endregion
3108
3102
  //#region src/profile/features/heading.ts
3109
3103
  function atxAt(source, lines, index, markerOffset) {
3110
3104
  let markerEnd = markerOffset + 1;
@@ -3146,17 +3140,21 @@ const feature$7 = { block: {
3146
3140
  close: 8
3147
3141
  },
3148
3142
  inlineContent: true,
3149
- build(tokenStart, context, inline) {
3143
+ build(tokenStart, context) {
3150
3144
  const tokens = context.structure.tokens;
3151
- return {
3145
+ const start = context.locator.locationAt(tokens.start(tokenStart));
3146
+ const inline = buildInlineFragment(tokenStart, 2, context);
3147
+ const result = {
3152
3148
  type: "heading",
3153
3149
  depth: tokens.end(tokenStart) - tokens.start(tokenStart),
3154
3150
  children: inline.children,
3155
3151
  position: {
3156
- start: tokens.start(tokenStart),
3157
- end: blockEnd(tokenStart, context)
3152
+ start,
3153
+ end: context.locator.locationAt(blockEnd(tokenStart, context))
3158
3154
  }
3159
3155
  };
3156
+ if (inline.attributes) result.attributes = inline.attributes;
3157
+ return result;
3160
3158
  }
3161
3159
  }, {
3162
3160
  rule: 3,
@@ -3166,18 +3164,21 @@ const feature$7 = { block: {
3166
3164
  close: 8
3167
3165
  },
3168
3166
  inlineContent: true,
3169
- build(tokenStart, context, inline) {
3167
+ build(tokenStart, context) {
3170
3168
  const tokens = context.structure.tokens;
3169
+ const inline = buildInlineFragment(tokenStart, 3, context);
3171
3170
  const children = inline.children;
3172
- return {
3171
+ const result = {
3173
3172
  type: "heading",
3174
3173
  depth: tokens.kind(tokenStart) === 6 ? 1 : 2,
3175
3174
  children,
3176
3175
  position: {
3177
3176
  start: firstChildStart(children),
3178
- end: tokens.start(tokenStart + tokens.nodeLength(tokenStart) - 1)
3177
+ end: context.locator.locationAt(tokens.start(tokenStart + tokens.nodeLength(tokenStart) - 1))
3179
3178
  }
3180
3179
  };
3180
+ if (inline.attributes) result.attributes = inline.attributes;
3181
+ return result;
3181
3182
  }
3182
3183
  }],
3183
3184
  starts: [{
@@ -3198,70 +3199,7 @@ const feature$7 = { block: {
3198
3199
  } };
3199
3200
  //#endregion
3200
3201
  //#region src/profile/features/html.ts
3201
- const htmlBlockTags = new Set([
3202
- "address",
3203
- "article",
3204
- "aside",
3205
- "base",
3206
- "basefont",
3207
- "blockquote",
3208
- "body",
3209
- "caption",
3210
- "center",
3211
- "col",
3212
- "colgroup",
3213
- "dd",
3214
- "details",
3215
- "dialog",
3216
- "dir",
3217
- "div",
3218
- "dl",
3219
- "dt",
3220
- "fieldset",
3221
- "figcaption",
3222
- "figure",
3223
- "footer",
3224
- "form",
3225
- "frame",
3226
- "frameset",
3227
- "h1",
3228
- "h2",
3229
- "h3",
3230
- "h4",
3231
- "h5",
3232
- "h6",
3233
- "head",
3234
- "header",
3235
- "hr",
3236
- "html",
3237
- "iframe",
3238
- "legend",
3239
- "li",
3240
- "link",
3241
- "main",
3242
- "menu",
3243
- "menuitem",
3244
- "nav",
3245
- "noframes",
3246
- "ol",
3247
- "optgroup",
3248
- "option",
3249
- "p",
3250
- "param",
3251
- "search",
3252
- "section",
3253
- "summary",
3254
- "table",
3255
- "tbody",
3256
- "td",
3257
- "tfoot",
3258
- "th",
3259
- "thead",
3260
- "title",
3261
- "tr",
3262
- "track",
3263
- "ul"
3264
- ]);
3202
+ const htmlBlockTags = new Set(htmlBlockNames);
3265
3203
  const htmlTagName = "[a-z][a-z0-9-]*";
3266
3204
  const completeHtmlTag = new RegExp(`^(?:<${htmlTagName}(?:\\s+[a-z_:][\\w.:-]*(?:\\s*=\\s*(?:[^\\s"'=<>\`]+|'[^']*'|"[^"]*"))?)*\\s*/?>|</${htmlTagName}\\s*>)[ \\t]*$`, "i");
3267
3205
  const htmlComment = /<!-->|<!--->|<!--[\s\S]*?(?:-->|$)/y;
@@ -3270,12 +3208,7 @@ const inlineHtml = /<[A-Za-z][A-Za-z0-9-]*(?:[ \t\n\r]+[A-Za-z_:][\w.:-]*(?:[ \t
3270
3208
  function htmlStartAt(source, lines, index, contentOffset) {
3271
3209
  const body = source.slice(contentOffset, lines.end(index));
3272
3210
  const lower = body.toLowerCase();
3273
- for (const tag of [
3274
- "script",
3275
- "pre",
3276
- "style",
3277
- "textarea"
3278
- ]) if (lower.startsWith(`<${tag}`) && (lower.length === tag.length + 1 || /[ \t>]/.test(lower[tag.length + 1]))) return {
3211
+ for (const tag of htmlRawNames) if (lower.startsWith(`<${tag}`) && (lower.length === tag.length + 1 || /[ \t>]/.test(lower[tag.length + 1]))) return {
3279
3212
  interruptParagraph: true,
3280
3213
  terminator: `</${tag}>`
3281
3214
  };
@@ -3299,11 +3232,6 @@ function htmlStartAt(source, lines, index, contentOffset) {
3299
3232
  if (tag && htmlBlockTags.has(tag)) return { interruptParagraph: true };
3300
3233
  if (completeHtmlTag.test(body)) return { interruptParagraph: false };
3301
3234
  }
3302
- function htmlBlockUnterminated(token, context) {
3303
- const result = context.structure.tokens.value(token);
3304
- if (context.structure.tokens.kind(token) !== 21 || result === void 0) throw new Error("HTML block lacks termination state");
3305
- return result;
3306
- }
3307
3235
  const buildInlineHtml = (tokenIndex, sourceSpan, context) => {
3308
3236
  return {
3309
3237
  type: "html",
@@ -3320,18 +3248,17 @@ const feature$6 = {
3320
3248
  token: 21
3321
3249
  },
3322
3250
  build(tokenStart, context) {
3323
- const offset = context.structure.tokens.start(tokenStart);
3324
- const end = context.structure.tokens.end(tokenStart);
3325
- const unterminated = htmlBlockUnterminated(tokenStart, context);
3326
- let html = normalizeLines(context.structure.tokens.text(context.source, tokenStart));
3251
+ const tokens = context.structure.tokens;
3252
+ const offset = tokens.start(tokenStart);
3253
+ const end = tokens.end(tokenStart);
3254
+ const unterminated = tokens.value(tokenStart);
3255
+ if (tokens.kind(tokenStart) !== 21 || unterminated === void 0) throw new Error("HTML block lacks termination state");
3256
+ let html = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
3327
3257
  if (!unterminated && html.endsWith("\n")) html = html.slice(0, -1);
3328
3258
  return {
3329
3259
  type: "html",
3330
3260
  value: html,
3331
- position: {
3332
- start: offset,
3333
- end: html.endsWith("\n") ? end : blockEnd(tokenStart, context)
3334
- }
3261
+ position: context.locator.positionAt(offset, html.endsWith("\n") ? end : blockEnd(tokenStart, context))
3335
3262
  };
3336
3263
  }
3337
3264
  }],
@@ -3507,7 +3434,7 @@ function reference(close, syntaxStart, syntaxEnd, context, image) {
3507
3434
  const full = closeText.startsWith("][") && closeText !== "][]";
3508
3435
  const labelSource = full ? closeText.slice(2, -1) : content;
3509
3436
  return {
3510
- identifier: normalizeAssociationLabel(labelSource).toLowerCase(),
3437
+ identifier: normalizeAssociationLabel(labelSource),
3511
3438
  label: semanticText(labelSource),
3512
3439
  referenceType: full ? "full" : closeText === "][]" ? "collapsed" : "shortcut"
3513
3440
  };
@@ -3623,8 +3550,16 @@ const feature$5 = { inline: {
3623
3550
  type: "text",
3624
3551
  value: label,
3625
3552
  position: {
3626
- start: sourceSpan.start + 1,
3627
- end: sourceSpan.end - 1
3553
+ start: {
3554
+ line: sourceSpan.start.line,
3555
+ column: sourceSpan.start.column + 1,
3556
+ offset: sourceSpan.start.offset + 1
3557
+ },
3558
+ end: {
3559
+ line: sourceSpan.end.line,
3560
+ column: sourceSpan.end.column - 1,
3561
+ offset: sourceSpan.end.offset - 1
3562
+ }
3628
3563
  }
3629
3564
  }],
3630
3565
  position: sourceSpan
@@ -3632,22 +3567,22 @@ const feature$5 = { inline: {
3632
3567
  }
3633
3568
  },
3634
3569
  {
3635
- kind: "leaf",
3570
+ kind: "text",
3636
3571
  token: 20,
3637
3572
  build: buildInlineText
3638
3573
  },
3639
3574
  {
3640
- kind: "leaf",
3575
+ kind: "text",
3641
3576
  token: 19,
3642
3577
  build: buildInlineText
3643
3578
  },
3644
3579
  {
3645
- kind: "leaf",
3580
+ kind: "text",
3646
3581
  token: 21,
3647
3582
  build: buildDecodedInlineText
3648
3583
  },
3649
3584
  {
3650
- kind: "leaf",
3585
+ kind: "text",
3651
3586
  token: 22,
3652
3587
  build: buildInlineText
3653
3588
  }
@@ -3664,8 +3599,11 @@ function listMarkerPadding(source, lines, index, markerEnd, markerColumn) {
3664
3599
  };
3665
3600
  let offset = markerEnd;
3666
3601
  let column = markerColumn;
3667
- while (offset < lineEnd && (source[offset] === " " || source[offset] === " ")) {
3668
- column += source[offset] === " " ? 4 - column % 4 : 1;
3602
+ while (offset < lineEnd) {
3603
+ const code = source.charCodeAt(offset);
3604
+ if (code === 32) column++;
3605
+ else if (code === 9) column += 4 - column % 4;
3606
+ else break;
3669
3607
  offset++;
3670
3608
  }
3671
3609
  const whitespaceColumns = column - markerColumn;
@@ -3674,20 +3612,22 @@ function listMarkerPadding(source, lines, index, markerEnd, markerColumn) {
3674
3612
  columns: whitespaceColumns,
3675
3613
  prefixColumns: 0
3676
3614
  };
3677
- const consumedColumn = markerColumn + (source[markerEnd] === " " ? 4 - markerColumn % 4 : 1);
3615
+ const firstPaddingColumns = source.charCodeAt(markerEnd) === 9 ? 4 - markerColumn % 4 : 1;
3678
3616
  return {
3679
3617
  offset: markerEnd + 1,
3680
3618
  columns: 1,
3681
- prefixColumns: Math.max(0, consumedColumn - markerColumn - 1)
3619
+ prefixColumns: firstPaddingColumns - 1
3682
3620
  };
3683
3621
  }
3684
3622
  function listMarkerAt(source, lines, index, contentOffset = lineIndentOffset(source, lines, index)) {
3685
3623
  if (contentOffset < 0) return;
3686
3624
  const indent = lines.prefixColumns(index) + contentOffset - lines.start(index);
3687
- const marker = source[contentOffset];
3625
+ const marker = source.charCodeAt(contentOffset);
3688
3626
  const markerEnd = contentOffset + 1;
3689
3627
  const lineEnd = lines.end(index);
3690
- if ((marker === "-" || marker === "+" || marker === "*") && (markerEnd === lineEnd || source[markerEnd] === " " || source[markerEnd] === " ") && !isThematicBreak(source, lines, index, contentOffset)) {
3628
+ if (marker === 45 || marker === 43 || marker === 42) {
3629
+ const following = source.charCodeAt(markerEnd);
3630
+ if (markerEnd !== lineEnd && following !== 32 && following !== 9 || isThematicBreak(source, lines, index, contentOffset)) return;
3691
3631
  const padding = listMarkerPadding(source, lines, index, markerEnd, indent + 1);
3692
3632
  return {
3693
3633
  kind: "unordered",
@@ -3697,11 +3637,10 @@ function listMarkerAt(source, lines, index, contentOffset = lineIndentOffset(sou
3697
3637
  contentOffset: padding.offset,
3698
3638
  contentIndent: indent + 1 + padding.columns,
3699
3639
  contentPrefixColumns: padding.prefixColumns,
3700
- delimiter: marker
3640
+ delimiter: String.fromCharCode(marker)
3701
3641
  };
3702
3642
  }
3703
- const markerCode = source.charCodeAt(contentOffset);
3704
- if (markerCode < 48 || markerCode > 57) return;
3643
+ if (marker < 48 || marker > 57) return;
3705
3644
  let startNumber = 0;
3706
3645
  let orderedEnd = contentOffset;
3707
3646
  while (orderedEnd < lineEnd && orderedEnd - contentOffset < 9) {
@@ -3711,7 +3650,11 @@ function listMarkerAt(source, lines, index, contentOffset = lineIndentOffset(sou
3711
3650
  orderedEnd++;
3712
3651
  }
3713
3652
  const delimiter = source[orderedEnd];
3714
- if (delimiter !== "." && delimiter !== ")" || orderedEnd + 1 < lineEnd && source[orderedEnd + 1] !== " " && source[orderedEnd + 1] !== " ") return;
3653
+ if (delimiter !== "." && delimiter !== ")") return;
3654
+ if (orderedEnd + 1 < lineEnd) {
3655
+ const code = source.charCodeAt(orderedEnd + 1);
3656
+ if (code !== 32 && code !== 9) return;
3657
+ }
3715
3658
  orderedEnd++;
3716
3659
  const markerWidth = orderedEnd - contentOffset;
3717
3660
  const padding = listMarkerPadding(source, lines, index, orderedEnd, indent + markerWidth);
@@ -3763,6 +3706,7 @@ function hasTaskListContent(source, tokens, firstChunk, contentStart) {
3763
3706
  const buildListItem = (tokenStart, context) => {
3764
3707
  const tokens = context.structure.tokens;
3765
3708
  const markerKind = tokens.kind(tokenStart);
3709
+ const start = context.locator.locationAt(tokens.start(tokenStart));
3766
3710
  const children = buildBlockChildren(tokenStart, context);
3767
3711
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
3768
3712
  return {
@@ -3771,22 +3715,18 @@ const buildListItem = (tokenStart, context) => {
3771
3715
  checked: markerKind === 17 ? true : markerKind === 16 ? false : null,
3772
3716
  children,
3773
3717
  position: {
3774
- start: context.structure.tokens.start(tokenStart),
3775
- end: lastChildEnd(children, blockEnd(tokenStart, context))
3718
+ start,
3719
+ end: lastChildEnd(children) ?? context.locator.locationAt(tokens.end(close))
3776
3720
  }
3777
3721
  };
3778
3722
  };
3779
3723
  function createBuildList(ordered) {
3780
3724
  return (tokenStart, context) => {
3781
- const structure = context.structure;
3782
- const tokens = structure.tokens;
3725
+ const tokens = context.structure.tokens;
3726
+ const start = context.locator.locationAt(tokens.start(tokenStart));
3783
3727
  const items = [];
3784
3728
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
3785
- for (let child = tokenStart + 1; child < close;) {
3786
- const length = tokens.nodeLength(child);
3787
- if (length > 0 && structure.ruleOf(child).rule === 5) items.push(buildListItem(child, context));
3788
- child += length || 1;
3789
- }
3729
+ for (let child = tokenStart + 1; child < close; child += tokens.nodeLength(child)) items.push(buildBlockNode(child, context));
3790
3730
  return {
3791
3731
  type: "list",
3792
3732
  ordered,
@@ -3794,8 +3734,8 @@ function createBuildList(ordered) {
3794
3734
  spread: tokens.value(close) === true,
3795
3735
  children: items,
3796
3736
  position: {
3797
- start: context.structure.tokens.start(tokenStart),
3798
- end: lastChildEnd(items, context.structure.tokens.end(tokenStart))
3737
+ start,
3738
+ end: lastChildEnd(items) ?? context.locator.locationAt(tokens.end(tokenStart))
3799
3739
  }
3800
3740
  };
3801
3741
  };
@@ -3813,26 +3753,31 @@ const listStart = (source, lines, start, contentOffset, out, context) => {
3813
3753
  let listSpread = false;
3814
3754
  let trailingBlank = false;
3815
3755
  while (marker && sameList(marker, listMarker)) {
3756
+ let sibling;
3816
3757
  listSpread ||= trailingBlank;
3817
3758
  trailingBlank = false;
3818
3759
  out.push(15, marker.offset, marker.end);
3819
3760
  const itemLines = new BlockLines();
3820
3761
  itemLines.pushFrom(lines, index, marker.contentOffset, marker.contentPrefixColumns);
3821
3762
  let hasContent = !isBlank(source, itemLines, 0);
3822
- let lazyParagraph = context.endsWithParagraphLeaf(source, itemLines, 0);
3763
+ let paragraphLeaf = hasContent ? 2 : 0;
3823
3764
  index++;
3824
3765
  while (index < lines.length) {
3825
3766
  const candidate = listMarkerAt(source, lines, index);
3826
- if (candidate && candidate.indent < marker.contentIndent) break;
3767
+ if (candidate && candidate.indent < marker.contentIndent) {
3768
+ sibling = candidate;
3769
+ break;
3770
+ }
3827
3771
  if (isBlank(source, lines, index)) {
3828
3772
  if (!hasContent) {
3829
3773
  trailingBlank = true;
3830
3774
  index++;
3775
+ sibling = index < lines.length ? listMarkerAt(source, lines, index) : void 0;
3831
3776
  break;
3832
3777
  }
3833
3778
  itemLines.pushFrom(lines, index);
3834
3779
  trailingBlank = true;
3835
- lazyParagraph = false;
3780
+ paragraphLeaf = 0;
3836
3781
  index++;
3837
3782
  continue;
3838
3783
  }
@@ -3841,19 +3786,19 @@ const listStart = (source, lines, start, contentOffset, out, context) => {
3841
3786
  itemLines.pushFrom(lines, index, content.offset, content.prefixColumns);
3842
3787
  trailingBlank = false;
3843
3788
  hasContent = true;
3844
- lazyParagraph = context.endsWithParagraphLeaf(source, itemLines, itemLines.length - 1);
3789
+ paragraphLeaf = 2;
3845
3790
  index++;
3846
3791
  continue;
3847
3792
  }
3848
- if (!lazyParagraph || context.startsInterruptingBlock(source, lines, index)) break;
3793
+ if (paragraphLeaf === 2) paragraphLeaf = context.endsWithParagraphLeaf(source, itemLines, itemLines.length - 1) ? 1 : 0;
3794
+ if (paragraphLeaf === 0 || context.startsInterruptingBlock(source, lines, index)) break;
3849
3795
  itemLines.pushLazy(lines, index);
3850
- trailingBlank = false;
3851
3796
  index++;
3852
3797
  }
3853
3798
  const itemSpread = context.scanLines(source, itemLines, out);
3854
3799
  listEnd = itemLines.next(itemLines.length - 1);
3855
3800
  out.push(18, listEnd, listEnd, itemSpread ? { value: true } : void 0);
3856
- marker = index < lines.length ? listMarkerAt(source, lines, index) : void 0;
3801
+ marker = sibling;
3857
3802
  }
3858
3803
  out.push(listClose, listEnd, listEnd, listSpread ? { value: true } : void 0);
3859
3804
  return index;
@@ -3892,7 +3837,8 @@ function feature$4(taskList = false) {
3892
3837
  17
3893
3838
  ],
3894
3839
  close: 18
3895
- }
3840
+ },
3841
+ build: buildListItem
3896
3842
  },
3897
3843
  {
3898
3844
  rule: 6,
@@ -3957,19 +3903,15 @@ const blockRules = [{
3957
3903
  token: 28
3958
3904
  },
3959
3905
  build(tokenStart, context) {
3960
- const offset = context.structure.tokens.start(tokenStart);
3961
- const end = context.structure.tokens.end(tokenStart);
3962
- const value = context.structure.tokens.text(context.source, tokenStart);
3963
- const block = context.structure.tokens.value(tokenStart);
3906
+ const tokens = context.structure.tokens;
3907
+ const value = tokens.text(context.source, tokenStart);
3908
+ const block = tokens.value(tokenStart);
3964
3909
  if (!block) throw new Error("Math block lacks fence metadata");
3965
3910
  return {
3966
3911
  type: "math",
3967
3912
  meta: semanticText(block.info) || null,
3968
- value: fencedBlockContent(value, block, 1),
3969
- position: {
3970
- start: offset + block.markerOffset,
3971
- end: block.closed || end < context.structure.tokens.sourceLength ? blockEnd(tokenStart, context) : end
3972
- }
3913
+ value: sourceColumnFenceContent(value, block),
3914
+ position: fencedBlockPosition(tokenStart, block, context)
3973
3915
  };
3974
3916
  }
3975
3917
  }];
@@ -4051,40 +3993,35 @@ function feature$3(options) {
4051
3993
  }
4052
3994
  //#endregion
4053
3995
  //#region src/profile/features/paragraph.ts
4054
- function emitInlineChunks(source, lines, start, end, out) {
4055
- while (start < end) {
4056
- const line = start++;
4057
- const offset = indentOffset(source, lines, line);
4058
- const chunkEnd = start < end ? lines.next(line) : lines.end(line);
4059
- if (chunkEnd > offset) out.push(1, offset, chunkEnd);
4060
- }
4061
- }
4062
3996
  const feature$2 = { block: {
4063
3997
  fallbacks: [(source, lines, start, contentOffset, out, context) => {
3998
+ const openToken = out.length;
3999
+ const offset = lines.start(start);
4000
+ out.push(9, offset, offset);
4001
+ let chunkOffset = contentOffset;
4064
4002
  let index = start + 1;
4065
4003
  while (index < lines.length) {
4066
- if (isBlank(source, lines, index)) break;
4067
- if (lines.lazy(index)) {
4068
- index++;
4069
- continue;
4070
- }
4071
- const contentOffset = lineIndentOffset(source, lines, index);
4072
- const setext = setextMarkerAt(source, lines, index, contentOffset);
4073
- if (setext) {
4074
- const headingStart = lines.start(start);
4075
- out.push(setext === "=" ? 6 : 7, headingStart, headingStart);
4076
- emitInlineChunks(source, lines, start, index, out);
4077
- const lineEnd = lines.end(index);
4078
- out.push(8, lineEnd, lineEnd);
4079
- return index + 1;
4004
+ const lineOffset = lines.lazy(index) ? -1 : lineIndentOffset(source, lines, index);
4005
+ if (lineOffset < 0) {
4006
+ if (isBlank(source, lines, index)) break;
4007
+ } else {
4008
+ if (lineOffset === lines.end(index)) break;
4009
+ const setext = setextMarkerAt(source, lines, index, lineOffset);
4010
+ if (setext) {
4011
+ out.setKind(openToken, setext === "=" ? 6 : 7);
4012
+ out.push(1, chunkOffset, lines.end(index - 1));
4013
+ const lineEnd = lines.end(index);
4014
+ out.push(8, lineEnd, lineEnd);
4015
+ return index + 1;
4016
+ }
4017
+ if (context.startsInterruptingBlock(source, lines, index, lineOffset)) break;
4080
4018
  }
4081
- if (context.startsInterruptingBlock(source, lines, index, contentOffset)) break;
4019
+ out.push(1, chunkOffset, lines.next(index - 1));
4020
+ chunkOffset = lineOffset < 0 ? indentOffset(source, lines, index) : lineOffset;
4082
4021
  index++;
4083
4022
  }
4084
- const offset = lines.start(start);
4085
- out.push(9, offset, offset);
4086
- emitInlineChunks(source, lines, start, index, out);
4087
4023
  const close = lines.end(index - 1);
4024
+ out.push(1, chunkOffset, close);
4088
4025
  out.push(10, close, close);
4089
4026
  return index;
4090
4027
  }],
@@ -4096,16 +4033,18 @@ const feature$2 = { block: {
4096
4033
  close: 10
4097
4034
  },
4098
4035
  inlineContent: true,
4099
- build(tokenStart, context, inline) {
4100
- const children = inline.children;
4101
- return {
4036
+ build(tokenStart, context) {
4037
+ const inline = buildInlineFragment(tokenStart, 4, context);
4038
+ const result = {
4102
4039
  type: "paragraph",
4103
- children,
4040
+ children: inline.children,
4104
4041
  position: {
4105
- start: firstChildStart(children),
4106
- end: blockEnd(tokenStart, context)
4042
+ start: firstChildStart(inline.children),
4043
+ end: context.locator.locationAt(blockEnd(tokenStart, context))
4107
4044
  }
4108
4045
  };
4046
+ if (inline.attributes) result.attributes = inline.attributes;
4047
+ return result;
4109
4048
  }
4110
4049
  }]
4111
4050
  } };
@@ -4288,14 +4227,11 @@ const feature$1 = { block: {
4288
4227
  if (definitionKey === void 0) throw new Error("Expected LinkDefinitionOpen token to contain a definition key");
4289
4228
  return {
4290
4229
  type: "definition",
4291
- identifier: definitionKey.toLowerCase(),
4230
+ identifier: definitionKey,
4292
4231
  label: semanticText(fields.label),
4293
4232
  url: semanticText(fields.destination),
4294
4233
  title: fields.title === void 0 ? null : semanticText(fields.title),
4295
- position: {
4296
- start: context.structure.tokens.start(tokenStart),
4297
- end: blockEnd(tokenStart, context)
4298
- }
4234
+ position: leafBlockPosition(tokenStart, context)
4299
4235
  };
4300
4236
  }
4301
4237
  }],
@@ -4321,8 +4257,16 @@ const feature$1 = { block: {
4321
4257
  //#endregion
4322
4258
  //#region src/profile/features/table.ts
4323
4259
  function appendTableCell(cells, source, start, contentStart, contentEnd) {
4324
- while (contentStart < contentEnd && (source[contentStart] === " " || source[contentStart] === " ")) contentStart++;
4325
- while (contentEnd > contentStart && (source[contentEnd - 1] === " " || source[contentEnd - 1] === " ")) contentEnd--;
4260
+ while (contentStart < contentEnd) {
4261
+ const code = source.charCodeAt(contentStart);
4262
+ if (code !== 32 && code !== 9) break;
4263
+ contentStart++;
4264
+ }
4265
+ while (contentEnd > contentStart) {
4266
+ const code = source.charCodeAt(contentEnd - 1);
4267
+ if (code !== 32 && code !== 9) break;
4268
+ contentEnd--;
4269
+ }
4326
4270
  cells.push(start, contentStart, contentEnd);
4327
4271
  }
4328
4272
  function tableCellsAt(source, lines, index, requirePipe, contentOffset) {
@@ -4331,17 +4275,21 @@ function tableCellsAt(source, lines, index, requirePipe, contentOffset) {
4331
4275
  let backslashes = 0;
4332
4276
  const lineEnd = lines.end(index);
4333
4277
  for (let offset = contentOffset; offset < lineEnd; offset++) {
4334
- const character = source[offset];
4335
- if (character === "\\") {
4278
+ const code = source.charCodeAt(offset);
4279
+ if (code === 92) {
4336
4280
  backslashes++;
4337
4281
  continue;
4338
4282
  }
4339
- if (character === "|" && backslashes % 2 === 0) pipes.push(offset);
4283
+ if (code === 124 && backslashes % 2 === 0) pipes.push(offset);
4340
4284
  backslashes = 0;
4341
4285
  }
4342
4286
  if (requirePipe && pipes.length === 0) return;
4343
4287
  let visibleEnd = lineEnd;
4344
- while (visibleEnd > contentOffset && (source[visibleEnd - 1] === " " || source[visibleEnd - 1] === " ")) visibleEnd--;
4288
+ while (visibleEnd > contentOffset) {
4289
+ const code = source.charCodeAt(visibleEnd - 1);
4290
+ if (code !== 32 && code !== 9) break;
4291
+ visibleEnd--;
4292
+ }
4345
4293
  const trailingPipe = pipes.at(-1) === visibleEnd - 1;
4346
4294
  const leadingPipe = pipes[0] === contentOffset;
4347
4295
  const cells = [];
@@ -4364,17 +4312,17 @@ function tableCellsAt(source, lines, index, requirePipe, contentOffset) {
4364
4312
  function alignmentAt(source, cells, cell) {
4365
4313
  let start = cells[cell + 1];
4366
4314
  let end = cells[cell + 2];
4367
- const left = source[start] === ":";
4315
+ const left = source.charCodeAt(start) === 58;
4368
4316
  if (left) start++;
4369
- const right = source[end - 1] === ":";
4317
+ const right = source.charCodeAt(end - 1) === 58;
4370
4318
  if (right) end--;
4371
4319
  if (start === end) return;
4372
- for (let offset = start; offset < end; offset++) if (source[offset] !== "-") return;
4320
+ for (let offset = start; offset < end; offset++) if (source.charCodeAt(offset) !== 45) return;
4373
4321
  return left ? right ? 37 : 35 : right ? 36 : 34;
4374
4322
  }
4375
4323
  function delimiterAt(source, lines, index, contentOffset) {
4376
- const first = source[contentOffset];
4377
- if (first !== "-" && first !== ":" && first !== "|") return;
4324
+ const first = source.charCodeAt(contentOffset);
4325
+ if (first !== 45 && first !== 58 && first !== 124) return;
4378
4326
  const cells = tableCellsAt(source, lines, index, false, contentOffset);
4379
4327
  if (!cells) return;
4380
4328
  for (let cell = 0; cell < cells.length; cell += 3) {
@@ -4394,28 +4342,30 @@ function emitTableRow(lines, index, cells, out) {
4394
4342
  const lineEnd = lines.end(index);
4395
4343
  out.push(32, lineEnd, lineEnd);
4396
4344
  }
4397
- const buildTableCell = (tokenStart, context, inline) => {
4345
+ const buildTableCell = (tokenStart, context) => {
4398
4346
  const tokens = context.structure.tokens;
4347
+ const start = context.locator.locationAt(tokens.start(tokenStart));
4399
4348
  return {
4400
4349
  type: "tableCell",
4401
- children: inline.children,
4350
+ children: buildInlineFragment(tokenStart, 17, context).children,
4402
4351
  position: {
4403
- start: tokens.start(tokenStart),
4404
- end: tokens.start(tokenStart + tokens.nodeLength(tokenStart))
4352
+ start,
4353
+ end: context.locator.locationAt(tokens.start(tokenStart + tokens.nodeLength(tokenStart)))
4405
4354
  }
4406
4355
  };
4407
4356
  };
4408
4357
  const buildTableRow = (tokenStart, context) => {
4409
4358
  const tokens = context.structure.tokens;
4410
4359
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
4360
+ const start = context.locator.locationAt(tokens.start(tokenStart));
4411
4361
  const children = [];
4412
- for (let cell = tokenStart + 1; cell < close; cell += tokens.nodeLength(cell)) children.push(buildTableCell(cell, context, buildInlineFragment(cell, 17, context)));
4362
+ for (let cell = tokenStart + 1; cell < close; cell += tokens.nodeLength(cell)) children.push(buildBlockNode(cell, context));
4413
4363
  return {
4414
4364
  type: "tableRow",
4415
4365
  children,
4416
4366
  position: {
4417
- start: tokens.start(tokenStart),
4418
- end: tokens.start(close)
4367
+ start,
4368
+ end: context.locator.locationAt(tokens.start(close))
4419
4369
  }
4420
4370
  };
4421
4371
  };
@@ -4465,7 +4415,8 @@ const feature = { block: {
4465
4415
  open: 33,
4466
4416
  close: 1
4467
4417
  },
4468
- inlineContent: true
4418
+ inlineContent: true,
4419
+ build: buildTableCell
4469
4420
  },
4470
4421
  {
4471
4422
  rule: 16,
@@ -4473,7 +4424,8 @@ const feature = { block: {
4473
4424
  kind: "frame",
4474
4425
  open: 31,
4475
4426
  close: 32
4476
- }
4427
+ },
4428
+ build: buildTableRow
4477
4429
  },
4478
4430
  {
4479
4431
  rule: 18,
@@ -4497,17 +4449,18 @@ const feature = { block: {
4497
4449
  build(tokenStart, context) {
4498
4450
  const tokens = context.structure.tokens;
4499
4451
  const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
4452
+ const start = context.locator.locationAt(tokens.start(tokenStart));
4500
4453
  const header = tokenStart + 1;
4501
4454
  const delimiter = header + tokens.nodeLength(header);
4502
- const rows = [buildTableRow(header, context)];
4503
- for (let row = delimiter + tokens.nodeLength(delimiter); row < close; row += tokens.nodeLength(row)) rows.push(buildTableRow(row, context));
4455
+ const rows = [buildBlockNode(header, context)];
4456
+ for (let row = delimiter + tokens.nodeLength(delimiter); row < close; row += tokens.nodeLength(row)) rows.push(buildBlockNode(row, context));
4504
4457
  return {
4505
4458
  type: "table",
4506
4459
  align: tableAlignment(delimiter, context),
4507
4460
  children: rows,
4508
4461
  position: {
4509
- start: tokens.start(tokenStart),
4510
- end: tokens.start(close)
4462
+ start,
4463
+ end: context.locator.locationAt(tokens.start(close))
4511
4464
  }
4512
4465
  };
4513
4466
  }
@@ -4665,7 +4618,7 @@ function compileDelimiterConfigs(delimiterConfigs) {
4665
4618
  return delimiterByKind;
4666
4619
  }
4667
4620
  //#endregion
4668
- //#region src/profile/inline-program.ts
4621
+ //#region src/profile/resolve.ts
4669
4622
  const frameHeaderSize = 1;
4670
4623
  const noBracketFrames = Object.freeze([0]);
4671
4624
  const delimiterOnlyFrames = Object.freeze([2]);
@@ -5049,7 +5002,7 @@ function emitResolvedTokens(tokens, frames, replacements) {
5049
5002
  }
5050
5003
  return result;
5051
5004
  }
5052
- function compileInlineProgram(options) {
5005
+ function compileInlineResolver(options) {
5053
5006
  return (delimiterConfigs) => {
5054
5007
  const delimiterByKind = compileDelimiterConfigs(delimiterConfigs);
5055
5008
  return (source, tokens, context) => {
@@ -5094,7 +5047,7 @@ function compileProfile(options = {}) {
5094
5047
  }
5095
5048
  return {
5096
5049
  block: compileBlockProfile(blockFeatures),
5097
- inline: compileInlineProfile(inlineFeatures, compileInlineProgram({
5050
+ inline: compileInlineProfile(inlineFeatures, compileInlineResolver({
5098
5051
  component: options.component === true,
5099
5052
  footnote: options.footnote === true
5100
5053
  }))