satorigear 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -21
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1740 -1952
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1,251 +1,5 @@
|
|
|
1
1
|
import { decodeHTMLStrict } from "entities";
|
|
2
2
|
import { parse } from "yaml";
|
|
3
|
-
//#region src/block/arena.ts
|
|
4
|
-
function leaf(tokenIndex) {
|
|
5
|
-
return ~tokenIndex;
|
|
6
|
-
}
|
|
7
|
-
var BlockArena = class {
|
|
8
|
-
#buildStarts = [];
|
|
9
|
-
#buildTokenEnds = [];
|
|
10
|
-
#buildTokenStarts = [];
|
|
11
|
-
#edgeCounts = [0];
|
|
12
|
-
#edgeLength = 0;
|
|
13
|
-
#edges = [];
|
|
14
|
-
#edgeStarts = [0];
|
|
15
|
-
#freeEdges = [];
|
|
16
|
-
#freeIds = [];
|
|
17
|
-
#lengths = [0];
|
|
18
|
-
#nodeCount = 0;
|
|
19
|
-
#records = [];
|
|
20
|
-
#releaseStack = [];
|
|
21
|
-
#rules;
|
|
22
|
-
#schema;
|
|
23
|
-
#tokens;
|
|
24
|
-
constructor(schema, tokens) {
|
|
25
|
-
this.#rules = [];
|
|
26
|
-
this.#schema = schema;
|
|
27
|
-
this.#tokens = tokens;
|
|
28
|
-
}
|
|
29
|
-
build() {
|
|
30
|
-
this.#edgeLength = 0;
|
|
31
|
-
this.#freeEdges.length = 0;
|
|
32
|
-
this.#freeIds.length = 0;
|
|
33
|
-
this.#nodeCount = 0;
|
|
34
|
-
this.#records = this.#buildRange(0, this.#tokens.length);
|
|
35
|
-
}
|
|
36
|
-
get records() {
|
|
37
|
-
return this.#records;
|
|
38
|
-
}
|
|
39
|
-
get tokens() {
|
|
40
|
-
return this.#tokens;
|
|
41
|
-
}
|
|
42
|
-
update(change) {
|
|
43
|
-
const previous = this.#records;
|
|
44
|
-
let prefixEnd = 0;
|
|
45
|
-
while (prefixEnd < previous.length && previous[prefixEnd].tokenEnd <= change.oldStart) prefixEnd++;
|
|
46
|
-
let suffixStart = prefixEnd;
|
|
47
|
-
while (suffixStart < previous.length && previous[suffixStart].tokenStart < change.oldEnd) suffixStart++;
|
|
48
|
-
const tokenDelta = change.newEnd - change.oldStart - (change.oldEnd - change.oldStart);
|
|
49
|
-
const buildStart = previous[prefixEnd - 1]?.tokenEnd ?? 0;
|
|
50
|
-
const oldSuffixTokenStart = previous[suffixStart]?.tokenStart;
|
|
51
|
-
const buildEnd = oldSuffixTokenStart === void 0 ? this.#tokens.length : oldSuffixTokenStart + tokenDelta;
|
|
52
|
-
for (let index = prefixEnd; index < suffixStart; index++) this.#release(previous[index].id);
|
|
53
|
-
this.#coalesceFreeEdges();
|
|
54
|
-
const changed = this.#buildRange(buildStart, buildEnd);
|
|
55
|
-
const suffix = previous.slice(suffixStart);
|
|
56
|
-
if (tokenDelta !== 0) for (const block of suffix) {
|
|
57
|
-
block.tokenStart += tokenDelta;
|
|
58
|
-
block.tokenEnd += tokenDelta;
|
|
59
|
-
}
|
|
60
|
-
this.#records = [
|
|
61
|
-
...previous.slice(0, prefixEnd),
|
|
62
|
-
...changed,
|
|
63
|
-
...suffix
|
|
64
|
-
];
|
|
65
|
-
return {
|
|
66
|
-
newEnd: prefixEnd + changed.length,
|
|
67
|
-
oldEnd: suffixStart,
|
|
68
|
-
oldStart: prefixEnd
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
#allocate(rule, children) {
|
|
72
|
-
const id = this.#freeIds.pop() ?? this.#nodeCount++;
|
|
73
|
-
const first = children[0];
|
|
74
|
-
const last = children.at(-1);
|
|
75
|
-
const start = first === void 0 ? 0 : this.#entryStart(first);
|
|
76
|
-
const end = last === void 0 ? start : this.#entryEnd(last);
|
|
77
|
-
const tokenBase = first === void 0 ? 0 : this.#entryTokenStart(first);
|
|
78
|
-
const tokenLimit = last === void 0 ? tokenBase : this.#entryTokenEnd(last);
|
|
79
|
-
const edgeStart = this.#allocateEdges(children.length);
|
|
80
|
-
this.#edgeStarts[id] = edgeStart;
|
|
81
|
-
this.#edgeCounts[id] = children.length;
|
|
82
|
-
for (let index = 0; index < children.length; index++) {
|
|
83
|
-
const entry = children[index];
|
|
84
|
-
const edge = (edgeStart + index) * 3;
|
|
85
|
-
this.#edges[edge] = entry < 0 ? leaf(~entry - tokenBase) : entry;
|
|
86
|
-
this.#edges[edge + 1] = this.#entryStart(entry) - start;
|
|
87
|
-
this.#edges[edge + 2] = this.#entryTokenStart(entry) - tokenBase;
|
|
88
|
-
}
|
|
89
|
-
this.#lengths[id] = end - start;
|
|
90
|
-
this.#rules[id] = rule;
|
|
91
|
-
this.#buildStarts[id] = start;
|
|
92
|
-
this.#buildTokenStarts[id] = tokenBase;
|
|
93
|
-
this.#buildTokenEnds[id] = tokenLimit;
|
|
94
|
-
return id;
|
|
95
|
-
}
|
|
96
|
-
#allocateEdges(count) {
|
|
97
|
-
if (count === 0) return 0;
|
|
98
|
-
let selected = -1;
|
|
99
|
-
for (let index = 0; index < this.#freeEdges.length; index++) {
|
|
100
|
-
const candidate = this.#freeEdges[index];
|
|
101
|
-
if (candidate.count >= count && (selected < 0 || candidate.count < this.#freeEdges[selected].count)) selected = index;
|
|
102
|
-
}
|
|
103
|
-
if (selected < 0) {
|
|
104
|
-
const start = this.#edgeLength;
|
|
105
|
-
this.#edgeLength += count;
|
|
106
|
-
return start;
|
|
107
|
-
}
|
|
108
|
-
const range = this.#freeEdges[selected];
|
|
109
|
-
const start = range.start;
|
|
110
|
-
if (range.count === count) this.#freeEdges.splice(selected, 1);
|
|
111
|
-
else {
|
|
112
|
-
range.start += count;
|
|
113
|
-
range.count -= count;
|
|
114
|
-
}
|
|
115
|
-
return start;
|
|
116
|
-
}
|
|
117
|
-
#buildRange(start, end) {
|
|
118
|
-
const document = {
|
|
119
|
-
close: 0,
|
|
120
|
-
children: []
|
|
121
|
-
};
|
|
122
|
-
const stack = [document];
|
|
123
|
-
for (let index = start; index < end; index++) {
|
|
124
|
-
const kind = this.#tokens.kind(index);
|
|
125
|
-
const current = stack.at(-1);
|
|
126
|
-
const spec = this.#schema.frameByOpen[kind];
|
|
127
|
-
if (spec !== void 0) {
|
|
128
|
-
stack.push({
|
|
129
|
-
close: spec.close,
|
|
130
|
-
children: [leaf(index)],
|
|
131
|
-
rule: spec.rule
|
|
132
|
-
});
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
const groupedRule = this.#schema.groupedRuleByToken[kind];
|
|
136
|
-
if (groupedRule !== void 0) {
|
|
137
|
-
const children = [];
|
|
138
|
-
do
|
|
139
|
-
children.push(leaf(index++));
|
|
140
|
-
while (index < end && this.#schema.groupedRuleByToken[this.#tokens.kind(index)] === groupedRule);
|
|
141
|
-
index--;
|
|
142
|
-
current.children.push(this.#allocate(groupedRule, children));
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
if (current.close === kind) {
|
|
146
|
-
current.children.push(leaf(index));
|
|
147
|
-
stack.pop();
|
|
148
|
-
const id = this.#allocate(current.rule, current.children);
|
|
149
|
-
stack.at(-1).children.push(id);
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
const leafRule = this.#schema.ruleByLeaf[kind];
|
|
153
|
-
if (leafRule !== void 0) {
|
|
154
|
-
current.children.push(this.#allocate(leafRule, [leaf(index)]));
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
current.children.push(leaf(index));
|
|
158
|
-
}
|
|
159
|
-
if (stack.length !== 1) throw new Error(`Block token stream did not close ${stack.at(-1).rule?.name}`);
|
|
160
|
-
return document.children.map((id) => ({
|
|
161
|
-
id,
|
|
162
|
-
tokenStart: this.#buildTokenStarts[id],
|
|
163
|
-
tokenEnd: this.#buildTokenEnds[id]
|
|
164
|
-
}));
|
|
165
|
-
}
|
|
166
|
-
#entryEnd(entry) {
|
|
167
|
-
return entry < 0 ? this.#tokens.end(~entry) : this.#buildStarts[entry] + this.#lengths[entry];
|
|
168
|
-
}
|
|
169
|
-
#entryStart(entry) {
|
|
170
|
-
return entry < 0 ? this.#tokens.start(~entry) : this.#buildStarts[entry];
|
|
171
|
-
}
|
|
172
|
-
#entryTokenEnd(entry) {
|
|
173
|
-
return entry < 0 ? ~entry + 1 : this.#buildTokenEnds[entry];
|
|
174
|
-
}
|
|
175
|
-
#entryTokenStart(entry) {
|
|
176
|
-
return entry < 0 ? ~entry : this.#buildTokenStarts[entry];
|
|
177
|
-
}
|
|
178
|
-
#release(id) {
|
|
179
|
-
const stack = this.#releaseStack;
|
|
180
|
-
stack.length = 1;
|
|
181
|
-
stack[0] = id;
|
|
182
|
-
while (stack.length > 0) {
|
|
183
|
-
const released = stack.pop();
|
|
184
|
-
const edgeStart = this.#edgeStarts[released];
|
|
185
|
-
const edgeCount = this.#edgeCounts[released];
|
|
186
|
-
for (let index = 0; index < edgeCount; index++) {
|
|
187
|
-
const child = this.#edges[(edgeStart + index) * 3];
|
|
188
|
-
if (child >= 0) stack.push(child);
|
|
189
|
-
}
|
|
190
|
-
this.#releaseEdges(released);
|
|
191
|
-
this.#freeIds.push(released);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
#releaseEdges(id) {
|
|
195
|
-
const count = this.#edgeCounts[id];
|
|
196
|
-
if (count > 0) {
|
|
197
|
-
this.#freeEdges.push({
|
|
198
|
-
start: this.#edgeStarts[id],
|
|
199
|
-
count
|
|
200
|
-
});
|
|
201
|
-
this.#edgeCounts[id] = 0;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
#coalesceFreeEdges() {
|
|
205
|
-
const ranges = this.#freeEdges;
|
|
206
|
-
if (ranges.length < 2) return;
|
|
207
|
-
ranges.sort((left, right) => left.start - right.start);
|
|
208
|
-
let write = 0;
|
|
209
|
-
for (let read = 1; read < ranges.length; read++) {
|
|
210
|
-
const current = ranges[write];
|
|
211
|
-
const next = ranges[read];
|
|
212
|
-
if (current.start + current.count === next.start) current.count += next.count;
|
|
213
|
-
else ranges[++write] = next;
|
|
214
|
-
}
|
|
215
|
-
ranges.length = write + 1;
|
|
216
|
-
}
|
|
217
|
-
childAt(id, index) {
|
|
218
|
-
return this.#edges[(this.#edgeStarts[id] + index) * 3];
|
|
219
|
-
}
|
|
220
|
-
childCount(id) {
|
|
221
|
-
return this.#edgeCounts[id];
|
|
222
|
-
}
|
|
223
|
-
childRelAt(id, index) {
|
|
224
|
-
return this.#edges[(this.#edgeStarts[id] + index) * 3 + 1];
|
|
225
|
-
}
|
|
226
|
-
childTokRelAt(id, index) {
|
|
227
|
-
return this.#edges[(this.#edgeStarts[id] + index) * 3 + 2];
|
|
228
|
-
}
|
|
229
|
-
leafToken(entry, tokenBase) {
|
|
230
|
-
return tokenBase + ~entry;
|
|
231
|
-
}
|
|
232
|
-
leafTokenKind(entry, tokenBase) {
|
|
233
|
-
return this.#tokens.kind(this.leafToken(entry, tokenBase));
|
|
234
|
-
}
|
|
235
|
-
lenOf(id) {
|
|
236
|
-
return this.#lengths[id];
|
|
237
|
-
}
|
|
238
|
-
isBlock(id) {
|
|
239
|
-
return this.#rules[id].block;
|
|
240
|
-
}
|
|
241
|
-
ruleNameOf(id) {
|
|
242
|
-
return this.#rules[id].name;
|
|
243
|
-
}
|
|
244
|
-
ruleOf(id) {
|
|
245
|
-
return this.#rules[id];
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
//#endregion
|
|
249
3
|
//#region src/block/lines.ts
|
|
250
4
|
function firstLineIndexAtOrAfter(lines, offset) {
|
|
251
5
|
let low = 0;
|
|
@@ -257,6 +11,27 @@ function firstLineIndexAtOrAfter(lines, offset) {
|
|
|
257
11
|
}
|
|
258
12
|
return low;
|
|
259
13
|
}
|
|
14
|
+
function firstNonspace(source, start, end) {
|
|
15
|
+
while (start < end && (source[start] === " " || source[start] === " ")) start++;
|
|
16
|
+
return start;
|
|
17
|
+
}
|
|
18
|
+
function lineEnd(source, offset, limit = source.length) {
|
|
19
|
+
for (; offset < limit; offset++) {
|
|
20
|
+
const character = source.charCodeAt(offset);
|
|
21
|
+
if (character === 10 || character === 13) return offset;
|
|
22
|
+
}
|
|
23
|
+
return limit;
|
|
24
|
+
}
|
|
25
|
+
function lineContentEnd(source, start, end) {
|
|
26
|
+
if (end <= start) return end;
|
|
27
|
+
if (source.charCodeAt(end - 1) === 10) return end - (end > start + 1 && source.charCodeAt(end - 2) === 13 ? 2 : 1);
|
|
28
|
+
return source.charCodeAt(end - 1) === 13 ? end - 1 : end;
|
|
29
|
+
}
|
|
30
|
+
function lineIndent(source, line) {
|
|
31
|
+
const indent = indentOf(source, line, 3);
|
|
32
|
+
if (source[indent.offset] === " " || source[indent.offset] === " ") return;
|
|
33
|
+
return indent;
|
|
34
|
+
}
|
|
260
35
|
function indentOf(source, line, limit = Number.POSITIVE_INFINITY) {
|
|
261
36
|
let offset = line.start;
|
|
262
37
|
let columns = line.prefixColumns ?? 0;
|
|
@@ -315,11 +90,6 @@ function logicalLine(source, line) {
|
|
|
315
90
|
}
|
|
316
91
|
return result + source.slice(offset, line.next);
|
|
317
92
|
}
|
|
318
|
-
function lineIndent(source, line) {
|
|
319
|
-
const indent = indentOf(source, line, 3);
|
|
320
|
-
if (source[indent.offset] === " " || source[indent.offset] === " ") return;
|
|
321
|
-
return indent;
|
|
322
|
-
}
|
|
323
93
|
function contentAfterColumns(source, line, columns) {
|
|
324
94
|
let offset = line.start;
|
|
325
95
|
let consumed = line.prefixColumns ?? 0;
|
|
@@ -345,6 +115,9 @@ function contentAfterColumns(source, line, columns) {
|
|
|
345
115
|
prefixColumns: Math.max(0, consumed - columns)
|
|
346
116
|
};
|
|
347
117
|
}
|
|
118
|
+
function normalizeLines(value) {
|
|
119
|
+
return value.replace(/\r\n|\r/g, "\n");
|
|
120
|
+
}
|
|
348
121
|
function removeIndent(value, columns) {
|
|
349
122
|
let offset = 0;
|
|
350
123
|
let consumed = 0;
|
|
@@ -357,46 +130,104 @@ function removeIndent(value, columns) {
|
|
|
357
130
|
return " ".repeat(Math.max(0, consumed - columns)) + value.slice(offset);
|
|
358
131
|
}
|
|
359
132
|
//#endregion
|
|
133
|
+
//#region src/primitives.ts
|
|
134
|
+
const emptyArray = [];
|
|
135
|
+
const emptySet = /* @__PURE__ */ new Set();
|
|
136
|
+
function isArrayEqual(foo, bar) {
|
|
137
|
+
if (foo.length !== bar.length) return false;
|
|
138
|
+
for (let index = 0; index < foo.length; index++) if (foo[index] !== bar[index]) return false;
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
function isSetEqual(foo, bar) {
|
|
142
|
+
if (foo.size !== bar.size) return false;
|
|
143
|
+
for (const val of foo) if (!bar.has(val)) return false;
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
360
147
|
//#region src/block/tokens.ts
|
|
361
148
|
const blockTokenStride = 4;
|
|
362
149
|
var BlockTokenStream = class {
|
|
150
|
+
#fieldLength;
|
|
363
151
|
#fields;
|
|
364
152
|
#metadata;
|
|
365
153
|
#relativeStart;
|
|
366
154
|
#sourceLength;
|
|
367
155
|
constructor(sourceLength = 0) {
|
|
368
|
-
this.#
|
|
156
|
+
this.#fieldLength = 0;
|
|
157
|
+
this.#fields = /* @__PURE__ */ new Int32Array();
|
|
369
158
|
this.#relativeStart = Number.POSITIVE_INFINITY;
|
|
370
159
|
this.#sourceLength = sourceLength;
|
|
371
160
|
}
|
|
372
161
|
reset(sourceLength) {
|
|
373
|
-
this.#
|
|
162
|
+
this.#fieldLength = 0;
|
|
374
163
|
this.#metadata = void 0;
|
|
375
164
|
this.#relativeStart = Number.POSITIVE_INFINITY;
|
|
376
165
|
this.#sourceLength = sourceLength;
|
|
377
166
|
}
|
|
378
167
|
get length() {
|
|
379
|
-
return this.#
|
|
168
|
+
return this.#fieldLength / blockTokenStride;
|
|
380
169
|
}
|
|
381
170
|
push(kind, start, end, meta) {
|
|
382
|
-
|
|
171
|
+
const field = this.#fieldLength;
|
|
172
|
+
this.#ensureCapacity(field + blockTokenStride);
|
|
173
|
+
this.#fields[field] = kind;
|
|
174
|
+
this.#fields[field + 1] = start;
|
|
175
|
+
this.#fields[field + 2] = end;
|
|
176
|
+
this.#fields[field + 3] = 0;
|
|
177
|
+
this.#fieldLength += blockTokenStride;
|
|
383
178
|
if (meta) {
|
|
384
179
|
this.#metadata ??= /* @__PURE__ */ new Map();
|
|
385
180
|
this.#metadata.set(this.length - 1, meta);
|
|
386
181
|
}
|
|
387
182
|
}
|
|
183
|
+
indexStructure(schema) {
|
|
184
|
+
const fields = this.#fields;
|
|
185
|
+
const opens = [];
|
|
186
|
+
const closes = [];
|
|
187
|
+
for (let index = 0; index < this.length; index++) {
|
|
188
|
+
const kind = this.kind(index);
|
|
189
|
+
const frame = schema.frameByOpen[kind];
|
|
190
|
+
if (frame) {
|
|
191
|
+
opens.push(index);
|
|
192
|
+
closes.push(frame.close);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const groupedRule = schema.groupedRuleByToken[kind];
|
|
196
|
+
if (groupedRule) {
|
|
197
|
+
const start = index;
|
|
198
|
+
do
|
|
199
|
+
index++;
|
|
200
|
+
while (index < this.length && schema.groupedRuleByToken[this.kind(index)] === groupedRule);
|
|
201
|
+
fields[start * blockTokenStride + 3] = index - start;
|
|
202
|
+
index--;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (closes.at(-1) === kind) {
|
|
206
|
+
const open = opens.pop();
|
|
207
|
+
closes.pop();
|
|
208
|
+
fields[open * blockTokenStride + 3] = index - open + 1;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (schema.ruleByLeaf[kind]) fields[index * blockTokenStride + 3] = 1;
|
|
212
|
+
}
|
|
213
|
+
if (opens.length > 0) throw new Error(`Block token stream did not close token ${this.kind(opens.at(-1))}`);
|
|
214
|
+
}
|
|
215
|
+
nodeLength(index) {
|
|
216
|
+
return this.#fields[index * blockTokenStride + 3];
|
|
217
|
+
}
|
|
388
218
|
equalsAfterShift(index, source, next, nextIndex, nextSource, delta) {
|
|
389
|
-
|
|
219
|
+
const start = this.start(index);
|
|
220
|
+
const end = this.end(index);
|
|
221
|
+
const nextStart = next.start(nextIndex);
|
|
222
|
+
const nextEnd = next.end(nextIndex);
|
|
223
|
+
if (this.kind(index) !== next.kind(nextIndex) || start + delta !== nextStart || end + delta !== nextEnd) return false;
|
|
390
224
|
const ranges = this.#metadata?.get(index)?.rangeOffsets;
|
|
391
225
|
const nextRanges = next.#metadata?.get(nextIndex)?.rangeOffsets;
|
|
392
|
-
if ((ranges
|
|
393
|
-
if (ranges && nextRanges) {
|
|
394
|
-
for (let range = 0; range < ranges.length; range++) if (ranges[range] !== nextRanges[range]) return false;
|
|
395
|
-
}
|
|
226
|
+
if (ranges !== nextRanges && !isArrayEqual(ranges ?? emptyArray, nextRanges ?? emptyArray)) return false;
|
|
396
227
|
const text = this.#metadata?.get(index)?.text;
|
|
397
228
|
const nextText = next.#metadata?.get(nextIndex)?.text;
|
|
398
229
|
if (text !== void 0 || nextText !== void 0) return text === nextText;
|
|
399
|
-
return
|
|
230
|
+
return end - start === nextEnd - nextStart && source.slice(start, end) === nextSource.slice(nextStart, nextEnd);
|
|
400
231
|
}
|
|
401
232
|
rangeCount(index) {
|
|
402
233
|
return (this.#metadata?.get(index)?.rangeOffsets?.length ?? 2) / 2;
|
|
@@ -437,12 +268,24 @@ var BlockTokenStream = class {
|
|
|
437
268
|
}
|
|
438
269
|
}
|
|
439
270
|
if (end === previousLength) {
|
|
440
|
-
|
|
441
|
-
|
|
271
|
+
const fieldStart = start * blockTokenStride;
|
|
272
|
+
const fieldEnd = fieldStart + replacement.#fieldLength;
|
|
273
|
+
this.#ensureCapacity(fieldEnd);
|
|
274
|
+
this.#fields.set(replacement.#fields.subarray(0, replacement.#fieldLength), fieldStart);
|
|
275
|
+
this.#fieldLength = fieldEnd;
|
|
442
276
|
} else if (replacementLength === replacedLength) {
|
|
443
277
|
const fieldStart = start * blockTokenStride;
|
|
444
|
-
|
|
445
|
-
} else
|
|
278
|
+
this.#fields.set(replacement.#fields.subarray(0, replacement.#fieldLength), fieldStart);
|
|
279
|
+
} else {
|
|
280
|
+
const fieldStart = start * blockTokenStride;
|
|
281
|
+
const oldFieldEnd = end * blockTokenStride;
|
|
282
|
+
const newFieldEnd = fieldStart + replacement.#fieldLength;
|
|
283
|
+
const nextFieldLength = this.#fieldLength + newFieldEnd - oldFieldEnd;
|
|
284
|
+
this.#ensureCapacity(nextFieldLength);
|
|
285
|
+
this.#fields.copyWithin(newFieldEnd, oldFieldEnd, this.#fieldLength);
|
|
286
|
+
this.#fields.set(replacement.#fields.subarray(0, replacement.#fieldLength), fieldStart);
|
|
287
|
+
this.#fieldLength = nextFieldLength;
|
|
288
|
+
}
|
|
446
289
|
const indexDelta = replacementLength - replacedLength;
|
|
447
290
|
if (end === previousLength || indexDelta === 0) {
|
|
448
291
|
if (this.#metadata) {
|
|
@@ -466,7 +309,7 @@ var BlockTokenStream = class {
|
|
|
466
309
|
return change;
|
|
467
310
|
}
|
|
468
311
|
truncate(length) {
|
|
469
|
-
this.#
|
|
312
|
+
this.#fieldLength = length * blockTokenStride;
|
|
470
313
|
if (this.#metadata) {
|
|
471
314
|
for (const index of this.#metadata.keys()) if (index >= length) this.#metadata.delete(index);
|
|
472
315
|
if (this.#metadata.size === 0) this.#metadata = void 0;
|
|
@@ -487,6 +330,14 @@ var BlockTokenStream = class {
|
|
|
487
330
|
value(index) {
|
|
488
331
|
return this.#metadata?.get(index)?.value;
|
|
489
332
|
}
|
|
333
|
+
#ensureCapacity(length) {
|
|
334
|
+
if (length <= this.#fields.length) return;
|
|
335
|
+
let capacity = Math.max(64, this.#fields.length * 2);
|
|
336
|
+
while (capacity < length) capacity *= 2;
|
|
337
|
+
const fields = new Int32Array(capacity);
|
|
338
|
+
fields.set(this.#fields.subarray(0, this.#fieldLength));
|
|
339
|
+
this.#fields = fields;
|
|
340
|
+
}
|
|
490
341
|
#position(position) {
|
|
491
342
|
return position < 0 ? position + this.#sourceLength + 1 : position;
|
|
492
343
|
}
|
|
@@ -516,9 +367,6 @@ function appendLogicalToken(out, kind, source, lines, start, end, value) {
|
|
|
516
367
|
value
|
|
517
368
|
});
|
|
518
369
|
}
|
|
519
|
-
function equalSourceText(previousSource, previousStart, previousEnd, nextSource, nextStart, nextEnd) {
|
|
520
|
-
return previousEnd - previousStart === nextEnd - nextStart && previousSource.slice(previousStart, previousEnd) === nextSource.slice(nextStart, nextEnd);
|
|
521
|
-
}
|
|
522
370
|
//#endregion
|
|
523
371
|
//#region src/block/scanner.ts
|
|
524
372
|
function profileStarts(profile, context, source, lines, start, out) {
|
|
@@ -710,6 +558,7 @@ var BlockScanner = class {
|
|
|
710
558
|
});
|
|
711
559
|
return false;
|
|
712
560
|
});
|
|
561
|
+
tokens.indexStructure(this.#profile.schema);
|
|
713
562
|
checkpoints.length = checkpointIndex;
|
|
714
563
|
this.#source = source;
|
|
715
564
|
this.#lines = lines;
|
|
@@ -769,6 +618,7 @@ var BlockScanner = class {
|
|
|
769
618
|
});
|
|
770
619
|
return false;
|
|
771
620
|
});
|
|
621
|
+
replacement.indexStructure(this.#profile.schema);
|
|
772
622
|
const oldTokenEnd = converged < 0 ? this.#tokens.length : this.#checkpoints[converged].tokenStart;
|
|
773
623
|
const tokenDelta = replacement.length - (oldTokenEnd - oldTokenStart);
|
|
774
624
|
const tokenChange = this.#tokens.replace(previousSource, nextSource, oldTokenStart, oldTokenEnd, replacement);
|
|
@@ -794,74 +644,140 @@ var BlockScanner = class {
|
|
|
794
644
|
}
|
|
795
645
|
};
|
|
796
646
|
//#endregion
|
|
647
|
+
//#region src/block/structure.ts
|
|
648
|
+
const noBlockEntry = Number.MIN_SAFE_INTEGER;
|
|
649
|
+
var BlockStructure = class {
|
|
650
|
+
#records = [];
|
|
651
|
+
#schema;
|
|
652
|
+
#tokens;
|
|
653
|
+
constructor(schema, tokens) {
|
|
654
|
+
this.#schema = schema;
|
|
655
|
+
this.#tokens = tokens;
|
|
656
|
+
}
|
|
657
|
+
build() {
|
|
658
|
+
this.#records = this.#buildRange(0, this.#tokens.length);
|
|
659
|
+
}
|
|
660
|
+
get records() {
|
|
661
|
+
return this.#records;
|
|
662
|
+
}
|
|
663
|
+
get tokens() {
|
|
664
|
+
return this.#tokens;
|
|
665
|
+
}
|
|
666
|
+
update(change) {
|
|
667
|
+
const previous = this.#records;
|
|
668
|
+
let prefixEnd = 0;
|
|
669
|
+
while (prefixEnd < previous.length && previous[prefixEnd].tokenEnd <= change.oldStart) prefixEnd++;
|
|
670
|
+
let suffixStart = prefixEnd;
|
|
671
|
+
while (suffixStart < previous.length && previous[suffixStart].tokenStart < change.oldEnd) suffixStart++;
|
|
672
|
+
const tokenDelta = change.newEnd - change.oldStart - (change.oldEnd - change.oldStart);
|
|
673
|
+
const buildStart = previous[prefixEnd - 1]?.tokenEnd ?? 0;
|
|
674
|
+
const oldSuffixTokenStart = previous[suffixStart]?.tokenStart;
|
|
675
|
+
const buildEnd = oldSuffixTokenStart === void 0 ? this.#tokens.length : oldSuffixTokenStart + tokenDelta;
|
|
676
|
+
const changed = this.#buildRange(buildStart, buildEnd);
|
|
677
|
+
const suffix = previous.slice(suffixStart);
|
|
678
|
+
if (tokenDelta !== 0) for (const block of suffix) {
|
|
679
|
+
block.tokenStart += tokenDelta;
|
|
680
|
+
block.tokenEnd += tokenDelta;
|
|
681
|
+
}
|
|
682
|
+
this.#records = [
|
|
683
|
+
...previous.slice(0, prefixEnd),
|
|
684
|
+
...changed,
|
|
685
|
+
...suffix
|
|
686
|
+
];
|
|
687
|
+
return {
|
|
688
|
+
newEnd: prefixEnd + changed.length,
|
|
689
|
+
oldEnd: suffixStart,
|
|
690
|
+
oldStart: prefixEnd,
|
|
691
|
+
tokenDelta
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
#buildRange(start, end) {
|
|
695
|
+
const records = [];
|
|
696
|
+
while (start < end) {
|
|
697
|
+
const length = this.#tokens.nodeLength(start);
|
|
698
|
+
if (length === 0) throw new Error(`Block token ${start} does not begin a semantic node`);
|
|
699
|
+
records.push({
|
|
700
|
+
tokenStart: start,
|
|
701
|
+
tokenEnd: start + length
|
|
702
|
+
});
|
|
703
|
+
start += length;
|
|
704
|
+
}
|
|
705
|
+
return records;
|
|
706
|
+
}
|
|
707
|
+
firstChild(tokenStart) {
|
|
708
|
+
return ~tokenStart;
|
|
709
|
+
}
|
|
710
|
+
nextChild(tokenStart, entry) {
|
|
711
|
+
const next = entry < 0 ? ~entry + 1 : entry + this.#tokens.nodeLength(entry);
|
|
712
|
+
if (next >= tokenStart + this.#tokens.nodeLength(tokenStart)) return noBlockEntry;
|
|
713
|
+
return this.#tokens.nodeLength(next) > 0 ? next : ~next;
|
|
714
|
+
}
|
|
715
|
+
leafToken(entry) {
|
|
716
|
+
return ~entry;
|
|
717
|
+
}
|
|
718
|
+
lenOf(tokenStart) {
|
|
719
|
+
const end = tokenStart + this.#tokens.nodeLength(tokenStart);
|
|
720
|
+
return this.#tokens.end(end - 1) - this.#tokens.start(tokenStart);
|
|
721
|
+
}
|
|
722
|
+
isBlock(tokenStart) {
|
|
723
|
+
return this.ruleOf(tokenStart).block;
|
|
724
|
+
}
|
|
725
|
+
ruleNameOf(tokenStart) {
|
|
726
|
+
return this.ruleOf(tokenStart).name;
|
|
727
|
+
}
|
|
728
|
+
ruleOf(tokenStart) {
|
|
729
|
+
const kind = this.#tokens.kind(tokenStart);
|
|
730
|
+
const rule = this.#schema.frameByOpen[kind]?.rule ?? this.#schema.groupedRuleByToken[kind] ?? this.#schema.ruleByLeaf[kind];
|
|
731
|
+
if (!rule) throw new Error(`Block token ${tokenStart} does not begin a semantic node`);
|
|
732
|
+
return rule;
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
//#endregion
|
|
797
736
|
//#region src/fragment/block.ts
|
|
798
|
-
function blockEnd(
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
if (end > offset && context.source[end - 1] === "\r") end--;
|
|
802
|
-
return end;
|
|
737
|
+
function blockEnd(tokenStart, context) {
|
|
738
|
+
const offset = context.structure.tokens.start(tokenStart);
|
|
739
|
+
return lineContentEnd(context.source, offset, offset + context.structure.lenOf(tokenStart));
|
|
803
740
|
}
|
|
804
|
-
function
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
const arena = context.arena;
|
|
810
|
-
const childCount = arena.childCount(nodeId);
|
|
811
|
-
for (let index = 0; index < childCount; index++) {
|
|
812
|
-
const entry = arena.childAt(nodeId, index);
|
|
813
|
-
if (entry < 0) {
|
|
814
|
-
const token = arena.leafToken(entry, tokenBase);
|
|
815
|
-
if (arena.tokens.kind(token) === kind) return token;
|
|
816
|
-
}
|
|
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;
|
|
817
746
|
}
|
|
818
747
|
}
|
|
819
|
-
function blockToken(
|
|
820
|
-
const token = directBlockToken(
|
|
821
|
-
if (token === void 0) throw new Error(`Expected ${context.
|
|
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}`);
|
|
822
751
|
return token;
|
|
823
752
|
}
|
|
824
|
-
function payloadBounds(
|
|
825
|
-
const
|
|
753
|
+
function payloadBounds(tokenStart, context) {
|
|
754
|
+
const structure = context.structure;
|
|
755
|
+
const offset = structure.tokens.start(tokenStart);
|
|
826
756
|
const result = {
|
|
827
|
-
start: offset +
|
|
757
|
+
start: offset + structure.lenOf(tokenStart),
|
|
828
758
|
end: offset
|
|
829
759
|
};
|
|
830
|
-
const
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
const end = arena.tokens.end(token);
|
|
838
|
-
if (end > start) {
|
|
839
|
-
result.start = Math.min(result.start, start);
|
|
840
|
-
result.end = Math.max(result.end, end);
|
|
841
|
-
}
|
|
842
|
-
} else visit(child, currentTokenBase + arena.childTokRelAt(currentId, index));
|
|
760
|
+
const endToken = tokenStart + structure.tokens.nodeLength(tokenStart);
|
|
761
|
+
for (let token = tokenStart; token < endToken; token++) {
|
|
762
|
+
const start = structure.tokens.start(token);
|
|
763
|
+
const end = structure.tokens.end(token);
|
|
764
|
+
if (end > start) {
|
|
765
|
+
result.start = Math.min(result.start, start);
|
|
766
|
+
result.end = Math.max(result.end, end);
|
|
843
767
|
}
|
|
844
|
-
}
|
|
845
|
-
visit(nodeId, tokenBase);
|
|
768
|
+
}
|
|
846
769
|
return result;
|
|
847
770
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
}
|
|
851
|
-
const buildBlockNode = (nodeId, offset, tokenBase, context) => {
|
|
852
|
-
const rule = context.arena.ruleOf(nodeId);
|
|
771
|
+
const buildBlockNode = (tokenStart, context) => {
|
|
772
|
+
const rule = context.structure.ruleOf(tokenStart);
|
|
853
773
|
const build = rule.build;
|
|
854
774
|
if (!build) throw new Error(`Unexpected block syntax rule: ${rule.name}`);
|
|
855
|
-
return build(
|
|
775
|
+
return build(tokenStart, context);
|
|
856
776
|
};
|
|
857
|
-
const buildBlockChildren = (
|
|
858
|
-
const
|
|
777
|
+
const buildBlockChildren = (tokenStart, context) => {
|
|
778
|
+
const structure = context.structure;
|
|
859
779
|
const children = [];
|
|
860
|
-
|
|
861
|
-
for (let index = 0; index < childCount; index++) {
|
|
862
|
-
const childId = arena.childAt(nodeId, index);
|
|
863
|
-
if (childId >= 0 && arena.isBlock(childId)) children.push(buildBlockNode(childId, offset + arena.childRelAt(nodeId, index), tokenBase + arena.childTokRelAt(nodeId, index), context));
|
|
864
|
-
}
|
|
780
|
+
for (let childId = structure.firstChild(tokenStart); childId !== noBlockEntry; childId = structure.nextChild(tokenStart, childId)) if (childId >= 0 && structure.isBlock(childId)) children.push(buildBlockNode(childId, context));
|
|
865
781
|
return children;
|
|
866
782
|
};
|
|
867
783
|
//#endregion
|
|
@@ -915,15 +831,6 @@ function snapshot(fragments, sourceLength, locate) {
|
|
|
915
831
|
};
|
|
916
832
|
}
|
|
917
833
|
//#endregion
|
|
918
|
-
//#region src/primitives.ts
|
|
919
|
-
const emptyArray = [];
|
|
920
|
-
const emptySet = /* @__PURE__ */ new Set();
|
|
921
|
-
function isSetEqual(foo, bar) {
|
|
922
|
-
if (foo.size !== bar.size) return false;
|
|
923
|
-
for (const val of foo) if (!bar.has(val)) return false;
|
|
924
|
-
return true;
|
|
925
|
-
}
|
|
926
|
-
//#endregion
|
|
927
834
|
//#region src/inline/region.ts
|
|
928
835
|
function hasDefinition(key) {
|
|
929
836
|
(this.dependencies ??= /* @__PURE__ */ new Set()).add(key);
|
|
@@ -933,19 +840,19 @@ var InlineRegion = class {
|
|
|
933
840
|
#definitionDependencies;
|
|
934
841
|
#definitions;
|
|
935
842
|
#rawTokens;
|
|
936
|
-
#
|
|
843
|
+
#profile;
|
|
937
844
|
#tokenSource;
|
|
938
845
|
#tokens;
|
|
939
|
-
|
|
846
|
+
offset;
|
|
940
847
|
revision = 0;
|
|
941
848
|
rule;
|
|
942
|
-
|
|
849
|
+
tokenStart;
|
|
943
850
|
view;
|
|
944
|
-
constructor(
|
|
945
|
-
this.#
|
|
946
|
-
this.
|
|
851
|
+
constructor(profile, binding, definitions) {
|
|
852
|
+
this.#profile = profile;
|
|
853
|
+
this.offset = binding.offset;
|
|
947
854
|
this.rule = binding.rule;
|
|
948
|
-
this.
|
|
855
|
+
this.tokenStart = binding.tokenStart;
|
|
949
856
|
this.view = binding.view;
|
|
950
857
|
this.#updateTokens(binding.view.text, definitions);
|
|
951
858
|
}
|
|
@@ -962,20 +869,19 @@ var InlineRegion = class {
|
|
|
962
869
|
updateDefinitions(definitions) {
|
|
963
870
|
if (this.#updateTokens(this.view.text, definitions)) this.revision++;
|
|
964
871
|
}
|
|
965
|
-
shift(delta) {
|
|
966
|
-
this.
|
|
967
|
-
this.
|
|
872
|
+
shift(delta, tokenDelta) {
|
|
873
|
+
this.tokenStart += tokenDelta;
|
|
874
|
+
this.offset += delta;
|
|
968
875
|
this.view.shift(delta);
|
|
969
876
|
}
|
|
970
877
|
#dependenciesChanged(definitions) {
|
|
971
|
-
if (!this.#definitionDependencies || !this.#definitions) return true;
|
|
972
878
|
for (const candidate of this.#definitionDependencies) if (this.#definitions.has(candidate) !== definitions.has(candidate)) return true;
|
|
973
879
|
return false;
|
|
974
880
|
}
|
|
975
881
|
#rebind(binding) {
|
|
976
|
-
this.
|
|
882
|
+
this.offset = binding.offset;
|
|
977
883
|
this.rule = binding.rule;
|
|
978
|
-
this.
|
|
884
|
+
this.tokenStart = binding.tokenStart;
|
|
979
885
|
this.view = binding.view;
|
|
980
886
|
}
|
|
981
887
|
#updateTokens(source, definitions) {
|
|
@@ -985,11 +891,10 @@ var InlineRegion = class {
|
|
|
985
891
|
}
|
|
986
892
|
const context = {
|
|
987
893
|
definitions,
|
|
988
|
-
hasDefinition
|
|
989
|
-
tokenize: this.#syntax.tokenize
|
|
894
|
+
hasDefinition
|
|
990
895
|
};
|
|
991
|
-
const rawTokens = source === this.#tokenSource && this.#rawTokens ? this.#rawTokens : this.#
|
|
992
|
-
const tokens = this.#
|
|
896
|
+
const rawTokens = source === this.#tokenSource && this.#rawTokens ? this.#rawTokens : this.#profile.tokenize(source);
|
|
897
|
+
const tokens = this.#profile.resolve(source, rawTokens, context);
|
|
993
898
|
this.#tokenSource = source;
|
|
994
899
|
this.#definitionDependencies = context.dependencies ?? emptySet;
|
|
995
900
|
this.#definitions = definitions;
|
|
@@ -1004,9 +909,9 @@ var InlineRegionCursor = class {
|
|
|
1004
909
|
constructor(regions) {
|
|
1005
910
|
this.#regions = regions;
|
|
1006
911
|
}
|
|
1007
|
-
take(
|
|
912
|
+
take(tokenStart) {
|
|
1008
913
|
const region = this.#regions[this.#index];
|
|
1009
|
-
if (region?.
|
|
914
|
+
if (region?.tokenStart !== tokenStart) return;
|
|
1010
915
|
this.#index++;
|
|
1011
916
|
return region;
|
|
1012
917
|
}
|
|
@@ -1112,21 +1017,22 @@ var SyntaxState = class {
|
|
|
1112
1017
|
#definitionEntries;
|
|
1113
1018
|
#definitions = emptySet;
|
|
1114
1019
|
#profile;
|
|
1115
|
-
#
|
|
1116
|
-
|
|
1020
|
+
#sourceLength = 0;
|
|
1021
|
+
#structure;
|
|
1022
|
+
constructor(source, profile, structure) {
|
|
1117
1023
|
this.#profile = profile;
|
|
1118
|
-
this.#
|
|
1024
|
+
this.#structure = structure;
|
|
1119
1025
|
this.update(source);
|
|
1120
1026
|
}
|
|
1121
1027
|
blocks() {
|
|
1122
1028
|
return this.#blocks;
|
|
1123
1029
|
}
|
|
1124
1030
|
update(source, change, stableBlockCount = 0) {
|
|
1125
|
-
const
|
|
1031
|
+
const structure = this.#structure;
|
|
1126
1032
|
const previousBlocks = this.#blocks;
|
|
1127
1033
|
const oldStart = change?.oldStart ?? 0;
|
|
1128
1034
|
const oldEnd = change?.oldEnd ?? 0;
|
|
1129
|
-
const newEnd = change?.newEnd ??
|
|
1035
|
+
const newEnd = change?.newEnd ?? structure.records.length;
|
|
1130
1036
|
const blocks = stableBlockCount === 0 ? [] : previousBlocks.slice(0, stableBlockCount);
|
|
1131
1037
|
const previousDefinitionEntries = this.#definitionEntries;
|
|
1132
1038
|
const definitions = /* @__PURE__ */ new Set();
|
|
@@ -1138,11 +1044,11 @@ var SyntaxState = class {
|
|
|
1138
1044
|
definitions.add(entry.key);
|
|
1139
1045
|
}
|
|
1140
1046
|
const bindings = [];
|
|
1141
|
-
const collectNode = (
|
|
1142
|
-
const rule =
|
|
1047
|
+
const collectNode = (tokenStart, offset, tokenBase, blockIndex) => {
|
|
1048
|
+
const rule = structure.ruleOf(tokenStart);
|
|
1143
1049
|
const definitionKey = rule.definitionKey;
|
|
1144
1050
|
if (definitionKey) {
|
|
1145
|
-
const key = definitionKey(
|
|
1051
|
+
const key = definitionKey(structure.tokens, tokenBase);
|
|
1146
1052
|
(definitionEntries ??= []).push({
|
|
1147
1053
|
blockIndex,
|
|
1148
1054
|
key
|
|
@@ -1150,36 +1056,27 @@ var SyntaxState = class {
|
|
|
1150
1056
|
definitions.add(key);
|
|
1151
1057
|
}
|
|
1152
1058
|
if (rule.inlineContent) {
|
|
1153
|
-
const inlineView = inlineViewOf(source,
|
|
1059
|
+
const inlineView = inlineViewOf(source, structure, tokenStart);
|
|
1154
1060
|
if (inlineView) bindings.push({
|
|
1155
|
-
|
|
1061
|
+
offset,
|
|
1156
1062
|
rule: rule.name,
|
|
1157
|
-
|
|
1158
|
-
start: offset,
|
|
1159
|
-
end: offset + arena.lenOf(nodeId)
|
|
1160
|
-
},
|
|
1063
|
+
tokenStart,
|
|
1161
1064
|
view: inlineView
|
|
1162
1065
|
});
|
|
1163
1066
|
return;
|
|
1164
1067
|
}
|
|
1165
|
-
|
|
1166
|
-
for (let index = 0; index < childCount; index++) {
|
|
1167
|
-
const child = arena.childAt(nodeId, index);
|
|
1168
|
-
if (child >= 0) collectNode(child, offset + arena.childRelAt(nodeId, index), tokenBase + arena.childTokRelAt(nodeId, index), blockIndex);
|
|
1169
|
-
}
|
|
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);
|
|
1170
1069
|
};
|
|
1171
1070
|
const bindingOffsets = [];
|
|
1172
1071
|
for (let index = stableBlockCount; index < newEnd; index++) {
|
|
1173
|
-
const record =
|
|
1072
|
+
const record = structure.records[index];
|
|
1174
1073
|
const tokenBase = record.tokenStart;
|
|
1175
|
-
const offset =
|
|
1074
|
+
const offset = structure.tokens.start(tokenBase);
|
|
1176
1075
|
bindingOffsets.push(bindings.length);
|
|
1177
|
-
collectNode(record.
|
|
1076
|
+
collectNode(record.tokenStart, offset, tokenBase, index);
|
|
1178
1077
|
blocks.push({
|
|
1179
|
-
offset,
|
|
1180
1078
|
record,
|
|
1181
1079
|
regions: emptyArray,
|
|
1182
|
-
tokenBase,
|
|
1183
1080
|
version: 0
|
|
1184
1081
|
});
|
|
1185
1082
|
}
|
|
@@ -1197,15 +1094,11 @@ var SyntaxState = class {
|
|
|
1197
1094
|
definitions.add(entry.key);
|
|
1198
1095
|
}
|
|
1199
1096
|
}
|
|
1200
|
-
const
|
|
1201
|
-
const
|
|
1202
|
-
const suffixOffsetDelta = firstSuffixBlock && firstSuffixRecord ? arena.tokens.start(firstSuffixRecord.tokenStart) - firstSuffixBlock.offset : 0;
|
|
1203
|
-
const suffixTokenDelta = firstSuffixBlock && firstSuffixRecord ? firstSuffixRecord.tokenStart - firstSuffixBlock.tokenBase : 0;
|
|
1097
|
+
const suffixOffsetDelta = source.length - this.#sourceLength;
|
|
1098
|
+
const suffixTokenDelta = change?.tokenDelta ?? 0;
|
|
1204
1099
|
for (let index = oldEnd; index < previousBlocks.length; index++) {
|
|
1205
1100
|
const block = previousBlocks[index];
|
|
1206
|
-
if (suffixOffsetDelta !== 0) for (const region of block.regions) region.shift(suffixOffsetDelta);
|
|
1207
|
-
block.offset += suffixOffsetDelta;
|
|
1208
|
-
block.tokenBase += suffixTokenDelta;
|
|
1101
|
+
if (suffixOffsetDelta !== 0 || suffixTokenDelta !== 0) for (const region of block.regions) region.shift(suffixOffsetDelta, suffixTokenDelta);
|
|
1209
1102
|
blocks.push(block);
|
|
1210
1103
|
}
|
|
1211
1104
|
const displacedRegions = [];
|
|
@@ -1226,12 +1119,12 @@ var SyntaxState = class {
|
|
|
1226
1119
|
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
1227
1120
|
for (let index = 0; index < displacedRegions.length; index++) {
|
|
1228
1121
|
const value = displacedRegions[index];
|
|
1229
|
-
if (value.
|
|
1122
|
+
if (value.tokenStart === binding.tokenStart) {
|
|
1230
1123
|
candidateIndex = index;
|
|
1231
1124
|
break;
|
|
1232
1125
|
}
|
|
1233
1126
|
if (value.rule === binding.rule) {
|
|
1234
|
-
const distance = Math.abs(value.
|
|
1127
|
+
const distance = Math.abs(value.offset - binding.offset);
|
|
1235
1128
|
if (distance < nearestDistance) {
|
|
1236
1129
|
nearestDistance = distance;
|
|
1237
1130
|
candidateIndex = index;
|
|
@@ -1264,66 +1157,56 @@ var SyntaxState = class {
|
|
|
1264
1157
|
this.#blocks = blocks;
|
|
1265
1158
|
this.#definitionEntries = definitionEntries;
|
|
1266
1159
|
this.#definitions = definitions;
|
|
1160
|
+
this.#sourceLength = source.length;
|
|
1267
1161
|
}
|
|
1268
1162
|
};
|
|
1269
|
-
function
|
|
1163
|
+
function resolveInlineRegions(source, profile, structure) {
|
|
1270
1164
|
const definitions = /* @__PURE__ */ new Set();
|
|
1271
1165
|
const regions = [];
|
|
1272
|
-
const collect = (
|
|
1273
|
-
const rule =
|
|
1274
|
-
if (rule.definitionKey) definitions.add(rule.definitionKey(
|
|
1166
|
+
const collect = (tokenStart, tokenBase) => {
|
|
1167
|
+
const rule = structure.ruleOf(tokenStart);
|
|
1168
|
+
if (rule.definitionKey) definitions.add(rule.definitionKey(structure.tokens, tokenBase));
|
|
1275
1169
|
if (rule.inlineContent) {
|
|
1276
|
-
const inlineView = inlineViewOf(source,
|
|
1170
|
+
const inlineView = inlineViewOf(source, structure, tokenStart);
|
|
1277
1171
|
if (inlineView) regions.push({
|
|
1278
|
-
id: nodeId,
|
|
1279
1172
|
rule: rule.name,
|
|
1173
|
+
tokenStart,
|
|
1280
1174
|
tokens: emptyArray,
|
|
1281
1175
|
view: inlineView
|
|
1282
1176
|
});
|
|
1283
1177
|
return;
|
|
1284
1178
|
}
|
|
1285
|
-
|
|
1286
|
-
for (let index = 0; index < childCount; index++) {
|
|
1287
|
-
const child = arena.childAt(nodeId, index);
|
|
1288
|
-
if (child >= 0) collect(child, tokenBase + arena.childTokRelAt(nodeId, index));
|
|
1289
|
-
}
|
|
1290
|
-
};
|
|
1291
|
-
for (const record of arena.records) collect(record.id, record.tokenStart);
|
|
1292
|
-
const context = {
|
|
1293
|
-
hasDefinition: (key) => definitions.has(key),
|
|
1294
|
-
tokenize: profile.tokenize
|
|
1179
|
+
for (let child = structure.firstChild(tokenStart); child !== noBlockEntry; child = structure.nextChild(tokenStart, child)) if (child >= 0) collect(child, child);
|
|
1295
1180
|
};
|
|
1181
|
+
for (const record of structure.records) collect(record.tokenStart, record.tokenStart);
|
|
1182
|
+
const context = { hasDefinition: (key) => definitions.has(key) };
|
|
1296
1183
|
for (const region of regions) {
|
|
1297
1184
|
const text = region.view.text;
|
|
1298
1185
|
region.tokens = profile.resolve(text, profile.tokenize(text), context);
|
|
1299
1186
|
}
|
|
1300
1187
|
return regions;
|
|
1301
1188
|
}
|
|
1302
|
-
function inlineViewOf(source,
|
|
1189
|
+
function inlineViewOf(source, structure, tokenStart) {
|
|
1303
1190
|
let firstStart = -1;
|
|
1304
1191
|
let firstEnd = -1;
|
|
1305
1192
|
let spans;
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
const
|
|
1311
|
-
if (
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
start,
|
|
1324
|
-
end
|
|
1325
|
-
});
|
|
1326
|
-
}
|
|
1193
|
+
for (let entry = structure.firstChild(tokenStart); entry !== noBlockEntry; entry = structure.nextChild(tokenStart, entry)) if (entry < 0) {
|
|
1194
|
+
const token = structure.leafToken(entry);
|
|
1195
|
+
if (structure.tokens.kind(token) === 1) {
|
|
1196
|
+
const start = structure.tokens.start(token);
|
|
1197
|
+
const end = structure.tokens.end(token);
|
|
1198
|
+
if (firstStart < 0) {
|
|
1199
|
+
firstStart = start;
|
|
1200
|
+
firstEnd = end;
|
|
1201
|
+
} else {
|
|
1202
|
+
spans ??= [{
|
|
1203
|
+
start: firstStart,
|
|
1204
|
+
end: firstEnd
|
|
1205
|
+
}];
|
|
1206
|
+
spans.push({
|
|
1207
|
+
start,
|
|
1208
|
+
end
|
|
1209
|
+
});
|
|
1327
1210
|
}
|
|
1328
1211
|
}
|
|
1329
1212
|
}
|
|
@@ -1356,7 +1239,7 @@ function applyEdits(source, edits) {
|
|
|
1356
1239
|
};
|
|
1357
1240
|
}
|
|
1358
1241
|
var DocumentImpl = class {
|
|
1359
|
-
#
|
|
1242
|
+
#blockStructure;
|
|
1360
1243
|
#blockScanner;
|
|
1361
1244
|
#fragments = [];
|
|
1362
1245
|
#previousFragments;
|
|
@@ -1365,10 +1248,10 @@ var DocumentImpl = class {
|
|
|
1365
1248
|
constructor(source, profile) {
|
|
1366
1249
|
this.#profile = profile;
|
|
1367
1250
|
this.#blockScanner = new BlockScanner(profile.block);
|
|
1368
|
-
this.#
|
|
1251
|
+
this.#blockStructure = new BlockStructure(profile.block.schema, this.#blockScanner.tokens);
|
|
1369
1252
|
this.#blockScanner.scan(source);
|
|
1370
|
-
this.#
|
|
1371
|
-
this.#syntaxState = new SyntaxState(source, profile.inline, this.#
|
|
1253
|
+
this.#blockStructure.build();
|
|
1254
|
+
this.#syntaxState = new SyntaxState(source, profile.inline, this.#blockStructure);
|
|
1372
1255
|
}
|
|
1373
1256
|
get source() {
|
|
1374
1257
|
return this.#blockScanner.source;
|
|
@@ -1386,8 +1269,8 @@ var DocumentImpl = class {
|
|
|
1386
1269
|
this.#previousFragments = fragments;
|
|
1387
1270
|
}
|
|
1388
1271
|
const { stableBlockCount, tokenChange } = this.#blockScanner.edit(applied.source, applied.changedSpan, applied.oldChangedEnd);
|
|
1389
|
-
const
|
|
1390
|
-
this.#syntaxState.update(this.source,
|
|
1272
|
+
const structureChange = this.#blockStructure.update(tokenChange);
|
|
1273
|
+
this.#syntaxState.update(this.source, structureChange, stableBlockCount);
|
|
1391
1274
|
return { changedSpan: applied.changedSpan };
|
|
1392
1275
|
}
|
|
1393
1276
|
snapshot() {
|
|
@@ -1401,36 +1284,37 @@ var DocumentImpl = class {
|
|
|
1401
1284
|
const regions = [];
|
|
1402
1285
|
for (const block of changedBlocks) for (const region of block.regions) regions.push(region);
|
|
1403
1286
|
const context = {
|
|
1404
|
-
|
|
1287
|
+
structure: this.#blockStructure,
|
|
1405
1288
|
inline: new InlineRegionCursor(regions),
|
|
1406
1289
|
profile: this.#profile.inline,
|
|
1407
1290
|
source: this.source
|
|
1408
1291
|
};
|
|
1409
1292
|
const nextFragments = blocks.map((block) => {
|
|
1293
|
+
const offset = this.#blockStructure.tokens.start(block.record.tokenStart);
|
|
1410
1294
|
const previous = previousFragments?.get(block.record);
|
|
1411
1295
|
const fragment = previous?.version === block.version ? previous : {
|
|
1412
|
-
node: buildBlockNode(block.record.
|
|
1413
|
-
offset
|
|
1414
|
-
origin:
|
|
1296
|
+
node: buildBlockNode(block.record.tokenStart, context),
|
|
1297
|
+
offset,
|
|
1298
|
+
origin: offset,
|
|
1415
1299
|
version: block.version
|
|
1416
1300
|
};
|
|
1417
|
-
fragment.offset =
|
|
1301
|
+
fragment.offset = offset;
|
|
1418
1302
|
return fragment;
|
|
1419
1303
|
});
|
|
1420
1304
|
this.#previousFragments = void 0;
|
|
1421
1305
|
this.#fragments = nextFragments;
|
|
1422
1306
|
return nextFragments;
|
|
1423
1307
|
}
|
|
1424
|
-
static parse(source, profile, blockScanner,
|
|
1308
|
+
static parse(source, profile, blockScanner, blockStructure) {
|
|
1425
1309
|
blockScanner.scan(source);
|
|
1426
|
-
|
|
1310
|
+
blockStructure.build();
|
|
1427
1311
|
const context = {
|
|
1428
|
-
|
|
1429
|
-
inline: new InlineRegionCursor(
|
|
1312
|
+
structure: blockStructure,
|
|
1313
|
+
inline: new InlineRegionCursor(resolveInlineRegions(source, profile.inline, blockStructure)),
|
|
1430
1314
|
profile: profile.inline,
|
|
1431
1315
|
source
|
|
1432
1316
|
};
|
|
1433
|
-
return materialize(
|
|
1317
|
+
return materialize(blockStructure.records.map((block) => buildBlockNode(block.tokenStart, context)), source.length, blockScanner.locator());
|
|
1434
1318
|
}
|
|
1435
1319
|
};
|
|
1436
1320
|
//#endregion
|
|
@@ -1503,202 +1387,32 @@ function compileBlockProfile(features) {
|
|
|
1503
1387
|
starts
|
|
1504
1388
|
};
|
|
1505
1389
|
}
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1390
|
+
//#endregion
|
|
1391
|
+
//#region src/inline/lexer.ts
|
|
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;
|
|
1511
1396
|
}
|
|
1512
|
-
function
|
|
1513
|
-
|
|
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;
|
|
1514
1402
|
}
|
|
1515
|
-
function
|
|
1516
|
-
|
|
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;
|
|
1517
1413
|
}
|
|
1518
|
-
function
|
|
1519
|
-
return tokens[index * 4 + 3];
|
|
1520
|
-
}
|
|
1521
|
-
function setInlineTokenFlags(tokens, index, flags) {
|
|
1522
|
-
tokens[index * 4 + 3] = flags;
|
|
1523
|
-
}
|
|
1524
|
-
function inlineTokenText(source, tokens, index) {
|
|
1525
|
-
return source.slice(inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index));
|
|
1526
|
-
}
|
|
1527
|
-
function appendInlineToken(target, kind, start, end, flags = 0) {
|
|
1528
|
-
target.push(kind, start, end, flags);
|
|
1529
|
-
}
|
|
1530
|
-
function copyInlineToken(target, tokens, index) {
|
|
1531
|
-
const offset = index * 4;
|
|
1532
|
-
for (let field = 0; field < 4; field++) target.push(tokens[offset + field]);
|
|
1533
|
-
}
|
|
1534
|
-
function firstInlineTokenEndingAfter(tokens, offset) {
|
|
1535
|
-
let low = 0;
|
|
1536
|
-
let high = inlineTokenCount(tokens);
|
|
1537
|
-
while (low < high) {
|
|
1538
|
-
const middle = low + high >>> 1;
|
|
1539
|
-
if (inlineTokenEnd(tokens, middle) <= offset) low = middle + 1;
|
|
1540
|
-
else high = middle;
|
|
1541
|
-
}
|
|
1542
|
-
return low;
|
|
1543
|
-
}
|
|
1544
|
-
//#endregion
|
|
1545
|
-
//#region src/inline/lexer.ts
|
|
1546
|
-
const htmlComment = /<!-->|<!--->|<!--[\s\S]*?(?:-->|$)/y;
|
|
1547
|
-
const autolink = /<(?:[A-Z][A-Z0-9+.\-]{1,31}:[^ \t\n\r<>]+|[\w!#$%&'*+\-/=?^`{|}~.]+@[A-Z0-9](?:[A-Z0-9]|-(?=[A-Z0-9]))*(?:\.[A-Z0-9](?:[A-Z0-9]|-(?=[A-Z0-9]))*)+)>/iy;
|
|
1548
|
-
const inlineHtml = /<[A-Za-z][A-Za-z0-9-]*(?:[ \t\n\r]+[A-Za-z_:][\w.:-]*(?:[ \t\n\r]*=[ \t\n\r]*(?:[^ \t\n\r"'=<>`]+|'[^']*'|"[^"]*"))?)*[ \t\n\r]*\/?>|<\/[A-Za-z][A-Za-z0-9-]*[ \t\n\r]*>|<\?[\s\S]*?\?>|<![A-Z][\s\S]*?>|<!\[CDATA\[[\s\S]*?\]\]>/y;
|
|
1549
|
-
const entity = /&(?:#x[0-9A-F]{1,6}|#\d{1,7}|[A-Z][A-Z0-9]{0,30});/iy;
|
|
1550
|
-
function matchEnd(pattern, source, start) {
|
|
1551
|
-
pattern.lastIndex = start;
|
|
1552
|
-
const match = pattern.exec(source);
|
|
1553
|
-
return match === null ? -1 : start + match[0].length;
|
|
1554
|
-
}
|
|
1555
|
-
function needsTextDecode(source, start, end) {
|
|
1556
|
-
for (let index = start; index < end; index++) {
|
|
1557
|
-
const code = source.charCodeAt(index);
|
|
1558
|
-
if (code === 38 || code === 92) return true;
|
|
1559
|
-
}
|
|
1560
|
-
return false;
|
|
1561
|
-
}
|
|
1562
|
-
function runEnd(source, start, marker) {
|
|
1563
|
-
let end = start + 1;
|
|
1564
|
-
while (source.charCodeAt(end) === marker) end++;
|
|
1565
|
-
return end;
|
|
1566
|
-
}
|
|
1567
|
-
function codeSpanEnd(source, start) {
|
|
1568
|
-
if (source.charCodeAt(start - 1) === 96) return -1;
|
|
1569
|
-
const openEnd = runEnd(source, start, 96);
|
|
1570
|
-
const markerLength = openEnd - start;
|
|
1571
|
-
let offset = openEnd;
|
|
1572
|
-
while (offset < source.length) {
|
|
1573
|
-
if (source.charCodeAt(offset) !== 96) {
|
|
1574
|
-
offset++;
|
|
1575
|
-
continue;
|
|
1576
|
-
}
|
|
1577
|
-
const closeEnd = runEnd(source, offset, 96);
|
|
1578
|
-
if (closeEnd - offset === markerLength) return closeEnd;
|
|
1579
|
-
offset = closeEnd;
|
|
1580
|
-
}
|
|
1581
|
-
return -1;
|
|
1582
|
-
}
|
|
1583
|
-
function skipWhitespace(source, start) {
|
|
1584
|
-
let end = start;
|
|
1585
|
-
while (end < source.length) {
|
|
1586
|
-
const code = source.charCodeAt(end);
|
|
1587
|
-
if (code !== 9 && code !== 10 && code !== 13 && code !== 32) break;
|
|
1588
|
-
end++;
|
|
1589
|
-
}
|
|
1590
|
-
return end;
|
|
1591
|
-
}
|
|
1592
|
-
function linkDestinationEnd(source, start) {
|
|
1593
|
-
if (source.charCodeAt(start) === 60) {
|
|
1594
|
-
let end = start + 1;
|
|
1595
|
-
while (end < source.length) {
|
|
1596
|
-
const code = source.charCodeAt(end);
|
|
1597
|
-
if (code === 62) return end + 1;
|
|
1598
|
-
if (code === 10 || code === 13 || code === 60) return -1;
|
|
1599
|
-
end += code === 92 && end + 1 < source.length ? 2 : 1;
|
|
1600
|
-
}
|
|
1601
|
-
return -1;
|
|
1602
|
-
}
|
|
1603
|
-
let depth = 0;
|
|
1604
|
-
let end = start;
|
|
1605
|
-
let consumed = false;
|
|
1606
|
-
while (end < source.length) {
|
|
1607
|
-
const code = source.charCodeAt(end);
|
|
1608
|
-
if (code === 92) {
|
|
1609
|
-
if (end + 1 >= source.length) break;
|
|
1610
|
-
consumed = true;
|
|
1611
|
-
end += 2;
|
|
1612
|
-
continue;
|
|
1613
|
-
}
|
|
1614
|
-
if (code === 40) {
|
|
1615
|
-
if (depth === 32) return -1;
|
|
1616
|
-
depth++;
|
|
1617
|
-
consumed = true;
|
|
1618
|
-
end++;
|
|
1619
|
-
continue;
|
|
1620
|
-
}
|
|
1621
|
-
if (code === 41) {
|
|
1622
|
-
if (depth === 0) break;
|
|
1623
|
-
depth--;
|
|
1624
|
-
consumed = true;
|
|
1625
|
-
end++;
|
|
1626
|
-
continue;
|
|
1627
|
-
}
|
|
1628
|
-
if (code === 9 || code === 10 || code === 13 || code === 32) break;
|
|
1629
|
-
consumed = true;
|
|
1630
|
-
end++;
|
|
1631
|
-
}
|
|
1632
|
-
return consumed && depth === 0 ? end : -1;
|
|
1633
|
-
}
|
|
1634
|
-
function linkTitleEnd(source, start) {
|
|
1635
|
-
const marker = source.charCodeAt(start);
|
|
1636
|
-
const close = marker === 40 ? 41 : marker;
|
|
1637
|
-
if (marker !== 34 && marker !== 39 && marker !== 40) return -1;
|
|
1638
|
-
let end = start + 1;
|
|
1639
|
-
while (end < source.length) {
|
|
1640
|
-
const code = source.charCodeAt(end);
|
|
1641
|
-
if (code === close) return end + 1;
|
|
1642
|
-
if (code === 10 || code === 13) return -1;
|
|
1643
|
-
end += code === 92 && end + 1 < source.length ? 2 : 1;
|
|
1644
|
-
}
|
|
1645
|
-
return -1;
|
|
1646
|
-
}
|
|
1647
|
-
function linkTailEnd(source, start) {
|
|
1648
|
-
if (source.charCodeAt(start + 1) !== 40) return -1;
|
|
1649
|
-
let offset = skipWhitespace(source, start + 2);
|
|
1650
|
-
if (source.charCodeAt(offset) === 41) return offset + 1;
|
|
1651
|
-
const destinationEnd = linkDestinationEnd(source, offset);
|
|
1652
|
-
if (destinationEnd < 0) return -1;
|
|
1653
|
-
offset = destinationEnd;
|
|
1654
|
-
const whitespaceEnd = skipWhitespace(source, offset);
|
|
1655
|
-
if (whitespaceEnd > offset && source.charCodeAt(whitespaceEnd) !== 41) {
|
|
1656
|
-
const titleEnd = linkTitleEnd(source, whitespaceEnd);
|
|
1657
|
-
if (titleEnd < 0) return -1;
|
|
1658
|
-
offset = titleEnd;
|
|
1659
|
-
} else offset = whitespaceEnd;
|
|
1660
|
-
offset = skipWhitespace(source, offset);
|
|
1661
|
-
return source.charCodeAt(offset) === 41 ? offset + 1 : -1;
|
|
1662
|
-
}
|
|
1663
|
-
function referenceTailEnd(source, start) {
|
|
1664
|
-
if (source.charCodeAt(start + 1) !== 91) return -1;
|
|
1665
|
-
let offset = start + 2;
|
|
1666
|
-
if (source.charCodeAt(offset) === 93) return offset + 1;
|
|
1667
|
-
let characters = 0;
|
|
1668
|
-
let hasContent = false;
|
|
1669
|
-
while (offset < source.length && characters < 999) {
|
|
1670
|
-
const code = source.charCodeAt(offset);
|
|
1671
|
-
if (code === 93) return hasContent ? offset + 1 : -1;
|
|
1672
|
-
if (code === 91) return -1;
|
|
1673
|
-
if (code === 92) {
|
|
1674
|
-
if (offset + 1 >= source.length) return -1;
|
|
1675
|
-
hasContent = true;
|
|
1676
|
-
offset += 2;
|
|
1677
|
-
} else {
|
|
1678
|
-
hasContent ||= code !== 9 && code !== 10 && code !== 13 && code !== 32;
|
|
1679
|
-
offset++;
|
|
1680
|
-
}
|
|
1681
|
-
characters++;
|
|
1682
|
-
}
|
|
1683
|
-
return -1;
|
|
1684
|
-
}
|
|
1685
|
-
function isAsciiPunctuation(code) {
|
|
1686
|
-
return code >= 33 && code <= 47 || code >= 58 && code <= 64 || code >= 91 && code <= 96 || code >= 123 && code <= 126;
|
|
1687
|
-
}
|
|
1688
|
-
function textEnd(source, start, boundary) {
|
|
1689
|
-
boundary.lastIndex = start;
|
|
1690
|
-
let match = boundary.exec(source);
|
|
1691
|
-
while (match !== null && source.charCodeAt(match.index) === 92) {
|
|
1692
|
-
const next = source.charCodeAt(match.index + 1);
|
|
1693
|
-
if (next !== 32 && next !== 9) break;
|
|
1694
|
-
boundary.lastIndex = match.index + 2;
|
|
1695
|
-
match = boundary.exec(source);
|
|
1696
|
-
}
|
|
1697
|
-
return match?.index ?? source.length;
|
|
1698
|
-
}
|
|
1699
|
-
function tokenizeInline(source) {
|
|
1414
|
+
function tokenize(source, textBoundary, lexicalByCode) {
|
|
1700
1415
|
const tokens = [];
|
|
1701
|
-
const textBoundary = / {2,}(?=[\n\r]|$)|[\n\r\\`*_[\]<!&~]/g;
|
|
1702
1416
|
let offset = 0;
|
|
1703
1417
|
let lineStart = true;
|
|
1704
1418
|
while (offset < source.length) {
|
|
@@ -1723,14 +1437,14 @@ function tokenizeInline(source) {
|
|
|
1723
1437
|
}
|
|
1724
1438
|
}
|
|
1725
1439
|
offset = content;
|
|
1726
|
-
if (tokens.length > 0) tokens.push(
|
|
1440
|
+
if (tokens.length > 0) tokens.push(42, offset, offset, 0);
|
|
1727
1441
|
lineStart = false;
|
|
1728
1442
|
continue;
|
|
1729
1443
|
}
|
|
1730
1444
|
const code = source.charCodeAt(offset);
|
|
1731
1445
|
if (code === 32 || code === 9) {
|
|
1732
1446
|
if (code === 32) {
|
|
1733
|
-
const end =
|
|
1447
|
+
const end = inlineMarkerRunEnd(source, offset);
|
|
1734
1448
|
const next = source.charCodeAt(end);
|
|
1735
1449
|
if (end - offset >= 2 && (next === 10 || next === 13)) {
|
|
1736
1450
|
tokens.push(7, offset, end, 0);
|
|
@@ -1751,71 +1465,78 @@ function tokenizeInline(source) {
|
|
|
1751
1465
|
lineStart = true;
|
|
1752
1466
|
continue;
|
|
1753
1467
|
}
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
end = matchEnd(autolink, source, offset);
|
|
1761
|
-
kind = 4;
|
|
1762
|
-
}
|
|
1763
|
-
if (end < 0) {
|
|
1764
|
-
end = matchEnd(inlineHtml, source, offset);
|
|
1765
|
-
kind = 5;
|
|
1766
|
-
}
|
|
1767
|
-
} else if (code === 38) {
|
|
1768
|
-
end = matchEnd(entity, source, offset);
|
|
1769
|
-
kind = 6;
|
|
1770
|
-
} else if (code === 92) {
|
|
1771
|
-
const next = source.charCodeAt(offset + 1);
|
|
1772
|
-
if (next === 10 || next === 13) {
|
|
1773
|
-
end = offset + 1;
|
|
1774
|
-
kind = 7;
|
|
1775
|
-
} else if (isAsciiPunctuation(next)) {
|
|
1776
|
-
end = offset + 2;
|
|
1777
|
-
kind = 8;
|
|
1778
|
-
} else if (next === 32 || next === 9) {
|
|
1779
|
-
end = textEnd(source, offset, textBoundary);
|
|
1780
|
-
kind = 9;
|
|
1781
|
-
}
|
|
1782
|
-
} else if (code === 96) {
|
|
1783
|
-
end = codeSpanEnd(source, offset);
|
|
1784
|
-
kind = 2;
|
|
1785
|
-
} else if (code === 42 || code === 95 || code === 126) {
|
|
1786
|
-
end = runEnd(source, offset, code);
|
|
1787
|
-
kind = code === 42 ? 10 : code === 95 ? 11 : 12;
|
|
1788
|
-
} else if (code === 33 && source.charCodeAt(offset + 1) === 91) {
|
|
1789
|
-
end = offset + 2;
|
|
1790
|
-
kind = 17;
|
|
1791
|
-
} else if (code === 91) {
|
|
1792
|
-
end = offset + 1;
|
|
1793
|
-
kind = 18;
|
|
1794
|
-
} else if (code === 93) {
|
|
1795
|
-
end = linkTailEnd(source, offset);
|
|
1796
|
-
kind = 19;
|
|
1797
|
-
if (end < 0) {
|
|
1798
|
-
end = referenceTailEnd(source, offset);
|
|
1799
|
-
kind = 20;
|
|
1800
|
-
}
|
|
1801
|
-
if (end < 0) {
|
|
1802
|
-
end = offset + 1;
|
|
1803
|
-
kind = 21;
|
|
1468
|
+
const scan = lexicalByCode[code];
|
|
1469
|
+
if (scan) {
|
|
1470
|
+
const lexicalEnd = scan(source, offset, tokens);
|
|
1471
|
+
if (lexicalEnd > offset) {
|
|
1472
|
+
offset = lexicalEnd;
|
|
1473
|
+
continue;
|
|
1804
1474
|
}
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
if (end <= offset) {
|
|
1810
|
-
end = offset + 1;
|
|
1811
|
-
kind = 38;
|
|
1475
|
+
const end = inlineTextEnd(source, offset + 1, textBoundary);
|
|
1476
|
+
tokens.push(9, offset, end, 0);
|
|
1477
|
+
offset = end;
|
|
1478
|
+
continue;
|
|
1812
1479
|
}
|
|
1813
|
-
const
|
|
1814
|
-
tokens.push(
|
|
1480
|
+
const end = inlineTextEnd(source, offset, textBoundary);
|
|
1481
|
+
tokens.push(9, offset, end, 0);
|
|
1815
1482
|
offset = end;
|
|
1816
1483
|
}
|
|
1817
1484
|
return tokens;
|
|
1818
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
|
+
}
|
|
1819
1540
|
//#endregion
|
|
1820
1541
|
//#region src/inline/pairing.ts
|
|
1821
1542
|
const whitespace = /\s/u;
|
|
@@ -1963,9 +1684,9 @@ function resolvePairedTokens(source, tokens, index, state) {
|
|
|
1963
1684
|
delimiterIsolations
|
|
1964
1685
|
};
|
|
1965
1686
|
}
|
|
1966
|
-
function applyPairReplacements(tokens, replacements) {
|
|
1687
|
+
function applyPairReplacements(tokens, replacements, ownsTokens) {
|
|
1967
1688
|
if (replacements.length === 0) return tokens;
|
|
1968
|
-
const result = tokens.slice();
|
|
1689
|
+
const result = ownsTokens ? tokens : tokens.slice();
|
|
1969
1690
|
for (let tokenIndex = 0; tokenIndex < replacements.length; tokenIndex++) {
|
|
1970
1691
|
const kind = replacements[tokenIndex];
|
|
1971
1692
|
if (kind !== void 0) {
|
|
@@ -2031,12 +1752,12 @@ function matchDelimiterRuns(runs, first, replacements) {
|
|
|
2031
1752
|
}
|
|
2032
1753
|
const opener = runs[openerIndex];
|
|
2033
1754
|
const use = opener.remaining >= 2 && closer.remaining >= 2 && closer.config.double ? 2 : 1;
|
|
2034
|
-
const openEnd = opener.offset +
|
|
2035
|
-
const openStart = openEnd - use
|
|
2036
|
-
const closeStart = closer.offset + closer.start
|
|
2037
|
-
const closeEnd = closeStart + use
|
|
1755
|
+
const openEnd = opener.offset + opener.start + opener.remaining;
|
|
1756
|
+
const openStart = openEnd - use;
|
|
1757
|
+
const closeStart = closer.offset + closer.start;
|
|
1758
|
+
const closeEnd = closeStart + use;
|
|
2038
1759
|
const pair = use === 2 ? closer.config.double : closer.config.single;
|
|
2039
|
-
if (!pair) throw new Error(`Delimiter ${closer.config.marker} has no replacement for a run of ${use}`);
|
|
1760
|
+
if (!pair) throw new Error(`Delimiter ${String.fromCharCode(closer.config.marker)} has no replacement for a run of ${use}`);
|
|
2040
1761
|
addReplacement(replacements, opener.tokenIndex, {
|
|
2041
1762
|
offset: openStart,
|
|
2042
1763
|
end: openEnd,
|
|
@@ -2067,7 +1788,7 @@ function resolveDelimiterRuns(source, tokens, configByKind, isolations) {
|
|
|
2067
1788
|
if (!config) continue;
|
|
2068
1789
|
const offset = inlineTokenStart(tokens, tokenIndex);
|
|
2069
1790
|
const end = inlineTokenEnd(tokens, tokenIndex);
|
|
2070
|
-
const length =
|
|
1791
|
+
const length = end - offset;
|
|
2071
1792
|
if (config.matchWholeRun && (length > 2 || (length === 1 ? !config.single : !config.double))) continue;
|
|
2072
1793
|
const flags = flanking(source, offset, end, config);
|
|
2073
1794
|
runs.push({
|
|
@@ -2100,10 +1821,11 @@ function resolveDelimiterRuns(source, tokens, configByKind, isolations) {
|
|
|
2100
1821
|
}
|
|
2101
1822
|
const replacements = [];
|
|
2102
1823
|
for (const first of scopeFirst) if (first !== void 0) matchDelimiterRuns(runs, first, replacements);
|
|
1824
|
+
if (replacements.length === 0) return tokens;
|
|
2103
1825
|
const result = [];
|
|
2104
1826
|
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
2105
|
-
const
|
|
2106
|
-
if (!
|
|
1827
|
+
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
1828
|
+
if (!configByKind[kind]) {
|
|
2107
1829
|
copyInlineToken(result, tokens, tokenIndex);
|
|
2108
1830
|
continue;
|
|
2109
1831
|
}
|
|
@@ -2111,12 +1833,12 @@ function resolveDelimiterRuns(source, tokens, configByKind, isolations) {
|
|
|
2111
1833
|
if (matched && matched.length > 1) matched.sort((left, right) => left.offset - right.offset);
|
|
2112
1834
|
let offset = inlineTokenStart(tokens, tokenIndex);
|
|
2113
1835
|
if (matched) for (const replacement of matched) {
|
|
2114
|
-
if (replacement.offset > offset) appendFragment(result, tokens, tokenIndex, offset, replacement.offset,
|
|
1836
|
+
if (replacement.offset > offset) appendFragment(result, tokens, tokenIndex, offset, replacement.offset, kind);
|
|
2115
1837
|
appendFragment(result, tokens, tokenIndex, replacement.offset, replacement.end, replacement.kind);
|
|
2116
1838
|
offset = replacement.end;
|
|
2117
1839
|
}
|
|
2118
1840
|
const end = inlineTokenEnd(tokens, tokenIndex);
|
|
2119
|
-
if (offset < end) appendFragment(result, tokens, tokenIndex, offset, end,
|
|
1841
|
+
if (offset < end) appendFragment(result, tokens, tokenIndex, offset, end, kind);
|
|
2120
1842
|
}
|
|
2121
1843
|
return result;
|
|
2122
1844
|
}
|
|
@@ -2125,7 +1847,6 @@ function createPairingResolver(delimiterConfigs, pairConfigs = []) {
|
|
|
2125
1847
|
delimiterConfigs.forEach((config, index) => {
|
|
2126
1848
|
delimiterByKind[config.token] = {
|
|
2127
1849
|
marker: config.marker,
|
|
2128
|
-
fallbackKind: config.fallbackToken,
|
|
2129
1850
|
single: config.single ? {
|
|
2130
1851
|
open: config.single.open,
|
|
2131
1852
|
close: config.single.close
|
|
@@ -2152,7 +1873,7 @@ function createPairingResolver(delimiterConfigs, pairConfigs = []) {
|
|
|
2152
1873
|
phasesByKind[openerKind] |= 1;
|
|
2153
1874
|
phasesByKind[closerKind] |= 1;
|
|
2154
1875
|
}
|
|
2155
|
-
return (source, tokens, state) => {
|
|
1876
|
+
return (source, tokens, state, ownsTokens = false) => {
|
|
2156
1877
|
const count = inlineTokenCount(tokens);
|
|
2157
1878
|
let activePhases = 0;
|
|
2158
1879
|
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
@@ -2176,50 +1897,13 @@ function createPairingResolver(delimiterConfigs, pairConfigs = []) {
|
|
|
2176
1897
|
} else if (expanded) copyInlineToken(expanded, tokens, tokenIndex);
|
|
2177
1898
|
}
|
|
2178
1899
|
if (expanded) paired = resolvePairedTokens(source, expanded, pairIndex, state);
|
|
2179
|
-
const resolvedPairs = applyPairReplacements(expanded ?? tokens, paired.replacements);
|
|
1900
|
+
const resolvedPairs = applyPairReplacements(expanded ?? tokens, paired.replacements, expanded !== void 0 || ownsTokens);
|
|
2180
1901
|
return activePhases & 2 ? resolveDelimiterRuns(source, resolvedPairs, delimiterByKind, paired.delimiterIsolations) : resolvedPairs;
|
|
2181
1902
|
};
|
|
2182
1903
|
}
|
|
2183
1904
|
//#endregion
|
|
2184
1905
|
//#region src/inline/profile.ts
|
|
2185
|
-
|
|
2186
|
-
function compileInlineSyntax(definitions) {
|
|
2187
|
-
const tokenBuilders = [];
|
|
2188
|
-
const containerByKind = [];
|
|
2189
|
-
const pairByOpenKind = [];
|
|
2190
|
-
const registerToken = (kind, build) => {
|
|
2191
|
-
tokenBuilders[kind] = build;
|
|
2192
|
-
return kind;
|
|
2193
|
-
};
|
|
2194
|
-
for (const definition of definitions) {
|
|
2195
|
-
if (definition.kind === "leaf") {
|
|
2196
|
-
registerToken(definition.token, definition.build);
|
|
2197
|
-
continue;
|
|
2198
|
-
}
|
|
2199
|
-
if (definition.kind === "container") {
|
|
2200
|
-
const tokenKind = registerToken(definition.token, ignoreInlineToken);
|
|
2201
|
-
containerByKind[tokenKind] = {
|
|
2202
|
-
closeKind: registerToken(definition.close, ignoreInlineToken),
|
|
2203
|
-
contentOpenKind: registerToken(definition.contentOpen, ignoreInlineToken),
|
|
2204
|
-
build: definition.build
|
|
2205
|
-
};
|
|
2206
|
-
continue;
|
|
2207
|
-
}
|
|
2208
|
-
const openKind = registerToken(definition.open, ignoreInlineToken);
|
|
2209
|
-
pairByOpenKind[openKind] = {
|
|
2210
|
-
closeKind: registerToken(definition.close, ignoreInlineToken),
|
|
2211
|
-
build: definition.build
|
|
2212
|
-
};
|
|
2213
|
-
}
|
|
2214
|
-
return {
|
|
2215
|
-
schema: {
|
|
2216
|
-
containerByKind,
|
|
2217
|
-
pairByOpenKind
|
|
2218
|
-
},
|
|
2219
|
-
tokenBuilders
|
|
2220
|
-
};
|
|
2221
|
-
}
|
|
2222
|
-
function composeTransforms(...rewrites) {
|
|
1906
|
+
function composeRewrites(rewrites) {
|
|
2223
1907
|
if (rewrites.length === 1) return rewrites[0];
|
|
2224
1908
|
return (source, tokens, context) => {
|
|
2225
1909
|
for (const rewrite of rewrites) tokens = rewrite(source, tokens, context);
|
|
@@ -2228,25 +1912,58 @@ function composeTransforms(...rewrites) {
|
|
|
2228
1912
|
}
|
|
2229
1913
|
function compileInlineProfile(features, decodeText) {
|
|
2230
1914
|
const delimiters = [];
|
|
2231
|
-
const
|
|
1915
|
+
const lexicalRules = [];
|
|
1916
|
+
const syntaxDefinitions = [];
|
|
2232
1917
|
const pairs = [];
|
|
2233
|
-
const
|
|
2234
|
-
const transforms = [];
|
|
1918
|
+
const rewrites = [];
|
|
2235
1919
|
for (const feature of features) {
|
|
2236
|
-
if (feature.
|
|
2237
|
-
|
|
2238
|
-
if (
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
1920
|
+
if (feature.delimiters) delimiters.push(...feature.delimiters);
|
|
1921
|
+
if (feature.lexical) lexicalRules.push(...feature.lexical);
|
|
1922
|
+
if (feature.pairs) pairs.push(...feature.pairs);
|
|
1923
|
+
if (feature.rewrite) rewrites.push(feature.rewrite);
|
|
1924
|
+
if (feature.syntax) syntaxDefinitions.push(...feature.syntax);
|
|
1925
|
+
}
|
|
1926
|
+
const tokenHandlers = [];
|
|
1927
|
+
const containerByKind = [];
|
|
1928
|
+
const pairByOpenKind = [];
|
|
1929
|
+
for (const definition of syntaxDefinitions) {
|
|
1930
|
+
if (definition.kind === "decorate") {
|
|
1931
|
+
tokenHandlers[definition.token] = definition.apply;
|
|
1932
|
+
continue;
|
|
2243
1933
|
}
|
|
1934
|
+
if (definition.kind === "leaf") {
|
|
1935
|
+
tokenHandlers[definition.token] = definition.build;
|
|
1936
|
+
continue;
|
|
1937
|
+
}
|
|
1938
|
+
if (definition.kind === "container") containerByKind[definition.token] = {
|
|
1939
|
+
closeKind: definition.close,
|
|
1940
|
+
contentOpenKind: definition.contentOpen,
|
|
1941
|
+
build: definition.build
|
|
1942
|
+
};
|
|
1943
|
+
else pairByOpenKind[definition.open] = {
|
|
1944
|
+
closeKind: definition.close,
|
|
1945
|
+
build: definition.build
|
|
1946
|
+
};
|
|
1947
|
+
if (definition.isolateDelimiters) pairs.push({
|
|
1948
|
+
opener: definition.kind === "container" ? definition.contentOpen : definition.open,
|
|
1949
|
+
closer: definition.close,
|
|
1950
|
+
isolateDelimiters: true
|
|
1951
|
+
});
|
|
2244
1952
|
}
|
|
1953
|
+
const pair = createPairingResolver(delimiters, pairs);
|
|
1954
|
+
const rewrite = rewrites.length === 0 ? void 0 : composeRewrites(rewrites);
|
|
2245
1955
|
return {
|
|
2246
|
-
...compileInlineSyntax(syntax),
|
|
2247
1956
|
decodeText,
|
|
2248
|
-
resolve:
|
|
2249
|
-
|
|
1957
|
+
resolve: rewrite === void 0 ? pair : (source, tokens, context) => {
|
|
1958
|
+
const rewritten = rewrite(source, tokens, context);
|
|
1959
|
+
return pair(source, rewritten, context, rewritten !== tokens);
|
|
1960
|
+
},
|
|
1961
|
+
schema: {
|
|
1962
|
+
containerByKind,
|
|
1963
|
+
pairByOpenKind
|
|
1964
|
+
},
|
|
1965
|
+
tokenHandlers,
|
|
1966
|
+
tokenize: compileInlineTokenizer(lexicalRules)
|
|
2250
1967
|
};
|
|
2251
1968
|
}
|
|
2252
1969
|
//#endregion
|
|
@@ -2255,182 +1972,15 @@ function extendSpan(value, end) {
|
|
|
2255
1972
|
const node = value;
|
|
2256
1973
|
node.position.end = Math.max(node.position.end, end);
|
|
2257
1974
|
}
|
|
2258
|
-
function firstChildStart(children) {
|
|
2259
|
-
const first = children[0];
|
|
2260
|
-
if (!first) throw new Error("mdast container unexpectedly has no children");
|
|
2261
|
-
return first.position.start;
|
|
2262
|
-
}
|
|
2263
|
-
function lastChildEnd(children, emptyEnd) {
|
|
2264
|
-
const last = children.at(-1);
|
|
2265
|
-
return last ? last.position.end : emptyEnd;
|
|
2266
|
-
}
|
|
2267
|
-
//#endregion
|
|
2268
|
-
//#region src/fragment/inline.ts
|
|
2269
|
-
function lineStart(source, offset) {
|
|
2270
|
-
while (offset > 0) {
|
|
2271
|
-
const character = source.charCodeAt(--offset);
|
|
2272
|
-
if (character === 10 || character === 13) return offset + 1;
|
|
2273
|
-
}
|
|
2274
|
-
return 0;
|
|
2275
|
-
}
|
|
2276
|
-
function lineEnd(source, offset, limit = source.length) {
|
|
2277
|
-
for (; offset < limit; offset++) {
|
|
2278
|
-
const character = source.charCodeAt(offset);
|
|
2279
|
-
if (character === 10 || character === 13) return offset;
|
|
2280
|
-
}
|
|
2281
|
-
return limit;
|
|
2282
|
-
}
|
|
2283
|
-
function lineEndingStart(source, offset) {
|
|
2284
|
-
const start = lineStart(source, offset);
|
|
2285
|
-
if (start === 0) return offset;
|
|
2286
|
-
return source[start - 1] === "\n" && source[start - 2] === "\r" ? start - 2 : start - 1;
|
|
2287
|
-
}
|
|
2288
|
-
function appendText(target, value, start, end) {
|
|
2289
|
-
if (!value) return;
|
|
2290
|
-
const previous = target.at(-1);
|
|
2291
|
-
if (previous?.type === "text" && !("attributes" in previous)) {
|
|
2292
|
-
previous.value += value;
|
|
2293
|
-
extendSpan(previous, end);
|
|
2294
|
-
} else target.push({
|
|
2295
|
-
type: "text",
|
|
2296
|
-
value,
|
|
2297
|
-
position: {
|
|
2298
|
-
start,
|
|
2299
|
-
end
|
|
2300
|
-
}
|
|
2301
|
-
});
|
|
2302
|
-
}
|
|
2303
|
-
function appendPhrasing(target, value) {
|
|
2304
|
-
if (value.type === "text") appendText(target, value.value, value.position.start, value.position.end);
|
|
2305
|
-
else target.push(value);
|
|
2306
|
-
}
|
|
2307
|
-
function createInlineAccumulator(context, target, cursor) {
|
|
2308
|
-
return {
|
|
2309
|
-
context,
|
|
2310
|
-
cursor,
|
|
2311
|
-
gapEnd: -1,
|
|
2312
|
-
gapStart: -1,
|
|
2313
|
-
target
|
|
2314
|
-
};
|
|
2315
|
-
}
|
|
2316
|
-
function appendInlineGap(accumulator, start, end) {
|
|
2317
|
-
accumulator.gapStart = -1;
|
|
2318
|
-
accumulator.gapEnd = -1;
|
|
2319
|
-
const { context, target } = accumulator;
|
|
2320
|
-
const gapSpan = context.view.mapSpan(start, end);
|
|
2321
|
-
appendText(target, context.decodeText(context.view.text.slice(start, end).replace(/[\r\n]/g, "")), gapSpan.start, gapSpan.end);
|
|
2322
|
-
}
|
|
2323
|
-
function appendInline(accumulator, value) {
|
|
2324
|
-
const { context, target } = accumulator;
|
|
2325
|
-
const nextLineOffset = value.position.start;
|
|
2326
|
-
const newline = value.type === "text" && value.value.startsWith("\n");
|
|
2327
|
-
if (accumulator.gapStart >= 0) {
|
|
2328
|
-
if (!newline) appendInlineGap(accumulator, accumulator.gapStart, accumulator.gapEnd);
|
|
2329
|
-
else {
|
|
2330
|
-
accumulator.gapStart = -1;
|
|
2331
|
-
accumulator.gapEnd = -1;
|
|
2332
|
-
}
|
|
2333
|
-
}
|
|
2334
|
-
if (newline) {
|
|
2335
|
-
const previous = target.at(-1);
|
|
2336
|
-
if (previous?.type === "break") {
|
|
2337
|
-
extendSpan(previous, lineStart(context.source, nextLineOffset));
|
|
2338
|
-
return;
|
|
2339
|
-
}
|
|
2340
|
-
value.position.start = lineEndingStart(context.source, nextLineOffset);
|
|
2341
|
-
if (previous?.type === "text") previous.value = previous.value.slice(0, trailingWhitespaceStart(previous.value));
|
|
2342
|
-
}
|
|
2343
|
-
appendPhrasing(target, value);
|
|
2344
|
-
}
|
|
2345
|
-
function appendInlineLeaf(tokenIndex, sourceSpan, accumulator) {
|
|
2346
|
-
const { context } = accumulator;
|
|
2347
|
-
const build = context.tokenBuilders[inlineTokenKind(context.tokens, tokenIndex)];
|
|
2348
|
-
if (!build) throw new Error(`Unexpected inline token kind ${inlineTokenKind(context.tokens, tokenIndex)}`);
|
|
2349
|
-
return build(tokenIndex, sourceSpan, accumulator);
|
|
2350
|
-
}
|
|
2351
|
-
function trailingWhitespaceStart(value) {
|
|
2352
|
-
let offset = value.length;
|
|
2353
|
-
while (offset > 0 && (value[offset - 1] === " " || value[offset - 1] === " ")) offset--;
|
|
2354
|
-
return offset;
|
|
2355
|
-
}
|
|
2356
|
-
function appendInlineRange(startToken, endToken, accumulator, closeKind) {
|
|
2357
|
-
const { context } = accumulator;
|
|
2358
|
-
let index = startToken;
|
|
2359
|
-
while (index < endToken) {
|
|
2360
|
-
if (inlineTokenKind(context.tokens, index) === closeKind) break;
|
|
2361
|
-
const childOffset = inlineTokenStart(context.tokens, index);
|
|
2362
|
-
if (accumulator.cursor !== void 0 && childOffset > accumulator.cursor) {
|
|
2363
|
-
accumulator.gapStart = accumulator.cursor;
|
|
2364
|
-
accumulator.gapEnd = childOffset;
|
|
2365
|
-
}
|
|
2366
|
-
const next = buildInlineSemantic(index, endToken, accumulator);
|
|
2367
|
-
const childEnd = inlineTokenEnd(context.tokens, next === void 0 ? index : next - 1);
|
|
2368
|
-
const childEmitted = next === void 0 ? appendInlineLeaf(index, context.view.mapSpan(childOffset, childEnd), accumulator) : true;
|
|
2369
|
-
index = next ?? index + 1;
|
|
2370
|
-
if (!childEmitted) continue;
|
|
2371
|
-
accumulator.cursor = childEnd;
|
|
2372
|
-
}
|
|
2373
|
-
return index;
|
|
2374
|
-
}
|
|
2375
|
-
function buildInlineSemantic(openToken, endToken, accumulator) {
|
|
2376
|
-
const { context } = accumulator;
|
|
2377
|
-
const kind = inlineTokenKind(context.tokens, openToken);
|
|
2378
|
-
const container = context.schema.containerByKind[kind];
|
|
2379
|
-
if (container) {
|
|
2380
|
-
let closeToken = openToken;
|
|
2381
|
-
let next = openToken + 1;
|
|
2382
|
-
const children = [];
|
|
2383
|
-
if (next < endToken && inlineTokenKind(context.tokens, next) === container.contentOpenKind) {
|
|
2384
|
-
const childAccumulator = createInlineAccumulator(context, children, inlineTokenEnd(context.tokens, next++));
|
|
2385
|
-
closeToken = appendInlineRange(next, endToken, childAccumulator, container.closeKind);
|
|
2386
|
-
if (closeToken >= endToken || inlineTokenKind(context.tokens, closeToken) !== container.closeKind) throw new Error(`Resolved inline stream did not close token kind ${kind}`);
|
|
2387
|
-
const contentEnd = inlineTokenStart(context.tokens, closeToken);
|
|
2388
|
-
if (childAccumulator.cursor !== void 0 && contentEnd > childAccumulator.cursor) appendInlineGap(childAccumulator, childAccumulator.cursor, contentEnd);
|
|
2389
|
-
next = closeToken + 1;
|
|
2390
|
-
}
|
|
2391
|
-
container.build(openToken, closeToken, children, context.view.mapSpan(inlineTokenStart(context.tokens, openToken), inlineTokenEnd(context.tokens, closeToken)), accumulator);
|
|
2392
|
-
return next;
|
|
2393
|
-
}
|
|
2394
|
-
const pair = context.schema.pairByOpenKind[kind];
|
|
2395
|
-
if (!pair) return;
|
|
2396
|
-
const contentStart = inlineTokenEnd(context.tokens, openToken);
|
|
2397
|
-
const children = [];
|
|
2398
|
-
const childAccumulator = createInlineAccumulator(context, children, contentStart);
|
|
2399
|
-
const closeToken = appendInlineRange(openToken + 1, endToken, childAccumulator, pair.closeKind);
|
|
2400
|
-
if (closeToken >= endToken || inlineTokenKind(context.tokens, closeToken) !== pair.closeKind) throw new Error(`Resolved inline stream did not close token kind ${kind}`);
|
|
2401
|
-
const contentEnd = inlineTokenStart(context.tokens, closeToken);
|
|
2402
|
-
if (childAccumulator.cursor !== void 0 && contentEnd > childAccumulator.cursor) appendInlineGap(childAccumulator, childAccumulator.cursor, contentEnd);
|
|
2403
|
-
pair.build(openToken, closeToken, children, context.view.mapSpan(inlineTokenStart(context.tokens, openToken), inlineTokenEnd(context.tokens, closeToken)), accumulator);
|
|
2404
|
-
return closeToken + 1;
|
|
2405
|
-
}
|
|
2406
|
-
function buildInlineChildren(nodeId, context, allowEmpty = false) {
|
|
2407
|
-
const region = context.inline.take(nodeId);
|
|
2408
|
-
if (!region) {
|
|
2409
|
-
const rule = context.arena.ruleNameOf(nodeId);
|
|
2410
|
-
if (allowEmpty) return [];
|
|
2411
|
-
throw new Error(`Expected ${rule} syntax to contain inline content`);
|
|
2412
|
-
}
|
|
2413
|
-
const inlineContext = {
|
|
2414
|
-
blockRule: region.rule,
|
|
2415
|
-
decodeText: context.profile.decodeText,
|
|
2416
|
-
schema: context.profile.schema,
|
|
2417
|
-
source: context.source,
|
|
2418
|
-
tokenBuilders: context.profile.tokenBuilders,
|
|
2419
|
-
tokens: region.tokens,
|
|
2420
|
-
view: region.view
|
|
2421
|
-
};
|
|
2422
|
-
const result = [];
|
|
2423
|
-
appendInlineRange(0, inlineTokenCount(region.tokens), createInlineAccumulator(inlineContext, result));
|
|
2424
|
-
const last = result.at(-1);
|
|
2425
|
-
if (last?.type === "text") {
|
|
2426
|
-
const end = trailingWhitespaceStart(last.value);
|
|
2427
|
-
const removed = last.value.length - end;
|
|
2428
|
-
last.value = last.value.slice(0, end);
|
|
2429
|
-
last.position.end -= removed;
|
|
2430
|
-
if (!last.value) result.pop();
|
|
2431
|
-
}
|
|
2432
|
-
return result;
|
|
2433
|
-
}
|
|
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
|
+
}
|
|
2434
1984
|
//#endregion
|
|
2435
1985
|
//#region src/profile/features/attributes/syntax.ts
|
|
2436
1986
|
const brackets = {
|
|
@@ -2448,8 +1998,8 @@ function isAsciiDigit(character) {
|
|
|
2448
1998
|
const code = character.charCodeAt(0);
|
|
2449
1999
|
return code >= 48 && code <= 57;
|
|
2450
2000
|
}
|
|
2451
|
-
function
|
|
2452
|
-
return character === " " || character === " "
|
|
2001
|
+
function isHorizontalWhitespace(character) {
|
|
2002
|
+
return character === " " || character === " ";
|
|
2453
2003
|
}
|
|
2454
2004
|
function componentNameEnd(source, start, block) {
|
|
2455
2005
|
if (!isAsciiLetter(source[start]) && source[start] !== "$") return;
|
|
@@ -2506,13 +2056,13 @@ function scanAttributes(source, start, attributes, limit = source.length) {
|
|
|
2506
2056
|
let offset = start + 1;
|
|
2507
2057
|
const readUntil = (stops) => {
|
|
2508
2058
|
const valueStart = offset;
|
|
2509
|
-
while (offset < limit && !stops.includes(source[offset])) if (source[offset] === "\\" && offset + 1 < limit) offset += 2;
|
|
2059
|
+
while (offset < limit && source[offset] !== "\n" && source[offset] !== "\r" && !stops.includes(source[offset])) if (source[offset] === "\\" && offset + 1 < limit) offset += 2;
|
|
2510
2060
|
else offset++;
|
|
2511
2061
|
return source.slice(valueStart, offset);
|
|
2512
2062
|
};
|
|
2513
2063
|
const readQuoted = (quote) => {
|
|
2514
2064
|
const valueStart = ++offset;
|
|
2515
|
-
while (offset < limit && source[offset] !== quote) offset += source[offset] === "\\" && offset + 1 < limit ? 2 : 1;
|
|
2065
|
+
while (offset < limit && source[offset] !== "\n" && source[offset] !== "\r" && source[offset] !== quote) offset += source[offset] === "\\" && offset + 1 < limit ? 2 : 1;
|
|
2516
2066
|
if (source[offset] !== quote) return;
|
|
2517
2067
|
const value = source.slice(valueStart, offset);
|
|
2518
2068
|
offset++;
|
|
@@ -2524,6 +2074,7 @@ function scanAttributes(source, start, attributes, limit = source.length) {
|
|
|
2524
2074
|
offset++;
|
|
2525
2075
|
while (offset < limit && stack.length > 0) {
|
|
2526
2076
|
const character = source[offset];
|
|
2077
|
+
if (character === "\n" || character === "\r") return;
|
|
2527
2078
|
if (character === "\\" && offset + 1 < limit) {
|
|
2528
2079
|
offset += 2;
|
|
2529
2080
|
continue;
|
|
@@ -2540,7 +2091,7 @@ function scanAttributes(source, start, attributes, limit = source.length) {
|
|
|
2540
2091
|
return stack.length === 0 ? source.slice(valueStart, offset) : void 0;
|
|
2541
2092
|
};
|
|
2542
2093
|
while (offset < limit) {
|
|
2543
|
-
while (
|
|
2094
|
+
while (isHorizontalWhitespace(source[offset])) offset++;
|
|
2544
2095
|
if (source[offset] === "}") return offset + 1;
|
|
2545
2096
|
const marker = source[offset];
|
|
2546
2097
|
if (marker === "." || marker === "#") {
|
|
@@ -2556,13 +2107,13 @@ function scanAttributes(source, start, attributes, limit = source.length) {
|
|
|
2556
2107
|
offset++;
|
|
2557
2108
|
while (isAsciiLetter(source[offset]) || isAsciiDigit(source[offset]) || source[offset] === "_" || source[offset] === "-") offset++;
|
|
2558
2109
|
const rawName = source.slice(nameStart, offset);
|
|
2559
|
-
while (
|
|
2110
|
+
while (isHorizontalWhitespace(source[offset])) offset++;
|
|
2560
2111
|
if (source[offset] !== "=") {
|
|
2561
2112
|
if (attributes) assignAttribute(attributes, rawName.startsWith(":") ? rawName : `:${rawName}`, "true");
|
|
2562
2113
|
continue;
|
|
2563
2114
|
}
|
|
2564
2115
|
offset++;
|
|
2565
|
-
while (
|
|
2116
|
+
while (isHorizontalWhitespace(source[offset])) offset++;
|
|
2566
2117
|
const character = source[offset];
|
|
2567
2118
|
let value;
|
|
2568
2119
|
if (character === "\"" || character === "'" || character === "`") value = readQuoted(character);
|
|
@@ -2605,14 +2156,14 @@ function takeTerminalAttributes(children) {
|
|
|
2605
2156
|
}
|
|
2606
2157
|
//#endregion
|
|
2607
2158
|
//#region src/profile/features/attributes/index.ts
|
|
2608
|
-
const decorateInlineContainer = (build) => (
|
|
2609
|
-
const result = build(
|
|
2159
|
+
const decorateInlineContainer = (build) => (tokenStart, context) => {
|
|
2160
|
+
const result = build(tokenStart, context);
|
|
2610
2161
|
const attributes = takeTerminalAttributes(result.children);
|
|
2611
2162
|
if (attributes) result.attributes = attributes;
|
|
2612
2163
|
return result;
|
|
2613
2164
|
};
|
|
2614
|
-
const decorateList = (build) => (
|
|
2615
|
-
const result = build(
|
|
2165
|
+
const decorateList = (build) => (tokenStart, context) => {
|
|
2166
|
+
const result = build(tokenStart, context);
|
|
2616
2167
|
if (!result.spread) for (const item of result.children) {
|
|
2617
2168
|
const paragraph = !item.spread && item.children.length === 1 && item.children[0].type === "paragraph" ? item.children[0] : void 0;
|
|
2618
2169
|
if (paragraph?.attributes) {
|
|
@@ -2622,8 +2173,8 @@ const decorateList = (build) => (nodeId, offset, tokenBase, context) => {
|
|
|
2622
2173
|
}
|
|
2623
2174
|
return result;
|
|
2624
2175
|
};
|
|
2625
|
-
const decorateBlockquote = (build) => (
|
|
2626
|
-
const result = build(
|
|
2176
|
+
const decorateBlockquote = (build) => (tokenStart, context) => {
|
|
2177
|
+
const result = build(tokenStart, context);
|
|
2627
2178
|
const paragraph = result.children.length === 1 && result.children[0].type === "paragraph" ? result.children[0] : void 0;
|
|
2628
2179
|
if (paragraph?.attributes) {
|
|
2629
2180
|
result.attributes = paragraph.attributes;
|
|
@@ -2638,73 +2189,39 @@ function hasVisibleText(source, start, end) {
|
|
|
2638
2189
|
for (let offset = start; offset < end; offset++) if (!isMarkdownWhitespace(source.charCodeAt(offset))) return true;
|
|
2639
2190
|
return false;
|
|
2640
2191
|
}
|
|
2641
|
-
function
|
|
2642
|
-
|
|
2643
|
-
let consumedEnd = 0;
|
|
2644
|
-
let hasContent = false;
|
|
2645
|
-
let regionEnd = source.length;
|
|
2646
|
-
const boundaries = [];
|
|
2647
|
-
for (let index = 0; index < inlineTokenCount(tokens); index++) if (inlineTokenKind(tokens, index) === 40) boundaries.push(inlineTokenStart(tokens, index));
|
|
2648
|
-
regionEnd = boundaries[0] ?? source.length;
|
|
2649
|
-
let boundaryIndex = 0;
|
|
2650
|
-
let attributeLineEnd = 0;
|
|
2651
|
-
for (let index = 0; index < inlineTokenCount(tokens); index++) {
|
|
2652
|
-
const kind = inlineTokenKind(tokens, index);
|
|
2653
|
-
const start = inlineTokenStart(tokens, index);
|
|
2654
|
-
const end = inlineTokenEnd(tokens, index);
|
|
2655
|
-
while (boundaryIndex < boundaries.length && boundaries[boundaryIndex] <= start) {
|
|
2656
|
-
regionEnd = boundaries[boundaryIndex + 1] ?? source.length;
|
|
2657
|
-
boundaryIndex++;
|
|
2658
|
-
hasContent = false;
|
|
2659
|
-
attributeLineEnd = 0;
|
|
2660
|
-
}
|
|
2661
|
-
if (kind === 40 || end <= consumedEnd) continue;
|
|
2662
|
-
if (kind !== 9) {
|
|
2663
|
-
hasContent = true;
|
|
2664
|
-
continue;
|
|
2665
|
-
}
|
|
2666
|
-
let cursor = Math.max(start, consumedEnd);
|
|
2667
|
-
for (let offset = source.indexOf("{", cursor); offset >= cursor && offset < end;) {
|
|
2668
|
-
if (hasVisibleText(source, cursor, offset)) hasContent = true;
|
|
2669
|
-
const invalidPrefix = source[offset + 1] === "{" || source[offset - 1] === "{" || source[offset - 1] === "$";
|
|
2670
|
-
if (!invalidPrefix && offset >= attributeLineEnd) attributeLineEnd = lineEnd(source, offset, regionEnd);
|
|
2671
|
-
const parsedEnd = invalidPrefix ? void 0 : attributesEnd(source, offset, attributeLineEnd);
|
|
2672
|
-
if (parsedEnd === void 0) {
|
|
2673
|
-
hasContent = true;
|
|
2674
|
-
cursor = offset + 1;
|
|
2675
|
-
offset = source.indexOf("{", cursor);
|
|
2676
|
-
continue;
|
|
2677
|
-
}
|
|
2678
|
-
if (!hasContent) {
|
|
2679
|
-
cursor = parsedEnd;
|
|
2680
|
-
offset = source.indexOf("{", cursor);
|
|
2681
|
-
continue;
|
|
2682
|
-
}
|
|
2683
|
-
spans.push({
|
|
2684
|
-
detached: offset > 0 && isMarkdownWhitespace(source.charCodeAt(offset - 1)),
|
|
2685
|
-
start: offset,
|
|
2686
|
-
end: parsedEnd
|
|
2687
|
-
});
|
|
2688
|
-
consumedEnd = parsedEnd;
|
|
2689
|
-
cursor = parsedEnd;
|
|
2690
|
-
offset = source.indexOf("{", cursor);
|
|
2691
|
-
}
|
|
2692
|
-
if (hasVisibleText(source, cursor, end)) hasContent = true;
|
|
2693
|
-
}
|
|
2694
|
-
return spans;
|
|
2192
|
+
function attributeEndAt(source, start) {
|
|
2193
|
+
return source[start + 1] === "{" || source[start - 1] === "{" || source[start - 1] === "$" ? void 0 : attributesEnd(source, start);
|
|
2695
2194
|
}
|
|
2696
|
-
function
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2195
|
+
function scanAttribute(source, start, tokens) {
|
|
2196
|
+
const end = attributeEndAt(source, start);
|
|
2197
|
+
if (end === void 0) return -1;
|
|
2198
|
+
if (tokens.length === 0) {
|
|
2199
|
+
let textEnd = end;
|
|
2200
|
+
while (true) {
|
|
2201
|
+
let next = textEnd;
|
|
2202
|
+
while (source.charCodeAt(next) === 9 || source.charCodeAt(next) === 32) next++;
|
|
2203
|
+
const nextEnd = source.charCodeAt(next) === 123 ? attributeEndAt(source, next) : void 0;
|
|
2204
|
+
if (nextEnd === void 0) break;
|
|
2205
|
+
textEnd = nextEnd;
|
|
2206
|
+
}
|
|
2207
|
+
appendInlineToken(tokens, 9, start, textEnd);
|
|
2208
|
+
return textEnd;
|
|
2209
|
+
}
|
|
2210
|
+
const previous = inlineTokenCount(tokens) - 1;
|
|
2211
|
+
const previousEnd = previous >= 0 ? inlineTokenEnd(tokens, previous) : start;
|
|
2212
|
+
if (previousEnd <= start && inlineTokenKind(tokens, previous) === 38) appendInlineToken(tokens, 9, previousEnd, start);
|
|
2213
|
+
appendInlineToken(tokens, 38, start, end, start > 0 && isMarkdownWhitespace(source.charCodeAt(start - 1)) ? 4 : 0);
|
|
2214
|
+
let next = end;
|
|
2215
|
+
while (isMarkdownWhitespace(source.charCodeAt(next))) next++;
|
|
2216
|
+
if (next === source.length) for (let index = inlineTokenCount(tokens) - 1; index >= 0; index--) {
|
|
2217
|
+
const kind = inlineTokenKind(tokens, index);
|
|
2218
|
+
if (kind === 9 && !hasVisibleText(source, inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index))) continue;
|
|
2219
|
+
if (kind !== 38) break;
|
|
2220
|
+
setInlineTokenFlags(tokens, index, inlineTokenFlags(tokens, index) | 8);
|
|
2705
2221
|
}
|
|
2222
|
+
return end;
|
|
2706
2223
|
}
|
|
2707
|
-
const feature$
|
|
2224
|
+
const feature$17 = {
|
|
2708
2225
|
block: { decorators: [
|
|
2709
2226
|
{
|
|
2710
2227
|
rule: "Paragraph",
|
|
@@ -2732,19 +2249,22 @@ const feature$16 = {
|
|
|
2732
2249
|
}
|
|
2733
2250
|
] },
|
|
2734
2251
|
inline: {
|
|
2735
|
-
|
|
2252
|
+
lexical: [{
|
|
2253
|
+
marker: 123,
|
|
2254
|
+
scan: scanAttribute
|
|
2255
|
+
}],
|
|
2736
2256
|
syntax: [{
|
|
2737
|
-
kind: "
|
|
2738
|
-
token:
|
|
2739
|
-
|
|
2740
|
-
const previous =
|
|
2741
|
-
const parsed = parseAttributes(
|
|
2257
|
+
kind: "decorate",
|
|
2258
|
+
token: 38,
|
|
2259
|
+
apply(tokenIndex, sourceSpan, context, target) {
|
|
2260
|
+
const previous = target.at(-1);
|
|
2261
|
+
const parsed = parseAttributes(context.view.text, inlineTokenStart(context.tokens, tokenIndex));
|
|
2742
2262
|
if (!previous || !parsed) return false;
|
|
2743
|
-
const flags = inlineTokenFlags(
|
|
2263
|
+
const flags = inlineTokenFlags(context.tokens, tokenIndex);
|
|
2744
2264
|
const terminal = Boolean(flags & 8);
|
|
2745
2265
|
const detached = Boolean(flags & 4);
|
|
2746
|
-
if (terminal && (detached || previous.type === "text" || hasTerminalAttributes(
|
|
2747
|
-
carryTerminalAttributes(
|
|
2266
|
+
if (terminal && (detached || previous.type === "text" || hasTerminalAttributes(target))) {
|
|
2267
|
+
carryTerminalAttributes(target, parsed.attributes);
|
|
2748
2268
|
return true;
|
|
2749
2269
|
}
|
|
2750
2270
|
if (previous.attributes) mergeAttributes(previous.attributes, parsed.attributes);
|
|
@@ -2755,28 +2275,49 @@ const feature$16 = {
|
|
|
2755
2275
|
}]
|
|
2756
2276
|
}
|
|
2757
2277
|
};
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
if (
|
|
2762
|
-
const
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
}
|
|
2777
|
-
}
|
|
2778
|
-
|
|
2779
|
-
|
|
2278
|
+
//#endregion
|
|
2279
|
+
//#region src/profile/features/binding.ts
|
|
2280
|
+
function bindingEnd(source, start) {
|
|
2281
|
+
if (source.charCodeAt(start + 1) !== 123) return -1;
|
|
2282
|
+
const close = source.indexOf("}}", start + 2);
|
|
2283
|
+
if (close < 0) return -1;
|
|
2284
|
+
const separator = source.indexOf("||", start + 2);
|
|
2285
|
+
const valueEnd = separator < 0 || separator > close ? close : separator;
|
|
2286
|
+
return source.slice(start + 2, valueEnd).trim() ? close + 2 : -1;
|
|
2287
|
+
}
|
|
2288
|
+
const feature$16 = { inline: {
|
|
2289
|
+
lexical: [{
|
|
2290
|
+
marker: 123,
|
|
2291
|
+
scan(source, start, tokens) {
|
|
2292
|
+
const end = bindingEnd(source, start);
|
|
2293
|
+
if (end < 0) return -1;
|
|
2294
|
+
appendInlineToken(tokens, 34, start, end);
|
|
2295
|
+
return end;
|
|
2296
|
+
}
|
|
2297
|
+
}],
|
|
2298
|
+
syntax: [{
|
|
2299
|
+
kind: "leaf",
|
|
2300
|
+
token: 34,
|
|
2301
|
+
build(tokenIndex, sourceSpan, context) {
|
|
2302
|
+
const source = context.view.text;
|
|
2303
|
+
const start = inlineTokenStart(context.tokens, tokenIndex) + 2;
|
|
2304
|
+
const end = inlineTokenEnd(context.tokens, tokenIndex) - 2;
|
|
2305
|
+
const match = source.indexOf("||", start);
|
|
2306
|
+
const separator = match < 0 || match > end ? end : match;
|
|
2307
|
+
const value = source.slice(start, separator).trim();
|
|
2308
|
+
const defaultValue = separator === end ? "" : source.slice(separator + 2, end).trim();
|
|
2309
|
+
const attributes = { ":value": value };
|
|
2310
|
+
if (defaultValue) attributes.defaultValue = defaultValue;
|
|
2311
|
+
return {
|
|
2312
|
+
type: "inlineComponent",
|
|
2313
|
+
name: "binding",
|
|
2314
|
+
attributes,
|
|
2315
|
+
children: [],
|
|
2316
|
+
position: sourceSpan
|
|
2317
|
+
};
|
|
2318
|
+
}
|
|
2319
|
+
}]
|
|
2320
|
+
} };
|
|
2780
2321
|
//#endregion
|
|
2781
2322
|
//#region src/profile/features/blockquote.ts
|
|
2782
2323
|
function blockQuoteOffset(source, line) {
|
|
@@ -2810,14 +2351,15 @@ const feature$15 = { block: {
|
|
|
2810
2351
|
open: 3,
|
|
2811
2352
|
close: 4
|
|
2812
2353
|
},
|
|
2813
|
-
build(
|
|
2814
|
-
const
|
|
2354
|
+
build(tokenStart, context) {
|
|
2355
|
+
const offset = context.structure.tokens.start(tokenStart);
|
|
2356
|
+
const marker = blockToken(tokenStart, 3, context);
|
|
2815
2357
|
return {
|
|
2816
2358
|
type: "blockquote",
|
|
2817
|
-
children: buildBlockChildren(
|
|
2359
|
+
children: buildBlockChildren(tokenStart, context),
|
|
2818
2360
|
position: {
|
|
2819
|
-
start: firstNonspace(context.source, context.
|
|
2820
|
-
end: blockEnd(
|
|
2361
|
+
start: firstNonspace(context.source, context.structure.tokens.start(marker), lineEnd(context.source, offset)),
|
|
2362
|
+
end: blockEnd(tokenStart, context)
|
|
2821
2363
|
}
|
|
2822
2364
|
};
|
|
2823
2365
|
}
|
|
@@ -2878,13 +2420,14 @@ const feature$14 = {
|
|
|
2878
2420
|
kind: "leaf",
|
|
2879
2421
|
token: 2
|
|
2880
2422
|
},
|
|
2881
|
-
build(
|
|
2882
|
-
const
|
|
2423
|
+
build(tokenStart, context) {
|
|
2424
|
+
const offset = context.structure.tokens.start(tokenStart);
|
|
2425
|
+
const end = offset + context.structure.lenOf(tokenStart);
|
|
2883
2426
|
return {
|
|
2884
2427
|
type: "thematicBreak",
|
|
2885
2428
|
position: {
|
|
2886
2429
|
start: firstNonspace(context.source, offset, end),
|
|
2887
|
-
end: blockEnd(
|
|
2430
|
+
end: blockEnd(tokenStart, context)
|
|
2888
2431
|
}
|
|
2889
2432
|
};
|
|
2890
2433
|
}
|
|
@@ -2909,23 +2452,21 @@ const feature$14 = {
|
|
|
2909
2452
|
inline: { syntax: [{
|
|
2910
2453
|
kind: "leaf",
|
|
2911
2454
|
token: 7,
|
|
2912
|
-
build(tokenIndex, sourceSpan
|
|
2913
|
-
|
|
2455
|
+
build(tokenIndex, sourceSpan) {
|
|
2456
|
+
return {
|
|
2914
2457
|
type: "break",
|
|
2915
2458
|
position: sourceSpan
|
|
2916
|
-
}
|
|
2917
|
-
return true;
|
|
2459
|
+
};
|
|
2918
2460
|
}
|
|
2919
2461
|
}, {
|
|
2920
2462
|
kind: "leaf",
|
|
2921
|
-
token:
|
|
2922
|
-
build(tokenIndex, sourceSpan
|
|
2923
|
-
|
|
2463
|
+
token: 42,
|
|
2464
|
+
build(tokenIndex, sourceSpan) {
|
|
2465
|
+
return {
|
|
2924
2466
|
type: "text",
|
|
2925
2467
|
value: "\n",
|
|
2926
2468
|
position: sourceSpan
|
|
2927
|
-
}
|
|
2928
|
-
return true;
|
|
2469
|
+
};
|
|
2929
2470
|
}
|
|
2930
2471
|
}] }
|
|
2931
2472
|
};
|
|
@@ -2944,6 +2485,7 @@ function fenceAt$1(source, line, rule) {
|
|
|
2944
2485
|
while (offset < line.end) if (source[offset++] === marker) return;
|
|
2945
2486
|
}
|
|
2946
2487
|
return {
|
|
2488
|
+
indent: indent.columns,
|
|
2947
2489
|
marker,
|
|
2948
2490
|
length,
|
|
2949
2491
|
offset: indent.offset
|
|
@@ -2958,51 +2500,33 @@ function closesFence(source, line, fence) {
|
|
|
2958
2500
|
while (offset < line.end && (source[offset] === " " || source[offset] === " ")) offset++;
|
|
2959
2501
|
return offset === line.end;
|
|
2960
2502
|
}
|
|
2961
|
-
function
|
|
2962
|
-
if (end <= start) return end;
|
|
2963
|
-
if (source.charCodeAt(end - 1) === 10) return end > start + 1 && source.charCodeAt(end - 2) === 13 ? end - 2 : end - 1;
|
|
2964
|
-
return source.charCodeAt(end - 1) === 13 ? end - 1 : end;
|
|
2965
|
-
}
|
|
2966
|
-
function readFencedBlock(source, rule) {
|
|
2967
|
-
if (!source) throw new Error("Fenced block token is empty");
|
|
2968
|
-
let openingEnd = 0;
|
|
2969
|
-
while (openingEnd < source.length && source[openingEnd] !== "\n" && source[openingEnd] !== "\r") openingEnd++;
|
|
2970
|
-
let contentStart = openingEnd;
|
|
2971
|
-
if (source[contentStart] === "\r") contentStart += source[contentStart + 1] === "\n" ? 2 : 1;
|
|
2972
|
-
else if (source[contentStart] === "\n") contentStart++;
|
|
2973
|
-
const fence = fenceAt$1(source, {
|
|
2974
|
-
start: 0,
|
|
2975
|
-
end: openingEnd,
|
|
2976
|
-
next: contentStart
|
|
2977
|
-
}, rule);
|
|
2978
|
-
if (!fence) throw new Error("Fenced block token has no opening fence");
|
|
2979
|
-
const finalLineEnd = lineContentEnd(source, 0, source.length);
|
|
2980
|
-
let finalLineStart = finalLineEnd;
|
|
2981
|
-
while (finalLineStart > 0 && source[finalLineStart - 1] !== "\n" && source[finalLineStart - 1] !== "\r") finalLineStart--;
|
|
2982
|
-
const closed = finalLineStart >= contentStart && closesFence(source, {
|
|
2983
|
-
start: finalLineStart,
|
|
2984
|
-
end: finalLineEnd,
|
|
2985
|
-
next: source.length
|
|
2986
|
-
}, fence);
|
|
2503
|
+
function fencedBlock(source, line, fence, closed) {
|
|
2987
2504
|
let infoStart = fence.offset + fence.length;
|
|
2988
|
-
while (infoStart <
|
|
2505
|
+
while (infoStart < line.end) {
|
|
2989
2506
|
const code = source.charCodeAt(infoStart);
|
|
2990
2507
|
if (code !== 32 && code !== 9) break;
|
|
2991
2508
|
infoStart++;
|
|
2992
2509
|
}
|
|
2993
2510
|
return {
|
|
2994
2511
|
closed,
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
indent: fence.offset,
|
|
2998
|
-
info: source.slice(infoStart, openingEnd)
|
|
2512
|
+
indent: fence.indent,
|
|
2513
|
+
info: source.slice(infoStart, line.end)
|
|
2999
2514
|
};
|
|
3000
2515
|
}
|
|
3001
2516
|
function fencedBlockContent(source, block, indentation = "spaces") {
|
|
3002
|
-
|
|
3003
|
-
|
|
2517
|
+
let contentStart = 0;
|
|
2518
|
+
while (contentStart < source.length && source[contentStart] !== "\n" && source[contentStart] !== "\r") contentStart++;
|
|
2519
|
+
if (source[contentStart] === "\r") contentStart += source[contentStart + 1] === "\n" ? 2 : 1;
|
|
2520
|
+
else if (source[contentStart] === "\n") contentStart++;
|
|
2521
|
+
let contentEnd = source.length;
|
|
2522
|
+
if (block.closed) {
|
|
2523
|
+
contentEnd = lineContentEnd(source, contentStart, contentEnd);
|
|
2524
|
+
while (contentEnd > contentStart && source[contentEnd - 1] !== "\n" && source[contentEnd - 1] !== "\r") contentEnd--;
|
|
2525
|
+
}
|
|
2526
|
+
const end = lineContentEnd(source, contentStart, contentEnd);
|
|
2527
|
+
if (!block.indent) return source.slice(contentStart, end);
|
|
3004
2528
|
const chunks = [];
|
|
3005
|
-
let lineStart =
|
|
2529
|
+
let lineStart = contentStart;
|
|
3006
2530
|
while (lineStart < end) {
|
|
3007
2531
|
const lf = source.indexOf("\n", lineStart);
|
|
3008
2532
|
const cr = source.indexOf("\r", lineStart);
|
|
@@ -3022,37 +2546,74 @@ function fencedBlockContent(source, block, indentation = "spaces") {
|
|
|
3022
2546
|
//#endregion
|
|
3023
2547
|
//#region src/profile/features/text.ts
|
|
3024
2548
|
const semanticCharacter = /\\([!"#$%&'()*+,./:;<=>?@[\\\]^_`{|}~-])|&(?:#x[\da-f]{1,6}|#\d{1,7}|[a-z][\da-z]{1,31});/gi;
|
|
2549
|
+
const entity = /&(?:#x[0-9A-F]{1,6}|#\d{1,7}|[A-Z][A-Z0-9]{0,30});/iy;
|
|
2550
|
+
function isAsciiPunctuation(code) {
|
|
2551
|
+
return code >= 33 && code <= 47 || code >= 58 && code <= 64 || code >= 91 && code <= 96 || code >= 123 && code <= 126;
|
|
2552
|
+
}
|
|
3025
2553
|
function semanticText(value) {
|
|
3026
2554
|
if (!value.includes("\\") && !value.includes("&")) return value;
|
|
3027
2555
|
return value.replace(semanticCharacter, (match, escaped) => escaped ?? decodeHTMLStrict(match));
|
|
3028
2556
|
}
|
|
3029
|
-
const buildInlineText = (tokenIndex, sourceSpan,
|
|
3030
|
-
const { context } = accumulator;
|
|
2557
|
+
const buildInlineText = (tokenIndex, sourceSpan, context) => {
|
|
3031
2558
|
const text = inlineTokenText(context.view.text, context.tokens, tokenIndex);
|
|
3032
|
-
|
|
2559
|
+
return {
|
|
3033
2560
|
type: "text",
|
|
3034
2561
|
value: inlineTokenFlags(context.tokens, tokenIndex) & 16 ? semanticText(text) : text,
|
|
3035
2562
|
position: sourceSpan
|
|
3036
|
-
}
|
|
3037
|
-
return true;
|
|
2563
|
+
};
|
|
3038
2564
|
};
|
|
3039
|
-
const feature$13 = { inline: {
|
|
3040
|
-
{
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
2565
|
+
const feature$13 = { inline: {
|
|
2566
|
+
lexical: [{
|
|
2567
|
+
marker: 38,
|
|
2568
|
+
scan(source, start, tokens) {
|
|
2569
|
+
const matchEnd = matchInlinePatternEnd(entity, source, start);
|
|
2570
|
+
const end = matchEnd < 0 ? start + 1 : matchEnd;
|
|
2571
|
+
appendInlineToken(tokens, matchEnd < 0 ? 41 : 6, start, end, matchEnd < 0 ? 0 : 16);
|
|
2572
|
+
return end;
|
|
2573
|
+
}
|
|
2574
|
+
}, {
|
|
2575
|
+
marker: 92,
|
|
2576
|
+
scan(source, start, tokens) {
|
|
2577
|
+
const next = source.charCodeAt(start + 1);
|
|
2578
|
+
let end = start + 1;
|
|
2579
|
+
let flags = 0;
|
|
2580
|
+
let kind = 41;
|
|
2581
|
+
if (next === 10 || next === 13) kind = 7;
|
|
2582
|
+
else if (isAsciiPunctuation(next)) {
|
|
2583
|
+
end++;
|
|
2584
|
+
flags = 16;
|
|
2585
|
+
kind = 8;
|
|
2586
|
+
} else if (next === 32 || next === 9) {
|
|
2587
|
+
end++;
|
|
2588
|
+
kind = 9;
|
|
2589
|
+
}
|
|
2590
|
+
appendInlineToken(tokens, kind, start, end, flags);
|
|
2591
|
+
return end;
|
|
2592
|
+
}
|
|
2593
|
+
}],
|
|
2594
|
+
syntax: [
|
|
2595
|
+
{
|
|
2596
|
+
kind: "leaf",
|
|
2597
|
+
token: 9,
|
|
2598
|
+
build: buildInlineText
|
|
2599
|
+
},
|
|
2600
|
+
{
|
|
2601
|
+
kind: "leaf",
|
|
2602
|
+
token: 41,
|
|
2603
|
+
build: buildInlineText
|
|
2604
|
+
},
|
|
2605
|
+
{
|
|
2606
|
+
kind: "leaf",
|
|
2607
|
+
token: 8,
|
|
2608
|
+
build: buildInlineText
|
|
2609
|
+
},
|
|
2610
|
+
{
|
|
2611
|
+
kind: "leaf",
|
|
2612
|
+
token: 6,
|
|
2613
|
+
build: buildInlineText
|
|
2614
|
+
}
|
|
2615
|
+
]
|
|
2616
|
+
} };
|
|
3056
2617
|
//#endregion
|
|
3057
2618
|
//#region src/profile/features/code.ts
|
|
3058
2619
|
const codeFenceRule = {
|
|
@@ -3063,29 +2624,12 @@ const codeFenceRule = {
|
|
|
3063
2624
|
function codeFenceAt(source, line) {
|
|
3064
2625
|
return fenceAt$1(source, line, codeFenceRule);
|
|
3065
2626
|
}
|
|
3066
|
-
function
|
|
3067
|
-
const
|
|
3068
|
-
|
|
3069
|
-
let result = normalizeLines(value.slice(markerLength, -markerLength));
|
|
3070
|
-
if (/^[ \n]/.test(result) && /[ \n]$/.test(result) && /[^ \n]/.test(result)) result = result.slice(1, -1);
|
|
3071
|
-
return result;
|
|
3072
|
-
}
|
|
3073
|
-
const buildInlineCode = (tokenIndex, sourceSpan, accumulator) => {
|
|
3074
|
-
const { context } = accumulator;
|
|
3075
|
-
const value = codeSpanValue(inlineTokenText(context.view.text, context.tokens, tokenIndex));
|
|
3076
|
-
appendInline(accumulator, {
|
|
3077
|
-
type: "inlineCode",
|
|
3078
|
-
value: context.blockRule === "TableCell" ? value.replace(/\\\|/g, "|") : value,
|
|
3079
|
-
position: sourceSpan
|
|
3080
|
-
});
|
|
3081
|
-
return true;
|
|
3082
|
-
};
|
|
3083
|
-
function indentedCodeEnd(nodeId, tokenBase, context) {
|
|
3084
|
-
const token = blockToken(nodeId, tokenBase, 20, context);
|
|
3085
|
-
const count = context.arena.tokens.rangeCount(token);
|
|
2627
|
+
function indentedCodeEnd(tokenStart, context) {
|
|
2628
|
+
const token = blockToken(tokenStart, 20, context);
|
|
2629
|
+
const count = context.structure.tokens.rangeCount(token);
|
|
3086
2630
|
for (let index = count - 1; index >= 0; index--) {
|
|
3087
|
-
const start = context.
|
|
3088
|
-
const rangeEnd = context.
|
|
2631
|
+
const start = context.structure.tokens.rangeStart(token, index);
|
|
2632
|
+
const rangeEnd = context.structure.tokens.rangeEnd(token, index);
|
|
3089
2633
|
if (/[^\r\n]/.test(context.source.slice(start, rangeEnd))) {
|
|
3090
2634
|
let end = rangeEnd;
|
|
3091
2635
|
while (end > start && /[\r\n]/.test(context.source[end - 1])) end--;
|
|
@@ -3109,10 +2653,13 @@ const feature$12 = {
|
|
|
3109
2653
|
kind: "leaf",
|
|
3110
2654
|
token: 19
|
|
3111
2655
|
},
|
|
3112
|
-
build(
|
|
3113
|
-
const
|
|
3114
|
-
const
|
|
3115
|
-
const
|
|
2656
|
+
build(tokenStart, context) {
|
|
2657
|
+
const offset = context.structure.tokens.start(tokenStart);
|
|
2658
|
+
const end = offset + context.structure.lenOf(tokenStart);
|
|
2659
|
+
const token = blockToken(tokenStart, 19, context);
|
|
2660
|
+
const source = normalizeLines(context.structure.tokens.text(context.source, token));
|
|
2661
|
+
const block = context.structure.tokens.value(token);
|
|
2662
|
+
if (!block) throw new Error("FencedCodeBlock token has no fence metadata");
|
|
3116
2663
|
const rawInfo = semanticText(block.info);
|
|
3117
2664
|
const langEnd = rawInfo.search(/[ \t]/);
|
|
3118
2665
|
const lang = rawInfo ? langEnd < 0 ? rawInfo : rawInfo.slice(0, langEnd) : null;
|
|
@@ -3124,7 +2671,7 @@ const feature$12 = {
|
|
|
3124
2671
|
value: fencedBlockContent(source, block),
|
|
3125
2672
|
position: {
|
|
3126
2673
|
start: firstNonspace(context.source, offset, lineEnd(context.source, offset)),
|
|
3127
|
-
end: block.closed || end < context.source.length ? blockEnd(
|
|
2674
|
+
end: block.closed || end < context.source.length ? blockEnd(tokenStart, context) : end
|
|
3128
2675
|
}
|
|
3129
2676
|
};
|
|
3130
2677
|
}
|
|
@@ -3134,9 +2681,10 @@ const feature$12 = {
|
|
|
3134
2681
|
kind: "leaf",
|
|
3135
2682
|
token: 20
|
|
3136
2683
|
},
|
|
3137
|
-
build(
|
|
3138
|
-
const
|
|
3139
|
-
const
|
|
2684
|
+
build(tokenStart, context) {
|
|
2685
|
+
const offset = context.structure.tokens.start(tokenStart);
|
|
2686
|
+
const token = blockToken(tokenStart, 20, context);
|
|
2687
|
+
const lines = normalizeLines(context.structure.tokens.text(context.source, token)).split("\n").map((line) => removeIndent(line, 4));
|
|
3140
2688
|
while (lines.length && /^[ \t]*$/.test(lines[lines.length - 1])) lines.pop();
|
|
3141
2689
|
return {
|
|
3142
2690
|
type: "code",
|
|
@@ -3145,7 +2693,7 @@ const feature$12 = {
|
|
|
3145
2693
|
value: lines.join("\n"),
|
|
3146
2694
|
position: {
|
|
3147
2695
|
start: offset,
|
|
3148
|
-
end: indentedCodeEnd(
|
|
2696
|
+
end: indentedCodeEnd(tokenStart, context)
|
|
3149
2697
|
}
|
|
3150
2698
|
};
|
|
3151
2699
|
}
|
|
@@ -3160,19 +2708,216 @@ const feature$12 = {
|
|
|
3160
2708
|
if (!fence) return;
|
|
3161
2709
|
let end = start + 1;
|
|
3162
2710
|
while (end < lines.length && !closesFence(source, lines[end], fence)) end++;
|
|
2711
|
+
const closed = end < lines.length;
|
|
3163
2712
|
if (end < lines.length) end++;
|
|
3164
|
-
appendLogicalToken(out, 19, source, lines, start, end);
|
|
2713
|
+
appendLogicalToken(out, 19, source, lines, start, end, fencedBlock(source, lines[start], fence, closed));
|
|
3165
2714
|
return end;
|
|
3166
2715
|
}
|
|
3167
2716
|
}]
|
|
3168
2717
|
},
|
|
3169
|
-
inline: {
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
2718
|
+
inline: {
|
|
2719
|
+
lexical: [{
|
|
2720
|
+
marker: 96,
|
|
2721
|
+
scan(source, start, tokens) {
|
|
2722
|
+
let end = -1;
|
|
2723
|
+
if (source.charCodeAt(start - 1) !== 96) {
|
|
2724
|
+
const openEnd = inlineMarkerRunEnd(source, start);
|
|
2725
|
+
const markerLength = openEnd - start;
|
|
2726
|
+
let offset = openEnd;
|
|
2727
|
+
while (offset < source.length) {
|
|
2728
|
+
if (source.charCodeAt(offset) !== 96) {
|
|
2729
|
+
offset++;
|
|
2730
|
+
continue;
|
|
2731
|
+
}
|
|
2732
|
+
const closeEnd = inlineMarkerRunEnd(source, offset);
|
|
2733
|
+
if (closeEnd - offset === markerLength) {
|
|
2734
|
+
end = closeEnd;
|
|
2735
|
+
break;
|
|
2736
|
+
}
|
|
2737
|
+
offset = closeEnd;
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
if (end < 0) end = start + 1;
|
|
2741
|
+
appendInlineToken(tokens, end === start + 1 ? 41 : 2, start, end);
|
|
2742
|
+
return end;
|
|
2743
|
+
}
|
|
2744
|
+
}],
|
|
2745
|
+
syntax: [{
|
|
2746
|
+
kind: "leaf",
|
|
2747
|
+
token: 2,
|
|
2748
|
+
build: (tokenIndex, sourceSpan, context) => {
|
|
2749
|
+
const text = inlineTokenText(context.view.text, context.tokens, tokenIndex);
|
|
2750
|
+
const markerLength = /^`+/.exec(text)?.[0].length;
|
|
2751
|
+
if (!markerLength) throw new Error("CodeSpan token does not start with a backtick run");
|
|
2752
|
+
let value = normalizeLines(text.slice(markerLength, -markerLength));
|
|
2753
|
+
if (/^[ \n]/.test(value) && /[ \n]$/.test(value) && /[^ \n]/.test(value)) value = value.slice(1, -1);
|
|
2754
|
+
return {
|
|
2755
|
+
type: "inlineCode",
|
|
2756
|
+
value: context.blockRule === "TableCell" ? value.replace(/\\\|/g, "|") : value,
|
|
2757
|
+
position: sourceSpan
|
|
2758
|
+
};
|
|
2759
|
+
}
|
|
2760
|
+
}]
|
|
2761
|
+
}
|
|
3174
2762
|
};
|
|
3175
2763
|
//#endregion
|
|
2764
|
+
//#region src/fragment/inline.ts
|
|
2765
|
+
function lineStart(source, offset) {
|
|
2766
|
+
while (offset > 0) {
|
|
2767
|
+
const character = source.charCodeAt(--offset);
|
|
2768
|
+
if (character === 10 || character === 13) return offset + 1;
|
|
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;
|
|
2776
|
+
}
|
|
2777
|
+
function appendText(target, value, start, end) {
|
|
2778
|
+
if (!value) return;
|
|
2779
|
+
const previous = target.at(-1);
|
|
2780
|
+
if (previous?.type === "text" && !("attributes" in previous)) {
|
|
2781
|
+
previous.value += value;
|
|
2782
|
+
extendSpan(previous, end);
|
|
2783
|
+
} else target.push({
|
|
2784
|
+
type: "text",
|
|
2785
|
+
value,
|
|
2786
|
+
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;
|
|
2879
|
+
}
|
|
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
|
+
};
|
|
2908
|
+
const result = [];
|
|
2909
|
+
appendInlineRange(0, inlineTokenCount(region.tokens), inlineContext, result);
|
|
2910
|
+
const last = result.at(-1);
|
|
2911
|
+
if (last?.type === "text") {
|
|
2912
|
+
const end = trailingWhitespaceStart(last.value);
|
|
2913
|
+
const removed = last.value.length - end;
|
|
2914
|
+
last.value = last.value.slice(0, end);
|
|
2915
|
+
last.position.end -= removed;
|
|
2916
|
+
if (!last.value) result.pop();
|
|
2917
|
+
}
|
|
2918
|
+
return result;
|
|
2919
|
+
}
|
|
2920
|
+
//#endregion
|
|
3176
2921
|
//#region src/profile/features/component/block.ts
|
|
3177
2922
|
function skipSpaces(source, offset, end) {
|
|
3178
2923
|
while (offset < end && (source[offset] === " " || source[offset] === " ")) offset++;
|
|
@@ -3355,31 +3100,24 @@ function emitOpening(source, contentOffset, opening, out) {
|
|
|
3355
3100
|
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(43, opening.attributesStart, opening.attributesEnd);
|
|
3356
3101
|
}
|
|
3357
3102
|
function parseYamlAttributes(token, context) {
|
|
3358
|
-
const value = parse(context.
|
|
3103
|
+
const value = parse(context.structure.tokens.text(context.source, token), { schema: "core" });
|
|
3359
3104
|
if (value === null || value === void 0) return {};
|
|
3360
3105
|
if (typeof value !== "object" || Array.isArray(value)) throw new TypeError("Component YAML props must be a mapping");
|
|
3361
3106
|
return value;
|
|
3362
3107
|
}
|
|
3363
|
-
function directRule(
|
|
3364
|
-
const
|
|
3365
|
-
for (let
|
|
3366
|
-
const child = arena.childAt(nodeId, index);
|
|
3367
|
-
if (child >= 0 && arena.ruleNameOf(child) === rule) return {
|
|
3368
|
-
id: child,
|
|
3369
|
-
offset: offset + arena.childRelAt(nodeId, index),
|
|
3370
|
-
tokenBase: tokenBase + arena.childTokRelAt(nodeId, index)
|
|
3371
|
-
};
|
|
3372
|
-
}
|
|
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;
|
|
3373
3111
|
}
|
|
3374
|
-
const buildBlockLabel = (
|
|
3375
|
-
const open = blockToken(
|
|
3376
|
-
const close = blockToken(
|
|
3112
|
+
const buildBlockLabel = (tokenStart, context) => {
|
|
3113
|
+
const open = blockToken(tokenStart, 41, context);
|
|
3114
|
+
const close = blockToken(tokenStart, 42, context);
|
|
3377
3115
|
return {
|
|
3378
3116
|
type: "paragraph",
|
|
3379
|
-
children: buildInlineChildren(
|
|
3117
|
+
children: buildInlineChildren(tokenStart, context, true),
|
|
3380
3118
|
position: {
|
|
3381
|
-
start: context.
|
|
3382
|
-
end: context.
|
|
3119
|
+
start: context.structure.tokens.start(open),
|
|
3120
|
+
end: context.structure.tokens.end(close)
|
|
3383
3121
|
}
|
|
3384
3122
|
};
|
|
3385
3123
|
};
|
|
@@ -3418,17 +3156,17 @@ const blockRules$2 = [
|
|
|
3418
3156
|
open: 39,
|
|
3419
3157
|
close: 40
|
|
3420
3158
|
},
|
|
3421
|
-
build(
|
|
3422
|
-
const open = blockToken(
|
|
3423
|
-
const close = blockToken(
|
|
3424
|
-
const attributesToken = directBlockToken(
|
|
3425
|
-
const parsed = attributesToken !== void 0 ? parseAttributes(context.source, context.
|
|
3426
|
-
const yamlToken = directBlockToken(
|
|
3427
|
-
const label = directRule(
|
|
3159
|
+
build(tokenStart, context) {
|
|
3160
|
+
const open = blockToken(tokenStart, 39, context);
|
|
3161
|
+
const close = blockToken(tokenStart, 40, context);
|
|
3162
|
+
const attributesToken = directBlockToken(tokenStart, 43, context);
|
|
3163
|
+
const parsed = attributesToken !== void 0 ? parseAttributes(context.source, context.structure.tokens.start(attributesToken)) : void 0;
|
|
3164
|
+
const yamlToken = directBlockToken(tokenStart, 44, context);
|
|
3165
|
+
const label = directRule(tokenStart, "BlockComponentLabel", context);
|
|
3428
3166
|
const children = [];
|
|
3429
|
-
if (label) children.push(buildBlockLabel(label
|
|
3430
|
-
children.push(...buildBlockChildren(
|
|
3431
|
-
const opening = context.
|
|
3167
|
+
if (label) children.push(buildBlockLabel(label, context));
|
|
3168
|
+
children.push(...buildBlockChildren(tokenStart, context));
|
|
3169
|
+
const opening = context.structure.tokens.text(context.source, open);
|
|
3432
3170
|
return {
|
|
3433
3171
|
type: "blockComponent",
|
|
3434
3172
|
name: normalizeComponentName(opening.slice(opening.lastIndexOf(":") + 1).trim()),
|
|
@@ -3437,8 +3175,8 @@ const blockRules$2 = [
|
|
|
3437
3175
|
...parsed?.attributes
|
|
3438
3176
|
} : parsed?.attributes ?? {},
|
|
3439
3177
|
position: {
|
|
3440
|
-
start: context.
|
|
3441
|
-
end: context.
|
|
3178
|
+
start: context.structure.tokens.start(open),
|
|
3179
|
+
end: context.structure.tokens.end(close)
|
|
3442
3180
|
},
|
|
3443
3181
|
children
|
|
3444
3182
|
};
|
|
@@ -3451,23 +3189,23 @@ const blockRules$2 = [
|
|
|
3451
3189
|
open: 45,
|
|
3452
3190
|
close: 46
|
|
3453
3191
|
},
|
|
3454
|
-
build(
|
|
3455
|
-
const open = blockToken(
|
|
3456
|
-
const close = blockToken(
|
|
3457
|
-
const attributesToken = directBlockToken(
|
|
3458
|
-
const parsed = attributesToken !== void 0 ? parseAttributes(context.source, context.
|
|
3459
|
-
const children = buildBlockChildren(
|
|
3192
|
+
build(tokenStart, context) {
|
|
3193
|
+
const open = blockToken(tokenStart, 45, context);
|
|
3194
|
+
const close = blockToken(tokenStart, 46, context);
|
|
3195
|
+
const attributesToken = directBlockToken(tokenStart, 43, context);
|
|
3196
|
+
const parsed = attributesToken !== void 0 ? parseAttributes(context.source, context.structure.tokens.start(attributesToken)) : void 0;
|
|
3197
|
+
const children = buildBlockChildren(tokenStart, context);
|
|
3460
3198
|
return {
|
|
3461
3199
|
type: "blockComponent",
|
|
3462
3200
|
name: "template",
|
|
3463
3201
|
attributes: {
|
|
3464
3202
|
...parsed?.attributes,
|
|
3465
|
-
name: normalizeComponentName(context.
|
|
3203
|
+
name: normalizeComponentName(context.structure.tokens.text(context.source, open).slice(1).trim())
|
|
3466
3204
|
},
|
|
3467
3205
|
children,
|
|
3468
3206
|
position: {
|
|
3469
|
-
start: context.
|
|
3470
|
-
end: context.
|
|
3207
|
+
start: context.structure.tokens.start(open),
|
|
3208
|
+
end: context.structure.tokens.end(close)
|
|
3471
3209
|
}
|
|
3472
3210
|
};
|
|
3473
3211
|
}
|
|
@@ -3485,177 +3223,141 @@ const blockStarts$2 = [{
|
|
|
3485
3223
|
}];
|
|
3486
3224
|
//#endregion
|
|
3487
3225
|
//#region src/profile/features/component/inline.ts
|
|
3488
|
-
function
|
|
3489
|
-
const stack = [];
|
|
3490
|
-
const pairs = /* @__PURE__ */ new Map();
|
|
3491
|
-
const linkLabels = [];
|
|
3492
|
-
const normalClosers = /* @__PURE__ */ new Set();
|
|
3493
|
-
const referenceSuffixes = /* @__PURE__ */ new Map();
|
|
3494
|
-
for (let index = 0; index < inlineTokenCount(tokens); index++) {
|
|
3495
|
-
const kind = inlineTokenKind(tokens, index);
|
|
3496
|
-
if (kind === 40) stack.length = 0;
|
|
3497
|
-
else if (kind === 18) stack.push({
|
|
3498
|
-
image: false,
|
|
3499
|
-
start: inlineTokenStart(tokens, index)
|
|
3500
|
-
});
|
|
3501
|
-
else if (kind === 17) stack.push({
|
|
3502
|
-
image: true,
|
|
3503
|
-
start: inlineTokenEnd(tokens, index) - 1
|
|
3504
|
-
});
|
|
3505
|
-
else if (kind === 21 || kind === 19 || kind === 20) {
|
|
3506
|
-
const open = stack.pop();
|
|
3507
|
-
if (open !== void 0) {
|
|
3508
|
-
const close = inlineTokenStart(tokens, index);
|
|
3509
|
-
if (!open.image) {
|
|
3510
|
-
pairs.set(open.start, close);
|
|
3511
|
-
normalClosers.add(close);
|
|
3512
|
-
if (kind === 19 || kind === 20) {
|
|
3513
|
-
let nested = linkLabels.at(-1);
|
|
3514
|
-
while (nested && nested.start > open.start) {
|
|
3515
|
-
linkLabels.pop();
|
|
3516
|
-
nested = linkLabels.at(-1);
|
|
3517
|
-
}
|
|
3518
|
-
linkLabels.push({
|
|
3519
|
-
start: open.start,
|
|
3520
|
-
end: close
|
|
3521
|
-
});
|
|
3522
|
-
}
|
|
3523
|
-
if (kind === 20) referenceSuffixes.set(close, inlineTokenEnd(tokens, index));
|
|
3524
|
-
}
|
|
3525
|
-
}
|
|
3526
|
-
}
|
|
3527
|
-
}
|
|
3528
|
-
return {
|
|
3529
|
-
linkLabels,
|
|
3530
|
-
normalClosers,
|
|
3531
|
-
pairs,
|
|
3532
|
-
referenceSuffixes
|
|
3533
|
-
};
|
|
3534
|
-
}
|
|
3535
|
-
function componentCandidate(source, start, flags, pairs) {
|
|
3226
|
+
function inlineComponentEnd(source, start) {
|
|
3536
3227
|
const previous = source[start - 1];
|
|
3537
3228
|
if (start > 0 && previous !== " " && previous !== " " && previous !== "\n" && previous !== "\r" && previous !== "*" && previous !== "_" && previous !== "[") return;
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
end
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
flags,
|
|
3560
|
-
inLinkLabel: false,
|
|
3561
|
-
kind: "component",
|
|
3562
|
-
nameEnd,
|
|
3563
|
-
start
|
|
3564
|
-
};
|
|
3565
|
-
}
|
|
3566
|
-
function insideLinkLabel(offset, labels) {
|
|
3567
|
-
let start = 0;
|
|
3568
|
-
let end = labels.length;
|
|
3569
|
-
while (start < end) {
|
|
3570
|
-
const middle = start + end >>> 1;
|
|
3571
|
-
if (labels[middle].end <= offset) start = middle + 1;
|
|
3572
|
-
else end = middle;
|
|
3229
|
+
return componentNameEnd(source, start + 1, false);
|
|
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
|
+
}];
|
|
3240
|
+
function appendLinkCandidates(target, candidates) {
|
|
3241
|
+
for (const candidate of candidates) {
|
|
3242
|
+
candidate.inLinkLabel = true;
|
|
3243
|
+
if (candidate.children.length > 0) {
|
|
3244
|
+
const children = [];
|
|
3245
|
+
appendLinkCandidates(children, candidate.children);
|
|
3246
|
+
candidate.children = children;
|
|
3247
|
+
}
|
|
3248
|
+
if (candidate.literalInLink) target.push(...candidate.children);
|
|
3249
|
+
else target.push(candidate);
|
|
3573
3250
|
}
|
|
3574
|
-
const label = labels[start];
|
|
3575
|
-
return label !== void 0 && offset > label.start;
|
|
3576
3251
|
}
|
|
3577
3252
|
function candidates(source, tokens) {
|
|
3578
|
-
const
|
|
3579
|
-
const
|
|
3580
|
-
const
|
|
3581
|
-
let attributeLineEnd = 0;
|
|
3253
|
+
const bracketStack = [];
|
|
3254
|
+
const normalClosers = /* @__PURE__ */ new Set();
|
|
3255
|
+
const roots = [];
|
|
3582
3256
|
for (let index = 0; index < inlineTokenCount(tokens); index++) {
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3257
|
+
const kind = inlineTokenKind(tokens, index);
|
|
3258
|
+
if (kind === 20) {
|
|
3259
|
+
const start = inlineTokenStart(tokens, index);
|
|
3260
|
+
const componentIndex = index - 1;
|
|
3261
|
+
bracketStack.push({
|
|
3262
|
+
children: [],
|
|
3263
|
+
componentIndex: componentIndex >= 0 && inlineTokenKind(tokens, componentIndex) === 35 && inlineTokenEnd(tokens, componentIndex) === start ? componentIndex : -1,
|
|
3264
|
+
image: false,
|
|
3265
|
+
start,
|
|
3266
|
+
tokenIndex: index
|
|
3267
|
+
});
|
|
3268
|
+
continue;
|
|
3269
|
+
}
|
|
3270
|
+
if (kind === 19) {
|
|
3271
|
+
bracketStack.push({
|
|
3272
|
+
children: [],
|
|
3273
|
+
componentIndex: -1,
|
|
3274
|
+
image: true,
|
|
3275
|
+
start: inlineTokenEnd(tokens, index) - 1,
|
|
3276
|
+
tokenIndex: index
|
|
3277
|
+
});
|
|
3278
|
+
continue;
|
|
3279
|
+
}
|
|
3280
|
+
if (kind !== 23 && kind !== 21 && kind !== 22) continue;
|
|
3281
|
+
const open = bracketStack.pop();
|
|
3282
|
+
if (!open) continue;
|
|
3283
|
+
const parent = bracketStack.at(-1)?.children ?? roots;
|
|
3284
|
+
if (open.image) {
|
|
3285
|
+
parent.push(...open.children);
|
|
3286
|
+
continue;
|
|
3287
|
+
}
|
|
3288
|
+
const close = inlineTokenStart(tokens, index);
|
|
3289
|
+
normalClosers.add(close);
|
|
3290
|
+
let children = open.children;
|
|
3291
|
+
if (kind === 21 || kind === 22) {
|
|
3292
|
+
children = [];
|
|
3293
|
+
appendLinkCandidates(children, open.children);
|
|
3294
|
+
}
|
|
3295
|
+
if (open.componentIndex >= 0) {
|
|
3296
|
+
const start = inlineTokenStart(tokens, open.componentIndex);
|
|
3297
|
+
const flags = inlineTokenFlags(tokens, open.componentIndex);
|
|
3298
|
+
parent.push({
|
|
3299
|
+
children,
|
|
3300
|
+
close,
|
|
3301
|
+
contentEnd: close,
|
|
3302
|
+
contentStart: open.start + 1,
|
|
3303
|
+
end: close + 1,
|
|
3304
|
+
flags,
|
|
3305
|
+
inLinkLabel: false,
|
|
3306
|
+
kind: "component",
|
|
3307
|
+
literalInLink: false,
|
|
3308
|
+
nameEnd: open.start,
|
|
3309
|
+
start
|
|
3310
|
+
});
|
|
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
|
+
});
|
|
3612
3328
|
}
|
|
3329
|
+
continue;
|
|
3330
|
+
}
|
|
3331
|
+
if (source[close + 1] === "(" || source[close + 1] === "[") {
|
|
3332
|
+
parent.push(...children);
|
|
3333
|
+
continue;
|
|
3613
3334
|
}
|
|
3614
|
-
}
|
|
3615
|
-
for (let index = 0; index < inlineTokenCount(tokens); index++) {
|
|
3616
|
-
if (inlineTokenKind(tokens, index) !== 18) continue;
|
|
3617
|
-
const start = inlineTokenStart(tokens, index);
|
|
3618
|
-
if (componentLabels.has(start)) continue;
|
|
3619
|
-
const close = brackets.pairs.get(start);
|
|
3620
|
-
if (close === void 0 || source[close + 1] === "(" || source[close + 1] === "[") continue;
|
|
3621
3335
|
const attributesStart = close + 1;
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
attributed = attributesEnd(source, attributesStart, attributeLineEnd) !== void 0;
|
|
3626
|
-
}
|
|
3627
|
-
const inLinkLabel = insideLinkLabel(start, brackets.linkLabels);
|
|
3628
|
-
if (!attributed && inLinkLabel) continue;
|
|
3629
|
-
result.push({
|
|
3630
|
-
children: [],
|
|
3336
|
+
const attributed = source[attributesStart] === "{" && attributesEnd(source, attributesStart) !== void 0;
|
|
3337
|
+
parent.push({
|
|
3338
|
+
children,
|
|
3631
3339
|
close,
|
|
3632
3340
|
contentEnd: close,
|
|
3633
|
-
contentStart: start + 1,
|
|
3341
|
+
contentStart: open.start + 1,
|
|
3634
3342
|
end: close + 1,
|
|
3635
|
-
flags: inlineTokenFlags(tokens,
|
|
3636
|
-
inLinkLabel,
|
|
3343
|
+
flags: inlineTokenFlags(tokens, open.tokenIndex),
|
|
3344
|
+
inLinkLabel: false,
|
|
3637
3345
|
kind: "span",
|
|
3638
|
-
|
|
3639
|
-
start
|
|
3346
|
+
literalInLink: !attributed,
|
|
3347
|
+
nameEnd: open.start + 1,
|
|
3348
|
+
start: open.start
|
|
3640
3349
|
});
|
|
3641
3350
|
}
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
for (const candidate of result) {
|
|
3646
|
-
while (stack.length > 0 && candidate.start >= stack.at(-1).end) stack.pop();
|
|
3647
|
-
const parent = stack.at(-1);
|
|
3648
|
-
if (parent && candidate.start >= parent.contentStart && candidate.end <= parent.contentEnd) parent.children.push(candidate);
|
|
3649
|
-
else if (!parent) roots.push(candidate);
|
|
3650
|
-
else continue;
|
|
3651
|
-
if (candidate.end > candidate.start) stack.push(candidate);
|
|
3351
|
+
while (bracketStack.length > 0) {
|
|
3352
|
+
const opening = bracketStack.pop();
|
|
3353
|
+
(bracketStack.at(-1)?.children ?? roots).push(...opening.children);
|
|
3652
3354
|
}
|
|
3653
3355
|
return {
|
|
3654
|
-
normalClosers
|
|
3356
|
+
normalClosers,
|
|
3655
3357
|
roots
|
|
3656
3358
|
};
|
|
3657
3359
|
}
|
|
3658
|
-
function copyRange
|
|
3360
|
+
function copyRange(target, tokens, start, end, inLinkLabel, normalClosers) {
|
|
3659
3361
|
for (let index = firstInlineTokenEndingAfter(tokens, start); index < inlineTokenCount(tokens); index++) {
|
|
3660
3362
|
const tokenStart = inlineTokenStart(tokens, index);
|
|
3661
3363
|
if (tokenStart >= end) break;
|
|
@@ -3663,56 +3365,37 @@ function copyRange$1(target, tokens, start, end, inLinkLabel, normalClosers) {
|
|
|
3663
3365
|
const tokenEnd = inlineTokenEnd(tokens, index);
|
|
3664
3366
|
const fragmentStart = Math.max(start, tokenStart);
|
|
3665
3367
|
const fragmentEnd = Math.min(end, tokenEnd);
|
|
3666
|
-
appendInlineToken(target, inLinkLabel && (kind ===
|
|
3368
|
+
appendInlineToken(target, inLinkLabel && (kind === 20 || normalClosers.has(tokenStart) && (kind === 21 || kind === 22 || kind === 23)) || fragmentStart !== tokenStart || fragmentEnd !== tokenEnd ? 9 : kind, fragmentStart, fragmentEnd, fragmentStart === tokenStart ? inlineTokenFlags(tokens, index) : 0);
|
|
3667
3369
|
}
|
|
3668
3370
|
}
|
|
3669
3371
|
function emitRange(target, tokens, start, end, nested, inLinkLabel, normalClosers) {
|
|
3670
3372
|
let cursor = start;
|
|
3671
3373
|
for (const candidate of nested) {
|
|
3672
|
-
copyRange
|
|
3374
|
+
copyRange(target, tokens, cursor, candidate.start, inLinkLabel, normalClosers);
|
|
3673
3375
|
if (candidate.kind === "component") {
|
|
3674
|
-
appendInlineToken(target,
|
|
3376
|
+
appendInlineToken(target, 35, candidate.start, candidate.nameEnd, candidate.flags);
|
|
3675
3377
|
if (candidate.contentStart < candidate.contentEnd) {
|
|
3676
|
-
appendInlineToken(target,
|
|
3378
|
+
appendInlineToken(target, 36, candidate.nameEnd, candidate.contentStart);
|
|
3677
3379
|
emitRange(target, tokens, candidate.contentStart, candidate.contentEnd, candidate.children, candidate.inLinkLabel, normalClosers);
|
|
3678
|
-
appendInlineToken(target,
|
|
3380
|
+
appendInlineToken(target, 37, candidate.close, candidate.close + 1);
|
|
3679
3381
|
}
|
|
3680
3382
|
} else {
|
|
3681
|
-
appendInlineToken(target,
|
|
3383
|
+
appendInlineToken(target, 39, candidate.start, candidate.contentStart, candidate.flags);
|
|
3682
3384
|
emitRange(target, tokens, candidate.contentStart, candidate.contentEnd, candidate.children, candidate.inLinkLabel, normalClosers);
|
|
3683
|
-
appendInlineToken(target,
|
|
3385
|
+
appendInlineToken(target, 40, candidate.close, candidate.close + 1);
|
|
3684
3386
|
}
|
|
3685
3387
|
cursor = candidate.end;
|
|
3686
3388
|
}
|
|
3687
|
-
copyRange
|
|
3389
|
+
copyRange(target, tokens, cursor, end, inLinkLabel, normalClosers);
|
|
3688
3390
|
}
|
|
3689
|
-
function
|
|
3690
|
-
if (!source.includes("
|
|
3391
|
+
function rewriteComponentTokens(source, tokens) {
|
|
3392
|
+
if (!source.includes("[")) return tokens;
|
|
3691
3393
|
const syntax = candidates(source, tokens);
|
|
3692
3394
|
if (syntax.roots.length === 0) return tokens;
|
|
3693
3395
|
const result = [];
|
|
3694
3396
|
emitRange(result, tokens, 0, source.length, syntax.roots, false, syntax.normalClosers);
|
|
3695
3397
|
return result;
|
|
3696
3398
|
}
|
|
3697
|
-
const buildInlineComponent = (open, close, children, sourceSpan, accumulator) => {
|
|
3698
|
-
const { context } = accumulator;
|
|
3699
|
-
appendInline(accumulator, {
|
|
3700
|
-
type: "inlineComponent",
|
|
3701
|
-
name: normalizeComponentName(context.view.text.slice(inlineTokenStart(context.tokens, open) + 1, inlineTokenEnd(context.tokens, open))),
|
|
3702
|
-
attributes: {},
|
|
3703
|
-
children,
|
|
3704
|
-
position: sourceSpan
|
|
3705
|
-
});
|
|
3706
|
-
};
|
|
3707
|
-
const buildInlineSpan = (open, close, children, sourceSpan, accumulator) => {
|
|
3708
|
-
appendInline(accumulator, {
|
|
3709
|
-
type: "inlineComponent",
|
|
3710
|
-
name: "span",
|
|
3711
|
-
attributes: {},
|
|
3712
|
-
children,
|
|
3713
|
-
position: sourceSpan
|
|
3714
|
-
});
|
|
3715
|
-
};
|
|
3716
3399
|
//#endregion
|
|
3717
3400
|
//#region src/profile/features/component/index.ts
|
|
3718
3401
|
const feature$11 = {
|
|
@@ -3721,30 +3404,38 @@ const feature$11 = {
|
|
|
3721
3404
|
starts: blockStarts$2
|
|
3722
3405
|
},
|
|
3723
3406
|
inline: {
|
|
3407
|
+
lexical: inlineLexical,
|
|
3408
|
+
rewrite: rewriteComponentTokens,
|
|
3724
3409
|
syntax: [{
|
|
3725
3410
|
kind: "container",
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3411
|
+
isolateDelimiters: true,
|
|
3412
|
+
token: 35,
|
|
3413
|
+
contentOpen: 36,
|
|
3414
|
+
close: 37,
|
|
3415
|
+
build(open, close, sourceSpan, children, context) {
|
|
3416
|
+
return {
|
|
3417
|
+
type: "inlineComponent",
|
|
3418
|
+
name: normalizeComponentName(context.view.text.slice(inlineTokenStart(context.tokens, open) + 1, inlineTokenEnd(context.tokens, open))),
|
|
3419
|
+
attributes: {},
|
|
3420
|
+
children,
|
|
3421
|
+
position: sourceSpan
|
|
3422
|
+
};
|
|
3423
|
+
}
|
|
3730
3424
|
}, {
|
|
3731
3425
|
kind: "pair",
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
isolateDelimiters: true
|
|
3746
|
-
}]
|
|
3747
|
-
}
|
|
3426
|
+
isolateDelimiters: true,
|
|
3427
|
+
open: 39,
|
|
3428
|
+
close: 40,
|
|
3429
|
+
build(open, close, sourceSpan, children) {
|
|
3430
|
+
return {
|
|
3431
|
+
type: "inlineComponent",
|
|
3432
|
+
name: "span",
|
|
3433
|
+
attributes: {},
|
|
3434
|
+
children,
|
|
3435
|
+
position: sourceSpan
|
|
3436
|
+
};
|
|
3437
|
+
}
|
|
3438
|
+
}]
|
|
3748
3439
|
}
|
|
3749
3440
|
};
|
|
3750
3441
|
//#endregion
|
|
@@ -3758,10 +3449,10 @@ function splitReferenceTail(tokens, index) {
|
|
|
3758
3449
|
const flags = inlineTokenFlags(tokens, index);
|
|
3759
3450
|
const decodeFlags = flags & 16;
|
|
3760
3451
|
const result = [];
|
|
3761
|
-
appendInlineToken(result,
|
|
3762
|
-
appendInlineToken(result,
|
|
3452
|
+
appendInlineToken(result, 24, start, start + 1, flags & -17);
|
|
3453
|
+
appendInlineToken(result, 20, start + 1, start + 2);
|
|
3763
3454
|
if (end > start + 3) appendInlineToken(result, 9, start + 2, end - 1, decodeFlags);
|
|
3764
|
-
appendInlineToken(result,
|
|
3455
|
+
appendInlineToken(result, 23, end - 1, end);
|
|
3765
3456
|
return result;
|
|
3766
3457
|
}
|
|
3767
3458
|
//#endregion
|
|
@@ -3834,17 +3525,17 @@ const blockRules$1 = [{
|
|
|
3834
3525
|
open: 24,
|
|
3835
3526
|
close: 25
|
|
3836
3527
|
},
|
|
3837
|
-
build(
|
|
3838
|
-
const token = blockToken(
|
|
3839
|
-
const fields = definitionFields(context.
|
|
3528
|
+
build(tokenStart, context) {
|
|
3529
|
+
const token = blockToken(tokenStart, 24, context);
|
|
3530
|
+
const fields = definitionFields(context.structure.tokens, token);
|
|
3840
3531
|
return {
|
|
3841
3532
|
type: "footnoteDefinition",
|
|
3842
3533
|
identifier: fields.normalizedLabel.toLowerCase(),
|
|
3843
3534
|
label: semanticText(fields.label),
|
|
3844
|
-
children: buildBlockChildren(
|
|
3535
|
+
children: buildBlockChildren(tokenStart, context),
|
|
3845
3536
|
position: {
|
|
3846
|
-
start: context.
|
|
3847
|
-
end: blockEnd(
|
|
3537
|
+
start: context.structure.tokens.start(token),
|
|
3538
|
+
end: blockEnd(tokenStart, context)
|
|
3848
3539
|
}
|
|
3849
3540
|
};
|
|
3850
3541
|
},
|
|
@@ -3911,62 +3602,50 @@ const blockStarts$1 = [{
|
|
|
3911
3602
|
function closerIndex(tokens, start, end) {
|
|
3912
3603
|
for (let index = start + 1; index < inlineTokenCount(tokens); index++) {
|
|
3913
3604
|
if (inlineTokenStart(tokens, index) >= end) break;
|
|
3914
|
-
|
|
3605
|
+
const kind = inlineTokenKind(tokens, index);
|
|
3606
|
+
if (inlineTokenEnd(tokens, index) === end && (kind === 23 || kind === 24) || kind === 22 && inlineTokenStart(tokens, index) + 1 === end) return index;
|
|
3915
3607
|
}
|
|
3916
3608
|
return -1;
|
|
3917
3609
|
}
|
|
3918
|
-
const
|
|
3919
|
-
let activeFootnoteEnd = -1;
|
|
3920
|
-
let result;
|
|
3921
|
-
for (let index = 0; index < inlineTokenCount(tokens); index++) {
|
|
3922
|
-
const kind = inlineTokenKind(tokens, index);
|
|
3923
|
-
const start = inlineTokenStart(tokens, index);
|
|
3924
|
-
if (start >= activeFootnoteEnd) activeFootnoteEnd = -1;
|
|
3925
|
-
if (kind === 18 || kind === 17) {
|
|
3926
|
-
const label = footnoteLabelAt(source, kind === 17 ? start + 1 : start, source.length);
|
|
3927
|
-
activeFootnoteEnd = label && context.hasDefinition(label.definitionKey) ? label.end : -1;
|
|
3928
|
-
}
|
|
3929
|
-
if (kind !== 20) {
|
|
3930
|
-
if (result) copyInlineToken(result, tokens, index);
|
|
3931
|
-
continue;
|
|
3932
|
-
}
|
|
3933
|
-
const embedded = footnoteLabelAt(source, start + 1, inlineTokenEnd(tokens, index));
|
|
3934
|
-
if (activeFootnoteEnd !== start + 1 && (!embedded || !context.hasDefinition(embedded.definitionKey))) {
|
|
3935
|
-
if (result) copyInlineToken(result, tokens, index);
|
|
3936
|
-
continue;
|
|
3937
|
-
}
|
|
3938
|
-
if (!result) {
|
|
3939
|
-
result = [];
|
|
3940
|
-
for (let prefix = 0; prefix < index; prefix++) copyInlineToken(result, tokens, prefix);
|
|
3941
|
-
}
|
|
3942
|
-
result.push(...splitReferenceTail(tokens, index));
|
|
3943
|
-
activeFootnoteEnd = -1;
|
|
3944
|
-
}
|
|
3945
|
-
return result ?? tokens;
|
|
3946
|
-
};
|
|
3947
|
-
const activateFootnoteReferences = (source, tokens, context) => {
|
|
3610
|
+
const rewriteFootnoteTokens = (source, tokens, context) => {
|
|
3948
3611
|
let result;
|
|
3949
3612
|
for (let index = 0; index < inlineTokenCount(tokens); index++) {
|
|
3950
3613
|
const start = inlineTokenStart(tokens, index);
|
|
3951
3614
|
const kind = inlineTokenKind(tokens, index);
|
|
3952
|
-
const labelStart = kind ===
|
|
3953
|
-
const label = kind ===
|
|
3615
|
+
const labelStart = kind === 19 ? start + 1 : start;
|
|
3616
|
+
const label = kind === 20 || kind === 19 ? footnoteLabelAt(source, labelStart, source.length) : void 0;
|
|
3954
3617
|
const close = label ? closerIndex(tokens, index, label.end) : -1;
|
|
3955
|
-
if (
|
|
3956
|
-
if (result)
|
|
3618
|
+
if (label && close >= 0 && context.hasDefinition(label.definitionKey)) {
|
|
3619
|
+
if (!result) {
|
|
3620
|
+
result = [];
|
|
3621
|
+
for (let prefix = 0; prefix < index; prefix++) copyInlineToken(result, tokens, prefix);
|
|
3622
|
+
}
|
|
3623
|
+
if (kind === 19) appendInlineToken(result, 9, start, labelStart, inlineTokenFlags(tokens, index));
|
|
3624
|
+
appendInlineToken(result, 33, labelStart, label.end, inlineTokenFlags(tokens, index));
|
|
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
|
+
}
|
|
3630
|
+
index = close;
|
|
3957
3631
|
continue;
|
|
3958
3632
|
}
|
|
3959
|
-
if (
|
|
3960
|
-
|
|
3961
|
-
|
|
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
|
+
}
|
|
3962
3644
|
}
|
|
3963
|
-
if (
|
|
3964
|
-
appendInlineToken(result, 31, labelStart, label.end, inlineTokenFlags(tokens, index));
|
|
3965
|
-
index = close;
|
|
3645
|
+
if (result) copyInlineToken(result, tokens, index);
|
|
3966
3646
|
}
|
|
3967
3647
|
return result ?? tokens;
|
|
3968
3648
|
};
|
|
3969
|
-
const transformFootnoteTokens = (source, tokens, context) => activateFootnoteReferences(source, splitFootnoteTails(source, tokens, context), context);
|
|
3970
3649
|
//#endregion
|
|
3971
3650
|
//#region src/profile/features/footnote/index.ts
|
|
3972
3651
|
const feature$10 = {
|
|
@@ -3975,20 +3654,18 @@ const feature$10 = {
|
|
|
3975
3654
|
starts: blockStarts$1
|
|
3976
3655
|
},
|
|
3977
3656
|
inline: {
|
|
3978
|
-
|
|
3657
|
+
rewrite: rewriteFootnoteTokens,
|
|
3979
3658
|
syntax: [{
|
|
3980
3659
|
kind: "leaf",
|
|
3981
|
-
token:
|
|
3982
|
-
build(tokenIndex, sourceSpan,
|
|
3983
|
-
const { context } = accumulator;
|
|
3660
|
+
token: 33,
|
|
3661
|
+
build(tokenIndex, sourceSpan, context) {
|
|
3984
3662
|
const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(2, -1);
|
|
3985
|
-
|
|
3663
|
+
return {
|
|
3986
3664
|
type: "footnoteReference",
|
|
3987
3665
|
identifier: normalizeAssociationLabel(label).toLowerCase(),
|
|
3988
3666
|
label: semanticText(label),
|
|
3989
3667
|
position: sourceSpan
|
|
3990
|
-
}
|
|
3991
|
-
return true;
|
|
3668
|
+
};
|
|
3992
3669
|
}
|
|
3993
3670
|
}]
|
|
3994
3671
|
}
|
|
@@ -3997,8 +3674,7 @@ const feature$10 = {
|
|
|
3997
3674
|
//#region src/profile/features/formatting.ts
|
|
3998
3675
|
const asteriskDelimiter = {
|
|
3999
3676
|
token: 10,
|
|
4000
|
-
marker:
|
|
4001
|
-
fallbackToken: 38,
|
|
3677
|
+
marker: 42,
|
|
4002
3678
|
single: {
|
|
4003
3679
|
open: 13,
|
|
4004
3680
|
close: 14
|
|
@@ -4014,8 +3690,7 @@ const asteriskDelimiter = {
|
|
|
4014
3690
|
};
|
|
4015
3691
|
const underscoreDelimiter = {
|
|
4016
3692
|
token: 11,
|
|
4017
|
-
marker:
|
|
4018
|
-
fallbackToken: 38,
|
|
3693
|
+
marker: 95,
|
|
4019
3694
|
single: {
|
|
4020
3695
|
open: 13,
|
|
4021
3696
|
close: 14
|
|
@@ -4032,61 +3707,83 @@ const underscoreDelimiter = {
|
|
|
4032
3707
|
};
|
|
4033
3708
|
const strikethroughDelimiter = {
|
|
4034
3709
|
token: 12,
|
|
4035
|
-
marker:
|
|
4036
|
-
fallbackToken: 38,
|
|
3710
|
+
marker: 126,
|
|
4037
3711
|
double: {
|
|
4038
|
-
open:
|
|
4039
|
-
close:
|
|
3712
|
+
open: 17,
|
|
3713
|
+
close: 18
|
|
4040
3714
|
},
|
|
4041
3715
|
pairing: { kind: "whole" }
|
|
4042
3716
|
};
|
|
3717
|
+
const scanFormatting = (source, start, tokens) => {
|
|
3718
|
+
const code = source.charCodeAt(start);
|
|
3719
|
+
const end = inlineMarkerRunEnd(source, start);
|
|
3720
|
+
appendInlineToken(tokens, code === 42 ? 10 : code === 95 ? 11 : 12, start, end);
|
|
3721
|
+
return end;
|
|
3722
|
+
};
|
|
4043
3723
|
function createBuildFormatting(type) {
|
|
4044
|
-
return (openToken, closeToken,
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
});
|
|
4050
|
-
};
|
|
3724
|
+
return (openToken, closeToken, sourceSpan, children) => ({
|
|
3725
|
+
type,
|
|
3726
|
+
children,
|
|
3727
|
+
position: sourceSpan
|
|
3728
|
+
});
|
|
4051
3729
|
}
|
|
4052
|
-
const buildInlineEmphasis = createBuildFormatting("emphasis");
|
|
4053
|
-
const buildInlineStrong = createBuildFormatting("strong");
|
|
4054
|
-
const buildInlineDelete = createBuildFormatting("delete");
|
|
4055
|
-
const buildInlineStrongOrDelete = (openToken, closeToken, children, sourceSpan, accumulator) => {
|
|
4056
|
-
(accumulator.context.source[sourceSpan.start] === "~" ? buildInlineDelete : buildInlineStrong)(openToken, closeToken, children, sourceSpan, accumulator);
|
|
4057
|
-
};
|
|
4058
3730
|
function feature$9(strikethroughOptions) {
|
|
4059
3731
|
const delimiters = [asteriskDelimiter, underscoreDelimiter];
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
}
|
|
3732
|
+
const lexical = [{
|
|
3733
|
+
marker: 42,
|
|
3734
|
+
scan: scanFormatting
|
|
3735
|
+
}, {
|
|
3736
|
+
marker: 95,
|
|
3737
|
+
scan: scanFormatting
|
|
3738
|
+
}];
|
|
3739
|
+
const syntax = [
|
|
3740
|
+
{
|
|
3741
|
+
kind: "leaf",
|
|
3742
|
+
token: 10,
|
|
3743
|
+
build: buildInlineText
|
|
3744
|
+
},
|
|
3745
|
+
{
|
|
3746
|
+
kind: "leaf",
|
|
3747
|
+
token: 11,
|
|
3748
|
+
build: buildInlineText
|
|
3749
|
+
},
|
|
3750
|
+
{
|
|
3751
|
+
kind: "pair",
|
|
3752
|
+
open: 13,
|
|
3753
|
+
close: 14,
|
|
3754
|
+
build: createBuildFormatting("emphasis")
|
|
3755
|
+
},
|
|
3756
|
+
{
|
|
3757
|
+
kind: "pair",
|
|
3758
|
+
open: 15,
|
|
3759
|
+
close: 16,
|
|
3760
|
+
build: createBuildFormatting("strong")
|
|
3761
|
+
}
|
|
3762
|
+
];
|
|
3763
|
+
if (strikethroughOptions) {
|
|
3764
|
+
lexical.push({
|
|
3765
|
+
marker: 126,
|
|
3766
|
+
scan: scanFormatting
|
|
3767
|
+
});
|
|
3768
|
+
delimiters.push(typeof strikethroughOptions !== "object" || strikethroughOptions.singleTilde !== false ? {
|
|
3769
|
+
...strikethroughDelimiter,
|
|
3770
|
+
single: strikethroughDelimiter.double
|
|
3771
|
+
} : strikethroughDelimiter);
|
|
3772
|
+
syntax.push({
|
|
3773
|
+
kind: "leaf",
|
|
3774
|
+
token: 12,
|
|
3775
|
+
build: buildInlineText
|
|
3776
|
+
}, {
|
|
3777
|
+
kind: "pair",
|
|
3778
|
+
open: 17,
|
|
3779
|
+
close: 18,
|
|
3780
|
+
build: createBuildFormatting("delete")
|
|
3781
|
+
});
|
|
3782
|
+
}
|
|
4064
3783
|
return { inline: {
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
kind: "leaf",
|
|
4069
|
-
token: 38,
|
|
4070
|
-
build: buildInlineText
|
|
4071
|
-
},
|
|
4072
|
-
{
|
|
4073
|
-
kind: "leaf",
|
|
4074
|
-
token: 12,
|
|
4075
|
-
build: buildInlineText
|
|
4076
|
-
},
|
|
4077
|
-
{
|
|
4078
|
-
kind: "pair",
|
|
4079
|
-
open: 13,
|
|
4080
|
-
close: 14,
|
|
4081
|
-
build: buildInlineEmphasis
|
|
4082
|
-
},
|
|
4083
|
-
{
|
|
4084
|
-
kind: "pair",
|
|
4085
|
-
open: 15,
|
|
4086
|
-
close: 16,
|
|
4087
|
-
build: strikethroughOptions ? buildInlineStrongOrDelete : buildInlineStrong
|
|
4088
|
-
}
|
|
4089
|
-
]
|
|
3784
|
+
lexical,
|
|
3785
|
+
delimiters,
|
|
3786
|
+
syntax
|
|
4090
3787
|
} };
|
|
4091
3788
|
}
|
|
4092
3789
|
//#endregion
|
|
@@ -4111,18 +3808,18 @@ function feature$8(marker) {
|
|
|
4111
3808
|
kind: "leaf",
|
|
4112
3809
|
token: 22
|
|
4113
3810
|
},
|
|
4114
|
-
build(
|
|
4115
|
-
const token = blockToken(
|
|
4116
|
-
const rangeCount = context.
|
|
3811
|
+
build(tokenStart, context) {
|
|
3812
|
+
const token = blockToken(tokenStart, 22, context);
|
|
3813
|
+
const rangeCount = context.structure.tokens.rangeCount(token);
|
|
4117
3814
|
if (rangeCount < 2) throw new Error("FrontmatterToken does not contain two fences");
|
|
4118
|
-
let value = normalizeLines(context.source.slice(context.
|
|
3815
|
+
let value = normalizeLines(context.source.slice(context.structure.tokens.rangeEnd(token, 0), context.structure.tokens.rangeStart(token, rangeCount - 1)));
|
|
4119
3816
|
if (value.endsWith("\n")) value = value.slice(0, -1);
|
|
4120
3817
|
return {
|
|
4121
3818
|
type: "yaml",
|
|
4122
3819
|
value,
|
|
4123
3820
|
position: {
|
|
4124
|
-
start: context.
|
|
4125
|
-
end: blockEnd(
|
|
3821
|
+
start: context.structure.tokens.start(token),
|
|
3822
|
+
end: blockEnd(tokenStart, context)
|
|
4126
3823
|
}
|
|
4127
3824
|
};
|
|
4128
3825
|
}
|
|
@@ -4180,15 +3877,15 @@ const feature$7 = { block: {
|
|
|
4180
3877
|
close: 8
|
|
4181
3878
|
},
|
|
4182
3879
|
inlineContent: true,
|
|
4183
|
-
build(
|
|
4184
|
-
const marker = blockToken(
|
|
3880
|
+
build(tokenStart, context) {
|
|
3881
|
+
const marker = blockToken(tokenStart, 5, context);
|
|
4185
3882
|
return {
|
|
4186
3883
|
type: "heading",
|
|
4187
|
-
depth: context.
|
|
4188
|
-
children: buildInlineChildren(
|
|
3884
|
+
depth: context.structure.tokens.end(marker) - context.structure.tokens.start(marker),
|
|
3885
|
+
children: buildInlineChildren(tokenStart, context, true),
|
|
4189
3886
|
position: {
|
|
4190
|
-
start: context.
|
|
4191
|
-
end: blockEnd(
|
|
3887
|
+
start: context.structure.tokens.start(marker),
|
|
3888
|
+
end: blockEnd(tokenStart, context)
|
|
4192
3889
|
}
|
|
4193
3890
|
};
|
|
4194
3891
|
}
|
|
@@ -4200,17 +3897,17 @@ const feature$7 = { block: {
|
|
|
4200
3897
|
close: 8
|
|
4201
3898
|
},
|
|
4202
3899
|
inlineContent: true,
|
|
4203
|
-
build(
|
|
4204
|
-
const levelOne = directBlockToken(
|
|
4205
|
-
if (levelOne === void 0) blockToken(
|
|
4206
|
-
const children = buildInlineChildren(
|
|
3900
|
+
build(tokenStart, context) {
|
|
3901
|
+
const levelOne = directBlockToken(tokenStart, 6, context);
|
|
3902
|
+
if (levelOne === void 0) blockToken(tokenStart, 7, context);
|
|
3903
|
+
const children = buildInlineChildren(tokenStart, context);
|
|
4207
3904
|
return {
|
|
4208
3905
|
type: "heading",
|
|
4209
3906
|
depth: levelOne === void 0 ? 2 : 1,
|
|
4210
3907
|
children,
|
|
4211
3908
|
position: {
|
|
4212
3909
|
start: firstChildStart(children),
|
|
4213
|
-
end: context.
|
|
3910
|
+
end: context.structure.tokens.start(blockToken(tokenStart, 8, context))
|
|
4214
3911
|
}
|
|
4215
3912
|
};
|
|
4216
3913
|
}
|
|
@@ -4299,6 +3996,9 @@ const htmlBlockTags = /* @__PURE__ */ new Set([
|
|
|
4299
3996
|
]);
|
|
4300
3997
|
const htmlTagName = "[a-z][a-z0-9-]*";
|
|
4301
3998
|
const completeHtmlTag = new RegExp(`^(?:<${htmlTagName}(?:\\s+[a-z_:][\\w.:-]*(?:\\s*=\\s*(?:[^\\s"'=<>\`]+|'[^']*'|"[^"]*"))?)*\\s*/?>|</${htmlTagName}\\s*>)[ \\t]*$`, "i");
|
|
3999
|
+
const htmlComment = /<!-->|<!--->|<!--[\s\S]*?(?:-->|$)/y;
|
|
4000
|
+
const autolink = /<(?:[A-Z][A-Z0-9+.\-]{1,31}:[^ \t\n\r<>]+|[\w!#$%&'*+\-/=?^`{|}~.]+@[A-Z0-9](?:[A-Z0-9]|-(?=[A-Z0-9]))*(?:\.[A-Z0-9](?:[A-Z0-9]|-(?=[A-Z0-9]))*)+)>/iy;
|
|
4001
|
+
const inlineHtml = /<[A-Za-z][A-Za-z0-9-]*(?:[ \t\n\r]+[A-Za-z_:][\w.:-]*(?:[ \t\n\r]*=[ \t\n\r]*(?:[^ \t\n\r"'=<>`]+|'[^']*'|"[^"]*"))?)*[ \t\n\r]*\/?>|<\/[A-Za-z][A-Za-z0-9-]*[ \t\n\r]*>|<\?[\s\S]*?\?>|<![A-Z][\s\S]*?>|<!\[CDATA\[[\s\S]*?\]\]>/y;
|
|
4302
4002
|
function htmlStartAt(source, line) {
|
|
4303
4003
|
const indent = lineIndent(source, line);
|
|
4304
4004
|
if (!indent || source[indent.offset] !== "<") return;
|
|
@@ -4334,18 +4034,16 @@ function htmlStartAt(source, line) {
|
|
|
4334
4034
|
if (completeHtmlTag.test(body)) return { interruptParagraph: false };
|
|
4335
4035
|
}
|
|
4336
4036
|
function htmlBlockUnterminated(token, context) {
|
|
4337
|
-
const result = context.
|
|
4338
|
-
if (context.
|
|
4037
|
+
const result = context.structure.tokens.value(token);
|
|
4038
|
+
if (context.structure.tokens.kind(token) !== 23 || result === void 0) throw new Error("Expected HtmlBlockToken to contain its termination state");
|
|
4339
4039
|
return result;
|
|
4340
4040
|
}
|
|
4341
|
-
const buildInlineHtml = (tokenIndex, sourceSpan,
|
|
4342
|
-
|
|
4343
|
-
appendInline(accumulator, {
|
|
4041
|
+
const buildInlineHtml = (tokenIndex, sourceSpan, context) => {
|
|
4042
|
+
return {
|
|
4344
4043
|
type: "html",
|
|
4345
4044
|
value: inlineTokenText(context.view.text, context.tokens, tokenIndex),
|
|
4346
4045
|
position: sourceSpan
|
|
4347
|
-
}
|
|
4348
|
-
return true;
|
|
4046
|
+
};
|
|
4349
4047
|
};
|
|
4350
4048
|
const feature$6 = {
|
|
4351
4049
|
block: {
|
|
@@ -4355,18 +4053,19 @@ const feature$6 = {
|
|
|
4355
4053
|
kind: "leaf",
|
|
4356
4054
|
token: 23
|
|
4357
4055
|
},
|
|
4358
|
-
build(
|
|
4359
|
-
const
|
|
4360
|
-
const
|
|
4056
|
+
build(tokenStart, context) {
|
|
4057
|
+
const offset = context.structure.tokens.start(tokenStart);
|
|
4058
|
+
const end = offset + context.structure.lenOf(tokenStart);
|
|
4059
|
+
const token = blockToken(tokenStart, 23, context);
|
|
4361
4060
|
const unterminated = htmlBlockUnterminated(token, context);
|
|
4362
|
-
let html = normalizeLines(context.
|
|
4061
|
+
let html = normalizeLines(context.structure.tokens.text(context.source, token));
|
|
4363
4062
|
if (!unterminated && html.endsWith("\n")) html = html.slice(0, -1);
|
|
4364
4063
|
return {
|
|
4365
4064
|
type: "html",
|
|
4366
4065
|
value: html,
|
|
4367
4066
|
position: {
|
|
4368
4067
|
start: offset,
|
|
4369
|
-
end: html.endsWith("\n") ? end : blockEnd(
|
|
4068
|
+
end: html.endsWith("\n") ? end : blockEnd(tokenStart, context)
|
|
4370
4069
|
}
|
|
4371
4070
|
};
|
|
4372
4071
|
}
|
|
@@ -4392,55 +4091,175 @@ const feature$6 = {
|
|
|
4392
4091
|
}
|
|
4393
4092
|
}]
|
|
4394
4093
|
},
|
|
4395
|
-
inline: {
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4094
|
+
inline: {
|
|
4095
|
+
lexical: [{
|
|
4096
|
+
marker: 60,
|
|
4097
|
+
scan(source, start, tokens) {
|
|
4098
|
+
let end = matchInlinePatternEnd(htmlComment, source, start);
|
|
4099
|
+
let kind = 1;
|
|
4100
|
+
if (end < 0) {
|
|
4101
|
+
end = matchInlinePatternEnd(autolink, source, start);
|
|
4102
|
+
kind = 4;
|
|
4103
|
+
}
|
|
4104
|
+
if (end < 0) {
|
|
4105
|
+
end = matchInlinePatternEnd(inlineHtml, source, start);
|
|
4106
|
+
kind = 5;
|
|
4107
|
+
}
|
|
4108
|
+
if (end < 0) {
|
|
4109
|
+
end = start + 1;
|
|
4110
|
+
kind = 41;
|
|
4111
|
+
}
|
|
4112
|
+
appendInlineToken(tokens, kind, start, end);
|
|
4113
|
+
return end;
|
|
4114
|
+
}
|
|
4115
|
+
}],
|
|
4116
|
+
syntax: [{
|
|
4117
|
+
kind: "leaf",
|
|
4118
|
+
token: 5,
|
|
4119
|
+
build: buildInlineHtml
|
|
4120
|
+
}, {
|
|
4121
|
+
kind: "leaf",
|
|
4122
|
+
token: 1,
|
|
4123
|
+
build: buildInlineHtml
|
|
4124
|
+
}]
|
|
4125
|
+
}
|
|
4404
4126
|
};
|
|
4405
4127
|
//#endregion
|
|
4406
4128
|
//#region src/profile/features/link.ts
|
|
4407
|
-
function
|
|
4408
|
-
|
|
4129
|
+
function skipWhitespace(source, start) {
|
|
4130
|
+
let end = start;
|
|
4131
|
+
while (end < source.length) {
|
|
4132
|
+
const code = source.charCodeAt(end);
|
|
4133
|
+
if (code !== 9 && code !== 10 && code !== 13 && code !== 32) break;
|
|
4134
|
+
end++;
|
|
4135
|
+
}
|
|
4136
|
+
return end;
|
|
4137
|
+
}
|
|
4138
|
+
function linkDestinationEnd(source, start) {
|
|
4139
|
+
if (source.charCodeAt(start) === 60) {
|
|
4140
|
+
let end = start + 1;
|
|
4141
|
+
while (end < source.length) {
|
|
4142
|
+
const code = source.charCodeAt(end);
|
|
4143
|
+
if (code === 62) return end + 1;
|
|
4144
|
+
if (code === 10 || code === 13 || code === 60) return -1;
|
|
4145
|
+
end += code === 92 && end + 1 < source.length ? 2 : 1;
|
|
4146
|
+
}
|
|
4147
|
+
return -1;
|
|
4148
|
+
}
|
|
4149
|
+
let depth = 0;
|
|
4150
|
+
let end = start;
|
|
4151
|
+
let consumed = false;
|
|
4152
|
+
while (end < source.length) {
|
|
4153
|
+
const code = source.charCodeAt(end);
|
|
4154
|
+
if (code === 92) {
|
|
4155
|
+
if (end + 1 >= source.length) break;
|
|
4156
|
+
consumed = true;
|
|
4157
|
+
end += 2;
|
|
4158
|
+
continue;
|
|
4159
|
+
}
|
|
4160
|
+
if (code === 40) {
|
|
4161
|
+
if (depth === 32) return -1;
|
|
4162
|
+
depth++;
|
|
4163
|
+
consumed = true;
|
|
4164
|
+
end++;
|
|
4165
|
+
continue;
|
|
4166
|
+
}
|
|
4167
|
+
if (code === 41) {
|
|
4168
|
+
if (depth === 0) break;
|
|
4169
|
+
depth--;
|
|
4170
|
+
consumed = true;
|
|
4171
|
+
end++;
|
|
4172
|
+
continue;
|
|
4173
|
+
}
|
|
4174
|
+
if (isLinkWhitespace(code)) break;
|
|
4175
|
+
consumed = true;
|
|
4176
|
+
end++;
|
|
4177
|
+
}
|
|
4178
|
+
return consumed && depth === 0 ? end : -1;
|
|
4179
|
+
}
|
|
4180
|
+
function linkTitleEnd(source, start) {
|
|
4181
|
+
const marker = source.charCodeAt(start);
|
|
4182
|
+
const close = marker === 40 ? 41 : marker;
|
|
4183
|
+
if (marker !== 34 && marker !== 39 && marker !== 40) return -1;
|
|
4184
|
+
let end = start + 1;
|
|
4185
|
+
while (end < source.length) {
|
|
4186
|
+
const code = source.charCodeAt(end);
|
|
4187
|
+
if (code === close) return end + 1;
|
|
4188
|
+
if (code === 10 || code === 13) return -1;
|
|
4189
|
+
end += code === 92 && end + 1 < source.length ? 2 : 1;
|
|
4190
|
+
}
|
|
4191
|
+
return -1;
|
|
4192
|
+
}
|
|
4193
|
+
function linkTailEnd(source, start) {
|
|
4194
|
+
if (source.charCodeAt(start + 1) !== 40) return -1;
|
|
4195
|
+
let offset = skipWhitespace(source, start + 2);
|
|
4196
|
+
if (source.charCodeAt(offset) === 41) return offset + 1;
|
|
4197
|
+
const destinationEnd = linkDestinationEnd(source, offset);
|
|
4198
|
+
if (destinationEnd < 0) return -1;
|
|
4199
|
+
offset = destinationEnd;
|
|
4200
|
+
const whitespaceEnd = skipWhitespace(source, offset);
|
|
4201
|
+
if (whitespaceEnd > offset && source.charCodeAt(whitespaceEnd) !== 41) {
|
|
4202
|
+
const titleEnd = linkTitleEnd(source, whitespaceEnd);
|
|
4203
|
+
if (titleEnd < 0) return -1;
|
|
4204
|
+
offset = titleEnd;
|
|
4205
|
+
} else offset = whitespaceEnd;
|
|
4206
|
+
offset = skipWhitespace(source, offset);
|
|
4207
|
+
return source.charCodeAt(offset) === 41 ? offset + 1 : -1;
|
|
4208
|
+
}
|
|
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
|
+
function isLinkWhitespace(code) {
|
|
4232
|
+
return code === 9 || code === 10 || code === 13 || code === 32;
|
|
4409
4233
|
}
|
|
4410
|
-
function
|
|
4411
|
-
|
|
4412
|
-
|
|
4234
|
+
function resourceAt(source, tokenStart, tokenEnd) {
|
|
4235
|
+
let start = tokenStart + 2;
|
|
4236
|
+
let end = tokenEnd - 1;
|
|
4237
|
+
while (start < end && isLinkWhitespace(source.charCodeAt(start))) start++;
|
|
4238
|
+
while (end > start && isLinkWhitespace(source.charCodeAt(end - 1))) end--;
|
|
4239
|
+
if (start === end) return {
|
|
4413
4240
|
url: "",
|
|
4414
4241
|
title: null
|
|
4415
4242
|
};
|
|
4416
|
-
let
|
|
4417
|
-
let
|
|
4418
|
-
if (
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
else
|
|
4423
|
-
|
|
4243
|
+
let destinationStart = start;
|
|
4244
|
+
let destinationEnd = start;
|
|
4245
|
+
if (source[start] === "<") {
|
|
4246
|
+
destinationStart++;
|
|
4247
|
+
destinationEnd = destinationStart;
|
|
4248
|
+
while (destinationEnd < end) if (source[destinationEnd] === "\\") destinationEnd += 2;
|
|
4249
|
+
else if (source[destinationEnd] === ">") break;
|
|
4250
|
+
else destinationEnd++;
|
|
4251
|
+
start = destinationEnd + 1;
|
|
4424
4252
|
} else {
|
|
4425
|
-
|
|
4426
|
-
while (
|
|
4427
|
-
else if (
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
} else if (body[offset] === ")") {
|
|
4431
|
-
depth--;
|
|
4432
|
-
offset++;
|
|
4433
|
-
} else if (depth === 0) {
|
|
4434
|
-
const code = body.charCodeAt(offset);
|
|
4435
|
-
if (code === 9 || code === 10 || code === 13 || code === 32) break;
|
|
4436
|
-
offset++;
|
|
4437
|
-
} else offset++;
|
|
4438
|
-
destination = body.slice(0, offset);
|
|
4253
|
+
destinationEnd = start;
|
|
4254
|
+
while (destinationEnd < end) if (source[destinationEnd] === "\\") destinationEnd += 2;
|
|
4255
|
+
else if (isLinkWhitespace(source.charCodeAt(destinationEnd))) break;
|
|
4256
|
+
else destinationEnd++;
|
|
4257
|
+
start = destinationEnd;
|
|
4439
4258
|
}
|
|
4440
|
-
|
|
4259
|
+
while (start < end && isLinkWhitespace(source.charCodeAt(start))) start++;
|
|
4441
4260
|
return {
|
|
4442
|
-
url: semanticText(
|
|
4443
|
-
title:
|
|
4261
|
+
url: semanticText(source.slice(destinationStart, destinationEnd)),
|
|
4262
|
+
title: start < end ? semanticText(source.slice(start + 1, end - 1)) : null
|
|
4444
4263
|
};
|
|
4445
4264
|
}
|
|
4446
4265
|
function reference(close, syntaxStart, syntaxEnd, context, image) {
|
|
@@ -4466,11 +4285,10 @@ function phrasingText(children) {
|
|
|
4466
4285
|
function createBuildMedia(media, resourceKind) {
|
|
4467
4286
|
const image = media === "image";
|
|
4468
4287
|
const referenceNode = resourceKind === "reference";
|
|
4469
|
-
return (openToken, closeToken,
|
|
4470
|
-
const context = accumulator.context;
|
|
4288
|
+
return (openToken, closeToken, sourceSpan, children, context) => {
|
|
4471
4289
|
if (referenceNode) {
|
|
4472
4290
|
const association = reference(closeToken, inlineTokenStart(context.tokens, openToken), inlineTokenEnd(context.tokens, closeToken), context, image);
|
|
4473
|
-
|
|
4291
|
+
return image ? {
|
|
4474
4292
|
type: "imageReference",
|
|
4475
4293
|
alt: phrasingText(children),
|
|
4476
4294
|
...association,
|
|
@@ -4480,106 +4298,141 @@ function createBuildMedia(media, resourceKind) {
|
|
|
4480
4298
|
children,
|
|
4481
4299
|
...association,
|
|
4482
4300
|
position: sourceSpan
|
|
4483
|
-
}
|
|
4484
|
-
} else {
|
|
4485
|
-
const resource = destinationTitle(inlineTokenText(context.view.text, context.tokens, closeToken).slice(2, -1));
|
|
4486
|
-
appendInline(accumulator, image ? {
|
|
4487
|
-
type: "image",
|
|
4488
|
-
alt: phrasingText(children),
|
|
4489
|
-
...resource,
|
|
4490
|
-
position: sourceSpan
|
|
4491
|
-
} : {
|
|
4492
|
-
type: "link",
|
|
4493
|
-
children,
|
|
4494
|
-
...resource,
|
|
4495
|
-
position: sourceSpan
|
|
4496
|
-
});
|
|
4301
|
+
};
|
|
4497
4302
|
}
|
|
4303
|
+
const resource = resourceAt(context.view.text, inlineTokenStart(context.tokens, closeToken), inlineTokenEnd(context.tokens, closeToken));
|
|
4304
|
+
return image ? {
|
|
4305
|
+
type: "image",
|
|
4306
|
+
alt: phrasingText(children),
|
|
4307
|
+
...resource,
|
|
4308
|
+
position: sourceSpan
|
|
4309
|
+
} : {
|
|
4310
|
+
type: "link",
|
|
4311
|
+
children,
|
|
4312
|
+
...resource,
|
|
4313
|
+
position: sourceSpan
|
|
4314
|
+
};
|
|
4498
4315
|
};
|
|
4499
4316
|
}
|
|
4500
4317
|
const buildInlineImage = createBuildMedia("image", "direct");
|
|
4501
4318
|
const buildInlineReferenceImage = createBuildMedia("image", "reference");
|
|
4502
4319
|
const buildInlineLink = createBuildMedia("link", "direct");
|
|
4503
4320
|
const buildInlineReferenceLink = createBuildMedia("link", "reference");
|
|
4504
|
-
const feature$5 = { inline: {
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
children: [{
|
|
4540
|
-
type: "text",
|
|
4541
|
-
value: label,
|
|
4542
|
-
position: {
|
|
4543
|
-
start: sourceSpan.start + 1,
|
|
4544
|
-
end: sourceSpan.end - 1
|
|
4545
|
-
}
|
|
4546
|
-
}],
|
|
4547
|
-
position: sourceSpan
|
|
4548
|
-
});
|
|
4549
|
-
return true;
|
|
4321
|
+
const feature$5 = { inline: {
|
|
4322
|
+
lexical: [
|
|
4323
|
+
{
|
|
4324
|
+
marker: 33,
|
|
4325
|
+
scan(source, start, tokens) {
|
|
4326
|
+
const image = source.charCodeAt(start + 1) === 91;
|
|
4327
|
+
const end = start + (image ? 2 : 1);
|
|
4328
|
+
appendInlineToken(tokens, image ? 19 : 41, start, end);
|
|
4329
|
+
return end;
|
|
4330
|
+
}
|
|
4331
|
+
},
|
|
4332
|
+
{
|
|
4333
|
+
marker: 91,
|
|
4334
|
+
scan(source, start, tokens) {
|
|
4335
|
+
const end = start + 1;
|
|
4336
|
+
appendInlineToken(tokens, 20, start, end);
|
|
4337
|
+
return end;
|
|
4338
|
+
}
|
|
4339
|
+
},
|
|
4340
|
+
{
|
|
4341
|
+
marker: 93,
|
|
4342
|
+
scan(source, start, tokens) {
|
|
4343
|
+
let end = linkTailEnd(source, start);
|
|
4344
|
+
let kind = 21;
|
|
4345
|
+
if (end < 0) {
|
|
4346
|
+
end = referenceTailEnd(source, start);
|
|
4347
|
+
kind = 22;
|
|
4348
|
+
}
|
|
4349
|
+
if (end < 0) {
|
|
4350
|
+
end = start + 1;
|
|
4351
|
+
kind = 23;
|
|
4352
|
+
}
|
|
4353
|
+
appendInlineToken(tokens, kind, start, end, kind === 23 ? 0 : 16);
|
|
4354
|
+
return end;
|
|
4355
|
+
}
|
|
4550
4356
|
}
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4357
|
+
],
|
|
4358
|
+
syntax: [
|
|
4359
|
+
{
|
|
4360
|
+
kind: "pair",
|
|
4361
|
+
open: 25,
|
|
4362
|
+
close: 26,
|
|
4363
|
+
build: buildInlineLink
|
|
4364
|
+
},
|
|
4365
|
+
{
|
|
4366
|
+
kind: "pair",
|
|
4367
|
+
open: 27,
|
|
4368
|
+
close: 28,
|
|
4369
|
+
build: buildInlineImage
|
|
4370
|
+
},
|
|
4371
|
+
{
|
|
4372
|
+
kind: "pair",
|
|
4373
|
+
open: 29,
|
|
4374
|
+
close: 30,
|
|
4375
|
+
build: buildInlineReferenceLink
|
|
4376
|
+
},
|
|
4377
|
+
{
|
|
4378
|
+
kind: "pair",
|
|
4379
|
+
open: 31,
|
|
4380
|
+
close: 32,
|
|
4381
|
+
build: buildInlineReferenceImage
|
|
4382
|
+
},
|
|
4383
|
+
{
|
|
4384
|
+
kind: "leaf",
|
|
4385
|
+
token: 4,
|
|
4386
|
+
build(tokenIndex, sourceSpan, context) {
|
|
4387
|
+
const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(1, -1);
|
|
4388
|
+
return {
|
|
4389
|
+
type: "link",
|
|
4390
|
+
url: label.includes(":") ? label : `mailto:${label}`,
|
|
4391
|
+
title: null,
|
|
4392
|
+
children: [{
|
|
4393
|
+
type: "text",
|
|
4394
|
+
value: label,
|
|
4395
|
+
position: {
|
|
4396
|
+
start: sourceSpan.start + 1,
|
|
4397
|
+
end: sourceSpan.end - 1
|
|
4398
|
+
}
|
|
4399
|
+
}],
|
|
4400
|
+
position: sourceSpan
|
|
4401
|
+
};
|
|
4402
|
+
}
|
|
4403
|
+
},
|
|
4404
|
+
{
|
|
4405
|
+
kind: "leaf",
|
|
4406
|
+
token: 20,
|
|
4407
|
+
build: buildInlineText
|
|
4408
|
+
},
|
|
4409
|
+
{
|
|
4410
|
+
kind: "leaf",
|
|
4411
|
+
token: 19,
|
|
4412
|
+
build: buildInlineText
|
|
4413
|
+
},
|
|
4414
|
+
{
|
|
4415
|
+
kind: "leaf",
|
|
4416
|
+
token: 21,
|
|
4417
|
+
build: buildInlineText
|
|
4418
|
+
},
|
|
4419
|
+
{
|
|
4420
|
+
kind: "leaf",
|
|
4421
|
+
token: 22,
|
|
4422
|
+
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
|
+
}
|
|
4434
|
+
]
|
|
4435
|
+
} };
|
|
4583
4436
|
//#endregion
|
|
4584
4437
|
//#region src/profile/features/list.ts
|
|
4585
4438
|
function listMarkerPadding(source, line, markerEnd, markerColumn) {
|
|
@@ -4678,55 +4531,48 @@ function hasBlankLineBetween(source, start, end, stripBlockQuotes) {
|
|
|
4678
4531
|
}
|
|
4679
4532
|
return false;
|
|
4680
4533
|
}
|
|
4681
|
-
function childrenSpread(
|
|
4682
|
-
const
|
|
4534
|
+
function childrenSpread(tokenStart, stripBlockQuotes, context, nestedRule) {
|
|
4535
|
+
const structure = context.structure;
|
|
4683
4536
|
let previous;
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
const childId = arena.childAt(nodeId, index);
|
|
4687
|
-
if (childId < 0 || (nestedRule === void 0 ? !arena.isBlock(childId) : arena.ruleNameOf(childId) !== nestedRule)) continue;
|
|
4688
|
-
const current = payloadBounds(childId, offset + arena.childRelAt(nodeId, index), tokenBase + arena.childTokRelAt(nodeId, index), context);
|
|
4537
|
+
for (let childId = structure.firstChild(tokenStart); childId !== noBlockEntry; childId = structure.nextChild(tokenStart, childId)) if (childId >= 0 && (nestedRule === void 0 ? structure.isBlock(childId) : structure.ruleNameOf(childId) === nestedRule)) {
|
|
4538
|
+
const current = payloadBounds(childId, context);
|
|
4689
4539
|
if (previous && hasBlankLineBetween(context.source, previous.end, current.start, stripBlockQuotes)) return true;
|
|
4690
4540
|
previous = current;
|
|
4691
4541
|
}
|
|
4692
4542
|
return false;
|
|
4693
4543
|
}
|
|
4694
|
-
const buildListItem = (
|
|
4695
|
-
const rule = context.
|
|
4544
|
+
const buildListItem = (tokenStart, context) => {
|
|
4545
|
+
const rule = context.structure.ruleNameOf(tokenStart);
|
|
4696
4546
|
if (rule !== "OrderedListItem" && rule !== "UnorderedListItem") throw new Error(`Expected list item syntax, received ${rule}`);
|
|
4697
|
-
const marker = blockToken(
|
|
4698
|
-
const children = buildBlockChildren(
|
|
4547
|
+
const marker = blockToken(tokenStart, rule === "OrderedListItem" ? 17 : 13, context);
|
|
4548
|
+
const children = buildBlockChildren(tokenStart, context);
|
|
4699
4549
|
return {
|
|
4700
4550
|
type: "listItem",
|
|
4701
|
-
spread: childrenSpread(
|
|
4551
|
+
spread: childrenSpread(tokenStart, true, context),
|
|
4702
4552
|
checked: null,
|
|
4703
4553
|
children,
|
|
4704
4554
|
position: {
|
|
4705
|
-
start: context.
|
|
4706
|
-
end: lastChildEnd(children, blockEnd(
|
|
4555
|
+
start: context.structure.tokens.start(marker),
|
|
4556
|
+
end: lastChildEnd(children, blockEnd(tokenStart, context))
|
|
4707
4557
|
}
|
|
4708
4558
|
};
|
|
4709
4559
|
};
|
|
4710
4560
|
function createBuildList(ordered) {
|
|
4711
|
-
return (
|
|
4712
|
-
const
|
|
4561
|
+
return (tokenStart, context) => {
|
|
4562
|
+
const structure = context.structure;
|
|
4713
4563
|
const itemRule = ordered ? "OrderedListItem" : "UnorderedListItem";
|
|
4714
|
-
const listMarker = blockToken(
|
|
4564
|
+
const listMarker = blockToken(tokenStart, ordered ? 15 : 11, context);
|
|
4715
4565
|
const items = [];
|
|
4716
|
-
|
|
4717
|
-
for (let index = 0; index < childCount; index++) {
|
|
4718
|
-
const childId = arena.childAt(nodeId, index);
|
|
4719
|
-
if (childId >= 0 && arena.ruleNameOf(childId) === itemRule) items.push(buildListItem(childId, offset + arena.childRelAt(nodeId, index), tokenBase + arena.childTokRelAt(nodeId, index), context));
|
|
4720
|
-
}
|
|
4566
|
+
for (let childId = structure.firstChild(tokenStart); childId !== noBlockEntry; childId = structure.nextChild(tokenStart, childId)) if (childId >= 0 && structure.ruleNameOf(childId) === itemRule) items.push(buildListItem(childId, context));
|
|
4721
4567
|
return {
|
|
4722
4568
|
type: "list",
|
|
4723
4569
|
ordered,
|
|
4724
|
-
start: ordered ? Number.parseInt(context.
|
|
4725
|
-
spread: childrenSpread(
|
|
4570
|
+
start: ordered ? Number.parseInt(context.structure.tokens.text(context.source, listMarker), 10) : null,
|
|
4571
|
+
spread: childrenSpread(tokenStart, false, context, itemRule),
|
|
4726
4572
|
children: items,
|
|
4727
4573
|
position: {
|
|
4728
|
-
start: context.
|
|
4729
|
-
end: lastChildEnd(items, context.
|
|
4574
|
+
start: context.structure.tokens.start(listMarker),
|
|
4575
|
+
end: lastChildEnd(items, context.structure.tokens.end(listMarker))
|
|
4730
4576
|
}
|
|
4731
4577
|
};
|
|
4732
4578
|
};
|
|
@@ -4874,17 +4720,20 @@ const blockRules = [{
|
|
|
4874
4720
|
kind: "leaf",
|
|
4875
4721
|
token: 21
|
|
4876
4722
|
},
|
|
4877
|
-
build(
|
|
4878
|
-
const
|
|
4879
|
-
const
|
|
4880
|
-
const
|
|
4723
|
+
build(tokenStart, context) {
|
|
4724
|
+
const offset = context.structure.tokens.start(tokenStart);
|
|
4725
|
+
const end = offset + context.structure.lenOf(tokenStart);
|
|
4726
|
+
const token = blockToken(tokenStart, 21, context);
|
|
4727
|
+
const value = context.structure.tokens.text(context.source, token);
|
|
4728
|
+
const block = context.structure.tokens.value(token);
|
|
4729
|
+
if (!block) throw new Error("MathBlockToken has no fence metadata");
|
|
4881
4730
|
return {
|
|
4882
4731
|
type: "math",
|
|
4883
4732
|
meta: semanticText(block.info) || null,
|
|
4884
4733
|
value: fencedBlockContent(value, block, "columns"),
|
|
4885
4734
|
position: {
|
|
4886
4735
|
start: firstNonspace(context.source, offset, lineEnd(context.source, offset)),
|
|
4887
|
-
end: block.closed || end < context.source.length ? blockEnd(
|
|
4736
|
+
end: block.closed || end < context.source.length ? blockEnd(tokenStart, context) : end
|
|
4888
4737
|
}
|
|
4889
4738
|
};
|
|
4890
4739
|
}
|
|
@@ -4899,81 +4748,38 @@ const blockStarts = [{
|
|
|
4899
4748
|
if (!fence) return;
|
|
4900
4749
|
let end = start + 1;
|
|
4901
4750
|
while (end < lines.length && !closesFence(source, lines[end], fence)) end++;
|
|
4751
|
+
const closed = end < lines.length;
|
|
4902
4752
|
if (end < lines.length) end++;
|
|
4903
|
-
appendLogicalToken(out, 21, source, lines, start, end);
|
|
4753
|
+
appendLogicalToken(out, 21, source, lines, start, end, fencedBlock(source, lines[start], fence, closed));
|
|
4904
4754
|
return end;
|
|
4905
4755
|
}
|
|
4906
4756
|
}];
|
|
4907
4757
|
//#endregion
|
|
4908
4758
|
//#region src/profile/features/math/inline.ts
|
|
4909
|
-
function
|
|
4910
|
-
const
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
const markerLength = openerEnd - start;
|
|
4930
|
-
search = openerEnd;
|
|
4931
|
-
if (markerLength < minimum) continue;
|
|
4932
|
-
let close = openerEnd;
|
|
4933
|
-
while (close < source.length) {
|
|
4934
|
-
close = source.indexOf("$", close);
|
|
4935
|
-
if (close < 0) break;
|
|
4936
|
-
const closeEnd = markerRunEnd(source, close);
|
|
4937
|
-
if (closeEnd - close === markerLength) return {
|
|
4938
|
-
start,
|
|
4939
|
-
end: closeEnd,
|
|
4940
|
-
flags: inlineTokenFlags(tokens, tokenIndex)
|
|
4941
|
-
};
|
|
4942
|
-
close = closeEnd;
|
|
4943
|
-
}
|
|
4944
|
-
}
|
|
4945
|
-
}
|
|
4946
|
-
function copyRange(target, tokens, start, end, offset) {
|
|
4947
|
-
for (let index = firstInlineTokenEndingAfter(tokens, start); index < inlineTokenCount(tokens); index++) {
|
|
4948
|
-
const tokenStart = inlineTokenStart(tokens, index);
|
|
4949
|
-
if (tokenStart >= end) break;
|
|
4950
|
-
const tokenEnd = inlineTokenEnd(tokens, index);
|
|
4951
|
-
const fragmentStart = Math.max(start, tokenStart);
|
|
4952
|
-
const fragmentEnd = Math.min(end, tokenEnd);
|
|
4953
|
-
appendInlineToken(target, inlineTokenKind(tokens, index), fragmentStart + offset, fragmentEnd + offset, fragmentStart === tokenStart ? inlineTokenFlags(tokens, index) : 0);
|
|
4954
|
-
}
|
|
4955
|
-
}
|
|
4956
|
-
function createMathTokensTransform(singleDollarTextMath) {
|
|
4957
|
-
return (source, tokens, context) => {
|
|
4958
|
-
const minimum = singleDollarTextMath ? 1 : 2;
|
|
4959
|
-
let segmentSource = source;
|
|
4960
|
-
let segmentStart = 0;
|
|
4961
|
-
let segmentTokens = tokens;
|
|
4962
|
-
let result;
|
|
4963
|
-
while (true) {
|
|
4964
|
-
const span = firstMathSpan(segmentSource, segmentTokens, minimum);
|
|
4965
|
-
if (!span) {
|
|
4966
|
-
if (!result) return tokens;
|
|
4967
|
-
copyRange(result, segmentTokens, 0, segmentSource.length, segmentStart);
|
|
4968
|
-
return result;
|
|
4759
|
+
function createMathLexicalRule(singleDollarTextMath) {
|
|
4760
|
+
const minimum = singleDollarTextMath ? 1 : 2;
|
|
4761
|
+
return {
|
|
4762
|
+
marker: 36,
|
|
4763
|
+
scan(source, start, tokens) {
|
|
4764
|
+
const openEnd = inlineMarkerRunEnd(source, start);
|
|
4765
|
+
const markerLength = openEnd - start;
|
|
4766
|
+
let end = -1;
|
|
4767
|
+
if (markerLength >= minimum) {
|
|
4768
|
+
let close = openEnd;
|
|
4769
|
+
while (close < source.length) {
|
|
4770
|
+
close = source.indexOf("$", close);
|
|
4771
|
+
if (close < 0) break;
|
|
4772
|
+
const closeEnd = inlineMarkerRunEnd(source, close);
|
|
4773
|
+
if (closeEnd - close === markerLength) {
|
|
4774
|
+
end = closeEnd;
|
|
4775
|
+
break;
|
|
4776
|
+
}
|
|
4777
|
+
close = closeEnd;
|
|
4778
|
+
}
|
|
4969
4779
|
}
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
segmentStart += span.end;
|
|
4974
|
-
if (segmentStart === source.length) return result;
|
|
4975
|
-
segmentSource = source.slice(segmentStart);
|
|
4976
|
-
segmentTokens = context.tokenize(segmentSource);
|
|
4780
|
+
if (end < 0) end = openEnd;
|
|
4781
|
+
appendInlineToken(tokens, end === openEnd ? 9 : 3, start, end);
|
|
4782
|
+
return end;
|
|
4977
4783
|
}
|
|
4978
4784
|
};
|
|
4979
4785
|
}
|
|
@@ -4990,14 +4796,12 @@ function mathTextValue(value) {
|
|
|
4990
4796
|
const inlineSyntax = [{
|
|
4991
4797
|
kind: "leaf",
|
|
4992
4798
|
token: 3,
|
|
4993
|
-
build(tokenIndex, sourceSpan,
|
|
4994
|
-
|
|
4995
|
-
appendInline(accumulator, {
|
|
4799
|
+
build(tokenIndex, sourceSpan, context) {
|
|
4800
|
+
return {
|
|
4996
4801
|
type: "inlineMath",
|
|
4997
4802
|
value: mathTextValue(inlineTokenText(context.view.text, context.tokens, tokenIndex)),
|
|
4998
4803
|
position: sourceSpan
|
|
4999
|
-
}
|
|
5000
|
-
return true;
|
|
4804
|
+
};
|
|
5001
4805
|
}
|
|
5002
4806
|
}];
|
|
5003
4807
|
//#endregion
|
|
@@ -5010,7 +4814,7 @@ function feature$3(options) {
|
|
|
5010
4814
|
starts: blockStarts
|
|
5011
4815
|
},
|
|
5012
4816
|
inline: {
|
|
5013
|
-
|
|
4817
|
+
lexical: [createMathLexicalRule(singleDollarTextMath)],
|
|
5014
4818
|
syntax: inlineSyntax
|
|
5015
4819
|
}
|
|
5016
4820
|
};
|
|
@@ -5065,14 +4869,14 @@ const feature$2 = { block: {
|
|
|
5065
4869
|
close: 10
|
|
5066
4870
|
},
|
|
5067
4871
|
inlineContent: true,
|
|
5068
|
-
build(
|
|
5069
|
-
const children = buildInlineChildren(
|
|
4872
|
+
build(tokenStart, context) {
|
|
4873
|
+
const children = buildInlineChildren(tokenStart, context);
|
|
5070
4874
|
return {
|
|
5071
4875
|
type: "paragraph",
|
|
5072
4876
|
children,
|
|
5073
4877
|
position: {
|
|
5074
4878
|
start: firstChildStart(children),
|
|
5075
|
-
end: blockEnd(
|
|
4879
|
+
end: blockEnd(tokenStart, context)
|
|
5076
4880
|
}
|
|
5077
4881
|
};
|
|
5078
4882
|
}
|
|
@@ -5085,37 +4889,35 @@ function linkDefinitionFields(tokens, token) {
|
|
|
5085
4889
|
if (tokens.kind(token) !== 26 || !fields) throw new Error("Expected LinkDefinitionOpen token to contain parsed fields");
|
|
5086
4890
|
return fields;
|
|
5087
4891
|
}
|
|
5088
|
-
function linkDefinitionAt(source, lines, startIndex) {
|
|
5089
|
-
const indent = lineIndent(source, lines[startIndex]);
|
|
5090
|
-
if (!indent || source[indent.offset] !== "[") return;
|
|
4892
|
+
function linkDefinitionAt(source, lines, startIndex, contentOffset) {
|
|
5091
4893
|
let lineIndex = startIndex;
|
|
5092
|
-
let offset =
|
|
4894
|
+
let offset = contentOffset + 1;
|
|
5093
4895
|
let label = "";
|
|
5094
4896
|
let labelLength = 0;
|
|
5095
4897
|
let labelHasContent = false;
|
|
5096
4898
|
let labelStart = offset;
|
|
5097
|
-
while (true) {
|
|
4899
|
+
scanLabel: while (true) {
|
|
5098
4900
|
const line = lines[lineIndex];
|
|
5099
|
-
|
|
5100
|
-
|
|
4901
|
+
while (offset < line.end) {
|
|
4902
|
+
const code = source.charCodeAt(offset);
|
|
4903
|
+
if (code === 92 && offset + 1 < line.end) {
|
|
4904
|
+
labelHasContent = true;
|
|
4905
|
+
labelLength += 2;
|
|
4906
|
+
offset += 2;
|
|
4907
|
+
continue;
|
|
4908
|
+
}
|
|
4909
|
+
if (code === 91) return;
|
|
4910
|
+
if (code === 93 && source.charCodeAt(offset + 1) === 58) break scanLabel;
|
|
4911
|
+
if (code !== 32 && code !== 9) labelHasContent = true;
|
|
5101
4912
|
if (++labelLength > 999) return;
|
|
5102
|
-
|
|
5103
|
-
lineIndex++;
|
|
5104
|
-
offset = lines[lineIndex].start;
|
|
5105
|
-
labelStart = offset;
|
|
5106
|
-
continue;
|
|
5107
|
-
}
|
|
5108
|
-
if (source[offset] === "\\" && offset + 1 < line.end) {
|
|
5109
|
-
labelHasContent = true;
|
|
5110
|
-
labelLength += 2;
|
|
5111
|
-
offset += 2;
|
|
5112
|
-
continue;
|
|
4913
|
+
offset++;
|
|
5113
4914
|
}
|
|
5114
|
-
if (source[
|
|
5115
|
-
if (source[offset] === "]" && source[offset + 1] === ":") break;
|
|
5116
|
-
if (source[offset] !== " " && source[offset] !== " ") labelHasContent = true;
|
|
4915
|
+
if (lineIndex + 1 >= lines.length || isBlank(source, lines[lineIndex + 1])) return;
|
|
5117
4916
|
if (++labelLength > 999) return;
|
|
5118
|
-
|
|
4917
|
+
label += source.slice(labelStart, line.next);
|
|
4918
|
+
lineIndex++;
|
|
4919
|
+
offset = lines[lineIndex].start;
|
|
4920
|
+
labelStart = offset;
|
|
5119
4921
|
}
|
|
5120
4922
|
label += source.slice(labelStart, offset);
|
|
5121
4923
|
if (!labelHasContent) return;
|
|
@@ -5162,7 +4964,7 @@ function linkDefinitionAt(source, lines, startIndex) {
|
|
|
5162
4964
|
if (offset < lines[lineIndex].end && source[offset] !== " " && source[offset] !== " ") return;
|
|
5163
4965
|
skipSpaces();
|
|
5164
4966
|
let titleOnNextLine = false;
|
|
5165
|
-
if (offset === lines[lineIndex].end && lineIndex + 1 < lines.length
|
|
4967
|
+
if (offset === lines[lineIndex].end && lineIndex + 1 < lines.length) {
|
|
5166
4968
|
lineIndex++;
|
|
5167
4969
|
offset = lines[lineIndex].start;
|
|
5168
4970
|
skipSpaces();
|
|
@@ -5173,7 +4975,7 @@ function linkDefinitionAt(source, lines, startIndex) {
|
|
|
5173
4975
|
definitionKey: normalizeAssociationLabel(label),
|
|
5174
4976
|
destination,
|
|
5175
4977
|
label,
|
|
5176
|
-
markerOffset:
|
|
4978
|
+
markerOffset: contentOffset - lines[startIndex].start,
|
|
5177
4979
|
title: void 0
|
|
5178
4980
|
};
|
|
5179
4981
|
if (!closer) return {
|
|
@@ -5226,21 +5028,21 @@ const reassociateReferenceTails = (source, tokens, context) => {
|
|
|
5226
5028
|
let result;
|
|
5227
5029
|
for (let index = 0; index < count; index++) {
|
|
5228
5030
|
const kind = inlineTokenKind(tokens, index);
|
|
5229
|
-
const label = kind ===
|
|
5230
|
-
if (kind !==
|
|
5031
|
+
const label = kind === 22 ? inlineTokenText(source, tokens, index).slice(2, -1) : "";
|
|
5032
|
+
if (kind !== 22 || context.hasDefinition(normalizeAssociationLabel(label))) {
|
|
5231
5033
|
if (result) copyInlineToken(result, tokens, index);
|
|
5232
5034
|
continue;
|
|
5233
5035
|
}
|
|
5234
5036
|
const openerIndex = index + 1;
|
|
5235
|
-
if (openerIndex >= count || inlineTokenKind(tokens, openerIndex) !==
|
|
5037
|
+
if (openerIndex >= count || inlineTokenKind(tokens, openerIndex) !== 20 || inlineTokenStart(tokens, openerIndex) !== inlineTokenEnd(tokens, index)) {
|
|
5236
5038
|
if (result) copyInlineToken(result, tokens, index);
|
|
5237
5039
|
continue;
|
|
5238
5040
|
}
|
|
5239
5041
|
let closerIndex = index + 2;
|
|
5240
5042
|
let nested = false;
|
|
5241
|
-
while (closerIndex < count && inlineTokenKind(tokens, closerIndex) !==
|
|
5043
|
+
while (closerIndex < count && inlineTokenKind(tokens, closerIndex) !== 23) {
|
|
5242
5044
|
const closerKind = inlineTokenKind(tokens, closerIndex);
|
|
5243
|
-
nested ||= closerKind ===
|
|
5045
|
+
nested ||= closerKind === 20 || closerKind === 19;
|
|
5244
5046
|
closerIndex++;
|
|
5245
5047
|
}
|
|
5246
5048
|
if (closerIndex === count || nested) {
|
|
@@ -5259,7 +5061,7 @@ const reassociateReferenceTails = (source, tokens, context) => {
|
|
|
5259
5061
|
const split = splitReferenceTail(tokens, index);
|
|
5260
5062
|
result.push(...split.slice(0, -4));
|
|
5261
5063
|
const offset = inlineTokenEnd(tokens, index) - 1;
|
|
5262
|
-
appendInlineToken(result,
|
|
5064
|
+
appendInlineToken(result, 22, offset, inlineTokenEnd(tokens, closerIndex), inlineTokenFlags(tokens, index));
|
|
5263
5065
|
index = closerIndex;
|
|
5264
5066
|
}
|
|
5265
5067
|
return result ?? tokens;
|
|
@@ -5288,9 +5090,9 @@ const feature$1 = {
|
|
|
5288
5090
|
open: 26,
|
|
5289
5091
|
close: 28
|
|
5290
5092
|
},
|
|
5291
|
-
build(
|
|
5292
|
-
const token = blockToken(
|
|
5293
|
-
const fields = linkDefinitionFields(context.
|
|
5093
|
+
build(tokenStart, context) {
|
|
5094
|
+
const token = blockToken(tokenStart, 26, context);
|
|
5095
|
+
const fields = linkDefinitionFields(context.structure.tokens, token);
|
|
5294
5096
|
return {
|
|
5295
5097
|
type: "definition",
|
|
5296
5098
|
identifier: fields.definitionKey.toLowerCase(),
|
|
@@ -5298,8 +5100,8 @@ const feature$1 = {
|
|
|
5298
5100
|
url: semanticText(fields.destination),
|
|
5299
5101
|
title: fields.title === void 0 ? null : semanticText(fields.title),
|
|
5300
5102
|
position: {
|
|
5301
|
-
start: context.
|
|
5302
|
-
end: blockEnd(
|
|
5103
|
+
start: context.structure.tokens.start(token) + fields.markerOffset,
|
|
5104
|
+
end: blockEnd(tokenStart, context)
|
|
5303
5105
|
}
|
|
5304
5106
|
};
|
|
5305
5107
|
},
|
|
@@ -5309,8 +5111,8 @@ const feature$1 = {
|
|
|
5309
5111
|
}],
|
|
5310
5112
|
starts: [{
|
|
5311
5113
|
codes: [91],
|
|
5312
|
-
start(source, lines, start, out) {
|
|
5313
|
-
const definition = linkDefinitionAt(source, lines, start);
|
|
5114
|
+
start(source, lines, start, out, contentOffset) {
|
|
5115
|
+
const definition = linkDefinitionAt(source, lines, start, contentOffset);
|
|
5314
5116
|
if (!definition) return;
|
|
5315
5117
|
const line = lines[start];
|
|
5316
5118
|
out.push(26, line.start, line.start, { value: definition.fields });
|
|
@@ -5325,71 +5127,71 @@ const feature$1 = {
|
|
|
5325
5127
|
}
|
|
5326
5128
|
}]
|
|
5327
5129
|
},
|
|
5328
|
-
inline: {
|
|
5329
|
-
postTransform: reassociateReferenceTails,
|
|
5130
|
+
inline: {
|
|
5330
5131
|
pairs: [
|
|
5331
5132
|
{
|
|
5332
|
-
opener:
|
|
5333
|
-
closer:
|
|
5334
|
-
open:
|
|
5335
|
-
close:
|
|
5336
|
-
deactivateEarlier: [
|
|
5133
|
+
opener: 20,
|
|
5134
|
+
closer: 21,
|
|
5135
|
+
open: 25,
|
|
5136
|
+
close: 26,
|
|
5137
|
+
deactivateEarlier: [20],
|
|
5337
5138
|
isolateDelimiters: true
|
|
5338
5139
|
},
|
|
5339
5140
|
{
|
|
5340
|
-
opener:
|
|
5341
|
-
closer:
|
|
5342
|
-
open:
|
|
5343
|
-
close:
|
|
5141
|
+
opener: 19,
|
|
5142
|
+
closer: 21,
|
|
5143
|
+
open: 27,
|
|
5144
|
+
close: 28
|
|
5344
5145
|
},
|
|
5345
5146
|
{
|
|
5346
|
-
opener:
|
|
5347
|
-
closer:
|
|
5348
|
-
open:
|
|
5349
|
-
close:
|
|
5350
|
-
deactivateEarlier: [
|
|
5147
|
+
opener: 20,
|
|
5148
|
+
closer: 22,
|
|
5149
|
+
open: 29,
|
|
5150
|
+
close: 30,
|
|
5151
|
+
deactivateEarlier: [20],
|
|
5351
5152
|
isolateDelimiters: true,
|
|
5352
5153
|
activate: activateReference,
|
|
5353
5154
|
splitUnmatchedCloser: splitReferenceTail
|
|
5354
5155
|
},
|
|
5355
5156
|
{
|
|
5356
|
-
opener:
|
|
5357
|
-
closer:
|
|
5358
|
-
open:
|
|
5359
|
-
close:
|
|
5360
|
-
deactivateEarlier: [
|
|
5157
|
+
opener: 20,
|
|
5158
|
+
closer: 23,
|
|
5159
|
+
open: 29,
|
|
5160
|
+
close: 30,
|
|
5161
|
+
deactivateEarlier: [20],
|
|
5361
5162
|
isolateDelimiters: true,
|
|
5362
5163
|
activate: activateReference,
|
|
5363
5164
|
content: {
|
|
5364
5165
|
requireNonWhitespace: true,
|
|
5365
5166
|
maxCharacters: 999,
|
|
5366
|
-
forbidTokens: [
|
|
5167
|
+
forbidTokens: [20, 19]
|
|
5367
5168
|
}
|
|
5368
5169
|
},
|
|
5369
5170
|
{
|
|
5370
|
-
opener:
|
|
5371
|
-
closer:
|
|
5372
|
-
open:
|
|
5373
|
-
close:
|
|
5171
|
+
opener: 19,
|
|
5172
|
+
closer: 22,
|
|
5173
|
+
open: 31,
|
|
5174
|
+
close: 32,
|
|
5374
5175
|
isolateDelimiters: true,
|
|
5375
5176
|
activate: activateReference,
|
|
5376
5177
|
splitUnmatchedCloser: splitReferenceTail
|
|
5377
5178
|
},
|
|
5378
5179
|
{
|
|
5379
|
-
opener:
|
|
5380
|
-
closer:
|
|
5381
|
-
open:
|
|
5382
|
-
close:
|
|
5180
|
+
opener: 19,
|
|
5181
|
+
closer: 23,
|
|
5182
|
+
open: 31,
|
|
5183
|
+
close: 32,
|
|
5383
5184
|
isolateDelimiters: true,
|
|
5384
5185
|
activate: activateReference,
|
|
5385
5186
|
content: {
|
|
5386
5187
|
requireNonWhitespace: true,
|
|
5387
5188
|
maxCharacters: 999,
|
|
5388
|
-
forbidTokens: [
|
|
5189
|
+
forbidTokens: [20, 19]
|
|
5389
5190
|
}
|
|
5390
5191
|
}
|
|
5391
|
-
]
|
|
5392
|
-
|
|
5192
|
+
],
|
|
5193
|
+
rewrite: reassociateReferenceTails
|
|
5194
|
+
}
|
|
5393
5195
|
};
|
|
5394
5196
|
//#endregion
|
|
5395
5197
|
//#region src/profile/features/table.ts
|
|
@@ -5478,142 +5280,127 @@ function emitTableRow(line, cells, out) {
|
|
|
5478
5280
|
}
|
|
5479
5281
|
out.push(32, line.end, line.end);
|
|
5480
5282
|
}
|
|
5481
|
-
function childRules(
|
|
5482
|
-
const
|
|
5283
|
+
function childRules(tokenStart, rule, context) {
|
|
5284
|
+
const structure = context.structure;
|
|
5483
5285
|
const result = [];
|
|
5484
|
-
for (let
|
|
5485
|
-
const child = arena.childAt(nodeId, index);
|
|
5486
|
-
if (child >= 0 && arena.ruleNameOf(child) === rule) result.push({
|
|
5487
|
-
id: child,
|
|
5488
|
-
offset: offset + arena.childRelAt(nodeId, index),
|
|
5489
|
-
tokenBase: tokenBase + arena.childTokRelAt(nodeId, index)
|
|
5490
|
-
});
|
|
5491
|
-
}
|
|
5286
|
+
for (let child = structure.firstChild(tokenStart); child !== noBlockEntry; child = structure.nextChild(tokenStart, child)) if (child >= 0 && structure.ruleNameOf(child) === rule) result.push(child);
|
|
5492
5287
|
return result;
|
|
5493
5288
|
}
|
|
5494
|
-
const buildTableCell = (
|
|
5495
|
-
const open = blockToken(
|
|
5496
|
-
const close = blockToken(
|
|
5289
|
+
const buildTableCell = (tokenStart, context) => {
|
|
5290
|
+
const open = blockToken(tokenStart, 33, context);
|
|
5291
|
+
const close = blockToken(tokenStart, 34, context);
|
|
5497
5292
|
return {
|
|
5498
5293
|
type: "tableCell",
|
|
5499
|
-
children: buildInlineChildren(
|
|
5294
|
+
children: buildInlineChildren(tokenStart, context, true),
|
|
5500
5295
|
position: {
|
|
5501
|
-
start: context.
|
|
5502
|
-
end: context.
|
|
5296
|
+
start: context.structure.tokens.start(open),
|
|
5297
|
+
end: context.structure.tokens.start(close)
|
|
5503
5298
|
}
|
|
5504
5299
|
};
|
|
5505
5300
|
};
|
|
5506
|
-
const buildTableRow = (
|
|
5507
|
-
const open = blockToken(
|
|
5508
|
-
const close = blockToken(
|
|
5301
|
+
const buildTableRow = (tokenStart, context) => {
|
|
5302
|
+
const open = blockToken(tokenStart, 31, context);
|
|
5303
|
+
const close = blockToken(tokenStart, 32, context);
|
|
5509
5304
|
return {
|
|
5510
5305
|
type: "tableRow",
|
|
5511
|
-
children: childRules(
|
|
5306
|
+
children: childRules(tokenStart, "TableCell", context).map((cell) => buildTableCell(cell, context)),
|
|
5512
5307
|
position: {
|
|
5513
|
-
start: context.
|
|
5514
|
-
end: context.
|
|
5308
|
+
start: context.structure.tokens.start(open),
|
|
5309
|
+
end: context.structure.tokens.start(close)
|
|
5515
5310
|
}
|
|
5516
5311
|
};
|
|
5517
5312
|
};
|
|
5518
|
-
function tableAlignment(
|
|
5519
|
-
const
|
|
5313
|
+
function tableAlignment(tokenStart, context) {
|
|
5314
|
+
const structure = context.structure;
|
|
5520
5315
|
const result = [];
|
|
5521
|
-
for (let
|
|
5522
|
-
const child = arena.childAt(nodeId, index);
|
|
5316
|
+
for (let child = structure.firstChild(tokenStart); child !== noBlockEntry; child = structure.nextChild(tokenStart, child)) {
|
|
5523
5317
|
if (child >= 0) continue;
|
|
5524
|
-
const kind =
|
|
5318
|
+
const kind = structure.tokens.kind(structure.leafToken(child));
|
|
5525
5319
|
result.push(kind === 36 ? "left" : kind === 37 ? "right" : kind === 38 ? "center" : null);
|
|
5526
5320
|
}
|
|
5527
5321
|
return result;
|
|
5528
5322
|
}
|
|
5529
|
-
const feature = {
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5323
|
+
const feature = { block: {
|
|
5324
|
+
fallbacks: [(source, lines, start, out, context) => {
|
|
5325
|
+
const delimiterLine = lines[start + 1];
|
|
5326
|
+
if (!delimiterLine || context.startsInterruptingBlock(source, delimiterLine)) return;
|
|
5327
|
+
const delimiter = delimiterAt(source, delimiterLine);
|
|
5328
|
+
const header = delimiter ? tableCellsAt(source, lines[start], true) : void 0;
|
|
5329
|
+
if (!header || !delimiter || header.length !== delimiter.cells.length) return;
|
|
5330
|
+
out.push(29, header[0].start, header[0].start);
|
|
5331
|
+
emitTableRow(lines[start], header, out);
|
|
5332
|
+
for (let index = 0; index < delimiter.cells.length; index++) {
|
|
5333
|
+
const cell = delimiter.cells[index];
|
|
5334
|
+
out.push(delimiter.tokens[index], cell.start, cell.end);
|
|
5335
|
+
}
|
|
5336
|
+
let end = start + 2;
|
|
5337
|
+
while (end < lines.length) {
|
|
5338
|
+
const line = lines[end];
|
|
5339
|
+
if (isBlank(source, line) || !lineIndent(source, line) || context.startsInterruptingBlock(source, line)) break;
|
|
5340
|
+
const cells = tableCellsAt(source, line, false);
|
|
5341
|
+
if (!cells) break;
|
|
5342
|
+
emitTableRow(line, cells, out);
|
|
5343
|
+
end++;
|
|
5344
|
+
}
|
|
5345
|
+
out.push(30, lines[end - 1].end, lines[end - 1].end);
|
|
5346
|
+
return end;
|
|
5347
|
+
}],
|
|
5348
|
+
rules: [
|
|
5349
|
+
{
|
|
5350
|
+
rule: "TableCell",
|
|
5351
|
+
syntax: {
|
|
5352
|
+
kind: "frame",
|
|
5353
|
+
open: 33,
|
|
5354
|
+
close: 34
|
|
5355
|
+
},
|
|
5356
|
+
inlineContent: true
|
|
5357
|
+
},
|
|
5358
|
+
{
|
|
5359
|
+
rule: "TableRow",
|
|
5360
|
+
syntax: {
|
|
5361
|
+
kind: "frame",
|
|
5362
|
+
open: 31,
|
|
5363
|
+
close: 32
|
|
5542
5364
|
}
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5365
|
+
},
|
|
5366
|
+
{
|
|
5367
|
+
rule: "TableDelimiter",
|
|
5368
|
+
syntax: {
|
|
5369
|
+
kind: "group",
|
|
5370
|
+
tokens: [
|
|
5371
|
+
35,
|
|
5372
|
+
36,
|
|
5373
|
+
37,
|
|
5374
|
+
38
|
|
5375
|
+
]
|
|
5551
5376
|
}
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
kind: "frame",
|
|
5560
|
-
open: 33,
|
|
5561
|
-
close: 34
|
|
5562
|
-
},
|
|
5563
|
-
inlineContent: true
|
|
5564
|
-
},
|
|
5565
|
-
{
|
|
5566
|
-
rule: "TableRow",
|
|
5567
|
-
syntax: {
|
|
5568
|
-
kind: "frame",
|
|
5569
|
-
open: 31,
|
|
5570
|
-
close: 32
|
|
5571
|
-
}
|
|
5572
|
-
},
|
|
5573
|
-
{
|
|
5574
|
-
rule: "TableDelimiter",
|
|
5575
|
-
syntax: {
|
|
5576
|
-
kind: "group",
|
|
5577
|
-
tokens: [
|
|
5578
|
-
35,
|
|
5579
|
-
36,
|
|
5580
|
-
37,
|
|
5581
|
-
38
|
|
5582
|
-
]
|
|
5583
|
-
}
|
|
5377
|
+
},
|
|
5378
|
+
{
|
|
5379
|
+
rule: "Table",
|
|
5380
|
+
syntax: {
|
|
5381
|
+
kind: "block",
|
|
5382
|
+
open: 29,
|
|
5383
|
+
close: 30
|
|
5584
5384
|
},
|
|
5585
|
-
{
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
align: tableAlignment(delimiter.id, delimiter.tokenBase, context),
|
|
5601
|
-
children: rows,
|
|
5602
|
-
position: {
|
|
5603
|
-
start: context.arena.tokens.start(open),
|
|
5604
|
-
end: context.arena.tokens.start(close)
|
|
5605
|
-
}
|
|
5606
|
-
};
|
|
5607
|
-
}
|
|
5385
|
+
build(tokenStart, context) {
|
|
5386
|
+
const open = blockToken(tokenStart, 29, context);
|
|
5387
|
+
const close = blockToken(tokenStart, 30, context);
|
|
5388
|
+
const rows = childRules(tokenStart, "TableRow", context).map((row) => buildTableRow(row, context));
|
|
5389
|
+
const delimiter = childRules(tokenStart, "TableDelimiter", context)[0];
|
|
5390
|
+
if (!delimiter) throw new Error("Table syntax does not contain a delimiter");
|
|
5391
|
+
return {
|
|
5392
|
+
type: "table",
|
|
5393
|
+
align: tableAlignment(delimiter, context),
|
|
5394
|
+
children: rows,
|
|
5395
|
+
position: {
|
|
5396
|
+
start: context.structure.tokens.start(open),
|
|
5397
|
+
end: context.structure.tokens.start(close)
|
|
5398
|
+
}
|
|
5399
|
+
};
|
|
5608
5400
|
}
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
kind: "leaf",
|
|
5613
|
-
token: 2,
|
|
5614
|
-
build: buildInlineCode
|
|
5615
|
-
}] }
|
|
5616
|
-
};
|
|
5401
|
+
}
|
|
5402
|
+
]
|
|
5403
|
+
} };
|
|
5617
5404
|
//#endregion
|
|
5618
5405
|
//#region src/profile/index.ts
|
|
5619
5406
|
function compileProfile(options = {}) {
|
|
@@ -5626,13 +5413,14 @@ function compileProfile(options = {}) {
|
|
|
5626
5413
|
feature$6
|
|
5627
5414
|
];
|
|
5628
5415
|
if (options.footnote) features.push(feature$10);
|
|
5629
|
-
features.push(feature$1);
|
|
5630
5416
|
if (options.frontmatter) features.unshift(feature$8(typeof options.frontmatter === "object" ? options.frontmatter.marker : "-"));
|
|
5631
5417
|
if (options.table) features.push(feature);
|
|
5632
5418
|
if (options.math) features.push(feature$3(options.math));
|
|
5633
5419
|
features.push(feature$2, feature$13, feature$9(options.strikethrough), feature$5);
|
|
5420
|
+
if (options.attributes) features.push(feature$17);
|
|
5421
|
+
if (options.binding) features.push(feature$16);
|
|
5634
5422
|
if (options.component) features.push(feature$11);
|
|
5635
|
-
|
|
5423
|
+
features.push(feature$1);
|
|
5636
5424
|
const blockFeatures = [];
|
|
5637
5425
|
const inlineFeatures = [];
|
|
5638
5426
|
for (const feature of features) {
|
|
@@ -5649,13 +5437,13 @@ function compileProfile(options = {}) {
|
|
|
5649
5437
|
function createParser(options) {
|
|
5650
5438
|
const profile = compileProfile(options?.features);
|
|
5651
5439
|
let blockScanner;
|
|
5652
|
-
let
|
|
5440
|
+
let blockStructure;
|
|
5653
5441
|
return {
|
|
5654
5442
|
createDocument: (source) => new DocumentImpl(source, profile),
|
|
5655
5443
|
parse: (source) => {
|
|
5656
5444
|
blockScanner ??= new BlockScanner(profile.block);
|
|
5657
|
-
|
|
5658
|
-
return DocumentImpl.parse(source, profile, blockScanner,
|
|
5445
|
+
blockStructure ??= new BlockStructure(profile.block.schema, blockScanner.tokens);
|
|
5446
|
+
return DocumentImpl.parse(source, profile, blockScanner, blockStructure);
|
|
5659
5447
|
}
|
|
5660
5448
|
};
|
|
5661
5449
|
}
|