satorigear 0.0.2 → 0.0.4
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 +2 -0
- package/dist/index.mjs +1047 -1300
- 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++) {
|
|
@@ -1842,11 +1762,10 @@ function resolveDelimiterRuns(source, tokens, configByKind, isolations) {
|
|
|
1842
1762
|
}
|
|
1843
1763
|
return result;
|
|
1844
1764
|
}
|
|
1845
|
-
function
|
|
1765
|
+
function createDelimiterResolver(delimiterConfigs, isolationCloseByOpen) {
|
|
1846
1766
|
const delimiterByKind = [];
|
|
1847
1767
|
delimiterConfigs.forEach((config, index) => {
|
|
1848
1768
|
delimiterByKind[config.token] = {
|
|
1849
|
-
marker: config.marker,
|
|
1850
1769
|
single: config.single ? {
|
|
1851
1770
|
open: config.single.open,
|
|
1852
1771
|
close: config.single.close
|
|
@@ -1861,127 +1780,192 @@ function createPairingResolver(delimiterConfigs, pairConfigs = []) {
|
|
|
1861
1780
|
index
|
|
1862
1781
|
};
|
|
1863
1782
|
});
|
|
1864
|
-
const
|
|
1865
|
-
const
|
|
1866
|
-
|
|
1867
|
-
const kind = config.token;
|
|
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) => {
|
|
1783
|
+
const delimiterKinds = [];
|
|
1784
|
+
for (const config of delimiterConfigs) delimiterKinds[config.token] = true;
|
|
1785
|
+
return (source, tokens) => {
|
|
1877
1786
|
const count = inlineTokenCount(tokens);
|
|
1878
|
-
let
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
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;
|
|
1895
1838
|
}
|
|
1896
|
-
|
|
1897
|
-
|
|
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;
|
|
1898
1880
|
}
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
}
|
|
1881
|
+
const end = inlineTextEnd(source, offset, textBoundary);
|
|
1882
|
+
tokens.push(9, offset, end, 0);
|
|
1883
|
+
offset = end;
|
|
1884
|
+
}
|
|
1885
|
+
return tokens;
|
|
1886
|
+
}
|
|
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);
|
|
1896
|
+
};
|
|
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
|
}
|
|
@@ -3223,20 +3075,11 @@ const blockStarts$2 = [{
|
|
|
3223
3075
|
}];
|
|
3224
3076
|
//#endregion
|
|
3225
3077
|
//#region src/profile/features/component/inline.ts
|
|
3078
|
+
const allowedPrevious = /[ \t\n\r\p{sc=Han}\p{sc=Hira}\p{sc=Kana}\p{sc=Hang}\p{P}]/u;
|
|
3226
3079
|
function inlineComponentEnd(source, start) {
|
|
3227
|
-
const
|
|
3228
|
-
if (start
|
|
3229
|
-
|
|
3230
|
-
}
|
|
3231
|
-
const inlineLexical = [{
|
|
3232
|
-
marker: 58,
|
|
3233
|
-
scan(source, start, tokens) {
|
|
3234
|
-
const end = inlineComponentEnd(source, start);
|
|
3235
|
-
if (end === void 0) return -1;
|
|
3236
|
-
appendInlineToken(tokens, 35, start, end);
|
|
3237
|
-
return end;
|
|
3238
|
-
}
|
|
3239
|
-
}];
|
|
3080
|
+
const prev = source[start - 1];
|
|
3081
|
+
if (start <= 0 || prev !== ":" && allowedPrevious.test(prev)) return componentNameEnd(source, start + 1, false);
|
|
3082
|
+
}
|
|
3240
3083
|
function appendLinkCandidates(target, candidates) {
|
|
3241
3084
|
for (const candidate of candidates) {
|
|
3242
3085
|
candidate.inLinkLabel = true;
|
|
@@ -3260,7 +3103,7 @@ function candidates(source, tokens) {
|
|
|
3260
3103
|
const componentIndex = index - 1;
|
|
3261
3104
|
bracketStack.push({
|
|
3262
3105
|
children: [],
|
|
3263
|
-
componentIndex: componentIndex >= 0 && inlineTokenKind(tokens, componentIndex) ===
|
|
3106
|
+
componentIndex: componentIndex >= 0 && inlineTokenKind(tokens, componentIndex) === 33 && inlineTokenEnd(tokens, componentIndex) === start ? componentIndex : -1,
|
|
3264
3107
|
image: false,
|
|
3265
3108
|
start,
|
|
3266
3109
|
tokenIndex: index
|
|
@@ -3277,7 +3120,7 @@ function candidates(source, tokens) {
|
|
|
3277
3120
|
});
|
|
3278
3121
|
continue;
|
|
3279
3122
|
}
|
|
3280
|
-
if (kind !==
|
|
3123
|
+
if (kind !== 22 && kind !== 21) continue;
|
|
3281
3124
|
const open = bracketStack.pop();
|
|
3282
3125
|
if (!open) continue;
|
|
3283
3126
|
const parent = bracketStack.at(-1)?.children ?? roots;
|
|
@@ -3288,7 +3131,7 @@ function candidates(source, tokens) {
|
|
|
3288
3131
|
const close = inlineTokenStart(tokens, index);
|
|
3289
3132
|
normalClosers.add(close);
|
|
3290
3133
|
let children = open.children;
|
|
3291
|
-
if (kind === 21
|
|
3134
|
+
if (kind === 21) {
|
|
3292
3135
|
children = [];
|
|
3293
3136
|
appendLinkCandidates(children, open.children);
|
|
3294
3137
|
}
|
|
@@ -3308,24 +3151,6 @@ function candidates(source, tokens) {
|
|
|
3308
3151
|
nameEnd: open.start,
|
|
3309
3152
|
start
|
|
3310
3153
|
});
|
|
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
3154
|
continue;
|
|
3330
3155
|
}
|
|
3331
3156
|
if (source[close + 1] === "(" || source[close + 1] === "[") {
|
|
@@ -3365,7 +3190,7 @@ function copyRange(target, tokens, start, end, inLinkLabel, normalClosers) {
|
|
|
3365
3190
|
const tokenEnd = inlineTokenEnd(tokens, index);
|
|
3366
3191
|
const fragmentStart = Math.max(start, tokenStart);
|
|
3367
3192
|
const fragmentEnd = Math.min(end, tokenEnd);
|
|
3368
|
-
appendInlineToken(target, inLinkLabel && (kind === 20 || normalClosers.has(tokenStart) && (kind === 21 || kind === 22
|
|
3193
|
+
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
3194
|
}
|
|
3370
3195
|
}
|
|
3371
3196
|
function emitRange(target, tokens, start, end, nested, inLinkLabel, normalClosers) {
|
|
@@ -3373,22 +3198,22 @@ function emitRange(target, tokens, start, end, nested, inLinkLabel, normalCloser
|
|
|
3373
3198
|
for (const candidate of nested) {
|
|
3374
3199
|
copyRange(target, tokens, cursor, candidate.start, inLinkLabel, normalClosers);
|
|
3375
3200
|
if (candidate.kind === "component") {
|
|
3376
|
-
appendInlineToken(target,
|
|
3201
|
+
appendInlineToken(target, 33, candidate.start, candidate.nameEnd, candidate.flags);
|
|
3377
3202
|
if (candidate.contentStart < candidate.contentEnd) {
|
|
3378
|
-
appendInlineToken(target,
|
|
3203
|
+
appendInlineToken(target, 34, candidate.nameEnd, candidate.contentStart);
|
|
3379
3204
|
emitRange(target, tokens, candidate.contentStart, candidate.contentEnd, candidate.children, candidate.inLinkLabel, normalClosers);
|
|
3380
|
-
appendInlineToken(target,
|
|
3205
|
+
appendInlineToken(target, 35, candidate.close, candidate.close + 1);
|
|
3381
3206
|
}
|
|
3382
3207
|
} else {
|
|
3383
|
-
appendInlineToken(target,
|
|
3208
|
+
appendInlineToken(target, 37, candidate.start, candidate.contentStart, candidate.flags);
|
|
3384
3209
|
emitRange(target, tokens, candidate.contentStart, candidate.contentEnd, candidate.children, candidate.inLinkLabel, normalClosers);
|
|
3385
|
-
appendInlineToken(target,
|
|
3210
|
+
appendInlineToken(target, 38, candidate.close, candidate.close + 1);
|
|
3386
3211
|
}
|
|
3387
3212
|
cursor = candidate.end;
|
|
3388
3213
|
}
|
|
3389
3214
|
copyRange(target, tokens, cursor, end, inLinkLabel, normalClosers);
|
|
3390
3215
|
}
|
|
3391
|
-
function
|
|
3216
|
+
function transformComponentTokens(source, tokens) {
|
|
3392
3217
|
if (!source.includes("[")) return tokens;
|
|
3393
3218
|
const syntax = candidates(source, tokens);
|
|
3394
3219
|
if (syntax.roots.length === 0) return tokens;
|
|
@@ -3398,20 +3223,27 @@ function rewriteComponentTokens(source, tokens) {
|
|
|
3398
3223
|
}
|
|
3399
3224
|
//#endregion
|
|
3400
3225
|
//#region src/profile/features/component/index.ts
|
|
3401
|
-
const feature$
|
|
3226
|
+
const feature$10 = {
|
|
3402
3227
|
block: {
|
|
3403
3228
|
rules: blockRules$2,
|
|
3404
3229
|
starts: blockStarts$2
|
|
3405
3230
|
},
|
|
3406
3231
|
inline: {
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3232
|
+
scan: [{
|
|
3233
|
+
marker: 58,
|
|
3234
|
+
scan(source, start, tokens) {
|
|
3235
|
+
const end = inlineComponentEnd(source, start);
|
|
3236
|
+
if (end === void 0) return -1;
|
|
3237
|
+
appendInlineToken(tokens, 33, start, end);
|
|
3238
|
+
return end;
|
|
3239
|
+
}
|
|
3240
|
+
}],
|
|
3241
|
+
resolve: { transform: transformComponentTokens },
|
|
3242
|
+
build: [{
|
|
3410
3243
|
kind: "container",
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
close: 37,
|
|
3244
|
+
token: 33,
|
|
3245
|
+
contentOpen: 34,
|
|
3246
|
+
close: 35,
|
|
3415
3247
|
build(open, close, sourceSpan, children, context) {
|
|
3416
3248
|
return {
|
|
3417
3249
|
type: "inlineComponent",
|
|
@@ -3423,9 +3255,8 @@ const feature$11 = {
|
|
|
3423
3255
|
}
|
|
3424
3256
|
}, {
|
|
3425
3257
|
kind: "pair",
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
close: 40,
|
|
3258
|
+
open: 37,
|
|
3259
|
+
close: 38,
|
|
3429
3260
|
build(open, close, sourceSpan, children) {
|
|
3430
3261
|
return {
|
|
3431
3262
|
type: "inlineComponent",
|
|
@@ -3441,20 +3272,21 @@ const feature$11 = {
|
|
|
3441
3272
|
//#endregion
|
|
3442
3273
|
//#region src/profile/utils.ts
|
|
3443
3274
|
function normalizeAssociationLabel(label) {
|
|
3275
|
+
scan: {
|
|
3276
|
+
let hasLowercase = false;
|
|
3277
|
+
for (let index = 0; index < label.length; index++) {
|
|
3278
|
+
const code = label.charCodeAt(index);
|
|
3279
|
+
if (code === 32) {
|
|
3280
|
+
if (index === 0 || index + 1 === label.length || label.charCodeAt(index + 1) === 32) break scan;
|
|
3281
|
+
continue;
|
|
3282
|
+
}
|
|
3283
|
+
if (code < 32 || code > 126) break scan;
|
|
3284
|
+
if (code >= 97 && code <= 122) hasLowercase = true;
|
|
3285
|
+
}
|
|
3286
|
+
return hasLowercase ? label.toUpperCase() : label;
|
|
3287
|
+
}
|
|
3444
3288
|
return label.trim().replace(/[ \t\r\n]+/g, " ").toLowerCase().toUpperCase();
|
|
3445
3289
|
}
|
|
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
3290
|
//#endregion
|
|
3459
3291
|
//#region src/profile/features/footnote/shared.ts
|
|
3460
3292
|
const footnoteDefinitionPrefix = "footnote\0";
|
|
@@ -3519,22 +3351,21 @@ function firstContentLine(line, match) {
|
|
|
3519
3351
|
};
|
|
3520
3352
|
}
|
|
3521
3353
|
const blockRules$1 = [{
|
|
3522
|
-
rule:
|
|
3354
|
+
rule: 21,
|
|
3523
3355
|
syntax: {
|
|
3524
3356
|
kind: "block",
|
|
3525
3357
|
open: 24,
|
|
3526
3358
|
close: 25
|
|
3527
3359
|
},
|
|
3528
3360
|
build(tokenStart, context) {
|
|
3529
|
-
const
|
|
3530
|
-
const fields = definitionFields(context.structure.tokens, token);
|
|
3361
|
+
const fields = definitionFields(context.structure.tokens, tokenStart);
|
|
3531
3362
|
return {
|
|
3532
3363
|
type: "footnoteDefinition",
|
|
3533
3364
|
identifier: fields.normalizedLabel.toLowerCase(),
|
|
3534
3365
|
label: semanticText(fields.label),
|
|
3535
3366
|
children: buildBlockChildren(tokenStart, context),
|
|
3536
3367
|
position: {
|
|
3537
|
-
start: context.structure.tokens.start(
|
|
3368
|
+
start: context.structure.tokens.start(tokenStart),
|
|
3538
3369
|
end: blockEnd(tokenStart, context)
|
|
3539
3370
|
}
|
|
3540
3371
|
};
|
|
@@ -3602,12 +3433,11 @@ const blockStarts$1 = [{
|
|
|
3602
3433
|
function closerIndex(tokens, start, end) {
|
|
3603
3434
|
for (let index = start + 1; index < inlineTokenCount(tokens); index++) {
|
|
3604
3435
|
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;
|
|
3436
|
+
if (inlineTokenKind(tokens, index) === 22 && inlineTokenEnd(tokens, index) === end) return index;
|
|
3607
3437
|
}
|
|
3608
3438
|
return -1;
|
|
3609
3439
|
}
|
|
3610
|
-
const
|
|
3440
|
+
const transformFootnoteTokens = (source, tokens, context) => {
|
|
3611
3441
|
let result;
|
|
3612
3442
|
for (let index = 0; index < inlineTokenCount(tokens); index++) {
|
|
3613
3443
|
const start = inlineTokenStart(tokens, index);
|
|
@@ -3621,26 +3451,9 @@ const rewriteFootnoteTokens = (source, tokens, context) => {
|
|
|
3621
3451
|
for (let prefix = 0; prefix < index; prefix++) copyInlineToken(result, tokens, prefix);
|
|
3622
3452
|
}
|
|
3623
3453
|
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
|
-
}
|
|
3454
|
+
appendInlineToken(result, 31, labelStart, label.end, inlineTokenFlags(tokens, index));
|
|
3630
3455
|
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
|
-
}
|
|
3456
|
+
continue;
|
|
3644
3457
|
}
|
|
3645
3458
|
if (result) copyInlineToken(result, tokens, index);
|
|
3646
3459
|
}
|
|
@@ -3648,16 +3461,16 @@ const rewriteFootnoteTokens = (source, tokens, context) => {
|
|
|
3648
3461
|
};
|
|
3649
3462
|
//#endregion
|
|
3650
3463
|
//#region src/profile/features/footnote/index.ts
|
|
3651
|
-
const feature$
|
|
3464
|
+
const feature$9 = {
|
|
3652
3465
|
block: {
|
|
3653
3466
|
rules: blockRules$1,
|
|
3654
3467
|
starts: blockStarts$1
|
|
3655
3468
|
},
|
|
3656
3469
|
inline: {
|
|
3657
|
-
|
|
3658
|
-
|
|
3470
|
+
resolve: { transform: transformFootnoteTokens },
|
|
3471
|
+
build: [{
|
|
3659
3472
|
kind: "leaf",
|
|
3660
|
-
token:
|
|
3473
|
+
token: 31,
|
|
3661
3474
|
build(tokenIndex, sourceSpan, context) {
|
|
3662
3475
|
const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(2, -1);
|
|
3663
3476
|
return {
|
|
@@ -3674,7 +3487,6 @@ const feature$10 = {
|
|
|
3674
3487
|
//#region src/profile/features/formatting.ts
|
|
3675
3488
|
const asteriskDelimiter = {
|
|
3676
3489
|
token: 10,
|
|
3677
|
-
marker: 42,
|
|
3678
3490
|
single: {
|
|
3679
3491
|
open: 13,
|
|
3680
3492
|
close: 14
|
|
@@ -3690,7 +3502,6 @@ const asteriskDelimiter = {
|
|
|
3690
3502
|
};
|
|
3691
3503
|
const underscoreDelimiter = {
|
|
3692
3504
|
token: 11,
|
|
3693
|
-
marker: 95,
|
|
3694
3505
|
single: {
|
|
3695
3506
|
open: 13,
|
|
3696
3507
|
close: 14
|
|
@@ -3707,7 +3518,6 @@ const underscoreDelimiter = {
|
|
|
3707
3518
|
};
|
|
3708
3519
|
const strikethroughDelimiter = {
|
|
3709
3520
|
token: 12,
|
|
3710
|
-
marker: 126,
|
|
3711
3521
|
double: {
|
|
3712
3522
|
open: 17,
|
|
3713
3523
|
close: 18
|
|
@@ -3727,16 +3537,16 @@ function createBuildFormatting(type) {
|
|
|
3727
3537
|
position: sourceSpan
|
|
3728
3538
|
});
|
|
3729
3539
|
}
|
|
3730
|
-
function feature$
|
|
3540
|
+
function feature$8(strikethroughOptions) {
|
|
3731
3541
|
const delimiters = [asteriskDelimiter, underscoreDelimiter];
|
|
3732
|
-
const
|
|
3542
|
+
const scans = [{
|
|
3733
3543
|
marker: 42,
|
|
3734
3544
|
scan: scanFormatting
|
|
3735
3545
|
}, {
|
|
3736
3546
|
marker: 95,
|
|
3737
3547
|
scan: scanFormatting
|
|
3738
3548
|
}];
|
|
3739
|
-
const
|
|
3549
|
+
const builds = [
|
|
3740
3550
|
{
|
|
3741
3551
|
kind: "leaf",
|
|
3742
3552
|
token: 10,
|
|
@@ -3761,7 +3571,7 @@ function feature$9(strikethroughOptions) {
|
|
|
3761
3571
|
}
|
|
3762
3572
|
];
|
|
3763
3573
|
if (strikethroughOptions) {
|
|
3764
|
-
|
|
3574
|
+
scans.push({
|
|
3765
3575
|
marker: 126,
|
|
3766
3576
|
scan: scanFormatting
|
|
3767
3577
|
});
|
|
@@ -3769,7 +3579,7 @@ function feature$9(strikethroughOptions) {
|
|
|
3769
3579
|
...strikethroughDelimiter,
|
|
3770
3580
|
single: strikethroughDelimiter.double
|
|
3771
3581
|
} : strikethroughDelimiter);
|
|
3772
|
-
|
|
3582
|
+
builds.push({
|
|
3773
3583
|
kind: "leaf",
|
|
3774
3584
|
token: 12,
|
|
3775
3585
|
build: buildInlineText
|
|
@@ -3781,59 +3591,9 @@ function feature$9(strikethroughOptions) {
|
|
|
3781
3591
|
});
|
|
3782
3592
|
}
|
|
3783
3593
|
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
|
-
}]
|
|
3594
|
+
scan: scans,
|
|
3595
|
+
resolve: { delimiters },
|
|
3596
|
+
build: builds
|
|
3837
3597
|
} };
|
|
3838
3598
|
}
|
|
3839
3599
|
//#endregion
|
|
@@ -3870,44 +3630,43 @@ function setextMarkerAt(source, line) {
|
|
|
3870
3630
|
}
|
|
3871
3631
|
const feature$7 = { block: {
|
|
3872
3632
|
rules: [{
|
|
3873
|
-
rule:
|
|
3633
|
+
rule: 0,
|
|
3874
3634
|
syntax: {
|
|
3875
3635
|
kind: "block",
|
|
3876
3636
|
open: 5,
|
|
3877
3637
|
close: 8
|
|
3878
3638
|
},
|
|
3879
3639
|
inlineContent: true,
|
|
3880
|
-
build(tokenStart, context) {
|
|
3881
|
-
const
|
|
3640
|
+
build(tokenStart, context, inline) {
|
|
3641
|
+
const tokens = context.structure.tokens;
|
|
3882
3642
|
return {
|
|
3883
3643
|
type: "heading",
|
|
3884
|
-
depth:
|
|
3885
|
-
children:
|
|
3644
|
+
depth: tokens.end(tokenStart) - tokens.start(tokenStart),
|
|
3645
|
+
children: inline.children,
|
|
3886
3646
|
position: {
|
|
3887
|
-
start:
|
|
3647
|
+
start: tokens.start(tokenStart),
|
|
3888
3648
|
end: blockEnd(tokenStart, context)
|
|
3889
3649
|
}
|
|
3890
3650
|
};
|
|
3891
3651
|
}
|
|
3892
3652
|
}, {
|
|
3893
|
-
rule:
|
|
3653
|
+
rule: 1,
|
|
3894
3654
|
syntax: {
|
|
3895
3655
|
kind: "block",
|
|
3896
3656
|
open: [6, 7],
|
|
3897
3657
|
close: 8
|
|
3898
3658
|
},
|
|
3899
3659
|
inlineContent: true,
|
|
3900
|
-
build(tokenStart, context) {
|
|
3901
|
-
const
|
|
3902
|
-
|
|
3903
|
-
const children = buildInlineChildren(tokenStart, context);
|
|
3660
|
+
build(tokenStart, context, inline) {
|
|
3661
|
+
const tokens = context.structure.tokens;
|
|
3662
|
+
const children = inline.children;
|
|
3904
3663
|
return {
|
|
3905
3664
|
type: "heading",
|
|
3906
|
-
depth:
|
|
3665
|
+
depth: tokens.kind(tokenStart) === 6 ? 1 : 2,
|
|
3907
3666
|
children,
|
|
3908
3667
|
position: {
|
|
3909
3668
|
start: firstChildStart(children),
|
|
3910
|
-
end:
|
|
3669
|
+
end: tokens.start(tokenStart + tokens.nodeLength(tokenStart) - 1)
|
|
3911
3670
|
}
|
|
3912
3671
|
};
|
|
3913
3672
|
}
|
|
@@ -4048,7 +3807,7 @@ const buildInlineHtml = (tokenIndex, sourceSpan, context) => {
|
|
|
4048
3807
|
const feature$6 = {
|
|
4049
3808
|
block: {
|
|
4050
3809
|
rules: [{
|
|
4051
|
-
rule:
|
|
3810
|
+
rule: 14,
|
|
4052
3811
|
syntax: {
|
|
4053
3812
|
kind: "leaf",
|
|
4054
3813
|
token: 23
|
|
@@ -4056,9 +3815,8 @@ const feature$6 = {
|
|
|
4056
3815
|
build(tokenStart, context) {
|
|
4057
3816
|
const offset = context.structure.tokens.start(tokenStart);
|
|
4058
3817
|
const end = offset + context.structure.lenOf(tokenStart);
|
|
4059
|
-
const
|
|
4060
|
-
|
|
4061
|
-
let html = normalizeLines(context.structure.tokens.text(context.source, token));
|
|
3818
|
+
const unterminated = htmlBlockUnterminated(tokenStart, context);
|
|
3819
|
+
let html = normalizeLines(context.structure.tokens.text(context.source, tokenStart));
|
|
4062
3820
|
if (!unterminated && html.endsWith("\n")) html = html.slice(0, -1);
|
|
4063
3821
|
return {
|
|
4064
3822
|
type: "html",
|
|
@@ -4092,7 +3850,7 @@ const feature$6 = {
|
|
|
4092
3850
|
}]
|
|
4093
3851
|
},
|
|
4094
3852
|
inline: {
|
|
4095
|
-
|
|
3853
|
+
scan: [{
|
|
4096
3854
|
marker: 60,
|
|
4097
3855
|
scan(source, start, tokens) {
|
|
4098
3856
|
let end = matchInlinePatternEnd(htmlComment, source, start);
|
|
@@ -4107,13 +3865,13 @@ const feature$6 = {
|
|
|
4107
3865
|
}
|
|
4108
3866
|
if (end < 0) {
|
|
4109
3867
|
end = start + 1;
|
|
4110
|
-
kind =
|
|
3868
|
+
kind = 39;
|
|
4111
3869
|
}
|
|
4112
3870
|
appendInlineToken(tokens, kind, start, end);
|
|
4113
3871
|
return end;
|
|
4114
3872
|
}
|
|
4115
3873
|
}],
|
|
4116
|
-
|
|
3874
|
+
build: [{
|
|
4117
3875
|
kind: "leaf",
|
|
4118
3876
|
token: 5,
|
|
4119
3877
|
build: buildInlineHtml
|
|
@@ -4206,28 +3964,6 @@ function linkTailEnd(source, start) {
|
|
|
4206
3964
|
offset = skipWhitespace(source, offset);
|
|
4207
3965
|
return source.charCodeAt(offset) === 41 ? offset + 1 : -1;
|
|
4208
3966
|
}
|
|
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
3967
|
function isLinkWhitespace(code) {
|
|
4232
3968
|
return code === 9 || code === 10 || code === 13 || code === 32;
|
|
4233
3969
|
}
|
|
@@ -4319,13 +4055,13 @@ const buildInlineReferenceImage = createBuildMedia("image", "reference");
|
|
|
4319
4055
|
const buildInlineLink = createBuildMedia("link", "direct");
|
|
4320
4056
|
const buildInlineReferenceLink = createBuildMedia("link", "reference");
|
|
4321
4057
|
const feature$5 = { inline: {
|
|
4322
|
-
|
|
4058
|
+
scan: [
|
|
4323
4059
|
{
|
|
4324
4060
|
marker: 33,
|
|
4325
4061
|
scan(source, start, tokens) {
|
|
4326
4062
|
const image = source.charCodeAt(start + 1) === 91;
|
|
4327
4063
|
const end = start + (image ? 2 : 1);
|
|
4328
|
-
appendInlineToken(tokens, image ? 19 :
|
|
4064
|
+
appendInlineToken(tokens, image ? 19 : 39, start, end);
|
|
4329
4065
|
return end;
|
|
4330
4066
|
}
|
|
4331
4067
|
},
|
|
@@ -4342,42 +4078,38 @@ const feature$5 = { inline: {
|
|
|
4342
4078
|
scan(source, start, tokens) {
|
|
4343
4079
|
let end = linkTailEnd(source, start);
|
|
4344
4080
|
let kind = 21;
|
|
4345
|
-
if (end < 0) {
|
|
4346
|
-
end = referenceTailEnd(source, start);
|
|
4347
|
-
kind = 22;
|
|
4348
|
-
}
|
|
4349
4081
|
if (end < 0) {
|
|
4350
4082
|
end = start + 1;
|
|
4351
|
-
kind =
|
|
4083
|
+
kind = 22;
|
|
4352
4084
|
}
|
|
4353
|
-
appendInlineToken(tokens, kind, start, end, kind ===
|
|
4085
|
+
appendInlineToken(tokens, kind, start, end, kind === 22 ? 0 : 16);
|
|
4354
4086
|
return end;
|
|
4355
4087
|
}
|
|
4356
4088
|
}
|
|
4357
4089
|
],
|
|
4358
|
-
|
|
4090
|
+
build: [
|
|
4359
4091
|
{
|
|
4360
4092
|
kind: "pair",
|
|
4361
|
-
open:
|
|
4362
|
-
close:
|
|
4093
|
+
open: 23,
|
|
4094
|
+
close: 24,
|
|
4363
4095
|
build: buildInlineLink
|
|
4364
4096
|
},
|
|
4365
4097
|
{
|
|
4366
4098
|
kind: "pair",
|
|
4367
|
-
open:
|
|
4368
|
-
close:
|
|
4099
|
+
open: 25,
|
|
4100
|
+
close: 26,
|
|
4369
4101
|
build: buildInlineImage
|
|
4370
4102
|
},
|
|
4371
4103
|
{
|
|
4372
4104
|
kind: "pair",
|
|
4373
|
-
open:
|
|
4374
|
-
close:
|
|
4105
|
+
open: 27,
|
|
4106
|
+
close: 28,
|
|
4375
4107
|
build: buildInlineReferenceLink
|
|
4376
4108
|
},
|
|
4377
4109
|
{
|
|
4378
4110
|
kind: "pair",
|
|
4379
|
-
open:
|
|
4380
|
-
close:
|
|
4111
|
+
open: 29,
|
|
4112
|
+
close: 30,
|
|
4381
4113
|
build: buildInlineReferenceImage
|
|
4382
4114
|
},
|
|
4383
4115
|
{
|
|
@@ -4420,16 +4152,6 @@ const feature$5 = { inline: {
|
|
|
4420
4152
|
kind: "leaf",
|
|
4421
4153
|
token: 22,
|
|
4422
4154
|
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
4155
|
}
|
|
4434
4156
|
]
|
|
4435
4157
|
} };
|
|
@@ -4531,10 +4253,37 @@ function hasBlankLineBetween(source, start, end, stripBlockQuotes) {
|
|
|
4531
4253
|
}
|
|
4532
4254
|
return false;
|
|
4533
4255
|
}
|
|
4256
|
+
function isTaskListWhitespace(code) {
|
|
4257
|
+
return code === 32 || code >= 9 && code <= 13;
|
|
4258
|
+
}
|
|
4259
|
+
function taskListMarkerAt(source, start, end) {
|
|
4260
|
+
while (source.charCodeAt(start) === 32) start++;
|
|
4261
|
+
if (source.charCodeAt(start++) !== 91) return;
|
|
4262
|
+
const state = source.charCodeAt(start++);
|
|
4263
|
+
const checked = state === 88 || state === 120;
|
|
4264
|
+
if (!checked && !isTaskListWhitespace(state)) return;
|
|
4265
|
+
if (source.charCodeAt(start++) !== 93) return;
|
|
4266
|
+
if (start >= end) return;
|
|
4267
|
+
const whitespace = source.charCodeAt(start++);
|
|
4268
|
+
if (!isTaskListWhitespace(whitespace)) return;
|
|
4269
|
+
if (whitespace === 13 && source.charCodeAt(start) === 10) start++;
|
|
4270
|
+
return {
|
|
4271
|
+
checked,
|
|
4272
|
+
contentStart: start
|
|
4273
|
+
};
|
|
4274
|
+
}
|
|
4275
|
+
function hasTaskListContent(source, tokens, firstChunk, contentStart) {
|
|
4276
|
+
for (let token = firstChunk; tokens.kind(token) === 1; token++) {
|
|
4277
|
+
const start = token === firstChunk ? contentStart : tokens.start(token);
|
|
4278
|
+
const end = tokens.end(token);
|
|
4279
|
+
for (let offset = start; offset < end; offset++) if (!isTaskListWhitespace(source.charCodeAt(offset))) return true;
|
|
4280
|
+
}
|
|
4281
|
+
return false;
|
|
4282
|
+
}
|
|
4534
4283
|
function childrenSpread(tokenStart, stripBlockQuotes, context, nestedRule) {
|
|
4535
4284
|
const structure = context.structure;
|
|
4536
4285
|
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.
|
|
4286
|
+
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
4287
|
const current = payloadBounds(childId, context);
|
|
4539
4288
|
if (previous && hasBlankLineBetween(context.source, previous.end, current.start, stripBlockQuotes)) return true;
|
|
4540
4289
|
previous = current;
|
|
@@ -4542,17 +4291,15 @@ function childrenSpread(tokenStart, stripBlockQuotes, context, nestedRule) {
|
|
|
4542
4291
|
return false;
|
|
4543
4292
|
}
|
|
4544
4293
|
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);
|
|
4294
|
+
const markerKind = context.structure.tokens.kind(tokenStart);
|
|
4548
4295
|
const children = buildBlockChildren(tokenStart, context);
|
|
4549
4296
|
return {
|
|
4550
4297
|
type: "listItem",
|
|
4551
4298
|
spread: childrenSpread(tokenStart, true, context),
|
|
4552
|
-
checked: null,
|
|
4299
|
+
checked: markerKind === 17 ? true : markerKind === 16 ? false : null,
|
|
4553
4300
|
children,
|
|
4554
4301
|
position: {
|
|
4555
|
-
start: context.structure.tokens.start(
|
|
4302
|
+
start: context.structure.tokens.start(tokenStart),
|
|
4556
4303
|
end: lastChildEnd(children, blockEnd(tokenStart, context))
|
|
4557
4304
|
}
|
|
4558
4305
|
};
|
|
@@ -4560,153 +4307,169 @@ const buildListItem = (tokenStart, context) => {
|
|
|
4560
4307
|
function createBuildList(ordered) {
|
|
4561
4308
|
return (tokenStart, context) => {
|
|
4562
4309
|
const structure = context.structure;
|
|
4563
|
-
const itemRule = ordered ? "OrderedListItem" : "UnorderedListItem";
|
|
4564
|
-
const listMarker = blockToken(tokenStart, ordered ? 15 : 11, context);
|
|
4565
4310
|
const items = [];
|
|
4566
|
-
for (let childId = structure.firstChild(tokenStart); childId !== noBlockEntry; childId = structure.nextChild(tokenStart, childId)) if (childId >= 0 && structure.
|
|
4311
|
+
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
4312
|
return {
|
|
4568
4313
|
type: "list",
|
|
4569
4314
|
ordered,
|
|
4570
|
-
start: ordered ? Number.parseInt(context.structure.tokens.text(context.source,
|
|
4571
|
-
spread: childrenSpread(tokenStart, false, context,
|
|
4315
|
+
start: ordered ? Number.parseInt(context.structure.tokens.text(context.source, tokenStart), 10) : null,
|
|
4316
|
+
spread: childrenSpread(tokenStart, false, context, 17),
|
|
4572
4317
|
children: items,
|
|
4573
4318
|
position: {
|
|
4574
|
-
start: context.structure.tokens.start(
|
|
4575
|
-
end: lastChildEnd(items, context.structure.tokens.end(
|
|
4319
|
+
start: context.structure.tokens.start(tokenStart),
|
|
4320
|
+
end: lastChildEnd(items, context.structure.tokens.end(tokenStart))
|
|
4576
4321
|
}
|
|
4577
4322
|
};
|
|
4578
4323
|
};
|
|
4579
4324
|
}
|
|
4580
|
-
const
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4325
|
+
const listStart = (source, lines, start, out, contentOffset, context) => {
|
|
4326
|
+
const listMarker = listMarkerAt(source, lines[start]);
|
|
4327
|
+
if (!listMarker) return;
|
|
4328
|
+
const kind = listMarker.kind;
|
|
4329
|
+
const listOpen = kind === "ordered" ? 13 : 11;
|
|
4330
|
+
const listClose = kind === "ordered" ? 14 : 12;
|
|
4331
|
+
out.push(listOpen, listMarker.offset, listMarker.offset + listMarker.text.length);
|
|
4332
|
+
let index = start;
|
|
4333
|
+
let listEnd = listMarker.offset + listMarker.text.length;
|
|
4334
|
+
while (index < lines.length) {
|
|
4335
|
+
const marker = listMarkerAt(source, lines[index]);
|
|
4336
|
+
if (!marker || !sameList(marker, listMarker)) break;
|
|
4337
|
+
out.push(15, marker.offset, marker.offset + marker.text.length);
|
|
4338
|
+
const itemLines = [{
|
|
4339
|
+
...lines[index],
|
|
4340
|
+
start: marker.contentOffset,
|
|
4341
|
+
prefixColumns: marker.contentPrefixColumns
|
|
4342
|
+
}];
|
|
4343
|
+
let hasContent = !isBlank(source, itemLines[0]);
|
|
4344
|
+
let lazyParagraph = context.endsWithParagraphLeaf(source, itemLines[0]);
|
|
4345
|
+
index++;
|
|
4346
|
+
while (index < lines.length) {
|
|
4347
|
+
const candidate = listMarkerAt(source, lines[index]);
|
|
4348
|
+
if (candidate && candidate.indent < marker.contentIndent) break;
|
|
4349
|
+
if (isBlank(source, lines[index])) {
|
|
4350
|
+
if (!hasContent) {
|
|
4351
|
+
index++;
|
|
4352
|
+
break;
|
|
4353
|
+
}
|
|
4354
|
+
itemLines.push(lines[index]);
|
|
4355
|
+
lazyParagraph = false;
|
|
4356
|
+
index++;
|
|
4357
|
+
continue;
|
|
4588
4358
|
}
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4359
|
+
if (indentOf(source, lines[index]).columns >= marker.contentIndent) {
|
|
4360
|
+
const content = contentAfterColumns(source, lines[index], marker.contentIndent);
|
|
4361
|
+
const contentLine = {
|
|
4362
|
+
...lines[index],
|
|
4363
|
+
start: content.offset,
|
|
4364
|
+
prefixColumns: content.prefixColumns
|
|
4365
|
+
};
|
|
4366
|
+
itemLines.push(contentLine);
|
|
4367
|
+
hasContent = true;
|
|
4368
|
+
lazyParagraph = context.endsWithParagraphLeaf(source, contentLine);
|
|
4369
|
+
index++;
|
|
4370
|
+
continue;
|
|
4596
4371
|
}
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4372
|
+
if (!lazyParagraph || context.startsInterruptingBlock(source, lines[index])) break;
|
|
4373
|
+
itemLines.push({
|
|
4374
|
+
...lines[index],
|
|
4375
|
+
lazy: true
|
|
4376
|
+
});
|
|
4377
|
+
index++;
|
|
4378
|
+
}
|
|
4379
|
+
context.scanLines(source, itemLines, out);
|
|
4380
|
+
listEnd = itemLines.at(-1)?.next ?? marker.offset;
|
|
4381
|
+
out.push(18, listEnd, listEnd);
|
|
4382
|
+
}
|
|
4383
|
+
out.push(listClose, listEnd, listEnd);
|
|
4384
|
+
return index;
|
|
4385
|
+
};
|
|
4386
|
+
const taskListStart = (source, lines, start, out, contentOffset, context) => {
|
|
4387
|
+
const listTokenStart = out.length;
|
|
4388
|
+
const nextLine = listStart(source, lines, start, out, contentOffset, context);
|
|
4389
|
+
if (nextLine === void 0) return;
|
|
4390
|
+
for (let item = listTokenStart + 1; item < out.length; item++) {
|
|
4391
|
+
if (out.kind(item) !== 15) continue;
|
|
4392
|
+
let paragraph = item + 1;
|
|
4393
|
+
let contentKind = out.kind(paragraph);
|
|
4394
|
+
while (contentKind === 26 || contentKind === 27 || contentKind === 28) {
|
|
4395
|
+
paragraph++;
|
|
4396
|
+
contentKind = out.kind(paragraph);
|
|
4397
|
+
}
|
|
4398
|
+
if (contentKind !== 9) continue;
|
|
4399
|
+
const firstChunk = paragraph + 1;
|
|
4400
|
+
const marker = taskListMarkerAt(source, out.start(firstChunk), out.end(firstChunk));
|
|
4401
|
+
if (!marker || !hasTaskListContent(source, out, firstChunk, marker.contentStart)) continue;
|
|
4402
|
+
out.setKind(item, marker.checked ? 17 : 16);
|
|
4403
|
+
out.setStart(firstChunk, marker.contentStart);
|
|
4404
|
+
}
|
|
4405
|
+
return nextLine;
|
|
4406
|
+
};
|
|
4407
|
+
function feature$4(taskList = false) {
|
|
4408
|
+
return { block: {
|
|
4409
|
+
rules: [
|
|
4410
|
+
{
|
|
4411
|
+
rule: 17,
|
|
4412
|
+
syntax: {
|
|
4413
|
+
kind: "frame",
|
|
4414
|
+
open: [
|
|
4415
|
+
15,
|
|
4416
|
+
16,
|
|
4417
|
+
17
|
|
4418
|
+
],
|
|
4419
|
+
close: 18
|
|
4420
|
+
}
|
|
4604
4421
|
},
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4422
|
+
{
|
|
4423
|
+
rule: 18,
|
|
4424
|
+
syntax: {
|
|
4425
|
+
kind: "block",
|
|
4426
|
+
open: 11,
|
|
4427
|
+
close: 12
|
|
4428
|
+
},
|
|
4429
|
+
build: createBuildList(false)
|
|
4613
4430
|
},
|
|
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
|
|
4431
|
+
{
|
|
4432
|
+
rule: 19,
|
|
4433
|
+
syntax: {
|
|
4434
|
+
kind: "block",
|
|
4435
|
+
open: 13,
|
|
4436
|
+
close: 14
|
|
4437
|
+
},
|
|
4438
|
+
build: createBuildList(true)
|
|
4439
|
+
}
|
|
4632
4440
|
],
|
|
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],
|
|
4441
|
+
starts: [{
|
|
4442
|
+
codes: [
|
|
4443
|
+
42,
|
|
4444
|
+
43,
|
|
4445
|
+
45,
|
|
4446
|
+
48,
|
|
4447
|
+
49,
|
|
4448
|
+
50,
|
|
4449
|
+
51,
|
|
4450
|
+
52,
|
|
4451
|
+
53,
|
|
4452
|
+
54,
|
|
4453
|
+
55,
|
|
4454
|
+
56,
|
|
4455
|
+
57
|
|
4456
|
+
],
|
|
4457
|
+
unwrapLazyContinuation(source, line) {
|
|
4458
|
+
const marker = listMarkerAt(source, line);
|
|
4459
|
+
return marker ? {
|
|
4460
|
+
...line,
|
|
4662
4461
|
start: marker.contentOffset,
|
|
4663
4462
|
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
|
-
} };
|
|
4463
|
+
} : void 0;
|
|
4464
|
+
},
|
|
4465
|
+
interrupt(source, line) {
|
|
4466
|
+
const marker = listMarkerAt(source, line);
|
|
4467
|
+
return hasListContent(source, line, marker) && (marker?.kind === "unordered" || marker?.kind === "ordered" && marker.startNumber === 1);
|
|
4468
|
+
},
|
|
4469
|
+
start: taskList ? taskListStart : listStart
|
|
4470
|
+
}]
|
|
4471
|
+
} };
|
|
4472
|
+
}
|
|
4710
4473
|
//#endregion
|
|
4711
4474
|
//#region src/profile/features/math/block.ts
|
|
4712
4475
|
const mathFenceRule = {
|
|
@@ -4715,7 +4478,7 @@ const mathFenceRule = {
|
|
|
4715
4478
|
minimumLength: 2
|
|
4716
4479
|
};
|
|
4717
4480
|
const blockRules = [{
|
|
4718
|
-
rule:
|
|
4481
|
+
rule: 22,
|
|
4719
4482
|
syntax: {
|
|
4720
4483
|
kind: "leaf",
|
|
4721
4484
|
token: 21
|
|
@@ -4723,9 +4486,8 @@ const blockRules = [{
|
|
|
4723
4486
|
build(tokenStart, context) {
|
|
4724
4487
|
const offset = context.structure.tokens.start(tokenStart);
|
|
4725
4488
|
const end = offset + context.structure.lenOf(tokenStart);
|
|
4726
|
-
const
|
|
4727
|
-
const
|
|
4728
|
-
const block = context.structure.tokens.value(token);
|
|
4489
|
+
const value = context.structure.tokens.text(context.source, tokenStart);
|
|
4490
|
+
const block = context.structure.tokens.value(tokenStart);
|
|
4729
4491
|
if (!block) throw new Error("MathBlockToken has no fence metadata");
|
|
4730
4492
|
return {
|
|
4731
4493
|
type: "math",
|
|
@@ -4756,7 +4518,7 @@ const blockStarts = [{
|
|
|
4756
4518
|
}];
|
|
4757
4519
|
//#endregion
|
|
4758
4520
|
//#region src/profile/features/math/inline.ts
|
|
4759
|
-
function
|
|
4521
|
+
function createMathScanRule(singleDollarTextMath) {
|
|
4760
4522
|
const minimum = singleDollarTextMath ? 1 : 2;
|
|
4761
4523
|
return {
|
|
4762
4524
|
marker: 36,
|
|
@@ -4793,7 +4555,7 @@ function mathTextValue(value) {
|
|
|
4793
4555
|
if (startPadding > 0 && endPadding > 0 && /[^ \r\n]/.test(result)) result = result.slice(startPadding, -endPadding);
|
|
4794
4556
|
return result;
|
|
4795
4557
|
}
|
|
4796
|
-
const
|
|
4558
|
+
const inlineBuilds = [{
|
|
4797
4559
|
kind: "leaf",
|
|
4798
4560
|
token: 3,
|
|
4799
4561
|
build(tokenIndex, sourceSpan, context) {
|
|
@@ -4814,8 +4576,8 @@ function feature$3(options) {
|
|
|
4814
4576
|
starts: blockStarts
|
|
4815
4577
|
},
|
|
4816
4578
|
inline: {
|
|
4817
|
-
|
|
4818
|
-
|
|
4579
|
+
scan: [createMathScanRule(singleDollarTextMath)],
|
|
4580
|
+
build: inlineBuilds
|
|
4819
4581
|
}
|
|
4820
4582
|
};
|
|
4821
4583
|
}
|
|
@@ -4862,15 +4624,15 @@ const feature$2 = { block: {
|
|
|
4862
4624
|
return index;
|
|
4863
4625
|
}],
|
|
4864
4626
|
rules: [{
|
|
4865
|
-
rule:
|
|
4627
|
+
rule: 9,
|
|
4866
4628
|
syntax: {
|
|
4867
4629
|
kind: "block",
|
|
4868
4630
|
open: 9,
|
|
4869
4631
|
close: 10
|
|
4870
4632
|
},
|
|
4871
4633
|
inlineContent: true,
|
|
4872
|
-
build(tokenStart, context) {
|
|
4873
|
-
const children =
|
|
4634
|
+
build(tokenStart, context, inline) {
|
|
4635
|
+
const children = inline.children;
|
|
4874
4636
|
return {
|
|
4875
4637
|
type: "paragraph",
|
|
4876
4638
|
children,
|
|
@@ -4907,7 +4669,10 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset) {
|
|
|
4907
4669
|
continue;
|
|
4908
4670
|
}
|
|
4909
4671
|
if (code === 91) return;
|
|
4910
|
-
if (code === 93
|
|
4672
|
+
if (code === 93) {
|
|
4673
|
+
if (source.charCodeAt(offset + 1) === 58) break scanLabel;
|
|
4674
|
+
return;
|
|
4675
|
+
}
|
|
4911
4676
|
if (code !== 32 && code !== 9) labelHasContent = true;
|
|
4912
4677
|
if (++labelLength > 999) return;
|
|
4913
4678
|
offset++;
|
|
@@ -4947,14 +4712,16 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset) {
|
|
|
4947
4712
|
} else {
|
|
4948
4713
|
let depth = 0;
|
|
4949
4714
|
const destinationStart = offset;
|
|
4950
|
-
while (offset < lines[lineIndex].end
|
|
4951
|
-
|
|
4715
|
+
while (offset < lines[lineIndex].end) {
|
|
4716
|
+
const code = source.charCodeAt(offset);
|
|
4717
|
+
if (code === 32 || code === 9) break;
|
|
4718
|
+
if (code === 92 && offset + 1 < lines[lineIndex].end) {
|
|
4952
4719
|
offset += 2;
|
|
4953
4720
|
continue;
|
|
4954
4721
|
}
|
|
4955
|
-
if (
|
|
4722
|
+
if (code === 40) {
|
|
4956
4723
|
if (++depth > 32) return;
|
|
4957
|
-
} else if (
|
|
4724
|
+
} else if (code === 41 && --depth < 0) return;
|
|
4958
4725
|
offset++;
|
|
4959
4726
|
}
|
|
4960
4727
|
if (offset === destinationStart || depth !== 0) return;
|
|
@@ -5023,54 +4790,104 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset) {
|
|
|
5023
4790
|
fields
|
|
5024
4791
|
};
|
|
5025
4792
|
}
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
let
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
4793
|
+
function referenceLabelEnd(source, start) {
|
|
4794
|
+
if (source.charCodeAt(start) !== 91) return -1;
|
|
4795
|
+
let offset = start + 1;
|
|
4796
|
+
if (source.charCodeAt(offset) === 93) return offset + 1;
|
|
4797
|
+
let characters = 0;
|
|
4798
|
+
let hasContent = false;
|
|
4799
|
+
while (offset < source.length && characters < 999) {
|
|
4800
|
+
const code = source.charCodeAt(offset);
|
|
4801
|
+
if (code === 93) return hasContent ? offset + 1 : -1;
|
|
4802
|
+
if (code === 91) return -1;
|
|
4803
|
+
if (code === 92) {
|
|
4804
|
+
if (offset + 1 >= source.length) return -1;
|
|
4805
|
+
hasContent = true;
|
|
4806
|
+
offset += 2;
|
|
4807
|
+
} else {
|
|
4808
|
+
hasContent ||= code !== 9 && code !== 10 && code !== 13 && code !== 32;
|
|
4809
|
+
offset++;
|
|
5040
4810
|
}
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
4811
|
+
characters++;
|
|
4812
|
+
}
|
|
4813
|
+
return -1;
|
|
4814
|
+
}
|
|
4815
|
+
function acceptsShortcutLabel(source, start, end) {
|
|
4816
|
+
let hasContent = false;
|
|
4817
|
+
let characters = 0;
|
|
4818
|
+
for (let offset = start; offset < end; offset++) {
|
|
4819
|
+
const code = source.charCodeAt(offset);
|
|
4820
|
+
hasContent ||= code !== 9 && code !== 10 && code !== 13 && code !== 32;
|
|
4821
|
+
if (code >= 55296 && code <= 56319 && offset + 1 < end) {
|
|
4822
|
+
const trailing = source.charCodeAt(offset + 1);
|
|
4823
|
+
if (trailing >= 56320 && trailing <= 57343) offset++;
|
|
5047
4824
|
}
|
|
5048
|
-
if (
|
|
5049
|
-
|
|
4825
|
+
if (++characters > 999) return false;
|
|
4826
|
+
}
|
|
4827
|
+
return hasContent;
|
|
4828
|
+
}
|
|
4829
|
+
function resolveReferenceTokens(source, tokens, context) {
|
|
4830
|
+
let closerEnds;
|
|
4831
|
+
let inactiveBefore = 0;
|
|
4832
|
+
let lastNestedOpener = 0;
|
|
4833
|
+
let openers;
|
|
4834
|
+
let replacementKinds;
|
|
4835
|
+
const count = inlineTokenCount(tokens);
|
|
4836
|
+
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
4837
|
+
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
4838
|
+
if (kind === 20) {
|
|
4839
|
+
(openers ??= []).push(tokenIndex);
|
|
4840
|
+
lastNestedOpener = tokenIndex + 1;
|
|
5050
4841
|
continue;
|
|
5051
4842
|
}
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
4843
|
+
if (kind === 19) {
|
|
4844
|
+
(openers ??= []).push(~tokenIndex);
|
|
4845
|
+
lastNestedOpener = tokenIndex + 1;
|
|
5055
4846
|
continue;
|
|
5056
4847
|
}
|
|
5057
|
-
if (
|
|
5058
|
-
|
|
5059
|
-
|
|
4848
|
+
if (kind !== 21 && kind !== 22) continue;
|
|
4849
|
+
const encodedOpener = openers?.pop();
|
|
4850
|
+
if (encodedOpener === void 0) continue;
|
|
4851
|
+
const image = encodedOpener < 0;
|
|
4852
|
+
const openerIndex = image ? ~encodedOpener : encodedOpener;
|
|
4853
|
+
if (!image && openerIndex + 1 < inactiveBefore) continue;
|
|
4854
|
+
const contentStart = inlineTokenEnd(tokens, openerIndex);
|
|
4855
|
+
const contentEnd = inlineTokenStart(tokens, tokenIndex);
|
|
4856
|
+
let closeEnd = inlineTokenEnd(tokens, tokenIndex);
|
|
4857
|
+
let reference = false;
|
|
4858
|
+
if (kind === 22) {
|
|
4859
|
+
const labelEnd = referenceLabelEnd(source, closeEnd);
|
|
4860
|
+
if (labelEnd > 0) {
|
|
4861
|
+
const label = source.slice(closeEnd + 1, labelEnd - 1) || source.slice(contentStart, contentEnd);
|
|
4862
|
+
if (!context.hasDefinition(normalizeAssociationLabel(label))) continue;
|
|
4863
|
+
closeEnd = labelEnd;
|
|
4864
|
+
reference = true;
|
|
4865
|
+
} else {
|
|
4866
|
+
if (lastNestedOpener > openerIndex + 1 || !acceptsShortcutLabel(source, contentStart, contentEnd) || !context.hasDefinition(normalizeAssociationLabel(source.slice(contentStart, contentEnd)))) continue;
|
|
4867
|
+
reference = true;
|
|
4868
|
+
}
|
|
5060
4869
|
}
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
4870
|
+
replacementKinds ??= [];
|
|
4871
|
+
replacementKinds[openerIndex] = image ? reference ? 29 : 25 : reference ? 27 : 23;
|
|
4872
|
+
replacementKinds[tokenIndex] = image ? reference ? 30 : 26 : reference ? 28 : 24;
|
|
4873
|
+
closerEnds ??= [];
|
|
4874
|
+
closerEnds[tokenIndex] = closeEnd;
|
|
4875
|
+
if (!image) inactiveBefore = Math.max(inactiveBefore, openerIndex + 1);
|
|
4876
|
+
while (tokenIndex + 1 < count && inlineTokenStart(tokens, tokenIndex + 1) < closeEnd) tokenIndex++;
|
|
5066
4877
|
}
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
4878
|
+
if (!replacementKinds) return tokens;
|
|
4879
|
+
const result = [];
|
|
4880
|
+
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
4881
|
+
const closerEnd = closerEnds?.[tokenIndex];
|
|
4882
|
+
const kind = replacementKinds[tokenIndex];
|
|
4883
|
+
if (closerEnd !== void 0) {
|
|
4884
|
+
appendInlineToken(result, kind, inlineTokenStart(tokens, tokenIndex), closerEnd, inlineTokenFlags(tokens, tokenIndex));
|
|
4885
|
+
while (tokenIndex + 1 < count && inlineTokenStart(tokens, tokenIndex + 1) < closerEnd) tokenIndex++;
|
|
4886
|
+
} else if (kind !== void 0) appendInlineToken(result, kind, inlineTokenStart(tokens, tokenIndex), inlineTokenEnd(tokens, tokenIndex), inlineTokenFlags(tokens, tokenIndex));
|
|
4887
|
+
else copyInlineToken(result, tokens, tokenIndex);
|
|
4888
|
+
}
|
|
4889
|
+
return result;
|
|
4890
|
+
}
|
|
5074
4891
|
const feature$1 = {
|
|
5075
4892
|
block: {
|
|
5076
4893
|
restart(source, lines, changedStart, changedEnd) {
|
|
@@ -5084,15 +4901,14 @@ const feature$1 = {
|
|
|
5084
4901
|
return candidate;
|
|
5085
4902
|
},
|
|
5086
4903
|
rules: [{
|
|
5087
|
-
rule:
|
|
4904
|
+
rule: 2,
|
|
5088
4905
|
syntax: {
|
|
5089
4906
|
kind: "block",
|
|
5090
4907
|
open: 26,
|
|
5091
4908
|
close: 28
|
|
5092
4909
|
},
|
|
5093
4910
|
build(tokenStart, context) {
|
|
5094
|
-
const
|
|
5095
|
-
const fields = linkDefinitionFields(context.structure.tokens, token);
|
|
4911
|
+
const fields = linkDefinitionFields(context.structure.tokens, tokenStart);
|
|
5096
4912
|
return {
|
|
5097
4913
|
type: "definition",
|
|
5098
4914
|
identifier: fields.definitionKey.toLowerCase(),
|
|
@@ -5100,7 +4916,7 @@ const feature$1 = {
|
|
|
5100
4916
|
url: semanticText(fields.destination),
|
|
5101
4917
|
title: fields.title === void 0 ? null : semanticText(fields.title),
|
|
5102
4918
|
position: {
|
|
5103
|
-
start: context.structure.tokens.start(
|
|
4919
|
+
start: context.structure.tokens.start(tokenStart) + fields.markerOffset,
|
|
5104
4920
|
end: blockEnd(tokenStart, context)
|
|
5105
4921
|
}
|
|
5106
4922
|
};
|
|
@@ -5127,71 +4943,7 @@ const feature$1 = {
|
|
|
5127
4943
|
}
|
|
5128
4944
|
}]
|
|
5129
4945
|
},
|
|
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
|
-
}
|
|
4946
|
+
inline: { resolve: { transform: resolveReferenceTokens } }
|
|
5195
4947
|
};
|
|
5196
4948
|
//#endregion
|
|
5197
4949
|
//#region src/profile/features/table.ts
|
|
@@ -5251,7 +5003,7 @@ function alignmentAt(source, cell) {
|
|
|
5251
5003
|
if (right) end--;
|
|
5252
5004
|
if (start === end) return;
|
|
5253
5005
|
for (let offset = start; offset < end; offset++) if (source[offset] !== "-") return;
|
|
5254
|
-
return left ? right ?
|
|
5006
|
+
return left ? right ? 37 : 35 : right ? 36 : 34;
|
|
5255
5007
|
}
|
|
5256
5008
|
function delimiterAt(source, line) {
|
|
5257
5009
|
const indent = lineIndent(source, line);
|
|
@@ -5275,48 +5027,42 @@ function emitTableRow(line, cells, out) {
|
|
|
5275
5027
|
out.push(31, cells[0].start, cells[0].start);
|
|
5276
5028
|
for (const cell of cells) {
|
|
5277
5029
|
out.push(33, cell.start, cell.start);
|
|
5278
|
-
|
|
5279
|
-
out.push(34, cell.end, cell.end);
|
|
5030
|
+
out.push(1, cell.contentStart, cell.contentEnd);
|
|
5280
5031
|
}
|
|
5281
5032
|
out.push(32, line.end, line.end);
|
|
5282
5033
|
}
|
|
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);
|
|
5034
|
+
const buildTableCell = (tokenStart, context, inline) => {
|
|
5035
|
+
const tokens = context.structure.tokens;
|
|
5292
5036
|
return {
|
|
5293
5037
|
type: "tableCell",
|
|
5294
|
-
children:
|
|
5038
|
+
children: inline.children,
|
|
5295
5039
|
position: {
|
|
5296
|
-
start:
|
|
5297
|
-
end:
|
|
5040
|
+
start: tokens.start(tokenStart),
|
|
5041
|
+
end: tokens.start(tokenStart + tokens.nodeLength(tokenStart))
|
|
5298
5042
|
}
|
|
5299
5043
|
};
|
|
5300
5044
|
};
|
|
5301
5045
|
const buildTableRow = (tokenStart, context) => {
|
|
5302
|
-
const
|
|
5303
|
-
const close =
|
|
5046
|
+
const tokens = context.structure.tokens;
|
|
5047
|
+
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
5048
|
+
const children = [];
|
|
5049
|
+
for (let cell = tokenStart + 1; cell < close; cell += tokens.nodeLength(cell)) children.push(buildTableCell(cell, context, buildInlineFragment(cell, context)));
|
|
5304
5050
|
return {
|
|
5305
5051
|
type: "tableRow",
|
|
5306
|
-
children
|
|
5052
|
+
children,
|
|
5307
5053
|
position: {
|
|
5308
|
-
start:
|
|
5309
|
-
end:
|
|
5054
|
+
start: tokens.start(tokenStart),
|
|
5055
|
+
end: tokens.start(close)
|
|
5310
5056
|
}
|
|
5311
5057
|
};
|
|
5312
5058
|
};
|
|
5313
5059
|
function tableAlignment(tokenStart, context) {
|
|
5314
|
-
const
|
|
5060
|
+
const tokens = context.structure.tokens;
|
|
5061
|
+
const tokenEnd = tokenStart + tokens.nodeLength(tokenStart);
|
|
5315
5062
|
const result = [];
|
|
5316
|
-
for (let
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
result.push(kind === 36 ? "left" : kind === 37 ? "right" : kind === 38 ? "center" : null);
|
|
5063
|
+
for (let token = tokenStart; token < tokenEnd; token++) {
|
|
5064
|
+
const kind = tokens.kind(token);
|
|
5065
|
+
result.push(kind === 35 ? "left" : kind === 36 ? "right" : kind === 37 ? "center" : null);
|
|
5320
5066
|
}
|
|
5321
5067
|
return result;
|
|
5322
5068
|
}
|
|
@@ -5347,16 +5093,16 @@ const feature = { block: {
|
|
|
5347
5093
|
}],
|
|
5348
5094
|
rules: [
|
|
5349
5095
|
{
|
|
5350
|
-
rule:
|
|
5096
|
+
rule: 3,
|
|
5351
5097
|
syntax: {
|
|
5352
5098
|
kind: "frame",
|
|
5353
5099
|
open: 33,
|
|
5354
|
-
close:
|
|
5100
|
+
close: 1
|
|
5355
5101
|
},
|
|
5356
5102
|
inlineContent: true
|
|
5357
5103
|
},
|
|
5358
5104
|
{
|
|
5359
|
-
rule:
|
|
5105
|
+
rule: 4,
|
|
5360
5106
|
syntax: {
|
|
5361
5107
|
kind: "frame",
|
|
5362
5108
|
open: 31,
|
|
@@ -5364,37 +5110,38 @@ const feature = { block: {
|
|
|
5364
5110
|
}
|
|
5365
5111
|
},
|
|
5366
5112
|
{
|
|
5367
|
-
rule:
|
|
5113
|
+
rule: 5,
|
|
5368
5114
|
syntax: {
|
|
5369
5115
|
kind: "group",
|
|
5370
5116
|
tokens: [
|
|
5117
|
+
34,
|
|
5371
5118
|
35,
|
|
5372
5119
|
36,
|
|
5373
|
-
37
|
|
5374
|
-
38
|
|
5120
|
+
37
|
|
5375
5121
|
]
|
|
5376
5122
|
}
|
|
5377
5123
|
},
|
|
5378
5124
|
{
|
|
5379
|
-
rule:
|
|
5125
|
+
rule: 6,
|
|
5380
5126
|
syntax: {
|
|
5381
5127
|
kind: "block",
|
|
5382
5128
|
open: 29,
|
|
5383
5129
|
close: 30
|
|
5384
5130
|
},
|
|
5385
5131
|
build(tokenStart, context) {
|
|
5386
|
-
const
|
|
5387
|
-
const close =
|
|
5388
|
-
const
|
|
5389
|
-
const delimiter =
|
|
5390
|
-
|
|
5132
|
+
const tokens = context.structure.tokens;
|
|
5133
|
+
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
5134
|
+
const header = tokenStart + 1;
|
|
5135
|
+
const delimiter = header + tokens.nodeLength(header);
|
|
5136
|
+
const rows = [buildTableRow(header, context)];
|
|
5137
|
+
for (let row = delimiter + tokens.nodeLength(delimiter); row < close; row += tokens.nodeLength(row)) rows.push(buildTableRow(row, context));
|
|
5391
5138
|
return {
|
|
5392
5139
|
type: "table",
|
|
5393
5140
|
align: tableAlignment(delimiter, context),
|
|
5394
5141
|
children: rows,
|
|
5395
5142
|
position: {
|
|
5396
|
-
start:
|
|
5397
|
-
end:
|
|
5143
|
+
start: tokens.start(tokenStart),
|
|
5144
|
+
end: tokens.start(close)
|
|
5398
5145
|
}
|
|
5399
5146
|
};
|
|
5400
5147
|
}
|
|
@@ -5408,18 +5155,18 @@ function compileProfile(options = {}) {
|
|
|
5408
5155
|
feature$7,
|
|
5409
5156
|
feature$14,
|
|
5410
5157
|
feature$15,
|
|
5411
|
-
feature$4,
|
|
5158
|
+
feature$4(options.taskList),
|
|
5412
5159
|
feature$12,
|
|
5413
5160
|
feature$6
|
|
5414
5161
|
];
|
|
5415
|
-
if (options.footnote) features.push(feature$
|
|
5416
|
-
if (options.frontmatter) features.unshift(feature$
|
|
5162
|
+
if (options.footnote) features.push(feature$9);
|
|
5163
|
+
if (options.frontmatter) features.unshift(feature$11(typeof options.frontmatter === "object" ? options.frontmatter.marker : "-"));
|
|
5417
5164
|
if (options.table) features.push(feature);
|
|
5418
5165
|
if (options.math) features.push(feature$3(options.math));
|
|
5419
|
-
features.push(feature$2, feature$13, feature$
|
|
5166
|
+
features.push(feature$2, feature$13, feature$8(options.strikethrough), feature$5);
|
|
5420
5167
|
if (options.attributes) features.push(feature$17);
|
|
5421
5168
|
if (options.binding) features.push(feature$16);
|
|
5422
|
-
if (options.component) features.push(feature$
|
|
5169
|
+
if (options.component) features.push(feature$10);
|
|
5423
5170
|
features.push(feature$1);
|
|
5424
5171
|
const blockFeatures = [];
|
|
5425
5172
|
const inlineFeatures = [];
|