satorigear 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -12
- package/dist/index.mjs +632 -656
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -120,6 +120,9 @@ var BlockLines = class BlockLines {
|
|
|
120
120
|
end: this.locationAt(end)
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
+
physicallyContiguous() {
|
|
124
|
+
return this.#sourceLength > 0;
|
|
125
|
+
}
|
|
123
126
|
push(start, end, next, prefixColumns = 0, lazy = false) {
|
|
124
127
|
const field = this.#fieldLength;
|
|
125
128
|
let fields = this.#fields;
|
|
@@ -137,6 +140,31 @@ var BlockLines = class BlockLines {
|
|
|
137
140
|
pushFrom(lines, index, start = lines.start(index), prefixColumns = lines.prefixColumns(index), lazy = lines.lazy(index)) {
|
|
138
141
|
this.push(start, lines.end(index), lines.next(index), prefixColumns, lazy);
|
|
139
142
|
}
|
|
143
|
+
pushAfterColumns(source, lines, index, columns) {
|
|
144
|
+
let offset = lines.start(index);
|
|
145
|
+
let consumed = lines.prefixColumns(index);
|
|
146
|
+
const end = lines.end(index);
|
|
147
|
+
while (offset < end && consumed < columns) {
|
|
148
|
+
const code = source.charCodeAt(offset);
|
|
149
|
+
if (code === 32) consumed++;
|
|
150
|
+
else if (code === 9) consumed += 4 - consumed % 4;
|
|
151
|
+
else break;
|
|
152
|
+
offset++;
|
|
153
|
+
}
|
|
154
|
+
if (offset === end) return 0;
|
|
155
|
+
if (consumed < columns) return -1;
|
|
156
|
+
const contentOffset = offset;
|
|
157
|
+
const prefixColumns = consumed - columns;
|
|
158
|
+
while (offset < end) {
|
|
159
|
+
const code = source.charCodeAt(offset);
|
|
160
|
+
if (code !== 32 && code !== 9) {
|
|
161
|
+
this.pushFrom(lines, index, contentOffset, prefixColumns);
|
|
162
|
+
return 1;
|
|
163
|
+
}
|
|
164
|
+
offset++;
|
|
165
|
+
}
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
140
168
|
pushLazy(lines, index) {
|
|
141
169
|
this.pushFrom(lines, index, void 0, void 0, true);
|
|
142
170
|
}
|
|
@@ -256,7 +284,7 @@ function lineIndentOffset(source, lines, index) {
|
|
|
256
284
|
const limit = offset + 3 - lines.prefixColumns(index);
|
|
257
285
|
const end = lines.end(index);
|
|
258
286
|
while (offset < end && offset < limit && source.charCodeAt(offset) === 32) offset++;
|
|
259
|
-
if (offset > limit) return -1;
|
|
287
|
+
if (offset > limit || offset === end) return -1;
|
|
260
288
|
const code = source.charCodeAt(offset);
|
|
261
289
|
return code === 32 || code === 9 ? -1 : offset;
|
|
262
290
|
}
|
|
@@ -300,21 +328,6 @@ function logicalLine(source, lines, index) {
|
|
|
300
328
|
}
|
|
301
329
|
return result + source.slice(offset, lines.next(index));
|
|
302
330
|
}
|
|
303
|
-
function contentAfterColumns(source, lines, index, columns) {
|
|
304
|
-
let offset = lines.start(index);
|
|
305
|
-
let consumed = lines.prefixColumns(index);
|
|
306
|
-
const end = lines.end(index);
|
|
307
|
-
while (offset < end && consumed < columns) {
|
|
308
|
-
if (source[offset] === " ") consumed++;
|
|
309
|
-
else if (source[offset] === " ") consumed += 4 - consumed % 4;
|
|
310
|
-
else break;
|
|
311
|
-
offset++;
|
|
312
|
-
}
|
|
313
|
-
if (consumed >= columns) return {
|
|
314
|
-
offset,
|
|
315
|
-
prefixColumns: consumed - columns
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
331
|
function removeIndent(value, columns) {
|
|
319
332
|
let offset = 0;
|
|
320
333
|
let consumed = 0;
|
|
@@ -332,12 +345,21 @@ const emptyArray = [];
|
|
|
332
345
|
const emptySet = new Set();
|
|
333
346
|
//#endregion
|
|
334
347
|
//#region src/block/tokens.ts
|
|
348
|
+
function copyMetadata(target, source, start, end, targetStart) {
|
|
349
|
+
end = Math.min(end, source.length);
|
|
350
|
+
for (let read = start, write = targetStart; read < end; read++, write++) {
|
|
351
|
+
const value = source[read];
|
|
352
|
+
if (value) target[write] = value;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
335
355
|
var BlockTokenStream = class {
|
|
336
356
|
#definitionCounts;
|
|
337
357
|
#definitionMembershipChanges;
|
|
338
358
|
#fieldLength;
|
|
339
359
|
#fields;
|
|
360
|
+
#groupField = -1;
|
|
340
361
|
#metadata;
|
|
362
|
+
#opens = [];
|
|
341
363
|
#relativeStart;
|
|
342
364
|
#sourceLength;
|
|
343
365
|
constructor(sourceLength = 0) {
|
|
@@ -350,7 +372,9 @@ var BlockTokenStream = class {
|
|
|
350
372
|
this.#definitionCounts?.clear();
|
|
351
373
|
this.#definitionMembershipChanges?.clear();
|
|
352
374
|
this.#fieldLength = 0;
|
|
375
|
+
this.#groupField = -1;
|
|
353
376
|
this.#metadata = void 0;
|
|
377
|
+
this.#opens.length = 0;
|
|
354
378
|
this.#relativeStart = Number.POSITIVE_INFINITY;
|
|
355
379
|
this.#sourceLength = sourceLength;
|
|
356
380
|
}
|
|
@@ -363,7 +387,10 @@ var BlockTokenStream = class {
|
|
|
363
387
|
hasDefinition(key) {
|
|
364
388
|
return this.#definitionCounts?.has(key) === true;
|
|
365
389
|
}
|
|
366
|
-
|
|
390
|
+
hasDefinitions() {
|
|
391
|
+
return !!this.#definitionCounts?.size;
|
|
392
|
+
}
|
|
393
|
+
push(kind, start, end, meta, role) {
|
|
367
394
|
const field = this.#fieldLength;
|
|
368
395
|
this.#ensureCapacity(field + 4);
|
|
369
396
|
this.#fields[field + 0] = kind;
|
|
@@ -372,44 +399,34 @@ var BlockTokenStream = class {
|
|
|
372
399
|
this.#fields[field + 3] = 0;
|
|
373
400
|
this.#fieldLength += 4;
|
|
374
401
|
if (meta) {
|
|
375
|
-
this.#metadata ??=
|
|
376
|
-
this.#metadata
|
|
402
|
+
this.#metadata ??= [];
|
|
403
|
+
this.#metadata[this.length - 1] = meta;
|
|
377
404
|
const definitionKey = meta.definitionKey;
|
|
378
405
|
if (definitionKey !== void 0) this.#updateDefinitionCount(definitionKey, 1, false);
|
|
379
406
|
}
|
|
407
|
+
const encodedRole = role ?? kind;
|
|
408
|
+
if (encodedRole >= 64) this.#indexToken(field, encodedRole);
|
|
380
409
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
395
|
-
if (rule && !rule.block) {
|
|
396
|
-
const start = field;
|
|
397
|
-
do
|
|
398
|
-
field += 4;
|
|
399
|
-
while (field < fieldLength && rules[fields[field]] === rule);
|
|
400
|
-
fields[start + 3] = (field - start) / 4;
|
|
401
|
-
field -= 4;
|
|
402
|
-
continue;
|
|
403
|
-
}
|
|
404
|
-
if (close === kind) {
|
|
405
|
-
const open = opens.pop();
|
|
406
|
-
close = fields[open + 3];
|
|
407
|
-
fields[open + 3] = (field - open) / 4 + 1;
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
if (rule) fields[field + 3] = 1;
|
|
410
|
+
#indexToken(field, encodedRole) {
|
|
411
|
+
if (encodedRole < 192) {
|
|
412
|
+
this.#opens.push(field);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (encodedRole < 256) {
|
|
416
|
+
const open = this.#opens.pop();
|
|
417
|
+
this.#fields[open + 3] = (field - open) / 4 + 1;
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (encodedRole < 320) {
|
|
421
|
+
this.#fields[field + 3] = 1;
|
|
422
|
+
return;
|
|
411
423
|
}
|
|
412
|
-
|
|
424
|
+
const group = this.#groupField;
|
|
425
|
+
const previous = field - 4;
|
|
426
|
+
if (group < 0 || previous < 0 || this.#fields[previous + 0] < 320) {
|
|
427
|
+
this.#groupField = field;
|
|
428
|
+
this.#fields[field + 3] = 1;
|
|
429
|
+
} else this.#fields[group + 3]++;
|
|
413
430
|
}
|
|
414
431
|
nodeLength(index) {
|
|
415
432
|
return this.#fields[index * 4 + 3];
|
|
@@ -420,8 +437,8 @@ var BlockTokenStream = class {
|
|
|
420
437
|
const nextStart = next.start(nextIndex);
|
|
421
438
|
const nextEnd = next.end(nextIndex);
|
|
422
439
|
if (this.kind(index) !== next.kind(nextIndex) || start + delta !== nextStart || end + delta !== nextEnd) return false;
|
|
423
|
-
const metadata = this.#metadata?.
|
|
424
|
-
const nextMetadata = next.#metadata?.
|
|
440
|
+
const metadata = this.#metadata?.[index];
|
|
441
|
+
const nextMetadata = next.#metadata?.[nextIndex];
|
|
425
442
|
if (metadata !== nextMetadata) {
|
|
426
443
|
if (metadata?.definitionKey !== nextMetadata?.definitionKey) return false;
|
|
427
444
|
const value = metadata?.value;
|
|
@@ -448,8 +465,8 @@ var BlockTokenStream = class {
|
|
|
448
465
|
const oldEnd = end - stableSuffixLength;
|
|
449
466
|
const newEnd = start + replacementLength - stableSuffixLength;
|
|
450
467
|
this.#definitionMembershipChanges?.clear();
|
|
451
|
-
for (let index = oldStart; index < oldEnd; index++) this.#updateDefinitionCount(this.#metadata?.
|
|
452
|
-
for (let index = stablePrefixLength; index < replacementLength - stableSuffixLength; index++) this.#updateDefinitionCount(replacement.#metadata?.
|
|
468
|
+
for (let index = oldStart; index < oldEnd; index++) this.#updateDefinitionCount(this.#metadata?.[index]?.definitionKey, -1, true);
|
|
469
|
+
for (let index = stablePrefixLength; index < replacementLength - stableSuffixLength; index++) this.#updateDefinitionCount(replacement.#metadata?.[index]?.definitionKey, 1, true);
|
|
453
470
|
const change = {
|
|
454
471
|
definitionMembershipChanges: this.#definitionMembershipChanges ?? emptySet,
|
|
455
472
|
newEnd,
|
|
@@ -490,21 +507,21 @@ var BlockTokenStream = class {
|
|
|
490
507
|
}
|
|
491
508
|
const indexDelta = replacementLength - replacedLength;
|
|
492
509
|
if (end === previousLength || indexDelta === 0) {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
if (
|
|
498
|
-
const metadata = this.#metadata ??= new Map();
|
|
499
|
-
for (const [index, value] of replacement.#metadata) metadata.set(start + index, value);
|
|
500
|
-
}
|
|
501
|
-
if (this.#metadata?.size === 0) this.#metadata = void 0;
|
|
510
|
+
const metadata = this.#metadata;
|
|
511
|
+
if (metadata) metadata.fill(void 0, start, end);
|
|
512
|
+
const replacementMetadata = replacement.#metadata;
|
|
513
|
+
if (replacementMetadata) copyMetadata(this.#metadata ??= [], replacementMetadata, 0, replacementMetadata.length, start);
|
|
514
|
+
if (end === previousLength && this.#metadata) this.#metadata.length = Math.min(this.#metadata.length, start + replacementLength);
|
|
502
515
|
} else {
|
|
503
|
-
const metadata =
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
516
|
+
const metadata = [];
|
|
517
|
+
const previousMetadata = this.#metadata;
|
|
518
|
+
if (previousMetadata) {
|
|
519
|
+
copyMetadata(metadata, previousMetadata, 0, start, 0);
|
|
520
|
+
copyMetadata(metadata, previousMetadata, end, previousMetadata.length, end + indexDelta);
|
|
521
|
+
}
|
|
522
|
+
const replacementMetadata = replacement.#metadata;
|
|
523
|
+
if (replacementMetadata) copyMetadata(metadata, replacementMetadata, 0, replacementMetadata.length, start);
|
|
524
|
+
this.#metadata = metadata.length > 0 ? metadata : void 0;
|
|
508
525
|
}
|
|
509
526
|
const newSuffixStart = start + replacementLength;
|
|
510
527
|
this.#relativeStart = newSuffixStart < this.length ? newSuffixStart : Number.POSITIVE_INFINITY;
|
|
@@ -512,13 +529,15 @@ var BlockTokenStream = class {
|
|
|
512
529
|
return change;
|
|
513
530
|
}
|
|
514
531
|
truncate(length) {
|
|
532
|
+
this.#groupField = -1;
|
|
515
533
|
this.#fieldLength = length * 4;
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
534
|
+
const metadata = this.#metadata;
|
|
535
|
+
if (metadata) {
|
|
536
|
+
for (let index = length; index < metadata.length; index++) {
|
|
537
|
+
const value = metadata[index];
|
|
538
|
+
if (value) this.#updateDefinitionCount(value.definitionKey, -1, false);
|
|
520
539
|
}
|
|
521
|
-
|
|
540
|
+
metadata.length = Math.min(metadata.length, length);
|
|
522
541
|
}
|
|
523
542
|
}
|
|
524
543
|
kind(index) {
|
|
@@ -542,13 +561,13 @@ var BlockTokenStream = class {
|
|
|
542
561
|
return last === 10 ? end - (source.charCodeAt(end - 2) === 13 ? 2 : 1) : last === 13 ? end - 1 : end;
|
|
543
562
|
}
|
|
544
563
|
text(source, index) {
|
|
545
|
-
return this.#metadata?.
|
|
564
|
+
return this.#metadata?.[index]?.text ?? source.slice(this.start(index), this.end(index));
|
|
546
565
|
}
|
|
547
566
|
value(index) {
|
|
548
|
-
return this.#metadata?.
|
|
567
|
+
return this.#metadata?.[index]?.value;
|
|
549
568
|
}
|
|
550
569
|
definitionKey(index) {
|
|
551
|
-
return this.#metadata?.
|
|
570
|
+
return this.#metadata?.[index]?.definitionKey;
|
|
552
571
|
}
|
|
553
572
|
#updateDefinitionCount(key, delta, trackMembership) {
|
|
554
573
|
if (key === void 0) return;
|
|
@@ -579,15 +598,18 @@ function appendLogicalToken(out, kind, source, lines, start, end, value) {
|
|
|
579
598
|
const tokenStart = lines.start(start);
|
|
580
599
|
const lastLine = end - 1;
|
|
581
600
|
const tokenEnd = lines.next(lastLine);
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
601
|
+
let canSliceSource = lines.physicallyContiguous();
|
|
602
|
+
if (!canSliceSource) {
|
|
603
|
+
const previous = source[tokenStart - 1];
|
|
604
|
+
canSliceSource = lines.prefixColumns(start) === 0 && (tokenStart === 0 || previous === "\n" || previous === "\r");
|
|
605
|
+
let previousLineEnd = lines.next(start);
|
|
606
|
+
for (let line = start + 1; canSliceSource && line < end; line++) {
|
|
607
|
+
if (lines.prefixColumns(line) !== 0 || lines.start(line) !== previousLineEnd) {
|
|
608
|
+
canSliceSource = false;
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
previousLineEnd = lines.next(line);
|
|
589
612
|
}
|
|
590
|
-
previousLineEnd = lines.next(line);
|
|
591
613
|
}
|
|
592
614
|
let text;
|
|
593
615
|
if (!canSliceSource) {
|
|
@@ -665,7 +687,7 @@ var BlockScanContext = class {
|
|
|
665
687
|
contentIndex = 0;
|
|
666
688
|
continue;
|
|
667
689
|
}
|
|
668
|
-
return !
|
|
690
|
+
return !this.startsInterruptingBlock(source, contentLines, contentIndex, contentOffset);
|
|
669
691
|
}
|
|
670
692
|
}
|
|
671
693
|
retainLookahead(end) {
|
|
@@ -734,7 +756,6 @@ var BlockScanner = class {
|
|
|
734
756
|
tokenStart
|
|
735
757
|
});
|
|
736
758
|
});
|
|
737
|
-
tokens.indexStructure(this.#profile.rules);
|
|
738
759
|
records.length = recordIndex;
|
|
739
760
|
this.#lines = lines;
|
|
740
761
|
}
|
|
@@ -805,7 +826,6 @@ var BlockScanner = class {
|
|
|
805
826
|
const expandedEnd = Math.min(nextSource.length, restartOffset + (scanEnd - restartOffset) * 2);
|
|
806
827
|
scanLineEnd = nextLines.indexAtOrAfter(expandedEnd);
|
|
807
828
|
}
|
|
808
|
-
replacement.indexStructure(this.#profile.rules);
|
|
809
829
|
const oldTokenLength = this.#tokens.length;
|
|
810
830
|
const oldTokenEnd = convergedIndex < 0 ? oldTokenLength : previousRecords[convergedIndex].tokenStart;
|
|
811
831
|
const tokenChange = this.#tokens.replace(oldTokenStart, oldTokenEnd, replacement, changedSpan.start, oldChangedEnd);
|
|
@@ -875,30 +895,27 @@ function buildBlockChildren(tokenStart, context) {
|
|
|
875
895
|
}
|
|
876
896
|
//#endregion
|
|
877
897
|
//#region src/source-view.ts
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
start: this.#offset + start,
|
|
891
|
-
end: this.#offset + end
|
|
892
|
-
};
|
|
893
|
-
}
|
|
894
|
-
shift(delta) {
|
|
895
|
-
this.#offset += delta;
|
|
896
|
-
}
|
|
897
|
-
};
|
|
898
|
-
var SegmentedSourceView = class {
|
|
898
|
+
function containingSegment(segments, offset) {
|
|
899
|
+
let low = 0;
|
|
900
|
+
let high = segments.length >>> 1;
|
|
901
|
+
while (low < high) {
|
|
902
|
+
const middle = low + high >>> 1;
|
|
903
|
+
if (offset < segments[middle * 2 + 1]) high = middle;
|
|
904
|
+
else low = middle + 1;
|
|
905
|
+
}
|
|
906
|
+
return low * 2;
|
|
907
|
+
}
|
|
908
|
+
var SourceView = class {
|
|
909
|
+
#offset = 0;
|
|
899
910
|
#segments;
|
|
900
911
|
text;
|
|
901
|
-
constructor(source,
|
|
912
|
+
constructor(source, startOrRanges, end) {
|
|
913
|
+
if (typeof startOrRanges === "number") {
|
|
914
|
+
this.#offset = startOrRanges;
|
|
915
|
+
this.text = source.slice(startOrRanges, end);
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
const ranges = startOrRanges;
|
|
902
919
|
const parts = [];
|
|
903
920
|
let viewOffset = 0;
|
|
904
921
|
let segmentCount = 0;
|
|
@@ -917,75 +934,66 @@ var SegmentedSourceView = class {
|
|
|
917
934
|
this.#segments = ranges;
|
|
918
935
|
this.text = parts.join("");
|
|
919
936
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
if (
|
|
923
|
-
|
|
924
|
-
return
|
|
937
|
+
mapOffset(offset) {
|
|
938
|
+
const segments = this.#segments;
|
|
939
|
+
if (!segments) return this.#offset + offset;
|
|
940
|
+
if (offset === this.text.length) return segments[segments.length - 2] + offset;
|
|
941
|
+
return segments[containingSegment(segments, offset)] + offset;
|
|
925
942
|
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
};
|
|
931
|
-
if (start === end) {
|
|
932
|
-
const point = this.mapPoint(start);
|
|
933
|
-
return {
|
|
934
|
-
start: point,
|
|
935
|
-
end: point
|
|
936
|
-
};
|
|
937
|
-
}
|
|
938
|
-
const first = this.#containingSegment(start);
|
|
939
|
-
const last = this.#containingSegment(end - 1);
|
|
940
|
-
return {
|
|
941
|
-
start: this.#segments[first] + start,
|
|
942
|
-
end: this.#segments[last] + end
|
|
943
|
-
};
|
|
943
|
+
mapEnd(offset) {
|
|
944
|
+
const segments = this.#segments;
|
|
945
|
+
if (!segments) return this.#offset + offset;
|
|
946
|
+
return segments[containingSegment(segments, Math.max(0, offset - 1))] + offset;
|
|
944
947
|
}
|
|
945
948
|
shift(delta) {
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
let high = this.#segments.length >>> 1;
|
|
951
|
-
while (low < high) {
|
|
952
|
-
const middle = low + high >>> 1;
|
|
953
|
-
if (offset < this.#segments[middle * 2 + 1]) high = middle;
|
|
954
|
-
else low = middle + 1;
|
|
949
|
+
const segments = this.#segments;
|
|
950
|
+
if (!segments) {
|
|
951
|
+
this.#offset += delta;
|
|
952
|
+
return;
|
|
955
953
|
}
|
|
956
|
-
|
|
954
|
+
for (let index = 0; index < segments.length; index += 2) segments[index] += delta;
|
|
957
955
|
}
|
|
958
956
|
};
|
|
959
957
|
//#endregion
|
|
960
958
|
//#region src/inline/region.ts
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
959
|
+
const definitionAny = Symbol();
|
|
960
|
+
var TrackedDefinitionLookup = class {
|
|
961
|
+
definitions;
|
|
962
|
+
dependencies;
|
|
963
|
+
constructor(definitions) {
|
|
964
|
+
this.definitions = definitions;
|
|
965
|
+
}
|
|
966
|
+
hasDefinition(key) {
|
|
967
|
+
(this.dependencies ??= new Set()).add(key);
|
|
968
|
+
return this.definitions.hasDefinition(key);
|
|
969
|
+
}
|
|
970
|
+
hasDefinitions() {
|
|
971
|
+
const hasAny = this.definitions.hasDefinitions();
|
|
972
|
+
if (!hasAny) (this.dependencies ??= new Set()).add(definitionAny);
|
|
973
|
+
return hasAny;
|
|
974
|
+
}
|
|
975
|
+
};
|
|
965
976
|
var InlineRegion = class {
|
|
966
977
|
#definitionDependencies;
|
|
967
978
|
#rawTokens;
|
|
968
979
|
#profile;
|
|
969
|
-
|
|
980
|
+
tokens;
|
|
970
981
|
tokenStart;
|
|
971
982
|
view;
|
|
972
|
-
constructor(profile, binding,
|
|
983
|
+
constructor(profile, binding, definitions) {
|
|
973
984
|
this.#profile = profile;
|
|
974
985
|
this.tokenStart = binding.tokenStart;
|
|
975
986
|
this.view = binding.view;
|
|
976
|
-
this.#updateTokens(binding.view.text,
|
|
977
|
-
}
|
|
978
|
-
get tokens() {
|
|
979
|
-
return this.#tokens;
|
|
987
|
+
this.#updateTokens(binding.view.text, definitions, emptySet);
|
|
980
988
|
}
|
|
981
|
-
update(binding,
|
|
982
|
-
this.#updateTokens(binding.view.text,
|
|
989
|
+
update(binding, definitions, definitionMembershipChanges) {
|
|
990
|
+
this.#updateTokens(binding.view.text, definitions, definitionMembershipChanges);
|
|
983
991
|
this.tokenStart = binding.tokenStart;
|
|
984
992
|
this.view = binding.view;
|
|
985
993
|
return this;
|
|
986
994
|
}
|
|
987
|
-
updateDefinitions(
|
|
988
|
-
return this.#updateTokens(this.view.text,
|
|
995
|
+
updateDefinitions(definitions, definitionMembershipChanges) {
|
|
996
|
+
return this.#updateTokens(this.view.text, definitions, definitionMembershipChanges);
|
|
989
997
|
}
|
|
990
998
|
shift(delta, tokenDelta) {
|
|
991
999
|
this.tokenStart += tokenDelta;
|
|
@@ -993,85 +1001,33 @@ var InlineRegion = class {
|
|
|
993
1001
|
}
|
|
994
1002
|
#dependenciesChanged(definitionMembershipChanges) {
|
|
995
1003
|
const dependencies = this.#definitionDependencies;
|
|
996
|
-
if (dependencies.
|
|
997
|
-
|
|
1004
|
+
if (dependencies.has(definitionAny)) return definitionMembershipChanges.size > 0;
|
|
1005
|
+
const labels = dependencies;
|
|
1006
|
+
if (labels.size < definitionMembershipChanges.size) {
|
|
1007
|
+
for (const key of labels) if (definitionMembershipChanges.has(key)) return true;
|
|
998
1008
|
} else for (const key of definitionMembershipChanges) if (dependencies.has(key)) return true;
|
|
999
1009
|
return false;
|
|
1000
1010
|
}
|
|
1001
|
-
#updateTokens(source,
|
|
1011
|
+
#updateTokens(source, definitions, definitionMembershipChanges) {
|
|
1002
1012
|
const previousTokens = this.#rawTokens;
|
|
1003
1013
|
const sourceUnchanged = previousTokens !== void 0 && source === this.view.text;
|
|
1004
1014
|
if (sourceUnchanged && !this.#dependenciesChanged(definitionMembershipChanges)) return false;
|
|
1005
|
-
|
|
1006
|
-
definitionContext,
|
|
1007
|
-
hasDefinition
|
|
1008
|
-
};
|
|
1015
|
+
definitions.dependencies = void 0;
|
|
1009
1016
|
const rawTokens = sourceUnchanged ? previousTokens : this.#profile.tokenize(source);
|
|
1010
|
-
const tokens = this.#profile.resolve(source, rawTokens,
|
|
1011
|
-
this.#definitionDependencies =
|
|
1017
|
+
const tokens = this.#profile.resolve(source, rawTokens, definitions);
|
|
1018
|
+
this.#definitionDependencies = definitions.dependencies ?? emptySet;
|
|
1012
1019
|
this.#rawTokens = rawTokens;
|
|
1013
|
-
this
|
|
1020
|
+
this.tokens = tokens;
|
|
1014
1021
|
return true;
|
|
1015
1022
|
}
|
|
1016
1023
|
};
|
|
1017
|
-
var
|
|
1018
|
-
#
|
|
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
|
|
1069
|
-
//#region src/syntax-state.ts
|
|
1070
|
-
var SyntaxState = class {
|
|
1024
|
+
var InlineRegionState = class {
|
|
1025
|
+
#lookup;
|
|
1071
1026
|
#profile;
|
|
1072
1027
|
#regionsByBlock = [];
|
|
1073
1028
|
#structure;
|
|
1074
1029
|
constructor(profile, structure) {
|
|
1030
|
+
this.#lookup = new TrackedDefinitionLookup(structure.tokens);
|
|
1075
1031
|
this.#profile = profile;
|
|
1076
1032
|
this.#structure = structure;
|
|
1077
1033
|
}
|
|
@@ -1137,7 +1093,7 @@ var SyntaxState = class {
|
|
|
1137
1093
|
while (displacedIndex < displacedRegions.length && displacedRegions[displacedIndex].tokenStart < previousTokenStart) displacedIndex++;
|
|
1138
1094
|
if (displacedRegions[displacedIndex]?.tokenStart === previousTokenStart) candidate = displacedRegions[displacedIndex++];
|
|
1139
1095
|
}
|
|
1140
|
-
regions[regionIndex] = candidate
|
|
1096
|
+
regions[regionIndex] = candidate?.update(binding, this.#lookup, definitionMembershipChanges) ?? new InlineRegion(this.#profile, binding, this.#lookup);
|
|
1141
1097
|
}
|
|
1142
1098
|
regionsByBlock[blockIndex] = regions;
|
|
1143
1099
|
}
|
|
@@ -1146,7 +1102,7 @@ var SyntaxState = class {
|
|
|
1146
1102
|
for (let index = start; index < end; index++) {
|
|
1147
1103
|
const regions = regionsByBlock[index];
|
|
1148
1104
|
let changed = false;
|
|
1149
|
-
for (const region of regions) if (region.updateDefinitions(
|
|
1105
|
+
for (const region of regions) if (region.updateDefinitions(this.#lookup, definitionMembershipChanges)) changed = true;
|
|
1150
1106
|
if (changed) (invalidatedBlocks ??= []).push(index);
|
|
1151
1107
|
}
|
|
1152
1108
|
};
|
|
@@ -1157,6 +1113,54 @@ var SyntaxState = class {
|
|
|
1157
1113
|
return invalidatedBlocks ?? emptyArray;
|
|
1158
1114
|
}
|
|
1159
1115
|
};
|
|
1116
|
+
var InlineRegionCursor = class {
|
|
1117
|
+
#index = 0;
|
|
1118
|
+
#regions = emptyArray;
|
|
1119
|
+
reset(regions) {
|
|
1120
|
+
this.#index = 0;
|
|
1121
|
+
this.#regions = regions;
|
|
1122
|
+
}
|
|
1123
|
+
take(tokenStart) {
|
|
1124
|
+
const region = this.#regions[this.#index];
|
|
1125
|
+
if (region?.tokenStart !== tokenStart) return;
|
|
1126
|
+
this.#index++;
|
|
1127
|
+
return region;
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
function resolveInlineRegion(source, profile, tokens, tokenStart) {
|
|
1131
|
+
const view = inlineViewOf(source, tokens, tokenStart, tokens.nodeLength(tokenStart));
|
|
1132
|
+
if (!view) return;
|
|
1133
|
+
const text = view.text;
|
|
1134
|
+
return {
|
|
1135
|
+
tokenStart,
|
|
1136
|
+
tokens: profile.resolve(text, profile.tokenize(text), tokens),
|
|
1137
|
+
view
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
function inlineViewOf(source, tokens, tokenStart, nodeLength) {
|
|
1141
|
+
let firstStart = -1;
|
|
1142
|
+
let firstEnd = -1;
|
|
1143
|
+
let ranges;
|
|
1144
|
+
const tokenEnd = tokenStart + nodeLength;
|
|
1145
|
+
for (let token = tokenStart + 1; token < tokenEnd; token++) {
|
|
1146
|
+
if (tokens.kind(token) !== 1) continue;
|
|
1147
|
+
const start = tokens.start(token);
|
|
1148
|
+
const end = tokens.end(token);
|
|
1149
|
+
if (firstStart < 0) {
|
|
1150
|
+
firstStart = start;
|
|
1151
|
+
firstEnd = end;
|
|
1152
|
+
} else if (start === firstEnd) {
|
|
1153
|
+
firstEnd = end;
|
|
1154
|
+
if (ranges) ranges[ranges.length - 1] = end;
|
|
1155
|
+
} else {
|
|
1156
|
+
ranges ??= [firstStart, firstEnd];
|
|
1157
|
+
ranges.push(start, end);
|
|
1158
|
+
firstEnd = end;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
if (ranges) return new SourceView(source, ranges);
|
|
1162
|
+
if (firstStart >= 0) return new SourceView(source, firstStart, firstEnd);
|
|
1163
|
+
}
|
|
1160
1164
|
//#endregion
|
|
1161
1165
|
//#region src/document.ts
|
|
1162
1166
|
function applyEdits(source, edits) {
|
|
@@ -1199,7 +1203,7 @@ var DocumentImpl = class {
|
|
|
1199
1203
|
#blockScanner;
|
|
1200
1204
|
#profile;
|
|
1201
1205
|
#source;
|
|
1202
|
-
#
|
|
1206
|
+
#regionState;
|
|
1203
1207
|
#tree = {
|
|
1204
1208
|
type: "root",
|
|
1205
1209
|
children: []
|
|
@@ -1209,8 +1213,8 @@ var DocumentImpl = class {
|
|
|
1209
1213
|
this.#source = source;
|
|
1210
1214
|
this.#blockScanner = new BlockScanner(profile.block);
|
|
1211
1215
|
this.#blockScanner.scan(source);
|
|
1212
|
-
this.#
|
|
1213
|
-
this.#updateTree(this.#
|
|
1216
|
+
this.#regionState = new InlineRegionState(profile.inline, this.#blockScanner);
|
|
1217
|
+
this.#updateTree(this.#regionState.update(source));
|
|
1214
1218
|
}
|
|
1215
1219
|
get source() {
|
|
1216
1220
|
return this.#source;
|
|
@@ -1225,14 +1229,14 @@ var DocumentImpl = class {
|
|
|
1225
1229
|
} };
|
|
1226
1230
|
const change = applyEdits(this.source, edits);
|
|
1227
1231
|
const blockChange = this.#blockScanner.edit(change);
|
|
1228
|
-
const invalidatedBlocks = this.#
|
|
1232
|
+
const invalidatedBlocks = this.#regionState.update(change.nextSource, blockChange);
|
|
1229
1233
|
this.#source = change.nextSource;
|
|
1230
1234
|
this.#updateTree(invalidatedBlocks, blockChange);
|
|
1231
1235
|
return { changedSpan: change.changedSpan };
|
|
1232
1236
|
}
|
|
1233
1237
|
#updateTree(invalidatedBlocks, change) {
|
|
1234
1238
|
const records = this.#blockScanner.records;
|
|
1235
|
-
const regionsByBlock = this.#
|
|
1239
|
+
const regionsByBlock = this.#regionState.regionsByBlock();
|
|
1236
1240
|
const locator = this.#blockScanner.locator();
|
|
1237
1241
|
const context = {
|
|
1238
1242
|
inlineContext: void 0,
|
|
@@ -1341,18 +1345,14 @@ function compileBlockProfile(features) {
|
|
|
1341
1345
|
}
|
|
1342
1346
|
if (feature.rules) for (const registration of feature.rules) {
|
|
1343
1347
|
const syntax = registration.syntax;
|
|
1348
|
+
const tokens = typeof syntax.token === "number" ? [syntax.token] : syntax.token;
|
|
1344
1349
|
const rule = {
|
|
1345
1350
|
block: syntax.kind === "block" || syntax.kind === "leaf",
|
|
1346
|
-
close: syntax.kind === "block" || syntax.kind === "frame" ? syntax.close : 0,
|
|
1347
1351
|
inlineContent: registration.inlineContent === true,
|
|
1348
1352
|
build: registration.build
|
|
1349
1353
|
};
|
|
1350
1354
|
ruleByBlockRule[registration.rule] = rule;
|
|
1351
|
-
|
|
1352
|
-
const opens = typeof syntax.open === "number" ? [syntax.open] : syntax.open;
|
|
1353
|
-
for (const open of opens) rules[open] = rule;
|
|
1354
|
-
} else if (syntax.kind === "group") for (const token of syntax.tokens) rules[token] = rule;
|
|
1355
|
-
else if (syntax.kind === "leaf") rules[syntax.token] = rule;
|
|
1355
|
+
for (const token of tokens) rules[token] = rule;
|
|
1356
1356
|
}
|
|
1357
1357
|
}
|
|
1358
1358
|
for (const registration of decorators) {
|
|
@@ -1371,7 +1371,7 @@ function compileBlockProfile(features) {
|
|
|
1371
1371
|
}
|
|
1372
1372
|
//#endregion
|
|
1373
1373
|
//#region src/inline/lexer.ts
|
|
1374
|
-
const
|
|
1374
|
+
const tokenizerFactories = new Map();
|
|
1375
1375
|
function matchInlinePatternEnd(pattern, source, start) {
|
|
1376
1376
|
pattern.lastIndex = start;
|
|
1377
1377
|
return pattern.test(source) ? pattern.lastIndex : -1;
|
|
@@ -1382,7 +1382,7 @@ function inlineMarkerRunEnd(source, start) {
|
|
|
1382
1382
|
while (source.charCodeAt(end) === marker) end++;
|
|
1383
1383
|
return end;
|
|
1384
1384
|
}
|
|
1385
|
-
function tokenize(source, textBoundary,
|
|
1385
|
+
function tokenize(source, textBoundary, scannerByCode) {
|
|
1386
1386
|
const tokens = [];
|
|
1387
1387
|
const end = source.length;
|
|
1388
1388
|
let lineStart = 0;
|
|
@@ -1393,7 +1393,7 @@ function tokenize(source, textBoundary, scanBoundary) {
|
|
|
1393
1393
|
while (source.charCodeAt(content) === 32) content++;
|
|
1394
1394
|
if (content === end) break;
|
|
1395
1395
|
offset = content;
|
|
1396
|
-
if (lineStart > 0) tokens.push(
|
|
1396
|
+
if (lineStart > 0) tokens.push(67, offset, offset, lineStart);
|
|
1397
1397
|
lineStart = -1;
|
|
1398
1398
|
}
|
|
1399
1399
|
const code = source.charCodeAt(offset);
|
|
@@ -1401,32 +1401,47 @@ function tokenize(source, textBoundary, scanBoundary) {
|
|
|
1401
1401
|
if (source.charCodeAt(offset - 1) === 32 && source.charCodeAt(offset - 2) === 32) {
|
|
1402
1402
|
let spaces = offset - 2;
|
|
1403
1403
|
while (source.charCodeAt(spaces - 1) === 32) spaces--;
|
|
1404
|
-
tokens.push(
|
|
1404
|
+
tokens.push(128, spaces, offset, 0);
|
|
1405
1405
|
}
|
|
1406
1406
|
offset++;
|
|
1407
1407
|
if (code === 13 && source.charCodeAt(offset) === 10) offset++;
|
|
1408
1408
|
lineStart = offset;
|
|
1409
1409
|
continue;
|
|
1410
1410
|
}
|
|
1411
|
-
const scannedEnd =
|
|
1411
|
+
const scannedEnd = scannerByCode[code]?.(source, offset, tokens) ?? offset;
|
|
1412
1412
|
offset = scannedEnd > offset ? scannedEnd : offset + 1;
|
|
1413
1413
|
textBoundary.lastIndex = offset;
|
|
1414
1414
|
offset = textBoundary.test(source) ? textBoundary.lastIndex - 1 : end;
|
|
1415
1415
|
}
|
|
1416
1416
|
return tokens;
|
|
1417
1417
|
}
|
|
1418
|
-
function
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1418
|
+
function generateInlineTokenizer(boundaryCodes, textBoundary, scannerByCode) {
|
|
1419
|
+
const key = String.fromCharCode(...boundaryCodes);
|
|
1420
|
+
let factory = tokenizerFactories.get(key);
|
|
1421
|
+
if (factory === void 0) {
|
|
1422
|
+
const names = boundaryCodes.map((code, index) => `scan${index}`);
|
|
1423
|
+
const source = [
|
|
1424
|
+
`return source=>{`,
|
|
1425
|
+
`const tokens=[],end=source.length;let lineStart=0,offset=0;`,
|
|
1426
|
+
`while(offset<end){`,
|
|
1427
|
+
`if(lineStart>=0){let content=offset;while(source.charCodeAt(content)===32)content++;`,
|
|
1428
|
+
`if(content===end)break;offset=content;`,
|
|
1429
|
+
`if(lineStart>0)tokens.push(67,offset,offset,lineStart);lineStart=-1}`,
|
|
1430
|
+
`const code=source.charCodeAt(offset);`,
|
|
1431
|
+
`if(code===10||code===13){`,
|
|
1432
|
+
`if(source.charCodeAt(offset-1)===32&&source.charCodeAt(offset-2)===32){`,
|
|
1433
|
+
`let spaces=offset-2;while(source.charCodeAt(spaces-1)===32)spaces--;`,
|
|
1434
|
+
`tokens.push(128,spaces,offset,0)}`,
|
|
1435
|
+
`offset++;if(code===13&&source.charCodeAt(offset)===10)offset++;`,
|
|
1436
|
+
`lineStart=offset;continue}`,
|
|
1437
|
+
`let scannedEnd;switch(code){${boundaryCodes.map((code, index) => `case ${code}:scannedEnd=scan${index}(source,offset,tokens);break;`).join("")}default:scannedEnd=offset}`,
|
|
1438
|
+
`offset=scannedEnd>offset?scannedEnd:offset+1;textBoundary.lastIndex=offset;`,
|
|
1439
|
+
`offset=textBoundary.test(source)?textBoundary.lastIndex-1:end}`,
|
|
1440
|
+
`return tokens}`
|
|
1441
|
+
].join("");
|
|
1442
|
+
tokenizerFactories.set(key, factory = Function("textBoundary", ...names, source));
|
|
1443
|
+
}
|
|
1444
|
+
return factory(textBoundary, ...boundaryCodes.map((code) => scannerByCode[code]));
|
|
1430
1445
|
}
|
|
1431
1446
|
function compileInlineTokenizer(rules) {
|
|
1432
1447
|
const scannerByCode = [];
|
|
@@ -1442,18 +1457,18 @@ function compileInlineTokenizer(rules) {
|
|
|
1442
1457
|
}
|
|
1443
1458
|
const boundaries = String.fromCharCode(...boundaryCodes).replaceAll(/[\\\]-]/g, "\\$&");
|
|
1444
1459
|
const textBoundary = new RegExp(`${boundaryCodes.length > 9 ? " {2,}[\\n\\r]|" : ""}[\\n\\r${boundaries}]`, "g");
|
|
1445
|
-
|
|
1446
|
-
|
|
1460
|
+
try {
|
|
1461
|
+
return generateInlineTokenizer(boundaryCodes, textBoundary, scannerByCode);
|
|
1462
|
+
} catch {
|
|
1463
|
+
return (source) => tokenize(source, textBoundary, scannerByCode);
|
|
1464
|
+
}
|
|
1447
1465
|
}
|
|
1448
1466
|
//#endregion
|
|
1449
1467
|
//#region src/inline/profile.ts
|
|
1450
1468
|
function compileInlineProfile(features, compileInlineResolver) {
|
|
1451
1469
|
const buildByKind = [];
|
|
1452
|
-
const decorateByKind = [];
|
|
1453
1470
|
const delimiters = [];
|
|
1454
1471
|
const scanRules = [];
|
|
1455
|
-
const syntaxByKind = [];
|
|
1456
|
-
const textByKind = [];
|
|
1457
1472
|
for (const feature of features) {
|
|
1458
1473
|
if (feature.scan) scanRules.push(...feature.scan);
|
|
1459
1474
|
if (feature.delimiters) delimiters.push(...feature.delimiters);
|
|
@@ -1462,32 +1477,19 @@ function compileInlineProfile(features, compileInlineResolver) {
|
|
|
1462
1477
|
for (const rule of build) switch (rule.kind) {
|
|
1463
1478
|
case "decorate":
|
|
1464
1479
|
buildByKind[rule.token] = rule.apply;
|
|
1465
|
-
decorateByKind[rule.token] = true;
|
|
1466
1480
|
break;
|
|
1467
1481
|
case "leaf":
|
|
1468
1482
|
buildByKind[rule.token] = rule.build;
|
|
1469
1483
|
break;
|
|
1470
1484
|
case "text":
|
|
1471
1485
|
buildByKind[rule.token] = rule.build;
|
|
1472
|
-
textByKind[rule.token] = true;
|
|
1473
|
-
break;
|
|
1474
|
-
case "container":
|
|
1475
|
-
buildByKind[rule.token] = rule.build;
|
|
1476
|
-
syntaxByKind[rule.token * 2] = rule.close;
|
|
1477
|
-
syntaxByKind[rule.token * 2 + 1] = rule.contentOpen;
|
|
1478
1486
|
break;
|
|
1479
|
-
case "pair":
|
|
1480
|
-
buildByKind[rule.open] = rule.build;
|
|
1481
|
-
syntaxByKind[rule.open * 2] = rule.close;
|
|
1482
|
-
syntaxByKind[rule.open * 2 + 1] = 0;
|
|
1487
|
+
case "pair": buildByKind[rule.token] = rule.build;
|
|
1483
1488
|
}
|
|
1484
1489
|
}
|
|
1485
1490
|
return {
|
|
1486
1491
|
buildByKind,
|
|
1487
|
-
decorateByKind,
|
|
1488
1492
|
resolve: compileInlineResolver(delimiters),
|
|
1489
|
-
syntaxByKind,
|
|
1490
|
-
textByKind,
|
|
1491
1493
|
tokenize: compileInlineTokenizer(scanRules)
|
|
1492
1494
|
};
|
|
1493
1495
|
}
|
|
@@ -1511,6 +1513,11 @@ function inlineTokenData(tokens, index) {
|
|
|
1511
1513
|
function setInlineTokenData(tokens, index, data) {
|
|
1512
1514
|
tokens[index * 4 + 3] = data;
|
|
1513
1515
|
}
|
|
1516
|
+
function rewriteInlineTokenTail(tokens, kind, end) {
|
|
1517
|
+
const offset = tokens.length - 4;
|
|
1518
|
+
tokens[offset + 0] = kind;
|
|
1519
|
+
tokens[offset + 2] = end;
|
|
1520
|
+
}
|
|
1514
1521
|
function inlineTokenText(source, tokens, index) {
|
|
1515
1522
|
return source.slice(inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index));
|
|
1516
1523
|
}
|
|
@@ -1725,14 +1732,14 @@ function scanAttribute(source, start, tokens) {
|
|
|
1725
1732
|
}
|
|
1726
1733
|
const previous = inlineTokenCount(tokens) - 1;
|
|
1727
1734
|
const previousEnd = previous >= 0 ? inlineTokenEnd(tokens, previous) : 0;
|
|
1728
|
-
if (previousEnd < start && (previous >= 0 && inlineTokenKind(tokens, previous) ===
|
|
1729
|
-
appendInlineToken(tokens,
|
|
1735
|
+
if (previousEnd < start && (previous >= 0 && inlineTokenKind(tokens, previous) === 256 || hasVisibleText(source, previousEnd, start))) appendInlineToken(tokens, 64, previousEnd, start);
|
|
1736
|
+
appendInlineToken(tokens, 256, start, end, start > 0 && isMarkdownWhitespace(source.charCodeAt(start - 1)) ? 1 : 0);
|
|
1730
1737
|
let next = end;
|
|
1731
1738
|
while (isMarkdownWhitespace(source.charCodeAt(next))) next++;
|
|
1732
1739
|
if (next === source.length) for (let index = inlineTokenCount(tokens) - 1; index >= 0; index--) {
|
|
1733
1740
|
const kind = inlineTokenKind(tokens, index);
|
|
1734
|
-
if (kind ===
|
|
1735
|
-
if (kind !==
|
|
1741
|
+
if (kind === 64 && !hasVisibleText(source, inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index))) continue;
|
|
1742
|
+
if (kind !== 256) break;
|
|
1736
1743
|
setInlineTokenData(tokens, index, inlineTokenData(tokens, index) | 2);
|
|
1737
1744
|
}
|
|
1738
1745
|
return end;
|
|
@@ -1759,7 +1766,7 @@ const feature$18 = {
|
|
|
1759
1766
|
}],
|
|
1760
1767
|
build: [{
|
|
1761
1768
|
kind: "decorate",
|
|
1762
|
-
token:
|
|
1769
|
+
token: 256,
|
|
1763
1770
|
apply(tokenIndex, sourceSpan, context, target) {
|
|
1764
1771
|
const previous = target.children.at(-1);
|
|
1765
1772
|
const parsed = parseAttributes(context.view.text, inlineTokenStart(context.tokens, tokenIndex));
|
|
@@ -1794,13 +1801,13 @@ const feature$17 = { inline: {
|
|
|
1794
1801
|
const valueEnd = separator < 0 || separator > close ? close : separator;
|
|
1795
1802
|
if (!source.slice(start + 2, valueEnd).trim()) return -1;
|
|
1796
1803
|
const end = close + 2;
|
|
1797
|
-
appendInlineToken(tokens,
|
|
1804
|
+
appendInlineToken(tokens, 135, start, end, valueEnd - start);
|
|
1798
1805
|
return end;
|
|
1799
1806
|
}
|
|
1800
1807
|
}],
|
|
1801
1808
|
build: [{
|
|
1802
1809
|
kind: "leaf",
|
|
1803
|
-
token:
|
|
1810
|
+
token: 135,
|
|
1804
1811
|
build(tokenIndex, sourceSpan, context) {
|
|
1805
1812
|
const source = context.view.text;
|
|
1806
1813
|
const tokenStart = inlineTokenStart(context.tokens, tokenIndex);
|
|
@@ -1842,8 +1849,7 @@ const feature$16 = { block: {
|
|
|
1842
1849
|
rule: 1,
|
|
1843
1850
|
syntax: {
|
|
1844
1851
|
kind: "block",
|
|
1845
|
-
|
|
1846
|
-
close: 4
|
|
1852
|
+
token: 64
|
|
1847
1853
|
},
|
|
1848
1854
|
build(tokenStart, context) {
|
|
1849
1855
|
const tokens = context.structure.tokens;
|
|
@@ -1884,10 +1890,10 @@ const feature$16 = { block: {
|
|
|
1884
1890
|
if (!lazyParagraph || isBlank(source, lines, index) || !lines.lazy(index) && context.startsInterruptingBlock(source, lines, index, markerOffset)) break;
|
|
1885
1891
|
quoteLines.pushLazy(lines, index);
|
|
1886
1892
|
}
|
|
1887
|
-
out.push(
|
|
1893
|
+
out.push(64, contentOffset, contentOffset + 1);
|
|
1888
1894
|
context.scanLines(source, quoteLines, out);
|
|
1889
1895
|
const end = quoteLines.next(quoteLines.length - 1);
|
|
1890
|
-
out.push(
|
|
1896
|
+
out.push(192, end, end);
|
|
1891
1897
|
return index;
|
|
1892
1898
|
}
|
|
1893
1899
|
}]
|
|
@@ -1911,7 +1917,7 @@ const feature$15 = {
|
|
|
1911
1917
|
rule: 0,
|
|
1912
1918
|
syntax: {
|
|
1913
1919
|
kind: "leaf",
|
|
1914
|
-
token:
|
|
1920
|
+
token: 256
|
|
1915
1921
|
},
|
|
1916
1922
|
build(tokenStart, context) {
|
|
1917
1923
|
return {
|
|
@@ -1931,14 +1937,14 @@ const feature$15 = {
|
|
|
1931
1937
|
},
|
|
1932
1938
|
start(source, lines, start, contentOffset, out) {
|
|
1933
1939
|
if (!isThematicBreak(source, lines, start, contentOffset)) return;
|
|
1934
|
-
out.push(
|
|
1940
|
+
out.push(256, contentOffset, lines.end(start));
|
|
1935
1941
|
return start + 1;
|
|
1936
1942
|
}
|
|
1937
1943
|
}]
|
|
1938
1944
|
},
|
|
1939
1945
|
inline: { build: [{
|
|
1940
1946
|
kind: "leaf",
|
|
1941
|
-
token:
|
|
1947
|
+
token: 128,
|
|
1942
1948
|
build(tokenIndex, sourceSpan) {
|
|
1943
1949
|
return {
|
|
1944
1950
|
type: "break",
|
|
@@ -1947,7 +1953,7 @@ const feature$15 = {
|
|
|
1947
1953
|
}
|
|
1948
1954
|
}, {
|
|
1949
1955
|
kind: "text",
|
|
1950
|
-
token:
|
|
1956
|
+
token: 67,
|
|
1951
1957
|
build() {
|
|
1952
1958
|
return "\n";
|
|
1953
1959
|
}
|
|
@@ -1991,12 +1997,19 @@ function closesFence(source, lines, index, fence) {
|
|
|
1991
1997
|
while (offset < lineEnd && (source[offset] === " " || source[offset] === " ")) offset++;
|
|
1992
1998
|
return offset === lineEnd;
|
|
1993
1999
|
}
|
|
1994
|
-
function fencedBlock(source, lines, index, fence, closed) {
|
|
2000
|
+
function fencedBlock(source, lines, index, end, fence, closed) {
|
|
1995
2001
|
let infoStart = fence.offset + fence.length;
|
|
1996
2002
|
const lineEnd = lines.end(index);
|
|
1997
2003
|
while (infoStart < lineEnd && (source[infoStart] === " " || source[infoStart] === " ")) infoStart++;
|
|
2004
|
+
let content;
|
|
2005
|
+
if (lines.physicallyContiguous()) {
|
|
2006
|
+
const contentStart = lines.next(index);
|
|
2007
|
+
const lastContentLine = end - (closed ? 2 : 1);
|
|
2008
|
+
content = source.slice(contentStart, lastContentLine > index ? lines.end(lastContentLine) : contentStart);
|
|
2009
|
+
}
|
|
1998
2010
|
return {
|
|
1999
2011
|
closed,
|
|
2012
|
+
content,
|
|
2000
2013
|
indent: fence.indent,
|
|
2001
2014
|
info: source.slice(infoStart, lineEnd),
|
|
2002
2015
|
markerOffset: fence.offset - lines.start(index)
|
|
@@ -2013,23 +2026,28 @@ const sourceColumnFenceTabIndent = [
|
|
|
2013
2026
|
/^(?<![\u2028\u2029]) {0,2}\t/gm
|
|
2014
2027
|
];
|
|
2015
2028
|
function normalizedFenceContent(source, block) {
|
|
2016
|
-
|
|
2017
|
-
if (
|
|
2018
|
-
|
|
2019
|
-
|
|
2029
|
+
let content = source;
|
|
2030
|
+
if (block.content === void 0) {
|
|
2031
|
+
const contentStart = source.indexOf("\n") + 1;
|
|
2032
|
+
if (!contentStart) return "";
|
|
2033
|
+
const limit = block.closed ? source.lastIndexOf("\n", source.length - 2) + 1 : source.length;
|
|
2034
|
+
content = source.slice(contentStart, lineContentEnd(source, contentStart, limit));
|
|
2035
|
+
}
|
|
2020
2036
|
return block.indent ? content.replace(fenceSpaceIndent[block.indent - 1], "") : content;
|
|
2021
2037
|
}
|
|
2022
2038
|
function sourceColumnFenceContent(source, block) {
|
|
2023
|
-
let
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
limit =
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2039
|
+
let content = block.content;
|
|
2040
|
+
if (content === void 0) {
|
|
2041
|
+
let contentStart = 0;
|
|
2042
|
+
while (contentStart < source.length && source[contentStart] !== "\n" && source[contentStart] !== "\r") contentStart++;
|
|
2043
|
+
if (contentStart < source.length) contentStart += source[contentStart] === "\r" && source[contentStart + 1] === "\n" ? 2 : 1;
|
|
2044
|
+
let limit = source.length;
|
|
2045
|
+
if (block.closed) {
|
|
2046
|
+
limit = lineContentEnd(source, contentStart, limit);
|
|
2047
|
+
while (limit > contentStart && source[limit - 1] !== "\n" && source[limit - 1] !== "\r") limit--;
|
|
2048
|
+
}
|
|
2049
|
+
content = source.slice(contentStart, lineContentEnd(source, contentStart, limit));
|
|
2050
|
+
}
|
|
2033
2051
|
if (block.indent) {
|
|
2034
2052
|
if (content.includes(" ")) content = content.replace(sourceColumnFenceTabIndent[block.indent - 1], " ");
|
|
2035
2053
|
content = content.replace(fenceSpaceIndent[block.indent - 1], "");
|
|
@@ -2057,7 +2075,7 @@ const feature$14 = { inline: {
|
|
|
2057
2075
|
scan(source, start, tokens) {
|
|
2058
2076
|
const matchEnd = matchInlinePatternEnd(entity, source, start);
|
|
2059
2077
|
if (matchEnd < 0) return start + 1;
|
|
2060
|
-
appendInlineToken(tokens,
|
|
2078
|
+
appendInlineToken(tokens, 66, start, matchEnd);
|
|
2061
2079
|
return matchEnd;
|
|
2062
2080
|
}
|
|
2063
2081
|
}, {
|
|
@@ -2065,12 +2083,12 @@ const feature$14 = { inline: {
|
|
|
2065
2083
|
scan(source, start, tokens) {
|
|
2066
2084
|
const next = source.charCodeAt(start + 1);
|
|
2067
2085
|
if (next === 10 || next === 13) {
|
|
2068
|
-
appendInlineToken(tokens,
|
|
2086
|
+
appendInlineToken(tokens, 128, start, start + 1);
|
|
2069
2087
|
return start + 1;
|
|
2070
2088
|
}
|
|
2071
2089
|
if (isAsciiPunctuation(next)) {
|
|
2072
2090
|
const end = start + 2;
|
|
2073
|
-
appendInlineToken(tokens,
|
|
2091
|
+
appendInlineToken(tokens, 65, start, end);
|
|
2074
2092
|
return end;
|
|
2075
2093
|
}
|
|
2076
2094
|
return start + (next === 32 || next === 9 ? 2 : 1);
|
|
@@ -2079,17 +2097,17 @@ const feature$14 = { inline: {
|
|
|
2079
2097
|
build: [
|
|
2080
2098
|
{
|
|
2081
2099
|
kind: "text",
|
|
2082
|
-
token:
|
|
2100
|
+
token: 64,
|
|
2083
2101
|
build: buildInlineText
|
|
2084
2102
|
},
|
|
2085
2103
|
{
|
|
2086
2104
|
kind: "text",
|
|
2087
|
-
token:
|
|
2105
|
+
token: 65,
|
|
2088
2106
|
build: buildDecodedInlineText
|
|
2089
2107
|
},
|
|
2090
2108
|
{
|
|
2091
2109
|
kind: "text",
|
|
2092
|
-
token:
|
|
2110
|
+
token: 66,
|
|
2093
2111
|
build: buildDecodedInlineText
|
|
2094
2112
|
}
|
|
2095
2113
|
]
|
|
@@ -2111,13 +2129,13 @@ const feature$13 = {
|
|
|
2111
2129
|
rule: 8,
|
|
2112
2130
|
syntax: {
|
|
2113
2131
|
kind: "leaf",
|
|
2114
|
-
token:
|
|
2132
|
+
token: 257
|
|
2115
2133
|
},
|
|
2116
2134
|
build(tokenStart, context) {
|
|
2117
2135
|
const tokens = context.structure.tokens;
|
|
2118
|
-
const source = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
|
|
2119
2136
|
const block = tokens.value(tokenStart);
|
|
2120
2137
|
if (!block) throw new Error("FencedCodeBlock token has no fence metadata");
|
|
2138
|
+
const source = context.locator.normalizeLineEndings(block.content ?? tokens.text(context.source, tokenStart));
|
|
2121
2139
|
const rawInfo = semanticText(block.info);
|
|
2122
2140
|
const langEnd = rawInfo.search(/[ \t]/);
|
|
2123
2141
|
const lang = rawInfo ? langEnd < 0 ? rawInfo : rawInfo.slice(0, langEnd) : null;
|
|
@@ -2134,7 +2152,7 @@ const feature$13 = {
|
|
|
2134
2152
|
rule: 9,
|
|
2135
2153
|
syntax: {
|
|
2136
2154
|
kind: "leaf",
|
|
2137
|
-
token:
|
|
2155
|
+
token: 258
|
|
2138
2156
|
},
|
|
2139
2157
|
build(tokenStart, context) {
|
|
2140
2158
|
const tokens = context.structure.tokens;
|
|
@@ -2155,11 +2173,11 @@ const feature$13 = {
|
|
|
2155
2173
|
codes: [-1],
|
|
2156
2174
|
start(source, lines, start, _contentOffset, out) {
|
|
2157
2175
|
let end = start + 1;
|
|
2158
|
-
while (end < lines.length &&
|
|
2176
|
+
while (end < lines.length && lineIndentOffset(source, lines, end) < 0) end++;
|
|
2159
2177
|
let contentEnd = end;
|
|
2160
2178
|
while (contentEnd > start && isBlank(source, lines, contentEnd - 1)) contentEnd--;
|
|
2161
2179
|
const contentLength = lines.end(contentEnd - 1) - lines.start(start);
|
|
2162
|
-
appendLogicalToken(out,
|
|
2180
|
+
appendLogicalToken(out, 258, source, lines, start, end, contentLength);
|
|
2163
2181
|
return end;
|
|
2164
2182
|
}
|
|
2165
2183
|
}, {
|
|
@@ -2174,7 +2192,7 @@ const feature$13 = {
|
|
|
2174
2192
|
while (end < lines.length && !closesFence(source, lines, end, fence)) end++;
|
|
2175
2193
|
const closed = end < lines.length;
|
|
2176
2194
|
if (end < lines.length) end++;
|
|
2177
|
-
appendLogicalToken(out,
|
|
2195
|
+
appendLogicalToken(out, 257, source, lines, start, end, fencedBlock(source, lines, start, end, fence, closed));
|
|
2178
2196
|
return end;
|
|
2179
2197
|
}
|
|
2180
2198
|
}]
|
|
@@ -2192,7 +2210,7 @@ const feature$13 = {
|
|
|
2192
2210
|
if (offset < 0) break;
|
|
2193
2211
|
const closeEnd = inlineMarkerRunEnd(source, offset);
|
|
2194
2212
|
if (closeEnd - offset === markerLength) {
|
|
2195
|
-
appendInlineToken(tokens,
|
|
2213
|
+
appendInlineToken(tokens, 129, start, closeEnd, markerLength);
|
|
2196
2214
|
return closeEnd;
|
|
2197
2215
|
}
|
|
2198
2216
|
offset = closeEnd;
|
|
@@ -2202,7 +2220,7 @@ const feature$13 = {
|
|
|
2202
2220
|
}],
|
|
2203
2221
|
build: [{
|
|
2204
2222
|
kind: "leaf",
|
|
2205
|
-
token:
|
|
2223
|
+
token: 129,
|
|
2206
2224
|
build: (tokenIndex, sourceSpan, context) => {
|
|
2207
2225
|
const text = inlineTokenText(context.view.text, context.tokens, tokenIndex);
|
|
2208
2226
|
const markerLength = inlineTokenData(context.tokens, tokenIndex);
|
|
@@ -2275,9 +2293,7 @@ function finishText(output, context) {
|
|
|
2275
2293
|
}
|
|
2276
2294
|
}
|
|
2277
2295
|
function appendGap(output, context, start, end) {
|
|
2278
|
-
|
|
2279
|
-
const sourceSpan = context.view.mapSpan(start, end);
|
|
2280
|
-
appendText(output, value, sourceSpan.start, sourceSpan.end, context);
|
|
2296
|
+
appendText(output, context.view.text.slice(start, end), context.view.mapOffset(start), context.view.mapEnd(end), context);
|
|
2281
2297
|
}
|
|
2282
2298
|
function appendToken(output, context, tokenIndex, viewStart, viewEnd, build, textToken, syntaxNewline) {
|
|
2283
2299
|
const cursor = output.cursor;
|
|
@@ -2291,17 +2307,18 @@ function appendToken(output, context, tokenIndex, viewStart, viewEnd, build, tex
|
|
|
2291
2307
|
}
|
|
2292
2308
|
const previous = output.children.at(-1);
|
|
2293
2309
|
if (previous?.type === "break") {
|
|
2294
|
-
previous.position.end = context.locator.locationAt(context.view.
|
|
2310
|
+
previous.position.end = context.locator.locationAt(context.view.mapOffset(viewLineStart - 1) + 1);
|
|
2295
2311
|
return;
|
|
2296
2312
|
}
|
|
2297
2313
|
viewStart = viewLineEndingStart;
|
|
2298
2314
|
trimTrailingText(output);
|
|
2299
2315
|
}
|
|
2300
|
-
const
|
|
2301
|
-
|
|
2316
|
+
const sourceStart = context.view.mapOffset(viewStart);
|
|
2317
|
+
const sourceEnd = viewStart === viewEnd ? sourceStart : context.view.mapEnd(viewEnd);
|
|
2318
|
+
if (textToken) appendText(output, build(tokenIndex, context), sourceStart, sourceEnd, context);
|
|
2302
2319
|
else {
|
|
2303
2320
|
finishText(output, context);
|
|
2304
|
-
output.children.push(build(tokenIndex, context.locator.positionAt(
|
|
2321
|
+
output.children.push(build(tokenIndex, context.locator.positionAt(sourceStart, sourceEnd), context));
|
|
2305
2322
|
output.lastText = void 0;
|
|
2306
2323
|
}
|
|
2307
2324
|
}
|
|
@@ -2310,27 +2327,31 @@ function appendRange(startToken, endToken, profile, context, output, closeKind =
|
|
|
2310
2327
|
while (index < endToken) {
|
|
2311
2328
|
const kind = inlineTokenKind(context.tokens, index);
|
|
2312
2329
|
if (kind === closeKind) break;
|
|
2313
|
-
const syntaxOffset = kind * 2;
|
|
2314
|
-
const semanticCloseKind = profile.syntaxByKind[syntaxOffset];
|
|
2315
2330
|
const build = profile.buildByKind[kind];
|
|
2316
2331
|
const childStart = inlineTokenStart(context.tokens, index);
|
|
2317
|
-
if (
|
|
2332
|
+
if (kind < 192) {
|
|
2333
|
+
const childEnd = inlineTokenEnd(context.tokens, index);
|
|
2334
|
+
appendToken(output, context, index, childStart, childEnd, build, kind < 128, kind === 67);
|
|
2335
|
+
output.cursor = childEnd;
|
|
2336
|
+
index++;
|
|
2337
|
+
continue;
|
|
2338
|
+
}
|
|
2339
|
+
if (kind < 256) {
|
|
2318
2340
|
if (childStart > output.cursor) appendGap(output, context, output.cursor, childStart);
|
|
2319
2341
|
finishText(output, context);
|
|
2320
|
-
index = appendSemantic(index, endToken, profile, context, output, build,
|
|
2342
|
+
index = appendSemantic(index, endToken, profile, context, output, build, kind + 1);
|
|
2321
2343
|
continue;
|
|
2322
2344
|
}
|
|
2323
2345
|
const childEnd = inlineTokenEnd(context.tokens, index);
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
appendToken(output, context, index, childStart, childEnd, build, profile.textByKind[kind], kind === 5);
|
|
2346
|
+
finishText(output, context);
|
|
2347
|
+
const sourceStart = context.view.mapOffset(childStart);
|
|
2348
|
+
const sourceSpan = {
|
|
2349
|
+
start: sourceStart,
|
|
2350
|
+
end: childStart === childEnd ? sourceStart : context.view.mapEnd(childEnd)
|
|
2351
|
+
};
|
|
2352
|
+
if (build(index, sourceSpan, context, output)) {
|
|
2353
|
+
const previous = output.children.at(-1);
|
|
2354
|
+
output.lastText = previous?.type === "text" ? previous : void 0;
|
|
2334
2355
|
output.cursor = childEnd;
|
|
2335
2356
|
}
|
|
2336
2357
|
index++;
|
|
@@ -2342,21 +2363,16 @@ function appendRange(startToken, endToken, profile, context, output, closeKind =
|
|
|
2342
2363
|
finishText(output, context);
|
|
2343
2364
|
return index;
|
|
2344
2365
|
}
|
|
2345
|
-
function appendSemantic(openToken, endToken, profile, context, output, build, closeKind
|
|
2366
|
+
function appendSemantic(openToken, endToken, profile, context, output, build, closeKind) {
|
|
2346
2367
|
const childStart = inlineTokenStart(context.tokens, openToken);
|
|
2347
|
-
const positionStart = context.locator.locationAt(context.view.
|
|
2348
|
-
let closeToken = openToken;
|
|
2349
|
-
let next = openToken + 1;
|
|
2368
|
+
const positionStart = context.locator.locationAt(context.view.mapOffset(childStart));
|
|
2350
2369
|
const children = [];
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
closeToken = appendRange(next, endToken, profile, context, childOutput, closeKind);
|
|
2354
|
-
}
|
|
2370
|
+
const childOutput = createInlineOutput(children, inlineTokenEnd(context.tokens, openToken));
|
|
2371
|
+
const closeToken = appendRange(openToken + 1, endToken, profile, context, childOutput, closeKind);
|
|
2355
2372
|
const childEnd = inlineTokenEnd(context.tokens, closeToken);
|
|
2356
|
-
const sourceSpan = context.view.mapSpan(childStart, childEnd);
|
|
2357
2373
|
const value = build(openToken, closeToken, {
|
|
2358
2374
|
start: positionStart,
|
|
2359
|
-
end: context.locator.locationAt(
|
|
2375
|
+
end: context.locator.locationAt(context.view.mapEnd(childEnd))
|
|
2360
2376
|
}, children, context);
|
|
2361
2377
|
output.children.push(value);
|
|
2362
2378
|
output.lastText = void 0;
|
|
@@ -2417,7 +2433,7 @@ function feature$12(marker) {
|
|
|
2417
2433
|
rule: 13,
|
|
2418
2434
|
syntax: {
|
|
2419
2435
|
kind: "leaf",
|
|
2420
|
-
token:
|
|
2436
|
+
token: 260
|
|
2421
2437
|
},
|
|
2422
2438
|
build: buildFrontmatter
|
|
2423
2439
|
}],
|
|
@@ -2426,7 +2442,7 @@ function feature$12(marker) {
|
|
|
2426
2442
|
start(source, lines, start, contentOffset, out, context) {
|
|
2427
2443
|
if (lines.start(start) !== 0 || !frontmatterFenceAt(source, lines, start, marker)) return;
|
|
2428
2444
|
for (let end = start + 1; end < lines.length; end++) if (frontmatterFenceAt(source, lines, end, marker)) {
|
|
2429
|
-
appendLogicalToken(out,
|
|
2445
|
+
appendLogicalToken(out, 260, source, lines, start, end + 1);
|
|
2430
2446
|
return end + 1;
|
|
2431
2447
|
}
|
|
2432
2448
|
context.retainLookahead(lines.next(lines.length - 1));
|
|
@@ -2569,14 +2585,14 @@ function nextSlot(source, lines, start, end) {
|
|
|
2569
2585
|
}
|
|
2570
2586
|
}
|
|
2571
2587
|
function emitSlotOpening(opening, out) {
|
|
2572
|
-
out.push(
|
|
2573
|
-
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(
|
|
2588
|
+
out.push(75, opening.offset, opening.nameEnd);
|
|
2589
|
+
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(3, opening.attributesStart, opening.attributesEnd);
|
|
2574
2590
|
}
|
|
2575
2591
|
function emitComponentBody(source, lines, start, end, closingOffset, out, context) {
|
|
2576
2592
|
let cursor = start;
|
|
2577
2593
|
const yamlEnd = cursor < end ? yamlPropsEnd(source, lines, cursor, end) : void 0;
|
|
2578
2594
|
if (yamlEnd !== void 0) {
|
|
2579
|
-
appendLogicalToken(out,
|
|
2595
|
+
appendLogicalToken(out, 262, source, lines, cursor, yamlEnd);
|
|
2580
2596
|
cursor = yamlEnd;
|
|
2581
2597
|
}
|
|
2582
2598
|
let slot = nextSlot(source, lines, cursor, end);
|
|
@@ -2591,18 +2607,18 @@ function emitComponentBody(source, lines, start, end, closingOffset, out, contex
|
|
|
2591
2607
|
emitSlotOpening(slot.opening, out);
|
|
2592
2608
|
context.scanLines(source, lines.slice(slot.index + 1, next), out);
|
|
2593
2609
|
const slotEnd = following ? following.opening.offset : closingOffset;
|
|
2594
|
-
out.push(
|
|
2610
|
+
out.push(204, slotEnd, slotEnd);
|
|
2595
2611
|
slot = following;
|
|
2596
2612
|
}
|
|
2597
2613
|
}
|
|
2598
2614
|
function emitOpening(contentOffset, opening, out) {
|
|
2599
|
-
out.push(
|
|
2615
|
+
out.push(74, contentOffset, opening.nameEnd);
|
|
2600
2616
|
if (opening.labelStart !== void 0 && opening.labelEnd !== void 0) {
|
|
2601
|
-
out.push(
|
|
2617
|
+
out.push(133, opening.labelStart, opening.labelStart + 1);
|
|
2602
2618
|
if (opening.labelEnd > opening.labelStart + 2) out.push(1, opening.labelStart + 1, opening.labelEnd - 1);
|
|
2603
|
-
out.push(
|
|
2619
|
+
out.push(203, opening.labelEnd - 1, opening.labelEnd);
|
|
2604
2620
|
}
|
|
2605
|
-
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(
|
|
2621
|
+
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(3, opening.attributesStart, opening.attributesEnd);
|
|
2606
2622
|
}
|
|
2607
2623
|
const buildBlockLabel = (tokenStart, context) => {
|
|
2608
2624
|
const tokens = context.structure.tokens;
|
|
@@ -2624,7 +2640,7 @@ function createBlockStart(shorthand) {
|
|
|
2624
2640
|
if (shorthand) {
|
|
2625
2641
|
emitOpening(contentOffset, opening, out);
|
|
2626
2642
|
const lineEnd = lines.end(start);
|
|
2627
|
-
out.push(
|
|
2643
|
+
out.push(202, lineEnd, lineEnd);
|
|
2628
2644
|
return start + 1;
|
|
2629
2645
|
}
|
|
2630
2646
|
const closing = blockClose(source, lines, start, opening);
|
|
@@ -2634,7 +2650,7 @@ function createBlockStart(shorthand) {
|
|
|
2634
2650
|
}
|
|
2635
2651
|
emitOpening(contentOffset, opening, out);
|
|
2636
2652
|
emitComponentBody(source, lines, start + 1, closing.index, closing.offset, out, context);
|
|
2637
|
-
out.push(
|
|
2653
|
+
out.push(202, closing.offset, lines.end(closing.index));
|
|
2638
2654
|
return closing.index + 1;
|
|
2639
2655
|
};
|
|
2640
2656
|
}
|
|
@@ -2643,7 +2659,7 @@ const blockRules$2 = [
|
|
|
2643
2659
|
rule: 21,
|
|
2644
2660
|
syntax: {
|
|
2645
2661
|
kind: "leaf",
|
|
2646
|
-
token:
|
|
2662
|
+
token: 262
|
|
2647
2663
|
},
|
|
2648
2664
|
build: buildFrontmatter
|
|
2649
2665
|
},
|
|
@@ -2651,8 +2667,7 @@ const blockRules$2 = [
|
|
|
2651
2667
|
rule: 20,
|
|
2652
2668
|
syntax: {
|
|
2653
2669
|
kind: "frame",
|
|
2654
|
-
|
|
2655
|
-
close: 41
|
|
2670
|
+
token: 133
|
|
2656
2671
|
},
|
|
2657
2672
|
inlineContent: true,
|
|
2658
2673
|
build: buildBlockLabel
|
|
@@ -2661,16 +2676,15 @@ const blockRules$2 = [
|
|
|
2661
2676
|
rule: 19,
|
|
2662
2677
|
syntax: {
|
|
2663
2678
|
kind: "block",
|
|
2664
|
-
|
|
2665
|
-
close: 39
|
|
2679
|
+
token: 74
|
|
2666
2680
|
},
|
|
2667
2681
|
build(tokenStart, context) {
|
|
2668
2682
|
const tokens = context.structure.tokens;
|
|
2669
2683
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
2670
2684
|
let openingToken = tokenStart + 1;
|
|
2671
|
-
const label = tokens.kind(openingToken) ===
|
|
2685
|
+
const label = tokens.kind(openingToken) === 133 ? openingToken : void 0;
|
|
2672
2686
|
if (label !== void 0) openingToken += tokens.nodeLength(label);
|
|
2673
|
-
const attributesToken = tokens.kind(openingToken) ===
|
|
2687
|
+
const attributesToken = tokens.kind(openingToken) === 3 ? openingToken++ : void 0;
|
|
2674
2688
|
const parsed = attributesToken !== void 0 ? parseAttributes(context.source, tokens.start(attributesToken)) : void 0;
|
|
2675
2689
|
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
2676
2690
|
const children = [];
|
|
@@ -2693,13 +2707,12 @@ const blockRules$2 = [
|
|
|
2693
2707
|
rule: 22,
|
|
2694
2708
|
syntax: {
|
|
2695
2709
|
kind: "block",
|
|
2696
|
-
|
|
2697
|
-
close: 45
|
|
2710
|
+
token: 75
|
|
2698
2711
|
},
|
|
2699
2712
|
build(tokenStart, context) {
|
|
2700
2713
|
const tokens = context.structure.tokens;
|
|
2701
2714
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
2702
|
-
const attributesToken = tokens.kind(tokenStart + 1) ===
|
|
2715
|
+
const attributesToken = tokens.kind(tokenStart + 1) === 3 ? tokenStart + 1 : void 0;
|
|
2703
2716
|
const parsed = attributesToken !== void 0 ? parseAttributes(context.source, tokens.start(attributesToken)) : void 0;
|
|
2704
2717
|
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
2705
2718
|
const children = buildBlockChildren(tokenStart, context);
|
|
@@ -2737,9 +2750,25 @@ function canStartInlineColon(source, start) {
|
|
|
2737
2750
|
const previous = source[start - 1];
|
|
2738
2751
|
return previous !== ":" && allowedPrevious.test(previous);
|
|
2739
2752
|
}
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2753
|
+
const inlineScans = [{
|
|
2754
|
+
marker: 58,
|
|
2755
|
+
scan(source, start, tokens) {
|
|
2756
|
+
const end = canStartInlineColon(source, start) ? componentNameEnd(source, start + 1, false) : void 0;
|
|
2757
|
+
if (end === void 0) return -1;
|
|
2758
|
+
appendInlineToken(tokens, 137, start, end);
|
|
2759
|
+
return end;
|
|
2760
|
+
}
|
|
2761
|
+
}];
|
|
2762
|
+
const buildInlineComponent = (open, close, sourceSpan, children, context) => {
|
|
2763
|
+
const nameEnd = inlineTokenEnd(context.tokens, open) - (inlineTokenKind(context.tokens, open) === 208 ? 1 : 0);
|
|
2764
|
+
return {
|
|
2765
|
+
type: "inlineComponent",
|
|
2766
|
+
name: normalizeComponentName(context.view.text.slice(inlineTokenStart(context.tokens, open) + 1, nameEnd)),
|
|
2767
|
+
attributes: {},
|
|
2768
|
+
children,
|
|
2769
|
+
position: sourceSpan
|
|
2770
|
+
};
|
|
2771
|
+
};
|
|
2743
2772
|
//#endregion
|
|
2744
2773
|
//#region src/profile/features/component/index.ts
|
|
2745
2774
|
const feature$11 = {
|
|
@@ -2748,43 +2777,34 @@ const feature$11 = {
|
|
|
2748
2777
|
starts: blockStarts$2
|
|
2749
2778
|
},
|
|
2750
2779
|
inline: {
|
|
2751
|
-
scan:
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
close: 36,
|
|
2778
|
-
build(open, close, sourceSpan, children) {
|
|
2779
|
-
return {
|
|
2780
|
-
type: "inlineComponent",
|
|
2781
|
-
name: "span",
|
|
2782
|
-
attributes: {},
|
|
2783
|
-
children,
|
|
2784
|
-
position: sourceSpan
|
|
2785
|
-
};
|
|
2780
|
+
scan: inlineScans,
|
|
2781
|
+
build: [
|
|
2782
|
+
{
|
|
2783
|
+
kind: "leaf",
|
|
2784
|
+
token: 137,
|
|
2785
|
+
build(token, sourceSpan, context) {
|
|
2786
|
+
return buildInlineComponent(token, token, sourceSpan, [], context);
|
|
2787
|
+
}
|
|
2788
|
+
},
|
|
2789
|
+
{
|
|
2790
|
+
kind: "pair",
|
|
2791
|
+
token: 208,
|
|
2792
|
+
build: buildInlineComponent
|
|
2793
|
+
},
|
|
2794
|
+
{
|
|
2795
|
+
kind: "pair",
|
|
2796
|
+
token: 206,
|
|
2797
|
+
build(open, close, sourceSpan, children) {
|
|
2798
|
+
return {
|
|
2799
|
+
type: "inlineComponent",
|
|
2800
|
+
name: "span",
|
|
2801
|
+
attributes: {},
|
|
2802
|
+
children,
|
|
2803
|
+
position: sourceSpan
|
|
2804
|
+
};
|
|
2805
|
+
}
|
|
2786
2806
|
}
|
|
2787
|
-
|
|
2807
|
+
]
|
|
2788
2808
|
}
|
|
2789
2809
|
};
|
|
2790
2810
|
//#endregion
|
|
@@ -2801,13 +2821,13 @@ const feature$10 = { inline: {
|
|
|
2801
2821
|
while (isShortcodeCharacter(source.charCodeAt(end))) end++;
|
|
2802
2822
|
if (end === start + 1 || source.charCodeAt(end) !== 58) return -1;
|
|
2803
2823
|
end++;
|
|
2804
|
-
appendInlineToken(tokens,
|
|
2824
|
+
appendInlineToken(tokens, 136, start, end);
|
|
2805
2825
|
return end;
|
|
2806
2826
|
}
|
|
2807
2827
|
}],
|
|
2808
2828
|
build: [{
|
|
2809
2829
|
kind: "leaf",
|
|
2810
|
-
token:
|
|
2830
|
+
token: 136,
|
|
2811
2831
|
build(tokenIndex, sourceSpan, context) {
|
|
2812
2832
|
return {
|
|
2813
2833
|
type: "emoji",
|
|
@@ -2892,7 +2912,7 @@ function definitionAt(source, lines, index, markerStart) {
|
|
|
2892
2912
|
}
|
|
2893
2913
|
function definitionFields(tokens, token) {
|
|
2894
2914
|
const fields = tokens.value(token);
|
|
2895
|
-
if (tokens.kind(token) !==
|
|
2915
|
+
if (tokens.kind(token) !== 72 || !fields) throw new Error("Expected FootnoteDefinitionOpen token to contain parsed fields");
|
|
2896
2916
|
return fields;
|
|
2897
2917
|
}
|
|
2898
2918
|
//#endregion
|
|
@@ -2903,8 +2923,7 @@ const feature$9 = {
|
|
|
2903
2923
|
rule: 12,
|
|
2904
2924
|
syntax: {
|
|
2905
2925
|
kind: "block",
|
|
2906
|
-
|
|
2907
|
-
close: 26
|
|
2926
|
+
token: 72
|
|
2908
2927
|
},
|
|
2909
2928
|
build(tokenStart, context) {
|
|
2910
2929
|
const tokens = context.structure.tokens;
|
|
@@ -2942,15 +2961,14 @@ const feature$9 = {
|
|
|
2942
2961
|
let index = start + 1;
|
|
2943
2962
|
let lazyParagraph = context.endsWithParagraphLeaf(source, definitionLines, 0);
|
|
2944
2963
|
while (index < lines.length) {
|
|
2945
|
-
|
|
2964
|
+
const line = definitionLines.pushAfterColumns(source, lines, index, 4);
|
|
2965
|
+
if (line === 0) {
|
|
2946
2966
|
definitionLines.pushFrom(lines, index);
|
|
2947
2967
|
lazyParagraph = false;
|
|
2948
2968
|
index++;
|
|
2949
2969
|
continue;
|
|
2950
2970
|
}
|
|
2951
|
-
|
|
2952
|
-
if (content) {
|
|
2953
|
-
definitionLines.pushFrom(lines, index, content.offset, content.prefixColumns);
|
|
2971
|
+
if (line === 1) {
|
|
2954
2972
|
lazyParagraph = context.endsWithParagraphLeaf(source, definitionLines, definitionLines.length - 1);
|
|
2955
2973
|
index++;
|
|
2956
2974
|
continue;
|
|
@@ -2960,7 +2978,7 @@ const feature$9 = {
|
|
|
2960
2978
|
index++;
|
|
2961
2979
|
}
|
|
2962
2980
|
while (definitionLines.length > 0 && isBlank(source, definitionLines, definitionLines.length - 1)) definitionLines.pop();
|
|
2963
|
-
out.push(
|
|
2981
|
+
out.push(72, contentOffset, match.markerEnd, {
|
|
2964
2982
|
definitionKey: match.definitionKey,
|
|
2965
2983
|
value: {
|
|
2966
2984
|
label: match.label,
|
|
@@ -2969,14 +2987,14 @@ const feature$9 = {
|
|
|
2969
2987
|
});
|
|
2970
2988
|
context.scanLines(source, definitionLines, out);
|
|
2971
2989
|
const end = definitionLines.length > 0 ? definitionLines.next(definitionLines.length - 1) : match.markerEnd;
|
|
2972
|
-
out.push(
|
|
2990
|
+
out.push(199, end, end);
|
|
2973
2991
|
return index;
|
|
2974
2992
|
}
|
|
2975
2993
|
}]
|
|
2976
2994
|
},
|
|
2977
2995
|
inline: { build: [{
|
|
2978
2996
|
kind: "leaf",
|
|
2979
|
-
token:
|
|
2997
|
+
token: 133,
|
|
2980
2998
|
build(tokenIndex, sourceSpan, context) {
|
|
2981
2999
|
const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(2, -1);
|
|
2982
3000
|
return {
|
|
@@ -2993,12 +3011,13 @@ const feature$9 = {
|
|
|
2993
3011
|
const scanFormatting = (source, start, tokens) => {
|
|
2994
3012
|
const code = source.charCodeAt(start);
|
|
2995
3013
|
const end = inlineMarkerRunEnd(source, start);
|
|
2996
|
-
appendInlineToken(tokens, code === 42 ?
|
|
3014
|
+
appendInlineToken(tokens, code === 42 ? 68 : code === 95 ? 69 : 70, start, end);
|
|
2997
3015
|
return end;
|
|
2998
3016
|
};
|
|
2999
3017
|
function createFormattingPair(type, open, close) {
|
|
3000
3018
|
return {
|
|
3001
3019
|
kind: "pair",
|
|
3020
|
+
token: open,
|
|
3002
3021
|
open,
|
|
3003
3022
|
close,
|
|
3004
3023
|
build(openToken, closeToken, sourceSpan, children) {
|
|
@@ -3010,11 +3029,11 @@ function createFormattingPair(type, open, close) {
|
|
|
3010
3029
|
}
|
|
3011
3030
|
};
|
|
3012
3031
|
}
|
|
3013
|
-
const emphasisPair = createFormattingPair("emphasis",
|
|
3014
|
-
const strongPair = createFormattingPair("strong",
|
|
3015
|
-
const deletePair = createFormattingPair("delete",
|
|
3032
|
+
const emphasisPair = createFormattingPair("emphasis", 192, 193);
|
|
3033
|
+
const strongPair = createFormattingPair("strong", 194, 195);
|
|
3034
|
+
const deletePair = createFormattingPair("delete", 196, 197);
|
|
3016
3035
|
const asteriskDelimiter = {
|
|
3017
|
-
token:
|
|
3036
|
+
token: 68,
|
|
3018
3037
|
single: emphasisPair,
|
|
3019
3038
|
double: strongPair,
|
|
3020
3039
|
pairing: {
|
|
@@ -3023,7 +3042,7 @@ const asteriskDelimiter = {
|
|
|
3023
3042
|
}
|
|
3024
3043
|
};
|
|
3025
3044
|
const underscoreDelimiter = {
|
|
3026
|
-
token:
|
|
3045
|
+
token: 69,
|
|
3027
3046
|
single: emphasisPair,
|
|
3028
3047
|
double: strongPair,
|
|
3029
3048
|
pairing: {
|
|
@@ -3033,7 +3052,7 @@ const underscoreDelimiter = {
|
|
|
3033
3052
|
allowIntraword: false
|
|
3034
3053
|
};
|
|
3035
3054
|
const strikethroughDelimiter = {
|
|
3036
|
-
token:
|
|
3055
|
+
token: 70,
|
|
3037
3056
|
double: deletePair,
|
|
3038
3057
|
pairing: { kind: "whole" }
|
|
3039
3058
|
};
|
|
@@ -3041,12 +3060,12 @@ function feature$8(strikethroughOptions) {
|
|
|
3041
3060
|
const builds = [
|
|
3042
3061
|
{
|
|
3043
3062
|
kind: "text",
|
|
3044
|
-
token:
|
|
3063
|
+
token: 68,
|
|
3045
3064
|
build: buildInlineText
|
|
3046
3065
|
},
|
|
3047
3066
|
{
|
|
3048
3067
|
kind: "text",
|
|
3049
|
-
token:
|
|
3068
|
+
token: 69,
|
|
3050
3069
|
build: buildInlineText
|
|
3051
3070
|
},
|
|
3052
3071
|
emphasisPair,
|
|
@@ -3063,7 +3082,7 @@ function feature$8(strikethroughOptions) {
|
|
|
3063
3082
|
if (strikethroughOptions) {
|
|
3064
3083
|
builds.push({
|
|
3065
3084
|
kind: "text",
|
|
3066
|
-
token:
|
|
3085
|
+
token: 70,
|
|
3067
3086
|
build: buildInlineText
|
|
3068
3087
|
}, deletePair);
|
|
3069
3088
|
delimiters.push(typeof strikethroughOptions !== "object" || strikethroughOptions.singleTilde !== false ? {
|
|
@@ -3136,8 +3155,7 @@ const feature$7 = { block: {
|
|
|
3136
3155
|
rule: 2,
|
|
3137
3156
|
syntax: {
|
|
3138
3157
|
kind: "block",
|
|
3139
|
-
|
|
3140
|
-
close: 8
|
|
3158
|
+
token: 65
|
|
3141
3159
|
},
|
|
3142
3160
|
inlineContent: true,
|
|
3143
3161
|
build(tokenStart, context) {
|
|
@@ -3160,8 +3178,7 @@ const feature$7 = { block: {
|
|
|
3160
3178
|
rule: 3,
|
|
3161
3179
|
syntax: {
|
|
3162
3180
|
kind: "block",
|
|
3163
|
-
|
|
3164
|
-
close: 8
|
|
3181
|
+
token: [66, 67]
|
|
3165
3182
|
},
|
|
3166
3183
|
inlineContent: true,
|
|
3167
3184
|
build(tokenStart, context) {
|
|
@@ -3170,7 +3187,7 @@ const feature$7 = { block: {
|
|
|
3170
3187
|
const children = inline.children;
|
|
3171
3188
|
const result = {
|
|
3172
3189
|
type: "heading",
|
|
3173
|
-
depth: tokens.kind(tokenStart) ===
|
|
3190
|
+
depth: tokens.kind(tokenStart) === 66 ? 1 : 2,
|
|
3174
3191
|
children,
|
|
3175
3192
|
position: {
|
|
3176
3193
|
start: firstChildStart(children),
|
|
@@ -3189,10 +3206,10 @@ const feature$7 = { block: {
|
|
|
3189
3206
|
start(source, lines, start, contentOffset, out) {
|
|
3190
3207
|
const atx = atxAt(source, lines, start, contentOffset);
|
|
3191
3208
|
if (!atx) return;
|
|
3192
|
-
out.push(
|
|
3209
|
+
out.push(65, contentOffset, atx.markerEnd);
|
|
3193
3210
|
if (atx.contentEnd > atx.contentOffset) out.push(1, atx.contentOffset, atx.contentEnd);
|
|
3194
3211
|
const lineEnd = lines.end(start);
|
|
3195
|
-
out.push(
|
|
3212
|
+
out.push(193, lineEnd, lineEnd);
|
|
3196
3213
|
return start + 1;
|
|
3197
3214
|
}
|
|
3198
3215
|
}]
|
|
@@ -3245,14 +3262,14 @@ const feature$6 = {
|
|
|
3245
3262
|
rule: 10,
|
|
3246
3263
|
syntax: {
|
|
3247
3264
|
kind: "leaf",
|
|
3248
|
-
token:
|
|
3265
|
+
token: 259
|
|
3249
3266
|
},
|
|
3250
3267
|
build(tokenStart, context) {
|
|
3251
3268
|
const tokens = context.structure.tokens;
|
|
3252
3269
|
const offset = tokens.start(tokenStart);
|
|
3253
3270
|
const end = tokens.end(tokenStart);
|
|
3254
3271
|
const unterminated = tokens.value(tokenStart);
|
|
3255
|
-
if (tokens.kind(tokenStart) !==
|
|
3272
|
+
if (tokens.kind(tokenStart) !== 259 || unterminated === void 0) throw new Error("HTML block lacks termination state");
|
|
3256
3273
|
let html = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
|
|
3257
3274
|
if (!unterminated && html.endsWith("\n")) html = html.slice(0, -1);
|
|
3258
3275
|
return {
|
|
@@ -3277,7 +3294,7 @@ const feature$6 = {
|
|
|
3277
3294
|
if (end < lines.length) end++;
|
|
3278
3295
|
else unterminated = true;
|
|
3279
3296
|
} else if (!htmlStart.terminator) while (end < lines.length && !isBlank(source, lines, end)) end++;
|
|
3280
|
-
appendLogicalToken(out,
|
|
3297
|
+
appendLogicalToken(out, 259, source, lines, start, end, unterminated);
|
|
3281
3298
|
return end;
|
|
3282
3299
|
}
|
|
3283
3300
|
}]
|
|
@@ -3287,14 +3304,14 @@ const feature$6 = {
|
|
|
3287
3304
|
marker: 60,
|
|
3288
3305
|
scan(source, start, tokens) {
|
|
3289
3306
|
let end = matchInlinePatternEnd(htmlComment, source, start);
|
|
3290
|
-
let kind =
|
|
3307
|
+
let kind = 130;
|
|
3291
3308
|
if (end < 0) {
|
|
3292
3309
|
end = matchInlinePatternEnd(autolink, source, start);
|
|
3293
|
-
kind =
|
|
3310
|
+
kind = 132;
|
|
3294
3311
|
}
|
|
3295
3312
|
if (end < 0) {
|
|
3296
3313
|
end = matchInlinePatternEnd(inlineHtml, source, start);
|
|
3297
|
-
kind =
|
|
3314
|
+
kind = 131;
|
|
3298
3315
|
}
|
|
3299
3316
|
if (end < 0) return start + 1;
|
|
3300
3317
|
appendInlineToken(tokens, kind, start, end);
|
|
@@ -3303,11 +3320,11 @@ const feature$6 = {
|
|
|
3303
3320
|
}],
|
|
3304
3321
|
build: [{
|
|
3305
3322
|
kind: "leaf",
|
|
3306
|
-
token:
|
|
3323
|
+
token: 131,
|
|
3307
3324
|
build: buildInlineHtml
|
|
3308
3325
|
}, {
|
|
3309
3326
|
kind: "leaf",
|
|
3310
|
-
token:
|
|
3327
|
+
token: 130,
|
|
3311
3328
|
build: buildInlineHtml
|
|
3312
3329
|
}]
|
|
3313
3330
|
}
|
|
@@ -3378,7 +3395,14 @@ function linkTitleEnd(source, start) {
|
|
|
3378
3395
|
}
|
|
3379
3396
|
return -1;
|
|
3380
3397
|
}
|
|
3398
|
+
const simpleLinkTail = /\([^<\\()\t\n\r ]+\)/y;
|
|
3381
3399
|
function scanLinkTail(source, start, tokens) {
|
|
3400
|
+
simpleLinkTail.lastIndex = start + 1;
|
|
3401
|
+
if (simpleLinkTail.test(source)) {
|
|
3402
|
+
const end = simpleLinkTail.lastIndex;
|
|
3403
|
+
appendInlineToken(tokens, 73, start, end, end - start - 1);
|
|
3404
|
+
return end;
|
|
3405
|
+
}
|
|
3382
3406
|
if (source.charCodeAt(start + 1) !== 40) return -1;
|
|
3383
3407
|
let offset = skipWhitespace(source, start + 2);
|
|
3384
3408
|
let destinationEnd = offset;
|
|
@@ -3390,13 +3414,12 @@ function scanLinkTail(source, start, tokens) {
|
|
|
3390
3414
|
if (whitespaceEnd > offset && source.charCodeAt(whitespaceEnd) !== 41) {
|
|
3391
3415
|
const titleEnd = linkTitleEnd(source, whitespaceEnd);
|
|
3392
3416
|
if (titleEnd < 0) return -1;
|
|
3393
|
-
offset = titleEnd;
|
|
3417
|
+
offset = skipWhitespace(source, titleEnd);
|
|
3394
3418
|
} else offset = whitespaceEnd;
|
|
3395
|
-
offset = skipWhitespace(source, offset);
|
|
3396
3419
|
if (source.charCodeAt(offset) !== 41) return -1;
|
|
3397
3420
|
}
|
|
3398
3421
|
const end = offset + 1;
|
|
3399
|
-
appendInlineToken(tokens,
|
|
3422
|
+
appendInlineToken(tokens, 73, start, end, destinationEnd - start);
|
|
3400
3423
|
return end;
|
|
3401
3424
|
}
|
|
3402
3425
|
function isLinkWhitespace(code) {
|
|
@@ -3490,7 +3513,7 @@ const feature$5 = { inline: {
|
|
|
3490
3513
|
scan(source, start, tokens) {
|
|
3491
3514
|
if (source.charCodeAt(start + 1) !== 91) return start + 1;
|
|
3492
3515
|
const end = start + 2;
|
|
3493
|
-
appendInlineToken(tokens,
|
|
3516
|
+
appendInlineToken(tokens, 71, start, end);
|
|
3494
3517
|
return end;
|
|
3495
3518
|
}
|
|
3496
3519
|
},
|
|
@@ -3498,7 +3521,7 @@ const feature$5 = { inline: {
|
|
|
3498
3521
|
marker: 91,
|
|
3499
3522
|
scan(source, start, tokens) {
|
|
3500
3523
|
const end = start + 1;
|
|
3501
|
-
appendInlineToken(tokens,
|
|
3524
|
+
appendInlineToken(tokens, 72, start, end);
|
|
3502
3525
|
return end;
|
|
3503
3526
|
}
|
|
3504
3527
|
},
|
|
@@ -3507,7 +3530,7 @@ const feature$5 = { inline: {
|
|
|
3507
3530
|
scan(source, start, tokens) {
|
|
3508
3531
|
const end = scanLinkTail(source, start, tokens);
|
|
3509
3532
|
if (end >= 0) return end;
|
|
3510
|
-
appendInlineToken(tokens,
|
|
3533
|
+
appendInlineToken(tokens, 74, start, start + 1);
|
|
3511
3534
|
return start + 1;
|
|
3512
3535
|
}
|
|
3513
3536
|
}
|
|
@@ -3515,31 +3538,27 @@ const feature$5 = { inline: {
|
|
|
3515
3538
|
build: [
|
|
3516
3539
|
{
|
|
3517
3540
|
kind: "pair",
|
|
3518
|
-
|
|
3519
|
-
close: 24,
|
|
3541
|
+
token: 198,
|
|
3520
3542
|
build: buildInlineLink
|
|
3521
3543
|
},
|
|
3522
3544
|
{
|
|
3523
3545
|
kind: "pair",
|
|
3524
|
-
|
|
3525
|
-
close: 26,
|
|
3546
|
+
token: 200,
|
|
3526
3547
|
build: buildInlineImage
|
|
3527
3548
|
},
|
|
3528
3549
|
{
|
|
3529
3550
|
kind: "pair",
|
|
3530
|
-
|
|
3531
|
-
close: 28,
|
|
3551
|
+
token: 202,
|
|
3532
3552
|
build: buildInlineReferenceLink
|
|
3533
3553
|
},
|
|
3534
3554
|
{
|
|
3535
3555
|
kind: "pair",
|
|
3536
|
-
|
|
3537
|
-
close: 30,
|
|
3556
|
+
token: 204,
|
|
3538
3557
|
build: buildInlineReferenceImage
|
|
3539
3558
|
},
|
|
3540
3559
|
{
|
|
3541
3560
|
kind: "leaf",
|
|
3542
|
-
token:
|
|
3561
|
+
token: 132,
|
|
3543
3562
|
build(tokenIndex, sourceSpan, context) {
|
|
3544
3563
|
const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(1, -1);
|
|
3545
3564
|
return {
|
|
@@ -3568,22 +3587,22 @@ const feature$5 = { inline: {
|
|
|
3568
3587
|
},
|
|
3569
3588
|
{
|
|
3570
3589
|
kind: "text",
|
|
3571
|
-
token:
|
|
3590
|
+
token: 72,
|
|
3572
3591
|
build: buildInlineText
|
|
3573
3592
|
},
|
|
3574
3593
|
{
|
|
3575
3594
|
kind: "text",
|
|
3576
|
-
token:
|
|
3595
|
+
token: 71,
|
|
3577
3596
|
build: buildInlineText
|
|
3578
3597
|
},
|
|
3579
3598
|
{
|
|
3580
3599
|
kind: "text",
|
|
3581
|
-
token:
|
|
3600
|
+
token: 73,
|
|
3582
3601
|
build: buildDecodedInlineText
|
|
3583
3602
|
},
|
|
3584
3603
|
{
|
|
3585
3604
|
kind: "text",
|
|
3586
|
-
token:
|
|
3605
|
+
token: 74,
|
|
3587
3606
|
build: buildInlineText
|
|
3588
3607
|
}
|
|
3589
3608
|
]
|
|
@@ -3595,6 +3614,7 @@ function listMarkerPadding(source, lines, index, markerEnd, markerColumn) {
|
|
|
3595
3614
|
if (markerEnd === lineEnd) return {
|
|
3596
3615
|
offset: markerEnd,
|
|
3597
3616
|
columns: 1,
|
|
3617
|
+
hasContent: false,
|
|
3598
3618
|
prefixColumns: 0
|
|
3599
3619
|
};
|
|
3600
3620
|
let offset = markerEnd;
|
|
@@ -3606,20 +3626,23 @@ function listMarkerPadding(source, lines, index, markerEnd, markerColumn) {
|
|
|
3606
3626
|
else break;
|
|
3607
3627
|
offset++;
|
|
3608
3628
|
}
|
|
3629
|
+
const hasContent = offset < lineEnd;
|
|
3609
3630
|
const whitespaceColumns = column - markerColumn;
|
|
3610
|
-
if (
|
|
3631
|
+
if (hasContent && whitespaceColumns <= 4) return {
|
|
3611
3632
|
offset,
|
|
3612
3633
|
columns: whitespaceColumns,
|
|
3634
|
+
hasContent: true,
|
|
3613
3635
|
prefixColumns: 0
|
|
3614
3636
|
};
|
|
3615
3637
|
const firstPaddingColumns = source.charCodeAt(markerEnd) === 9 ? 4 - markerColumn % 4 : 1;
|
|
3616
3638
|
return {
|
|
3617
3639
|
offset: markerEnd + 1,
|
|
3618
3640
|
columns: 1,
|
|
3641
|
+
hasContent,
|
|
3619
3642
|
prefixColumns: firstPaddingColumns - 1
|
|
3620
3643
|
};
|
|
3621
3644
|
}
|
|
3622
|
-
function listMarkerAt(source, lines, index, contentOffset
|
|
3645
|
+
function listMarkerAt(source, lines, index, contentOffset) {
|
|
3623
3646
|
if (contentOffset < 0) return;
|
|
3624
3647
|
const indent = lines.prefixColumns(index) + contentOffset - lines.start(index);
|
|
3625
3648
|
const marker = source.charCodeAt(contentOffset);
|
|
@@ -3634,6 +3657,7 @@ function listMarkerAt(source, lines, index, contentOffset = lineIndentOffset(sou
|
|
|
3634
3657
|
indent,
|
|
3635
3658
|
offset: contentOffset,
|
|
3636
3659
|
end: markerEnd,
|
|
3660
|
+
hasContent: padding.hasContent,
|
|
3637
3661
|
contentOffset: padding.offset,
|
|
3638
3662
|
contentIndent: indent + 1 + padding.columns,
|
|
3639
3663
|
contentPrefixColumns: padding.prefixColumns,
|
|
@@ -3663,6 +3687,7 @@ function listMarkerAt(source, lines, index, contentOffset = lineIndentOffset(sou
|
|
|
3663
3687
|
indent,
|
|
3664
3688
|
offset: contentOffset,
|
|
3665
3689
|
end: orderedEnd,
|
|
3690
|
+
hasContent: padding.hasContent,
|
|
3666
3691
|
contentOffset: padding.offset,
|
|
3667
3692
|
contentIndent: indent + markerWidth + padding.columns,
|
|
3668
3693
|
contentPrefixColumns: padding.prefixColumns,
|
|
@@ -3673,9 +3698,6 @@ function listMarkerAt(source, lines, index, contentOffset = lineIndentOffset(sou
|
|
|
3673
3698
|
function sameList(a, b) {
|
|
3674
3699
|
return a.kind === b.kind && a.delimiter === b.delimiter;
|
|
3675
3700
|
}
|
|
3676
|
-
function hasListContent(source, lines, index, marker) {
|
|
3677
|
-
return !!marker && /\S/.test(source.slice(marker.contentOffset, lines.end(index)));
|
|
3678
|
-
}
|
|
3679
3701
|
function isTaskListWhitespace(code) {
|
|
3680
3702
|
return code === 32 || code >= 9 && code <= 13;
|
|
3681
3703
|
}
|
|
@@ -3712,7 +3734,7 @@ const buildListItem = (tokenStart, context) => {
|
|
|
3712
3734
|
return {
|
|
3713
3735
|
type: "listItem",
|
|
3714
3736
|
spread: tokens.value(close) === true,
|
|
3715
|
-
checked: markerKind ===
|
|
3737
|
+
checked: markerKind === 130 ? true : markerKind === 129 ? false : null,
|
|
3716
3738
|
children,
|
|
3717
3739
|
position: {
|
|
3718
3740
|
start,
|
|
@@ -3745,8 +3767,8 @@ const listStart = (source, lines, start, contentOffset, out, context) => {
|
|
|
3745
3767
|
if (!marker) return;
|
|
3746
3768
|
const listMarker = marker;
|
|
3747
3769
|
const kind = listMarker.kind;
|
|
3748
|
-
const listOpen = kind === "ordered" ?
|
|
3749
|
-
const listClose = kind === "ordered" ?
|
|
3770
|
+
const listOpen = kind === "ordered" ? 70 : 69;
|
|
3771
|
+
const listClose = kind === "ordered" ? 196 : 195;
|
|
3750
3772
|
out.push(listOpen, listMarker.offset, listMarker.end, kind === "ordered" ? { value: listMarker.startNumber } : void 0);
|
|
3751
3773
|
let index = start;
|
|
3752
3774
|
let listEnd = listMarker.end;
|
|
@@ -3756,23 +3778,19 @@ const listStart = (source, lines, start, contentOffset, out, context) => {
|
|
|
3756
3778
|
let sibling;
|
|
3757
3779
|
listSpread ||= trailingBlank;
|
|
3758
3780
|
trailingBlank = false;
|
|
3759
|
-
out.push(
|
|
3781
|
+
out.push(128, marker.offset, marker.end);
|
|
3760
3782
|
const itemLines = new BlockLines();
|
|
3761
3783
|
itemLines.pushFrom(lines, index, marker.contentOffset, marker.contentPrefixColumns);
|
|
3762
|
-
let hasContent =
|
|
3784
|
+
let hasContent = marker.hasContent;
|
|
3763
3785
|
let paragraphLeaf = hasContent ? 2 : 0;
|
|
3764
3786
|
index++;
|
|
3765
3787
|
while (index < lines.length) {
|
|
3766
|
-
const
|
|
3767
|
-
if (
|
|
3768
|
-
sibling = candidate;
|
|
3769
|
-
break;
|
|
3770
|
-
}
|
|
3771
|
-
if (isBlank(source, lines, index)) {
|
|
3788
|
+
const line = itemLines.pushAfterColumns(source, lines, index, marker.contentIndent);
|
|
3789
|
+
if (line === 0) {
|
|
3772
3790
|
if (!hasContent) {
|
|
3773
3791
|
trailingBlank = true;
|
|
3774
3792
|
index++;
|
|
3775
|
-
sibling = index < lines.length ? listMarkerAt(source, lines, index) : void 0;
|
|
3793
|
+
sibling = index < lines.length ? listMarkerAt(source, lines, index, lineIndentOffset(source, lines, index)) : void 0;
|
|
3776
3794
|
break;
|
|
3777
3795
|
}
|
|
3778
3796
|
itemLines.pushFrom(lines, index);
|
|
@@ -3781,15 +3799,18 @@ const listStart = (source, lines, start, contentOffset, out, context) => {
|
|
|
3781
3799
|
index++;
|
|
3782
3800
|
continue;
|
|
3783
3801
|
}
|
|
3784
|
-
|
|
3785
|
-
if (content) {
|
|
3786
|
-
itemLines.pushFrom(lines, index, content.offset, content.prefixColumns);
|
|
3802
|
+
if (line === 1) {
|
|
3787
3803
|
trailingBlank = false;
|
|
3788
3804
|
hasContent = true;
|
|
3789
3805
|
paragraphLeaf = 2;
|
|
3790
3806
|
index++;
|
|
3791
3807
|
continue;
|
|
3792
3808
|
}
|
|
3809
|
+
const candidate = listMarkerAt(source, lines, index, lineIndentOffset(source, lines, index));
|
|
3810
|
+
if (candidate) {
|
|
3811
|
+
sibling = candidate;
|
|
3812
|
+
break;
|
|
3813
|
+
}
|
|
3793
3814
|
if (paragraphLeaf === 2) paragraphLeaf = context.endsWithParagraphLeaf(source, itemLines, itemLines.length - 1) ? 1 : 0;
|
|
3794
3815
|
if (paragraphLeaf === 0 || context.startsInterruptingBlock(source, lines, index)) break;
|
|
3795
3816
|
itemLines.pushLazy(lines, index);
|
|
@@ -3797,29 +3818,28 @@ const listStart = (source, lines, start, contentOffset, out, context) => {
|
|
|
3797
3818
|
}
|
|
3798
3819
|
const itemSpread = context.scanLines(source, itemLines, out);
|
|
3799
3820
|
listEnd = itemLines.next(itemLines.length - 1);
|
|
3800
|
-
out.push(
|
|
3821
|
+
out.push(197, listEnd, listEnd, itemSpread ? { value: true } : void 0);
|
|
3801
3822
|
marker = sibling;
|
|
3802
3823
|
}
|
|
3803
3824
|
out.push(listClose, listEnd, listEnd, listSpread ? { value: true } : void 0);
|
|
3804
3825
|
return index;
|
|
3805
3826
|
};
|
|
3806
3827
|
const taskListStart = (source, lines, start, contentOffset, out, context) => {
|
|
3807
|
-
const
|
|
3828
|
+
const listToken = out.length;
|
|
3808
3829
|
const nextLine = listStart(source, lines, start, contentOffset, out, context);
|
|
3809
3830
|
if (nextLine === void 0) return;
|
|
3810
|
-
for (let item =
|
|
3811
|
-
if (out.kind(item) !== 15) continue;
|
|
3831
|
+
for (let item = listToken + 1; item < out.length - 1; item += out.nodeLength(item)) {
|
|
3812
3832
|
let paragraph = item + 1;
|
|
3813
3833
|
let contentKind = out.kind(paragraph);
|
|
3814
|
-
while (contentKind ===
|
|
3834
|
+
while (contentKind === 71 || contentKind === 2 || contentKind === 198) {
|
|
3815
3835
|
paragraph++;
|
|
3816
3836
|
contentKind = out.kind(paragraph);
|
|
3817
3837
|
}
|
|
3818
|
-
if (contentKind !==
|
|
3838
|
+
if (contentKind !== 68) continue;
|
|
3819
3839
|
const firstChunk = paragraph + 1;
|
|
3820
3840
|
const marker = taskListMarkerAt(source, out.start(firstChunk), out.end(firstChunk));
|
|
3821
3841
|
if (!marker || !hasTaskListContent(source, out, firstChunk, marker.contentStart)) continue;
|
|
3822
|
-
out.setKind(item, marker.checked ?
|
|
3842
|
+
out.setKind(item, marker.checked ? 130 : 129);
|
|
3823
3843
|
out.setStart(firstChunk, marker.contentStart);
|
|
3824
3844
|
}
|
|
3825
3845
|
return nextLine;
|
|
@@ -3831,12 +3851,11 @@ function feature$4(taskList = false) {
|
|
|
3831
3851
|
rule: 5,
|
|
3832
3852
|
syntax: {
|
|
3833
3853
|
kind: "frame",
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
]
|
|
3839
|
-
close: 18
|
|
3854
|
+
token: [
|
|
3855
|
+
128,
|
|
3856
|
+
129,
|
|
3857
|
+
130
|
|
3858
|
+
]
|
|
3840
3859
|
},
|
|
3841
3860
|
build: buildListItem
|
|
3842
3861
|
},
|
|
@@ -3844,8 +3863,7 @@ function feature$4(taskList = false) {
|
|
|
3844
3863
|
rule: 6,
|
|
3845
3864
|
syntax: {
|
|
3846
3865
|
kind: "block",
|
|
3847
|
-
|
|
3848
|
-
close: 12
|
|
3866
|
+
token: 69
|
|
3849
3867
|
},
|
|
3850
3868
|
build: createBuildList(false)
|
|
3851
3869
|
},
|
|
@@ -3853,8 +3871,7 @@ function feature$4(taskList = false) {
|
|
|
3853
3871
|
rule: 7,
|
|
3854
3872
|
syntax: {
|
|
3855
3873
|
kind: "block",
|
|
3856
|
-
|
|
3857
|
-
close: 14
|
|
3874
|
+
token: 70
|
|
3858
3875
|
},
|
|
3859
3876
|
build: createBuildList(true)
|
|
3860
3877
|
}
|
|
@@ -3883,7 +3900,7 @@ function feature$4(taskList = false) {
|
|
|
3883
3900
|
},
|
|
3884
3901
|
interrupt(source, lines, index, contentOffset) {
|
|
3885
3902
|
const marker = listMarkerAt(source, lines, index, contentOffset);
|
|
3886
|
-
return
|
|
3903
|
+
return marker?.hasContent === true && (marker.kind === "unordered" || marker.kind === "ordered" && marker.startNumber === 1);
|
|
3887
3904
|
},
|
|
3888
3905
|
start: taskList ? taskListStart : listStart
|
|
3889
3906
|
}]
|
|
@@ -3900,13 +3917,13 @@ const blockRules = [{
|
|
|
3900
3917
|
rule: 14,
|
|
3901
3918
|
syntax: {
|
|
3902
3919
|
kind: "leaf",
|
|
3903
|
-
token:
|
|
3920
|
+
token: 261
|
|
3904
3921
|
},
|
|
3905
3922
|
build(tokenStart, context) {
|
|
3906
3923
|
const tokens = context.structure.tokens;
|
|
3907
|
-
const value = tokens.text(context.source, tokenStart);
|
|
3908
3924
|
const block = tokens.value(tokenStart);
|
|
3909
3925
|
if (!block) throw new Error("Math block lacks fence metadata");
|
|
3926
|
+
const value = block.content ?? tokens.text(context.source, tokenStart);
|
|
3910
3927
|
return {
|
|
3911
3928
|
type: "math",
|
|
3912
3929
|
meta: semanticText(block.info) || null,
|
|
@@ -3927,7 +3944,7 @@ const blockStarts = [{
|
|
|
3927
3944
|
while (end < lines.length && !closesFence(source, lines, end, fence)) end++;
|
|
3928
3945
|
const closed = end < lines.length;
|
|
3929
3946
|
if (end < lines.length) end++;
|
|
3930
|
-
appendLogicalToken(out,
|
|
3947
|
+
appendLogicalToken(out, 261, source, lines, start, end, fencedBlock(source, lines, start, end, fence, closed));
|
|
3931
3948
|
return end;
|
|
3932
3949
|
}
|
|
3933
3950
|
}];
|
|
@@ -3955,14 +3972,14 @@ function createMathScanRule(singleDollarTextMath) {
|
|
|
3955
3972
|
}
|
|
3956
3973
|
}
|
|
3957
3974
|
if (end < 0) return openEnd;
|
|
3958
|
-
appendInlineToken(tokens,
|
|
3975
|
+
appendInlineToken(tokens, 134, start, end, markerLength);
|
|
3959
3976
|
return end;
|
|
3960
3977
|
}
|
|
3961
3978
|
};
|
|
3962
3979
|
}
|
|
3963
3980
|
const inlineBuilds = [{
|
|
3964
3981
|
kind: "leaf",
|
|
3965
|
-
token:
|
|
3982
|
+
token: 134,
|
|
3966
3983
|
build(tokenIndex, sourceSpan, context) {
|
|
3967
3984
|
const markerLength = inlineTokenData(context.tokens, tokenIndex);
|
|
3968
3985
|
let value = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(markerLength, -markerLength);
|
|
@@ -3997,7 +4014,7 @@ const feature$2 = { block: {
|
|
|
3997
4014
|
fallbacks: [(source, lines, start, contentOffset, out, context) => {
|
|
3998
4015
|
const openToken = out.length;
|
|
3999
4016
|
const offset = lines.start(start);
|
|
4000
|
-
out.push(
|
|
4017
|
+
out.push(68, offset, offset);
|
|
4001
4018
|
let chunkOffset = contentOffset;
|
|
4002
4019
|
let index = start + 1;
|
|
4003
4020
|
while (index < lines.length) {
|
|
@@ -4005,13 +4022,12 @@ const feature$2 = { block: {
|
|
|
4005
4022
|
if (lineOffset < 0) {
|
|
4006
4023
|
if (isBlank(source, lines, index)) break;
|
|
4007
4024
|
} else {
|
|
4008
|
-
if (lineOffset === lines.end(index)) break;
|
|
4009
4025
|
const setext = setextMarkerAt(source, lines, index, lineOffset);
|
|
4010
4026
|
if (setext) {
|
|
4011
|
-
out.setKind(openToken, setext === "=" ?
|
|
4027
|
+
out.setKind(openToken, setext === "=" ? 66 : 67);
|
|
4012
4028
|
out.push(1, chunkOffset, lines.end(index - 1));
|
|
4013
4029
|
const lineEnd = lines.end(index);
|
|
4014
|
-
out.push(
|
|
4030
|
+
out.push(193, lineEnd, lineEnd);
|
|
4015
4031
|
return index + 1;
|
|
4016
4032
|
}
|
|
4017
4033
|
if (context.startsInterruptingBlock(source, lines, index, lineOffset)) break;
|
|
@@ -4022,15 +4038,14 @@ const feature$2 = { block: {
|
|
|
4022
4038
|
}
|
|
4023
4039
|
const close = lines.end(index - 1);
|
|
4024
4040
|
out.push(1, chunkOffset, close);
|
|
4025
|
-
out.push(
|
|
4041
|
+
out.push(194, close, close);
|
|
4026
4042
|
return index;
|
|
4027
4043
|
}],
|
|
4028
4044
|
rules: [{
|
|
4029
4045
|
rule: 4,
|
|
4030
4046
|
syntax: {
|
|
4031
4047
|
kind: "block",
|
|
4032
|
-
|
|
4033
|
-
close: 10
|
|
4048
|
+
token: 68
|
|
4034
4049
|
},
|
|
4035
4050
|
inlineContent: true,
|
|
4036
4051
|
build(tokenStart, context) {
|
|
@@ -4052,13 +4067,19 @@ const feature$2 = { block: {
|
|
|
4052
4067
|
//#region src/profile/features/reference.ts
|
|
4053
4068
|
function linkDefinitionFields(tokens, token) {
|
|
4054
4069
|
const fields = tokens.value(token);
|
|
4055
|
-
if (tokens.kind(token) !==
|
|
4070
|
+
if (tokens.kind(token) !== 71 || !fields) throw new Error("Expected LinkDefinitionOpen token to contain parsed fields");
|
|
4056
4071
|
return fields;
|
|
4057
4072
|
}
|
|
4058
4073
|
function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
|
|
4074
|
+
let offset = contentOffset + 1;
|
|
4075
|
+
const labelClose = source.indexOf("]", offset);
|
|
4076
|
+
if (labelClose >= 0 && labelClose < lines.end(startIndex) && source.charCodeAt(labelClose + 1) !== 58) {
|
|
4077
|
+
let escapeStart = labelClose;
|
|
4078
|
+
while (escapeStart > offset && source.charCodeAt(escapeStart - 1) === 92) escapeStart--;
|
|
4079
|
+
if ((labelClose - escapeStart & 1) === 0) return;
|
|
4080
|
+
}
|
|
4059
4081
|
let lineIndex = startIndex;
|
|
4060
4082
|
let lookaheadEnd = -1;
|
|
4061
|
-
let offset = contentOffset + 1;
|
|
4062
4083
|
let label = "";
|
|
4063
4084
|
let labelLength = 0;
|
|
4064
4085
|
let labelHasContent = false;
|
|
@@ -4217,8 +4238,7 @@ const feature$1 = { block: {
|
|
|
4217
4238
|
rule: 11,
|
|
4218
4239
|
syntax: {
|
|
4219
4240
|
kind: "block",
|
|
4220
|
-
|
|
4221
|
-
close: 24
|
|
4241
|
+
token: 71
|
|
4222
4242
|
},
|
|
4223
4243
|
build(tokenStart, context) {
|
|
4224
4244
|
const tokens = context.structure.tokens;
|
|
@@ -4240,16 +4260,16 @@ const feature$1 = { block: {
|
|
|
4240
4260
|
start(source, lines, start, contentOffset, out, context) {
|
|
4241
4261
|
const definition = linkDefinitionAt(source, lines, start, contentOffset, context);
|
|
4242
4262
|
if (!definition) return;
|
|
4243
|
-
out.push(
|
|
4263
|
+
out.push(71, contentOffset, contentOffset, {
|
|
4244
4264
|
definitionKey: definition.definitionKey,
|
|
4245
4265
|
value: definition.fields
|
|
4246
4266
|
});
|
|
4247
4267
|
let definitionEnd = contentOffset;
|
|
4248
4268
|
for (let definitionLine = start; definitionLine < definition.end; definitionLine++) {
|
|
4249
4269
|
definitionEnd = definitionLine + 1 < definition.end ? lines.next(definitionLine) : lines.end(definitionLine);
|
|
4250
|
-
out.push(
|
|
4270
|
+
out.push(2, lines.start(definitionLine), definitionEnd);
|
|
4251
4271
|
}
|
|
4252
|
-
out.push(
|
|
4272
|
+
out.push(198, definitionEnd, definitionEnd);
|
|
4253
4273
|
return definition.end;
|
|
4254
4274
|
}
|
|
4255
4275
|
}]
|
|
@@ -4318,7 +4338,7 @@ function alignmentAt(source, cells, cell) {
|
|
|
4318
4338
|
if (right) end--;
|
|
4319
4339
|
if (start === end) return;
|
|
4320
4340
|
for (let offset = start; offset < end; offset++) if (source.charCodeAt(offset) !== 45) return;
|
|
4321
|
-
return left ? right ?
|
|
4341
|
+
return left ? right ? 323 : 321 : right ? 322 : 320;
|
|
4322
4342
|
}
|
|
4323
4343
|
function delimiterAt(source, lines, index, contentOffset) {
|
|
4324
4344
|
const first = source.charCodeAt(contentOffset);
|
|
@@ -4333,14 +4353,14 @@ function delimiterAt(source, lines, index, contentOffset) {
|
|
|
4333
4353
|
return cells;
|
|
4334
4354
|
}
|
|
4335
4355
|
function emitTableRow(lines, index, cells, out) {
|
|
4336
|
-
out.push(
|
|
4356
|
+
out.push(131, cells[0], cells[0]);
|
|
4337
4357
|
for (let cell = 0; cell < cells.length; cell += 3) {
|
|
4338
4358
|
const start = cells[cell];
|
|
4339
|
-
out.push(
|
|
4340
|
-
out.push(1, cells[cell + 1], cells[cell + 2]);
|
|
4359
|
+
out.push(132, start, start);
|
|
4360
|
+
out.push(1, cells[cell + 1], cells[cell + 2], void 0, 192);
|
|
4341
4361
|
}
|
|
4342
4362
|
const lineEnd = lines.end(index);
|
|
4343
|
-
out.push(
|
|
4363
|
+
out.push(201, lineEnd, lineEnd);
|
|
4344
4364
|
}
|
|
4345
4365
|
const buildTableCell = (tokenStart, context) => {
|
|
4346
4366
|
const tokens = context.structure.tokens;
|
|
@@ -4375,7 +4395,7 @@ function tableAlignment(tokenStart, context) {
|
|
|
4375
4395
|
const result = [];
|
|
4376
4396
|
for (let token = tokenStart; token < tokenEnd; token++) {
|
|
4377
4397
|
const kind = tokens.kind(token);
|
|
4378
|
-
result.push(kind ===
|
|
4398
|
+
result.push(kind === 321 ? "left" : kind === 322 ? "right" : kind === 323 ? "center" : null);
|
|
4379
4399
|
}
|
|
4380
4400
|
return result;
|
|
4381
4401
|
}
|
|
@@ -4389,13 +4409,12 @@ const feature = { block: {
|
|
|
4389
4409
|
if (!delimiter) return;
|
|
4390
4410
|
const header = tableCellsAt(source, lines, start, true, contentOffset);
|
|
4391
4411
|
if (header?.length !== delimiter.length) return;
|
|
4392
|
-
out.push(
|
|
4412
|
+
out.push(73, header[0], header[0]);
|
|
4393
4413
|
emitTableRow(lines, start, header, out);
|
|
4394
4414
|
const delimiterEnd = lines.end(delimiterLine);
|
|
4395
4415
|
for (let cell = 0; cell < delimiter.length; cell += 3) out.push(delimiter[cell + 1], delimiter[cell], delimiter[cell + 3] ?? delimiterEnd);
|
|
4396
4416
|
let end = start + 2;
|
|
4397
4417
|
while (end < lines.length) {
|
|
4398
|
-
if (isBlank(source, lines, end)) break;
|
|
4399
4418
|
const contentOffset = lineIndentOffset(source, lines, end);
|
|
4400
4419
|
if (contentOffset < 0 || context.startsInterruptingBlock(source, lines, end, contentOffset)) break;
|
|
4401
4420
|
const cells = tableCellsAt(source, lines, end, false, contentOffset);
|
|
@@ -4404,7 +4423,7 @@ const feature = { block: {
|
|
|
4404
4423
|
end++;
|
|
4405
4424
|
}
|
|
4406
4425
|
const tableEnd = lines.end(end - 1);
|
|
4407
|
-
out.push(
|
|
4426
|
+
out.push(200, tableEnd, tableEnd);
|
|
4408
4427
|
return end;
|
|
4409
4428
|
}],
|
|
4410
4429
|
rules: [
|
|
@@ -4412,8 +4431,7 @@ const feature = { block: {
|
|
|
4412
4431
|
rule: 17,
|
|
4413
4432
|
syntax: {
|
|
4414
4433
|
kind: "frame",
|
|
4415
|
-
|
|
4416
|
-
close: 1
|
|
4434
|
+
token: 132
|
|
4417
4435
|
},
|
|
4418
4436
|
inlineContent: true,
|
|
4419
4437
|
build: buildTableCell
|
|
@@ -4422,8 +4440,7 @@ const feature = { block: {
|
|
|
4422
4440
|
rule: 16,
|
|
4423
4441
|
syntax: {
|
|
4424
4442
|
kind: "frame",
|
|
4425
|
-
|
|
4426
|
-
close: 32
|
|
4443
|
+
token: 131
|
|
4427
4444
|
},
|
|
4428
4445
|
build: buildTableRow
|
|
4429
4446
|
},
|
|
@@ -4431,11 +4448,11 @@ const feature = { block: {
|
|
|
4431
4448
|
rule: 18,
|
|
4432
4449
|
syntax: {
|
|
4433
4450
|
kind: "group",
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4451
|
+
token: [
|
|
4452
|
+
320,
|
|
4453
|
+
321,
|
|
4454
|
+
322,
|
|
4455
|
+
323
|
|
4439
4456
|
]
|
|
4440
4457
|
}
|
|
4441
4458
|
},
|
|
@@ -4443,8 +4460,7 @@ const feature = { block: {
|
|
|
4443
4460
|
rule: 15,
|
|
4444
4461
|
syntax: {
|
|
4445
4462
|
kind: "block",
|
|
4446
|
-
|
|
4447
|
-
close: 30
|
|
4463
|
+
token: 73
|
|
4448
4464
|
},
|
|
4449
4465
|
build(tokenStart, context) {
|
|
4450
4466
|
const tokens = context.structure.tokens;
|
|
@@ -4626,56 +4642,35 @@ const noDelimiterReplacements = [];
|
|
|
4626
4642
|
function frameClaim(frames, frame) {
|
|
4627
4643
|
return frames[frame + 5] & 7;
|
|
4628
4644
|
}
|
|
4629
|
-
function
|
|
4630
|
-
frames[frame + 5] =
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
frames[owner + 3] = candidate;
|
|
4638
|
-
}
|
|
4639
|
-
function promoteCandidates(frames, owner, source) {
|
|
4640
|
-
if (owner < 0) return;
|
|
4641
|
-
const first = frames[source + 2];
|
|
4642
|
-
if (first < 0) return;
|
|
4643
|
-
const last = frames[source + 3];
|
|
4644
|
-
const ownerLast = frames[owner + 3];
|
|
4645
|
-
if (ownerLast >= 0) frames[ownerLast + 4] = first;
|
|
4646
|
-
else frames[owner + 2] = first;
|
|
4647
|
-
frames[owner + 3] = last;
|
|
4648
|
-
}
|
|
4649
|
-
function rewriteLinkCandidates(frames, owner) {
|
|
4650
|
-
let candidate = frames[owner + 2];
|
|
4651
|
-
frames[owner + 2] = -1;
|
|
4652
|
-
frames[owner + 3] = -1;
|
|
4653
|
-
while (candidate >= 0) {
|
|
4654
|
-
const next = frames[candidate + 4];
|
|
4655
|
-
rewriteLinkCandidates(frames, candidate);
|
|
4645
|
+
function setFrameState(frames, frame, state) {
|
|
4646
|
+
frames[frame + 5] = state;
|
|
4647
|
+
frames[0] |= 4;
|
|
4648
|
+
}
|
|
4649
|
+
function rewriteLinkCandidates(frames, candidates, start) {
|
|
4650
|
+
let write = start;
|
|
4651
|
+
for (let read = start; read < candidates.length; read++) {
|
|
4652
|
+
const candidate = candidates[read];
|
|
4656
4653
|
const state = frames[candidate + 5];
|
|
4657
|
-
if ((state & 7) === 3 && !(state & 8))
|
|
4658
|
-
|
|
4659
|
-
promoteCandidates(frames, owner, candidate);
|
|
4660
|
-
} else {
|
|
4654
|
+
if ((state & 7) === 3 && !(state & 8)) frames[candidate + 5] = 0;
|
|
4655
|
+
else {
|
|
4661
4656
|
frames[candidate + 5] = state | 16;
|
|
4662
|
-
|
|
4657
|
+
candidates[write++] = candidate;
|
|
4663
4658
|
}
|
|
4664
|
-
candidate = next;
|
|
4665
4659
|
}
|
|
4660
|
+
candidates.length = write;
|
|
4666
4661
|
}
|
|
4667
|
-
function allocateFrame(frames, openToken, parent) {
|
|
4662
|
+
function allocateFrame(frames, openToken, parent, candidateStart) {
|
|
4668
4663
|
const frame = frames.length;
|
|
4669
|
-
frames.push(openToken, -1,
|
|
4664
|
+
frames.push(openToken, -1, candidateStart, -1, parent, 0, 0);
|
|
4670
4665
|
return frame;
|
|
4671
4666
|
}
|
|
4672
4667
|
function isImageFrame(tokens, frames, frame) {
|
|
4673
|
-
return inlineTokenKind(tokens, frames[frame + 0]) ===
|
|
4668
|
+
return inlineTokenKind(tokens, frames[frame + 0]) === 71;
|
|
4674
4669
|
}
|
|
4675
4670
|
function hasAdjacentComponent(tokens, frames, frame) {
|
|
4676
4671
|
const openToken = frames[frame + 0];
|
|
4677
4672
|
const componentToken = openToken - 1;
|
|
4678
|
-
return componentToken >= 0 && inlineTokenKind(tokens, componentToken) ===
|
|
4673
|
+
return componentToken >= 0 && inlineTokenKind(tokens, componentToken) === 137 && inlineTokenEnd(tokens, componentToken) === inlineTokenStart(tokens, openToken);
|
|
4679
4674
|
}
|
|
4680
4675
|
function referenceLabelEnd(source, start) {
|
|
4681
4676
|
if (source.charCodeAt(start) !== 91) return -1;
|
|
@@ -4713,73 +4708,60 @@ function acceptsShortcutLabel(source, start, end) {
|
|
|
4713
4708
|
}
|
|
4714
4709
|
return hasContent;
|
|
4715
4710
|
}
|
|
4716
|
-
function analyzeBrackets(source, tokens, delimiterByKind,
|
|
4717
|
-
let
|
|
4711
|
+
function analyzeBrackets(source, tokens, delimiterByKind, definitions, options) {
|
|
4712
|
+
let hasDelimiter = false;
|
|
4718
4713
|
let frames;
|
|
4714
|
+
let candidates;
|
|
4719
4715
|
let stackTop = -1;
|
|
4720
4716
|
const count = inlineTokenCount(tokens);
|
|
4721
4717
|
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
4722
4718
|
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
4723
|
-
if (delimiterByKind[kind])
|
|
4724
|
-
if (kind ===
|
|
4725
|
-
|
|
4726
|
-
frames
|
|
4727
|
-
stackTop = allocateFrame(frames, tokenIndex, stackTop);
|
|
4719
|
+
if (delimiterByKind[kind]) hasDelimiter = true;
|
|
4720
|
+
if (kind === 72 || kind === 71) {
|
|
4721
|
+
frames ??= [1];
|
|
4722
|
+
stackTop = allocateFrame(frames, tokenIndex, stackTop, candidates?.length ?? 0);
|
|
4728
4723
|
continue;
|
|
4729
4724
|
}
|
|
4730
|
-
if (kind !==
|
|
4725
|
+
if (kind !== 74 && kind !== 73) continue;
|
|
4731
4726
|
if (stackTop < 0) continue;
|
|
4732
4727
|
const frame = stackTop;
|
|
4733
4728
|
const arena = frames;
|
|
4734
|
-
|
|
4735
|
-
stackTop = parent;
|
|
4729
|
+
stackTop = arena[frame + 4];
|
|
4736
4730
|
arena[frame + 1] = tokenIndex;
|
|
4737
4731
|
const image = isImageFrame(tokens, arena, frame);
|
|
4738
|
-
if (options.footnote && kind ===
|
|
4732
|
+
if (options.footnote && kind === 74) {
|
|
4739
4733
|
const openToken = arena[frame + 0];
|
|
4740
4734
|
const label = footnoteLabelAt(source, inlineTokenStart(tokens, openToken) + (image ? 1 : 0), source.length);
|
|
4741
|
-
if (label && label.end === inlineTokenEnd(tokens, tokenIndex) &&
|
|
4742
|
-
|
|
4735
|
+
if (label && label.end === inlineTokenEnd(tokens, tokenIndex) && definitions.hasDefinition(label.definitionKey)) {
|
|
4736
|
+
setFrameState(arena, frame, 1);
|
|
4737
|
+
if (candidates) candidates.length = arena[frame + 2];
|
|
4743
4738
|
continue;
|
|
4744
4739
|
}
|
|
4745
4740
|
}
|
|
4746
|
-
if (!options.component) continue;
|
|
4747
|
-
if (
|
|
4748
|
-
|
|
4749
|
-
continue;
|
|
4741
|
+
if (!options.component || image) continue;
|
|
4742
|
+
if (kind === 73) {
|
|
4743
|
+
if (candidates) rewriteLinkCandidates(arena, candidates, arena[frame + 2]);
|
|
4750
4744
|
}
|
|
4751
|
-
if (kind === 21) rewriteLinkCandidates(arena, frame);
|
|
4752
4745
|
if (hasAdjacentComponent(tokens, arena, frame)) {
|
|
4753
|
-
|
|
4754
|
-
|
|
4746
|
+
setFrameState(arena, frame, 2);
|
|
4747
|
+
(candidates ??= []).push(frame);
|
|
4755
4748
|
continue;
|
|
4756
4749
|
}
|
|
4757
4750
|
const close = inlineTokenStart(tokens, tokenIndex);
|
|
4758
4751
|
const trailing = source.charCodeAt(close + 1);
|
|
4759
|
-
if (trailing === 40 || trailing === 91)
|
|
4760
|
-
promoteCandidates(arena, parent, frame);
|
|
4761
|
-
continue;
|
|
4762
|
-
}
|
|
4752
|
+
if (trailing === 40 || trailing === 91) continue;
|
|
4763
4753
|
const attributesStart = close + 1;
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
if (parent >= 0) appendCandidate(arena, parent, frame);
|
|
4767
|
-
}
|
|
4768
|
-
if (options.component && stackTop >= 0) {
|
|
4769
|
-
const arena = frames;
|
|
4770
|
-
while (stackTop >= 0) {
|
|
4771
|
-
const frame = stackTop;
|
|
4772
|
-
stackTop = arena[frame + 4];
|
|
4773
|
-
promoteCandidates(arena, stackTop, frame);
|
|
4774
|
-
}
|
|
4754
|
+
setFrameState(arena, frame, 3 | (source.charCodeAt(attributesStart) === 123 && attributesEnd(source, attributesStart) !== void 0 ? 8 : 0));
|
|
4755
|
+
(candidates ??= []).push(frame);
|
|
4775
4756
|
}
|
|
4776
4757
|
if (frames) {
|
|
4777
|
-
frames[0]
|
|
4758
|
+
frames[0] |= hasDelimiter ? 2 : 0;
|
|
4778
4759
|
return frames;
|
|
4779
4760
|
}
|
|
4780
|
-
return
|
|
4761
|
+
return hasDelimiter ? delimiterOnlyFrames : noBracketFrames;
|
|
4781
4762
|
}
|
|
4782
|
-
function resolveReferences(source, tokens, frames,
|
|
4763
|
+
function resolveReferences(source, tokens, frames, definitions) {
|
|
4764
|
+
const hasDefinitions = definitions.hasDefinitions();
|
|
4783
4765
|
let rawTop = -1;
|
|
4784
4766
|
let logicalTop = -1;
|
|
4785
4767
|
let frameCursor = frameHeaderSize;
|
|
@@ -4797,13 +4779,12 @@ function resolveReferences(source, tokens, frames, context) {
|
|
|
4797
4779
|
consumeFrames = false;
|
|
4798
4780
|
}
|
|
4799
4781
|
const consuming = consumedEnd >= 0;
|
|
4800
|
-
if (kind ===
|
|
4782
|
+
if (kind === 72 || kind === 71) {
|
|
4801
4783
|
const frame = frameCursor;
|
|
4802
4784
|
frameCursor += 7;
|
|
4803
|
-
frames[frame + 2] = rawTop;
|
|
4804
4785
|
rawTop = frame;
|
|
4805
4786
|
if (consuming) {
|
|
4806
|
-
if (consumeFrames)
|
|
4787
|
+
if (consumeFrames) setFrameState(frames, frame, 6);
|
|
4807
4788
|
continue;
|
|
4808
4789
|
}
|
|
4809
4790
|
const claim = frameClaim(frames, frame);
|
|
@@ -4816,48 +4797,48 @@ function resolveReferences(source, tokens, frames, context) {
|
|
|
4816
4797
|
if (frames[frame + 5] & 16) literalDepth++;
|
|
4817
4798
|
continue;
|
|
4818
4799
|
}
|
|
4819
|
-
if (literalDepth > 0 && !(kind ===
|
|
4800
|
+
if (literalDepth > 0 && !(kind === 71)) continue;
|
|
4820
4801
|
frames[frame + 3] = logicalTop;
|
|
4821
4802
|
logicalTop = frame;
|
|
4822
4803
|
lastVisibleOpener = tokenIndex;
|
|
4823
4804
|
continue;
|
|
4824
4805
|
}
|
|
4825
|
-
if (kind !==
|
|
4806
|
+
if (kind !== 74 && kind !== 73) continue;
|
|
4826
4807
|
const rawFrame = rawTop;
|
|
4827
|
-
if (rawFrame >= 0) rawTop = frames[rawFrame +
|
|
4808
|
+
if (rawFrame >= 0) rawTop = frames[rawFrame + 4];
|
|
4828
4809
|
if (consuming) {
|
|
4829
|
-
if (consumeFrames && rawFrame >= 0)
|
|
4810
|
+
if (consumeFrames && rawFrame >= 0) setFrameState(frames, rawFrame, 6);
|
|
4830
4811
|
continue;
|
|
4831
4812
|
}
|
|
4832
4813
|
const rawClaim = rawFrame < 0 ? 0 : frameClaim(frames, rawFrame);
|
|
4833
4814
|
if (!(rawClaim === 1 || rawClaim === 2 || rawClaim === 3) && (literalDepth <= 0 || rawFrame < 0 || isImageFrame(tokens, frames, rawFrame))) {
|
|
4834
4815
|
const frame = logicalTop;
|
|
4835
|
-
if (frame >= 0)
|
|
4836
|
-
|
|
4816
|
+
if (frame >= 0) logicalTop = frames[frame + 3];
|
|
4817
|
+
if (frame >= 0 && (kind === 73 || hasDefinitions)) {
|
|
4837
4818
|
const openToken = frames[frame + 0];
|
|
4838
4819
|
const image = isImageFrame(tokens, frames, frame);
|
|
4839
|
-
if (
|
|
4820
|
+
if (image || openToken + 1 >= inactiveBefore) {
|
|
4840
4821
|
const contentStart = inlineTokenEnd(tokens, openToken);
|
|
4841
4822
|
const contentEnd = tokenStart;
|
|
4842
4823
|
let closeEnd = inlineTokenEnd(tokens, tokenIndex);
|
|
4843
4824
|
let reference = false;
|
|
4844
|
-
let matched = kind ===
|
|
4825
|
+
let matched = kind === 73;
|
|
4845
4826
|
if (!matched) {
|
|
4846
4827
|
const labelEnd = referenceLabelEnd(source, closeEnd);
|
|
4847
4828
|
if (labelEnd > 0) {
|
|
4848
4829
|
const label = source.slice(closeEnd + 1, labelEnd - 1) || source.slice(contentStart, contentEnd);
|
|
4849
|
-
matched =
|
|
4830
|
+
matched = definitions.hasDefinition(normalizeAssociationLabel(label));
|
|
4850
4831
|
if (matched) {
|
|
4851
4832
|
closeEnd = labelEnd;
|
|
4852
4833
|
reference = true;
|
|
4853
4834
|
}
|
|
4854
|
-
} else if (lastVisibleOpener <= openToken && acceptsShortcutLabel(source, contentStart, contentEnd) &&
|
|
4835
|
+
} else if (lastVisibleOpener <= openToken && acceptsShortcutLabel(source, contentStart, contentEnd) && definitions.hasDefinition(normalizeAssociationLabel(source.slice(contentStart, contentEnd)))) {
|
|
4855
4836
|
matched = true;
|
|
4856
4837
|
reference = true;
|
|
4857
4838
|
}
|
|
4858
4839
|
}
|
|
4859
4840
|
if (matched) {
|
|
4860
|
-
|
|
4841
|
+
setFrameState(frames, frame, reference ? 5 : 4);
|
|
4861
4842
|
frames[frame + 1] = tokenIndex;
|
|
4862
4843
|
frames[frame + 6] = closeEnd;
|
|
4863
4844
|
if (!image) inactiveBefore = Math.max(inactiveBefore, openToken + 1);
|
|
@@ -4869,7 +4850,7 @@ function resolveReferences(source, tokens, frames, context) {
|
|
|
4869
4850
|
}
|
|
4870
4851
|
}
|
|
4871
4852
|
}
|
|
4872
|
-
if (rawFrame >= 0 &&
|
|
4853
|
+
if (rawFrame >= 0 && frames[rawFrame + 5] & 16) literalDepth--;
|
|
4873
4854
|
}
|
|
4874
4855
|
}
|
|
4875
4856
|
function assignDelimiterScopes(source, tokens, frames, delimiterByKind) {
|
|
@@ -4890,7 +4871,7 @@ function assignDelimiterScopes(source, tokens, frames, delimiterByKind) {
|
|
|
4890
4871
|
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
4891
4872
|
const tokenStart = inlineTokenStart(tokens, tokenIndex);
|
|
4892
4873
|
if (skipEnd >= 0 && tokenStart >= skipEnd) skipEnd = -1;
|
|
4893
|
-
if (kind ===
|
|
4874
|
+
if (kind === 72 || kind === 71) {
|
|
4894
4875
|
const frame = frameCursor;
|
|
4895
4876
|
frameCursor += 7;
|
|
4896
4877
|
const claim = frameClaim(frames, frame);
|
|
@@ -4901,33 +4882,29 @@ function assignDelimiterScopes(source, tokens, frames, delimiterByKind) {
|
|
|
4901
4882
|
if (claim === 3 || claim === 4 || claim === 5 || claim === 2 && inlineTokenEnd(tokens, frames[frame + 0]) < inlineTokenStart(tokens, frames[frame + 1])) {
|
|
4902
4883
|
workspace[frame + 2] = activeTop;
|
|
4903
4884
|
activeTop = frame;
|
|
4904
|
-
workspace[frame +
|
|
4885
|
+
workspace[frame + 3] = -1;
|
|
4905
4886
|
}
|
|
4906
4887
|
}
|
|
4907
4888
|
if (skipEnd < 0) {
|
|
4908
4889
|
const run = delimiterRunAt(source, tokens, tokenIndex, delimiterByKind);
|
|
4909
4890
|
if (run) {
|
|
4910
4891
|
const runIndex = runs?.length ?? 0;
|
|
4911
|
-
const previous = activeTop < 0 ? rootLastRun : frames[activeTop +
|
|
4892
|
+
const previous = activeTop < 0 ? rootLastRun : frames[activeTop + 3];
|
|
4912
4893
|
if (previous >= 0) {
|
|
4913
4894
|
run.previous = previous;
|
|
4914
4895
|
runs[previous].next = runIndex;
|
|
4915
4896
|
}
|
|
4916
4897
|
if (activeTop < 0) rootLastRun = runIndex;
|
|
4917
|
-
else workspace[activeTop +
|
|
4898
|
+
else workspace[activeTop + 3] = runIndex;
|
|
4918
4899
|
(runs ??= []).push(run);
|
|
4919
4900
|
}
|
|
4920
4901
|
}
|
|
4921
4902
|
}
|
|
4922
4903
|
return runs;
|
|
4923
4904
|
}
|
|
4924
|
-
function hasBracketRewrite(frames) {
|
|
4925
|
-
for (let frame = frameHeaderSize; frame < frames.length; frame += 7) if (frameClaim(frames, frame) !== 0) return true;
|
|
4926
|
-
return false;
|
|
4927
|
-
}
|
|
4928
4905
|
function appendReferenceBoundary(result, tokens, frames, frame, close) {
|
|
4929
4906
|
const token = frames[frame + (close ? 1 : 0)];
|
|
4930
|
-
const kind = (frameClaim(frames, frame) === 5 ?
|
|
4907
|
+
const kind = (frameClaim(frames, frame) === 5 ? 202 : 198) + (isImageFrame(tokens, frames, frame) ? 2 : 0) + (close ? 1 : 0);
|
|
4931
4908
|
const end = close ? frames[frame + 6] : inlineTokenEnd(tokens, token);
|
|
4932
4909
|
appendInlineToken(result, kind, inlineTokenStart(tokens, token), end, inlineTokenData(tokens, token));
|
|
4933
4910
|
return end;
|
|
@@ -4946,35 +4923,34 @@ function emitResolvedTokens(tokens, frames, replacements) {
|
|
|
4946
4923
|
const tokenStart = inlineTokenStart(tokens, tokenIndex);
|
|
4947
4924
|
if (skipEnd >= 0 && tokenStart >= skipEnd) skipEnd = -1;
|
|
4948
4925
|
const skipping = skipEnd >= 0;
|
|
4949
|
-
if (kind ===
|
|
4926
|
+
if (kind === 72 || kind === 71) {
|
|
4950
4927
|
const frame = frameCursor;
|
|
4951
4928
|
frameCursor += 7;
|
|
4952
|
-
workspace[frame + 2] = rawTop;
|
|
4953
4929
|
rawTop = frame;
|
|
4954
4930
|
const claim = frameClaim(frames, frame);
|
|
4955
4931
|
if (!skipping) {
|
|
4956
4932
|
if (claim === 1) {
|
|
4957
4933
|
const closeToken = frames[frame + 1];
|
|
4958
|
-
const start = inlineTokenStart(tokens, tokenIndex) + (kind ===
|
|
4934
|
+
const start = inlineTokenStart(tokens, tokenIndex) + (kind === 71 ? 1 : 0);
|
|
4959
4935
|
skipEnd = inlineTokenEnd(tokens, closeToken);
|
|
4960
|
-
appendInlineToken(result,
|
|
4936
|
+
appendInlineToken(result, 133, start, skipEnd);
|
|
4961
4937
|
} else if (claim === 2) {
|
|
4962
4938
|
const closeToken = frames[frame + 1];
|
|
4963
|
-
if (inlineTokenEnd(tokens, tokenIndex) < inlineTokenStart(tokens, closeToken))
|
|
4964
|
-
} else if (claim === 3) appendInlineToken(result,
|
|
4939
|
+
if (inlineTokenEnd(tokens, tokenIndex) < inlineTokenStart(tokens, closeToken)) rewriteInlineTokenTail(result, 208, inlineTokenEnd(tokens, tokenIndex));
|
|
4940
|
+
} else if (claim === 3) appendInlineToken(result, 206, inlineTokenStart(tokens, tokenIndex), inlineTokenEnd(tokens, tokenIndex));
|
|
4965
4941
|
else if (claim === 4 || claim === 5) {
|
|
4966
4942
|
appendReferenceBoundary(result, tokens, frames, frame, false);
|
|
4967
4943
|
workspace[frame + 3] = referenceTop;
|
|
4968
4944
|
referenceTop = frame;
|
|
4969
4945
|
} else if (claim === 6) skipEnd = inlineTokenEnd(tokens, frames[frame + 1]);
|
|
4970
|
-
else if (!(literalDepth > 0 && kind !==
|
|
4946
|
+
else if (!(literalDepth > 0 && kind !== 71)) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
4971
4947
|
}
|
|
4972
|
-
if (
|
|
4948
|
+
if (frames[frame + 5] & 16) literalDepth++;
|
|
4973
4949
|
continue;
|
|
4974
4950
|
}
|
|
4975
|
-
if (kind ===
|
|
4951
|
+
if (kind === 74 || kind === 73) {
|
|
4976
4952
|
const rawFrame = rawTop;
|
|
4977
|
-
if (rawFrame >= 0) rawTop = frames[rawFrame +
|
|
4953
|
+
if (rawFrame >= 0) rawTop = frames[rawFrame + 4];
|
|
4978
4954
|
const referenceFrame = referenceTop;
|
|
4979
4955
|
const closesReference = referenceFrame >= 0 && frames[referenceFrame + 1] === tokenIndex;
|
|
4980
4956
|
if (!skipping) {
|
|
@@ -4985,8 +4961,8 @@ function emitResolvedTokens(tokens, frames, replacements) {
|
|
|
4985
4961
|
const claim = frameClaim(frames, rawFrame);
|
|
4986
4962
|
if (claim === 2) {
|
|
4987
4963
|
const openToken = frames[rawFrame + 0];
|
|
4988
|
-
if (inlineTokenEnd(tokens, openToken) < tokenStart) appendInlineToken(result,
|
|
4989
|
-
} else if (claim === 3) appendInlineToken(result,
|
|
4964
|
+
if (inlineTokenEnd(tokens, openToken) < tokenStart) appendInlineToken(result, 209, tokenStart, tokenStart + 1);
|
|
4965
|
+
} else if (claim === 3) appendInlineToken(result, 207, tokenStart, tokenStart + 1);
|
|
4990
4966
|
else if (claim === 0 || claim === 4 || claim === 5) {
|
|
4991
4967
|
const image = isImageFrame(tokens, frames, rawFrame);
|
|
4992
4968
|
if (literalDepth === 0 || image) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
@@ -4995,7 +4971,7 @@ function emitResolvedTokens(tokens, frames, replacements) {
|
|
|
4995
4971
|
}
|
|
4996
4972
|
} else appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
4997
4973
|
}
|
|
4998
|
-
if (rawFrame >= 0 &&
|
|
4974
|
+
if (rawFrame >= 0 && frames[rawFrame + 5] & 16) literalDepth--;
|
|
4999
4975
|
continue;
|
|
5000
4976
|
}
|
|
5001
4977
|
if (!skipping) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
@@ -5005,16 +4981,16 @@ function emitResolvedTokens(tokens, frames, replacements) {
|
|
|
5005
4981
|
function compileInlineResolver(options) {
|
|
5006
4982
|
return (delimiterConfigs) => {
|
|
5007
4983
|
const delimiterByKind = compileDelimiterConfigs(delimiterConfigs);
|
|
5008
|
-
return (source, tokens,
|
|
5009
|
-
const frames = analyzeBrackets(source, tokens, delimiterByKind,
|
|
5010
|
-
const
|
|
5011
|
-
if (
|
|
4984
|
+
return (source, tokens, definitions) => {
|
|
4985
|
+
const frames = analyzeBrackets(source, tokens, delimiterByKind, definitions, options);
|
|
4986
|
+
const flags = frames[0];
|
|
4987
|
+
if (flags & 1) resolveReferences(source, tokens, frames, definitions);
|
|
5012
4988
|
let replacements = noDelimiterReplacements;
|
|
5013
|
-
if (
|
|
4989
|
+
if (flags & 2) {
|
|
5014
4990
|
const runs = assignDelimiterScopes(source, tokens, frames, delimiterByKind);
|
|
5015
4991
|
if (runs) replacements = resolveDelimiterMatches(runs);
|
|
5016
4992
|
}
|
|
5017
|
-
return
|
|
4993
|
+
return frames[0] & 4 || replacements.length > 0 ? emitResolvedTokens(tokens, frames, replacements) : tokens;
|
|
5018
4994
|
};
|
|
5019
4995
|
};
|
|
5020
4996
|
}
|