satorigear 0.0.2 → 0.0.3
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 +22 -21
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1057 -1309
- package/package.json +2 -3
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { decodeHTMLStrict } from "entities";
|
|
2
|
-
import { parse } from "yaml";
|
|
3
2
|
//#region src/block/lines.ts
|
|
4
3
|
function firstLineIndexAtOrAfter(lines, offset) {
|
|
5
4
|
let low = 0;
|
|
@@ -318,9 +317,15 @@ var BlockTokenStream = class {
|
|
|
318
317
|
kind(index) {
|
|
319
318
|
return this.#fields[index * blockTokenStride];
|
|
320
319
|
}
|
|
320
|
+
setKind(index, kind) {
|
|
321
|
+
this.#fields[index * blockTokenStride] = kind;
|
|
322
|
+
}
|
|
321
323
|
start(index) {
|
|
322
324
|
return this.#position(this.#fields[index * blockTokenStride + 1]);
|
|
323
325
|
}
|
|
326
|
+
setStart(index, start) {
|
|
327
|
+
this.#fields[index * blockTokenStride + 1] = start;
|
|
328
|
+
}
|
|
324
329
|
end(index) {
|
|
325
330
|
return this.#position(this.#fields[index * blockTokenStride + 2]);
|
|
326
331
|
}
|
|
@@ -722,8 +727,8 @@ var BlockStructure = class {
|
|
|
722
727
|
isBlock(tokenStart) {
|
|
723
728
|
return this.ruleOf(tokenStart).block;
|
|
724
729
|
}
|
|
725
|
-
|
|
726
|
-
return this.ruleOf(tokenStart).
|
|
730
|
+
isRule(tokenStart, rule) {
|
|
731
|
+
return this.ruleOf(tokenStart).rule === rule;
|
|
727
732
|
}
|
|
728
733
|
ruleOf(tokenStart) {
|
|
729
734
|
const kind = this.#tokens.kind(tokenStart);
|
|
@@ -732,24 +737,228 @@ var BlockStructure = class {
|
|
|
732
737
|
return rule;
|
|
733
738
|
}
|
|
734
739
|
};
|
|
740
|
+
function inlineTokenCount(tokens) {
|
|
741
|
+
return tokens.length / 4;
|
|
742
|
+
}
|
|
743
|
+
function inlineTokenKind(tokens, index) {
|
|
744
|
+
return tokens[index * 4];
|
|
745
|
+
}
|
|
746
|
+
function inlineTokenStart(tokens, index) {
|
|
747
|
+
return tokens[index * 4 + 1];
|
|
748
|
+
}
|
|
749
|
+
function inlineTokenEnd(tokens, index) {
|
|
750
|
+
return tokens[index * 4 + 2];
|
|
751
|
+
}
|
|
752
|
+
function inlineTokenFlags(tokens, index) {
|
|
753
|
+
return tokens[index * 4 + 3];
|
|
754
|
+
}
|
|
755
|
+
function setInlineTokenFlags(tokens, index, flags) {
|
|
756
|
+
tokens[index * 4 + 3] = flags;
|
|
757
|
+
}
|
|
758
|
+
function inlineTokenText(source, tokens, index) {
|
|
759
|
+
return source.slice(inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index));
|
|
760
|
+
}
|
|
761
|
+
function appendInlineToken(target, kind, start, end, flags = 0) {
|
|
762
|
+
target.push(kind, start, end, flags);
|
|
763
|
+
}
|
|
764
|
+
function copyInlineToken(target, tokens, index) {
|
|
765
|
+
const offset = index * 4;
|
|
766
|
+
for (let field = 0; field < 4; field++) target.push(tokens[offset + field]);
|
|
767
|
+
}
|
|
768
|
+
function firstInlineTokenEndingAfter(tokens, offset) {
|
|
769
|
+
let low = 0;
|
|
770
|
+
let high = inlineTokenCount(tokens);
|
|
771
|
+
while (low < high) {
|
|
772
|
+
const middle = low + high >>> 1;
|
|
773
|
+
if (inlineTokenEnd(tokens, middle) <= offset) low = middle + 1;
|
|
774
|
+
else high = middle;
|
|
775
|
+
}
|
|
776
|
+
return low;
|
|
777
|
+
}
|
|
778
|
+
//#endregion
|
|
779
|
+
//#region src/fragment/node.ts
|
|
780
|
+
function extendSpan(value, end) {
|
|
781
|
+
const node = value;
|
|
782
|
+
node.position.end = Math.max(node.position.end, end);
|
|
783
|
+
}
|
|
784
|
+
function firstChildStart(children) {
|
|
785
|
+
const first = children[0];
|
|
786
|
+
if (!first) throw new Error("mdast container unexpectedly has no children");
|
|
787
|
+
return first.position.start;
|
|
788
|
+
}
|
|
789
|
+
function lastChildEnd(children, emptyEnd) {
|
|
790
|
+
const last = children.at(-1);
|
|
791
|
+
return last ? last.position.end : emptyEnd;
|
|
792
|
+
}
|
|
793
|
+
//#endregion
|
|
794
|
+
//#region src/fragment/inline.ts
|
|
795
|
+
function lineStart(source, offset) {
|
|
796
|
+
while (offset > 0) {
|
|
797
|
+
const character = source.charCodeAt(--offset);
|
|
798
|
+
if (character === 10 || character === 13) return offset + 1;
|
|
799
|
+
}
|
|
800
|
+
return 0;
|
|
801
|
+
}
|
|
802
|
+
function lineEndingStart(source, offset) {
|
|
803
|
+
const start = lineStart(source, offset);
|
|
804
|
+
if (start === 0) return offset;
|
|
805
|
+
return source[start - 1] === "\n" && source[start - 2] === "\r" ? start - 2 : start - 1;
|
|
806
|
+
}
|
|
807
|
+
function appendText(target, value, start, end) {
|
|
808
|
+
if (!value) return;
|
|
809
|
+
const previous = target.at(-1);
|
|
810
|
+
if (previous?.type === "text" && !("attributes" in previous)) {
|
|
811
|
+
previous.value += value;
|
|
812
|
+
extendSpan(previous, end);
|
|
813
|
+
} else target.push({
|
|
814
|
+
type: "text",
|
|
815
|
+
value,
|
|
816
|
+
position: {
|
|
817
|
+
start,
|
|
818
|
+
end
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
function appendPhrasing(target, value) {
|
|
823
|
+
if (value.type === "text") appendText(target, value.value, value.position.start, value.position.end);
|
|
824
|
+
else target.push(value);
|
|
825
|
+
}
|
|
826
|
+
function appendInlineGap(output, context, start, end) {
|
|
827
|
+
output.gapStart = -1;
|
|
828
|
+
output.gapEnd = -1;
|
|
829
|
+
const gapSpan = context.view.mapSpan(start, end);
|
|
830
|
+
appendText(output.children, context.decodeText(context.view.text.slice(start, end).replace(/[\r\n]/g, "")), gapSpan.start, gapSpan.end);
|
|
831
|
+
}
|
|
832
|
+
function appendInline(output, context, value) {
|
|
833
|
+
const target = output.children;
|
|
834
|
+
const nextLineOffset = value.position.start;
|
|
835
|
+
const newline = value.type === "text" && value.value.startsWith("\n");
|
|
836
|
+
if (output.gapStart >= 0) {
|
|
837
|
+
if (!newline) appendInlineGap(output, context, output.gapStart, output.gapEnd);
|
|
838
|
+
else {
|
|
839
|
+
output.gapStart = -1;
|
|
840
|
+
output.gapEnd = -1;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (newline) {
|
|
844
|
+
const previous = target.at(-1);
|
|
845
|
+
if (previous?.type === "break") {
|
|
846
|
+
extendSpan(previous, lineStart(context.source, nextLineOffset));
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
value.position.start = lineEndingStart(context.source, nextLineOffset);
|
|
850
|
+
if (previous?.type === "text") previous.value = previous.value.slice(0, trailingWhitespaceStart(previous.value));
|
|
851
|
+
}
|
|
852
|
+
appendPhrasing(target, value);
|
|
853
|
+
}
|
|
854
|
+
function appendInlineLeaf(tokenIndex, sourceSpan, output, context) {
|
|
855
|
+
const kind = inlineTokenKind(context.tokens, tokenIndex);
|
|
856
|
+
const handle = context.tokenHandlers[kind];
|
|
857
|
+
if (!handle) throw new Error(`Unexpected inline token kind ${kind}`);
|
|
858
|
+
const value = handle(tokenIndex, sourceSpan, context, output);
|
|
859
|
+
if (typeof value === "boolean") return value;
|
|
860
|
+
if (!value) return false;
|
|
861
|
+
appendInline(output, context, value);
|
|
862
|
+
return true;
|
|
863
|
+
}
|
|
864
|
+
function trailingWhitespaceStart(value) {
|
|
865
|
+
let offset = value.length;
|
|
866
|
+
while (offset > 0 && (value[offset - 1] === " " || value[offset - 1] === " ")) offset--;
|
|
867
|
+
return offset;
|
|
868
|
+
}
|
|
869
|
+
function appendInlineRange(startToken, endToken, context, output, closeKind) {
|
|
870
|
+
let index = startToken;
|
|
871
|
+
while (index < endToken) {
|
|
872
|
+
if (inlineTokenKind(context.tokens, index) === closeKind) break;
|
|
873
|
+
const childOffset = inlineTokenStart(context.tokens, index);
|
|
874
|
+
if (output.cursor !== void 0 && childOffset > output.cursor) {
|
|
875
|
+
output.gapStart = output.cursor;
|
|
876
|
+
output.gapEnd = childOffset;
|
|
877
|
+
}
|
|
878
|
+
const next = buildInlineSemantic(index, endToken, output, context);
|
|
879
|
+
const childEnd = inlineTokenEnd(context.tokens, next === void 0 ? index : next - 1);
|
|
880
|
+
const childEmitted = next === void 0 ? appendInlineLeaf(index, context.view.mapSpan(childOffset, childEnd), output, context) : true;
|
|
881
|
+
index = next ?? index + 1;
|
|
882
|
+
if (!childEmitted) continue;
|
|
883
|
+
output.cursor = childEnd;
|
|
884
|
+
}
|
|
885
|
+
if (closeKind !== void 0 && index < endToken && output.cursor !== void 0) {
|
|
886
|
+
const contentEnd = inlineTokenStart(context.tokens, index);
|
|
887
|
+
if (contentEnd > output.cursor) appendInlineGap(output, context, output.cursor, contentEnd);
|
|
888
|
+
}
|
|
889
|
+
return index;
|
|
890
|
+
}
|
|
891
|
+
function buildInlineSemantic(openToken, endToken, output, context) {
|
|
892
|
+
const kind = inlineTokenKind(context.tokens, openToken);
|
|
893
|
+
const container = context.schema.containerByKind[kind];
|
|
894
|
+
if (container) {
|
|
895
|
+
let closeToken = openToken;
|
|
896
|
+
let next = openToken + 1;
|
|
897
|
+
const children = [];
|
|
898
|
+
if (next < endToken && inlineTokenKind(context.tokens, next) === container.contentOpenKind) {
|
|
899
|
+
const childOutput = {
|
|
900
|
+
children,
|
|
901
|
+
cursor: inlineTokenEnd(context.tokens, next++),
|
|
902
|
+
gapEnd: -1,
|
|
903
|
+
gapStart: -1
|
|
904
|
+
};
|
|
905
|
+
closeToken = appendInlineRange(next, endToken, context, childOutput, container.closeKind);
|
|
906
|
+
if (closeToken >= endToken || inlineTokenKind(context.tokens, closeToken) !== container.closeKind) throw new Error(`Resolved inline stream did not close token kind ${kind}`);
|
|
907
|
+
next = closeToken + 1;
|
|
908
|
+
}
|
|
909
|
+
appendInline(output, context, container.build(openToken, closeToken, context.view.mapSpan(inlineTokenStart(context.tokens, openToken), inlineTokenEnd(context.tokens, closeToken)), children, context));
|
|
910
|
+
return next;
|
|
911
|
+
}
|
|
912
|
+
const pair = context.schema.pairByOpenKind[kind];
|
|
913
|
+
if (!pair) return;
|
|
914
|
+
const contentStart = inlineTokenEnd(context.tokens, openToken);
|
|
915
|
+
const children = [];
|
|
916
|
+
const childOutput = {
|
|
917
|
+
children,
|
|
918
|
+
cursor: contentStart,
|
|
919
|
+
gapEnd: -1,
|
|
920
|
+
gapStart: -1
|
|
921
|
+
};
|
|
922
|
+
const closeToken = appendInlineRange(openToken + 1, endToken, context, childOutput, pair.closeKind);
|
|
923
|
+
if (closeToken >= endToken || inlineTokenKind(context.tokens, closeToken) !== pair.closeKind) throw new Error(`Resolved inline stream did not close token kind ${kind}`);
|
|
924
|
+
appendInline(output, context, pair.build(openToken, closeToken, context.view.mapSpan(inlineTokenStart(context.tokens, openToken), inlineTokenEnd(context.tokens, closeToken)), children, context));
|
|
925
|
+
return closeToken + 1;
|
|
926
|
+
}
|
|
927
|
+
function buildInlineFragment(tokenStart, context) {
|
|
928
|
+
const region = context.cursor.take(tokenStart);
|
|
929
|
+
if (!region) return { children: [] };
|
|
930
|
+
const inlineContext = {
|
|
931
|
+
blockRule: region.rule,
|
|
932
|
+
decodeText: context.profile.decodeText,
|
|
933
|
+
schema: context.profile.schema,
|
|
934
|
+
source: context.source,
|
|
935
|
+
tokenHandlers: context.profile.tokenHandlers,
|
|
936
|
+
tokens: region.tokens,
|
|
937
|
+
view: region.view
|
|
938
|
+
};
|
|
939
|
+
const result = {
|
|
940
|
+
children: [],
|
|
941
|
+
cursor: void 0,
|
|
942
|
+
gapEnd: -1,
|
|
943
|
+
gapStart: -1
|
|
944
|
+
};
|
|
945
|
+
appendInlineRange(0, inlineTokenCount(region.tokens), inlineContext, result);
|
|
946
|
+
const last = result.children.at(-1);
|
|
947
|
+
if (last?.type === "text") {
|
|
948
|
+
const end = trailingWhitespaceStart(last.value);
|
|
949
|
+
const removed = last.value.length - end;
|
|
950
|
+
last.value = last.value.slice(0, end);
|
|
951
|
+
last.position.end -= removed;
|
|
952
|
+
if (!last.value) result.children.pop();
|
|
953
|
+
}
|
|
954
|
+
return result;
|
|
955
|
+
}
|
|
735
956
|
//#endregion
|
|
736
957
|
//#region src/fragment/block.ts
|
|
737
958
|
function blockEnd(tokenStart, context) {
|
|
738
959
|
const offset = context.structure.tokens.start(tokenStart);
|
|
739
960
|
return lineContentEnd(context.source, offset, offset + context.structure.lenOf(tokenStart));
|
|
740
961
|
}
|
|
741
|
-
function directBlockToken(tokenStart, kind, context) {
|
|
742
|
-
const structure = context.structure;
|
|
743
|
-
for (let entry = structure.firstChild(tokenStart); entry !== noBlockEntry; entry = structure.nextChild(tokenStart, entry)) if (entry < 0) {
|
|
744
|
-
const token = structure.leafToken(entry);
|
|
745
|
-
if (structure.tokens.kind(token) === kind) return token;
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
function blockToken(tokenStart, kind, context) {
|
|
749
|
-
const token = directBlockToken(tokenStart, kind, context);
|
|
750
|
-
if (token === void 0) throw new Error(`Expected ${context.structure.ruleNameOf(tokenStart)} syntax to contain block token ${kind}`);
|
|
751
|
-
return token;
|
|
752
|
-
}
|
|
753
962
|
function payloadBounds(tokenStart, context) {
|
|
754
963
|
const structure = context.structure;
|
|
755
964
|
const offset = structure.tokens.start(tokenStart);
|
|
@@ -771,8 +980,8 @@ function payloadBounds(tokenStart, context) {
|
|
|
771
980
|
const buildBlockNode = (tokenStart, context) => {
|
|
772
981
|
const rule = context.structure.ruleOf(tokenStart);
|
|
773
982
|
const build = rule.build;
|
|
774
|
-
if (!build) throw new Error(`Unexpected block syntax
|
|
775
|
-
return build(tokenStart, context);
|
|
983
|
+
if (!build) throw new Error(`Unexpected block syntax at token ${tokenStart}`);
|
|
984
|
+
return rule.inlineContent ? build(tokenStart, context, buildInlineFragment(tokenStart, context)) : build(tokenStart, context);
|
|
776
985
|
};
|
|
777
986
|
const buildBlockChildren = (tokenStart, context) => {
|
|
778
987
|
const structure = context.structure;
|
|
@@ -942,34 +1151,34 @@ var ContiguousSourceView = class {
|
|
|
942
1151
|
var SegmentedSourceView = class {
|
|
943
1152
|
#segments;
|
|
944
1153
|
text;
|
|
945
|
-
constructor(source,
|
|
946
|
-
const segments = [];
|
|
1154
|
+
constructor(source, ranges) {
|
|
947
1155
|
const parts = [];
|
|
948
1156
|
let viewOffset = 0;
|
|
949
1157
|
let previousEnd = 0;
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
previousEnd =
|
|
964
|
-
}
|
|
965
|
-
|
|
1158
|
+
let segmentCount = 0;
|
|
1159
|
+
for (let read = 0; read < ranges.length; read += 2) {
|
|
1160
|
+
const start = ranges[read];
|
|
1161
|
+
const end = ranges[read + 1];
|
|
1162
|
+
validateSourceSpan(start, end, source.length);
|
|
1163
|
+
if (segmentCount > 0 && start < previousEnd) throw new RangeError(`Source spans must be ordered and non-overlapping: ${start} < ${previousEnd}`);
|
|
1164
|
+
if (start === end) continue;
|
|
1165
|
+
const write = segmentCount * 2;
|
|
1166
|
+
ranges[write] = start - viewOffset;
|
|
1167
|
+
viewOffset += end - start;
|
|
1168
|
+
parts.push(source.slice(start, end));
|
|
1169
|
+
ranges[write + 1] = viewOffset;
|
|
1170
|
+
segmentCount++;
|
|
1171
|
+
previousEnd = end;
|
|
1172
|
+
}
|
|
1173
|
+
ranges.length = segmentCount * 2;
|
|
1174
|
+
this.#segments = ranges;
|
|
966
1175
|
this.text = parts.join("");
|
|
967
1176
|
}
|
|
968
1177
|
mapPoint(offset) {
|
|
969
1178
|
if (this.#segments.length === 0) return 0;
|
|
970
|
-
if (offset === this.text.length) return this.#segments[this.#segments.length -
|
|
1179
|
+
if (offset === this.text.length) return this.#segments[this.#segments.length - 2] + offset;
|
|
971
1180
|
const segment = this.#containingSegment(offset);
|
|
972
|
-
return segment
|
|
1181
|
+
return this.#segments[segment] + offset;
|
|
973
1182
|
}
|
|
974
1183
|
mapSpan(start, end) {
|
|
975
1184
|
if (this.#segments.length === 0) return {
|
|
@@ -986,25 +1195,22 @@ var SegmentedSourceView = class {
|
|
|
986
1195
|
const first = this.#containingSegment(start);
|
|
987
1196
|
const last = this.#containingSegment(end - 1);
|
|
988
1197
|
return {
|
|
989
|
-
start: first
|
|
990
|
-
end: last
|
|
1198
|
+
start: this.#segments[first] + start,
|
|
1199
|
+
end: this.#segments[last] + end
|
|
991
1200
|
};
|
|
992
1201
|
}
|
|
993
1202
|
shift(delta) {
|
|
994
|
-
for (
|
|
995
|
-
segment.start += delta;
|
|
996
|
-
segment.end += delta;
|
|
997
|
-
}
|
|
1203
|
+
for (let index = 0; index < this.#segments.length; index += 2) this.#segments[index] += delta;
|
|
998
1204
|
}
|
|
999
1205
|
#containingSegment(offset) {
|
|
1000
1206
|
let low = 0;
|
|
1001
|
-
let high = this.#segments.length;
|
|
1207
|
+
let high = this.#segments.length >>> 1;
|
|
1002
1208
|
while (low < high) {
|
|
1003
1209
|
const middle = low + high >>> 1;
|
|
1004
|
-
if (offset < this.#segments[middle]
|
|
1210
|
+
if (offset < this.#segments[middle * 2 + 1]) high = middle;
|
|
1005
1211
|
else low = middle + 1;
|
|
1006
1212
|
}
|
|
1007
|
-
return
|
|
1213
|
+
return low * 2;
|
|
1008
1214
|
}
|
|
1009
1215
|
};
|
|
1010
1216
|
function validateSourceSpan(start, end, sourceLength) {
|
|
@@ -1029,6 +1235,7 @@ var SyntaxState = class {
|
|
|
1029
1235
|
}
|
|
1030
1236
|
update(source, change, stableBlockCount = 0) {
|
|
1031
1237
|
const structure = this.#structure;
|
|
1238
|
+
const tokens = structure.tokens;
|
|
1032
1239
|
const previousBlocks = this.#blocks;
|
|
1033
1240
|
const oldStart = change?.oldStart ?? 0;
|
|
1034
1241
|
const oldEnd = change?.oldEnd ?? 0;
|
|
@@ -1044,36 +1251,34 @@ var SyntaxState = class {
|
|
|
1044
1251
|
definitions.add(entry.key);
|
|
1045
1252
|
}
|
|
1046
1253
|
const bindings = [];
|
|
1047
|
-
const collectNode = (tokenStart, offset, tokenBase, blockIndex) => {
|
|
1048
|
-
const rule = structure.ruleOf(tokenStart);
|
|
1049
|
-
const definitionKey = rule.definitionKey;
|
|
1050
|
-
if (definitionKey) {
|
|
1051
|
-
const key = definitionKey(structure.tokens, tokenBase);
|
|
1052
|
-
(definitionEntries ??= []).push({
|
|
1053
|
-
blockIndex,
|
|
1054
|
-
key
|
|
1055
|
-
});
|
|
1056
|
-
definitions.add(key);
|
|
1057
|
-
}
|
|
1058
|
-
if (rule.inlineContent) {
|
|
1059
|
-
const inlineView = inlineViewOf(source, structure, tokenStart);
|
|
1060
|
-
if (inlineView) bindings.push({
|
|
1061
|
-
offset,
|
|
1062
|
-
rule: rule.name,
|
|
1063
|
-
tokenStart,
|
|
1064
|
-
view: inlineView
|
|
1065
|
-
});
|
|
1066
|
-
return;
|
|
1067
|
-
}
|
|
1068
|
-
for (let child = structure.firstChild(tokenStart); child !== noBlockEntry; child = structure.nextChild(tokenStart, child)) if (child >= 0) collectNode(child, structure.tokens.start(child), child, blockIndex);
|
|
1069
|
-
};
|
|
1070
1254
|
const bindingOffsets = [];
|
|
1071
1255
|
for (let index = stableBlockCount; index < newEnd; index++) {
|
|
1072
1256
|
const record = structure.records[index];
|
|
1073
|
-
const tokenBase = record.tokenStart;
|
|
1074
|
-
const offset = structure.tokens.start(tokenBase);
|
|
1075
1257
|
bindingOffsets.push(bindings.length);
|
|
1076
|
-
|
|
1258
|
+
for (let token = record.tokenStart; token < record.tokenEnd; token++) {
|
|
1259
|
+
const nodeLength = tokens.nodeLength(token);
|
|
1260
|
+
if (nodeLength === 0) continue;
|
|
1261
|
+
const rule = structure.ruleOf(token);
|
|
1262
|
+
const definitionKey = rule.definitionKey;
|
|
1263
|
+
if (definitionKey) {
|
|
1264
|
+
const key = definitionKey(tokens, token);
|
|
1265
|
+
(definitionEntries ??= []).push({
|
|
1266
|
+
blockIndex: index,
|
|
1267
|
+
key
|
|
1268
|
+
});
|
|
1269
|
+
definitions.add(key);
|
|
1270
|
+
}
|
|
1271
|
+
if (rule.inlineContent) {
|
|
1272
|
+
const inlineView = inlineViewOf(source, tokens, token, nodeLength);
|
|
1273
|
+
if (inlineView) bindings.push({
|
|
1274
|
+
offset: tokens.start(token),
|
|
1275
|
+
rule: rule.rule,
|
|
1276
|
+
tokenStart: token,
|
|
1277
|
+
view: inlineView
|
|
1278
|
+
});
|
|
1279
|
+
token += nodeLength - 1;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1077
1282
|
blocks.push({
|
|
1078
1283
|
record,
|
|
1079
1284
|
regions: emptyArray,
|
|
@@ -1163,22 +1368,23 @@ var SyntaxState = class {
|
|
|
1163
1368
|
function resolveInlineRegions(source, profile, structure) {
|
|
1164
1369
|
const definitions = /* @__PURE__ */ new Set();
|
|
1165
1370
|
const regions = [];
|
|
1166
|
-
const
|
|
1167
|
-
|
|
1168
|
-
|
|
1371
|
+
const tokens = structure.tokens;
|
|
1372
|
+
for (const record of structure.records) for (let token = record.tokenStart; token < record.tokenEnd; token++) {
|
|
1373
|
+
const nodeLength = tokens.nodeLength(token);
|
|
1374
|
+
if (nodeLength === 0) continue;
|
|
1375
|
+
const rule = structure.ruleOf(token);
|
|
1376
|
+
if (rule.definitionKey) definitions.add(rule.definitionKey(tokens, token));
|
|
1169
1377
|
if (rule.inlineContent) {
|
|
1170
|
-
const inlineView = inlineViewOf(source,
|
|
1378
|
+
const inlineView = inlineViewOf(source, tokens, token, nodeLength);
|
|
1171
1379
|
if (inlineView) regions.push({
|
|
1172
|
-
rule: rule.
|
|
1173
|
-
tokenStart,
|
|
1380
|
+
rule: rule.rule,
|
|
1381
|
+
tokenStart: token,
|
|
1174
1382
|
tokens: emptyArray,
|
|
1175
1383
|
view: inlineView
|
|
1176
1384
|
});
|
|
1177
|
-
|
|
1385
|
+
token += nodeLength - 1;
|
|
1178
1386
|
}
|
|
1179
|
-
|
|
1180
|
-
};
|
|
1181
|
-
for (const record of structure.records) collect(record.tokenStart, record.tokenStart);
|
|
1387
|
+
}
|
|
1182
1388
|
const context = { hasDefinition: (key) => definitions.has(key) };
|
|
1183
1389
|
for (const region of regions) {
|
|
1184
1390
|
const text = region.view.text;
|
|
@@ -1186,31 +1392,23 @@ function resolveInlineRegions(source, profile, structure) {
|
|
|
1186
1392
|
}
|
|
1187
1393
|
return regions;
|
|
1188
1394
|
}
|
|
1189
|
-
function inlineViewOf(source,
|
|
1395
|
+
function inlineViewOf(source, tokens, tokenStart, nodeLength) {
|
|
1190
1396
|
let firstStart = -1;
|
|
1191
1397
|
let firstEnd = -1;
|
|
1192
|
-
let
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
start: firstStart,
|
|
1204
|
-
end: firstEnd
|
|
1205
|
-
}];
|
|
1206
|
-
spans.push({
|
|
1207
|
-
start,
|
|
1208
|
-
end
|
|
1209
|
-
});
|
|
1210
|
-
}
|
|
1398
|
+
let ranges;
|
|
1399
|
+
const tokenEnd = tokenStart + nodeLength;
|
|
1400
|
+
for (let token = tokenStart + 1; token < tokenEnd; token++) if (tokens.kind(token) === 1) {
|
|
1401
|
+
const start = tokens.start(token);
|
|
1402
|
+
const end = tokens.end(token);
|
|
1403
|
+
if (firstStart < 0) {
|
|
1404
|
+
firstStart = start;
|
|
1405
|
+
firstEnd = end;
|
|
1406
|
+
} else {
|
|
1407
|
+
ranges ??= [firstStart, firstEnd];
|
|
1408
|
+
ranges.push(start, end);
|
|
1211
1409
|
}
|
|
1212
1410
|
}
|
|
1213
|
-
if (
|
|
1411
|
+
if (ranges) return new SegmentedSourceView(source, ranges);
|
|
1214
1412
|
if (firstStart >= 0) return new ContiguousSourceView(source, firstStart, firstEnd);
|
|
1215
1413
|
}
|
|
1216
1414
|
//#endregion
|
|
@@ -1285,7 +1483,7 @@ var DocumentImpl = class {
|
|
|
1285
1483
|
for (const block of changedBlocks) for (const region of block.regions) regions.push(region);
|
|
1286
1484
|
const context = {
|
|
1287
1485
|
structure: this.#blockStructure,
|
|
1288
|
-
|
|
1486
|
+
cursor: new InlineRegionCursor(regions),
|
|
1289
1487
|
profile: this.#profile.inline,
|
|
1290
1488
|
source: this.source
|
|
1291
1489
|
};
|
|
@@ -1310,7 +1508,7 @@ var DocumentImpl = class {
|
|
|
1310
1508
|
blockStructure.build();
|
|
1311
1509
|
const context = {
|
|
1312
1510
|
structure: blockStructure,
|
|
1313
|
-
|
|
1511
|
+
cursor: new InlineRegionCursor(resolveInlineRegions(source, profile.inline, blockStructure)),
|
|
1314
1512
|
profile: profile.inline,
|
|
1315
1513
|
source
|
|
1316
1514
|
};
|
|
@@ -1326,7 +1524,7 @@ function compileBlockProfile(features) {
|
|
|
1326
1524
|
const groupedRuleByToken = [];
|
|
1327
1525
|
const interrupts = [];
|
|
1328
1526
|
const ruleByLeaf = [];
|
|
1329
|
-
const rules =
|
|
1527
|
+
const rules = [];
|
|
1330
1528
|
const restarts = [];
|
|
1331
1529
|
const starts = [];
|
|
1332
1530
|
const lazyContinuationUnwrappers = [];
|
|
@@ -1347,7 +1545,7 @@ function compileBlockProfile(features) {
|
|
|
1347
1545
|
block: syntax.kind === "block" || syntax.kind === "leaf",
|
|
1348
1546
|
definitionKey: registration.definitionKey,
|
|
1349
1547
|
inlineContent: registration.inlineContent === true,
|
|
1350
|
-
|
|
1548
|
+
rule: registration.rule,
|
|
1351
1549
|
build: registration.build
|
|
1352
1550
|
};
|
|
1353
1551
|
rules[registration.rule] = rule;
|
|
@@ -1388,157 +1586,7 @@ function compileBlockProfile(features) {
|
|
|
1388
1586
|
};
|
|
1389
1587
|
}
|
|
1390
1588
|
//#endregion
|
|
1391
|
-
//#region src/inline/
|
|
1392
|
-
function matchInlinePatternEnd(pattern, source, start) {
|
|
1393
|
-
pattern.lastIndex = start;
|
|
1394
|
-
const match = pattern.exec(source);
|
|
1395
|
-
return match === null ? -1 : start + match[0].length;
|
|
1396
|
-
}
|
|
1397
|
-
function inlineMarkerRunEnd(source, start) {
|
|
1398
|
-
const marker = source.charCodeAt(start);
|
|
1399
|
-
let end = start + 1;
|
|
1400
|
-
while (source.charCodeAt(end) === marker) end++;
|
|
1401
|
-
return end;
|
|
1402
|
-
}
|
|
1403
|
-
function inlineTextEnd(source, start, boundary) {
|
|
1404
|
-
boundary.lastIndex = start;
|
|
1405
|
-
let match = boundary.exec(source);
|
|
1406
|
-
while (match !== null && source.charCodeAt(match.index) === 92) {
|
|
1407
|
-
const next = source.charCodeAt(match.index + 1);
|
|
1408
|
-
if (next !== 32 && next !== 9) break;
|
|
1409
|
-
boundary.lastIndex = match.index + 2;
|
|
1410
|
-
match = boundary.exec(source);
|
|
1411
|
-
}
|
|
1412
|
-
return match?.index ?? source.length;
|
|
1413
|
-
}
|
|
1414
|
-
function tokenize(source, textBoundary, lexicalByCode) {
|
|
1415
|
-
const tokens = [];
|
|
1416
|
-
let offset = 0;
|
|
1417
|
-
let lineStart = true;
|
|
1418
|
-
while (offset < source.length) {
|
|
1419
|
-
if (lineStart) {
|
|
1420
|
-
let content = offset;
|
|
1421
|
-
while (source.charCodeAt(content) === 32) content++;
|
|
1422
|
-
if (content === source.length) break;
|
|
1423
|
-
let code = source.charCodeAt(content);
|
|
1424
|
-
if (code === 10 || code === 13) {
|
|
1425
|
-
offset = content + 1;
|
|
1426
|
-
if (code === 13 && source.charCodeAt(offset) === 10) offset++;
|
|
1427
|
-
continue;
|
|
1428
|
-
}
|
|
1429
|
-
if (code === 9) {
|
|
1430
|
-
let blankEnd = content;
|
|
1431
|
-
while (source.charCodeAt(blankEnd) === 9 || source.charCodeAt(blankEnd) === 32) blankEnd++;
|
|
1432
|
-
code = source.charCodeAt(blankEnd);
|
|
1433
|
-
if (blankEnd === source.length || code === 10 || code === 13) {
|
|
1434
|
-
offset = blankEnd + (blankEnd < source.length ? 1 : 0);
|
|
1435
|
-
if (code === 13 && source.charCodeAt(offset) === 10) offset++;
|
|
1436
|
-
continue;
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
offset = content;
|
|
1440
|
-
if (tokens.length > 0) tokens.push(42, offset, offset, 0);
|
|
1441
|
-
lineStart = false;
|
|
1442
|
-
continue;
|
|
1443
|
-
}
|
|
1444
|
-
const code = source.charCodeAt(offset);
|
|
1445
|
-
if (code === 32 || code === 9) {
|
|
1446
|
-
if (code === 32) {
|
|
1447
|
-
const end = inlineMarkerRunEnd(source, offset);
|
|
1448
|
-
const next = source.charCodeAt(end);
|
|
1449
|
-
if (end - offset >= 2 && (next === 10 || next === 13)) {
|
|
1450
|
-
tokens.push(7, offset, end, 0);
|
|
1451
|
-
offset = end;
|
|
1452
|
-
continue;
|
|
1453
|
-
}
|
|
1454
|
-
if (end > offset + 1) {
|
|
1455
|
-
offset = end;
|
|
1456
|
-
continue;
|
|
1457
|
-
}
|
|
1458
|
-
}
|
|
1459
|
-
offset++;
|
|
1460
|
-
continue;
|
|
1461
|
-
}
|
|
1462
|
-
if (code === 10 || code === 13) {
|
|
1463
|
-
offset++;
|
|
1464
|
-
if (code === 13 && source.charCodeAt(offset) === 10) offset++;
|
|
1465
|
-
lineStart = true;
|
|
1466
|
-
continue;
|
|
1467
|
-
}
|
|
1468
|
-
const scan = lexicalByCode[code];
|
|
1469
|
-
if (scan) {
|
|
1470
|
-
const lexicalEnd = scan(source, offset, tokens);
|
|
1471
|
-
if (lexicalEnd > offset) {
|
|
1472
|
-
offset = lexicalEnd;
|
|
1473
|
-
continue;
|
|
1474
|
-
}
|
|
1475
|
-
const end = inlineTextEnd(source, offset + 1, textBoundary);
|
|
1476
|
-
tokens.push(9, offset, end, 0);
|
|
1477
|
-
offset = end;
|
|
1478
|
-
continue;
|
|
1479
|
-
}
|
|
1480
|
-
const end = inlineTextEnd(source, offset, textBoundary);
|
|
1481
|
-
tokens.push(9, offset, end, 0);
|
|
1482
|
-
offset = end;
|
|
1483
|
-
}
|
|
1484
|
-
return tokens;
|
|
1485
|
-
}
|
|
1486
|
-
function compileInlineTokenizer(rules) {
|
|
1487
|
-
const lexicalByCode = [];
|
|
1488
|
-
const boundaryCodes = [];
|
|
1489
|
-
for (const rule of rules) {
|
|
1490
|
-
const code = rule.marker;
|
|
1491
|
-
const previous = lexicalByCode[code];
|
|
1492
|
-
lexicalByCode[code] = previous === void 0 ? rule.scan : (source, start, tokens) => {
|
|
1493
|
-
const end = previous(source, start, tokens);
|
|
1494
|
-
return end > start ? end : rule.scan(source, start, tokens);
|
|
1495
|
-
};
|
|
1496
|
-
if (previous === void 0) boundaryCodes.push(code);
|
|
1497
|
-
}
|
|
1498
|
-
const boundaries = String.fromCharCode(...boundaryCodes).replaceAll(/[\\\]-]/g, "\\$&");
|
|
1499
|
-
const textBoundary = new RegExp(` {2,}(?=[\\n\\r]|$)|[\\n\\r${boundaries}]`, "g");
|
|
1500
|
-
return (source) => tokenize(source, textBoundary, lexicalByCode);
|
|
1501
|
-
}
|
|
1502
|
-
function inlineTokenCount(tokens) {
|
|
1503
|
-
return tokens.length / 4;
|
|
1504
|
-
}
|
|
1505
|
-
function inlineTokenKind(tokens, index) {
|
|
1506
|
-
return tokens[index * 4];
|
|
1507
|
-
}
|
|
1508
|
-
function inlineTokenStart(tokens, index) {
|
|
1509
|
-
return tokens[index * 4 + 1];
|
|
1510
|
-
}
|
|
1511
|
-
function inlineTokenEnd(tokens, index) {
|
|
1512
|
-
return tokens[index * 4 + 2];
|
|
1513
|
-
}
|
|
1514
|
-
function inlineTokenFlags(tokens, index) {
|
|
1515
|
-
return tokens[index * 4 + 3];
|
|
1516
|
-
}
|
|
1517
|
-
function setInlineTokenFlags(tokens, index, flags) {
|
|
1518
|
-
tokens[index * 4 + 3] = flags;
|
|
1519
|
-
}
|
|
1520
|
-
function inlineTokenText(source, tokens, index) {
|
|
1521
|
-
return source.slice(inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index));
|
|
1522
|
-
}
|
|
1523
|
-
function appendInlineToken(target, kind, start, end, flags = 0) {
|
|
1524
|
-
target.push(kind, start, end, flags);
|
|
1525
|
-
}
|
|
1526
|
-
function copyInlineToken(target, tokens, index) {
|
|
1527
|
-
const offset = index * 4;
|
|
1528
|
-
for (let field = 0; field < 4; field++) target.push(tokens[offset + field]);
|
|
1529
|
-
}
|
|
1530
|
-
function firstInlineTokenEndingAfter(tokens, offset) {
|
|
1531
|
-
let low = 0;
|
|
1532
|
-
let high = inlineTokenCount(tokens);
|
|
1533
|
-
while (low < high) {
|
|
1534
|
-
const middle = low + high >>> 1;
|
|
1535
|
-
if (inlineTokenEnd(tokens, middle) <= offset) low = middle + 1;
|
|
1536
|
-
else high = middle;
|
|
1537
|
-
}
|
|
1538
|
-
return low;
|
|
1539
|
-
}
|
|
1540
|
-
//#endregion
|
|
1541
|
-
//#region src/inline/pairing.ts
|
|
1589
|
+
//#region src/inline/delimiter.ts
|
|
1542
1590
|
const whitespace = /\s/u;
|
|
1543
1591
|
const punctuation = /[\p{P}\p{S}]/u;
|
|
1544
1592
|
function characterBefore(source, offset) {
|
|
@@ -1571,151 +1619,9 @@ function canPair(opener, closer) {
|
|
|
1571
1619
|
if (!closer.config.ruleOfThree || !opener.canClose && !closer.canOpen) return true;
|
|
1572
1620
|
return (opener.length + closer.length) % 3 !== 0 || opener.length % 3 === 0 && closer.length % 3 === 0;
|
|
1573
1621
|
}
|
|
1574
|
-
function acceptsContent(source, start, end, config) {
|
|
1575
|
-
let hasNonWhitespace = !config.requireNonWhitespace;
|
|
1576
|
-
let characters = 0;
|
|
1577
|
-
for (let offset = start; offset < end; offset++) {
|
|
1578
|
-
if (!hasNonWhitespace && !whitespace.test(source[offset])) hasNonWhitespace = true;
|
|
1579
|
-
if (config.maxCharacters !== void 0) {
|
|
1580
|
-
const leading = source.charCodeAt(offset);
|
|
1581
|
-
if (leading >= 55296 && leading <= 56319 && offset + 1 < end) {
|
|
1582
|
-
const trailing = source.charCodeAt(offset + 1);
|
|
1583
|
-
if (trailing >= 56320 && trailing <= 57343) offset++;
|
|
1584
|
-
}
|
|
1585
|
-
characters++;
|
|
1586
|
-
if (characters > config.maxCharacters) return false;
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1589
|
-
return hasNonWhitespace;
|
|
1590
|
-
}
|
|
1591
|
-
function indexPairs(configs) {
|
|
1592
|
-
const byCloser = [];
|
|
1593
|
-
const openerKinds = [];
|
|
1594
|
-
const splitByCloser = [];
|
|
1595
|
-
for (const config of configs) {
|
|
1596
|
-
const openerKind = config.opener;
|
|
1597
|
-
const closerKind = config.closer;
|
|
1598
|
-
openerKinds[openerKind] = true;
|
|
1599
|
-
const pairs = byCloser[closerKind] ?? [];
|
|
1600
|
-
pairs.push({
|
|
1601
|
-
activate: config.activate,
|
|
1602
|
-
closeKind: config.close ?? closerKind,
|
|
1603
|
-
content: config.content,
|
|
1604
|
-
deactivatedKinds: config.deactivateEarlier ?? [],
|
|
1605
|
-
forbiddenKinds: config.content?.forbidTokens ?? [],
|
|
1606
|
-
isolateDelimiters: config.isolateDelimiters,
|
|
1607
|
-
openKind: config.open ?? openerKind,
|
|
1608
|
-
openerKind
|
|
1609
|
-
});
|
|
1610
|
-
byCloser[closerKind] = pairs;
|
|
1611
|
-
if (config.splitUnmatchedCloser) splitByCloser[closerKind] = config.splitUnmatchedCloser;
|
|
1612
|
-
}
|
|
1613
|
-
return {
|
|
1614
|
-
byCloser,
|
|
1615
|
-
openerKinds,
|
|
1616
|
-
splitByCloser
|
|
1617
|
-
};
|
|
1618
|
-
}
|
|
1619
|
-
function resolvePairedTokens(source, tokens, index, state) {
|
|
1620
|
-
const openerStacks = [];
|
|
1621
|
-
const inactiveBefore = [];
|
|
1622
|
-
const lastSeen = [];
|
|
1623
|
-
const replacements = [];
|
|
1624
|
-
const matchedClosers = [];
|
|
1625
|
-
const delimiterIsolations = [];
|
|
1626
|
-
function resolveCloser(tokenIndex, tokenKind) {
|
|
1627
|
-
const pairs = index.byCloser[tokenKind];
|
|
1628
|
-
if (!pairs) return;
|
|
1629
|
-
let openerIndex = -1;
|
|
1630
|
-
let pair = pairs[0];
|
|
1631
|
-
let openerStack;
|
|
1632
|
-
for (const candidate of pairs) {
|
|
1633
|
-
const candidates = openerStacks[candidate.openerKind];
|
|
1634
|
-
if (!candidates || candidates.length === 0) continue;
|
|
1635
|
-
const candidateIndex = candidates[candidates.length - 1];
|
|
1636
|
-
if (candidateIndex > openerIndex) {
|
|
1637
|
-
openerIndex = candidateIndex;
|
|
1638
|
-
pair = candidate;
|
|
1639
|
-
openerStack = candidates;
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
if (!openerStack) return;
|
|
1643
|
-
openerStack.pop();
|
|
1644
|
-
if (openerIndex + 1 < (inactiveBefore[pair.openerKind] ?? 0)) return;
|
|
1645
|
-
const contentStart = inlineTokenEnd(tokens, openerIndex);
|
|
1646
|
-
const closerStart = inlineTokenStart(tokens, tokenIndex);
|
|
1647
|
-
if (pair.content && !acceptsContent(source, contentStart, closerStart, pair.content)) return;
|
|
1648
|
-
for (const forbiddenKind of pair.forbiddenKinds) if ((lastSeen[forbiddenKind] ?? 0) > openerIndex + 1) return;
|
|
1649
|
-
if (pair.activate) {
|
|
1650
|
-
const content = source.slice(contentStart, closerStart);
|
|
1651
|
-
if (!pair.activate({
|
|
1652
|
-
source,
|
|
1653
|
-
tokens,
|
|
1654
|
-
openerIndex,
|
|
1655
|
-
closerIndex: tokenIndex,
|
|
1656
|
-
content,
|
|
1657
|
-
state
|
|
1658
|
-
})) return;
|
|
1659
|
-
}
|
|
1660
|
-
if (inlineTokenKind(tokens, openerIndex) !== pair.openKind) replacements[openerIndex] = pair.openKind;
|
|
1661
|
-
if (tokenKind !== pair.closeKind) replacements[tokenIndex] = pair.closeKind;
|
|
1662
|
-
matchedClosers[tokenIndex] = true;
|
|
1663
|
-
for (const kind of pair.deactivatedKinds) inactiveBefore[kind] = Math.max(inactiveBefore[kind] ?? 0, openerIndex + 1);
|
|
1664
|
-
if (pair.isolateDelimiters) delimiterIsolations.push({
|
|
1665
|
-
start: contentStart,
|
|
1666
|
-
end: closerStart,
|
|
1667
|
-
id: delimiterIsolations.length
|
|
1668
|
-
});
|
|
1669
|
-
}
|
|
1670
|
-
const count = inlineTokenCount(tokens);
|
|
1671
|
-
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
1672
|
-
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
1673
|
-
if (index.openerKinds[kind]) {
|
|
1674
|
-
const stack = openerStacks[kind] ?? [];
|
|
1675
|
-
stack.push(tokenIndex);
|
|
1676
|
-
openerStacks[kind] = stack;
|
|
1677
|
-
}
|
|
1678
|
-
resolveCloser(tokenIndex, kind);
|
|
1679
|
-
lastSeen[kind] = tokenIndex + 1;
|
|
1680
|
-
}
|
|
1681
|
-
return {
|
|
1682
|
-
replacements,
|
|
1683
|
-
matchedClosers,
|
|
1684
|
-
delimiterIsolations
|
|
1685
|
-
};
|
|
1686
|
-
}
|
|
1687
|
-
function applyPairReplacements(tokens, replacements, ownsTokens) {
|
|
1688
|
-
if (replacements.length === 0) return tokens;
|
|
1689
|
-
const result = ownsTokens ? tokens : tokens.slice();
|
|
1690
|
-
for (let tokenIndex = 0; tokenIndex < replacements.length; tokenIndex++) {
|
|
1691
|
-
const kind = replacements[tokenIndex];
|
|
1692
|
-
if (kind !== void 0) {
|
|
1693
|
-
const offset = tokenIndex * 4;
|
|
1694
|
-
result[offset] = kind;
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
return result;
|
|
1698
|
-
}
|
|
1699
1622
|
function appendFragment(result, tokens, tokenIndex, start, end, kind) {
|
|
1700
1623
|
appendInlineToken(result, kind, start, end, start === inlineTokenStart(tokens, tokenIndex) ? inlineTokenFlags(tokens, tokenIndex) : 0);
|
|
1701
1624
|
}
|
|
1702
|
-
function assignDelimiterScopes(runs, isolations) {
|
|
1703
|
-
if (isolations.length === 0) return;
|
|
1704
|
-
const ordered = [...isolations].sort((left, right) => left.start - right.start || right.end - left.end);
|
|
1705
|
-
const active = [];
|
|
1706
|
-
let isolationIndex = 0;
|
|
1707
|
-
for (const run of runs) {
|
|
1708
|
-
while (isolationIndex < ordered.length && ordered[isolationIndex].start <= run.offset) {
|
|
1709
|
-
const isolation = ordered[isolationIndex++];
|
|
1710
|
-
while (active.length > 0 && active[active.length - 1].end <= isolation.start) active.pop();
|
|
1711
|
-
const parent = active[active.length - 1];
|
|
1712
|
-
if (parent && isolation.end > parent.end) throw new Error("Delimiter isolation ranges must be nested or disjoint");
|
|
1713
|
-
if (isolation.end > run.offset) active.push(isolation);
|
|
1714
|
-
}
|
|
1715
|
-
while (active.length > 0 && active[active.length - 1].end <= run.offset) active.pop();
|
|
1716
|
-
run.scope = active[active.length - 1]?.id ?? -1;
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
1625
|
function unlinkRun(runs, runIndex) {
|
|
1720
1626
|
const run = runs[runIndex];
|
|
1721
1627
|
if (run.previous >= 0) runs[run.previous].next = run.next;
|
|
@@ -1757,7 +1663,6 @@ function matchDelimiterRuns(runs, first, replacements) {
|
|
|
1757
1663
|
const closeStart = closer.offset + closer.start;
|
|
1758
1664
|
const closeEnd = closeStart + use;
|
|
1759
1665
|
const pair = use === 2 ? closer.config.double : closer.config.single;
|
|
1760
|
-
if (!pair) throw new Error(`Delimiter ${String.fromCharCode(closer.config.marker)} has no replacement for a run of ${use}`);
|
|
1761
1666
|
addReplacement(replacements, opener.tokenIndex, {
|
|
1762
1667
|
offset: openStart,
|
|
1763
1668
|
end: openEnd,
|
|
@@ -1780,11 +1685,27 @@ function matchDelimiterRuns(runs, first, replacements) {
|
|
|
1780
1685
|
}
|
|
1781
1686
|
}
|
|
1782
1687
|
}
|
|
1783
|
-
function resolveDelimiterRuns(source, tokens, configByKind,
|
|
1688
|
+
function resolveDelimiterRuns(source, tokens, configByKind, isolationCloseByOpen) {
|
|
1784
1689
|
const runs = [];
|
|
1690
|
+
const isolationClosers = [];
|
|
1691
|
+
const isolationScopes = [];
|
|
1692
|
+
let nextIsolationScope = 0;
|
|
1785
1693
|
const count = inlineTokenCount(tokens);
|
|
1786
1694
|
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
1787
|
-
const
|
|
1695
|
+
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
1696
|
+
const isolationIndex = isolationClosers.length - 1;
|
|
1697
|
+
if (isolationIndex >= 0 && isolationClosers[isolationIndex] === kind) {
|
|
1698
|
+
isolationClosers.pop();
|
|
1699
|
+
isolationScopes.pop();
|
|
1700
|
+
continue;
|
|
1701
|
+
}
|
|
1702
|
+
const isolationClose = isolationCloseByOpen[kind];
|
|
1703
|
+
if (isolationClose !== void 0) {
|
|
1704
|
+
isolationClosers.push(isolationClose);
|
|
1705
|
+
isolationScopes.push(nextIsolationScope++);
|
|
1706
|
+
continue;
|
|
1707
|
+
}
|
|
1708
|
+
const config = configByKind[kind];
|
|
1788
1709
|
if (!config) continue;
|
|
1789
1710
|
const offset = inlineTokenStart(tokens, tokenIndex);
|
|
1790
1711
|
const end = inlineTokenEnd(tokens, tokenIndex);
|
|
@@ -1798,7 +1719,7 @@ function resolveDelimiterRuns(source, tokens, configByKind, isolations) {
|
|
|
1798
1719
|
length,
|
|
1799
1720
|
start: 0,
|
|
1800
1721
|
remaining: length,
|
|
1801
|
-
scope: -1,
|
|
1722
|
+
scope: isolationScopes[isolationScopes.length - 1] ?? -1,
|
|
1802
1723
|
previous: -1,
|
|
1803
1724
|
next: -1,
|
|
1804
1725
|
canOpen: Boolean(flags & 1),
|
|
@@ -1806,7 +1727,6 @@ function resolveDelimiterRuns(source, tokens, configByKind, isolations) {
|
|
|
1806
1727
|
});
|
|
1807
1728
|
}
|
|
1808
1729
|
if (runs.length === 0) return tokens;
|
|
1809
|
-
assignDelimiterScopes(runs, isolations);
|
|
1810
1730
|
const scopeFirst = [];
|
|
1811
1731
|
const scopeLast = [];
|
|
1812
1732
|
for (let runIndex = 0; runIndex < runs.length; runIndex++) {
|
|
@@ -1840,148 +1760,212 @@ function resolveDelimiterRuns(source, tokens, configByKind, isolations) {
|
|
|
1840
1760
|
const end = inlineTokenEnd(tokens, tokenIndex);
|
|
1841
1761
|
if (offset < end) appendFragment(result, tokens, tokenIndex, offset, end, kind);
|
|
1842
1762
|
}
|
|
1843
|
-
return result;
|
|
1763
|
+
return result;
|
|
1764
|
+
}
|
|
1765
|
+
function createDelimiterResolver(delimiterConfigs, isolationCloseByOpen) {
|
|
1766
|
+
const delimiterByKind = [];
|
|
1767
|
+
delimiterConfigs.forEach((config, index) => {
|
|
1768
|
+
delimiterByKind[config.token] = {
|
|
1769
|
+
single: config.single ? {
|
|
1770
|
+
open: config.single.open,
|
|
1771
|
+
close: config.single.close
|
|
1772
|
+
} : void 0,
|
|
1773
|
+
double: config.double ? {
|
|
1774
|
+
open: config.double.open,
|
|
1775
|
+
close: config.double.close
|
|
1776
|
+
} : void 0,
|
|
1777
|
+
allowIntraword: config.allowIntraword,
|
|
1778
|
+
matchWholeRun: config.pairing.kind === "whole" ? true : void 0,
|
|
1779
|
+
ruleOfThree: config.pairing.kind === "partial" ? config.pairing.ruleOfThree : void 0,
|
|
1780
|
+
index
|
|
1781
|
+
};
|
|
1782
|
+
});
|
|
1783
|
+
const delimiterKinds = [];
|
|
1784
|
+
for (const config of delimiterConfigs) delimiterKinds[config.token] = true;
|
|
1785
|
+
return (source, tokens) => {
|
|
1786
|
+
const count = inlineTokenCount(tokens);
|
|
1787
|
+
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) if (delimiterKinds[inlineTokenKind(tokens, tokenIndex)]) return resolveDelimiterRuns(source, tokens, delimiterByKind, isolationCloseByOpen);
|
|
1788
|
+
return tokens;
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
//#endregion
|
|
1792
|
+
//#region src/inline/lexer.ts
|
|
1793
|
+
function matchInlinePatternEnd(pattern, source, start) {
|
|
1794
|
+
pattern.lastIndex = start;
|
|
1795
|
+
const match = pattern.exec(source);
|
|
1796
|
+
return match === null ? -1 : start + match[0].length;
|
|
1797
|
+
}
|
|
1798
|
+
function inlineMarkerRunEnd(source, start) {
|
|
1799
|
+
const marker = source.charCodeAt(start);
|
|
1800
|
+
let end = start + 1;
|
|
1801
|
+
while (source.charCodeAt(end) === marker) end++;
|
|
1802
|
+
return end;
|
|
1803
|
+
}
|
|
1804
|
+
function inlineTextEnd(source, start, boundary) {
|
|
1805
|
+
boundary.lastIndex = start;
|
|
1806
|
+
let match = boundary.exec(source);
|
|
1807
|
+
while (match !== null && source.charCodeAt(match.index) === 92) {
|
|
1808
|
+
const next = source.charCodeAt(match.index + 1);
|
|
1809
|
+
if (next !== 32 && next !== 9) break;
|
|
1810
|
+
boundary.lastIndex = match.index + 2;
|
|
1811
|
+
match = boundary.exec(source);
|
|
1812
|
+
}
|
|
1813
|
+
return match?.index ?? source.length;
|
|
1814
|
+
}
|
|
1815
|
+
function tokenize(source, textBoundary, scannerByCode) {
|
|
1816
|
+
const tokens = [];
|
|
1817
|
+
let offset = 0;
|
|
1818
|
+
let lineStart = true;
|
|
1819
|
+
while (offset < source.length) {
|
|
1820
|
+
if (lineStart) {
|
|
1821
|
+
let content = offset;
|
|
1822
|
+
while (source.charCodeAt(content) === 32) content++;
|
|
1823
|
+
if (content === source.length) break;
|
|
1824
|
+
let code = source.charCodeAt(content);
|
|
1825
|
+
if (code === 10 || code === 13) {
|
|
1826
|
+
offset = content + 1;
|
|
1827
|
+
if (code === 13 && source.charCodeAt(offset) === 10) offset++;
|
|
1828
|
+
continue;
|
|
1829
|
+
}
|
|
1830
|
+
if (code === 9) {
|
|
1831
|
+
let blankEnd = content;
|
|
1832
|
+
while (source.charCodeAt(blankEnd) === 9 || source.charCodeAt(blankEnd) === 32) blankEnd++;
|
|
1833
|
+
code = source.charCodeAt(blankEnd);
|
|
1834
|
+
if (blankEnd === source.length || code === 10 || code === 13) {
|
|
1835
|
+
offset = blankEnd + (blankEnd < source.length ? 1 : 0);
|
|
1836
|
+
if (code === 13 && source.charCodeAt(offset) === 10) offset++;
|
|
1837
|
+
continue;
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
offset = content;
|
|
1841
|
+
if (tokens.length > 0) tokens.push(40, offset, offset, 0);
|
|
1842
|
+
lineStart = false;
|
|
1843
|
+
continue;
|
|
1844
|
+
}
|
|
1845
|
+
const code = source.charCodeAt(offset);
|
|
1846
|
+
if (code === 32 || code === 9) {
|
|
1847
|
+
if (code === 32) {
|
|
1848
|
+
const end = inlineMarkerRunEnd(source, offset);
|
|
1849
|
+
const next = source.charCodeAt(end);
|
|
1850
|
+
if (end - offset >= 2 && (next === 10 || next === 13)) {
|
|
1851
|
+
tokens.push(7, offset, end, 0);
|
|
1852
|
+
offset = end;
|
|
1853
|
+
continue;
|
|
1854
|
+
}
|
|
1855
|
+
if (end > offset + 1) {
|
|
1856
|
+
offset = end;
|
|
1857
|
+
continue;
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
offset++;
|
|
1861
|
+
continue;
|
|
1862
|
+
}
|
|
1863
|
+
if (code === 10 || code === 13) {
|
|
1864
|
+
offset++;
|
|
1865
|
+
if (code === 13 && source.charCodeAt(offset) === 10) offset++;
|
|
1866
|
+
lineStart = true;
|
|
1867
|
+
continue;
|
|
1868
|
+
}
|
|
1869
|
+
const scan = scannerByCode[code];
|
|
1870
|
+
if (scan) {
|
|
1871
|
+
const scannedEnd = scan(source, offset, tokens);
|
|
1872
|
+
if (scannedEnd > offset) {
|
|
1873
|
+
offset = scannedEnd;
|
|
1874
|
+
continue;
|
|
1875
|
+
}
|
|
1876
|
+
const end = inlineTextEnd(source, offset + 1, textBoundary);
|
|
1877
|
+
tokens.push(9, offset, end, 0);
|
|
1878
|
+
offset = end;
|
|
1879
|
+
continue;
|
|
1880
|
+
}
|
|
1881
|
+
const end = inlineTextEnd(source, offset, textBoundary);
|
|
1882
|
+
tokens.push(9, offset, end, 0);
|
|
1883
|
+
offset = end;
|
|
1884
|
+
}
|
|
1885
|
+
return tokens;
|
|
1844
1886
|
}
|
|
1845
|
-
function
|
|
1846
|
-
const
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
double: config.double ? {
|
|
1855
|
-
open: config.double.open,
|
|
1856
|
-
close: config.double.close
|
|
1857
|
-
} : void 0,
|
|
1858
|
-
allowIntraword: config.allowIntraword,
|
|
1859
|
-
matchWholeRun: config.pairing.kind === "whole" ? true : void 0,
|
|
1860
|
-
ruleOfThree: config.pairing.kind === "partial" ? config.pairing.ruleOfThree : void 0,
|
|
1861
|
-
index
|
|
1887
|
+
function compileInlineTokenizer(rules) {
|
|
1888
|
+
const scannerByCode = [];
|
|
1889
|
+
const boundaryCodes = [];
|
|
1890
|
+
for (const rule of rules) {
|
|
1891
|
+
const code = rule.marker;
|
|
1892
|
+
const previous = scannerByCode[code];
|
|
1893
|
+
scannerByCode[code] = previous === void 0 ? rule.scan : (source, start, tokens) => {
|
|
1894
|
+
const end = previous(source, start, tokens);
|
|
1895
|
+
return end > start ? end : rule.scan(source, start, tokens);
|
|
1862
1896
|
};
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
const
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
phasesByKind[kind] |= 2;
|
|
1869
|
-
}
|
|
1870
|
-
for (const config of pairConfigs) {
|
|
1871
|
-
const openerKind = config.opener;
|
|
1872
|
-
const closerKind = config.closer;
|
|
1873
|
-
phasesByKind[openerKind] |= 1;
|
|
1874
|
-
phasesByKind[closerKind] |= 1;
|
|
1875
|
-
}
|
|
1876
|
-
return (source, tokens, state, ownsTokens = false) => {
|
|
1877
|
-
const count = inlineTokenCount(tokens);
|
|
1878
|
-
let activePhases = 0;
|
|
1879
|
-
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
1880
|
-
const phases = phasesByKind[inlineTokenKind(tokens, tokenIndex)];
|
|
1881
|
-
if (phases === void 0) continue;
|
|
1882
|
-
activePhases |= phases;
|
|
1883
|
-
if (activePhases === 3) break;
|
|
1884
|
-
}
|
|
1885
|
-
if (!(activePhases & 1)) return activePhases & 2 ? resolveDelimiterRuns(source, tokens, delimiterByKind, emptyArray) : tokens;
|
|
1886
|
-
let paired = resolvePairedTokens(source, tokens, pairIndex, state);
|
|
1887
|
-
let expanded;
|
|
1888
|
-
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
1889
|
-
const split = pairIndex.splitByCloser[inlineTokenKind(tokens, tokenIndex)];
|
|
1890
|
-
const fragments = split && !paired.matchedClosers[tokenIndex] ? split(tokens, tokenIndex) : void 0;
|
|
1891
|
-
if (fragments) {
|
|
1892
|
-
if (!expanded) {
|
|
1893
|
-
expanded = [];
|
|
1894
|
-
for (let prefix = 0; prefix < tokenIndex; prefix++) copyInlineToken(expanded, tokens, prefix);
|
|
1895
|
-
}
|
|
1896
|
-
for (const value of fragments) expanded.push(value);
|
|
1897
|
-
} else if (expanded) copyInlineToken(expanded, tokens, tokenIndex);
|
|
1898
|
-
}
|
|
1899
|
-
if (expanded) paired = resolvePairedTokens(source, expanded, pairIndex, state);
|
|
1900
|
-
const resolvedPairs = applyPairReplacements(expanded ?? tokens, paired.replacements, expanded !== void 0 || ownsTokens);
|
|
1901
|
-
return activePhases & 2 ? resolveDelimiterRuns(source, resolvedPairs, delimiterByKind, paired.delimiterIsolations) : resolvedPairs;
|
|
1902
|
-
};
|
|
1897
|
+
if (previous === void 0) boundaryCodes.push(code);
|
|
1898
|
+
}
|
|
1899
|
+
const boundaries = String.fromCharCode(...boundaryCodes).replaceAll(/[\\\]-]/g, "\\$&");
|
|
1900
|
+
const textBoundary = new RegExp(` {2,}(?=[\\n\\r]|$)|[\\n\\r${boundaries}]`, "g");
|
|
1901
|
+
return (source) => tokenize(source, textBoundary, scannerByCode);
|
|
1903
1902
|
}
|
|
1904
1903
|
//#endregion
|
|
1905
1904
|
//#region src/inline/profile.ts
|
|
1906
|
-
function
|
|
1907
|
-
if (
|
|
1905
|
+
function composeTransforms(transforms) {
|
|
1906
|
+
if (transforms.length === 1) return transforms[0];
|
|
1908
1907
|
return (source, tokens, context) => {
|
|
1909
|
-
for (const
|
|
1908
|
+
for (const transform of transforms) tokens = transform(source, tokens, context);
|
|
1910
1909
|
return tokens;
|
|
1911
1910
|
};
|
|
1912
1911
|
}
|
|
1913
1912
|
function compileInlineProfile(features, decodeText) {
|
|
1914
1913
|
const delimiters = [];
|
|
1915
|
-
const
|
|
1916
|
-
const
|
|
1917
|
-
const
|
|
1918
|
-
const rewrites = [];
|
|
1914
|
+
const scanRules = [];
|
|
1915
|
+
const transforms = [];
|
|
1916
|
+
const buildRules = [];
|
|
1919
1917
|
for (const feature of features) {
|
|
1920
|
-
|
|
1921
|
-
if (feature.
|
|
1922
|
-
if (
|
|
1923
|
-
if (
|
|
1924
|
-
if (feature.
|
|
1918
|
+
const resolve = feature.resolve;
|
|
1919
|
+
if (feature.scan) scanRules.push(...feature.scan);
|
|
1920
|
+
if (resolve?.delimiters) delimiters.push(...resolve.delimiters);
|
|
1921
|
+
if (resolve?.transform) transforms.push(resolve.transform);
|
|
1922
|
+
if (feature.build) buildRules.push(...feature.build);
|
|
1925
1923
|
}
|
|
1926
1924
|
const tokenHandlers = [];
|
|
1927
1925
|
const containerByKind = [];
|
|
1928
1926
|
const pairByOpenKind = [];
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1927
|
+
const isolationCloseByOpen = [];
|
|
1928
|
+
for (const rule of buildRules) {
|
|
1929
|
+
if (rule.kind === "decorate") {
|
|
1930
|
+
tokenHandlers[rule.token] = rule.apply;
|
|
1932
1931
|
continue;
|
|
1933
1932
|
}
|
|
1934
|
-
if (
|
|
1935
|
-
tokenHandlers[
|
|
1933
|
+
if (rule.kind === "leaf") {
|
|
1934
|
+
tokenHandlers[rule.token] = rule.build;
|
|
1936
1935
|
continue;
|
|
1937
1936
|
}
|
|
1938
|
-
if (
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
}
|
|
1937
|
+
if (rule.kind === "container") {
|
|
1938
|
+
isolationCloseByOpen[rule.contentOpen] = rule.close;
|
|
1939
|
+
containerByKind[rule.token] = {
|
|
1940
|
+
closeKind: rule.close,
|
|
1941
|
+
contentOpenKind: rule.contentOpen,
|
|
1942
|
+
build: rule.build
|
|
1943
|
+
};
|
|
1944
|
+
} else {
|
|
1945
|
+
isolationCloseByOpen[rule.open] = rule.close;
|
|
1946
|
+
pairByOpenKind[rule.open] = {
|
|
1947
|
+
closeKind: rule.close,
|
|
1948
|
+
build: rule.build
|
|
1949
|
+
};
|
|
1950
|
+
}
|
|
1952
1951
|
}
|
|
1953
|
-
const
|
|
1954
|
-
const
|
|
1952
|
+
const resolveDelimiters = createDelimiterResolver(delimiters, isolationCloseByOpen);
|
|
1953
|
+
const transform = transforms.length ? composeTransforms(transforms) : void 0;
|
|
1955
1954
|
return {
|
|
1956
1955
|
decodeText,
|
|
1957
|
-
resolve:
|
|
1958
|
-
const
|
|
1959
|
-
return
|
|
1956
|
+
resolve: transform === void 0 ? resolveDelimiters : (source, tokens, context) => {
|
|
1957
|
+
const transformed = transform(source, tokens, context);
|
|
1958
|
+
return resolveDelimiters(source, transformed);
|
|
1960
1959
|
},
|
|
1961
1960
|
schema: {
|
|
1962
1961
|
containerByKind,
|
|
1963
1962
|
pairByOpenKind
|
|
1964
1963
|
},
|
|
1965
1964
|
tokenHandlers,
|
|
1966
|
-
tokenize: compileInlineTokenizer(
|
|
1965
|
+
tokenize: compileInlineTokenizer(scanRules)
|
|
1967
1966
|
};
|
|
1968
1967
|
}
|
|
1969
1968
|
//#endregion
|
|
1970
|
-
//#region src/fragment/node.ts
|
|
1971
|
-
function extendSpan(value, end) {
|
|
1972
|
-
const node = value;
|
|
1973
|
-
node.position.end = Math.max(node.position.end, end);
|
|
1974
|
-
}
|
|
1975
|
-
function firstChildStart(children) {
|
|
1976
|
-
const first = children[0];
|
|
1977
|
-
if (!first) throw new Error("mdast container unexpectedly has no children");
|
|
1978
|
-
return first.position.start;
|
|
1979
|
-
}
|
|
1980
|
-
function lastChildEnd(children, emptyEnd) {
|
|
1981
|
-
const last = children.at(-1);
|
|
1982
|
-
return last ? last.position.end : emptyEnd;
|
|
1983
|
-
}
|
|
1984
|
-
//#endregion
|
|
1985
1969
|
//#region src/profile/features/attributes/syntax.ts
|
|
1986
1970
|
const brackets = {
|
|
1987
1971
|
"[": "]",
|
|
@@ -2041,6 +2025,9 @@ function assignAttribute(attributes, name, value) {
|
|
|
2041
2025
|
if (name === "class" && typeof value === "string" && typeof attributes.class === "string") attributes.class += ` ${value}`;
|
|
2042
2026
|
else attributes[name] = value;
|
|
2043
2027
|
}
|
|
2028
|
+
function mergeAttributes(target, source) {
|
|
2029
|
+
for (const key in source) assignAttribute(target, key, source[key]);
|
|
2030
|
+
}
|
|
2044
2031
|
function closingBracket(source, start) {
|
|
2045
2032
|
if (source[start] !== "[") return;
|
|
2046
2033
|
let depth = 0;
|
|
@@ -2135,31 +2122,10 @@ function parseAttributes(source, start) {
|
|
|
2135
2122
|
};
|
|
2136
2123
|
}
|
|
2137
2124
|
//#endregion
|
|
2138
|
-
//#region src/profile/features/attributes/carrier.ts
|
|
2139
|
-
const terminalAttributes = Symbol("terminalAttributes");
|
|
2140
|
-
function mergeAttributes(target, source) {
|
|
2141
|
-
for (const key in source) assignAttribute(target, key, source[key]);
|
|
2142
|
-
}
|
|
2143
|
-
function carryTerminalAttributes(children, attributes) {
|
|
2144
|
-
const target = children;
|
|
2145
|
-
if (target[terminalAttributes]) mergeAttributes(target[terminalAttributes], attributes);
|
|
2146
|
-
else target[terminalAttributes] = attributes;
|
|
2147
|
-
}
|
|
2148
|
-
function hasTerminalAttributes(children) {
|
|
2149
|
-
return terminalAttributes in children;
|
|
2150
|
-
}
|
|
2151
|
-
function takeTerminalAttributes(children) {
|
|
2152
|
-
const target = children;
|
|
2153
|
-
const attributes = target[terminalAttributes];
|
|
2154
|
-
if (attributes) delete target[terminalAttributes];
|
|
2155
|
-
return attributes;
|
|
2156
|
-
}
|
|
2157
|
-
//#endregion
|
|
2158
2125
|
//#region src/profile/features/attributes/index.ts
|
|
2159
|
-
const decorateInlineContainer = (build) => (tokenStart, context) => {
|
|
2160
|
-
const result = build(tokenStart, context);
|
|
2161
|
-
|
|
2162
|
-
if (attributes) result.attributes = attributes;
|
|
2126
|
+
const decorateInlineContainer = (build) => (tokenStart, context, inline) => {
|
|
2127
|
+
const result = build(tokenStart, context, inline);
|
|
2128
|
+
if (inline?.attributes) result.attributes = inline.attributes;
|
|
2163
2129
|
return result;
|
|
2164
2130
|
};
|
|
2165
2131
|
const decorateList = (build) => (tokenStart, context) => {
|
|
@@ -2209,14 +2175,14 @@ function scanAttribute(source, start, tokens) {
|
|
|
2209
2175
|
}
|
|
2210
2176
|
const previous = inlineTokenCount(tokens) - 1;
|
|
2211
2177
|
const previousEnd = previous >= 0 ? inlineTokenEnd(tokens, previous) : start;
|
|
2212
|
-
if (previousEnd <= start && inlineTokenKind(tokens, previous) ===
|
|
2213
|
-
appendInlineToken(tokens,
|
|
2178
|
+
if (previousEnd <= start && inlineTokenKind(tokens, previous) === 36) appendInlineToken(tokens, 9, previousEnd, start);
|
|
2179
|
+
appendInlineToken(tokens, 36, start, end, start > 0 && isMarkdownWhitespace(source.charCodeAt(start - 1)) ? 4 : 0);
|
|
2214
2180
|
let next = end;
|
|
2215
2181
|
while (isMarkdownWhitespace(source.charCodeAt(next))) next++;
|
|
2216
2182
|
if (next === source.length) for (let index = inlineTokenCount(tokens) - 1; index >= 0; index--) {
|
|
2217
2183
|
const kind = inlineTokenKind(tokens, index);
|
|
2218
2184
|
if (kind === 9 && !hasVisibleText(source, inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index))) continue;
|
|
2219
|
-
if (kind !==
|
|
2185
|
+
if (kind !== 36) break;
|
|
2220
2186
|
setInlineTokenFlags(tokens, index, inlineTokenFlags(tokens, index) | 8);
|
|
2221
2187
|
}
|
|
2222
2188
|
return end;
|
|
@@ -2224,47 +2190,48 @@ function scanAttribute(source, start, tokens) {
|
|
|
2224
2190
|
const feature$17 = {
|
|
2225
2191
|
block: { decorators: [
|
|
2226
2192
|
{
|
|
2227
|
-
rule:
|
|
2193
|
+
rule: 9,
|
|
2228
2194
|
decorate: decorateInlineContainer
|
|
2229
2195
|
},
|
|
2230
2196
|
{
|
|
2231
|
-
rule:
|
|
2197
|
+
rule: 0,
|
|
2232
2198
|
decorate: decorateInlineContainer
|
|
2233
2199
|
},
|
|
2234
2200
|
{
|
|
2235
|
-
rule:
|
|
2201
|
+
rule: 1,
|
|
2236
2202
|
decorate: decorateInlineContainer
|
|
2237
2203
|
},
|
|
2238
2204
|
{
|
|
2239
|
-
rule:
|
|
2205
|
+
rule: 18,
|
|
2240
2206
|
decorate: decorateList
|
|
2241
2207
|
},
|
|
2242
2208
|
{
|
|
2243
|
-
rule:
|
|
2209
|
+
rule: 19,
|
|
2244
2210
|
decorate: decorateList
|
|
2245
2211
|
},
|
|
2246
2212
|
{
|
|
2247
|
-
rule:
|
|
2213
|
+
rule: 8,
|
|
2248
2214
|
decorate: decorateBlockquote
|
|
2249
2215
|
}
|
|
2250
2216
|
] },
|
|
2251
2217
|
inline: {
|
|
2252
|
-
|
|
2218
|
+
scan: [{
|
|
2253
2219
|
marker: 123,
|
|
2254
2220
|
scan: scanAttribute
|
|
2255
2221
|
}],
|
|
2256
|
-
|
|
2222
|
+
build: [{
|
|
2257
2223
|
kind: "decorate",
|
|
2258
|
-
token:
|
|
2224
|
+
token: 36,
|
|
2259
2225
|
apply(tokenIndex, sourceSpan, context, target) {
|
|
2260
|
-
const previous = target.at(-1);
|
|
2226
|
+
const previous = target.children.at(-1);
|
|
2261
2227
|
const parsed = parseAttributes(context.view.text, inlineTokenStart(context.tokens, tokenIndex));
|
|
2262
2228
|
if (!previous || !parsed) return false;
|
|
2263
2229
|
const flags = inlineTokenFlags(context.tokens, tokenIndex);
|
|
2264
2230
|
const terminal = Boolean(flags & 8);
|
|
2265
2231
|
const detached = Boolean(flags & 4);
|
|
2266
|
-
if (terminal && (detached || previous.type === "text" ||
|
|
2267
|
-
|
|
2232
|
+
if (terminal && (detached || previous.type === "text" || target.attributes !== void 0)) {
|
|
2233
|
+
if (target.attributes) mergeAttributes(target.attributes, parsed.attributes);
|
|
2234
|
+
else target.attributes = parsed.attributes;
|
|
2268
2235
|
return true;
|
|
2269
2236
|
}
|
|
2270
2237
|
if (previous.attributes) mergeAttributes(previous.attributes, parsed.attributes);
|
|
@@ -2286,18 +2253,18 @@ function bindingEnd(source, start) {
|
|
|
2286
2253
|
return source.slice(start + 2, valueEnd).trim() ? close + 2 : -1;
|
|
2287
2254
|
}
|
|
2288
2255
|
const feature$16 = { inline: {
|
|
2289
|
-
|
|
2256
|
+
scan: [{
|
|
2290
2257
|
marker: 123,
|
|
2291
2258
|
scan(source, start, tokens) {
|
|
2292
2259
|
const end = bindingEnd(source, start);
|
|
2293
2260
|
if (end < 0) return -1;
|
|
2294
|
-
appendInlineToken(tokens,
|
|
2261
|
+
appendInlineToken(tokens, 32, start, end);
|
|
2295
2262
|
return end;
|
|
2296
2263
|
}
|
|
2297
2264
|
}],
|
|
2298
|
-
|
|
2265
|
+
build: [{
|
|
2299
2266
|
kind: "leaf",
|
|
2300
|
-
token:
|
|
2267
|
+
token: 32,
|
|
2301
2268
|
build(tokenIndex, sourceSpan, context) {
|
|
2302
2269
|
const source = context.view.text;
|
|
2303
2270
|
const start = inlineTokenStart(context.tokens, tokenIndex) + 2;
|
|
@@ -2345,7 +2312,7 @@ function unwrapBlockQuote(source, line) {
|
|
|
2345
2312
|
}
|
|
2346
2313
|
const feature$15 = { block: {
|
|
2347
2314
|
rules: [{
|
|
2348
|
-
rule:
|
|
2315
|
+
rule: 8,
|
|
2349
2316
|
syntax: {
|
|
2350
2317
|
kind: "block",
|
|
2351
2318
|
open: 3,
|
|
@@ -2353,12 +2320,11 @@ const feature$15 = { block: {
|
|
|
2353
2320
|
},
|
|
2354
2321
|
build(tokenStart, context) {
|
|
2355
2322
|
const offset = context.structure.tokens.start(tokenStart);
|
|
2356
|
-
const marker = blockToken(tokenStart, 3, context);
|
|
2357
2323
|
return {
|
|
2358
2324
|
type: "blockquote",
|
|
2359
2325
|
children: buildBlockChildren(tokenStart, context),
|
|
2360
2326
|
position: {
|
|
2361
|
-
start: firstNonspace(context.source,
|
|
2327
|
+
start: firstNonspace(context.source, offset, lineEnd(context.source, offset)),
|
|
2362
2328
|
end: blockEnd(tokenStart, context)
|
|
2363
2329
|
}
|
|
2364
2330
|
};
|
|
@@ -2415,7 +2381,7 @@ function isThematicBreak(source, line, contentOffset) {
|
|
|
2415
2381
|
const feature$14 = {
|
|
2416
2382
|
block: {
|
|
2417
2383
|
rules: [{
|
|
2418
|
-
rule:
|
|
2384
|
+
rule: 7,
|
|
2419
2385
|
syntax: {
|
|
2420
2386
|
kind: "leaf",
|
|
2421
2387
|
token: 2
|
|
@@ -2449,7 +2415,7 @@ const feature$14 = {
|
|
|
2449
2415
|
}
|
|
2450
2416
|
}]
|
|
2451
2417
|
},
|
|
2452
|
-
inline: {
|
|
2418
|
+
inline: { build: [{
|
|
2453
2419
|
kind: "leaf",
|
|
2454
2420
|
token: 7,
|
|
2455
2421
|
build(tokenIndex, sourceSpan) {
|
|
@@ -2460,7 +2426,7 @@ const feature$14 = {
|
|
|
2460
2426
|
}
|
|
2461
2427
|
}, {
|
|
2462
2428
|
kind: "leaf",
|
|
2463
|
-
token:
|
|
2429
|
+
token: 40,
|
|
2464
2430
|
build(tokenIndex, sourceSpan) {
|
|
2465
2431
|
return {
|
|
2466
2432
|
type: "text",
|
|
@@ -2563,12 +2529,12 @@ const buildInlineText = (tokenIndex, sourceSpan, context) => {
|
|
|
2563
2529
|
};
|
|
2564
2530
|
};
|
|
2565
2531
|
const feature$13 = { inline: {
|
|
2566
|
-
|
|
2532
|
+
scan: [{
|
|
2567
2533
|
marker: 38,
|
|
2568
2534
|
scan(source, start, tokens) {
|
|
2569
2535
|
const matchEnd = matchInlinePatternEnd(entity, source, start);
|
|
2570
2536
|
const end = matchEnd < 0 ? start + 1 : matchEnd;
|
|
2571
|
-
appendInlineToken(tokens, matchEnd < 0 ?
|
|
2537
|
+
appendInlineToken(tokens, matchEnd < 0 ? 39 : 6, start, end, matchEnd < 0 ? 0 : 16);
|
|
2572
2538
|
return end;
|
|
2573
2539
|
}
|
|
2574
2540
|
}, {
|
|
@@ -2577,7 +2543,7 @@ const feature$13 = { inline: {
|
|
|
2577
2543
|
const next = source.charCodeAt(start + 1);
|
|
2578
2544
|
let end = start + 1;
|
|
2579
2545
|
let flags = 0;
|
|
2580
|
-
let kind =
|
|
2546
|
+
let kind = 39;
|
|
2581
2547
|
if (next === 10 || next === 13) kind = 7;
|
|
2582
2548
|
else if (isAsciiPunctuation(next)) {
|
|
2583
2549
|
end++;
|
|
@@ -2591,7 +2557,7 @@ const feature$13 = { inline: {
|
|
|
2591
2557
|
return end;
|
|
2592
2558
|
}
|
|
2593
2559
|
}],
|
|
2594
|
-
|
|
2560
|
+
build: [
|
|
2595
2561
|
{
|
|
2596
2562
|
kind: "leaf",
|
|
2597
2563
|
token: 9,
|
|
@@ -2599,7 +2565,7 @@ const feature$13 = { inline: {
|
|
|
2599
2565
|
},
|
|
2600
2566
|
{
|
|
2601
2567
|
kind: "leaf",
|
|
2602
|
-
token:
|
|
2568
|
+
token: 39,
|
|
2603
2569
|
build: buildInlineText
|
|
2604
2570
|
},
|
|
2605
2571
|
{
|
|
@@ -2625,11 +2591,10 @@ function codeFenceAt(source, line) {
|
|
|
2625
2591
|
return fenceAt$1(source, line, codeFenceRule);
|
|
2626
2592
|
}
|
|
2627
2593
|
function indentedCodeEnd(tokenStart, context) {
|
|
2628
|
-
const
|
|
2629
|
-
const count = context.structure.tokens.rangeCount(token);
|
|
2594
|
+
const count = context.structure.tokens.rangeCount(tokenStart);
|
|
2630
2595
|
for (let index = count - 1; index >= 0; index--) {
|
|
2631
|
-
const start = context.structure.tokens.rangeStart(
|
|
2632
|
-
const rangeEnd = context.structure.tokens.rangeEnd(
|
|
2596
|
+
const start = context.structure.tokens.rangeStart(tokenStart, index);
|
|
2597
|
+
const rangeEnd = context.structure.tokens.rangeEnd(tokenStart, index);
|
|
2633
2598
|
if (/[^\r\n]/.test(context.source.slice(start, rangeEnd))) {
|
|
2634
2599
|
let end = rangeEnd;
|
|
2635
2600
|
while (end > start && /[\r\n]/.test(context.source[end - 1])) end--;
|
|
@@ -2648,7 +2613,7 @@ const feature$12 = {
|
|
|
2648
2613
|
return end;
|
|
2649
2614
|
}],
|
|
2650
2615
|
rules: [{
|
|
2651
|
-
rule:
|
|
2616
|
+
rule: 15,
|
|
2652
2617
|
syntax: {
|
|
2653
2618
|
kind: "leaf",
|
|
2654
2619
|
token: 19
|
|
@@ -2656,9 +2621,8 @@ const feature$12 = {
|
|
|
2656
2621
|
build(tokenStart, context) {
|
|
2657
2622
|
const offset = context.structure.tokens.start(tokenStart);
|
|
2658
2623
|
const end = offset + context.structure.lenOf(tokenStart);
|
|
2659
|
-
const
|
|
2660
|
-
const
|
|
2661
|
-
const block = context.structure.tokens.value(token);
|
|
2624
|
+
const source = normalizeLines(context.structure.tokens.text(context.source, tokenStart));
|
|
2625
|
+
const block = context.structure.tokens.value(tokenStart);
|
|
2662
2626
|
if (!block) throw new Error("FencedCodeBlock token has no fence metadata");
|
|
2663
2627
|
const rawInfo = semanticText(block.info);
|
|
2664
2628
|
const langEnd = rawInfo.search(/[ \t]/);
|
|
@@ -2676,15 +2640,14 @@ const feature$12 = {
|
|
|
2676
2640
|
};
|
|
2677
2641
|
}
|
|
2678
2642
|
}, {
|
|
2679
|
-
rule:
|
|
2643
|
+
rule: 16,
|
|
2680
2644
|
syntax: {
|
|
2681
2645
|
kind: "leaf",
|
|
2682
2646
|
token: 20
|
|
2683
2647
|
},
|
|
2684
2648
|
build(tokenStart, context) {
|
|
2685
2649
|
const offset = context.structure.tokens.start(tokenStart);
|
|
2686
|
-
const
|
|
2687
|
-
const lines = normalizeLines(context.structure.tokens.text(context.source, token)).split("\n").map((line) => removeIndent(line, 4));
|
|
2650
|
+
const lines = normalizeLines(context.structure.tokens.text(context.source, tokenStart)).split("\n").map((line) => removeIndent(line, 4));
|
|
2688
2651
|
while (lines.length && /^[ \t]*$/.test(lines[lines.length - 1])) lines.pop();
|
|
2689
2652
|
return {
|
|
2690
2653
|
type: "code",
|
|
@@ -2716,7 +2679,7 @@ const feature$12 = {
|
|
|
2716
2679
|
}]
|
|
2717
2680
|
},
|
|
2718
2681
|
inline: {
|
|
2719
|
-
|
|
2682
|
+
scan: [{
|
|
2720
2683
|
marker: 96,
|
|
2721
2684
|
scan(source, start, tokens) {
|
|
2722
2685
|
let end = -1;
|
|
@@ -2738,11 +2701,11 @@ const feature$12 = {
|
|
|
2738
2701
|
}
|
|
2739
2702
|
}
|
|
2740
2703
|
if (end < 0) end = start + 1;
|
|
2741
|
-
appendInlineToken(tokens, end === start + 1 ?
|
|
2704
|
+
appendInlineToken(tokens, end === start + 1 ? 39 : 2, start, end);
|
|
2742
2705
|
return end;
|
|
2743
2706
|
}
|
|
2744
2707
|
}],
|
|
2745
|
-
|
|
2708
|
+
build: [{
|
|
2746
2709
|
kind: "leaf",
|
|
2747
2710
|
token: 2,
|
|
2748
2711
|
build: (tokenIndex, sourceSpan, context) => {
|
|
@@ -2753,7 +2716,7 @@ const feature$12 = {
|
|
|
2753
2716
|
if (/^[ \n]/.test(value) && /[ \n]$/.test(value) && /[^ \n]/.test(value)) value = value.slice(1, -1);
|
|
2754
2717
|
return {
|
|
2755
2718
|
type: "inlineCode",
|
|
2756
|
-
value: context.blockRule ===
|
|
2719
|
+
value: context.blockRule === 3 ? value.replace(/\\\|/g, "|") : value,
|
|
2757
2720
|
position: sourceSpan
|
|
2758
2721
|
};
|
|
2759
2722
|
}
|
|
@@ -2761,161 +2724,55 @@ const feature$12 = {
|
|
|
2761
2724
|
}
|
|
2762
2725
|
};
|
|
2763
2726
|
//#endregion
|
|
2764
|
-
//#region src/
|
|
2765
|
-
function
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
}
|
|
2770
|
-
return 0;
|
|
2771
|
-
}
|
|
2772
|
-
function lineEndingStart(source, offset) {
|
|
2773
|
-
const start = lineStart(source, offset);
|
|
2774
|
-
if (start === 0) return offset;
|
|
2775
|
-
return source[start - 1] === "\n" && source[start - 2] === "\r" ? start - 2 : start - 1;
|
|
2727
|
+
//#region src/profile/features/frontmatter.ts
|
|
2728
|
+
function frontmatterFenceAt(source, line, marker) {
|
|
2729
|
+
if (source[line.start] !== marker || source[line.start + 1] !== marker || source[line.start + 2] !== marker) return false;
|
|
2730
|
+
for (let offset = line.start + 3; offset < line.end; offset++) if (source[offset] !== " " && source[offset] !== " ") return false;
|
|
2731
|
+
return true;
|
|
2776
2732
|
}
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
const
|
|
2780
|
-
if (
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
type: "
|
|
2733
|
+
const buildFrontmatter = (tokenStart, context) => {
|
|
2734
|
+
const tokens = context.structure.tokens;
|
|
2735
|
+
const rangeCount = tokens.rangeCount(tokenStart);
|
|
2736
|
+
if (rangeCount < 2) throw new Error("YAML token does not contain two fences");
|
|
2737
|
+
let value = normalizeLines(context.source.slice(tokens.rangeEnd(tokenStart, 0), tokens.rangeStart(tokenStart, rangeCount - 1)));
|
|
2738
|
+
if (value.endsWith("\n")) value = value.slice(0, -1);
|
|
2739
|
+
return {
|
|
2740
|
+
type: "yaml",
|
|
2785
2741
|
value,
|
|
2786
2742
|
position: {
|
|
2787
|
-
start,
|
|
2788
|
-
end
|
|
2789
|
-
}
|
|
2790
|
-
});
|
|
2791
|
-
}
|
|
2792
|
-
function appendPhrasing(target, value) {
|
|
2793
|
-
if (value.type === "text") appendText(target, value.value, value.position.start, value.position.end);
|
|
2794
|
-
else target.push(value);
|
|
2795
|
-
}
|
|
2796
|
-
function appendInlineGap(output, context, start, end) {
|
|
2797
|
-
output.gapStart = -1;
|
|
2798
|
-
output.gapEnd = -1;
|
|
2799
|
-
const gapSpan = context.view.mapSpan(start, end);
|
|
2800
|
-
appendText(output.target, context.decodeText(context.view.text.slice(start, end).replace(/[\r\n]/g, "")), gapSpan.start, gapSpan.end);
|
|
2801
|
-
}
|
|
2802
|
-
function appendInline(output, context, value) {
|
|
2803
|
-
const { target } = output;
|
|
2804
|
-
const nextLineOffset = value.position.start;
|
|
2805
|
-
const newline = value.type === "text" && value.value.startsWith("\n");
|
|
2806
|
-
if (output.gapStart >= 0) {
|
|
2807
|
-
if (!newline) appendInlineGap(output, context, output.gapStart, output.gapEnd);
|
|
2808
|
-
else {
|
|
2809
|
-
output.gapStart = -1;
|
|
2810
|
-
output.gapEnd = -1;
|
|
2811
|
-
}
|
|
2812
|
-
}
|
|
2813
|
-
if (newline) {
|
|
2814
|
-
const previous = target.at(-1);
|
|
2815
|
-
if (previous?.type === "break") {
|
|
2816
|
-
extendSpan(previous, lineStart(context.source, nextLineOffset));
|
|
2817
|
-
return;
|
|
2818
|
-
}
|
|
2819
|
-
value.position.start = lineEndingStart(context.source, nextLineOffset);
|
|
2820
|
-
if (previous?.type === "text") previous.value = previous.value.slice(0, trailingWhitespaceStart(previous.value));
|
|
2821
|
-
}
|
|
2822
|
-
appendPhrasing(target, value);
|
|
2823
|
-
}
|
|
2824
|
-
function appendInlineLeaf(tokenIndex, sourceSpan, output, context) {
|
|
2825
|
-
const kind = inlineTokenKind(context.tokens, tokenIndex);
|
|
2826
|
-
const handle = context.tokenHandlers[kind];
|
|
2827
|
-
if (!handle) throw new Error(`Unexpected inline token kind ${kind}`);
|
|
2828
|
-
const value = handle(tokenIndex, sourceSpan, context, output.target);
|
|
2829
|
-
if (typeof value === "boolean") return value;
|
|
2830
|
-
if (!value) return false;
|
|
2831
|
-
appendInline(output, context, value);
|
|
2832
|
-
return true;
|
|
2833
|
-
}
|
|
2834
|
-
function trailingWhitespaceStart(value) {
|
|
2835
|
-
let offset = value.length;
|
|
2836
|
-
while (offset > 0 && (value[offset - 1] === " " || value[offset - 1] === " ")) offset--;
|
|
2837
|
-
return offset;
|
|
2838
|
-
}
|
|
2839
|
-
function appendInlineRange(startToken, endToken, context, target, cursor, closeKind) {
|
|
2840
|
-
const output = {
|
|
2841
|
-
cursor,
|
|
2842
|
-
gapEnd: -1,
|
|
2843
|
-
gapStart: -1,
|
|
2844
|
-
target
|
|
2845
|
-
};
|
|
2846
|
-
let index = startToken;
|
|
2847
|
-
while (index < endToken) {
|
|
2848
|
-
if (inlineTokenKind(context.tokens, index) === closeKind) break;
|
|
2849
|
-
const childOffset = inlineTokenStart(context.tokens, index);
|
|
2850
|
-
if (output.cursor !== void 0 && childOffset > output.cursor) {
|
|
2851
|
-
output.gapStart = output.cursor;
|
|
2852
|
-
output.gapEnd = childOffset;
|
|
2853
|
-
}
|
|
2854
|
-
const next = buildInlineSemantic(index, endToken, output, context);
|
|
2855
|
-
const childEnd = inlineTokenEnd(context.tokens, next === void 0 ? index : next - 1);
|
|
2856
|
-
const childEmitted = next === void 0 ? appendInlineLeaf(index, context.view.mapSpan(childOffset, childEnd), output, context) : true;
|
|
2857
|
-
index = next ?? index + 1;
|
|
2858
|
-
if (!childEmitted) continue;
|
|
2859
|
-
output.cursor = childEnd;
|
|
2860
|
-
}
|
|
2861
|
-
if (closeKind !== void 0 && index < endToken && output.cursor !== void 0) {
|
|
2862
|
-
const contentEnd = inlineTokenStart(context.tokens, index);
|
|
2863
|
-
if (contentEnd > output.cursor) appendInlineGap(output, context, output.cursor, contentEnd);
|
|
2864
|
-
}
|
|
2865
|
-
return index;
|
|
2866
|
-
}
|
|
2867
|
-
function buildInlineSemantic(openToken, endToken, output, context) {
|
|
2868
|
-
const kind = inlineTokenKind(context.tokens, openToken);
|
|
2869
|
-
const container = context.schema.containerByKind[kind];
|
|
2870
|
-
if (container) {
|
|
2871
|
-
let closeToken = openToken;
|
|
2872
|
-
let next = openToken + 1;
|
|
2873
|
-
const children = [];
|
|
2874
|
-
if (next < endToken && inlineTokenKind(context.tokens, next) === container.contentOpenKind) {
|
|
2875
|
-
const contentStart = inlineTokenEnd(context.tokens, next++);
|
|
2876
|
-
closeToken = appendInlineRange(next, endToken, context, children, contentStart, container.closeKind);
|
|
2877
|
-
if (closeToken >= endToken || inlineTokenKind(context.tokens, closeToken) !== container.closeKind) throw new Error(`Resolved inline stream did not close token kind ${kind}`);
|
|
2878
|
-
next = closeToken + 1;
|
|
2743
|
+
start: tokens.start(tokenStart),
|
|
2744
|
+
end: blockEnd(tokenStart, context)
|
|
2879
2745
|
}
|
|
2880
|
-
appendInline(output, context, container.build(openToken, closeToken, context.view.mapSpan(inlineTokenStart(context.tokens, openToken), inlineTokenEnd(context.tokens, closeToken)), children, context));
|
|
2881
|
-
return next;
|
|
2882
|
-
}
|
|
2883
|
-
const pair = context.schema.pairByOpenKind[kind];
|
|
2884
|
-
if (!pair) return;
|
|
2885
|
-
const contentStart = inlineTokenEnd(context.tokens, openToken);
|
|
2886
|
-
const children = [];
|
|
2887
|
-
const closeToken = appendInlineRange(openToken + 1, endToken, context, children, contentStart, pair.closeKind);
|
|
2888
|
-
if (closeToken >= endToken || inlineTokenKind(context.tokens, closeToken) !== pair.closeKind) throw new Error(`Resolved inline stream did not close token kind ${kind}`);
|
|
2889
|
-
appendInline(output, context, pair.build(openToken, closeToken, context.view.mapSpan(inlineTokenStart(context.tokens, openToken), inlineTokenEnd(context.tokens, closeToken)), children, context));
|
|
2890
|
-
return closeToken + 1;
|
|
2891
|
-
}
|
|
2892
|
-
function buildInlineChildren(tokenStart, context, allowEmpty = false) {
|
|
2893
|
-
const region = context.inline.take(tokenStart);
|
|
2894
|
-
if (!region) {
|
|
2895
|
-
const rule = context.structure.ruleNameOf(tokenStart);
|
|
2896
|
-
if (allowEmpty) return [];
|
|
2897
|
-
throw new Error(`Expected ${rule} syntax to contain inline content`);
|
|
2898
|
-
}
|
|
2899
|
-
const inlineContext = {
|
|
2900
|
-
blockRule: region.rule,
|
|
2901
|
-
decodeText: context.profile.decodeText,
|
|
2902
|
-
schema: context.profile.schema,
|
|
2903
|
-
source: context.source,
|
|
2904
|
-
tokenHandlers: context.profile.tokenHandlers,
|
|
2905
|
-
tokens: region.tokens,
|
|
2906
|
-
view: region.view
|
|
2907
2746
|
};
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2747
|
+
};
|
|
2748
|
+
function feature$11(marker) {
|
|
2749
|
+
return { block: {
|
|
2750
|
+
restart(source, lines, changedStart) {
|
|
2751
|
+
const opening = lines[0];
|
|
2752
|
+
if (!opening) return;
|
|
2753
|
+
if (!frontmatterFenceAt(source, opening, marker)) return changedStart < opening.next ? 0 : void 0;
|
|
2754
|
+
for (let index = 1; index < lines.length; index++) if (frontmatterFenceAt(source, lines[index], marker)) return changedStart < lines[index].next ? 0 : void 0;
|
|
2755
|
+
return 0;
|
|
2756
|
+
},
|
|
2757
|
+
rules: [{
|
|
2758
|
+
rule: 20,
|
|
2759
|
+
syntax: {
|
|
2760
|
+
kind: "leaf",
|
|
2761
|
+
token: 22
|
|
2762
|
+
},
|
|
2763
|
+
build: buildFrontmatter
|
|
2764
|
+
}],
|
|
2765
|
+
starts: [{
|
|
2766
|
+
codes: [marker.charCodeAt(0)],
|
|
2767
|
+
start(source, lines, start, out) {
|
|
2768
|
+
if (lines[start].start !== 0 || !frontmatterFenceAt(source, lines[start], marker)) return;
|
|
2769
|
+
for (let end = start + 1; end < lines.length; end++) if (frontmatterFenceAt(source, lines[end], marker)) {
|
|
2770
|
+
appendLogicalToken(out, 22, source, lines, start, end + 1);
|
|
2771
|
+
return end + 1;
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
}]
|
|
2775
|
+
} };
|
|
2919
2776
|
}
|
|
2920
2777
|
//#endregion
|
|
2921
2778
|
//#region src/profile/features/component/block.ts
|
|
@@ -3063,15 +2920,14 @@ function nextSlot(source, lines, start, end) {
|
|
|
3063
2920
|
}
|
|
3064
2921
|
}
|
|
3065
2922
|
function emitSlotOpening(source, opening, out) {
|
|
3066
|
-
out.push(
|
|
3067
|
-
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(
|
|
2923
|
+
out.push(44, opening.offset, opening.nameEnd);
|
|
2924
|
+
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(42, opening.attributesStart, opening.attributesEnd);
|
|
3068
2925
|
}
|
|
3069
2926
|
function emitComponentBody(source, lines, start, end, closingOffset, out, context) {
|
|
3070
2927
|
let cursor = start;
|
|
3071
2928
|
const yaml = cursor < end ? yamlPropsAt(source, lines, cursor, end) : void 0;
|
|
3072
2929
|
if (yaml) {
|
|
3073
|
-
|
|
3074
|
-
else out.push(44, lines[yaml.open].end, lines[yaml.open].end);
|
|
2930
|
+
appendLogicalToken(out, 43, source, lines, yaml.open, yaml.close + 1);
|
|
3075
2931
|
cursor = yaml.close + 1;
|
|
3076
2932
|
}
|
|
3077
2933
|
let slot = nextSlot(source, lines, cursor, end);
|
|
@@ -3086,38 +2942,28 @@ function emitComponentBody(source, lines, start, end, closingOffset, out, contex
|
|
|
3086
2942
|
emitSlotOpening(source, slot.opening, out);
|
|
3087
2943
|
context.scanLines(source, lines.slice(slot.index + 1, next), out);
|
|
3088
2944
|
const slotEnd = following ? following.opening.offset : closingOffset;
|
|
3089
|
-
out.push(
|
|
2945
|
+
out.push(45, slotEnd, slotEnd);
|
|
3090
2946
|
slot = following;
|
|
3091
2947
|
}
|
|
3092
2948
|
}
|
|
3093
2949
|
function emitOpening(source, contentOffset, opening, out) {
|
|
3094
|
-
out.push(
|
|
2950
|
+
out.push(38, contentOffset, opening.nameEnd);
|
|
3095
2951
|
if (opening.labelStart !== void 0 && opening.labelEnd !== void 0) {
|
|
3096
|
-
out.push(
|
|
2952
|
+
out.push(40, opening.labelStart, opening.labelStart + 1);
|
|
3097
2953
|
if (opening.labelEnd > opening.labelStart + 2) out.push(1, opening.labelStart + 1, opening.labelEnd - 1);
|
|
3098
|
-
out.push(
|
|
2954
|
+
out.push(41, opening.labelEnd - 1, opening.labelEnd);
|
|
3099
2955
|
}
|
|
3100
|
-
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(
|
|
2956
|
+
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(42, opening.attributesStart, opening.attributesEnd);
|
|
3101
2957
|
}
|
|
3102
|
-
|
|
3103
|
-
const
|
|
3104
|
-
|
|
3105
|
-
if (typeof value !== "object" || Array.isArray(value)) throw new TypeError("Component YAML props must be a mapping");
|
|
3106
|
-
return value;
|
|
3107
|
-
}
|
|
3108
|
-
function directRule(tokenStart, rule, context) {
|
|
3109
|
-
const structure = context.structure;
|
|
3110
|
-
for (let child = structure.firstChild(tokenStart); child !== noBlockEntry; child = structure.nextChild(tokenStart, child)) if (child >= 0 && structure.ruleNameOf(child) === rule) return child;
|
|
3111
|
-
}
|
|
3112
|
-
const buildBlockLabel = (tokenStart, context) => {
|
|
3113
|
-
const open = blockToken(tokenStart, 41, context);
|
|
3114
|
-
const close = blockToken(tokenStart, 42, context);
|
|
2958
|
+
const buildBlockLabel = (tokenStart, context, inline) => {
|
|
2959
|
+
const tokens = context.structure.tokens;
|
|
2960
|
+
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
3115
2961
|
return {
|
|
3116
2962
|
type: "paragraph",
|
|
3117
|
-
children:
|
|
2963
|
+
children: inline.children,
|
|
3118
2964
|
position: {
|
|
3119
|
-
start:
|
|
3120
|
-
end:
|
|
2965
|
+
start: tokens.start(tokenStart),
|
|
2966
|
+
end: tokens.end(close)
|
|
3121
2967
|
}
|
|
3122
2968
|
};
|
|
3123
2969
|
};
|
|
@@ -3127,85 +2973,91 @@ function createBlockStart(shorthand) {
|
|
|
3127
2973
|
if (!opening) return;
|
|
3128
2974
|
if (shorthand) {
|
|
3129
2975
|
emitOpening(source, contentOffset, opening, out);
|
|
3130
|
-
out.push(
|
|
2976
|
+
out.push(39, lines[start].end, lines[start].end);
|
|
3131
2977
|
return start + 1;
|
|
3132
2978
|
}
|
|
3133
2979
|
const closing = blockClose(source, lines, start, opening);
|
|
3134
2980
|
if (!closing) return;
|
|
3135
2981
|
emitOpening(source, contentOffset, opening, out);
|
|
3136
2982
|
emitComponentBody(source, lines, start + 1, closing.index, closing.offset, out, context);
|
|
3137
|
-
out.push(
|
|
2983
|
+
out.push(39, closing.offset, lines[closing.index].end);
|
|
3138
2984
|
return closing.index + 1;
|
|
3139
2985
|
};
|
|
3140
2986
|
}
|
|
3141
2987
|
const blockRules$2 = [
|
|
3142
2988
|
{
|
|
3143
|
-
rule:
|
|
2989
|
+
rule: 11,
|
|
2990
|
+
syntax: {
|
|
2991
|
+
kind: "leaf",
|
|
2992
|
+
token: 43
|
|
2993
|
+
},
|
|
2994
|
+
build: buildFrontmatter
|
|
2995
|
+
},
|
|
2996
|
+
{
|
|
2997
|
+
rule: 10,
|
|
3144
2998
|
syntax: {
|
|
3145
2999
|
kind: "frame",
|
|
3146
|
-
open:
|
|
3147
|
-
close:
|
|
3000
|
+
open: 40,
|
|
3001
|
+
close: 41
|
|
3148
3002
|
},
|
|
3149
3003
|
inlineContent: true,
|
|
3150
3004
|
build: buildBlockLabel
|
|
3151
3005
|
},
|
|
3152
3006
|
{
|
|
3153
|
-
rule:
|
|
3007
|
+
rule: 12,
|
|
3154
3008
|
syntax: {
|
|
3155
3009
|
kind: "block",
|
|
3156
|
-
open:
|
|
3157
|
-
close:
|
|
3010
|
+
open: 38,
|
|
3011
|
+
close: 39
|
|
3158
3012
|
},
|
|
3159
3013
|
build(tokenStart, context) {
|
|
3160
|
-
const
|
|
3161
|
-
const close =
|
|
3162
|
-
|
|
3163
|
-
const
|
|
3164
|
-
|
|
3165
|
-
const
|
|
3014
|
+
const tokens = context.structure.tokens;
|
|
3015
|
+
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
3016
|
+
let openingToken = tokenStart + 1;
|
|
3017
|
+
const label = tokens.kind(openingToken) === 40 ? openingToken : void 0;
|
|
3018
|
+
if (label !== void 0) openingToken += tokens.nodeLength(label);
|
|
3019
|
+
const attributesToken = tokens.kind(openingToken) === 42 ? openingToken++ : void 0;
|
|
3020
|
+
const parsed = attributesToken !== void 0 ? parseAttributes(context.source, tokens.start(attributesToken)) : void 0;
|
|
3166
3021
|
const children = [];
|
|
3167
|
-
if (label) children.push(buildBlockLabel(label, context));
|
|
3022
|
+
if (label) children.push(buildBlockLabel(label, context, buildInlineFragment(label, context)));
|
|
3168
3023
|
children.push(...buildBlockChildren(tokenStart, context));
|
|
3169
|
-
const opening =
|
|
3024
|
+
const opening = tokens.text(context.source, tokenStart);
|
|
3170
3025
|
return {
|
|
3171
3026
|
type: "blockComponent",
|
|
3172
3027
|
name: normalizeComponentName(opening.slice(opening.lastIndexOf(":") + 1).trim()),
|
|
3173
|
-
attributes:
|
|
3174
|
-
...parseYamlAttributes(yamlToken, context),
|
|
3175
|
-
...parsed?.attributes
|
|
3176
|
-
} : parsed?.attributes ?? {},
|
|
3028
|
+
attributes: parsed?.attributes ?? {},
|
|
3177
3029
|
position: {
|
|
3178
|
-
start:
|
|
3179
|
-
end:
|
|
3030
|
+
start: tokens.start(tokenStart),
|
|
3031
|
+
end: tokens.end(close)
|
|
3180
3032
|
},
|
|
3181
3033
|
children
|
|
3182
3034
|
};
|
|
3183
3035
|
}
|
|
3184
3036
|
},
|
|
3185
3037
|
{
|
|
3186
|
-
rule:
|
|
3038
|
+
rule: 13,
|
|
3187
3039
|
syntax: {
|
|
3188
3040
|
kind: "block",
|
|
3189
|
-
open:
|
|
3190
|
-
close:
|
|
3041
|
+
open: 44,
|
|
3042
|
+
close: 45
|
|
3191
3043
|
},
|
|
3192
3044
|
build(tokenStart, context) {
|
|
3193
|
-
const
|
|
3194
|
-
const close =
|
|
3195
|
-
const attributesToken =
|
|
3196
|
-
const parsed = attributesToken !== void 0 ? parseAttributes(context.source,
|
|
3045
|
+
const tokens = context.structure.tokens;
|
|
3046
|
+
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
3047
|
+
const attributesToken = tokens.kind(tokenStart + 1) === 42 ? tokenStart + 1 : void 0;
|
|
3048
|
+
const parsed = attributesToken !== void 0 ? parseAttributes(context.source, tokens.start(attributesToken)) : void 0;
|
|
3197
3049
|
const children = buildBlockChildren(tokenStart, context);
|
|
3198
3050
|
return {
|
|
3199
3051
|
type: "blockComponent",
|
|
3200
3052
|
name: "template",
|
|
3201
3053
|
attributes: {
|
|
3202
3054
|
...parsed?.attributes,
|
|
3203
|
-
name: normalizeComponentName(
|
|
3055
|
+
name: normalizeComponentName(tokens.text(context.source, tokenStart).slice(1).trim())
|
|
3204
3056
|
},
|
|
3205
3057
|
children,
|
|
3206
3058
|
position: {
|
|
3207
|
-
start:
|
|
3208
|
-
end:
|
|
3059
|
+
start: tokens.start(tokenStart),
|
|
3060
|
+
end: tokens.end(close)
|
|
3209
3061
|
}
|
|
3210
3062
|
};
|
|
3211
3063
|
}
|
|
@@ -3228,12 +3080,12 @@ function inlineComponentEnd(source, start) {
|
|
|
3228
3080
|
if (start > 0 && previous !== " " && previous !== " " && previous !== "\n" && previous !== "\r" && previous !== "*" && previous !== "_" && previous !== "[") return;
|
|
3229
3081
|
return componentNameEnd(source, start + 1, false);
|
|
3230
3082
|
}
|
|
3231
|
-
const
|
|
3083
|
+
const inlineScans = [{
|
|
3232
3084
|
marker: 58,
|
|
3233
3085
|
scan(source, start, tokens) {
|
|
3234
3086
|
const end = inlineComponentEnd(source, start);
|
|
3235
3087
|
if (end === void 0) return -1;
|
|
3236
|
-
appendInlineToken(tokens,
|
|
3088
|
+
appendInlineToken(tokens, 33, start, end);
|
|
3237
3089
|
return end;
|
|
3238
3090
|
}
|
|
3239
3091
|
}];
|
|
@@ -3260,7 +3112,7 @@ function candidates(source, tokens) {
|
|
|
3260
3112
|
const componentIndex = index - 1;
|
|
3261
3113
|
bracketStack.push({
|
|
3262
3114
|
children: [],
|
|
3263
|
-
componentIndex: componentIndex >= 0 && inlineTokenKind(tokens, componentIndex) ===
|
|
3115
|
+
componentIndex: componentIndex >= 0 && inlineTokenKind(tokens, componentIndex) === 33 && inlineTokenEnd(tokens, componentIndex) === start ? componentIndex : -1,
|
|
3264
3116
|
image: false,
|
|
3265
3117
|
start,
|
|
3266
3118
|
tokenIndex: index
|
|
@@ -3277,7 +3129,7 @@ function candidates(source, tokens) {
|
|
|
3277
3129
|
});
|
|
3278
3130
|
continue;
|
|
3279
3131
|
}
|
|
3280
|
-
if (kind !==
|
|
3132
|
+
if (kind !== 22 && kind !== 21) continue;
|
|
3281
3133
|
const open = bracketStack.pop();
|
|
3282
3134
|
if (!open) continue;
|
|
3283
3135
|
const parent = bracketStack.at(-1)?.children ?? roots;
|
|
@@ -3288,7 +3140,7 @@ function candidates(source, tokens) {
|
|
|
3288
3140
|
const close = inlineTokenStart(tokens, index);
|
|
3289
3141
|
normalClosers.add(close);
|
|
3290
3142
|
let children = open.children;
|
|
3291
|
-
if (kind === 21
|
|
3143
|
+
if (kind === 21) {
|
|
3292
3144
|
children = [];
|
|
3293
3145
|
appendLinkCandidates(children, open.children);
|
|
3294
3146
|
}
|
|
@@ -3308,24 +3160,6 @@ function candidates(source, tokens) {
|
|
|
3308
3160
|
nameEnd: open.start,
|
|
3309
3161
|
start
|
|
3310
3162
|
});
|
|
3311
|
-
if (kind === 22) {
|
|
3312
|
-
const suffixStart = close + 1;
|
|
3313
|
-
const suffixEnd = inlineTokenEnd(tokens, index);
|
|
3314
|
-
const suffixClose = suffixEnd - 1;
|
|
3315
|
-
parent.push({
|
|
3316
|
-
children: [],
|
|
3317
|
-
close: suffixClose,
|
|
3318
|
-
contentEnd: suffixClose,
|
|
3319
|
-
contentStart: suffixStart + 1,
|
|
3320
|
-
end: suffixEnd,
|
|
3321
|
-
flags,
|
|
3322
|
-
inLinkLabel: false,
|
|
3323
|
-
kind: "span",
|
|
3324
|
-
literalInLink: false,
|
|
3325
|
-
nameEnd: suffixStart + 1,
|
|
3326
|
-
start: suffixStart
|
|
3327
|
-
});
|
|
3328
|
-
}
|
|
3329
3163
|
continue;
|
|
3330
3164
|
}
|
|
3331
3165
|
if (source[close + 1] === "(" || source[close + 1] === "[") {
|
|
@@ -3365,7 +3199,7 @@ function copyRange(target, tokens, start, end, inLinkLabel, normalClosers) {
|
|
|
3365
3199
|
const tokenEnd = inlineTokenEnd(tokens, index);
|
|
3366
3200
|
const fragmentStart = Math.max(start, tokenStart);
|
|
3367
3201
|
const fragmentEnd = Math.min(end, tokenEnd);
|
|
3368
|
-
appendInlineToken(target, inLinkLabel && (kind === 20 || normalClosers.has(tokenStart) && (kind === 21 || kind === 22
|
|
3202
|
+
appendInlineToken(target, inLinkLabel && (kind === 20 || normalClosers.has(tokenStart) && (kind === 21 || kind === 22)) || fragmentStart !== tokenStart || fragmentEnd !== tokenEnd ? 9 : kind, fragmentStart, fragmentEnd, fragmentStart === tokenStart ? inlineTokenFlags(tokens, index) : 0);
|
|
3369
3203
|
}
|
|
3370
3204
|
}
|
|
3371
3205
|
function emitRange(target, tokens, start, end, nested, inLinkLabel, normalClosers) {
|
|
@@ -3373,22 +3207,22 @@ function emitRange(target, tokens, start, end, nested, inLinkLabel, normalCloser
|
|
|
3373
3207
|
for (const candidate of nested) {
|
|
3374
3208
|
copyRange(target, tokens, cursor, candidate.start, inLinkLabel, normalClosers);
|
|
3375
3209
|
if (candidate.kind === "component") {
|
|
3376
|
-
appendInlineToken(target,
|
|
3210
|
+
appendInlineToken(target, 33, candidate.start, candidate.nameEnd, candidate.flags);
|
|
3377
3211
|
if (candidate.contentStart < candidate.contentEnd) {
|
|
3378
|
-
appendInlineToken(target,
|
|
3212
|
+
appendInlineToken(target, 34, candidate.nameEnd, candidate.contentStart);
|
|
3379
3213
|
emitRange(target, tokens, candidate.contentStart, candidate.contentEnd, candidate.children, candidate.inLinkLabel, normalClosers);
|
|
3380
|
-
appendInlineToken(target,
|
|
3214
|
+
appendInlineToken(target, 35, candidate.close, candidate.close + 1);
|
|
3381
3215
|
}
|
|
3382
3216
|
} else {
|
|
3383
|
-
appendInlineToken(target,
|
|
3217
|
+
appendInlineToken(target, 37, candidate.start, candidate.contentStart, candidate.flags);
|
|
3384
3218
|
emitRange(target, tokens, candidate.contentStart, candidate.contentEnd, candidate.children, candidate.inLinkLabel, normalClosers);
|
|
3385
|
-
appendInlineToken(target,
|
|
3219
|
+
appendInlineToken(target, 38, candidate.close, candidate.close + 1);
|
|
3386
3220
|
}
|
|
3387
3221
|
cursor = candidate.end;
|
|
3388
3222
|
}
|
|
3389
3223
|
copyRange(target, tokens, cursor, end, inLinkLabel, normalClosers);
|
|
3390
3224
|
}
|
|
3391
|
-
function
|
|
3225
|
+
function transformComponentTokens(source, tokens) {
|
|
3392
3226
|
if (!source.includes("[")) return tokens;
|
|
3393
3227
|
const syntax = candidates(source, tokens);
|
|
3394
3228
|
if (syntax.roots.length === 0) return tokens;
|
|
@@ -3398,20 +3232,19 @@ function rewriteComponentTokens(source, tokens) {
|
|
|
3398
3232
|
}
|
|
3399
3233
|
//#endregion
|
|
3400
3234
|
//#region src/profile/features/component/index.ts
|
|
3401
|
-
const feature$
|
|
3235
|
+
const feature$10 = {
|
|
3402
3236
|
block: {
|
|
3403
3237
|
rules: blockRules$2,
|
|
3404
3238
|
starts: blockStarts$2
|
|
3405
3239
|
},
|
|
3406
3240
|
inline: {
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3241
|
+
scan: inlineScans,
|
|
3242
|
+
resolve: { transform: transformComponentTokens },
|
|
3243
|
+
build: [{
|
|
3410
3244
|
kind: "container",
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
close: 37,
|
|
3245
|
+
token: 33,
|
|
3246
|
+
contentOpen: 34,
|
|
3247
|
+
close: 35,
|
|
3415
3248
|
build(open, close, sourceSpan, children, context) {
|
|
3416
3249
|
return {
|
|
3417
3250
|
type: "inlineComponent",
|
|
@@ -3423,9 +3256,8 @@ const feature$11 = {
|
|
|
3423
3256
|
}
|
|
3424
3257
|
}, {
|
|
3425
3258
|
kind: "pair",
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
close: 40,
|
|
3259
|
+
open: 37,
|
|
3260
|
+
close: 38,
|
|
3429
3261
|
build(open, close, sourceSpan, children) {
|
|
3430
3262
|
return {
|
|
3431
3263
|
type: "inlineComponent",
|
|
@@ -3441,20 +3273,21 @@ const feature$11 = {
|
|
|
3441
3273
|
//#endregion
|
|
3442
3274
|
//#region src/profile/utils.ts
|
|
3443
3275
|
function normalizeAssociationLabel(label) {
|
|
3276
|
+
scan: {
|
|
3277
|
+
let hasLowercase = false;
|
|
3278
|
+
for (let index = 0; index < label.length; index++) {
|
|
3279
|
+
const code = label.charCodeAt(index);
|
|
3280
|
+
if (code === 32) {
|
|
3281
|
+
if (index === 0 || index + 1 === label.length || label.charCodeAt(index + 1) === 32) break scan;
|
|
3282
|
+
continue;
|
|
3283
|
+
}
|
|
3284
|
+
if (code < 32 || code > 126) break scan;
|
|
3285
|
+
if (code >= 97 && code <= 122) hasLowercase = true;
|
|
3286
|
+
}
|
|
3287
|
+
return hasLowercase ? label.toUpperCase() : label;
|
|
3288
|
+
}
|
|
3444
3289
|
return label.trim().replace(/[ \t\r\n]+/g, " ").toLowerCase().toUpperCase();
|
|
3445
3290
|
}
|
|
3446
|
-
function splitReferenceTail(tokens, index) {
|
|
3447
|
-
const start = inlineTokenStart(tokens, index);
|
|
3448
|
-
const end = inlineTokenEnd(tokens, index);
|
|
3449
|
-
const flags = inlineTokenFlags(tokens, index);
|
|
3450
|
-
const decodeFlags = flags & 16;
|
|
3451
|
-
const result = [];
|
|
3452
|
-
appendInlineToken(result, 24, start, start + 1, flags & -17);
|
|
3453
|
-
appendInlineToken(result, 20, start + 1, start + 2);
|
|
3454
|
-
if (end > start + 3) appendInlineToken(result, 9, start + 2, end - 1, decodeFlags);
|
|
3455
|
-
appendInlineToken(result, 23, end - 1, end);
|
|
3456
|
-
return result;
|
|
3457
|
-
}
|
|
3458
3291
|
//#endregion
|
|
3459
3292
|
//#region src/profile/features/footnote/shared.ts
|
|
3460
3293
|
const footnoteDefinitionPrefix = "footnote\0";
|
|
@@ -3519,22 +3352,21 @@ function firstContentLine(line, match) {
|
|
|
3519
3352
|
};
|
|
3520
3353
|
}
|
|
3521
3354
|
const blockRules$1 = [{
|
|
3522
|
-
rule:
|
|
3355
|
+
rule: 21,
|
|
3523
3356
|
syntax: {
|
|
3524
3357
|
kind: "block",
|
|
3525
3358
|
open: 24,
|
|
3526
3359
|
close: 25
|
|
3527
3360
|
},
|
|
3528
3361
|
build(tokenStart, context) {
|
|
3529
|
-
const
|
|
3530
|
-
const fields = definitionFields(context.structure.tokens, token);
|
|
3362
|
+
const fields = definitionFields(context.structure.tokens, tokenStart);
|
|
3531
3363
|
return {
|
|
3532
3364
|
type: "footnoteDefinition",
|
|
3533
3365
|
identifier: fields.normalizedLabel.toLowerCase(),
|
|
3534
3366
|
label: semanticText(fields.label),
|
|
3535
3367
|
children: buildBlockChildren(tokenStart, context),
|
|
3536
3368
|
position: {
|
|
3537
|
-
start: context.structure.tokens.start(
|
|
3369
|
+
start: context.structure.tokens.start(tokenStart),
|
|
3538
3370
|
end: blockEnd(tokenStart, context)
|
|
3539
3371
|
}
|
|
3540
3372
|
};
|
|
@@ -3602,12 +3434,11 @@ const blockStarts$1 = [{
|
|
|
3602
3434
|
function closerIndex(tokens, start, end) {
|
|
3603
3435
|
for (let index = start + 1; index < inlineTokenCount(tokens); index++) {
|
|
3604
3436
|
if (inlineTokenStart(tokens, index) >= end) break;
|
|
3605
|
-
|
|
3606
|
-
if (inlineTokenEnd(tokens, index) === end && (kind === 23 || kind === 24) || kind === 22 && inlineTokenStart(tokens, index) + 1 === end) return index;
|
|
3437
|
+
if (inlineTokenKind(tokens, index) === 22 && inlineTokenEnd(tokens, index) === end) return index;
|
|
3607
3438
|
}
|
|
3608
3439
|
return -1;
|
|
3609
3440
|
}
|
|
3610
|
-
const
|
|
3441
|
+
const transformFootnoteTokens = (source, tokens, context) => {
|
|
3611
3442
|
let result;
|
|
3612
3443
|
for (let index = 0; index < inlineTokenCount(tokens); index++) {
|
|
3613
3444
|
const start = inlineTokenStart(tokens, index);
|
|
@@ -3621,26 +3452,9 @@ const rewriteFootnoteTokens = (source, tokens, context) => {
|
|
|
3621
3452
|
for (let prefix = 0; prefix < index; prefix++) copyInlineToken(result, tokens, prefix);
|
|
3622
3453
|
}
|
|
3623
3454
|
if (kind === 19) appendInlineToken(result, 9, start, labelStart, inlineTokenFlags(tokens, index));
|
|
3624
|
-
appendInlineToken(result,
|
|
3625
|
-
if (inlineTokenKind(tokens, close) === 22) {
|
|
3626
|
-
const embedded = footnoteLabelAt(source, label.end, inlineTokenEnd(tokens, close));
|
|
3627
|
-
if (embedded && context.hasDefinition(embedded.definitionKey)) appendInlineToken(result, 33, label.end, embedded.end);
|
|
3628
|
-
else result.push(...splitReferenceTail(tokens, close).slice(4));
|
|
3629
|
-
}
|
|
3455
|
+
appendInlineToken(result, 31, labelStart, label.end, inlineTokenFlags(tokens, index));
|
|
3630
3456
|
index = close;
|
|
3631
|
-
continue;
|
|
3632
|
-
}
|
|
3633
|
-
if (kind === 22) {
|
|
3634
|
-
const embedded = footnoteLabelAt(source, start + 1, inlineTokenEnd(tokens, index));
|
|
3635
|
-
if (embedded && context.hasDefinition(embedded.definitionKey)) {
|
|
3636
|
-
if (!result) {
|
|
3637
|
-
result = [];
|
|
3638
|
-
for (let prefix = 0; prefix < index; prefix++) copyInlineToken(result, tokens, prefix);
|
|
3639
|
-
}
|
|
3640
|
-
result.push(...splitReferenceTail(tokens, index).slice(0, 4));
|
|
3641
|
-
appendInlineToken(result, 33, start + 1, embedded.end);
|
|
3642
|
-
continue;
|
|
3643
|
-
}
|
|
3457
|
+
continue;
|
|
3644
3458
|
}
|
|
3645
3459
|
if (result) copyInlineToken(result, tokens, index);
|
|
3646
3460
|
}
|
|
@@ -3648,16 +3462,16 @@ const rewriteFootnoteTokens = (source, tokens, context) => {
|
|
|
3648
3462
|
};
|
|
3649
3463
|
//#endregion
|
|
3650
3464
|
//#region src/profile/features/footnote/index.ts
|
|
3651
|
-
const feature$
|
|
3465
|
+
const feature$9 = {
|
|
3652
3466
|
block: {
|
|
3653
3467
|
rules: blockRules$1,
|
|
3654
3468
|
starts: blockStarts$1
|
|
3655
3469
|
},
|
|
3656
3470
|
inline: {
|
|
3657
|
-
|
|
3658
|
-
|
|
3471
|
+
resolve: { transform: transformFootnoteTokens },
|
|
3472
|
+
build: [{
|
|
3659
3473
|
kind: "leaf",
|
|
3660
|
-
token:
|
|
3474
|
+
token: 31,
|
|
3661
3475
|
build(tokenIndex, sourceSpan, context) {
|
|
3662
3476
|
const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(2, -1);
|
|
3663
3477
|
return {
|
|
@@ -3674,7 +3488,6 @@ const feature$10 = {
|
|
|
3674
3488
|
//#region src/profile/features/formatting.ts
|
|
3675
3489
|
const asteriskDelimiter = {
|
|
3676
3490
|
token: 10,
|
|
3677
|
-
marker: 42,
|
|
3678
3491
|
single: {
|
|
3679
3492
|
open: 13,
|
|
3680
3493
|
close: 14
|
|
@@ -3690,7 +3503,6 @@ const asteriskDelimiter = {
|
|
|
3690
3503
|
};
|
|
3691
3504
|
const underscoreDelimiter = {
|
|
3692
3505
|
token: 11,
|
|
3693
|
-
marker: 95,
|
|
3694
3506
|
single: {
|
|
3695
3507
|
open: 13,
|
|
3696
3508
|
close: 14
|
|
@@ -3707,7 +3519,6 @@ const underscoreDelimiter = {
|
|
|
3707
3519
|
};
|
|
3708
3520
|
const strikethroughDelimiter = {
|
|
3709
3521
|
token: 12,
|
|
3710
|
-
marker: 126,
|
|
3711
3522
|
double: {
|
|
3712
3523
|
open: 17,
|
|
3713
3524
|
close: 18
|
|
@@ -3727,16 +3538,16 @@ function createBuildFormatting(type) {
|
|
|
3727
3538
|
position: sourceSpan
|
|
3728
3539
|
});
|
|
3729
3540
|
}
|
|
3730
|
-
function feature$
|
|
3541
|
+
function feature$8(strikethroughOptions) {
|
|
3731
3542
|
const delimiters = [asteriskDelimiter, underscoreDelimiter];
|
|
3732
|
-
const
|
|
3543
|
+
const scans = [{
|
|
3733
3544
|
marker: 42,
|
|
3734
3545
|
scan: scanFormatting
|
|
3735
3546
|
}, {
|
|
3736
3547
|
marker: 95,
|
|
3737
3548
|
scan: scanFormatting
|
|
3738
3549
|
}];
|
|
3739
|
-
const
|
|
3550
|
+
const builds = [
|
|
3740
3551
|
{
|
|
3741
3552
|
kind: "leaf",
|
|
3742
3553
|
token: 10,
|
|
@@ -3761,7 +3572,7 @@ function feature$9(strikethroughOptions) {
|
|
|
3761
3572
|
}
|
|
3762
3573
|
];
|
|
3763
3574
|
if (strikethroughOptions) {
|
|
3764
|
-
|
|
3575
|
+
scans.push({
|
|
3765
3576
|
marker: 126,
|
|
3766
3577
|
scan: scanFormatting
|
|
3767
3578
|
});
|
|
@@ -3769,7 +3580,7 @@ function feature$9(strikethroughOptions) {
|
|
|
3769
3580
|
...strikethroughDelimiter,
|
|
3770
3581
|
single: strikethroughDelimiter.double
|
|
3771
3582
|
} : strikethroughDelimiter);
|
|
3772
|
-
|
|
3583
|
+
builds.push({
|
|
3773
3584
|
kind: "leaf",
|
|
3774
3585
|
token: 12,
|
|
3775
3586
|
build: buildInlineText
|
|
@@ -3781,59 +3592,9 @@ function feature$9(strikethroughOptions) {
|
|
|
3781
3592
|
});
|
|
3782
3593
|
}
|
|
3783
3594
|
return { inline: {
|
|
3784
|
-
|
|
3785
|
-
delimiters,
|
|
3786
|
-
|
|
3787
|
-
} };
|
|
3788
|
-
}
|
|
3789
|
-
//#endregion
|
|
3790
|
-
//#region src/profile/features/frontmatter.ts
|
|
3791
|
-
function frontmatterFenceAt(source, line, marker) {
|
|
3792
|
-
if (source[line.start] !== marker || source[line.start + 1] !== marker || source[line.start + 2] !== marker) return false;
|
|
3793
|
-
for (let offset = line.start + 3; offset < line.end; offset++) if (source[offset] !== " " && source[offset] !== " ") return false;
|
|
3794
|
-
return true;
|
|
3795
|
-
}
|
|
3796
|
-
function feature$8(marker) {
|
|
3797
|
-
return { block: {
|
|
3798
|
-
restart(source, lines, changedStart) {
|
|
3799
|
-
const opening = lines[0];
|
|
3800
|
-
if (!opening) return;
|
|
3801
|
-
if (!frontmatterFenceAt(source, opening, marker)) return changedStart < opening.next ? 0 : void 0;
|
|
3802
|
-
for (let index = 1; index < lines.length; index++) if (frontmatterFenceAt(source, lines[index], marker)) return changedStart < lines[index].next ? 0 : void 0;
|
|
3803
|
-
return 0;
|
|
3804
|
-
},
|
|
3805
|
-
rules: [{
|
|
3806
|
-
rule: "Frontmatter",
|
|
3807
|
-
syntax: {
|
|
3808
|
-
kind: "leaf",
|
|
3809
|
-
token: 22
|
|
3810
|
-
},
|
|
3811
|
-
build(tokenStart, context) {
|
|
3812
|
-
const token = blockToken(tokenStart, 22, context);
|
|
3813
|
-
const rangeCount = context.structure.tokens.rangeCount(token);
|
|
3814
|
-
if (rangeCount < 2) throw new Error("FrontmatterToken does not contain two fences");
|
|
3815
|
-
let value = normalizeLines(context.source.slice(context.structure.tokens.rangeEnd(token, 0), context.structure.tokens.rangeStart(token, rangeCount - 1)));
|
|
3816
|
-
if (value.endsWith("\n")) value = value.slice(0, -1);
|
|
3817
|
-
return {
|
|
3818
|
-
type: "yaml",
|
|
3819
|
-
value,
|
|
3820
|
-
position: {
|
|
3821
|
-
start: context.structure.tokens.start(token),
|
|
3822
|
-
end: blockEnd(tokenStart, context)
|
|
3823
|
-
}
|
|
3824
|
-
};
|
|
3825
|
-
}
|
|
3826
|
-
}],
|
|
3827
|
-
starts: [{
|
|
3828
|
-
codes: [marker.charCodeAt(0)],
|
|
3829
|
-
start(source, lines, start, out) {
|
|
3830
|
-
if (lines[start].start !== 0 || !frontmatterFenceAt(source, lines[start], marker)) return;
|
|
3831
|
-
for (let end = start + 1; end < lines.length; end++) if (frontmatterFenceAt(source, lines[end], marker)) {
|
|
3832
|
-
appendLogicalToken(out, 22, source, lines, start, end + 1);
|
|
3833
|
-
return end + 1;
|
|
3834
|
-
}
|
|
3835
|
-
}
|
|
3836
|
-
}]
|
|
3595
|
+
scan: scans,
|
|
3596
|
+
resolve: { delimiters },
|
|
3597
|
+
build: builds
|
|
3837
3598
|
} };
|
|
3838
3599
|
}
|
|
3839
3600
|
//#endregion
|
|
@@ -3870,44 +3631,43 @@ function setextMarkerAt(source, line) {
|
|
|
3870
3631
|
}
|
|
3871
3632
|
const feature$7 = { block: {
|
|
3872
3633
|
rules: [{
|
|
3873
|
-
rule:
|
|
3634
|
+
rule: 0,
|
|
3874
3635
|
syntax: {
|
|
3875
3636
|
kind: "block",
|
|
3876
3637
|
open: 5,
|
|
3877
3638
|
close: 8
|
|
3878
3639
|
},
|
|
3879
3640
|
inlineContent: true,
|
|
3880
|
-
build(tokenStart, context) {
|
|
3881
|
-
const
|
|
3641
|
+
build(tokenStart, context, inline) {
|
|
3642
|
+
const tokens = context.structure.tokens;
|
|
3882
3643
|
return {
|
|
3883
3644
|
type: "heading",
|
|
3884
|
-
depth:
|
|
3885
|
-
children:
|
|
3645
|
+
depth: tokens.end(tokenStart) - tokens.start(tokenStart),
|
|
3646
|
+
children: inline.children,
|
|
3886
3647
|
position: {
|
|
3887
|
-
start:
|
|
3648
|
+
start: tokens.start(tokenStart),
|
|
3888
3649
|
end: blockEnd(tokenStart, context)
|
|
3889
3650
|
}
|
|
3890
3651
|
};
|
|
3891
3652
|
}
|
|
3892
3653
|
}, {
|
|
3893
|
-
rule:
|
|
3654
|
+
rule: 1,
|
|
3894
3655
|
syntax: {
|
|
3895
3656
|
kind: "block",
|
|
3896
3657
|
open: [6, 7],
|
|
3897
3658
|
close: 8
|
|
3898
3659
|
},
|
|
3899
3660
|
inlineContent: true,
|
|
3900
|
-
build(tokenStart, context) {
|
|
3901
|
-
const
|
|
3902
|
-
|
|
3903
|
-
const children = buildInlineChildren(tokenStart, context);
|
|
3661
|
+
build(tokenStart, context, inline) {
|
|
3662
|
+
const tokens = context.structure.tokens;
|
|
3663
|
+
const children = inline.children;
|
|
3904
3664
|
return {
|
|
3905
3665
|
type: "heading",
|
|
3906
|
-
depth:
|
|
3666
|
+
depth: tokens.kind(tokenStart) === 6 ? 1 : 2,
|
|
3907
3667
|
children,
|
|
3908
3668
|
position: {
|
|
3909
3669
|
start: firstChildStart(children),
|
|
3910
|
-
end:
|
|
3670
|
+
end: tokens.start(tokenStart + tokens.nodeLength(tokenStart) - 1)
|
|
3911
3671
|
}
|
|
3912
3672
|
};
|
|
3913
3673
|
}
|
|
@@ -4048,7 +3808,7 @@ const buildInlineHtml = (tokenIndex, sourceSpan, context) => {
|
|
|
4048
3808
|
const feature$6 = {
|
|
4049
3809
|
block: {
|
|
4050
3810
|
rules: [{
|
|
4051
|
-
rule:
|
|
3811
|
+
rule: 14,
|
|
4052
3812
|
syntax: {
|
|
4053
3813
|
kind: "leaf",
|
|
4054
3814
|
token: 23
|
|
@@ -4056,9 +3816,8 @@ const feature$6 = {
|
|
|
4056
3816
|
build(tokenStart, context) {
|
|
4057
3817
|
const offset = context.structure.tokens.start(tokenStart);
|
|
4058
3818
|
const end = offset + context.structure.lenOf(tokenStart);
|
|
4059
|
-
const
|
|
4060
|
-
|
|
4061
|
-
let html = normalizeLines(context.structure.tokens.text(context.source, token));
|
|
3819
|
+
const unterminated = htmlBlockUnterminated(tokenStart, context);
|
|
3820
|
+
let html = normalizeLines(context.structure.tokens.text(context.source, tokenStart));
|
|
4062
3821
|
if (!unterminated && html.endsWith("\n")) html = html.slice(0, -1);
|
|
4063
3822
|
return {
|
|
4064
3823
|
type: "html",
|
|
@@ -4092,7 +3851,7 @@ const feature$6 = {
|
|
|
4092
3851
|
}]
|
|
4093
3852
|
},
|
|
4094
3853
|
inline: {
|
|
4095
|
-
|
|
3854
|
+
scan: [{
|
|
4096
3855
|
marker: 60,
|
|
4097
3856
|
scan(source, start, tokens) {
|
|
4098
3857
|
let end = matchInlinePatternEnd(htmlComment, source, start);
|
|
@@ -4107,13 +3866,13 @@ const feature$6 = {
|
|
|
4107
3866
|
}
|
|
4108
3867
|
if (end < 0) {
|
|
4109
3868
|
end = start + 1;
|
|
4110
|
-
kind =
|
|
3869
|
+
kind = 39;
|
|
4111
3870
|
}
|
|
4112
3871
|
appendInlineToken(tokens, kind, start, end);
|
|
4113
3872
|
return end;
|
|
4114
3873
|
}
|
|
4115
3874
|
}],
|
|
4116
|
-
|
|
3875
|
+
build: [{
|
|
4117
3876
|
kind: "leaf",
|
|
4118
3877
|
token: 5,
|
|
4119
3878
|
build: buildInlineHtml
|
|
@@ -4206,28 +3965,6 @@ function linkTailEnd(source, start) {
|
|
|
4206
3965
|
offset = skipWhitespace(source, offset);
|
|
4207
3966
|
return source.charCodeAt(offset) === 41 ? offset + 1 : -1;
|
|
4208
3967
|
}
|
|
4209
|
-
function referenceTailEnd(source, start) {
|
|
4210
|
-
if (source.charCodeAt(start + 1) !== 91) return -1;
|
|
4211
|
-
let offset = start + 2;
|
|
4212
|
-
if (source.charCodeAt(offset) === 93) return offset + 1;
|
|
4213
|
-
let characters = 0;
|
|
4214
|
-
let hasContent = false;
|
|
4215
|
-
while (offset < source.length && characters < 999) {
|
|
4216
|
-
const code = source.charCodeAt(offset);
|
|
4217
|
-
if (code === 93) return hasContent ? offset + 1 : -1;
|
|
4218
|
-
if (code === 91) return -1;
|
|
4219
|
-
if (code === 92) {
|
|
4220
|
-
if (offset + 1 >= source.length) return -1;
|
|
4221
|
-
hasContent = true;
|
|
4222
|
-
offset += 2;
|
|
4223
|
-
} else {
|
|
4224
|
-
hasContent ||= !isLinkWhitespace(code);
|
|
4225
|
-
offset++;
|
|
4226
|
-
}
|
|
4227
|
-
characters++;
|
|
4228
|
-
}
|
|
4229
|
-
return -1;
|
|
4230
|
-
}
|
|
4231
3968
|
function isLinkWhitespace(code) {
|
|
4232
3969
|
return code === 9 || code === 10 || code === 13 || code === 32;
|
|
4233
3970
|
}
|
|
@@ -4319,13 +4056,13 @@ const buildInlineReferenceImage = createBuildMedia("image", "reference");
|
|
|
4319
4056
|
const buildInlineLink = createBuildMedia("link", "direct");
|
|
4320
4057
|
const buildInlineReferenceLink = createBuildMedia("link", "reference");
|
|
4321
4058
|
const feature$5 = { inline: {
|
|
4322
|
-
|
|
4059
|
+
scan: [
|
|
4323
4060
|
{
|
|
4324
4061
|
marker: 33,
|
|
4325
4062
|
scan(source, start, tokens) {
|
|
4326
4063
|
const image = source.charCodeAt(start + 1) === 91;
|
|
4327
4064
|
const end = start + (image ? 2 : 1);
|
|
4328
|
-
appendInlineToken(tokens, image ? 19 :
|
|
4065
|
+
appendInlineToken(tokens, image ? 19 : 39, start, end);
|
|
4329
4066
|
return end;
|
|
4330
4067
|
}
|
|
4331
4068
|
},
|
|
@@ -4342,42 +4079,38 @@ const feature$5 = { inline: {
|
|
|
4342
4079
|
scan(source, start, tokens) {
|
|
4343
4080
|
let end = linkTailEnd(source, start);
|
|
4344
4081
|
let kind = 21;
|
|
4345
|
-
if (end < 0) {
|
|
4346
|
-
end = referenceTailEnd(source, start);
|
|
4347
|
-
kind = 22;
|
|
4348
|
-
}
|
|
4349
4082
|
if (end < 0) {
|
|
4350
4083
|
end = start + 1;
|
|
4351
|
-
kind =
|
|
4084
|
+
kind = 22;
|
|
4352
4085
|
}
|
|
4353
|
-
appendInlineToken(tokens, kind, start, end, kind ===
|
|
4086
|
+
appendInlineToken(tokens, kind, start, end, kind === 22 ? 0 : 16);
|
|
4354
4087
|
return end;
|
|
4355
4088
|
}
|
|
4356
4089
|
}
|
|
4357
4090
|
],
|
|
4358
|
-
|
|
4091
|
+
build: [
|
|
4359
4092
|
{
|
|
4360
4093
|
kind: "pair",
|
|
4361
|
-
open:
|
|
4362
|
-
close:
|
|
4094
|
+
open: 23,
|
|
4095
|
+
close: 24,
|
|
4363
4096
|
build: buildInlineLink
|
|
4364
4097
|
},
|
|
4365
4098
|
{
|
|
4366
4099
|
kind: "pair",
|
|
4367
|
-
open:
|
|
4368
|
-
close:
|
|
4100
|
+
open: 25,
|
|
4101
|
+
close: 26,
|
|
4369
4102
|
build: buildInlineImage
|
|
4370
4103
|
},
|
|
4371
4104
|
{
|
|
4372
4105
|
kind: "pair",
|
|
4373
|
-
open:
|
|
4374
|
-
close:
|
|
4106
|
+
open: 27,
|
|
4107
|
+
close: 28,
|
|
4375
4108
|
build: buildInlineReferenceLink
|
|
4376
4109
|
},
|
|
4377
4110
|
{
|
|
4378
4111
|
kind: "pair",
|
|
4379
|
-
open:
|
|
4380
|
-
close:
|
|
4112
|
+
open: 29,
|
|
4113
|
+
close: 30,
|
|
4381
4114
|
build: buildInlineReferenceImage
|
|
4382
4115
|
},
|
|
4383
4116
|
{
|
|
@@ -4420,16 +4153,6 @@ const feature$5 = { inline: {
|
|
|
4420
4153
|
kind: "leaf",
|
|
4421
4154
|
token: 22,
|
|
4422
4155
|
build: buildInlineText
|
|
4423
|
-
},
|
|
4424
|
-
{
|
|
4425
|
-
kind: "leaf",
|
|
4426
|
-
token: 23,
|
|
4427
|
-
build: buildInlineText
|
|
4428
|
-
},
|
|
4429
|
-
{
|
|
4430
|
-
kind: "leaf",
|
|
4431
|
-
token: 24,
|
|
4432
|
-
build: buildInlineText
|
|
4433
4156
|
}
|
|
4434
4157
|
]
|
|
4435
4158
|
} };
|
|
@@ -4531,10 +4254,37 @@ function hasBlankLineBetween(source, start, end, stripBlockQuotes) {
|
|
|
4531
4254
|
}
|
|
4532
4255
|
return false;
|
|
4533
4256
|
}
|
|
4257
|
+
function isTaskListWhitespace(code) {
|
|
4258
|
+
return code === 32 || code >= 9 && code <= 13;
|
|
4259
|
+
}
|
|
4260
|
+
function taskListMarkerAt(source, start, end) {
|
|
4261
|
+
while (source.charCodeAt(start) === 32) start++;
|
|
4262
|
+
if (source.charCodeAt(start++) !== 91) return;
|
|
4263
|
+
const state = source.charCodeAt(start++);
|
|
4264
|
+
const checked = state === 88 || state === 120;
|
|
4265
|
+
if (!checked && !isTaskListWhitespace(state)) return;
|
|
4266
|
+
if (source.charCodeAt(start++) !== 93) return;
|
|
4267
|
+
if (start >= end) return;
|
|
4268
|
+
const whitespace = source.charCodeAt(start++);
|
|
4269
|
+
if (!isTaskListWhitespace(whitespace)) return;
|
|
4270
|
+
if (whitespace === 13 && source.charCodeAt(start) === 10) start++;
|
|
4271
|
+
return {
|
|
4272
|
+
checked,
|
|
4273
|
+
contentStart: start
|
|
4274
|
+
};
|
|
4275
|
+
}
|
|
4276
|
+
function hasTaskListContent(source, tokens, firstChunk, contentStart) {
|
|
4277
|
+
for (let token = firstChunk; tokens.kind(token) === 1; token++) {
|
|
4278
|
+
const start = token === firstChunk ? contentStart : tokens.start(token);
|
|
4279
|
+
const end = tokens.end(token);
|
|
4280
|
+
for (let offset = start; offset < end; offset++) if (!isTaskListWhitespace(source.charCodeAt(offset))) return true;
|
|
4281
|
+
}
|
|
4282
|
+
return false;
|
|
4283
|
+
}
|
|
4534
4284
|
function childrenSpread(tokenStart, stripBlockQuotes, context, nestedRule) {
|
|
4535
4285
|
const structure = context.structure;
|
|
4536
4286
|
let previous;
|
|
4537
|
-
for (let childId = structure.firstChild(tokenStart); childId !== noBlockEntry; childId = structure.nextChild(tokenStart, childId)) if (childId >= 0 && (nestedRule === void 0 ? structure.isBlock(childId) : structure.
|
|
4287
|
+
for (let childId = structure.firstChild(tokenStart); childId !== noBlockEntry; childId = structure.nextChild(tokenStart, childId)) if (childId >= 0 && (nestedRule === void 0 ? structure.isBlock(childId) : structure.isRule(childId, nestedRule))) {
|
|
4538
4288
|
const current = payloadBounds(childId, context);
|
|
4539
4289
|
if (previous && hasBlankLineBetween(context.source, previous.end, current.start, stripBlockQuotes)) return true;
|
|
4540
4290
|
previous = current;
|
|
@@ -4542,17 +4292,15 @@ function childrenSpread(tokenStart, stripBlockQuotes, context, nestedRule) {
|
|
|
4542
4292
|
return false;
|
|
4543
4293
|
}
|
|
4544
4294
|
const buildListItem = (tokenStart, context) => {
|
|
4545
|
-
const
|
|
4546
|
-
if (rule !== "OrderedListItem" && rule !== "UnorderedListItem") throw new Error(`Expected list item syntax, received ${rule}`);
|
|
4547
|
-
const marker = blockToken(tokenStart, rule === "OrderedListItem" ? 17 : 13, context);
|
|
4295
|
+
const markerKind = context.structure.tokens.kind(tokenStart);
|
|
4548
4296
|
const children = buildBlockChildren(tokenStart, context);
|
|
4549
4297
|
return {
|
|
4550
4298
|
type: "listItem",
|
|
4551
4299
|
spread: childrenSpread(tokenStart, true, context),
|
|
4552
|
-
checked: null,
|
|
4300
|
+
checked: markerKind === 17 ? true : markerKind === 16 ? false : null,
|
|
4553
4301
|
children,
|
|
4554
4302
|
position: {
|
|
4555
|
-
start: context.structure.tokens.start(
|
|
4303
|
+
start: context.structure.tokens.start(tokenStart),
|
|
4556
4304
|
end: lastChildEnd(children, blockEnd(tokenStart, context))
|
|
4557
4305
|
}
|
|
4558
4306
|
};
|
|
@@ -4560,153 +4308,169 @@ const buildListItem = (tokenStart, context) => {
|
|
|
4560
4308
|
function createBuildList(ordered) {
|
|
4561
4309
|
return (tokenStart, context) => {
|
|
4562
4310
|
const structure = context.structure;
|
|
4563
|
-
const itemRule = ordered ? "OrderedListItem" : "UnorderedListItem";
|
|
4564
|
-
const listMarker = blockToken(tokenStart, ordered ? 15 : 11, context);
|
|
4565
4311
|
const items = [];
|
|
4566
|
-
for (let childId = structure.firstChild(tokenStart); childId !== noBlockEntry; childId = structure.nextChild(tokenStart, childId)) if (childId >= 0 && structure.
|
|
4312
|
+
for (let childId = structure.firstChild(tokenStart); childId !== noBlockEntry; childId = structure.nextChild(tokenStart, childId)) if (childId >= 0 && structure.isRule(childId, 17)) items.push(buildListItem(childId, context));
|
|
4567
4313
|
return {
|
|
4568
4314
|
type: "list",
|
|
4569
4315
|
ordered,
|
|
4570
|
-
start: ordered ? Number.parseInt(context.structure.tokens.text(context.source,
|
|
4571
|
-
spread: childrenSpread(tokenStart, false, context,
|
|
4316
|
+
start: ordered ? Number.parseInt(context.structure.tokens.text(context.source, tokenStart), 10) : null,
|
|
4317
|
+
spread: childrenSpread(tokenStart, false, context, 17),
|
|
4572
4318
|
children: items,
|
|
4573
4319
|
position: {
|
|
4574
|
-
start: context.structure.tokens.start(
|
|
4575
|
-
end: lastChildEnd(items, context.structure.tokens.end(
|
|
4320
|
+
start: context.structure.tokens.start(tokenStart),
|
|
4321
|
+
end: lastChildEnd(items, context.structure.tokens.end(tokenStart))
|
|
4576
4322
|
}
|
|
4577
4323
|
};
|
|
4578
4324
|
};
|
|
4579
4325
|
}
|
|
4580
|
-
const
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4326
|
+
const listStart = (source, lines, start, out, contentOffset, context) => {
|
|
4327
|
+
const listMarker = listMarkerAt(source, lines[start]);
|
|
4328
|
+
if (!listMarker) return;
|
|
4329
|
+
const kind = listMarker.kind;
|
|
4330
|
+
const listOpen = kind === "ordered" ? 13 : 11;
|
|
4331
|
+
const listClose = kind === "ordered" ? 14 : 12;
|
|
4332
|
+
out.push(listOpen, listMarker.offset, listMarker.offset + listMarker.text.length);
|
|
4333
|
+
let index = start;
|
|
4334
|
+
let listEnd = listMarker.offset + listMarker.text.length;
|
|
4335
|
+
while (index < lines.length) {
|
|
4336
|
+
const marker = listMarkerAt(source, lines[index]);
|
|
4337
|
+
if (!marker || !sameList(marker, listMarker)) break;
|
|
4338
|
+
out.push(15, marker.offset, marker.offset + marker.text.length);
|
|
4339
|
+
const itemLines = [{
|
|
4340
|
+
...lines[index],
|
|
4341
|
+
start: marker.contentOffset,
|
|
4342
|
+
prefixColumns: marker.contentPrefixColumns
|
|
4343
|
+
}];
|
|
4344
|
+
let hasContent = !isBlank(source, itemLines[0]);
|
|
4345
|
+
let lazyParagraph = context.endsWithParagraphLeaf(source, itemLines[0]);
|
|
4346
|
+
index++;
|
|
4347
|
+
while (index < lines.length) {
|
|
4348
|
+
const candidate = listMarkerAt(source, lines[index]);
|
|
4349
|
+
if (candidate && candidate.indent < marker.contentIndent) break;
|
|
4350
|
+
if (isBlank(source, lines[index])) {
|
|
4351
|
+
if (!hasContent) {
|
|
4352
|
+
index++;
|
|
4353
|
+
break;
|
|
4354
|
+
}
|
|
4355
|
+
itemLines.push(lines[index]);
|
|
4356
|
+
lazyParagraph = false;
|
|
4357
|
+
index++;
|
|
4358
|
+
continue;
|
|
4588
4359
|
}
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4360
|
+
if (indentOf(source, lines[index]).columns >= marker.contentIndent) {
|
|
4361
|
+
const content = contentAfterColumns(source, lines[index], marker.contentIndent);
|
|
4362
|
+
const contentLine = {
|
|
4363
|
+
...lines[index],
|
|
4364
|
+
start: content.offset,
|
|
4365
|
+
prefixColumns: content.prefixColumns
|
|
4366
|
+
};
|
|
4367
|
+
itemLines.push(contentLine);
|
|
4368
|
+
hasContent = true;
|
|
4369
|
+
lazyParagraph = context.endsWithParagraphLeaf(source, contentLine);
|
|
4370
|
+
index++;
|
|
4371
|
+
continue;
|
|
4596
4372
|
}
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4373
|
+
if (!lazyParagraph || context.startsInterruptingBlock(source, lines[index])) break;
|
|
4374
|
+
itemLines.push({
|
|
4375
|
+
...lines[index],
|
|
4376
|
+
lazy: true
|
|
4377
|
+
});
|
|
4378
|
+
index++;
|
|
4379
|
+
}
|
|
4380
|
+
context.scanLines(source, itemLines, out);
|
|
4381
|
+
listEnd = itemLines.at(-1)?.next ?? marker.offset;
|
|
4382
|
+
out.push(18, listEnd, listEnd);
|
|
4383
|
+
}
|
|
4384
|
+
out.push(listClose, listEnd, listEnd);
|
|
4385
|
+
return index;
|
|
4386
|
+
};
|
|
4387
|
+
const taskListStart = (source, lines, start, out, contentOffset, context) => {
|
|
4388
|
+
const listTokenStart = out.length;
|
|
4389
|
+
const nextLine = listStart(source, lines, start, out, contentOffset, context);
|
|
4390
|
+
if (nextLine === void 0) return;
|
|
4391
|
+
for (let item = listTokenStart + 1; item < out.length; item++) {
|
|
4392
|
+
if (out.kind(item) !== 15) continue;
|
|
4393
|
+
let paragraph = item + 1;
|
|
4394
|
+
let contentKind = out.kind(paragraph);
|
|
4395
|
+
while (contentKind === 26 || contentKind === 27 || contentKind === 28) {
|
|
4396
|
+
paragraph++;
|
|
4397
|
+
contentKind = out.kind(paragraph);
|
|
4398
|
+
}
|
|
4399
|
+
if (contentKind !== 9) continue;
|
|
4400
|
+
const firstChunk = paragraph + 1;
|
|
4401
|
+
const marker = taskListMarkerAt(source, out.start(firstChunk), out.end(firstChunk));
|
|
4402
|
+
if (!marker || !hasTaskListContent(source, out, firstChunk, marker.contentStart)) continue;
|
|
4403
|
+
out.setKind(item, marker.checked ? 17 : 16);
|
|
4404
|
+
out.setStart(firstChunk, marker.contentStart);
|
|
4405
|
+
}
|
|
4406
|
+
return nextLine;
|
|
4407
|
+
};
|
|
4408
|
+
function feature$4(taskList = false) {
|
|
4409
|
+
return { block: {
|
|
4410
|
+
rules: [
|
|
4411
|
+
{
|
|
4412
|
+
rule: 17,
|
|
4413
|
+
syntax: {
|
|
4414
|
+
kind: "frame",
|
|
4415
|
+
open: [
|
|
4416
|
+
15,
|
|
4417
|
+
16,
|
|
4418
|
+
17
|
|
4419
|
+
],
|
|
4420
|
+
close: 18
|
|
4421
|
+
}
|
|
4604
4422
|
},
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4423
|
+
{
|
|
4424
|
+
rule: 18,
|
|
4425
|
+
syntax: {
|
|
4426
|
+
kind: "block",
|
|
4427
|
+
open: 11,
|
|
4428
|
+
close: 12
|
|
4429
|
+
},
|
|
4430
|
+
build: createBuildList(false)
|
|
4613
4431
|
},
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
49,
|
|
4624
|
-
50,
|
|
4625
|
-
51,
|
|
4626
|
-
52,
|
|
4627
|
-
53,
|
|
4628
|
-
54,
|
|
4629
|
-
55,
|
|
4630
|
-
56,
|
|
4631
|
-
57
|
|
4432
|
+
{
|
|
4433
|
+
rule: 19,
|
|
4434
|
+
syntax: {
|
|
4435
|
+
kind: "block",
|
|
4436
|
+
open: 13,
|
|
4437
|
+
close: 14
|
|
4438
|
+
},
|
|
4439
|
+
build: createBuildList(true)
|
|
4440
|
+
}
|
|
4632
4441
|
],
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
out.push(listOpen, listMarker.offset, listMarker.offset + listMarker.text.length);
|
|
4654
|
-
let index = start;
|
|
4655
|
-
let listEnd = listMarker.offset + listMarker.text.length;
|
|
4656
|
-
while (index < lines.length) {
|
|
4657
|
-
const marker = listMarkerAt(source, lines[index]);
|
|
4658
|
-
if (!marker || !sameList(marker, listMarker)) break;
|
|
4659
|
-
out.push(itemOpen, marker.offset, marker.offset + marker.text.length);
|
|
4660
|
-
const itemLines = [{
|
|
4661
|
-
...lines[index],
|
|
4442
|
+
starts: [{
|
|
4443
|
+
codes: [
|
|
4444
|
+
42,
|
|
4445
|
+
43,
|
|
4446
|
+
45,
|
|
4447
|
+
48,
|
|
4448
|
+
49,
|
|
4449
|
+
50,
|
|
4450
|
+
51,
|
|
4451
|
+
52,
|
|
4452
|
+
53,
|
|
4453
|
+
54,
|
|
4454
|
+
55,
|
|
4455
|
+
56,
|
|
4456
|
+
57
|
|
4457
|
+
],
|
|
4458
|
+
unwrapLazyContinuation(source, line) {
|
|
4459
|
+
const marker = listMarkerAt(source, line);
|
|
4460
|
+
return marker ? {
|
|
4461
|
+
...line,
|
|
4662
4462
|
start: marker.contentOffset,
|
|
4663
4463
|
prefixColumns: marker.contentPrefixColumns
|
|
4664
|
-
}
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
break;
|
|
4675
|
-
}
|
|
4676
|
-
itemLines.push(lines[index]);
|
|
4677
|
-
lazyParagraph = false;
|
|
4678
|
-
index++;
|
|
4679
|
-
continue;
|
|
4680
|
-
}
|
|
4681
|
-
if (indentOf(source, lines[index]).columns >= marker.contentIndent) {
|
|
4682
|
-
const content = contentAfterColumns(source, lines[index], marker.contentIndent);
|
|
4683
|
-
const contentLine = {
|
|
4684
|
-
...lines[index],
|
|
4685
|
-
start: content.offset,
|
|
4686
|
-
prefixColumns: content.prefixColumns
|
|
4687
|
-
};
|
|
4688
|
-
itemLines.push(contentLine);
|
|
4689
|
-
hasContent = true;
|
|
4690
|
-
lazyParagraph = context.endsWithParagraphLeaf(source, contentLine);
|
|
4691
|
-
index++;
|
|
4692
|
-
continue;
|
|
4693
|
-
}
|
|
4694
|
-
if (!lazyParagraph || context.startsInterruptingBlock(source, lines[index])) break;
|
|
4695
|
-
itemLines.push({
|
|
4696
|
-
...lines[index],
|
|
4697
|
-
lazy: true
|
|
4698
|
-
});
|
|
4699
|
-
index++;
|
|
4700
|
-
}
|
|
4701
|
-
context.scanLines(source, itemLines, out);
|
|
4702
|
-
listEnd = itemLines.at(-1)?.next ?? marker.offset;
|
|
4703
|
-
out.push(itemClose, listEnd, listEnd);
|
|
4704
|
-
}
|
|
4705
|
-
out.push(listClose, listEnd, listEnd);
|
|
4706
|
-
return index;
|
|
4707
|
-
}
|
|
4708
|
-
}]
|
|
4709
|
-
} };
|
|
4464
|
+
} : void 0;
|
|
4465
|
+
},
|
|
4466
|
+
interrupt(source, line) {
|
|
4467
|
+
const marker = listMarkerAt(source, line);
|
|
4468
|
+
return hasListContent(source, line, marker) && (marker?.kind === "unordered" || marker?.kind === "ordered" && marker.startNumber === 1);
|
|
4469
|
+
},
|
|
4470
|
+
start: taskList ? taskListStart : listStart
|
|
4471
|
+
}]
|
|
4472
|
+
} };
|
|
4473
|
+
}
|
|
4710
4474
|
//#endregion
|
|
4711
4475
|
//#region src/profile/features/math/block.ts
|
|
4712
4476
|
const mathFenceRule = {
|
|
@@ -4715,7 +4479,7 @@ const mathFenceRule = {
|
|
|
4715
4479
|
minimumLength: 2
|
|
4716
4480
|
};
|
|
4717
4481
|
const blockRules = [{
|
|
4718
|
-
rule:
|
|
4482
|
+
rule: 22,
|
|
4719
4483
|
syntax: {
|
|
4720
4484
|
kind: "leaf",
|
|
4721
4485
|
token: 21
|
|
@@ -4723,9 +4487,8 @@ const blockRules = [{
|
|
|
4723
4487
|
build(tokenStart, context) {
|
|
4724
4488
|
const offset = context.structure.tokens.start(tokenStart);
|
|
4725
4489
|
const end = offset + context.structure.lenOf(tokenStart);
|
|
4726
|
-
const
|
|
4727
|
-
const
|
|
4728
|
-
const block = context.structure.tokens.value(token);
|
|
4490
|
+
const value = context.structure.tokens.text(context.source, tokenStart);
|
|
4491
|
+
const block = context.structure.tokens.value(tokenStart);
|
|
4729
4492
|
if (!block) throw new Error("MathBlockToken has no fence metadata");
|
|
4730
4493
|
return {
|
|
4731
4494
|
type: "math",
|
|
@@ -4756,7 +4519,7 @@ const blockStarts = [{
|
|
|
4756
4519
|
}];
|
|
4757
4520
|
//#endregion
|
|
4758
4521
|
//#region src/profile/features/math/inline.ts
|
|
4759
|
-
function
|
|
4522
|
+
function createMathScanRule(singleDollarTextMath) {
|
|
4760
4523
|
const minimum = singleDollarTextMath ? 1 : 2;
|
|
4761
4524
|
return {
|
|
4762
4525
|
marker: 36,
|
|
@@ -4793,7 +4556,7 @@ function mathTextValue(value) {
|
|
|
4793
4556
|
if (startPadding > 0 && endPadding > 0 && /[^ \r\n]/.test(result)) result = result.slice(startPadding, -endPadding);
|
|
4794
4557
|
return result;
|
|
4795
4558
|
}
|
|
4796
|
-
const
|
|
4559
|
+
const inlineBuilds = [{
|
|
4797
4560
|
kind: "leaf",
|
|
4798
4561
|
token: 3,
|
|
4799
4562
|
build(tokenIndex, sourceSpan, context) {
|
|
@@ -4814,8 +4577,8 @@ function feature$3(options) {
|
|
|
4814
4577
|
starts: blockStarts
|
|
4815
4578
|
},
|
|
4816
4579
|
inline: {
|
|
4817
|
-
|
|
4818
|
-
|
|
4580
|
+
scan: [createMathScanRule(singleDollarTextMath)],
|
|
4581
|
+
build: inlineBuilds
|
|
4819
4582
|
}
|
|
4820
4583
|
};
|
|
4821
4584
|
}
|
|
@@ -4862,15 +4625,15 @@ const feature$2 = { block: {
|
|
|
4862
4625
|
return index;
|
|
4863
4626
|
}],
|
|
4864
4627
|
rules: [{
|
|
4865
|
-
rule:
|
|
4628
|
+
rule: 9,
|
|
4866
4629
|
syntax: {
|
|
4867
4630
|
kind: "block",
|
|
4868
4631
|
open: 9,
|
|
4869
4632
|
close: 10
|
|
4870
4633
|
},
|
|
4871
4634
|
inlineContent: true,
|
|
4872
|
-
build(tokenStart, context) {
|
|
4873
|
-
const children =
|
|
4635
|
+
build(tokenStart, context, inline) {
|
|
4636
|
+
const children = inline.children;
|
|
4874
4637
|
return {
|
|
4875
4638
|
type: "paragraph",
|
|
4876
4639
|
children,
|
|
@@ -4907,7 +4670,10 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset) {
|
|
|
4907
4670
|
continue;
|
|
4908
4671
|
}
|
|
4909
4672
|
if (code === 91) return;
|
|
4910
|
-
if (code === 93
|
|
4673
|
+
if (code === 93) {
|
|
4674
|
+
if (source.charCodeAt(offset + 1) === 58) break scanLabel;
|
|
4675
|
+
return;
|
|
4676
|
+
}
|
|
4911
4677
|
if (code !== 32 && code !== 9) labelHasContent = true;
|
|
4912
4678
|
if (++labelLength > 999) return;
|
|
4913
4679
|
offset++;
|
|
@@ -4947,14 +4713,16 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset) {
|
|
|
4947
4713
|
} else {
|
|
4948
4714
|
let depth = 0;
|
|
4949
4715
|
const destinationStart = offset;
|
|
4950
|
-
while (offset < lines[lineIndex].end
|
|
4951
|
-
|
|
4716
|
+
while (offset < lines[lineIndex].end) {
|
|
4717
|
+
const code = source.charCodeAt(offset);
|
|
4718
|
+
if (code === 32 || code === 9) break;
|
|
4719
|
+
if (code === 92 && offset + 1 < lines[lineIndex].end) {
|
|
4952
4720
|
offset += 2;
|
|
4953
4721
|
continue;
|
|
4954
4722
|
}
|
|
4955
|
-
if (
|
|
4723
|
+
if (code === 40) {
|
|
4956
4724
|
if (++depth > 32) return;
|
|
4957
|
-
} else if (
|
|
4725
|
+
} else if (code === 41 && --depth < 0) return;
|
|
4958
4726
|
offset++;
|
|
4959
4727
|
}
|
|
4960
4728
|
if (offset === destinationStart || depth !== 0) return;
|
|
@@ -5023,54 +4791,104 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset) {
|
|
|
5023
4791
|
fields
|
|
5024
4792
|
};
|
|
5025
4793
|
}
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
let
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
4794
|
+
function referenceLabelEnd(source, start) {
|
|
4795
|
+
if (source.charCodeAt(start) !== 91) return -1;
|
|
4796
|
+
let offset = start + 1;
|
|
4797
|
+
if (source.charCodeAt(offset) === 93) return offset + 1;
|
|
4798
|
+
let characters = 0;
|
|
4799
|
+
let hasContent = false;
|
|
4800
|
+
while (offset < source.length && characters < 999) {
|
|
4801
|
+
const code = source.charCodeAt(offset);
|
|
4802
|
+
if (code === 93) return hasContent ? offset + 1 : -1;
|
|
4803
|
+
if (code === 91) return -1;
|
|
4804
|
+
if (code === 92) {
|
|
4805
|
+
if (offset + 1 >= source.length) return -1;
|
|
4806
|
+
hasContent = true;
|
|
4807
|
+
offset += 2;
|
|
4808
|
+
} else {
|
|
4809
|
+
hasContent ||= code !== 9 && code !== 10 && code !== 13 && code !== 32;
|
|
4810
|
+
offset++;
|
|
5040
4811
|
}
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
4812
|
+
characters++;
|
|
4813
|
+
}
|
|
4814
|
+
return -1;
|
|
4815
|
+
}
|
|
4816
|
+
function acceptsShortcutLabel(source, start, end) {
|
|
4817
|
+
let hasContent = false;
|
|
4818
|
+
let characters = 0;
|
|
4819
|
+
for (let offset = start; offset < end; offset++) {
|
|
4820
|
+
const code = source.charCodeAt(offset);
|
|
4821
|
+
hasContent ||= code !== 9 && code !== 10 && code !== 13 && code !== 32;
|
|
4822
|
+
if (code >= 55296 && code <= 56319 && offset + 1 < end) {
|
|
4823
|
+
const trailing = source.charCodeAt(offset + 1);
|
|
4824
|
+
if (trailing >= 56320 && trailing <= 57343) offset++;
|
|
5047
4825
|
}
|
|
5048
|
-
if (
|
|
5049
|
-
|
|
4826
|
+
if (++characters > 999) return false;
|
|
4827
|
+
}
|
|
4828
|
+
return hasContent;
|
|
4829
|
+
}
|
|
4830
|
+
function resolveReferenceTokens(source, tokens, context) {
|
|
4831
|
+
let closerEnds;
|
|
4832
|
+
let inactiveBefore = 0;
|
|
4833
|
+
let lastNestedOpener = 0;
|
|
4834
|
+
let openers;
|
|
4835
|
+
let replacementKinds;
|
|
4836
|
+
const count = inlineTokenCount(tokens);
|
|
4837
|
+
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
4838
|
+
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
4839
|
+
if (kind === 20) {
|
|
4840
|
+
(openers ??= []).push(tokenIndex);
|
|
4841
|
+
lastNestedOpener = tokenIndex + 1;
|
|
5050
4842
|
continue;
|
|
5051
4843
|
}
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
4844
|
+
if (kind === 19) {
|
|
4845
|
+
(openers ??= []).push(~tokenIndex);
|
|
4846
|
+
lastNestedOpener = tokenIndex + 1;
|
|
5055
4847
|
continue;
|
|
5056
4848
|
}
|
|
5057
|
-
if (
|
|
5058
|
-
|
|
5059
|
-
|
|
4849
|
+
if (kind !== 21 && kind !== 22) continue;
|
|
4850
|
+
const encodedOpener = openers?.pop();
|
|
4851
|
+
if (encodedOpener === void 0) continue;
|
|
4852
|
+
const image = encodedOpener < 0;
|
|
4853
|
+
const openerIndex = image ? ~encodedOpener : encodedOpener;
|
|
4854
|
+
if (!image && openerIndex + 1 < inactiveBefore) continue;
|
|
4855
|
+
const contentStart = inlineTokenEnd(tokens, openerIndex);
|
|
4856
|
+
const contentEnd = inlineTokenStart(tokens, tokenIndex);
|
|
4857
|
+
let closeEnd = inlineTokenEnd(tokens, tokenIndex);
|
|
4858
|
+
let reference = false;
|
|
4859
|
+
if (kind === 22) {
|
|
4860
|
+
const labelEnd = referenceLabelEnd(source, closeEnd);
|
|
4861
|
+
if (labelEnd > 0) {
|
|
4862
|
+
const label = source.slice(closeEnd + 1, labelEnd - 1) || source.slice(contentStart, contentEnd);
|
|
4863
|
+
if (!context.hasDefinition(normalizeAssociationLabel(label))) continue;
|
|
4864
|
+
closeEnd = labelEnd;
|
|
4865
|
+
reference = true;
|
|
4866
|
+
} else {
|
|
4867
|
+
if (lastNestedOpener > openerIndex + 1 || !acceptsShortcutLabel(source, contentStart, contentEnd) || !context.hasDefinition(normalizeAssociationLabel(source.slice(contentStart, contentEnd)))) continue;
|
|
4868
|
+
reference = true;
|
|
4869
|
+
}
|
|
5060
4870
|
}
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
4871
|
+
replacementKinds ??= [];
|
|
4872
|
+
replacementKinds[openerIndex] = image ? reference ? 29 : 25 : reference ? 27 : 23;
|
|
4873
|
+
replacementKinds[tokenIndex] = image ? reference ? 30 : 26 : reference ? 28 : 24;
|
|
4874
|
+
closerEnds ??= [];
|
|
4875
|
+
closerEnds[tokenIndex] = closeEnd;
|
|
4876
|
+
if (!image) inactiveBefore = Math.max(inactiveBefore, openerIndex + 1);
|
|
4877
|
+
while (tokenIndex + 1 < count && inlineTokenStart(tokens, tokenIndex + 1) < closeEnd) tokenIndex++;
|
|
5066
4878
|
}
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
4879
|
+
if (!replacementKinds) return tokens;
|
|
4880
|
+
const result = [];
|
|
4881
|
+
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
4882
|
+
const closerEnd = closerEnds?.[tokenIndex];
|
|
4883
|
+
const kind = replacementKinds[tokenIndex];
|
|
4884
|
+
if (closerEnd !== void 0) {
|
|
4885
|
+
appendInlineToken(result, kind, inlineTokenStart(tokens, tokenIndex), closerEnd, inlineTokenFlags(tokens, tokenIndex));
|
|
4886
|
+
while (tokenIndex + 1 < count && inlineTokenStart(tokens, tokenIndex + 1) < closerEnd) tokenIndex++;
|
|
4887
|
+
} else if (kind !== void 0) appendInlineToken(result, kind, inlineTokenStart(tokens, tokenIndex), inlineTokenEnd(tokens, tokenIndex), inlineTokenFlags(tokens, tokenIndex));
|
|
4888
|
+
else copyInlineToken(result, tokens, tokenIndex);
|
|
4889
|
+
}
|
|
4890
|
+
return result;
|
|
4891
|
+
}
|
|
5074
4892
|
const feature$1 = {
|
|
5075
4893
|
block: {
|
|
5076
4894
|
restart(source, lines, changedStart, changedEnd) {
|
|
@@ -5084,15 +4902,14 @@ const feature$1 = {
|
|
|
5084
4902
|
return candidate;
|
|
5085
4903
|
},
|
|
5086
4904
|
rules: [{
|
|
5087
|
-
rule:
|
|
4905
|
+
rule: 2,
|
|
5088
4906
|
syntax: {
|
|
5089
4907
|
kind: "block",
|
|
5090
4908
|
open: 26,
|
|
5091
4909
|
close: 28
|
|
5092
4910
|
},
|
|
5093
4911
|
build(tokenStart, context) {
|
|
5094
|
-
const
|
|
5095
|
-
const fields = linkDefinitionFields(context.structure.tokens, token);
|
|
4912
|
+
const fields = linkDefinitionFields(context.structure.tokens, tokenStart);
|
|
5096
4913
|
return {
|
|
5097
4914
|
type: "definition",
|
|
5098
4915
|
identifier: fields.definitionKey.toLowerCase(),
|
|
@@ -5100,7 +4917,7 @@ const feature$1 = {
|
|
|
5100
4917
|
url: semanticText(fields.destination),
|
|
5101
4918
|
title: fields.title === void 0 ? null : semanticText(fields.title),
|
|
5102
4919
|
position: {
|
|
5103
|
-
start: context.structure.tokens.start(
|
|
4920
|
+
start: context.structure.tokens.start(tokenStart) + fields.markerOffset,
|
|
5104
4921
|
end: blockEnd(tokenStart, context)
|
|
5105
4922
|
}
|
|
5106
4923
|
};
|
|
@@ -5127,71 +4944,7 @@ const feature$1 = {
|
|
|
5127
4944
|
}
|
|
5128
4945
|
}]
|
|
5129
4946
|
},
|
|
5130
|
-
inline: {
|
|
5131
|
-
pairs: [
|
|
5132
|
-
{
|
|
5133
|
-
opener: 20,
|
|
5134
|
-
closer: 21,
|
|
5135
|
-
open: 25,
|
|
5136
|
-
close: 26,
|
|
5137
|
-
deactivateEarlier: [20],
|
|
5138
|
-
isolateDelimiters: true
|
|
5139
|
-
},
|
|
5140
|
-
{
|
|
5141
|
-
opener: 19,
|
|
5142
|
-
closer: 21,
|
|
5143
|
-
open: 27,
|
|
5144
|
-
close: 28
|
|
5145
|
-
},
|
|
5146
|
-
{
|
|
5147
|
-
opener: 20,
|
|
5148
|
-
closer: 22,
|
|
5149
|
-
open: 29,
|
|
5150
|
-
close: 30,
|
|
5151
|
-
deactivateEarlier: [20],
|
|
5152
|
-
isolateDelimiters: true,
|
|
5153
|
-
activate: activateReference,
|
|
5154
|
-
splitUnmatchedCloser: splitReferenceTail
|
|
5155
|
-
},
|
|
5156
|
-
{
|
|
5157
|
-
opener: 20,
|
|
5158
|
-
closer: 23,
|
|
5159
|
-
open: 29,
|
|
5160
|
-
close: 30,
|
|
5161
|
-
deactivateEarlier: [20],
|
|
5162
|
-
isolateDelimiters: true,
|
|
5163
|
-
activate: activateReference,
|
|
5164
|
-
content: {
|
|
5165
|
-
requireNonWhitespace: true,
|
|
5166
|
-
maxCharacters: 999,
|
|
5167
|
-
forbidTokens: [20, 19]
|
|
5168
|
-
}
|
|
5169
|
-
},
|
|
5170
|
-
{
|
|
5171
|
-
opener: 19,
|
|
5172
|
-
closer: 22,
|
|
5173
|
-
open: 31,
|
|
5174
|
-
close: 32,
|
|
5175
|
-
isolateDelimiters: true,
|
|
5176
|
-
activate: activateReference,
|
|
5177
|
-
splitUnmatchedCloser: splitReferenceTail
|
|
5178
|
-
},
|
|
5179
|
-
{
|
|
5180
|
-
opener: 19,
|
|
5181
|
-
closer: 23,
|
|
5182
|
-
open: 31,
|
|
5183
|
-
close: 32,
|
|
5184
|
-
isolateDelimiters: true,
|
|
5185
|
-
activate: activateReference,
|
|
5186
|
-
content: {
|
|
5187
|
-
requireNonWhitespace: true,
|
|
5188
|
-
maxCharacters: 999,
|
|
5189
|
-
forbidTokens: [20, 19]
|
|
5190
|
-
}
|
|
5191
|
-
}
|
|
5192
|
-
],
|
|
5193
|
-
rewrite: reassociateReferenceTails
|
|
5194
|
-
}
|
|
4947
|
+
inline: { resolve: { transform: resolveReferenceTokens } }
|
|
5195
4948
|
};
|
|
5196
4949
|
//#endregion
|
|
5197
4950
|
//#region src/profile/features/table.ts
|
|
@@ -5251,7 +5004,7 @@ function alignmentAt(source, cell) {
|
|
|
5251
5004
|
if (right) end--;
|
|
5252
5005
|
if (start === end) return;
|
|
5253
5006
|
for (let offset = start; offset < end; offset++) if (source[offset] !== "-") return;
|
|
5254
|
-
return left ? right ?
|
|
5007
|
+
return left ? right ? 37 : 35 : right ? 36 : 34;
|
|
5255
5008
|
}
|
|
5256
5009
|
function delimiterAt(source, line) {
|
|
5257
5010
|
const indent = lineIndent(source, line);
|
|
@@ -5275,48 +5028,42 @@ function emitTableRow(line, cells, out) {
|
|
|
5275
5028
|
out.push(31, cells[0].start, cells[0].start);
|
|
5276
5029
|
for (const cell of cells) {
|
|
5277
5030
|
out.push(33, cell.start, cell.start);
|
|
5278
|
-
|
|
5279
|
-
out.push(34, cell.end, cell.end);
|
|
5031
|
+
out.push(1, cell.contentStart, cell.contentEnd);
|
|
5280
5032
|
}
|
|
5281
5033
|
out.push(32, line.end, line.end);
|
|
5282
5034
|
}
|
|
5283
|
-
|
|
5284
|
-
const
|
|
5285
|
-
const result = [];
|
|
5286
|
-
for (let child = structure.firstChild(tokenStart); child !== noBlockEntry; child = structure.nextChild(tokenStart, child)) if (child >= 0 && structure.ruleNameOf(child) === rule) result.push(child);
|
|
5287
|
-
return result;
|
|
5288
|
-
}
|
|
5289
|
-
const buildTableCell = (tokenStart, context) => {
|
|
5290
|
-
const open = blockToken(tokenStart, 33, context);
|
|
5291
|
-
const close = blockToken(tokenStart, 34, context);
|
|
5035
|
+
const buildTableCell = (tokenStart, context, inline) => {
|
|
5036
|
+
const tokens = context.structure.tokens;
|
|
5292
5037
|
return {
|
|
5293
5038
|
type: "tableCell",
|
|
5294
|
-
children:
|
|
5039
|
+
children: inline.children,
|
|
5295
5040
|
position: {
|
|
5296
|
-
start:
|
|
5297
|
-
end:
|
|
5041
|
+
start: tokens.start(tokenStart),
|
|
5042
|
+
end: tokens.start(tokenStart + tokens.nodeLength(tokenStart))
|
|
5298
5043
|
}
|
|
5299
5044
|
};
|
|
5300
5045
|
};
|
|
5301
5046
|
const buildTableRow = (tokenStart, context) => {
|
|
5302
|
-
const
|
|
5303
|
-
const close =
|
|
5047
|
+
const tokens = context.structure.tokens;
|
|
5048
|
+
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
5049
|
+
const children = [];
|
|
5050
|
+
for (let cell = tokenStart + 1; cell < close; cell += tokens.nodeLength(cell)) children.push(buildTableCell(cell, context, buildInlineFragment(cell, context)));
|
|
5304
5051
|
return {
|
|
5305
5052
|
type: "tableRow",
|
|
5306
|
-
children
|
|
5053
|
+
children,
|
|
5307
5054
|
position: {
|
|
5308
|
-
start:
|
|
5309
|
-
end:
|
|
5055
|
+
start: tokens.start(tokenStart),
|
|
5056
|
+
end: tokens.start(close)
|
|
5310
5057
|
}
|
|
5311
5058
|
};
|
|
5312
5059
|
};
|
|
5313
5060
|
function tableAlignment(tokenStart, context) {
|
|
5314
|
-
const
|
|
5061
|
+
const tokens = context.structure.tokens;
|
|
5062
|
+
const tokenEnd = tokenStart + tokens.nodeLength(tokenStart);
|
|
5315
5063
|
const result = [];
|
|
5316
|
-
for (let
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
result.push(kind === 36 ? "left" : kind === 37 ? "right" : kind === 38 ? "center" : null);
|
|
5064
|
+
for (let token = tokenStart; token < tokenEnd; token++) {
|
|
5065
|
+
const kind = tokens.kind(token);
|
|
5066
|
+
result.push(kind === 35 ? "left" : kind === 36 ? "right" : kind === 37 ? "center" : null);
|
|
5320
5067
|
}
|
|
5321
5068
|
return result;
|
|
5322
5069
|
}
|
|
@@ -5347,16 +5094,16 @@ const feature = { block: {
|
|
|
5347
5094
|
}],
|
|
5348
5095
|
rules: [
|
|
5349
5096
|
{
|
|
5350
|
-
rule:
|
|
5097
|
+
rule: 3,
|
|
5351
5098
|
syntax: {
|
|
5352
5099
|
kind: "frame",
|
|
5353
5100
|
open: 33,
|
|
5354
|
-
close:
|
|
5101
|
+
close: 1
|
|
5355
5102
|
},
|
|
5356
5103
|
inlineContent: true
|
|
5357
5104
|
},
|
|
5358
5105
|
{
|
|
5359
|
-
rule:
|
|
5106
|
+
rule: 4,
|
|
5360
5107
|
syntax: {
|
|
5361
5108
|
kind: "frame",
|
|
5362
5109
|
open: 31,
|
|
@@ -5364,37 +5111,38 @@ const feature = { block: {
|
|
|
5364
5111
|
}
|
|
5365
5112
|
},
|
|
5366
5113
|
{
|
|
5367
|
-
rule:
|
|
5114
|
+
rule: 5,
|
|
5368
5115
|
syntax: {
|
|
5369
5116
|
kind: "group",
|
|
5370
5117
|
tokens: [
|
|
5118
|
+
34,
|
|
5371
5119
|
35,
|
|
5372
5120
|
36,
|
|
5373
|
-
37
|
|
5374
|
-
38
|
|
5121
|
+
37
|
|
5375
5122
|
]
|
|
5376
5123
|
}
|
|
5377
5124
|
},
|
|
5378
5125
|
{
|
|
5379
|
-
rule:
|
|
5126
|
+
rule: 6,
|
|
5380
5127
|
syntax: {
|
|
5381
5128
|
kind: "block",
|
|
5382
5129
|
open: 29,
|
|
5383
5130
|
close: 30
|
|
5384
5131
|
},
|
|
5385
5132
|
build(tokenStart, context) {
|
|
5386
|
-
const
|
|
5387
|
-
const close =
|
|
5388
|
-
const
|
|
5389
|
-
const delimiter =
|
|
5390
|
-
|
|
5133
|
+
const tokens = context.structure.tokens;
|
|
5134
|
+
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
5135
|
+
const header = tokenStart + 1;
|
|
5136
|
+
const delimiter = header + tokens.nodeLength(header);
|
|
5137
|
+
const rows = [buildTableRow(header, context)];
|
|
5138
|
+
for (let row = delimiter + tokens.nodeLength(delimiter); row < close; row += tokens.nodeLength(row)) rows.push(buildTableRow(row, context));
|
|
5391
5139
|
return {
|
|
5392
5140
|
type: "table",
|
|
5393
5141
|
align: tableAlignment(delimiter, context),
|
|
5394
5142
|
children: rows,
|
|
5395
5143
|
position: {
|
|
5396
|
-
start:
|
|
5397
|
-
end:
|
|
5144
|
+
start: tokens.start(tokenStart),
|
|
5145
|
+
end: tokens.start(close)
|
|
5398
5146
|
}
|
|
5399
5147
|
};
|
|
5400
5148
|
}
|
|
@@ -5408,18 +5156,18 @@ function compileProfile(options = {}) {
|
|
|
5408
5156
|
feature$7,
|
|
5409
5157
|
feature$14,
|
|
5410
5158
|
feature$15,
|
|
5411
|
-
feature$4,
|
|
5159
|
+
feature$4(options.taskList),
|
|
5412
5160
|
feature$12,
|
|
5413
5161
|
feature$6
|
|
5414
5162
|
];
|
|
5415
|
-
if (options.footnote) features.push(feature$
|
|
5416
|
-
if (options.frontmatter) features.unshift(feature$
|
|
5163
|
+
if (options.footnote) features.push(feature$9);
|
|
5164
|
+
if (options.frontmatter) features.unshift(feature$11(typeof options.frontmatter === "object" ? options.frontmatter.marker : "-"));
|
|
5417
5165
|
if (options.table) features.push(feature);
|
|
5418
5166
|
if (options.math) features.push(feature$3(options.math));
|
|
5419
|
-
features.push(feature$2, feature$13, feature$
|
|
5167
|
+
features.push(feature$2, feature$13, feature$8(options.strikethrough), feature$5);
|
|
5420
5168
|
if (options.attributes) features.push(feature$17);
|
|
5421
5169
|
if (options.binding) features.push(feature$16);
|
|
5422
|
-
if (options.component) features.push(feature$
|
|
5170
|
+
if (options.component) features.push(feature$10);
|
|
5423
5171
|
features.push(feature$1);
|
|
5424
5172
|
const blockFeatures = [];
|
|
5425
5173
|
const inlineFeatures = [];
|