satorigear 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -68
- package/dist/index.mjs +1207 -1278
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { decodeString } from "micromark-util-decode-string";
|
|
2
|
+
import { htmlBlockNames, htmlRawNames } from "micromark-util-html-tag-name";
|
|
2
3
|
//#region src/block/lines.ts
|
|
3
4
|
var BlockLines = class BlockLines {
|
|
4
5
|
#fieldLength = 0;
|
|
5
6
|
#fields;
|
|
7
|
+
#locatorField = 0;
|
|
6
8
|
#relativeStart = Infinity;
|
|
7
9
|
#sourceLength;
|
|
10
|
+
#lineEndingsNormalized = true;
|
|
8
11
|
constructor(sourceLength = 0, lineCapacity = 4) {
|
|
9
12
|
this.#sourceLength = sourceLength;
|
|
10
13
|
this.#fields = new Int32Array(lineCapacity * 4);
|
|
@@ -13,7 +16,7 @@ var BlockLines = class BlockLines {
|
|
|
13
16
|
const sourceLength = source.length;
|
|
14
17
|
if (start > 0 || limit < sourceLength) source = source.slice(start, limit);
|
|
15
18
|
const lines = new BlockLines(sourceLength, Math.min(source.length + 15 >>> 4, 16384));
|
|
16
|
-
BlockLines.#scan(source, lines);
|
|
19
|
+
lines.#fieldLength = BlockLines.#scan(source, lines);
|
|
17
20
|
if (start !== 0) lines.#shiftPositions(0, start);
|
|
18
21
|
return lines;
|
|
19
22
|
}
|
|
@@ -22,6 +25,7 @@ var BlockLines = class BlockLines {
|
|
|
22
25
|
let start = 0;
|
|
23
26
|
let lineFeed = source.indexOf("\n");
|
|
24
27
|
let carriageReturn = source.indexOf("\r");
|
|
28
|
+
lines.#lineEndingsNormalized = carriageReturn < 0;
|
|
25
29
|
let field = 0;
|
|
26
30
|
let fields = lines.#fields;
|
|
27
31
|
while (start < limit) {
|
|
@@ -44,7 +48,7 @@ var BlockLines = class BlockLines {
|
|
|
44
48
|
field += 4;
|
|
45
49
|
start = next;
|
|
46
50
|
}
|
|
47
|
-
|
|
51
|
+
return field;
|
|
48
52
|
}
|
|
49
53
|
get length() {
|
|
50
54
|
return this.#fieldLength / 4;
|
|
@@ -75,43 +79,50 @@ var BlockLines = class BlockLines {
|
|
|
75
79
|
return low;
|
|
76
80
|
}
|
|
77
81
|
locator() {
|
|
78
|
-
|
|
82
|
+
this.#locatorField = 0;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
normalizeLineEndings(value) {
|
|
86
|
+
return this.#lineEndingsNormalized || !value.includes("\r") ? value : value.replace(/\r\n|\r/g, "\n");
|
|
87
|
+
}
|
|
88
|
+
locationAt(offset) {
|
|
79
89
|
const fieldLength = this.#fieldLength;
|
|
80
|
-
|
|
81
|
-
if (fieldLength === 0) return (offset) => ({
|
|
90
|
+
if (fieldLength === 0) return {
|
|
82
91
|
line: 1,
|
|
83
92
|
column: 1,
|
|
84
93
|
offset
|
|
85
|
-
}
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
let start = fields[field + 0];
|
|
107
|
-
if (start < 0) start += positionBase;
|
|
108
|
-
return {
|
|
109
|
-
line: line + 1,
|
|
110
|
-
column: offset - start + 1,
|
|
111
|
-
offset
|
|
112
|
-
};
|
|
94
|
+
};
|
|
95
|
+
const fields = this.#fields;
|
|
96
|
+
const sourceLength = this.#sourceLength;
|
|
97
|
+
if (offset === sourceLength && this.#position(fields[fieldLength - 4 + 1]) < sourceLength) return {
|
|
98
|
+
line: fieldLength / 4 + 1,
|
|
99
|
+
column: 1,
|
|
100
|
+
offset
|
|
101
|
+
};
|
|
102
|
+
let field = this.#locatorField;
|
|
103
|
+
let start = this.#position(fields[field + 0]);
|
|
104
|
+
while (field + 4 < fieldLength) {
|
|
105
|
+
const nextStart = this.#position(fields[field + 4 + 0]);
|
|
106
|
+
if (nextStart > offset) break;
|
|
107
|
+
field += 4;
|
|
108
|
+
start = nextStart;
|
|
109
|
+
}
|
|
110
|
+
this.#locatorField = field;
|
|
111
|
+
return {
|
|
112
|
+
line: field / 4 + 1,
|
|
113
|
+
column: offset - start + 1,
|
|
114
|
+
offset
|
|
113
115
|
};
|
|
114
116
|
}
|
|
117
|
+
positionAt(start, end) {
|
|
118
|
+
return {
|
|
119
|
+
start: this.locationAt(start),
|
|
120
|
+
end: this.locationAt(end)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
physicallyContiguous() {
|
|
124
|
+
return this.#sourceLength > 0;
|
|
125
|
+
}
|
|
115
126
|
push(start, end, next, prefixColumns = 0, lazy = false) {
|
|
116
127
|
const field = this.#fieldLength;
|
|
117
128
|
let fields = this.#fields;
|
|
@@ -129,6 +140,31 @@ var BlockLines = class BlockLines {
|
|
|
129
140
|
pushFrom(lines, index, start = lines.start(index), prefixColumns = lines.prefixColumns(index), lazy = lines.lazy(index)) {
|
|
130
141
|
this.push(start, lines.end(index), lines.next(index), prefixColumns, lazy);
|
|
131
142
|
}
|
|
143
|
+
pushAfterColumns(source, lines, index, columns) {
|
|
144
|
+
let offset = lines.start(index);
|
|
145
|
+
let consumed = lines.prefixColumns(index);
|
|
146
|
+
const end = lines.end(index);
|
|
147
|
+
while (offset < end && consumed < columns) {
|
|
148
|
+
const code = source.charCodeAt(offset);
|
|
149
|
+
if (code === 32) consumed++;
|
|
150
|
+
else if (code === 9) consumed += 4 - consumed % 4;
|
|
151
|
+
else break;
|
|
152
|
+
offset++;
|
|
153
|
+
}
|
|
154
|
+
if (offset === end) return 0;
|
|
155
|
+
if (consumed < columns) return -1;
|
|
156
|
+
const contentOffset = offset;
|
|
157
|
+
const prefixColumns = consumed - columns;
|
|
158
|
+
while (offset < end) {
|
|
159
|
+
const code = source.charCodeAt(offset);
|
|
160
|
+
if (code !== 32 && code !== 9) {
|
|
161
|
+
this.pushFrom(lines, index, contentOffset, prefixColumns);
|
|
162
|
+
return 1;
|
|
163
|
+
}
|
|
164
|
+
offset++;
|
|
165
|
+
}
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
132
168
|
pushLazy(lines, index) {
|
|
133
169
|
this.pushFrom(lines, index, void 0, void 0, true);
|
|
134
170
|
}
|
|
@@ -145,6 +181,7 @@ var BlockLines = class BlockLines {
|
|
|
145
181
|
const fieldEnd = end * 4;
|
|
146
182
|
result.#fields = this.#fields.slice(fieldStart, fieldEnd);
|
|
147
183
|
result.#fieldLength = fieldEnd - fieldStart;
|
|
184
|
+
result.#lineEndingsNormalized = this.#lineEndingsNormalized;
|
|
148
185
|
if (this.#relativeStart < end) result.#relativeStart = Math.max(0, this.#relativeStart - start);
|
|
149
186
|
return result;
|
|
150
187
|
}
|
|
@@ -157,12 +194,14 @@ var BlockLines = class BlockLines {
|
|
|
157
194
|
if (delta === 0 && changed.length === suffix - prefixEnd) {
|
|
158
195
|
const next = this.slice();
|
|
159
196
|
for (let index = 0; index < changed.length; index++) next.#setAbsoluteFrom(prefixEnd + index, changed, index);
|
|
197
|
+
next.#lineEndingsNormalized &&= changed.#lineEndingsNormalized;
|
|
160
198
|
return next;
|
|
161
199
|
}
|
|
162
200
|
const next = new BlockLines(nextSource.length, prefixEnd + changed.length + this.length - suffix);
|
|
163
201
|
next.#appendAbsoluteRange(this, 0, prefixEnd);
|
|
164
202
|
next.#appendRawRange(changed, 0, changed.length);
|
|
165
203
|
next.#appendRelativeRange(this, suffix);
|
|
204
|
+
next.#lineEndingsNormalized = this.#lineEndingsNormalized && changed.#lineEndingsNormalized;
|
|
166
205
|
return next;
|
|
167
206
|
}
|
|
168
207
|
pop() {
|
|
@@ -237,18 +276,23 @@ function indentOffset(source, lines, index) {
|
|
|
237
276
|
let offset = lines.start(index);
|
|
238
277
|
const limit = offset + 3 - lines.prefixColumns(index);
|
|
239
278
|
const end = lines.end(index);
|
|
240
|
-
while (offset < end && offset < limit && source
|
|
279
|
+
while (offset < end && offset < limit && source.charCodeAt(offset) === 32) offset++;
|
|
241
280
|
return offset;
|
|
242
281
|
}
|
|
243
282
|
function lineIndentOffset(source, lines, index) {
|
|
244
283
|
let offset = lines.start(index);
|
|
245
284
|
const limit = offset + 3 - lines.prefixColumns(index);
|
|
246
285
|
const end = lines.end(index);
|
|
247
|
-
while (offset < end && offset < limit && source
|
|
248
|
-
|
|
286
|
+
while (offset < end && offset < limit && source.charCodeAt(offset) === 32) offset++;
|
|
287
|
+
if (offset > limit || offset === end) return -1;
|
|
288
|
+
const code = source.charCodeAt(offset);
|
|
289
|
+
return code === 32 || code === 9 ? -1 : offset;
|
|
249
290
|
}
|
|
250
291
|
function isBlank(source, lines, index) {
|
|
251
|
-
for (let offset = lines.start(index), end = lines.end(index); offset < end; offset++)
|
|
292
|
+
for (let offset = lines.start(index), end = lines.end(index); offset < end; offset++) {
|
|
293
|
+
const code = source.charCodeAt(offset);
|
|
294
|
+
if (code !== 32 && code !== 9) return false;
|
|
295
|
+
}
|
|
252
296
|
return true;
|
|
253
297
|
}
|
|
254
298
|
function physicalColumnAt(source, offset) {
|
|
@@ -284,24 +328,6 @@ function logicalLine(source, lines, index) {
|
|
|
284
328
|
}
|
|
285
329
|
return result + source.slice(offset, lines.next(index));
|
|
286
330
|
}
|
|
287
|
-
function contentAfterColumns(source, lines, index, columns) {
|
|
288
|
-
let offset = lines.start(index);
|
|
289
|
-
let consumed = lines.prefixColumns(index);
|
|
290
|
-
const end = lines.end(index);
|
|
291
|
-
while (offset < end && consumed < columns) {
|
|
292
|
-
if (source[offset] === " ") consumed++;
|
|
293
|
-
else if (source[offset] === " ") consumed += 4 - consumed % 4;
|
|
294
|
-
else break;
|
|
295
|
-
offset++;
|
|
296
|
-
}
|
|
297
|
-
if (consumed >= columns) return {
|
|
298
|
-
offset,
|
|
299
|
-
prefixColumns: consumed - columns
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
function normalizeLines(value) {
|
|
303
|
-
return value.includes("\r") ? value.replace(/\r\n|\r/g, "\n") : value;
|
|
304
|
-
}
|
|
305
331
|
function removeIndent(value, columns) {
|
|
306
332
|
let offset = 0;
|
|
307
333
|
let consumed = 0;
|
|
@@ -319,13 +345,21 @@ const emptyArray = [];
|
|
|
319
345
|
const emptySet = new Set();
|
|
320
346
|
//#endregion
|
|
321
347
|
//#region src/block/tokens.ts
|
|
322
|
-
|
|
348
|
+
function copyMetadata(target, source, start, end, targetStart) {
|
|
349
|
+
end = Math.min(end, source.length);
|
|
350
|
+
for (let read = start, write = targetStart; read < end; read++, write++) {
|
|
351
|
+
const value = source[read];
|
|
352
|
+
if (value) target[write] = value;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
323
355
|
var BlockTokenStream = class {
|
|
324
356
|
#definitionCounts;
|
|
325
357
|
#definitionMembershipChanges;
|
|
326
358
|
#fieldLength;
|
|
327
359
|
#fields;
|
|
360
|
+
#groupField = -1;
|
|
328
361
|
#metadata;
|
|
362
|
+
#opens = [];
|
|
329
363
|
#relativeStart;
|
|
330
364
|
#sourceLength;
|
|
331
365
|
constructor(sourceLength = 0) {
|
|
@@ -338,12 +372,14 @@ var BlockTokenStream = class {
|
|
|
338
372
|
this.#definitionCounts?.clear();
|
|
339
373
|
this.#definitionMembershipChanges?.clear();
|
|
340
374
|
this.#fieldLength = 0;
|
|
375
|
+
this.#groupField = -1;
|
|
341
376
|
this.#metadata = void 0;
|
|
377
|
+
this.#opens.length = 0;
|
|
342
378
|
this.#relativeStart = Number.POSITIVE_INFINITY;
|
|
343
379
|
this.#sourceLength = sourceLength;
|
|
344
380
|
}
|
|
345
381
|
get length() {
|
|
346
|
-
return this.#fieldLength /
|
|
382
|
+
return this.#fieldLength / 4;
|
|
347
383
|
}
|
|
348
384
|
get sourceLength() {
|
|
349
385
|
return this.#sourceLength;
|
|
@@ -351,56 +387,49 @@ var BlockTokenStream = class {
|
|
|
351
387
|
hasDefinition(key) {
|
|
352
388
|
return this.#definitionCounts?.has(key) === true;
|
|
353
389
|
}
|
|
354
|
-
|
|
390
|
+
hasDefinitions() {
|
|
391
|
+
return !!this.#definitionCounts?.size;
|
|
392
|
+
}
|
|
393
|
+
push(kind, start, end, meta, role) {
|
|
355
394
|
const field = this.#fieldLength;
|
|
356
|
-
this.#ensureCapacity(field +
|
|
357
|
-
this.#fields[field] = kind;
|
|
395
|
+
this.#ensureCapacity(field + 4);
|
|
396
|
+
this.#fields[field + 0] = kind;
|
|
358
397
|
this.#fields[field + 1] = start;
|
|
359
398
|
this.#fields[field + 2] = end;
|
|
360
399
|
this.#fields[field + 3] = 0;
|
|
361
|
-
this.#fieldLength +=
|
|
400
|
+
this.#fieldLength += 4;
|
|
362
401
|
if (meta) {
|
|
363
|
-
this.#metadata ??=
|
|
364
|
-
this.#metadata
|
|
402
|
+
this.#metadata ??= [];
|
|
403
|
+
this.#metadata[this.length - 1] = meta;
|
|
365
404
|
const definitionKey = meta.definitionKey;
|
|
366
405
|
if (definitionKey !== void 0) this.#updateDefinitionCount(definitionKey, 1, false);
|
|
367
406
|
}
|
|
407
|
+
const encodedRole = role ?? kind;
|
|
408
|
+
if (encodedRole >= 64) this.#indexToken(field, encodedRole);
|
|
368
409
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
let close = 0;
|
|
374
|
-
for (let field = 0; field < fieldLength; field += blockTokenStride) {
|
|
375
|
-
const kind = fields[field];
|
|
376
|
-
const rule = rules[kind];
|
|
377
|
-
if (rule && rule.close !== 0) {
|
|
378
|
-
opens.push(field);
|
|
379
|
-
fields[field + 3] = close;
|
|
380
|
-
close = rule.close;
|
|
381
|
-
continue;
|
|
382
|
-
}
|
|
383
|
-
if (rule && !rule.block) {
|
|
384
|
-
const start = field;
|
|
385
|
-
do
|
|
386
|
-
field += blockTokenStride;
|
|
387
|
-
while (field < fieldLength && rules[fields[field]] === rule);
|
|
388
|
-
fields[start + 3] = (field - start) / blockTokenStride;
|
|
389
|
-
field -= blockTokenStride;
|
|
390
|
-
continue;
|
|
391
|
-
}
|
|
392
|
-
if (close === kind) {
|
|
393
|
-
const open = opens.pop();
|
|
394
|
-
close = fields[open + 3];
|
|
395
|
-
fields[open + 3] = (field - open) / blockTokenStride + 1;
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
if (rule) fields[field + 3] = 1;
|
|
410
|
+
#indexToken(field, encodedRole) {
|
|
411
|
+
if (encodedRole < 192) {
|
|
412
|
+
this.#opens.push(field);
|
|
413
|
+
return;
|
|
399
414
|
}
|
|
400
|
-
if (
|
|
415
|
+
if (encodedRole < 256) {
|
|
416
|
+
const open = this.#opens.pop();
|
|
417
|
+
this.#fields[open + 3] = (field - open) / 4 + 1;
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (encodedRole < 320) {
|
|
421
|
+
this.#fields[field + 3] = 1;
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const group = this.#groupField;
|
|
425
|
+
const previous = field - 4;
|
|
426
|
+
if (group < 0 || previous < 0 || this.#fields[previous + 0] < 320) {
|
|
427
|
+
this.#groupField = field;
|
|
428
|
+
this.#fields[field + 3] = 1;
|
|
429
|
+
} else this.#fields[group + 3]++;
|
|
401
430
|
}
|
|
402
431
|
nodeLength(index) {
|
|
403
|
-
return this.#fields[index *
|
|
432
|
+
return this.#fields[index * 4 + 3];
|
|
404
433
|
}
|
|
405
434
|
equalsAfterShift(index, next, nextIndex, delta, damageStart, damageEnd) {
|
|
406
435
|
const start = this.start(index);
|
|
@@ -408,11 +437,10 @@ var BlockTokenStream = class {
|
|
|
408
437
|
const nextStart = next.start(nextIndex);
|
|
409
438
|
const nextEnd = next.end(nextIndex);
|
|
410
439
|
if (this.kind(index) !== next.kind(nextIndex) || start + delta !== nextStart || end + delta !== nextEnd) return false;
|
|
411
|
-
const metadata = this.#metadata?.
|
|
412
|
-
const nextMetadata = next.#metadata?.
|
|
440
|
+
const metadata = this.#metadata?.[index];
|
|
441
|
+
const nextMetadata = next.#metadata?.[nextIndex];
|
|
413
442
|
if (metadata !== nextMetadata) {
|
|
414
443
|
if (metadata?.definitionKey !== nextMetadata?.definitionKey) return false;
|
|
415
|
-
if ((metadata?.contentEndOffset ?? end - start) !== (nextMetadata?.contentEndOffset ?? nextEnd - nextStart)) return false;
|
|
416
444
|
const value = metadata?.value;
|
|
417
445
|
const nextValue = nextMetadata?.value;
|
|
418
446
|
if (value !== nextValue && (value === null || typeof value !== "object" || nextValue === null || typeof nextValue !== "object")) return false;
|
|
@@ -437,8 +465,8 @@ var BlockTokenStream = class {
|
|
|
437
465
|
const oldEnd = end - stableSuffixLength;
|
|
438
466
|
const newEnd = start + replacementLength - stableSuffixLength;
|
|
439
467
|
this.#definitionMembershipChanges?.clear();
|
|
440
|
-
for (let index = oldStart; index < oldEnd; index++) this.#updateDefinitionCount(this.#metadata?.
|
|
441
|
-
for (let index = stablePrefixLength; index < replacementLength - stableSuffixLength; index++) this.#updateDefinitionCount(replacement.#metadata?.
|
|
468
|
+
for (let index = oldStart; index < oldEnd; index++) this.#updateDefinitionCount(this.#metadata?.[index]?.definitionKey, -1, true);
|
|
469
|
+
for (let index = stablePrefixLength; index < replacementLength - stableSuffixLength; index++) this.#updateDefinitionCount(replacement.#metadata?.[index]?.definitionKey, 1, true);
|
|
442
470
|
const change = {
|
|
443
471
|
definitionMembershipChanges: this.#definitionMembershipChanges ?? emptySet,
|
|
444
472
|
newEnd,
|
|
@@ -446,30 +474,30 @@ var BlockTokenStream = class {
|
|
|
446
474
|
oldStart
|
|
447
475
|
};
|
|
448
476
|
if (this.#relativeStart < end) for (let index = this.#relativeStart; index < end; index++) {
|
|
449
|
-
const field = index *
|
|
477
|
+
const field = index * 4;
|
|
450
478
|
this.#fields[field + 1] += this.#sourceLength + 1;
|
|
451
479
|
this.#fields[field + 2] += this.#sourceLength + 1;
|
|
452
480
|
}
|
|
453
481
|
else if (this.#relativeStart > end) {
|
|
454
482
|
const relativeEnd = Math.min(this.#relativeStart, previousLength);
|
|
455
483
|
for (let index = end; index < relativeEnd; index++) {
|
|
456
|
-
const field = index *
|
|
484
|
+
const field = index * 4;
|
|
457
485
|
this.#fields[field + 1] -= this.#sourceLength + 1;
|
|
458
486
|
this.#fields[field + 2] -= this.#sourceLength + 1;
|
|
459
487
|
}
|
|
460
488
|
}
|
|
461
489
|
if (end === previousLength) {
|
|
462
|
-
const fieldStart = start *
|
|
490
|
+
const fieldStart = start * 4;
|
|
463
491
|
const fieldEnd = fieldStart + replacement.#fieldLength;
|
|
464
492
|
this.#ensureCapacity(fieldEnd);
|
|
465
493
|
this.#fields.set(replacement.#fields.subarray(0, replacement.#fieldLength), fieldStart);
|
|
466
494
|
this.#fieldLength = fieldEnd;
|
|
467
495
|
} else if (replacementLength === replacedLength) {
|
|
468
|
-
const fieldStart = start *
|
|
496
|
+
const fieldStart = start * 4;
|
|
469
497
|
this.#fields.set(replacement.#fields.subarray(0, replacement.#fieldLength), fieldStart);
|
|
470
498
|
} else {
|
|
471
|
-
const fieldStart = start *
|
|
472
|
-
const oldFieldEnd = end *
|
|
499
|
+
const fieldStart = start * 4;
|
|
500
|
+
const oldFieldEnd = end * 4;
|
|
473
501
|
const newFieldEnd = fieldStart + replacement.#fieldLength;
|
|
474
502
|
const nextFieldLength = this.#fieldLength + newFieldEnd - oldFieldEnd;
|
|
475
503
|
this.#ensureCapacity(nextFieldLength);
|
|
@@ -479,21 +507,21 @@ var BlockTokenStream = class {
|
|
|
479
507
|
}
|
|
480
508
|
const indexDelta = replacementLength - replacedLength;
|
|
481
509
|
if (end === previousLength || indexDelta === 0) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
if (
|
|
487
|
-
const metadata = this.#metadata ??= new Map();
|
|
488
|
-
for (const [index, value] of replacement.#metadata) metadata.set(start + index, value);
|
|
489
|
-
}
|
|
490
|
-
if (this.#metadata?.size === 0) this.#metadata = void 0;
|
|
510
|
+
const metadata = this.#metadata;
|
|
511
|
+
if (metadata) metadata.fill(void 0, start, end);
|
|
512
|
+
const replacementMetadata = replacement.#metadata;
|
|
513
|
+
if (replacementMetadata) copyMetadata(this.#metadata ??= [], replacementMetadata, 0, replacementMetadata.length, start);
|
|
514
|
+
if (end === previousLength && this.#metadata) this.#metadata.length = Math.min(this.#metadata.length, start + replacementLength);
|
|
491
515
|
} else {
|
|
492
|
-
const metadata =
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
516
|
+
const metadata = [];
|
|
517
|
+
const previousMetadata = this.#metadata;
|
|
518
|
+
if (previousMetadata) {
|
|
519
|
+
copyMetadata(metadata, previousMetadata, 0, start, 0);
|
|
520
|
+
copyMetadata(metadata, previousMetadata, end, previousMetadata.length, end + indexDelta);
|
|
521
|
+
}
|
|
522
|
+
const replacementMetadata = replacement.#metadata;
|
|
523
|
+
if (replacementMetadata) copyMetadata(metadata, replacementMetadata, 0, replacementMetadata.length, start);
|
|
524
|
+
this.#metadata = metadata.length > 0 ? metadata : void 0;
|
|
497
525
|
}
|
|
498
526
|
const newSuffixStart = start + replacementLength;
|
|
499
527
|
this.#relativeStart = newSuffixStart < this.length ? newSuffixStart : Number.POSITIVE_INFINITY;
|
|
@@ -501,42 +529,45 @@ var BlockTokenStream = class {
|
|
|
501
529
|
return change;
|
|
502
530
|
}
|
|
503
531
|
truncate(length) {
|
|
504
|
-
this.#
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
532
|
+
this.#groupField = -1;
|
|
533
|
+
this.#fieldLength = length * 4;
|
|
534
|
+
const metadata = this.#metadata;
|
|
535
|
+
if (metadata) {
|
|
536
|
+
for (let index = length; index < metadata.length; index++) {
|
|
537
|
+
const value = metadata[index];
|
|
538
|
+
if (value) this.#updateDefinitionCount(value.definitionKey, -1, false);
|
|
509
539
|
}
|
|
510
|
-
|
|
540
|
+
metadata.length = Math.min(metadata.length, length);
|
|
511
541
|
}
|
|
512
542
|
}
|
|
513
543
|
kind(index) {
|
|
514
|
-
return this.#fields[index *
|
|
544
|
+
return this.#fields[index * 4];
|
|
515
545
|
}
|
|
516
546
|
setKind(index, kind) {
|
|
517
|
-
this.#fields[index *
|
|
547
|
+
this.#fields[index * 4] = kind;
|
|
518
548
|
}
|
|
519
549
|
start(index) {
|
|
520
|
-
return this.#position(this.#fields[index *
|
|
550
|
+
return this.#position(this.#fields[index * 4 + 1]);
|
|
521
551
|
}
|
|
522
552
|
setStart(index, start) {
|
|
523
|
-
this.#fields[index *
|
|
553
|
+
this.#fields[index * 4 + 1] = start;
|
|
524
554
|
}
|
|
525
555
|
end(index) {
|
|
526
|
-
return this.#position(this.#fields[index *
|
|
556
|
+
return this.#position(this.#fields[index * 4 + 2]);
|
|
527
557
|
}
|
|
528
|
-
contentEnd(index) {
|
|
529
|
-
const
|
|
530
|
-
|
|
558
|
+
contentEnd(source, index) {
|
|
559
|
+
const end = this.end(index);
|
|
560
|
+
const last = source.charCodeAt(end - 1);
|
|
561
|
+
return last === 10 ? end - (source.charCodeAt(end - 2) === 13 ? 2 : 1) : last === 13 ? end - 1 : end;
|
|
531
562
|
}
|
|
532
563
|
text(source, index) {
|
|
533
|
-
return this.#metadata?.
|
|
564
|
+
return this.#metadata?.[index]?.text ?? source.slice(this.start(index), this.end(index));
|
|
534
565
|
}
|
|
535
566
|
value(index) {
|
|
536
|
-
return this.#metadata?.
|
|
567
|
+
return this.#metadata?.[index]?.value;
|
|
537
568
|
}
|
|
538
569
|
definitionKey(index) {
|
|
539
|
-
return this.#metadata?.
|
|
570
|
+
return this.#metadata?.[index]?.definitionKey;
|
|
540
571
|
}
|
|
541
572
|
#updateDefinitionCount(key, delta, trackMembership) {
|
|
542
573
|
if (key === void 0) return;
|
|
@@ -567,17 +598,18 @@ function appendLogicalToken(out, kind, source, lines, start, end, value) {
|
|
|
567
598
|
const tokenStart = lines.start(start);
|
|
568
599
|
const lastLine = end - 1;
|
|
569
600
|
const tokenEnd = lines.next(lastLine);
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
601
|
+
let canSliceSource = lines.physicallyContiguous();
|
|
602
|
+
if (!canSliceSource) {
|
|
603
|
+
const previous = source[tokenStart - 1];
|
|
604
|
+
canSliceSource = lines.prefixColumns(start) === 0 && (tokenStart === 0 || previous === "\n" || previous === "\r");
|
|
605
|
+
let previousLineEnd = lines.next(start);
|
|
606
|
+
for (let line = start + 1; canSliceSource && line < end; line++) {
|
|
607
|
+
if (lines.prefixColumns(line) !== 0 || lines.start(line) !== previousLineEnd) {
|
|
608
|
+
canSliceSource = false;
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
previousLineEnd = lines.next(line);
|
|
612
|
+
}
|
|
581
613
|
}
|
|
582
614
|
let text;
|
|
583
615
|
if (!canSliceSource) {
|
|
@@ -585,16 +617,14 @@ function appendLogicalToken(out, kind, source, lines, start, end, value) {
|
|
|
585
617
|
for (let index = 0; index < count; index++) logicalLines[index] = logicalLine(source, lines, start + index);
|
|
586
618
|
text = logicalLines.join("");
|
|
587
619
|
}
|
|
588
|
-
out.push(kind, tokenStart, tokenEnd,
|
|
589
|
-
contentEndOffset,
|
|
620
|
+
out.push(kind, tokenStart, tokenEnd, text === void 0 && value === void 0 ? void 0 : {
|
|
590
621
|
text,
|
|
591
622
|
value
|
|
592
623
|
});
|
|
593
624
|
}
|
|
594
625
|
//#endregion
|
|
595
626
|
//#region src/block/scanner.ts
|
|
596
|
-
function scanBlock(profile, context, source, lines, start, out) {
|
|
597
|
-
const contentOffset = lineIndentOffset(source, lines, start);
|
|
627
|
+
function scanBlock(profile, context, source, lines, start, contentOffset, out) {
|
|
598
628
|
const starts = profile.starts[contentOffset < 0 ? -1 : source.charCodeAt(contentOffset)];
|
|
599
629
|
if (starts) for (const resolve of starts) {
|
|
600
630
|
const end = resolve(source, lines, start, contentOffset, out, context);
|
|
@@ -608,13 +638,23 @@ function scanBlock(profile, context, source, lines, start, out) {
|
|
|
608
638
|
}
|
|
609
639
|
function scanBlockLines(profile, context, source, lines, out, visit) {
|
|
610
640
|
for (let index = 0; index < lines.length;) {
|
|
611
|
-
|
|
641
|
+
let contentOffset = lines.start(index);
|
|
642
|
+
const lineEnd = lines.end(index);
|
|
643
|
+
let columns = lines.prefixColumns(index);
|
|
644
|
+
while (contentOffset < lineEnd) {
|
|
645
|
+
const code = source.charCodeAt(contentOffset);
|
|
646
|
+
if (code !== 32 && code !== 9) break;
|
|
647
|
+
columns += code === 32 ? 1 : 4 - columns % 4;
|
|
648
|
+
contentOffset++;
|
|
649
|
+
}
|
|
650
|
+
if (contentOffset === lineEnd) {
|
|
612
651
|
index++;
|
|
613
652
|
continue;
|
|
614
653
|
}
|
|
654
|
+
if (columns > 3) contentOffset = -1;
|
|
615
655
|
const lineStart = index;
|
|
616
656
|
const tokenStart = out.length;
|
|
617
|
-
index = scanBlock(profile, context, source, lines, index, out);
|
|
657
|
+
index = scanBlock(profile, context, source, lines, index, contentOffset, out);
|
|
618
658
|
if (visit(lineStart, index, tokenStart, out.length)) return;
|
|
619
659
|
}
|
|
620
660
|
}
|
|
@@ -647,7 +687,7 @@ var BlockScanContext = class {
|
|
|
647
687
|
contentIndex = 0;
|
|
648
688
|
continue;
|
|
649
689
|
}
|
|
650
|
-
return !
|
|
690
|
+
return !this.startsInterruptingBlock(source, contentLines, contentIndex, contentOffset);
|
|
651
691
|
}
|
|
652
692
|
}
|
|
653
693
|
retainLookahead(end) {
|
|
@@ -716,7 +756,6 @@ var BlockScanner = class {
|
|
|
716
756
|
tokenStart
|
|
717
757
|
});
|
|
718
758
|
});
|
|
719
|
-
tokens.indexStructure(this.#profile.rules);
|
|
720
759
|
records.length = recordIndex;
|
|
721
760
|
this.#lines = lines;
|
|
722
761
|
}
|
|
@@ -787,7 +826,6 @@ var BlockScanner = class {
|
|
|
787
826
|
const expandedEnd = Math.min(nextSource.length, restartOffset + (scanEnd - restartOffset) * 2);
|
|
788
827
|
scanLineEnd = nextLines.indexAtOrAfter(expandedEnd);
|
|
789
828
|
}
|
|
790
|
-
replacement.indexStructure(this.#profile.rules);
|
|
791
829
|
const oldTokenLength = this.#tokens.length;
|
|
792
830
|
const oldTokenEnd = convergedIndex < 0 ? oldTokenLength : previousRecords[convergedIndex].tokenStart;
|
|
793
831
|
const tokenChange = this.#tokens.replace(oldTokenStart, oldTokenEnd, replacement, changedSpan.start, oldChangedEnd);
|
|
@@ -822,213 +860,28 @@ var BlockScanner = class {
|
|
|
822
860
|
};
|
|
823
861
|
}
|
|
824
862
|
};
|
|
825
|
-
function inlineTokenCount(tokens) {
|
|
826
|
-
return tokens.length / 4;
|
|
827
|
-
}
|
|
828
|
-
function inlineTokenKind(tokens, index) {
|
|
829
|
-
return tokens[index * 4];
|
|
830
|
-
}
|
|
831
|
-
function inlineTokenStart(tokens, index) {
|
|
832
|
-
return tokens[index * 4 + 1];
|
|
833
|
-
}
|
|
834
|
-
function inlineTokenEnd(tokens, index) {
|
|
835
|
-
return tokens[index * 4 + 2];
|
|
836
|
-
}
|
|
837
|
-
function inlineTokenData(tokens, index) {
|
|
838
|
-
return tokens[index * 4 + 3];
|
|
839
|
-
}
|
|
840
|
-
function setInlineTokenData(tokens, index, data) {
|
|
841
|
-
tokens[index * 4 + 3] = data;
|
|
842
|
-
}
|
|
843
|
-
function inlineTokenText(source, tokens, index) {
|
|
844
|
-
return source.slice(inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index));
|
|
845
|
-
}
|
|
846
|
-
function appendInlineToken(target, kind, start, end, data = 0) {
|
|
847
|
-
target.push(kind, start, end, data);
|
|
848
|
-
}
|
|
849
|
-
function copyInlineToken(target, tokens, index) {
|
|
850
|
-
const offset = index * 4;
|
|
851
|
-
target.push(tokens[offset], tokens[offset + 1], tokens[offset + 2], tokens[offset + 3]);
|
|
852
|
-
}
|
|
853
|
-
//#endregion
|
|
854
|
-
//#region src/fragment/node.ts
|
|
855
|
-
function extendSpan(value, end) {
|
|
856
|
-
const node = value;
|
|
857
|
-
node.position.end = Math.max(node.position.end, end);
|
|
858
|
-
}
|
|
859
|
-
function firstChildStart(children) {
|
|
860
|
-
const first = children[0];
|
|
861
|
-
if (!first) throw new Error("mdast container unexpectedly has no children");
|
|
862
|
-
return first.position.start;
|
|
863
|
-
}
|
|
864
|
-
function lastChildEnd(children, emptyEnd) {
|
|
865
|
-
const last = children.at(-1);
|
|
866
|
-
return last ? last.position.end : emptyEnd;
|
|
867
|
-
}
|
|
868
|
-
//#endregion
|
|
869
|
-
//#region src/fragment/inline.ts
|
|
870
|
-
function lineStart(source, offset) {
|
|
871
|
-
while (offset > 0) {
|
|
872
|
-
const character = source.charCodeAt(--offset);
|
|
873
|
-
if (character === 10 || character === 13) return offset + 1;
|
|
874
|
-
}
|
|
875
|
-
return 0;
|
|
876
|
-
}
|
|
877
|
-
function lineEndingStart(source, offset) {
|
|
878
|
-
const start = lineStart(source, offset);
|
|
879
|
-
if (start === 0) return offset;
|
|
880
|
-
return source[start - 1] === "\n" && source[start - 2] === "\r" ? start - 2 : start - 1;
|
|
881
|
-
}
|
|
882
|
-
function countTrailingSpaces(value) {
|
|
883
|
-
let offset = value.length;
|
|
884
|
-
while (offset > 0 && (value[offset - 1] === " " || value[offset - 1] === " ")) offset--;
|
|
885
|
-
return value.length - offset;
|
|
886
|
-
}
|
|
887
|
-
function appendText(output, value, span) {
|
|
888
|
-
const previous = output.children.at(-1);
|
|
889
|
-
if (output.trailingSpaces >= 0) {
|
|
890
|
-
const trailingSpaces = countTrailingSpaces(value);
|
|
891
|
-
output.trailingSpaces = trailingSpaces === value.length && previous?.type === "text" && !("attributes" in previous) ? output.trailingSpaces + trailingSpaces : trailingSpaces;
|
|
892
|
-
}
|
|
893
|
-
if (previous?.type === "text" && !("attributes" in previous)) {
|
|
894
|
-
previous.value += value;
|
|
895
|
-
extendSpan(previous, span.end);
|
|
896
|
-
} else output.children.push({
|
|
897
|
-
type: "text",
|
|
898
|
-
value,
|
|
899
|
-
position: span
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
function appendChild(output, value) {
|
|
903
|
-
if (value.type === "text") appendText(output, value.value, value.position);
|
|
904
|
-
else {
|
|
905
|
-
output.children.push(value);
|
|
906
|
-
if (output.trailingSpaces > 0) output.trailingSpaces = 0;
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
function appendGap(output, context, start, end) {
|
|
910
|
-
appendText(output, context.view.text.slice(start, end), context.view.mapSpan(start, end));
|
|
911
|
-
}
|
|
912
|
-
function appendToken(output, context, tokenIndex, value) {
|
|
913
|
-
const newline = value.type === "text" && value.value.startsWith("\n");
|
|
914
|
-
if (output.gapStart >= 0) {
|
|
915
|
-
const gapStart = output.gapStart;
|
|
916
|
-
output.gapStart = -1;
|
|
917
|
-
const gapEnd = newline ? lineEndingStart(context.view.text, output.gapEnd) : output.gapEnd;
|
|
918
|
-
if (gapEnd > gapStart) appendGap(output, context, gapStart, gapEnd);
|
|
919
|
-
}
|
|
920
|
-
if (newline) {
|
|
921
|
-
const viewStart = inlineTokenStart(context.tokens, tokenIndex);
|
|
922
|
-
const previous = output.children.at(-1);
|
|
923
|
-
if (previous?.type === "break") {
|
|
924
|
-
const viewLineStart = lineStart(context.view.text, viewStart);
|
|
925
|
-
extendSpan(previous, viewLineStart === 0 ? context.view.mapPoint(0) : context.view.mapPoint(viewLineStart - 1) + 1);
|
|
926
|
-
return;
|
|
927
|
-
}
|
|
928
|
-
value.position.start = context.view.mapPoint(lineEndingStart(context.view.text, viewStart));
|
|
929
|
-
if (previous?.type === "text") {
|
|
930
|
-
if (output.trailingSpaces < 0) previous.value = previous.value.slice(0, previous.value.length - countTrailingSpaces(previous.value));
|
|
931
|
-
else if (output.trailingSpaces > 0) {
|
|
932
|
-
previous.value = previous.value.slice(0, -output.trailingSpaces);
|
|
933
|
-
output.trailingSpaces = 0;
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
appendChild(output, value);
|
|
938
|
-
}
|
|
939
|
-
function appendLeaf(tokenIndex, handle, sourceSpan, output, context) {
|
|
940
|
-
const value = handle(tokenIndex, sourceSpan, context, output);
|
|
941
|
-
if (typeof value === "boolean") return value;
|
|
942
|
-
appendToken(output, context, tokenIndex, value);
|
|
943
|
-
return true;
|
|
944
|
-
}
|
|
945
|
-
function appendRange(startToken, endToken, context, output, closeKind = 0) {
|
|
946
|
-
let index = startToken;
|
|
947
|
-
while (index < endToken) {
|
|
948
|
-
const kind = inlineTokenKind(context.tokens, index);
|
|
949
|
-
if (kind === closeKind) break;
|
|
950
|
-
const syntaxOffset = kind * 2;
|
|
951
|
-
const semanticCloseKind = context.syntaxByKind[syntaxOffset];
|
|
952
|
-
const build = context.buildByKind[kind];
|
|
953
|
-
const childStart = inlineTokenStart(context.tokens, index);
|
|
954
|
-
if (childStart > output.cursor) {
|
|
955
|
-
output.gapStart = output.cursor;
|
|
956
|
-
output.gapEnd = childStart;
|
|
957
|
-
}
|
|
958
|
-
if (semanticCloseKind !== void 0) {
|
|
959
|
-
index = appendSemantic(index, endToken, output, context, build, semanticCloseKind, context.syntaxByKind[syntaxOffset + 1]);
|
|
960
|
-
continue;
|
|
961
|
-
}
|
|
962
|
-
const childEnd = inlineTokenEnd(context.tokens, index);
|
|
963
|
-
if (appendLeaf(index, build, context.view.mapSpan(childStart, childEnd), output, context)) output.cursor = childEnd;
|
|
964
|
-
index++;
|
|
965
|
-
}
|
|
966
|
-
if (index < endToken) {
|
|
967
|
-
const contentEnd = inlineTokenStart(context.tokens, index);
|
|
968
|
-
if (contentEnd > output.cursor) appendGap(output, context, output.cursor, contentEnd);
|
|
969
|
-
} else if (closeKind === 0 && context.view.text.length > output.cursor) appendGap(output, context, output.cursor, context.view.text.length);
|
|
970
|
-
return index;
|
|
971
|
-
}
|
|
972
|
-
function appendSemantic(openToken, endToken, output, context, build, closeKind, contentOpenKind) {
|
|
973
|
-
let closeToken = openToken;
|
|
974
|
-
let next = openToken + 1;
|
|
975
|
-
const children = [];
|
|
976
|
-
if (contentOpenKind === 0 || next < endToken && inlineTokenKind(context.tokens, next) === contentOpenKind) {
|
|
977
|
-
const childOutput = {
|
|
978
|
-
children,
|
|
979
|
-
cursor: inlineTokenEnd(context.tokens, contentOpenKind === 0 ? openToken : next++),
|
|
980
|
-
gapEnd: -1,
|
|
981
|
-
gapStart: -1,
|
|
982
|
-
trailingSpaces: output.trailingSpaces < 0 ? -1 : 0
|
|
983
|
-
};
|
|
984
|
-
closeToken = appendRange(next, endToken, context, childOutput, closeKind);
|
|
985
|
-
}
|
|
986
|
-
const childStart = inlineTokenStart(context.tokens, openToken);
|
|
987
|
-
const childEnd = inlineTokenEnd(context.tokens, closeToken);
|
|
988
|
-
appendToken(output, context, openToken, build(openToken, closeToken, context.view.mapSpan(childStart, childEnd), children, context));
|
|
989
|
-
output.cursor = childEnd;
|
|
990
|
-
return closeToken + 1;
|
|
991
|
-
}
|
|
992
|
-
function buildInlineFragment(tokenStart, blockRule, context) {
|
|
993
|
-
const region = context.cursor.take(tokenStart);
|
|
994
|
-
if (!region) return { children: [] };
|
|
995
|
-
const { tokens, view } = region;
|
|
996
|
-
const inlineContext = {
|
|
997
|
-
blockRule,
|
|
998
|
-
buildByKind: context.profile.buildByKind,
|
|
999
|
-
syntaxByKind: context.profile.syntaxByKind,
|
|
1000
|
-
tokens,
|
|
1001
|
-
view
|
|
1002
|
-
};
|
|
1003
|
-
const result = {
|
|
1004
|
-
children: [],
|
|
1005
|
-
cursor: 0,
|
|
1006
|
-
gapEnd: -1,
|
|
1007
|
-
gapStart: -1,
|
|
1008
|
-
trailingSpaces: tokens.length && (view.text.includes("\n") || view.text.includes("\r")) ? 0 : -1
|
|
1009
|
-
};
|
|
1010
|
-
appendRange(0, inlineTokenCount(tokens), inlineContext, result);
|
|
1011
|
-
const last = result.children.at(-1);
|
|
1012
|
-
if (last?.type === "text") {
|
|
1013
|
-
const removed = result.trailingSpaces < 0 ? countTrailingSpaces(last.value) : result.trailingSpaces;
|
|
1014
|
-
last.value = last.value.slice(0, last.value.length - removed);
|
|
1015
|
-
last.position.end -= removed;
|
|
1016
|
-
if (!last.value) result.children.pop();
|
|
1017
|
-
}
|
|
1018
|
-
return result;
|
|
1019
|
-
}
|
|
1020
863
|
//#endregion
|
|
1021
864
|
//#region src/fragment/block.ts
|
|
1022
865
|
function blockEnd(tokenStart, context) {
|
|
1023
866
|
const tokens = context.structure.tokens;
|
|
1024
|
-
|
|
867
|
+
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
868
|
+
return tokens.nodeLength(close) === 0 ? tokens.end(close) : tokens.contentEnd(context.source, close);
|
|
1025
869
|
}
|
|
1026
|
-
|
|
1027
|
-
const
|
|
1028
|
-
const
|
|
1029
|
-
return
|
|
1030
|
-
}
|
|
1031
|
-
|
|
870
|
+
function leafBlockPosition(tokenStart, context) {
|
|
871
|
+
const tokens = context.structure.tokens;
|
|
872
|
+
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
873
|
+
return context.locator.positionAt(tokens.start(tokenStart), tokens.contentEnd(context.source, close));
|
|
874
|
+
}
|
|
875
|
+
function fencedBlockPosition(tokenStart, block, context) {
|
|
876
|
+
const tokens = context.structure.tokens;
|
|
877
|
+
const end = tokens.end(tokenStart);
|
|
878
|
+
const positionEnd = block.closed || end < tokens.sourceLength ? blockEnd(tokenStart, context) : end;
|
|
879
|
+
return context.locator.positionAt(tokens.start(tokenStart) + block.markerOffset, positionEnd);
|
|
880
|
+
}
|
|
881
|
+
function buildBlockNode(tokenStart, context) {
|
|
882
|
+
return context.structure.ruleOf(tokenStart).build(tokenStart, context);
|
|
883
|
+
}
|
|
884
|
+
function buildBlockChildren(tokenStart, context) {
|
|
1032
885
|
const structure = context.structure;
|
|
1033
886
|
const tokens = structure.tokens;
|
|
1034
887
|
const children = [];
|
|
@@ -1039,37 +892,108 @@ const buildBlockChildren = (tokenStart, context) => {
|
|
|
1039
892
|
child += length || 1;
|
|
1040
893
|
}
|
|
1041
894
|
return children;
|
|
895
|
+
}
|
|
896
|
+
//#endregion
|
|
897
|
+
//#region src/source-view.ts
|
|
898
|
+
function containingSegment(segments, offset) {
|
|
899
|
+
let low = 0;
|
|
900
|
+
let high = segments.length >>> 1;
|
|
901
|
+
while (low < high) {
|
|
902
|
+
const middle = low + high >>> 1;
|
|
903
|
+
if (offset < segments[middle * 2 + 1]) high = middle;
|
|
904
|
+
else low = middle + 1;
|
|
905
|
+
}
|
|
906
|
+
return low * 2;
|
|
907
|
+
}
|
|
908
|
+
var SourceView = class {
|
|
909
|
+
#offset = 0;
|
|
910
|
+
#segments;
|
|
911
|
+
text;
|
|
912
|
+
constructor(source, startOrRanges, end) {
|
|
913
|
+
if (typeof startOrRanges === "number") {
|
|
914
|
+
this.#offset = startOrRanges;
|
|
915
|
+
this.text = source.slice(startOrRanges, end);
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
const ranges = startOrRanges;
|
|
919
|
+
const parts = [];
|
|
920
|
+
let viewOffset = 0;
|
|
921
|
+
let segmentCount = 0;
|
|
922
|
+
for (let read = 0; read < ranges.length; read += 2) {
|
|
923
|
+
const start = ranges[read];
|
|
924
|
+
const end = ranges[read + 1];
|
|
925
|
+
if (start === end) continue;
|
|
926
|
+
const write = segmentCount * 2;
|
|
927
|
+
ranges[write] = start - viewOffset;
|
|
928
|
+
viewOffset += end - start;
|
|
929
|
+
parts.push(source.slice(start, end));
|
|
930
|
+
ranges[write + 1] = viewOffset;
|
|
931
|
+
segmentCount++;
|
|
932
|
+
}
|
|
933
|
+
ranges.length = segmentCount * 2;
|
|
934
|
+
this.#segments = ranges;
|
|
935
|
+
this.text = parts.join("");
|
|
936
|
+
}
|
|
937
|
+
mapOffset(offset) {
|
|
938
|
+
const segments = this.#segments;
|
|
939
|
+
if (!segments) return this.#offset + offset;
|
|
940
|
+
if (offset === this.text.length) return segments[segments.length - 2] + offset;
|
|
941
|
+
return segments[containingSegment(segments, offset)] + offset;
|
|
942
|
+
}
|
|
943
|
+
mapEnd(offset) {
|
|
944
|
+
const segments = this.#segments;
|
|
945
|
+
if (!segments) return this.#offset + offset;
|
|
946
|
+
return segments[containingSegment(segments, Math.max(0, offset - 1))] + offset;
|
|
947
|
+
}
|
|
948
|
+
shift(delta) {
|
|
949
|
+
const segments = this.#segments;
|
|
950
|
+
if (!segments) {
|
|
951
|
+
this.#offset += delta;
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
for (let index = 0; index < segments.length; index += 2) segments[index] += delta;
|
|
955
|
+
}
|
|
1042
956
|
};
|
|
1043
957
|
//#endregion
|
|
1044
958
|
//#region src/inline/region.ts
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
959
|
+
const definitionAny = Symbol();
|
|
960
|
+
var TrackedDefinitionLookup = class {
|
|
961
|
+
definitions;
|
|
962
|
+
dependencies;
|
|
963
|
+
constructor(definitions) {
|
|
964
|
+
this.definitions = definitions;
|
|
965
|
+
}
|
|
966
|
+
hasDefinition(key) {
|
|
967
|
+
(this.dependencies ??= new Set()).add(key);
|
|
968
|
+
return this.definitions.hasDefinition(key);
|
|
969
|
+
}
|
|
970
|
+
hasDefinitions() {
|
|
971
|
+
const hasAny = this.definitions.hasDefinitions();
|
|
972
|
+
if (!hasAny) (this.dependencies ??= new Set()).add(definitionAny);
|
|
973
|
+
return hasAny;
|
|
974
|
+
}
|
|
975
|
+
};
|
|
1049
976
|
var InlineRegion = class {
|
|
1050
977
|
#definitionDependencies;
|
|
1051
978
|
#rawTokens;
|
|
1052
979
|
#profile;
|
|
1053
|
-
|
|
980
|
+
tokens;
|
|
1054
981
|
tokenStart;
|
|
1055
982
|
view;
|
|
1056
|
-
constructor(profile, binding,
|
|
983
|
+
constructor(profile, binding, definitions) {
|
|
1057
984
|
this.#profile = profile;
|
|
1058
985
|
this.tokenStart = binding.tokenStart;
|
|
1059
986
|
this.view = binding.view;
|
|
1060
|
-
this.#updateTokens(binding.view.text,
|
|
1061
|
-
}
|
|
1062
|
-
get tokens() {
|
|
1063
|
-
return this.#tokens;
|
|
987
|
+
this.#updateTokens(binding.view.text, definitions, emptySet);
|
|
1064
988
|
}
|
|
1065
|
-
update(binding,
|
|
1066
|
-
this.#updateTokens(binding.view.text,
|
|
989
|
+
update(binding, definitions, definitionMembershipChanges) {
|
|
990
|
+
this.#updateTokens(binding.view.text, definitions, definitionMembershipChanges);
|
|
1067
991
|
this.tokenStart = binding.tokenStart;
|
|
1068
992
|
this.view = binding.view;
|
|
1069
993
|
return this;
|
|
1070
994
|
}
|
|
1071
|
-
updateDefinitions(
|
|
1072
|
-
return this.#updateTokens(this.view.text,
|
|
995
|
+
updateDefinitions(definitions, definitionMembershipChanges) {
|
|
996
|
+
return this.#updateTokens(this.view.text, definitions, definitionMembershipChanges);
|
|
1073
997
|
}
|
|
1074
998
|
shift(delta, tokenDelta) {
|
|
1075
999
|
this.tokenStart += tokenDelta;
|
|
@@ -1077,134 +1001,33 @@ var InlineRegion = class {
|
|
|
1077
1001
|
}
|
|
1078
1002
|
#dependenciesChanged(definitionMembershipChanges) {
|
|
1079
1003
|
const dependencies = this.#definitionDependencies;
|
|
1080
|
-
if (dependencies.
|
|
1081
|
-
|
|
1004
|
+
if (dependencies.has(definitionAny)) return definitionMembershipChanges.size > 0;
|
|
1005
|
+
const labels = dependencies;
|
|
1006
|
+
if (labels.size < definitionMembershipChanges.size) {
|
|
1007
|
+
for (const key of labels) if (definitionMembershipChanges.has(key)) return true;
|
|
1082
1008
|
} else for (const key of definitionMembershipChanges) if (dependencies.has(key)) return true;
|
|
1083
1009
|
return false;
|
|
1084
1010
|
}
|
|
1085
|
-
#updateTokens(source,
|
|
1011
|
+
#updateTokens(source, definitions, definitionMembershipChanges) {
|
|
1086
1012
|
const previousTokens = this.#rawTokens;
|
|
1087
1013
|
const sourceUnchanged = previousTokens !== void 0 && source === this.view.text;
|
|
1088
1014
|
if (sourceUnchanged && !this.#dependenciesChanged(definitionMembershipChanges)) return false;
|
|
1089
|
-
|
|
1090
|
-
definitionContext,
|
|
1091
|
-
hasDefinition
|
|
1092
|
-
};
|
|
1015
|
+
definitions.dependencies = void 0;
|
|
1093
1016
|
const rawTokens = sourceUnchanged ? previousTokens : this.#profile.tokenize(source);
|
|
1094
|
-
const tokens = this.#profile.resolve(source, rawTokens,
|
|
1095
|
-
this.#definitionDependencies =
|
|
1017
|
+
const tokens = this.#profile.resolve(source, rawTokens, definitions);
|
|
1018
|
+
this.#definitionDependencies = definitions.dependencies ?? emptySet;
|
|
1096
1019
|
this.#rawTokens = rawTokens;
|
|
1097
|
-
this
|
|
1020
|
+
this.tokens = tokens;
|
|
1098
1021
|
return true;
|
|
1099
1022
|
}
|
|
1100
1023
|
};
|
|
1101
|
-
var
|
|
1102
|
-
#
|
|
1103
|
-
#regions;
|
|
1104
|
-
constructor(regions = emptyArray) {
|
|
1105
|
-
this.#regions = regions;
|
|
1106
|
-
}
|
|
1107
|
-
reset(regions) {
|
|
1108
|
-
this.#index = 0;
|
|
1109
|
-
this.#regions = regions;
|
|
1110
|
-
}
|
|
1111
|
-
take(tokenStart) {
|
|
1112
|
-
const region = this.#regions[this.#index];
|
|
1113
|
-
if (region?.tokenStart !== tokenStart) return;
|
|
1114
|
-
this.#index++;
|
|
1115
|
-
return region;
|
|
1116
|
-
}
|
|
1117
|
-
};
|
|
1118
|
-
//#endregion
|
|
1119
|
-
//#region src/source-view.ts
|
|
1120
|
-
var ContiguousSourceView = class {
|
|
1121
|
-
#offset;
|
|
1122
|
-
text;
|
|
1123
|
-
constructor(source, start, end) {
|
|
1124
|
-
this.#offset = start;
|
|
1125
|
-
this.text = source.slice(start, end);
|
|
1126
|
-
}
|
|
1127
|
-
mapPoint(offset) {
|
|
1128
|
-
return this.#offset + offset;
|
|
1129
|
-
}
|
|
1130
|
-
mapSpan(start, end) {
|
|
1131
|
-
return {
|
|
1132
|
-
start: this.#offset + start,
|
|
1133
|
-
end: this.#offset + end
|
|
1134
|
-
};
|
|
1135
|
-
}
|
|
1136
|
-
shift(delta) {
|
|
1137
|
-
this.#offset += delta;
|
|
1138
|
-
}
|
|
1139
|
-
};
|
|
1140
|
-
var SegmentedSourceView = class {
|
|
1141
|
-
#segments;
|
|
1142
|
-
text;
|
|
1143
|
-
constructor(source, ranges) {
|
|
1144
|
-
const parts = [];
|
|
1145
|
-
let viewOffset = 0;
|
|
1146
|
-
let segmentCount = 0;
|
|
1147
|
-
for (let read = 0; read < ranges.length; read += 2) {
|
|
1148
|
-
const start = ranges[read];
|
|
1149
|
-
const end = ranges[read + 1];
|
|
1150
|
-
if (start === end) continue;
|
|
1151
|
-
const write = segmentCount * 2;
|
|
1152
|
-
ranges[write] = start - viewOffset;
|
|
1153
|
-
viewOffset += end - start;
|
|
1154
|
-
parts.push(source.slice(start, end));
|
|
1155
|
-
ranges[write + 1] = viewOffset;
|
|
1156
|
-
segmentCount++;
|
|
1157
|
-
}
|
|
1158
|
-
ranges.length = segmentCount * 2;
|
|
1159
|
-
this.#segments = ranges;
|
|
1160
|
-
this.text = parts.join("");
|
|
1161
|
-
}
|
|
1162
|
-
mapPoint(offset) {
|
|
1163
|
-
if (this.#segments.length === 0) return 0;
|
|
1164
|
-
if (offset === this.text.length) return this.#segments[this.#segments.length - 2] + offset;
|
|
1165
|
-
const segment = this.#containingSegment(offset);
|
|
1166
|
-
return this.#segments[segment] + offset;
|
|
1167
|
-
}
|
|
1168
|
-
mapSpan(start, end) {
|
|
1169
|
-
if (this.#segments.length === 0) return {
|
|
1170
|
-
start: 0,
|
|
1171
|
-
end: 0
|
|
1172
|
-
};
|
|
1173
|
-
if (start === end) {
|
|
1174
|
-
const point = this.mapPoint(start);
|
|
1175
|
-
return {
|
|
1176
|
-
start: point,
|
|
1177
|
-
end: point
|
|
1178
|
-
};
|
|
1179
|
-
}
|
|
1180
|
-
const first = this.#containingSegment(start);
|
|
1181
|
-
const last = this.#containingSegment(end - 1);
|
|
1182
|
-
return {
|
|
1183
|
-
start: this.#segments[first] + start,
|
|
1184
|
-
end: this.#segments[last] + end
|
|
1185
|
-
};
|
|
1186
|
-
}
|
|
1187
|
-
shift(delta) {
|
|
1188
|
-
for (let index = 0; index < this.#segments.length; index += 2) this.#segments[index] += delta;
|
|
1189
|
-
}
|
|
1190
|
-
#containingSegment(offset) {
|
|
1191
|
-
let low = 0;
|
|
1192
|
-
let high = this.#segments.length >>> 1;
|
|
1193
|
-
while (low < high) {
|
|
1194
|
-
const middle = low + high >>> 1;
|
|
1195
|
-
if (offset < this.#segments[middle * 2 + 1]) high = middle;
|
|
1196
|
-
else low = middle + 1;
|
|
1197
|
-
}
|
|
1198
|
-
return low * 2;
|
|
1199
|
-
}
|
|
1200
|
-
};
|
|
1201
|
-
//#endregion
|
|
1202
|
-
//#region src/syntax-state.ts
|
|
1203
|
-
var SyntaxState = class {
|
|
1024
|
+
var InlineRegionState = class {
|
|
1025
|
+
#lookup;
|
|
1204
1026
|
#profile;
|
|
1205
1027
|
#regionsByBlock = [];
|
|
1206
1028
|
#structure;
|
|
1207
1029
|
constructor(profile, structure) {
|
|
1030
|
+
this.#lookup = new TrackedDefinitionLookup(structure.tokens);
|
|
1208
1031
|
this.#profile = profile;
|
|
1209
1032
|
this.#structure = structure;
|
|
1210
1033
|
}
|
|
@@ -1270,7 +1093,7 @@ var SyntaxState = class {
|
|
|
1270
1093
|
while (displacedIndex < displacedRegions.length && displacedRegions[displacedIndex].tokenStart < previousTokenStart) displacedIndex++;
|
|
1271
1094
|
if (displacedRegions[displacedIndex]?.tokenStart === previousTokenStart) candidate = displacedRegions[displacedIndex++];
|
|
1272
1095
|
}
|
|
1273
|
-
regions[regionIndex] = candidate
|
|
1096
|
+
regions[regionIndex] = candidate?.update(binding, this.#lookup, definitionMembershipChanges) ?? new InlineRegion(this.#profile, binding, this.#lookup);
|
|
1274
1097
|
}
|
|
1275
1098
|
regionsByBlock[blockIndex] = regions;
|
|
1276
1099
|
}
|
|
@@ -1279,7 +1102,7 @@ var SyntaxState = class {
|
|
|
1279
1102
|
for (let index = start; index < end; index++) {
|
|
1280
1103
|
const regions = regionsByBlock[index];
|
|
1281
1104
|
let changed = false;
|
|
1282
|
-
for (const region of regions) if (region.updateDefinitions(
|
|
1105
|
+
for (const region of regions) if (region.updateDefinitions(this.#lookup, definitionMembershipChanges)) changed = true;
|
|
1283
1106
|
if (changed) (invalidatedBlocks ??= []).push(index);
|
|
1284
1107
|
}
|
|
1285
1108
|
};
|
|
@@ -1290,37 +1113,37 @@ var SyntaxState = class {
|
|
|
1290
1113
|
return invalidatedBlocks ?? emptyArray;
|
|
1291
1114
|
}
|
|
1292
1115
|
};
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
const text = inlineView.text;
|
|
1306
|
-
regions.push({
|
|
1307
|
-
tokenStart: token,
|
|
1308
|
-
tokens: profile.resolve(text, profile.tokenize(text), tokens),
|
|
1309
|
-
view: inlineView
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
|
-
token += nodeLength - 1;
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1116
|
+
var InlineRegionCursor = class {
|
|
1117
|
+
#index = 0;
|
|
1118
|
+
#regions = emptyArray;
|
|
1119
|
+
reset(regions) {
|
|
1120
|
+
this.#index = 0;
|
|
1121
|
+
this.#regions = regions;
|
|
1122
|
+
}
|
|
1123
|
+
take(tokenStart) {
|
|
1124
|
+
const region = this.#regions[this.#index];
|
|
1125
|
+
if (region?.tokenStart !== tokenStart) return;
|
|
1126
|
+
this.#index++;
|
|
1127
|
+
return region;
|
|
1315
1128
|
}
|
|
1316
|
-
|
|
1129
|
+
};
|
|
1130
|
+
function resolveInlineRegion(source, profile, tokens, tokenStart) {
|
|
1131
|
+
const view = inlineViewOf(source, tokens, tokenStart, tokens.nodeLength(tokenStart));
|
|
1132
|
+
if (!view) return;
|
|
1133
|
+
const text = view.text;
|
|
1134
|
+
return {
|
|
1135
|
+
tokenStart,
|
|
1136
|
+
tokens: profile.resolve(text, profile.tokenize(text), tokens),
|
|
1137
|
+
view
|
|
1138
|
+
};
|
|
1317
1139
|
}
|
|
1318
1140
|
function inlineViewOf(source, tokens, tokenStart, nodeLength) {
|
|
1319
1141
|
let firstStart = -1;
|
|
1320
1142
|
let firstEnd = -1;
|
|
1321
1143
|
let ranges;
|
|
1322
1144
|
const tokenEnd = tokenStart + nodeLength;
|
|
1323
|
-
for (let token = tokenStart + 1; token < tokenEnd; token++)
|
|
1145
|
+
for (let token = tokenStart + 1; token < tokenEnd; token++) {
|
|
1146
|
+
if (tokens.kind(token) !== 1) continue;
|
|
1324
1147
|
const start = tokens.start(token);
|
|
1325
1148
|
const end = tokens.end(token);
|
|
1326
1149
|
if (firstStart < 0) {
|
|
@@ -1335,8 +1158,8 @@ function inlineViewOf(source, tokens, tokenStart, nodeLength) {
|
|
|
1335
1158
|
firstEnd = end;
|
|
1336
1159
|
}
|
|
1337
1160
|
}
|
|
1338
|
-
if (ranges) return new
|
|
1339
|
-
if (firstStart >= 0) return new
|
|
1161
|
+
if (ranges) return new SourceView(source, ranges);
|
|
1162
|
+
if (firstStart >= 0) return new SourceView(source, firstStart, firstEnd);
|
|
1340
1163
|
}
|
|
1341
1164
|
//#endregion
|
|
1342
1165
|
//#region src/document.ts
|
|
@@ -1361,18 +1184,9 @@ function applyEdits(source, edits) {
|
|
|
1361
1184
|
offsetDelta: delta
|
|
1362
1185
|
};
|
|
1363
1186
|
}
|
|
1364
|
-
function
|
|
1365
|
-
const { position, children } = value;
|
|
1366
|
-
const result = position;
|
|
1367
|
-
result.start = locate(position.start);
|
|
1368
|
-
if (children) for (const child of children) materializeNode(child, locate);
|
|
1369
|
-
result.end = locate(position.end);
|
|
1370
|
-
}
|
|
1371
|
-
function buildTreeBlock(record, regions, context, locate) {
|
|
1187
|
+
function buildTreeBlock(record, regions, context) {
|
|
1372
1188
|
context.cursor.reset(regions);
|
|
1373
|
-
|
|
1374
|
-
materializeNode(node, locate);
|
|
1375
|
-
return node;
|
|
1189
|
+
return buildBlockNode(record.tokenStart, context);
|
|
1376
1190
|
}
|
|
1377
1191
|
function shiftLocation(location, shift) {
|
|
1378
1192
|
if (location.line === shift.columnLine) location.column += shift.column;
|
|
@@ -1389,7 +1203,7 @@ var DocumentImpl = class {
|
|
|
1389
1203
|
#blockScanner;
|
|
1390
1204
|
#profile;
|
|
1391
1205
|
#source;
|
|
1392
|
-
#
|
|
1206
|
+
#regionState;
|
|
1393
1207
|
#tree = {
|
|
1394
1208
|
type: "root",
|
|
1395
1209
|
children: []
|
|
@@ -1399,8 +1213,8 @@ var DocumentImpl = class {
|
|
|
1399
1213
|
this.#source = source;
|
|
1400
1214
|
this.#blockScanner = new BlockScanner(profile.block);
|
|
1401
1215
|
this.#blockScanner.scan(source);
|
|
1402
|
-
this.#
|
|
1403
|
-
this.#updateTree(this.#
|
|
1216
|
+
this.#regionState = new InlineRegionState(profile.inline, this.#blockScanner);
|
|
1217
|
+
this.#updateTree(this.#regionState.update(source));
|
|
1404
1218
|
}
|
|
1405
1219
|
get source() {
|
|
1406
1220
|
return this.#source;
|
|
@@ -1415,23 +1229,25 @@ var DocumentImpl = class {
|
|
|
1415
1229
|
} };
|
|
1416
1230
|
const change = applyEdits(this.source, edits);
|
|
1417
1231
|
const blockChange = this.#blockScanner.edit(change);
|
|
1418
|
-
const invalidatedBlocks = this.#
|
|
1232
|
+
const invalidatedBlocks = this.#regionState.update(change.nextSource, blockChange);
|
|
1419
1233
|
this.#source = change.nextSource;
|
|
1420
1234
|
this.#updateTree(invalidatedBlocks, blockChange);
|
|
1421
1235
|
return { changedSpan: change.changedSpan };
|
|
1422
1236
|
}
|
|
1423
1237
|
#updateTree(invalidatedBlocks, change) {
|
|
1424
1238
|
const records = this.#blockScanner.records;
|
|
1425
|
-
const regionsByBlock = this.#
|
|
1239
|
+
const regionsByBlock = this.#regionState.regionsByBlock();
|
|
1240
|
+
const locator = this.#blockScanner.locator();
|
|
1426
1241
|
const context = {
|
|
1427
|
-
|
|
1242
|
+
inlineContext: void 0,
|
|
1428
1243
|
cursor: new InlineRegionCursor(),
|
|
1244
|
+
locator,
|
|
1245
|
+
structure: this.#blockScanner,
|
|
1429
1246
|
profile: this.#profile.inline,
|
|
1430
1247
|
source: this.#source
|
|
1431
1248
|
};
|
|
1432
|
-
const locate = this.#blockScanner.locator();
|
|
1433
1249
|
const root = this.#tree;
|
|
1434
|
-
const start =
|
|
1250
|
+
const start = locator.locationAt(0);
|
|
1435
1251
|
const children = root.children;
|
|
1436
1252
|
const rebuildStart = change?.stableBlockCount ?? 0;
|
|
1437
1253
|
const oldRebuildEnd = change?.oldRecordEnd ?? 0;
|
|
@@ -1450,19 +1266,19 @@ var DocumentImpl = class {
|
|
|
1450
1266
|
let invalidatedIndex = 0;
|
|
1451
1267
|
while (invalidatedIndex < invalidatedBlocks.length && invalidatedBlocks[invalidatedIndex] < rebuildStart) {
|
|
1452
1268
|
const index = invalidatedBlocks[invalidatedIndex++];
|
|
1453
|
-
children[index] = buildTreeBlock(records[index], regionsByBlock[index], context
|
|
1269
|
+
children[index] = buildTreeBlock(records[index], regionsByBlock[index], context);
|
|
1454
1270
|
}
|
|
1455
|
-
for (let index = rebuildStart; index < newRebuildEnd; index++) children[index] = buildTreeBlock(records[index], regionsByBlock[index], context
|
|
1271
|
+
for (let index = rebuildStart; index < newRebuildEnd; index++) children[index] = buildTreeBlock(records[index], regionsByBlock[index], context);
|
|
1456
1272
|
let positionShift;
|
|
1457
1273
|
for (let index = newRebuildEnd; index < records.length; index++) {
|
|
1458
1274
|
if (invalidatedBlocks[invalidatedIndex] === index) {
|
|
1459
|
-
children[index] = buildTreeBlock(records[index], regionsByBlock[index], context
|
|
1275
|
+
children[index] = buildTreeBlock(records[index], regionsByBlock[index], context);
|
|
1460
1276
|
invalidatedIndex++;
|
|
1461
1277
|
continue;
|
|
1462
1278
|
}
|
|
1463
1279
|
if (!positionShift) {
|
|
1464
1280
|
const previousStart = children[index].position.start;
|
|
1465
|
-
const nextStart =
|
|
1281
|
+
const nextStart = locator.locationAt(previousStart.offset + suffixOffsetDelta);
|
|
1466
1282
|
if (nextStart.offset === previousStart.offset && nextStart.line === previousStart.line && nextStart.column === previousStart.column) break;
|
|
1467
1283
|
positionShift = {
|
|
1468
1284
|
offset: nextStart.offset - previousStart.offset,
|
|
@@ -1475,33 +1291,34 @@ var DocumentImpl = class {
|
|
|
1475
1291
|
}
|
|
1476
1292
|
while (invalidatedIndex < invalidatedBlocks.length) {
|
|
1477
1293
|
const index = invalidatedBlocks[invalidatedIndex++];
|
|
1478
|
-
children[index] = buildTreeBlock(records[index], regionsByBlock[index], context
|
|
1294
|
+
children[index] = buildTreeBlock(records[index], regionsByBlock[index], context);
|
|
1479
1295
|
}
|
|
1480
1296
|
root.position = {
|
|
1481
1297
|
start,
|
|
1482
|
-
end:
|
|
1298
|
+
end: locator.locationAt(this.#source.length)
|
|
1483
1299
|
};
|
|
1484
1300
|
}
|
|
1485
1301
|
static parse(source, profile, blockScanner) {
|
|
1486
1302
|
blockScanner.scan(source);
|
|
1303
|
+
const locator = blockScanner.locator();
|
|
1487
1304
|
const context = {
|
|
1305
|
+
inlineContext: void 0,
|
|
1306
|
+
cursor: void 0,
|
|
1307
|
+
locator,
|
|
1488
1308
|
structure: blockScanner,
|
|
1489
|
-
cursor: new InlineRegionCursor(resolveInlineRegions(source, profile.inline, blockScanner)),
|
|
1490
1309
|
profile: profile.inline,
|
|
1491
1310
|
source
|
|
1492
1311
|
};
|
|
1493
|
-
const
|
|
1494
|
-
const
|
|
1312
|
+
const start = locator.locationAt(0);
|
|
1313
|
+
const records = blockScanner.records;
|
|
1314
|
+
const children = new Array(records.length);
|
|
1315
|
+
for (let index = 0; index < records.length; index++) children[index] = buildBlockNode(records[index].tokenStart, context);
|
|
1495
1316
|
return {
|
|
1496
1317
|
type: "root",
|
|
1497
|
-
children
|
|
1498
|
-
const node = buildBlockNode(block.tokenStart, context);
|
|
1499
|
-
materializeNode(node, locate);
|
|
1500
|
-
return node;
|
|
1501
|
-
}),
|
|
1318
|
+
children,
|
|
1502
1319
|
position: {
|
|
1503
1320
|
start,
|
|
1504
|
-
end:
|
|
1321
|
+
end: locator.locationAt(source.length)
|
|
1505
1322
|
}
|
|
1506
1323
|
};
|
|
1507
1324
|
}
|
|
@@ -1528,19 +1345,14 @@ function compileBlockProfile(features) {
|
|
|
1528
1345
|
}
|
|
1529
1346
|
if (feature.rules) for (const registration of feature.rules) {
|
|
1530
1347
|
const syntax = registration.syntax;
|
|
1348
|
+
const tokens = typeof syntax.token === "number" ? [syntax.token] : syntax.token;
|
|
1531
1349
|
const rule = {
|
|
1532
1350
|
block: syntax.kind === "block" || syntax.kind === "leaf",
|
|
1533
|
-
close: syntax.kind === "block" || syntax.kind === "frame" ? syntax.close : 0,
|
|
1534
1351
|
inlineContent: registration.inlineContent === true,
|
|
1535
|
-
rule: registration.rule,
|
|
1536
1352
|
build: registration.build
|
|
1537
1353
|
};
|
|
1538
1354
|
ruleByBlockRule[registration.rule] = rule;
|
|
1539
|
-
|
|
1540
|
-
const opens = typeof syntax.open === "number" ? [syntax.open] : syntax.open;
|
|
1541
|
-
for (const open of opens) rules[open] = rule;
|
|
1542
|
-
} else if (syntax.kind === "group") for (const token of syntax.tokens) rules[token] = rule;
|
|
1543
|
-
else if (syntax.kind === "leaf") rules[syntax.token] = rule;
|
|
1355
|
+
for (const token of tokens) rules[token] = rule;
|
|
1544
1356
|
}
|
|
1545
1357
|
}
|
|
1546
1358
|
for (const registration of decorators) {
|
|
@@ -1559,6 +1371,7 @@ function compileBlockProfile(features) {
|
|
|
1559
1371
|
}
|
|
1560
1372
|
//#endregion
|
|
1561
1373
|
//#region src/inline/lexer.ts
|
|
1374
|
+
const tokenizerFactories = new Map();
|
|
1562
1375
|
function matchInlinePatternEnd(pattern, source, start) {
|
|
1563
1376
|
pattern.lastIndex = start;
|
|
1564
1377
|
return pattern.test(source) ? pattern.lastIndex : -1;
|
|
@@ -1571,62 +1384,65 @@ function inlineMarkerRunEnd(source, start) {
|
|
|
1571
1384
|
}
|
|
1572
1385
|
function tokenize(source, textBoundary, scannerByCode) {
|
|
1573
1386
|
const tokens = [];
|
|
1574
|
-
|
|
1387
|
+
const end = source.length;
|
|
1388
|
+
let lineStart = 0;
|
|
1575
1389
|
let offset = 0;
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
if (lineStart) {
|
|
1390
|
+
while (offset < end) {
|
|
1391
|
+
if (lineStart >= 0) {
|
|
1579
1392
|
let content = offset;
|
|
1580
1393
|
while (source.charCodeAt(content) === 32) content++;
|
|
1581
|
-
if (content ===
|
|
1582
|
-
let code = source.charCodeAt(content);
|
|
1583
|
-
if (code === 10 || code === 13) {
|
|
1584
|
-
offset = content + 1;
|
|
1585
|
-
if (code === 13 && source.charCodeAt(offset) === 10) offset++;
|
|
1586
|
-
continue;
|
|
1587
|
-
}
|
|
1588
|
-
if (code === 9) {
|
|
1589
|
-
let blankEnd = content;
|
|
1590
|
-
while (source.charCodeAt(blankEnd) === 9 || source.charCodeAt(blankEnd) === 32) blankEnd++;
|
|
1591
|
-
code = source.charCodeAt(blankEnd);
|
|
1592
|
-
if (blankEnd === source.length || code === 10 || code === 13) {
|
|
1593
|
-
offset = blankEnd + (blankEnd < source.length ? 1 : 0);
|
|
1594
|
-
if (code === 13 && source.charCodeAt(offset) === 10) offset++;
|
|
1595
|
-
continue;
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1394
|
+
if (content === end) break;
|
|
1598
1395
|
offset = content;
|
|
1599
|
-
if (
|
|
1600
|
-
|
|
1601
|
-
lineStart = false;
|
|
1602
|
-
continue;
|
|
1396
|
+
if (lineStart > 0) tokens.push(67, offset, offset, lineStart);
|
|
1397
|
+
lineStart = -1;
|
|
1603
1398
|
}
|
|
1604
1399
|
const code = source.charCodeAt(offset);
|
|
1605
1400
|
if (code === 10 || code === 13) {
|
|
1606
1401
|
if (source.charCodeAt(offset - 1) === 32 && source.charCodeAt(offset - 2) === 32) {
|
|
1607
1402
|
let spaces = offset - 2;
|
|
1608
1403
|
while (source.charCodeAt(spaces - 1) === 32) spaces--;
|
|
1609
|
-
tokens.push(
|
|
1404
|
+
tokens.push(128, spaces, offset, 0);
|
|
1610
1405
|
}
|
|
1611
1406
|
offset++;
|
|
1612
1407
|
if (code === 13 && source.charCodeAt(offset) === 10) offset++;
|
|
1613
|
-
lineStart =
|
|
1408
|
+
lineStart = offset;
|
|
1614
1409
|
continue;
|
|
1615
1410
|
}
|
|
1616
|
-
const
|
|
1617
|
-
|
|
1618
|
-
const scannedEnd = scan(source, offset, tokens);
|
|
1619
|
-
if (scannedEnd > offset) {
|
|
1620
|
-
offset = scannedEnd;
|
|
1621
|
-
continue;
|
|
1622
|
-
}
|
|
1623
|
-
offset++;
|
|
1624
|
-
}
|
|
1411
|
+
const scannedEnd = scannerByCode[code]?.(source, offset, tokens) ?? offset;
|
|
1412
|
+
offset = scannedEnd > offset ? scannedEnd : offset + 1;
|
|
1625
1413
|
textBoundary.lastIndex = offset;
|
|
1626
|
-
offset = textBoundary.test(source) ? textBoundary.lastIndex - 1 :
|
|
1414
|
+
offset = textBoundary.test(source) ? textBoundary.lastIndex - 1 : end;
|
|
1627
1415
|
}
|
|
1628
1416
|
return tokens;
|
|
1629
1417
|
}
|
|
1418
|
+
function generateInlineTokenizer(boundaryCodes, textBoundary, scannerByCode) {
|
|
1419
|
+
const key = String.fromCharCode(...boundaryCodes);
|
|
1420
|
+
let factory = tokenizerFactories.get(key);
|
|
1421
|
+
if (factory === void 0) {
|
|
1422
|
+
const names = boundaryCodes.map((code, index) => `scan${index}`);
|
|
1423
|
+
const source = [
|
|
1424
|
+
`return source=>{`,
|
|
1425
|
+
`const tokens=[],end=source.length;let lineStart=0,offset=0;`,
|
|
1426
|
+
`while(offset<end){`,
|
|
1427
|
+
`if(lineStart>=0){let content=offset;while(source.charCodeAt(content)===32)content++;`,
|
|
1428
|
+
`if(content===end)break;offset=content;`,
|
|
1429
|
+
`if(lineStart>0)tokens.push(67,offset,offset,lineStart);lineStart=-1}`,
|
|
1430
|
+
`const code=source.charCodeAt(offset);`,
|
|
1431
|
+
`if(code===10||code===13){`,
|
|
1432
|
+
`if(source.charCodeAt(offset-1)===32&&source.charCodeAt(offset-2)===32){`,
|
|
1433
|
+
`let spaces=offset-2;while(source.charCodeAt(spaces-1)===32)spaces--;`,
|
|
1434
|
+
`tokens.push(128,spaces,offset,0)}`,
|
|
1435
|
+
`offset++;if(code===13&&source.charCodeAt(offset)===10)offset++;`,
|
|
1436
|
+
`lineStart=offset;continue}`,
|
|
1437
|
+
`let scannedEnd;switch(code){${boundaryCodes.map((code, index) => `case ${code}:scannedEnd=scan${index}(source,offset,tokens);break;`).join("")}default:scannedEnd=offset}`,
|
|
1438
|
+
`offset=scannedEnd>offset?scannedEnd:offset+1;textBoundary.lastIndex=offset;`,
|
|
1439
|
+
`offset=textBoundary.test(source)?textBoundary.lastIndex-1:end}`,
|
|
1440
|
+
`return tokens}`
|
|
1441
|
+
].join("");
|
|
1442
|
+
tokenizerFactories.set(key, factory = Function("textBoundary", ...names, source));
|
|
1443
|
+
}
|
|
1444
|
+
return factory(textBoundary, ...boundaryCodes.map((code) => scannerByCode[code]));
|
|
1445
|
+
}
|
|
1630
1446
|
function compileInlineTokenizer(rules) {
|
|
1631
1447
|
const scannerByCode = [];
|
|
1632
1448
|
const boundaryCodes = [];
|
|
@@ -1641,15 +1457,18 @@ function compileInlineTokenizer(rules) {
|
|
|
1641
1457
|
}
|
|
1642
1458
|
const boundaries = String.fromCharCode(...boundaryCodes).replaceAll(/[\\\]-]/g, "\\$&");
|
|
1643
1459
|
const textBoundary = new RegExp(`${boundaryCodes.length > 9 ? " {2,}[\\n\\r]|" : ""}[\\n\\r${boundaries}]`, "g");
|
|
1644
|
-
|
|
1460
|
+
try {
|
|
1461
|
+
return generateInlineTokenizer(boundaryCodes, textBoundary, scannerByCode);
|
|
1462
|
+
} catch {
|
|
1463
|
+
return (source) => tokenize(source, textBoundary, scannerByCode);
|
|
1464
|
+
}
|
|
1645
1465
|
}
|
|
1646
1466
|
//#endregion
|
|
1647
1467
|
//#region src/inline/profile.ts
|
|
1648
|
-
function compileInlineProfile(features,
|
|
1468
|
+
function compileInlineProfile(features, compileInlineResolver) {
|
|
1649
1469
|
const buildByKind = [];
|
|
1650
1470
|
const delimiters = [];
|
|
1651
1471
|
const scanRules = [];
|
|
1652
|
-
const syntaxByKind = [];
|
|
1653
1472
|
for (const feature of features) {
|
|
1654
1473
|
if (feature.scan) scanRules.push(...feature.scan);
|
|
1655
1474
|
if (feature.delimiters) delimiters.push(...feature.delimiters);
|
|
@@ -1662,25 +1481,54 @@ function compileInlineProfile(features, compileResolver) {
|
|
|
1662
1481
|
case "leaf":
|
|
1663
1482
|
buildByKind[rule.token] = rule.build;
|
|
1664
1483
|
break;
|
|
1665
|
-
case "
|
|
1484
|
+
case "text":
|
|
1666
1485
|
buildByKind[rule.token] = rule.build;
|
|
1667
|
-
syntaxByKind[rule.token * 2] = rule.close;
|
|
1668
|
-
syntaxByKind[rule.token * 2 + 1] = rule.contentOpen;
|
|
1669
1486
|
break;
|
|
1670
|
-
case "pair":
|
|
1671
|
-
buildByKind[rule.open] = rule.build;
|
|
1672
|
-
syntaxByKind[rule.open * 2] = rule.close;
|
|
1673
|
-
syntaxByKind[rule.open * 2 + 1] = 0;
|
|
1487
|
+
case "pair": buildByKind[rule.token] = rule.build;
|
|
1674
1488
|
}
|
|
1675
1489
|
}
|
|
1676
1490
|
return {
|
|
1677
1491
|
buildByKind,
|
|
1678
|
-
resolve:
|
|
1679
|
-
syntaxByKind,
|
|
1492
|
+
resolve: compileInlineResolver(delimiters),
|
|
1680
1493
|
tokenize: compileInlineTokenizer(scanRules)
|
|
1681
1494
|
};
|
|
1682
1495
|
}
|
|
1683
1496
|
//#endregion
|
|
1497
|
+
//#region src/inline/tokens.ts
|
|
1498
|
+
function inlineTokenCount(tokens) {
|
|
1499
|
+
return tokens.length / 4;
|
|
1500
|
+
}
|
|
1501
|
+
function inlineTokenKind(tokens, index) {
|
|
1502
|
+
return tokens[index * 4 + 0];
|
|
1503
|
+
}
|
|
1504
|
+
function inlineTokenStart(tokens, index) {
|
|
1505
|
+
return tokens[index * 4 + 1];
|
|
1506
|
+
}
|
|
1507
|
+
function inlineTokenEnd(tokens, index) {
|
|
1508
|
+
return tokens[index * 4 + 2];
|
|
1509
|
+
}
|
|
1510
|
+
function inlineTokenData(tokens, index) {
|
|
1511
|
+
return tokens[index * 4 + 3];
|
|
1512
|
+
}
|
|
1513
|
+
function setInlineTokenData(tokens, index, data) {
|
|
1514
|
+
tokens[index * 4 + 3] = data;
|
|
1515
|
+
}
|
|
1516
|
+
function rewriteInlineTokenTail(tokens, kind, end) {
|
|
1517
|
+
const offset = tokens.length - 4;
|
|
1518
|
+
tokens[offset + 0] = kind;
|
|
1519
|
+
tokens[offset + 2] = end;
|
|
1520
|
+
}
|
|
1521
|
+
function inlineTokenText(source, tokens, index) {
|
|
1522
|
+
return source.slice(inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index));
|
|
1523
|
+
}
|
|
1524
|
+
function appendInlineToken(target, kind, start, end, data = 0) {
|
|
1525
|
+
target.push(kind, start, end, data);
|
|
1526
|
+
}
|
|
1527
|
+
function copyInlineToken(target, tokens, index) {
|
|
1528
|
+
const offset = index * 4;
|
|
1529
|
+
target.push(tokens[offset], tokens[offset + 1], tokens[offset + 2], tokens[offset + 3]);
|
|
1530
|
+
}
|
|
1531
|
+
//#endregion
|
|
1684
1532
|
//#region src/profile/features/attributes/syntax.ts
|
|
1685
1533
|
const brackets = {
|
|
1686
1534
|
"[": "]",
|
|
@@ -1838,11 +1686,6 @@ function parseAttributes(source, start) {
|
|
|
1838
1686
|
}
|
|
1839
1687
|
//#endregion
|
|
1840
1688
|
//#region src/profile/features/attributes/index.ts
|
|
1841
|
-
const decorateInlineContainer = (build) => (tokenStart, context, inline) => {
|
|
1842
|
-
const result = build(tokenStart, context, inline);
|
|
1843
|
-
if (inline?.attributes) result.attributes = inline.attributes;
|
|
1844
|
-
return result;
|
|
1845
|
-
};
|
|
1846
1689
|
const decorateList = (build) => (tokenStart, context) => {
|
|
1847
1690
|
const result = build(tokenStart, context);
|
|
1848
1691
|
if (!result.spread) for (const item of result.children) {
|
|
@@ -1889,32 +1732,20 @@ function scanAttribute(source, start, tokens) {
|
|
|
1889
1732
|
}
|
|
1890
1733
|
const previous = inlineTokenCount(tokens) - 1;
|
|
1891
1734
|
const previousEnd = previous >= 0 ? inlineTokenEnd(tokens, previous) : 0;
|
|
1892
|
-
if (previousEnd < start && (previous >= 0 && inlineTokenKind(tokens, previous) ===
|
|
1893
|
-
appendInlineToken(tokens,
|
|
1735
|
+
if (previousEnd < start && (previous >= 0 && inlineTokenKind(tokens, previous) === 256 || hasVisibleText(source, previousEnd, start))) appendInlineToken(tokens, 64, previousEnd, start);
|
|
1736
|
+
appendInlineToken(tokens, 256, start, end, start > 0 && isMarkdownWhitespace(source.charCodeAt(start - 1)) ? 1 : 0);
|
|
1894
1737
|
let next = end;
|
|
1895
1738
|
while (isMarkdownWhitespace(source.charCodeAt(next))) next++;
|
|
1896
1739
|
if (next === source.length) for (let index = inlineTokenCount(tokens) - 1; index >= 0; index--) {
|
|
1897
1740
|
const kind = inlineTokenKind(tokens, index);
|
|
1898
|
-
if (kind ===
|
|
1899
|
-
if (kind !==
|
|
1741
|
+
if (kind === 64 && !hasVisibleText(source, inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index))) continue;
|
|
1742
|
+
if (kind !== 256) break;
|
|
1900
1743
|
setInlineTokenData(tokens, index, inlineTokenData(tokens, index) | 2);
|
|
1901
1744
|
}
|
|
1902
1745
|
return end;
|
|
1903
1746
|
}
|
|
1904
1747
|
const feature$18 = {
|
|
1905
1748
|
block: { decorators: [
|
|
1906
|
-
{
|
|
1907
|
-
rule: 4,
|
|
1908
|
-
decorate: decorateInlineContainer
|
|
1909
|
-
},
|
|
1910
|
-
{
|
|
1911
|
-
rule: 2,
|
|
1912
|
-
decorate: decorateInlineContainer
|
|
1913
|
-
},
|
|
1914
|
-
{
|
|
1915
|
-
rule: 3,
|
|
1916
|
-
decorate: decorateInlineContainer
|
|
1917
|
-
},
|
|
1918
1749
|
{
|
|
1919
1750
|
rule: 6,
|
|
1920
1751
|
decorate: decorateList
|
|
@@ -1935,7 +1766,7 @@ const feature$18 = {
|
|
|
1935
1766
|
}],
|
|
1936
1767
|
build: [{
|
|
1937
1768
|
kind: "decorate",
|
|
1938
|
-
token:
|
|
1769
|
+
token: 256,
|
|
1939
1770
|
apply(tokenIndex, sourceSpan, context, target) {
|
|
1940
1771
|
const previous = target.children.at(-1);
|
|
1941
1772
|
const parsed = parseAttributes(context.view.text, inlineTokenStart(context.tokens, tokenIndex));
|
|
@@ -1948,9 +1779,10 @@ const feature$18 = {
|
|
|
1948
1779
|
else target.attributes = parsed.attributes;
|
|
1949
1780
|
return true;
|
|
1950
1781
|
}
|
|
1951
|
-
|
|
1782
|
+
const attributes = previous.attributes;
|
|
1783
|
+
if (attributes) mergeAttributes(attributes, parsed.attributes);
|
|
1952
1784
|
else previous.attributes = parsed.attributes;
|
|
1953
|
-
|
|
1785
|
+
previous.position.end = context.locator.locationAt(sourceSpan.end);
|
|
1954
1786
|
return true;
|
|
1955
1787
|
}
|
|
1956
1788
|
}]
|
|
@@ -1969,13 +1801,13 @@ const feature$17 = { inline: {
|
|
|
1969
1801
|
const valueEnd = separator < 0 || separator > close ? close : separator;
|
|
1970
1802
|
if (!source.slice(start + 2, valueEnd).trim()) return -1;
|
|
1971
1803
|
const end = close + 2;
|
|
1972
|
-
appendInlineToken(tokens,
|
|
1804
|
+
appendInlineToken(tokens, 135, start, end, valueEnd - start);
|
|
1973
1805
|
return end;
|
|
1974
1806
|
}
|
|
1975
1807
|
}],
|
|
1976
1808
|
build: [{
|
|
1977
1809
|
kind: "leaf",
|
|
1978
|
-
token:
|
|
1810
|
+
token: 135,
|
|
1979
1811
|
build(tokenIndex, sourceSpan, context) {
|
|
1980
1812
|
const source = context.view.text;
|
|
1981
1813
|
const tokenStart = inlineTokenStart(context.tokens, tokenIndex);
|
|
@@ -2017,17 +1849,17 @@ const feature$16 = { block: {
|
|
|
2017
1849
|
rule: 1,
|
|
2018
1850
|
syntax: {
|
|
2019
1851
|
kind: "block",
|
|
2020
|
-
|
|
2021
|
-
close: 4
|
|
1852
|
+
token: 64
|
|
2022
1853
|
},
|
|
2023
1854
|
build(tokenStart, context) {
|
|
2024
1855
|
const tokens = context.structure.tokens;
|
|
1856
|
+
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
2025
1857
|
return {
|
|
2026
1858
|
type: "blockquote",
|
|
2027
1859
|
children: buildBlockChildren(tokenStart, context),
|
|
2028
1860
|
position: {
|
|
2029
|
-
start
|
|
2030
|
-
end: blockEnd(tokenStart, context)
|
|
1861
|
+
start,
|
|
1862
|
+
end: context.locator.locationAt(blockEnd(tokenStart, context))
|
|
2031
1863
|
}
|
|
2032
1864
|
};
|
|
2033
1865
|
}
|
|
@@ -2058,10 +1890,10 @@ const feature$16 = { block: {
|
|
|
2058
1890
|
if (!lazyParagraph || isBlank(source, lines, index) || !lines.lazy(index) && context.startsInterruptingBlock(source, lines, index, markerOffset)) break;
|
|
2059
1891
|
quoteLines.pushLazy(lines, index);
|
|
2060
1892
|
}
|
|
2061
|
-
out.push(
|
|
1893
|
+
out.push(64, contentOffset, contentOffset + 1);
|
|
2062
1894
|
context.scanLines(source, quoteLines, out);
|
|
2063
1895
|
const end = quoteLines.next(quoteLines.length - 1);
|
|
2064
|
-
out.push(
|
|
1896
|
+
out.push(192, end, end);
|
|
2065
1897
|
return index;
|
|
2066
1898
|
}
|
|
2067
1899
|
}]
|
|
@@ -2069,13 +1901,13 @@ const feature$16 = { block: {
|
|
|
2069
1901
|
//#endregion
|
|
2070
1902
|
//#region src/profile/features/break.ts
|
|
2071
1903
|
function isThematicBreak(source, lines, index, contentOffset) {
|
|
2072
|
-
const marker = source
|
|
2073
|
-
if (marker !==
|
|
1904
|
+
const marker = source.charCodeAt(contentOffset);
|
|
1905
|
+
if (marker !== 42 && marker !== 45 && marker !== 95) return false;
|
|
2074
1906
|
let count = 0;
|
|
2075
1907
|
for (let offset = contentOffset, end = lines.end(index); offset < end; offset++) {
|
|
2076
|
-
const
|
|
2077
|
-
if (
|
|
2078
|
-
else if (
|
|
1908
|
+
const code = source.charCodeAt(offset);
|
|
1909
|
+
if (code === marker) count++;
|
|
1910
|
+
else if (code !== 32 && code !== 9) return false;
|
|
2079
1911
|
}
|
|
2080
1912
|
return count >= 3;
|
|
2081
1913
|
}
|
|
@@ -2085,15 +1917,12 @@ const feature$15 = {
|
|
|
2085
1917
|
rule: 0,
|
|
2086
1918
|
syntax: {
|
|
2087
1919
|
kind: "leaf",
|
|
2088
|
-
token:
|
|
1920
|
+
token: 256
|
|
2089
1921
|
},
|
|
2090
1922
|
build(tokenStart, context) {
|
|
2091
1923
|
return {
|
|
2092
1924
|
type: "thematicBreak",
|
|
2093
|
-
position:
|
|
2094
|
-
start: context.structure.tokens.start(tokenStart),
|
|
2095
|
-
end: blockEnd(tokenStart, context)
|
|
2096
|
-
}
|
|
1925
|
+
position: leafBlockPosition(tokenStart, context)
|
|
2097
1926
|
};
|
|
2098
1927
|
}
|
|
2099
1928
|
}],
|
|
@@ -2108,14 +1937,14 @@ const feature$15 = {
|
|
|
2108
1937
|
},
|
|
2109
1938
|
start(source, lines, start, contentOffset, out) {
|
|
2110
1939
|
if (!isThematicBreak(source, lines, start, contentOffset)) return;
|
|
2111
|
-
out.push(
|
|
1940
|
+
out.push(256, contentOffset, lines.end(start));
|
|
2112
1941
|
return start + 1;
|
|
2113
1942
|
}
|
|
2114
1943
|
}]
|
|
2115
1944
|
},
|
|
2116
1945
|
inline: { build: [{
|
|
2117
1946
|
kind: "leaf",
|
|
2118
|
-
token:
|
|
1947
|
+
token: 128,
|
|
2119
1948
|
build(tokenIndex, sourceSpan) {
|
|
2120
1949
|
return {
|
|
2121
1950
|
type: "break",
|
|
@@ -2123,14 +1952,10 @@ const feature$15 = {
|
|
|
2123
1952
|
};
|
|
2124
1953
|
}
|
|
2125
1954
|
}, {
|
|
2126
|
-
kind: "
|
|
2127
|
-
token:
|
|
2128
|
-
build(
|
|
2129
|
-
return
|
|
2130
|
-
type: "text",
|
|
2131
|
-
value: "\n",
|
|
2132
|
-
position: sourceSpan
|
|
2133
|
-
};
|
|
1955
|
+
kind: "text",
|
|
1956
|
+
token: 67,
|
|
1957
|
+
build() {
|
|
1958
|
+
return "\n";
|
|
2134
1959
|
}
|
|
2135
1960
|
}] }
|
|
2136
1961
|
};
|
|
@@ -2172,76 +1997,77 @@ function closesFence(source, lines, index, fence) {
|
|
|
2172
1997
|
while (offset < lineEnd && (source[offset] === " " || source[offset] === " ")) offset++;
|
|
2173
1998
|
return offset === lineEnd;
|
|
2174
1999
|
}
|
|
2175
|
-
function fencedBlock(source, lines, index, fence, closed) {
|
|
2000
|
+
function fencedBlock(source, lines, index, end, fence, closed) {
|
|
2176
2001
|
let infoStart = fence.offset + fence.length;
|
|
2177
2002
|
const lineEnd = lines.end(index);
|
|
2178
2003
|
while (infoStart < lineEnd && (source[infoStart] === " " || source[infoStart] === " ")) infoStart++;
|
|
2004
|
+
let content;
|
|
2005
|
+
if (lines.physicallyContiguous()) {
|
|
2006
|
+
const contentStart = lines.next(index);
|
|
2007
|
+
const lastContentLine = end - (closed ? 2 : 1);
|
|
2008
|
+
content = source.slice(contentStart, lastContentLine > index ? lines.end(lastContentLine) : contentStart);
|
|
2009
|
+
}
|
|
2179
2010
|
return {
|
|
2180
2011
|
closed,
|
|
2012
|
+
content,
|
|
2181
2013
|
indent: fence.indent,
|
|
2182
2014
|
info: source.slice(infoStart, lineEnd),
|
|
2183
2015
|
markerOffset: fence.offset - lines.start(index)
|
|
2184
2016
|
};
|
|
2185
2017
|
}
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2018
|
+
const fenceSpaceIndent = [
|
|
2019
|
+
/^(?<![\u2028\u2029]) /gm,
|
|
2020
|
+
/^(?<![\u2028\u2029]) {1,2}/gm,
|
|
2021
|
+
/^(?<![\u2028\u2029]) {1,3}/gm
|
|
2022
|
+
];
|
|
2023
|
+
const sourceColumnFenceTabIndent = [
|
|
2024
|
+
/^(?<![\u2028\u2029])\t/gm,
|
|
2025
|
+
/^(?<![\u2028\u2029]) ?\t/gm,
|
|
2026
|
+
/^(?<![\u2028\u2029]) {0,2}\t/gm
|
|
2027
|
+
];
|
|
2028
|
+
function normalizedFenceContent(source, block) {
|
|
2029
|
+
let content = source;
|
|
2030
|
+
if (block.content === void 0) {
|
|
2031
|
+
const contentStart = source.indexOf("\n") + 1;
|
|
2191
2032
|
if (!contentStart) return "";
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2033
|
+
const limit = block.closed ? source.lastIndexOf("\n", source.length - 2) + 1 : source.length;
|
|
2034
|
+
content = source.slice(contentStart, lineContentEnd(source, contentStart, limit));
|
|
2035
|
+
}
|
|
2036
|
+
return block.indent ? content.replace(fenceSpaceIndent[block.indent - 1], "") : content;
|
|
2037
|
+
}
|
|
2038
|
+
function sourceColumnFenceContent(source, block) {
|
|
2039
|
+
let content = block.content;
|
|
2040
|
+
if (content === void 0) {
|
|
2041
|
+
let contentStart = 0;
|
|
2195
2042
|
while (contentStart < source.length && source[contentStart] !== "\n" && source[contentStart] !== "\r") contentStart++;
|
|
2196
2043
|
if (contentStart < source.length) contentStart += source[contentStart] === "\r" && source[contentStart + 1] === "\n" ? 2 : 1;
|
|
2044
|
+
let limit = source.length;
|
|
2197
2045
|
if (block.closed) {
|
|
2198
|
-
|
|
2199
|
-
while (
|
|
2200
|
-
}
|
|
2201
|
-
}
|
|
2202
|
-
const end = lineContentEnd(source, contentStart, contentEnd);
|
|
2203
|
-
if (!block.indent) return source.slice(contentStart, end);
|
|
2204
|
-
const chunks = [];
|
|
2205
|
-
let lineStart = contentStart;
|
|
2206
|
-
while (lineStart < end) {
|
|
2207
|
-
const lf = source.indexOf("\n", lineStart);
|
|
2208
|
-
const cr = source.indexOf("\r", lineStart);
|
|
2209
|
-
let next = Math.min(lf < 0 ? end : lf, cr < 0 ? end : cr, end);
|
|
2210
|
-
if (next < end) next += source[next] === "\r" && source[next + 1] === "\n" ? 2 : 1;
|
|
2211
|
-
if (mode === 1) chunks.push(removeIndent(source.slice(lineStart, next), block.indent));
|
|
2212
|
-
else {
|
|
2213
|
-
let start = lineStart;
|
|
2214
|
-
while (start - lineStart < block.indent && source.charCodeAt(start) === 32) start++;
|
|
2215
|
-
chunks.push(source.slice(start, next));
|
|
2046
|
+
limit = lineContentEnd(source, contentStart, limit);
|
|
2047
|
+
while (limit > contentStart && source[limit - 1] !== "\n" && source[limit - 1] !== "\r") limit--;
|
|
2216
2048
|
}
|
|
2217
|
-
|
|
2049
|
+
content = source.slice(contentStart, lineContentEnd(source, contentStart, limit));
|
|
2218
2050
|
}
|
|
2219
|
-
|
|
2051
|
+
if (block.indent) {
|
|
2052
|
+
if (content.includes(" ")) content = content.replace(sourceColumnFenceTabIndent[block.indent - 1], " ");
|
|
2053
|
+
content = content.replace(fenceSpaceIndent[block.indent - 1], "");
|
|
2054
|
+
}
|
|
2055
|
+
return content;
|
|
2220
2056
|
}
|
|
2221
2057
|
//#endregion
|
|
2222
2058
|
//#region src/profile/features/text.ts
|
|
2223
|
-
const semanticCharacter = /\\([!"#$%&'()*+,./:;<=>?@[\\\]^_`{|}~-])|&(?:#x[\da-f]{1,6}|#\d{1,7}|[a-z][\da-z]{1,31});/gi;
|
|
2224
2059
|
const entity = /&(?:#x[0-9A-F]{1,6}|#\d{1,7}|[A-Z][A-Z0-9]{0,30});/iy;
|
|
2225
2060
|
function isAsciiPunctuation(code) {
|
|
2226
2061
|
return code >= 33 && code <= 47 || code >= 58 && code <= 64 || code >= 91 && code <= 96 || code >= 123 && code <= 126;
|
|
2227
2062
|
}
|
|
2228
2063
|
function semanticText(value) {
|
|
2229
|
-
|
|
2230
|
-
return value.replace(semanticCharacter, (match, escaped) => escaped ?? decodeHTMLStrict(match));
|
|
2064
|
+
return value.includes("\\") || value.includes("&") ? decodeString(value) : value;
|
|
2231
2065
|
}
|
|
2232
|
-
const buildInlineText = (tokenIndex,
|
|
2233
|
-
return
|
|
2234
|
-
type: "text",
|
|
2235
|
-
value: inlineTokenText(context.view.text, context.tokens, tokenIndex),
|
|
2236
|
-
position: sourceSpan
|
|
2237
|
-
};
|
|
2066
|
+
const buildInlineText = (tokenIndex, context) => {
|
|
2067
|
+
return inlineTokenText(context.view.text, context.tokens, tokenIndex);
|
|
2238
2068
|
};
|
|
2239
|
-
const buildDecodedInlineText = (tokenIndex,
|
|
2240
|
-
return
|
|
2241
|
-
type: "text",
|
|
2242
|
-
value: semanticText(inlineTokenText(context.view.text, context.tokens, tokenIndex)),
|
|
2243
|
-
position: sourceSpan
|
|
2244
|
-
};
|
|
2069
|
+
const buildDecodedInlineText = (tokenIndex, context) => {
|
|
2070
|
+
return semanticText(inlineTokenText(context.view.text, context.tokens, tokenIndex));
|
|
2245
2071
|
};
|
|
2246
2072
|
const feature$14 = { inline: {
|
|
2247
2073
|
scan: [{
|
|
@@ -2249,7 +2075,7 @@ const feature$14 = { inline: {
|
|
|
2249
2075
|
scan(source, start, tokens) {
|
|
2250
2076
|
const matchEnd = matchInlinePatternEnd(entity, source, start);
|
|
2251
2077
|
if (matchEnd < 0) return start + 1;
|
|
2252
|
-
appendInlineToken(tokens,
|
|
2078
|
+
appendInlineToken(tokens, 66, start, matchEnd);
|
|
2253
2079
|
return matchEnd;
|
|
2254
2080
|
}
|
|
2255
2081
|
}, {
|
|
@@ -2257,12 +2083,12 @@ const feature$14 = { inline: {
|
|
|
2257
2083
|
scan(source, start, tokens) {
|
|
2258
2084
|
const next = source.charCodeAt(start + 1);
|
|
2259
2085
|
if (next === 10 || next === 13) {
|
|
2260
|
-
appendInlineToken(tokens,
|
|
2086
|
+
appendInlineToken(tokens, 128, start, start + 1);
|
|
2261
2087
|
return start + 1;
|
|
2262
2088
|
}
|
|
2263
2089
|
if (isAsciiPunctuation(next)) {
|
|
2264
2090
|
const end = start + 2;
|
|
2265
|
-
appendInlineToken(tokens,
|
|
2091
|
+
appendInlineToken(tokens, 65, start, end);
|
|
2266
2092
|
return end;
|
|
2267
2093
|
}
|
|
2268
2094
|
return start + (next === 32 || next === 9 ? 2 : 1);
|
|
@@ -2270,18 +2096,18 @@ const feature$14 = { inline: {
|
|
|
2270
2096
|
}],
|
|
2271
2097
|
build: [
|
|
2272
2098
|
{
|
|
2273
|
-
kind: "
|
|
2274
|
-
token:
|
|
2099
|
+
kind: "text",
|
|
2100
|
+
token: 64,
|
|
2275
2101
|
build: buildInlineText
|
|
2276
2102
|
},
|
|
2277
2103
|
{
|
|
2278
|
-
kind: "
|
|
2279
|
-
token:
|
|
2104
|
+
kind: "text",
|
|
2105
|
+
token: 65,
|
|
2280
2106
|
build: buildDecodedInlineText
|
|
2281
2107
|
},
|
|
2282
2108
|
{
|
|
2283
|
-
kind: "
|
|
2284
|
-
token:
|
|
2109
|
+
kind: "text",
|
|
2110
|
+
token: 66,
|
|
2285
2111
|
build: buildDecodedInlineText
|
|
2286
2112
|
}
|
|
2287
2113
|
]
|
|
@@ -2303,14 +2129,13 @@ const feature$13 = {
|
|
|
2303
2129
|
rule: 8,
|
|
2304
2130
|
syntax: {
|
|
2305
2131
|
kind: "leaf",
|
|
2306
|
-
token:
|
|
2132
|
+
token: 257
|
|
2307
2133
|
},
|
|
2308
2134
|
build(tokenStart, context) {
|
|
2309
|
-
const
|
|
2310
|
-
const
|
|
2311
|
-
const source = normalizeLines(context.structure.tokens.text(context.source, tokenStart));
|
|
2312
|
-
const block = context.structure.tokens.value(tokenStart);
|
|
2135
|
+
const tokens = context.structure.tokens;
|
|
2136
|
+
const block = tokens.value(tokenStart);
|
|
2313
2137
|
if (!block) throw new Error("FencedCodeBlock token has no fence metadata");
|
|
2138
|
+
const source = context.locator.normalizeLineEndings(block.content ?? tokens.text(context.source, tokenStart));
|
|
2314
2139
|
const rawInfo = semanticText(block.info);
|
|
2315
2140
|
const langEnd = rawInfo.search(/[ \t]/);
|
|
2316
2141
|
const lang = rawInfo ? langEnd < 0 ? rawInfo : rawInfo.slice(0, langEnd) : null;
|
|
@@ -2319,34 +2144,28 @@ const feature$13 = {
|
|
|
2319
2144
|
type: "code",
|
|
2320
2145
|
lang,
|
|
2321
2146
|
meta: metaStart < 0 ? null : rawInfo.slice(langEnd + metaStart),
|
|
2322
|
-
value:
|
|
2323
|
-
position:
|
|
2324
|
-
start: offset + block.markerOffset,
|
|
2325
|
-
end: block.closed || end < context.structure.tokens.sourceLength ? blockEnd(tokenStart, context) : end
|
|
2326
|
-
}
|
|
2147
|
+
value: normalizedFenceContent(source, block),
|
|
2148
|
+
position: fencedBlockPosition(tokenStart, block, context)
|
|
2327
2149
|
};
|
|
2328
2150
|
}
|
|
2329
2151
|
}, {
|
|
2330
2152
|
rule: 9,
|
|
2331
2153
|
syntax: {
|
|
2332
2154
|
kind: "leaf",
|
|
2333
|
-
token:
|
|
2155
|
+
token: 258
|
|
2334
2156
|
},
|
|
2335
2157
|
build(tokenStart, context) {
|
|
2336
2158
|
const tokens = context.structure.tokens;
|
|
2337
2159
|
const offset = tokens.start(tokenStart);
|
|
2338
2160
|
const contentLength = tokens.value(tokenStart);
|
|
2339
|
-
const lines =
|
|
2161
|
+
const lines = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart)).split("\n").map((line) => removeIndent(line, 4));
|
|
2340
2162
|
while (lines.length && /^[ \t]*$/.test(lines[lines.length - 1])) lines.pop();
|
|
2341
2163
|
return {
|
|
2342
2164
|
type: "code",
|
|
2343
2165
|
lang: null,
|
|
2344
2166
|
meta: null,
|
|
2345
2167
|
value: lines.join("\n"),
|
|
2346
|
-
position:
|
|
2347
|
-
start: offset,
|
|
2348
|
-
end: offset + contentLength
|
|
2349
|
-
}
|
|
2168
|
+
position: context.locator.positionAt(offset, offset + contentLength)
|
|
2350
2169
|
};
|
|
2351
2170
|
}
|
|
2352
2171
|
}],
|
|
@@ -2354,11 +2173,11 @@ const feature$13 = {
|
|
|
2354
2173
|
codes: [-1],
|
|
2355
2174
|
start(source, lines, start, _contentOffset, out) {
|
|
2356
2175
|
let end = start + 1;
|
|
2357
|
-
while (end < lines.length &&
|
|
2176
|
+
while (end < lines.length && lineIndentOffset(source, lines, end) < 0) end++;
|
|
2358
2177
|
let contentEnd = end;
|
|
2359
2178
|
while (contentEnd > start && isBlank(source, lines, contentEnd - 1)) contentEnd--;
|
|
2360
2179
|
const contentLength = lines.end(contentEnd - 1) - lines.start(start);
|
|
2361
|
-
appendLogicalToken(out,
|
|
2180
|
+
appendLogicalToken(out, 258, source, lines, start, end, contentLength);
|
|
2362
2181
|
return end;
|
|
2363
2182
|
}
|
|
2364
2183
|
}, {
|
|
@@ -2373,7 +2192,7 @@ const feature$13 = {
|
|
|
2373
2192
|
while (end < lines.length && !closesFence(source, lines, end, fence)) end++;
|
|
2374
2193
|
const closed = end < lines.length;
|
|
2375
2194
|
if (end < lines.length) end++;
|
|
2376
|
-
appendLogicalToken(out,
|
|
2195
|
+
appendLogicalToken(out, 257, source, lines, start, end, fencedBlock(source, lines, start, end, fence, closed));
|
|
2377
2196
|
return end;
|
|
2378
2197
|
}
|
|
2379
2198
|
}]
|
|
@@ -2385,32 +2204,27 @@ const feature$13 = {
|
|
|
2385
2204
|
if (source.charCodeAt(start - 1) === 96) return start + 1;
|
|
2386
2205
|
const openEnd = inlineMarkerRunEnd(source, start);
|
|
2387
2206
|
const markerLength = openEnd - start;
|
|
2388
|
-
let end = -1;
|
|
2389
2207
|
let offset = openEnd;
|
|
2390
2208
|
while (offset < source.length) {
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
continue;
|
|
2394
|
-
}
|
|
2209
|
+
offset = source.indexOf("`", offset);
|
|
2210
|
+
if (offset < 0) break;
|
|
2395
2211
|
const closeEnd = inlineMarkerRunEnd(source, offset);
|
|
2396
2212
|
if (closeEnd - offset === markerLength) {
|
|
2397
|
-
|
|
2398
|
-
|
|
2213
|
+
appendInlineToken(tokens, 129, start, closeEnd, markerLength);
|
|
2214
|
+
return closeEnd;
|
|
2399
2215
|
}
|
|
2400
2216
|
offset = closeEnd;
|
|
2401
2217
|
}
|
|
2402
|
-
|
|
2403
|
-
appendInlineToken(tokens, 6, start, end, markerLength);
|
|
2404
|
-
return end;
|
|
2218
|
+
return start + 1;
|
|
2405
2219
|
}
|
|
2406
2220
|
}],
|
|
2407
2221
|
build: [{
|
|
2408
2222
|
kind: "leaf",
|
|
2409
|
-
token:
|
|
2223
|
+
token: 129,
|
|
2410
2224
|
build: (tokenIndex, sourceSpan, context) => {
|
|
2411
2225
|
const text = inlineTokenText(context.view.text, context.tokens, tokenIndex);
|
|
2412
2226
|
const markerLength = inlineTokenData(context.tokens, tokenIndex);
|
|
2413
|
-
let value =
|
|
2227
|
+
let value = context.locator.normalizeLineEndings(text.slice(markerLength, -markerLength));
|
|
2414
2228
|
if (/^[ \n]/.test(value) && /[ \n]$/.test(value) && /[^ \n]/.test(value)) value = value.slice(1, -1);
|
|
2415
2229
|
return {
|
|
2416
2230
|
type: "inlineCode",
|
|
@@ -2422,6 +2236,176 @@ const feature$13 = {
|
|
|
2422
2236
|
}
|
|
2423
2237
|
};
|
|
2424
2238
|
//#endregion
|
|
2239
|
+
//#region src/fragment/inline.ts
|
|
2240
|
+
function createInlineOutput(children, cursor) {
|
|
2241
|
+
return {
|
|
2242
|
+
children,
|
|
2243
|
+
cursor,
|
|
2244
|
+
lastText: void 0,
|
|
2245
|
+
textEnd: -1,
|
|
2246
|
+
trailingSpaces: 0
|
|
2247
|
+
};
|
|
2248
|
+
}
|
|
2249
|
+
function lineEndingStart(source, lineStart) {
|
|
2250
|
+
return source.charCodeAt(lineStart - 1) === 10 && source.charCodeAt(lineStart - 2) === 13 ? lineStart - 2 : lineStart - 1;
|
|
2251
|
+
}
|
|
2252
|
+
function trimTrailingText(output) {
|
|
2253
|
+
const text = output.lastText;
|
|
2254
|
+
const removed = text ? output.trailingSpaces : 0;
|
|
2255
|
+
if (removed > 0) {
|
|
2256
|
+
text.value = text.value.slice(0, -removed);
|
|
2257
|
+
output.trailingSpaces = 0;
|
|
2258
|
+
}
|
|
2259
|
+
return removed;
|
|
2260
|
+
}
|
|
2261
|
+
function appendText(output, value, start, end, context) {
|
|
2262
|
+
const previousText = output.lastText;
|
|
2263
|
+
const mergeForward = previousText !== void 0 && !("attributes" in previousText);
|
|
2264
|
+
let offset = value.length;
|
|
2265
|
+
while (offset > 0) {
|
|
2266
|
+
const code = value.charCodeAt(offset - 1);
|
|
2267
|
+
if (code !== 32 && code !== 9) break;
|
|
2268
|
+
offset--;
|
|
2269
|
+
}
|
|
2270
|
+
const trailingSpaces = value.length - offset;
|
|
2271
|
+
output.trailingSpaces = trailingSpaces === value.length && mergeForward ? output.trailingSpaces + trailingSpaces : trailingSpaces;
|
|
2272
|
+
if (mergeForward) previousText.value += value;
|
|
2273
|
+
else {
|
|
2274
|
+
const startLocation = context.locator.locationAt(start);
|
|
2275
|
+
const text = {
|
|
2276
|
+
type: "text",
|
|
2277
|
+
value,
|
|
2278
|
+
position: {
|
|
2279
|
+
start: startLocation,
|
|
2280
|
+
end: startLocation
|
|
2281
|
+
}
|
|
2282
|
+
};
|
|
2283
|
+
output.children.push(text);
|
|
2284
|
+
output.lastText = text;
|
|
2285
|
+
}
|
|
2286
|
+
output.textEnd = end;
|
|
2287
|
+
}
|
|
2288
|
+
function finishText(output, context) {
|
|
2289
|
+
const end = output.textEnd;
|
|
2290
|
+
if (end >= 0) {
|
|
2291
|
+
output.lastText.position.end = context.locator.locationAt(end);
|
|
2292
|
+
output.textEnd = -1;
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
function appendGap(output, context, start, end) {
|
|
2296
|
+
appendText(output, context.view.text.slice(start, end), context.view.mapOffset(start), context.view.mapEnd(end), context);
|
|
2297
|
+
}
|
|
2298
|
+
function appendToken(output, context, tokenIndex, viewStart, viewEnd, build, textToken, syntaxNewline) {
|
|
2299
|
+
const cursor = output.cursor;
|
|
2300
|
+
if (!syntaxNewline) {
|
|
2301
|
+
if (viewStart > cursor) appendGap(output, context, cursor, viewStart);
|
|
2302
|
+
} else {
|
|
2303
|
+
const viewLineStart = inlineTokenData(context.tokens, tokenIndex);
|
|
2304
|
+
const viewLineEndingStart = lineEndingStart(context.view.text, viewLineStart);
|
|
2305
|
+
if (viewStart > cursor) {
|
|
2306
|
+
if (viewLineEndingStart > cursor) appendGap(output, context, cursor, viewLineEndingStart);
|
|
2307
|
+
}
|
|
2308
|
+
const previous = output.children.at(-1);
|
|
2309
|
+
if (previous?.type === "break") {
|
|
2310
|
+
previous.position.end = context.locator.locationAt(context.view.mapOffset(viewLineStart - 1) + 1);
|
|
2311
|
+
return;
|
|
2312
|
+
}
|
|
2313
|
+
viewStart = viewLineEndingStart;
|
|
2314
|
+
trimTrailingText(output);
|
|
2315
|
+
}
|
|
2316
|
+
const sourceStart = context.view.mapOffset(viewStart);
|
|
2317
|
+
const sourceEnd = viewStart === viewEnd ? sourceStart : context.view.mapEnd(viewEnd);
|
|
2318
|
+
if (textToken) appendText(output, build(tokenIndex, context), sourceStart, sourceEnd, context);
|
|
2319
|
+
else {
|
|
2320
|
+
finishText(output, context);
|
|
2321
|
+
output.children.push(build(tokenIndex, context.locator.positionAt(sourceStart, sourceEnd), context));
|
|
2322
|
+
output.lastText = void 0;
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
function appendRange(startToken, endToken, profile, context, output, closeKind = 0) {
|
|
2326
|
+
let index = startToken;
|
|
2327
|
+
while (index < endToken) {
|
|
2328
|
+
const kind = inlineTokenKind(context.tokens, index);
|
|
2329
|
+
if (kind === closeKind) break;
|
|
2330
|
+
const build = profile.buildByKind[kind];
|
|
2331
|
+
const childStart = inlineTokenStart(context.tokens, index);
|
|
2332
|
+
if (kind < 192) {
|
|
2333
|
+
const childEnd = inlineTokenEnd(context.tokens, index);
|
|
2334
|
+
appendToken(output, context, index, childStart, childEnd, build, kind < 128, kind === 67);
|
|
2335
|
+
output.cursor = childEnd;
|
|
2336
|
+
index++;
|
|
2337
|
+
continue;
|
|
2338
|
+
}
|
|
2339
|
+
if (kind < 256) {
|
|
2340
|
+
if (childStart > output.cursor) appendGap(output, context, output.cursor, childStart);
|
|
2341
|
+
finishText(output, context);
|
|
2342
|
+
index = appendSemantic(index, endToken, profile, context, output, build, kind + 1);
|
|
2343
|
+
continue;
|
|
2344
|
+
}
|
|
2345
|
+
const childEnd = inlineTokenEnd(context.tokens, index);
|
|
2346
|
+
finishText(output, context);
|
|
2347
|
+
const sourceStart = context.view.mapOffset(childStart);
|
|
2348
|
+
const sourceSpan = {
|
|
2349
|
+
start: sourceStart,
|
|
2350
|
+
end: childStart === childEnd ? sourceStart : context.view.mapEnd(childEnd)
|
|
2351
|
+
};
|
|
2352
|
+
if (build(index, sourceSpan, context, output)) {
|
|
2353
|
+
const previous = output.children.at(-1);
|
|
2354
|
+
output.lastText = previous?.type === "text" ? previous : void 0;
|
|
2355
|
+
output.cursor = childEnd;
|
|
2356
|
+
}
|
|
2357
|
+
index++;
|
|
2358
|
+
}
|
|
2359
|
+
if (index < endToken) {
|
|
2360
|
+
const contentEnd = inlineTokenStart(context.tokens, index);
|
|
2361
|
+
if (contentEnd > output.cursor) appendGap(output, context, output.cursor, contentEnd);
|
|
2362
|
+
} else if (context.view.text.length > output.cursor) appendGap(output, context, output.cursor, context.view.text.length);
|
|
2363
|
+
finishText(output, context);
|
|
2364
|
+
return index;
|
|
2365
|
+
}
|
|
2366
|
+
function appendSemantic(openToken, endToken, profile, context, output, build, closeKind) {
|
|
2367
|
+
const childStart = inlineTokenStart(context.tokens, openToken);
|
|
2368
|
+
const positionStart = context.locator.locationAt(context.view.mapOffset(childStart));
|
|
2369
|
+
const children = [];
|
|
2370
|
+
const childOutput = createInlineOutput(children, inlineTokenEnd(context.tokens, openToken));
|
|
2371
|
+
const closeToken = appendRange(openToken + 1, endToken, profile, context, childOutput, closeKind);
|
|
2372
|
+
const childEnd = inlineTokenEnd(context.tokens, closeToken);
|
|
2373
|
+
const value = build(openToken, closeToken, {
|
|
2374
|
+
start: positionStart,
|
|
2375
|
+
end: context.locator.locationAt(context.view.mapEnd(childEnd))
|
|
2376
|
+
}, children, context);
|
|
2377
|
+
output.children.push(value);
|
|
2378
|
+
output.lastText = void 0;
|
|
2379
|
+
output.cursor = childEnd;
|
|
2380
|
+
return closeToken + 1;
|
|
2381
|
+
}
|
|
2382
|
+
function buildInlineFragment(tokenStart, blockRule, context) {
|
|
2383
|
+
const region = context.cursor ? context.cursor.take(tokenStart) : resolveInlineRegion(context.source, context.profile, context.structure.tokens, tokenStart);
|
|
2384
|
+
if (!region) return { children: [] };
|
|
2385
|
+
const { tokens, view } = region;
|
|
2386
|
+
const inlineContext = context.inlineContext ??= {
|
|
2387
|
+
blockRule,
|
|
2388
|
+
locator: context.locator,
|
|
2389
|
+
tokens,
|
|
2390
|
+
view
|
|
2391
|
+
};
|
|
2392
|
+
inlineContext.blockRule = blockRule;
|
|
2393
|
+
inlineContext.tokens = tokens;
|
|
2394
|
+
inlineContext.view = view;
|
|
2395
|
+
const result = createInlineOutput([], 0);
|
|
2396
|
+
appendRange(0, inlineTokenCount(tokens), context.profile, inlineContext, result);
|
|
2397
|
+
const last = result.lastText;
|
|
2398
|
+
if (last) {
|
|
2399
|
+
const removed = trimTrailingText(result);
|
|
2400
|
+
if (removed > 0) {
|
|
2401
|
+
last.position.end.offset -= removed;
|
|
2402
|
+
last.position.end.column -= removed;
|
|
2403
|
+
}
|
|
2404
|
+
if (!last.value) result.children.pop();
|
|
2405
|
+
}
|
|
2406
|
+
return result;
|
|
2407
|
+
}
|
|
2408
|
+
//#endregion
|
|
2425
2409
|
//#region src/profile/features/frontmatter.ts
|
|
2426
2410
|
function frontmatterFenceAt(source, lines, index, marker) {
|
|
2427
2411
|
const start = lines.start(index);
|
|
@@ -2431,7 +2415,7 @@ function frontmatterFenceAt(source, lines, index, marker) {
|
|
|
2431
2415
|
}
|
|
2432
2416
|
const buildFrontmatter = (tokenStart, context) => {
|
|
2433
2417
|
const tokens = context.structure.tokens;
|
|
2434
|
-
const text =
|
|
2418
|
+
const text = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
|
|
2435
2419
|
const contentStart = text.indexOf("\n") + 1;
|
|
2436
2420
|
const closingEnd = text.endsWith("\n") ? text.length - 1 : text.length;
|
|
2437
2421
|
const closingStart = text.lastIndexOf("\n", closingEnd - 1) + 1;
|
|
@@ -2440,10 +2424,7 @@ const buildFrontmatter = (tokenStart, context) => {
|
|
|
2440
2424
|
return {
|
|
2441
2425
|
type: "yaml",
|
|
2442
2426
|
value,
|
|
2443
|
-
position:
|
|
2444
|
-
start: tokens.start(tokenStart),
|
|
2445
|
-
end: blockEnd(tokenStart, context)
|
|
2446
|
-
}
|
|
2427
|
+
position: leafBlockPosition(tokenStart, context)
|
|
2447
2428
|
};
|
|
2448
2429
|
};
|
|
2449
2430
|
function feature$12(marker) {
|
|
@@ -2452,7 +2433,7 @@ function feature$12(marker) {
|
|
|
2452
2433
|
rule: 13,
|
|
2453
2434
|
syntax: {
|
|
2454
2435
|
kind: "leaf",
|
|
2455
|
-
token:
|
|
2436
|
+
token: 260
|
|
2456
2437
|
},
|
|
2457
2438
|
build: buildFrontmatter
|
|
2458
2439
|
}],
|
|
@@ -2461,7 +2442,7 @@ function feature$12(marker) {
|
|
|
2461
2442
|
start(source, lines, start, contentOffset, out, context) {
|
|
2462
2443
|
if (lines.start(start) !== 0 || !frontmatterFenceAt(source, lines, start, marker)) return;
|
|
2463
2444
|
for (let end = start + 1; end < lines.length; end++) if (frontmatterFenceAt(source, lines, end, marker)) {
|
|
2464
|
-
appendLogicalToken(out,
|
|
2445
|
+
appendLogicalToken(out, 260, source, lines, start, end + 1);
|
|
2465
2446
|
return end + 1;
|
|
2466
2447
|
}
|
|
2467
2448
|
context.retainLookahead(lines.next(lines.length - 1));
|
|
@@ -2604,14 +2585,14 @@ function nextSlot(source, lines, start, end) {
|
|
|
2604
2585
|
}
|
|
2605
2586
|
}
|
|
2606
2587
|
function emitSlotOpening(opening, out) {
|
|
2607
|
-
out.push(
|
|
2608
|
-
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(
|
|
2588
|
+
out.push(75, opening.offset, opening.nameEnd);
|
|
2589
|
+
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(3, opening.attributesStart, opening.attributesEnd);
|
|
2609
2590
|
}
|
|
2610
2591
|
function emitComponentBody(source, lines, start, end, closingOffset, out, context) {
|
|
2611
2592
|
let cursor = start;
|
|
2612
2593
|
const yamlEnd = cursor < end ? yamlPropsEnd(source, lines, cursor, end) : void 0;
|
|
2613
2594
|
if (yamlEnd !== void 0) {
|
|
2614
|
-
appendLogicalToken(out,
|
|
2595
|
+
appendLogicalToken(out, 262, source, lines, cursor, yamlEnd);
|
|
2615
2596
|
cursor = yamlEnd;
|
|
2616
2597
|
}
|
|
2617
2598
|
let slot = nextSlot(source, lines, cursor, end);
|
|
@@ -2626,28 +2607,29 @@ function emitComponentBody(source, lines, start, end, closingOffset, out, contex
|
|
|
2626
2607
|
emitSlotOpening(slot.opening, out);
|
|
2627
2608
|
context.scanLines(source, lines.slice(slot.index + 1, next), out);
|
|
2628
2609
|
const slotEnd = following ? following.opening.offset : closingOffset;
|
|
2629
|
-
out.push(
|
|
2610
|
+
out.push(204, slotEnd, slotEnd);
|
|
2630
2611
|
slot = following;
|
|
2631
2612
|
}
|
|
2632
2613
|
}
|
|
2633
2614
|
function emitOpening(contentOffset, opening, out) {
|
|
2634
|
-
out.push(
|
|
2615
|
+
out.push(74, contentOffset, opening.nameEnd);
|
|
2635
2616
|
if (opening.labelStart !== void 0 && opening.labelEnd !== void 0) {
|
|
2636
|
-
out.push(
|
|
2617
|
+
out.push(133, opening.labelStart, opening.labelStart + 1);
|
|
2637
2618
|
if (opening.labelEnd > opening.labelStart + 2) out.push(1, opening.labelStart + 1, opening.labelEnd - 1);
|
|
2638
|
-
out.push(
|
|
2619
|
+
out.push(203, opening.labelEnd - 1, opening.labelEnd);
|
|
2639
2620
|
}
|
|
2640
|
-
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(
|
|
2621
|
+
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(3, opening.attributesStart, opening.attributesEnd);
|
|
2641
2622
|
}
|
|
2642
|
-
const buildBlockLabel = (tokenStart, context
|
|
2623
|
+
const buildBlockLabel = (tokenStart, context) => {
|
|
2643
2624
|
const tokens = context.structure.tokens;
|
|
2644
2625
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
2626
|
+
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
2645
2627
|
return {
|
|
2646
2628
|
type: "paragraph",
|
|
2647
|
-
children:
|
|
2629
|
+
children: buildInlineFragment(tokenStart, 20, context).children,
|
|
2648
2630
|
position: {
|
|
2649
|
-
start
|
|
2650
|
-
end: tokens.end(close)
|
|
2631
|
+
start,
|
|
2632
|
+
end: context.locator.locationAt(tokens.end(close))
|
|
2651
2633
|
}
|
|
2652
2634
|
};
|
|
2653
2635
|
};
|
|
@@ -2658,7 +2640,7 @@ function createBlockStart(shorthand) {
|
|
|
2658
2640
|
if (shorthand) {
|
|
2659
2641
|
emitOpening(contentOffset, opening, out);
|
|
2660
2642
|
const lineEnd = lines.end(start);
|
|
2661
|
-
out.push(
|
|
2643
|
+
out.push(202, lineEnd, lineEnd);
|
|
2662
2644
|
return start + 1;
|
|
2663
2645
|
}
|
|
2664
2646
|
const closing = blockClose(source, lines, start, opening);
|
|
@@ -2668,7 +2650,7 @@ function createBlockStart(shorthand) {
|
|
|
2668
2650
|
}
|
|
2669
2651
|
emitOpening(contentOffset, opening, out);
|
|
2670
2652
|
emitComponentBody(source, lines, start + 1, closing.index, closing.offset, out, context);
|
|
2671
|
-
out.push(
|
|
2653
|
+
out.push(202, closing.offset, lines.end(closing.index));
|
|
2672
2654
|
return closing.index + 1;
|
|
2673
2655
|
};
|
|
2674
2656
|
}
|
|
@@ -2677,7 +2659,7 @@ const blockRules$2 = [
|
|
|
2677
2659
|
rule: 21,
|
|
2678
2660
|
syntax: {
|
|
2679
2661
|
kind: "leaf",
|
|
2680
|
-
token:
|
|
2662
|
+
token: 262
|
|
2681
2663
|
},
|
|
2682
2664
|
build: buildFrontmatter
|
|
2683
2665
|
},
|
|
@@ -2685,8 +2667,7 @@ const blockRules$2 = [
|
|
|
2685
2667
|
rule: 20,
|
|
2686
2668
|
syntax: {
|
|
2687
2669
|
kind: "frame",
|
|
2688
|
-
|
|
2689
|
-
close: 41
|
|
2670
|
+
token: 133
|
|
2690
2671
|
},
|
|
2691
2672
|
inlineContent: true,
|
|
2692
2673
|
build: buildBlockLabel
|
|
@@ -2695,19 +2676,19 @@ const blockRules$2 = [
|
|
|
2695
2676
|
rule: 19,
|
|
2696
2677
|
syntax: {
|
|
2697
2678
|
kind: "block",
|
|
2698
|
-
|
|
2699
|
-
close: 39
|
|
2679
|
+
token: 74
|
|
2700
2680
|
},
|
|
2701
2681
|
build(tokenStart, context) {
|
|
2702
2682
|
const tokens = context.structure.tokens;
|
|
2703
2683
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
2704
2684
|
let openingToken = tokenStart + 1;
|
|
2705
|
-
const label = tokens.kind(openingToken) ===
|
|
2685
|
+
const label = tokens.kind(openingToken) === 133 ? openingToken : void 0;
|
|
2706
2686
|
if (label !== void 0) openingToken += tokens.nodeLength(label);
|
|
2707
|
-
const attributesToken = tokens.kind(openingToken) ===
|
|
2687
|
+
const attributesToken = tokens.kind(openingToken) === 3 ? openingToken++ : void 0;
|
|
2708
2688
|
const parsed = attributesToken !== void 0 ? parseAttributes(context.source, tokens.start(attributesToken)) : void 0;
|
|
2689
|
+
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
2709
2690
|
const children = [];
|
|
2710
|
-
if (label) children.push(
|
|
2691
|
+
if (label) children.push(buildBlockNode(label, context));
|
|
2711
2692
|
children.push(...buildBlockChildren(tokenStart, context));
|
|
2712
2693
|
const opening = tokens.text(context.source, tokenStart);
|
|
2713
2694
|
return {
|
|
@@ -2715,8 +2696,8 @@ const blockRules$2 = [
|
|
|
2715
2696
|
name: normalizeComponentName(opening.slice(opening.lastIndexOf(":") + 1).trim()),
|
|
2716
2697
|
attributes: parsed?.attributes ?? {},
|
|
2717
2698
|
position: {
|
|
2718
|
-
start
|
|
2719
|
-
end: tokens.end(close)
|
|
2699
|
+
start,
|
|
2700
|
+
end: context.locator.locationAt(tokens.end(close))
|
|
2720
2701
|
},
|
|
2721
2702
|
children
|
|
2722
2703
|
};
|
|
@@ -2726,14 +2707,14 @@ const blockRules$2 = [
|
|
|
2726
2707
|
rule: 22,
|
|
2727
2708
|
syntax: {
|
|
2728
2709
|
kind: "block",
|
|
2729
|
-
|
|
2730
|
-
close: 45
|
|
2710
|
+
token: 75
|
|
2731
2711
|
},
|
|
2732
2712
|
build(tokenStart, context) {
|
|
2733
2713
|
const tokens = context.structure.tokens;
|
|
2734
2714
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
2735
|
-
const attributesToken = tokens.kind(tokenStart + 1) ===
|
|
2715
|
+
const attributesToken = tokens.kind(tokenStart + 1) === 3 ? tokenStart + 1 : void 0;
|
|
2736
2716
|
const parsed = attributesToken !== void 0 ? parseAttributes(context.source, tokens.start(attributesToken)) : void 0;
|
|
2717
|
+
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
2737
2718
|
const children = buildBlockChildren(tokenStart, context);
|
|
2738
2719
|
return {
|
|
2739
2720
|
type: "blockComponent",
|
|
@@ -2744,8 +2725,8 @@ const blockRules$2 = [
|
|
|
2744
2725
|
},
|
|
2745
2726
|
children,
|
|
2746
2727
|
position: {
|
|
2747
|
-
start
|
|
2748
|
-
end: tokens.end(close)
|
|
2728
|
+
start,
|
|
2729
|
+
end: context.locator.locationAt(tokens.end(close))
|
|
2749
2730
|
}
|
|
2750
2731
|
};
|
|
2751
2732
|
}
|
|
@@ -2769,9 +2750,25 @@ function canStartInlineColon(source, start) {
|
|
|
2769
2750
|
const previous = source[start - 1];
|
|
2770
2751
|
return previous !== ":" && allowedPrevious.test(previous);
|
|
2771
2752
|
}
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2753
|
+
const inlineScans = [{
|
|
2754
|
+
marker: 58,
|
|
2755
|
+
scan(source, start, tokens) {
|
|
2756
|
+
const end = canStartInlineColon(source, start) ? componentNameEnd(source, start + 1, false) : void 0;
|
|
2757
|
+
if (end === void 0) return -1;
|
|
2758
|
+
appendInlineToken(tokens, 137, start, end);
|
|
2759
|
+
return end;
|
|
2760
|
+
}
|
|
2761
|
+
}];
|
|
2762
|
+
const buildInlineComponent = (open, close, sourceSpan, children, context) => {
|
|
2763
|
+
const nameEnd = inlineTokenEnd(context.tokens, open) - (inlineTokenKind(context.tokens, open) === 208 ? 1 : 0);
|
|
2764
|
+
return {
|
|
2765
|
+
type: "inlineComponent",
|
|
2766
|
+
name: normalizeComponentName(context.view.text.slice(inlineTokenStart(context.tokens, open) + 1, nameEnd)),
|
|
2767
|
+
attributes: {},
|
|
2768
|
+
children,
|
|
2769
|
+
position: sourceSpan
|
|
2770
|
+
};
|
|
2771
|
+
};
|
|
2775
2772
|
//#endregion
|
|
2776
2773
|
//#region src/profile/features/component/index.ts
|
|
2777
2774
|
const feature$11 = {
|
|
@@ -2780,43 +2777,34 @@ const feature$11 = {
|
|
|
2780
2777
|
starts: blockStarts$2
|
|
2781
2778
|
},
|
|
2782
2779
|
inline: {
|
|
2783
|
-
scan:
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
close: 36,
|
|
2810
|
-
build(open, close, sourceSpan, children) {
|
|
2811
|
-
return {
|
|
2812
|
-
type: "inlineComponent",
|
|
2813
|
-
name: "span",
|
|
2814
|
-
attributes: {},
|
|
2815
|
-
children,
|
|
2816
|
-
position: sourceSpan
|
|
2817
|
-
};
|
|
2780
|
+
scan: inlineScans,
|
|
2781
|
+
build: [
|
|
2782
|
+
{
|
|
2783
|
+
kind: "leaf",
|
|
2784
|
+
token: 137,
|
|
2785
|
+
build(token, sourceSpan, context) {
|
|
2786
|
+
return buildInlineComponent(token, token, sourceSpan, [], context);
|
|
2787
|
+
}
|
|
2788
|
+
},
|
|
2789
|
+
{
|
|
2790
|
+
kind: "pair",
|
|
2791
|
+
token: 208,
|
|
2792
|
+
build: buildInlineComponent
|
|
2793
|
+
},
|
|
2794
|
+
{
|
|
2795
|
+
kind: "pair",
|
|
2796
|
+
token: 206,
|
|
2797
|
+
build(open, close, sourceSpan, children) {
|
|
2798
|
+
return {
|
|
2799
|
+
type: "inlineComponent",
|
|
2800
|
+
name: "span",
|
|
2801
|
+
attributes: {},
|
|
2802
|
+
children,
|
|
2803
|
+
position: sourceSpan
|
|
2804
|
+
};
|
|
2805
|
+
}
|
|
2818
2806
|
}
|
|
2819
|
-
|
|
2807
|
+
]
|
|
2820
2808
|
}
|
|
2821
2809
|
};
|
|
2822
2810
|
//#endregion
|
|
@@ -2833,13 +2821,13 @@ const feature$10 = { inline: {
|
|
|
2833
2821
|
while (isShortcodeCharacter(source.charCodeAt(end))) end++;
|
|
2834
2822
|
if (end === start + 1 || source.charCodeAt(end) !== 58) return -1;
|
|
2835
2823
|
end++;
|
|
2836
|
-
appendInlineToken(tokens,
|
|
2824
|
+
appendInlineToken(tokens, 136, start, end);
|
|
2837
2825
|
return end;
|
|
2838
2826
|
}
|
|
2839
2827
|
}],
|
|
2840
2828
|
build: [{
|
|
2841
2829
|
kind: "leaf",
|
|
2842
|
-
token:
|
|
2830
|
+
token: 136,
|
|
2843
2831
|
build(tokenIndex, sourceSpan, context) {
|
|
2844
2832
|
return {
|
|
2845
2833
|
type: "emoji",
|
|
@@ -2853,7 +2841,7 @@ const feature$10 = { inline: {
|
|
|
2853
2841
|
//#region src/profile/utils.ts
|
|
2854
2842
|
function normalizeAssociationLabel(label) {
|
|
2855
2843
|
scan: {
|
|
2856
|
-
let
|
|
2844
|
+
let hasUppercase = false;
|
|
2857
2845
|
for (let index = 0; index < label.length; index++) {
|
|
2858
2846
|
const code = label.charCodeAt(index);
|
|
2859
2847
|
if (code === 32) {
|
|
@@ -2861,29 +2849,31 @@ function normalizeAssociationLabel(label) {
|
|
|
2861
2849
|
continue;
|
|
2862
2850
|
}
|
|
2863
2851
|
if (code < 32 || code > 126) break scan;
|
|
2864
|
-
if (code >=
|
|
2852
|
+
if (code >= 65 && code <= 90) hasUppercase = true;
|
|
2865
2853
|
}
|
|
2866
|
-
return
|
|
2854
|
+
return hasUppercase ? label.toLowerCase() : label;
|
|
2867
2855
|
}
|
|
2868
|
-
return label.trim().replace(/[ \t\r\n]+/g, " ").toLowerCase().toUpperCase();
|
|
2856
|
+
return label.trim().replace(/[ \t\r\n]+/g, " ").toLowerCase().toUpperCase().toLowerCase();
|
|
2869
2857
|
}
|
|
2870
2858
|
//#endregion
|
|
2871
2859
|
//#region src/profile/features/footnote/shared.ts
|
|
2872
2860
|
const footnoteDefinitionPrefix = "footnote\0";
|
|
2861
|
+
function isLabelWhitespace(code) {
|
|
2862
|
+
return code === 32 || code === 9 || code === 10 || code === 13;
|
|
2863
|
+
}
|
|
2873
2864
|
function footnoteLabelAt(source, start, limit) {
|
|
2874
|
-
if (source
|
|
2865
|
+
if (source.charCodeAt(start) !== 91 || source.charCodeAt(start + 1) !== 94) return;
|
|
2875
2866
|
const labelStart = start + 2;
|
|
2876
2867
|
let offset = labelStart;
|
|
2877
2868
|
let length = 0;
|
|
2878
2869
|
while (offset < limit) {
|
|
2879
|
-
const
|
|
2880
|
-
if (
|
|
2881
|
-
if (
|
|
2882
|
-
|
|
2883
|
-
if (escaped === " " || escaped === " " || escaped === "\n" || escaped === "\r") return;
|
|
2870
|
+
const code = source.charCodeAt(offset);
|
|
2871
|
+
if (isLabelWhitespace(code)) return;
|
|
2872
|
+
if (code === 92 && offset + 1 < limit) {
|
|
2873
|
+
if (isLabelWhitespace(source.charCodeAt(offset + 1))) return;
|
|
2884
2874
|
offset += 2;
|
|
2885
2875
|
length += 2;
|
|
2886
|
-
} else if (
|
|
2876
|
+
} else if (code === 93) {
|
|
2887
2877
|
if (length === 0) return;
|
|
2888
2878
|
const label = source.slice(labelStart, offset);
|
|
2889
2879
|
const normalizedLabel = normalizeAssociationLabel(label);
|
|
@@ -2894,7 +2884,7 @@ function footnoteLabelAt(source, start, limit) {
|
|
|
2894
2884
|
normalizedLabel
|
|
2895
2885
|
};
|
|
2896
2886
|
} else {
|
|
2897
|
-
if (
|
|
2887
|
+
if (code === 91) return;
|
|
2898
2888
|
offset++;
|
|
2899
2889
|
length++;
|
|
2900
2890
|
}
|
|
@@ -2906,10 +2896,14 @@ function footnoteLabelAt(source, start, limit) {
|
|
|
2906
2896
|
function definitionAt(source, lines, index, markerStart) {
|
|
2907
2897
|
const lineEnd = lines.end(index);
|
|
2908
2898
|
const label = footnoteLabelAt(source, markerStart, lineEnd);
|
|
2909
|
-
if (!label || source
|
|
2899
|
+
if (!label || source.charCodeAt(label.end) !== 58) return;
|
|
2910
2900
|
const markerEnd = label.end + 1;
|
|
2911
2901
|
let contentOffset = markerEnd;
|
|
2912
|
-
while (contentOffset < lineEnd
|
|
2902
|
+
while (contentOffset < lineEnd) {
|
|
2903
|
+
const code = source.charCodeAt(contentOffset);
|
|
2904
|
+
if (code !== 32 && code !== 9) break;
|
|
2905
|
+
contentOffset++;
|
|
2906
|
+
}
|
|
2913
2907
|
return {
|
|
2914
2908
|
...label,
|
|
2915
2909
|
contentOffset,
|
|
@@ -2918,7 +2912,7 @@ function definitionAt(source, lines, index, markerStart) {
|
|
|
2918
2912
|
}
|
|
2919
2913
|
function definitionFields(tokens, token) {
|
|
2920
2914
|
const fields = tokens.value(token);
|
|
2921
|
-
if (tokens.kind(token) !==
|
|
2915
|
+
if (tokens.kind(token) !== 72 || !fields) throw new Error("Expected FootnoteDefinitionOpen token to contain parsed fields");
|
|
2922
2916
|
return fields;
|
|
2923
2917
|
}
|
|
2924
2918
|
//#endregion
|
|
@@ -2929,19 +2923,21 @@ const feature$9 = {
|
|
|
2929
2923
|
rule: 12,
|
|
2930
2924
|
syntax: {
|
|
2931
2925
|
kind: "block",
|
|
2932
|
-
|
|
2933
|
-
close: 26
|
|
2926
|
+
token: 72
|
|
2934
2927
|
},
|
|
2935
2928
|
build(tokenStart, context) {
|
|
2936
|
-
const
|
|
2929
|
+
const tokens = context.structure.tokens;
|
|
2930
|
+
const fields = definitionFields(tokens, tokenStart);
|
|
2931
|
+
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
2932
|
+
const children = buildBlockChildren(tokenStart, context);
|
|
2937
2933
|
return {
|
|
2938
2934
|
type: "footnoteDefinition",
|
|
2939
|
-
identifier: fields.normalizedLabel
|
|
2935
|
+
identifier: fields.normalizedLabel,
|
|
2940
2936
|
label: semanticText(fields.label),
|
|
2941
|
-
children
|
|
2937
|
+
children,
|
|
2942
2938
|
position: {
|
|
2943
|
-
start
|
|
2944
|
-
end: blockEnd(tokenStart, context)
|
|
2939
|
+
start,
|
|
2940
|
+
end: context.locator.locationAt(blockEnd(tokenStart, context))
|
|
2945
2941
|
}
|
|
2946
2942
|
};
|
|
2947
2943
|
}
|
|
@@ -2965,15 +2961,14 @@ const feature$9 = {
|
|
|
2965
2961
|
let index = start + 1;
|
|
2966
2962
|
let lazyParagraph = context.endsWithParagraphLeaf(source, definitionLines, 0);
|
|
2967
2963
|
while (index < lines.length) {
|
|
2968
|
-
|
|
2964
|
+
const line = definitionLines.pushAfterColumns(source, lines, index, 4);
|
|
2965
|
+
if (line === 0) {
|
|
2969
2966
|
definitionLines.pushFrom(lines, index);
|
|
2970
2967
|
lazyParagraph = false;
|
|
2971
2968
|
index++;
|
|
2972
2969
|
continue;
|
|
2973
2970
|
}
|
|
2974
|
-
|
|
2975
|
-
if (content) {
|
|
2976
|
-
definitionLines.pushFrom(lines, index, content.offset, content.prefixColumns);
|
|
2971
|
+
if (line === 1) {
|
|
2977
2972
|
lazyParagraph = context.endsWithParagraphLeaf(source, definitionLines, definitionLines.length - 1);
|
|
2978
2973
|
index++;
|
|
2979
2974
|
continue;
|
|
@@ -2983,7 +2978,7 @@ const feature$9 = {
|
|
|
2983
2978
|
index++;
|
|
2984
2979
|
}
|
|
2985
2980
|
while (definitionLines.length > 0 && isBlank(source, definitionLines, definitionLines.length - 1)) definitionLines.pop();
|
|
2986
|
-
out.push(
|
|
2981
|
+
out.push(72, contentOffset, match.markerEnd, {
|
|
2987
2982
|
definitionKey: match.definitionKey,
|
|
2988
2983
|
value: {
|
|
2989
2984
|
label: match.label,
|
|
@@ -2992,19 +2987,19 @@ const feature$9 = {
|
|
|
2992
2987
|
});
|
|
2993
2988
|
context.scanLines(source, definitionLines, out);
|
|
2994
2989
|
const end = definitionLines.length > 0 ? definitionLines.next(definitionLines.length - 1) : match.markerEnd;
|
|
2995
|
-
out.push(
|
|
2990
|
+
out.push(199, end, end);
|
|
2996
2991
|
return index;
|
|
2997
2992
|
}
|
|
2998
2993
|
}]
|
|
2999
2994
|
},
|
|
3000
2995
|
inline: { build: [{
|
|
3001
2996
|
kind: "leaf",
|
|
3002
|
-
token:
|
|
2997
|
+
token: 133,
|
|
3003
2998
|
build(tokenIndex, sourceSpan, context) {
|
|
3004
2999
|
const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(2, -1);
|
|
3005
3000
|
return {
|
|
3006
3001
|
type: "footnoteReference",
|
|
3007
|
-
identifier: normalizeAssociationLabel(label)
|
|
3002
|
+
identifier: normalizeAssociationLabel(label),
|
|
3008
3003
|
label: semanticText(label),
|
|
3009
3004
|
position: sourceSpan
|
|
3010
3005
|
};
|
|
@@ -3016,12 +3011,13 @@ const feature$9 = {
|
|
|
3016
3011
|
const scanFormatting = (source, start, tokens) => {
|
|
3017
3012
|
const code = source.charCodeAt(start);
|
|
3018
3013
|
const end = inlineMarkerRunEnd(source, start);
|
|
3019
|
-
appendInlineToken(tokens, code === 42 ?
|
|
3014
|
+
appendInlineToken(tokens, code === 42 ? 68 : code === 95 ? 69 : 70, start, end);
|
|
3020
3015
|
return end;
|
|
3021
3016
|
};
|
|
3022
3017
|
function createFormattingPair(type, open, close) {
|
|
3023
3018
|
return {
|
|
3024
3019
|
kind: "pair",
|
|
3020
|
+
token: open,
|
|
3025
3021
|
open,
|
|
3026
3022
|
close,
|
|
3027
3023
|
build(openToken, closeToken, sourceSpan, children) {
|
|
@@ -3033,11 +3029,11 @@ function createFormattingPair(type, open, close) {
|
|
|
3033
3029
|
}
|
|
3034
3030
|
};
|
|
3035
3031
|
}
|
|
3036
|
-
const emphasisPair = createFormattingPair("emphasis",
|
|
3037
|
-
const strongPair = createFormattingPair("strong",
|
|
3038
|
-
const deletePair = createFormattingPair("delete",
|
|
3032
|
+
const emphasisPair = createFormattingPair("emphasis", 192, 193);
|
|
3033
|
+
const strongPair = createFormattingPair("strong", 194, 195);
|
|
3034
|
+
const deletePair = createFormattingPair("delete", 196, 197);
|
|
3039
3035
|
const asteriskDelimiter = {
|
|
3040
|
-
token:
|
|
3036
|
+
token: 68,
|
|
3041
3037
|
single: emphasisPair,
|
|
3042
3038
|
double: strongPair,
|
|
3043
3039
|
pairing: {
|
|
@@ -3046,7 +3042,7 @@ const asteriskDelimiter = {
|
|
|
3046
3042
|
}
|
|
3047
3043
|
};
|
|
3048
3044
|
const underscoreDelimiter = {
|
|
3049
|
-
token:
|
|
3045
|
+
token: 69,
|
|
3050
3046
|
single: emphasisPair,
|
|
3051
3047
|
double: strongPair,
|
|
3052
3048
|
pairing: {
|
|
@@ -3056,20 +3052,20 @@ const underscoreDelimiter = {
|
|
|
3056
3052
|
allowIntraword: false
|
|
3057
3053
|
};
|
|
3058
3054
|
const strikethroughDelimiter = {
|
|
3059
|
-
token:
|
|
3055
|
+
token: 70,
|
|
3060
3056
|
double: deletePair,
|
|
3061
3057
|
pairing: { kind: "whole" }
|
|
3062
3058
|
};
|
|
3063
3059
|
function feature$8(strikethroughOptions) {
|
|
3064
3060
|
const builds = [
|
|
3065
3061
|
{
|
|
3066
|
-
kind: "
|
|
3067
|
-
token:
|
|
3062
|
+
kind: "text",
|
|
3063
|
+
token: 68,
|
|
3068
3064
|
build: buildInlineText
|
|
3069
3065
|
},
|
|
3070
3066
|
{
|
|
3071
|
-
kind: "
|
|
3072
|
-
token:
|
|
3067
|
+
kind: "text",
|
|
3068
|
+
token: 69,
|
|
3073
3069
|
build: buildInlineText
|
|
3074
3070
|
},
|
|
3075
3071
|
emphasisPair,
|
|
@@ -3085,8 +3081,8 @@ function feature$8(strikethroughOptions) {
|
|
|
3085
3081
|
}];
|
|
3086
3082
|
if (strikethroughOptions) {
|
|
3087
3083
|
builds.push({
|
|
3088
|
-
kind: "
|
|
3089
|
-
token:
|
|
3084
|
+
kind: "text",
|
|
3085
|
+
token: 70,
|
|
3090
3086
|
build: buildInlineText
|
|
3091
3087
|
}, deletePair);
|
|
3092
3088
|
delimiters.push(typeof strikethroughOptions !== "object" || strikethroughOptions.singleTilde !== false ? {
|
|
@@ -3105,6 +3101,23 @@ function feature$8(strikethroughOptions) {
|
|
|
3105
3101
|
} };
|
|
3106
3102
|
}
|
|
3107
3103
|
//#endregion
|
|
3104
|
+
//#region src/fragment/node.ts
|
|
3105
|
+
function cloneLocation(location) {
|
|
3106
|
+
return {
|
|
3107
|
+
line: location.line,
|
|
3108
|
+
column: location.column,
|
|
3109
|
+
offset: location.offset
|
|
3110
|
+
};
|
|
3111
|
+
}
|
|
3112
|
+
function firstChildStart(children) {
|
|
3113
|
+
const first = children[0];
|
|
3114
|
+
return cloneLocation(first.position.start);
|
|
3115
|
+
}
|
|
3116
|
+
function lastChildEnd(children) {
|
|
3117
|
+
const last = children.at(-1);
|
|
3118
|
+
return last ? cloneLocation(last.position.end) : void 0;
|
|
3119
|
+
}
|
|
3120
|
+
//#endregion
|
|
3108
3121
|
//#region src/profile/features/heading.ts
|
|
3109
3122
|
function atxAt(source, lines, index, markerOffset) {
|
|
3110
3123
|
let markerEnd = markerOffset + 1;
|
|
@@ -3142,42 +3155,47 @@ const feature$7 = { block: {
|
|
|
3142
3155
|
rule: 2,
|
|
3143
3156
|
syntax: {
|
|
3144
3157
|
kind: "block",
|
|
3145
|
-
|
|
3146
|
-
close: 8
|
|
3158
|
+
token: 65
|
|
3147
3159
|
},
|
|
3148
3160
|
inlineContent: true,
|
|
3149
|
-
build(tokenStart, context
|
|
3161
|
+
build(tokenStart, context) {
|
|
3150
3162
|
const tokens = context.structure.tokens;
|
|
3151
|
-
|
|
3163
|
+
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
3164
|
+
const inline = buildInlineFragment(tokenStart, 2, context);
|
|
3165
|
+
const result = {
|
|
3152
3166
|
type: "heading",
|
|
3153
3167
|
depth: tokens.end(tokenStart) - tokens.start(tokenStart),
|
|
3154
3168
|
children: inline.children,
|
|
3155
3169
|
position: {
|
|
3156
|
-
start
|
|
3157
|
-
end: blockEnd(tokenStart, context)
|
|
3170
|
+
start,
|
|
3171
|
+
end: context.locator.locationAt(blockEnd(tokenStart, context))
|
|
3158
3172
|
}
|
|
3159
3173
|
};
|
|
3174
|
+
if (inline.attributes) result.attributes = inline.attributes;
|
|
3175
|
+
return result;
|
|
3160
3176
|
}
|
|
3161
3177
|
}, {
|
|
3162
3178
|
rule: 3,
|
|
3163
3179
|
syntax: {
|
|
3164
3180
|
kind: "block",
|
|
3165
|
-
|
|
3166
|
-
close: 8
|
|
3181
|
+
token: [66, 67]
|
|
3167
3182
|
},
|
|
3168
3183
|
inlineContent: true,
|
|
3169
|
-
build(tokenStart, context
|
|
3184
|
+
build(tokenStart, context) {
|
|
3170
3185
|
const tokens = context.structure.tokens;
|
|
3186
|
+
const inline = buildInlineFragment(tokenStart, 3, context);
|
|
3171
3187
|
const children = inline.children;
|
|
3172
|
-
|
|
3188
|
+
const result = {
|
|
3173
3189
|
type: "heading",
|
|
3174
|
-
depth: tokens.kind(tokenStart) ===
|
|
3190
|
+
depth: tokens.kind(tokenStart) === 66 ? 1 : 2,
|
|
3175
3191
|
children,
|
|
3176
3192
|
position: {
|
|
3177
3193
|
start: firstChildStart(children),
|
|
3178
|
-
end: tokens.start(tokenStart + tokens.nodeLength(tokenStart) - 1)
|
|
3194
|
+
end: context.locator.locationAt(tokens.start(tokenStart + tokens.nodeLength(tokenStart) - 1))
|
|
3179
3195
|
}
|
|
3180
3196
|
};
|
|
3197
|
+
if (inline.attributes) result.attributes = inline.attributes;
|
|
3198
|
+
return result;
|
|
3181
3199
|
}
|
|
3182
3200
|
}],
|
|
3183
3201
|
starts: [{
|
|
@@ -3188,80 +3206,17 @@ const feature$7 = { block: {
|
|
|
3188
3206
|
start(source, lines, start, contentOffset, out) {
|
|
3189
3207
|
const atx = atxAt(source, lines, start, contentOffset);
|
|
3190
3208
|
if (!atx) return;
|
|
3191
|
-
out.push(
|
|
3209
|
+
out.push(65, contentOffset, atx.markerEnd);
|
|
3192
3210
|
if (atx.contentEnd > atx.contentOffset) out.push(1, atx.contentOffset, atx.contentEnd);
|
|
3193
3211
|
const lineEnd = lines.end(start);
|
|
3194
|
-
out.push(
|
|
3212
|
+
out.push(193, lineEnd, lineEnd);
|
|
3195
3213
|
return start + 1;
|
|
3196
3214
|
}
|
|
3197
3215
|
}]
|
|
3198
3216
|
} };
|
|
3199
3217
|
//#endregion
|
|
3200
3218
|
//#region src/profile/features/html.ts
|
|
3201
|
-
const htmlBlockTags = new Set(
|
|
3202
|
-
"address",
|
|
3203
|
-
"article",
|
|
3204
|
-
"aside",
|
|
3205
|
-
"base",
|
|
3206
|
-
"basefont",
|
|
3207
|
-
"blockquote",
|
|
3208
|
-
"body",
|
|
3209
|
-
"caption",
|
|
3210
|
-
"center",
|
|
3211
|
-
"col",
|
|
3212
|
-
"colgroup",
|
|
3213
|
-
"dd",
|
|
3214
|
-
"details",
|
|
3215
|
-
"dialog",
|
|
3216
|
-
"dir",
|
|
3217
|
-
"div",
|
|
3218
|
-
"dl",
|
|
3219
|
-
"dt",
|
|
3220
|
-
"fieldset",
|
|
3221
|
-
"figcaption",
|
|
3222
|
-
"figure",
|
|
3223
|
-
"footer",
|
|
3224
|
-
"form",
|
|
3225
|
-
"frame",
|
|
3226
|
-
"frameset",
|
|
3227
|
-
"h1",
|
|
3228
|
-
"h2",
|
|
3229
|
-
"h3",
|
|
3230
|
-
"h4",
|
|
3231
|
-
"h5",
|
|
3232
|
-
"h6",
|
|
3233
|
-
"head",
|
|
3234
|
-
"header",
|
|
3235
|
-
"hr",
|
|
3236
|
-
"html",
|
|
3237
|
-
"iframe",
|
|
3238
|
-
"legend",
|
|
3239
|
-
"li",
|
|
3240
|
-
"link",
|
|
3241
|
-
"main",
|
|
3242
|
-
"menu",
|
|
3243
|
-
"menuitem",
|
|
3244
|
-
"nav",
|
|
3245
|
-
"noframes",
|
|
3246
|
-
"ol",
|
|
3247
|
-
"optgroup",
|
|
3248
|
-
"option",
|
|
3249
|
-
"p",
|
|
3250
|
-
"param",
|
|
3251
|
-
"search",
|
|
3252
|
-
"section",
|
|
3253
|
-
"summary",
|
|
3254
|
-
"table",
|
|
3255
|
-
"tbody",
|
|
3256
|
-
"td",
|
|
3257
|
-
"tfoot",
|
|
3258
|
-
"th",
|
|
3259
|
-
"thead",
|
|
3260
|
-
"title",
|
|
3261
|
-
"tr",
|
|
3262
|
-
"track",
|
|
3263
|
-
"ul"
|
|
3264
|
-
]);
|
|
3219
|
+
const htmlBlockTags = new Set(htmlBlockNames);
|
|
3265
3220
|
const htmlTagName = "[a-z][a-z0-9-]*";
|
|
3266
3221
|
const completeHtmlTag = new RegExp(`^(?:<${htmlTagName}(?:\\s+[a-z_:][\\w.:-]*(?:\\s*=\\s*(?:[^\\s"'=<>\`]+|'[^']*'|"[^"]*"))?)*\\s*/?>|</${htmlTagName}\\s*>)[ \\t]*$`, "i");
|
|
3267
3222
|
const htmlComment = /<!-->|<!--->|<!--[\s\S]*?(?:-->|$)/y;
|
|
@@ -3270,12 +3225,7 @@ const inlineHtml = /<[A-Za-z][A-Za-z0-9-]*(?:[ \t\n\r]+[A-Za-z_:][\w.:-]*(?:[ \t
|
|
|
3270
3225
|
function htmlStartAt(source, lines, index, contentOffset) {
|
|
3271
3226
|
const body = source.slice(contentOffset, lines.end(index));
|
|
3272
3227
|
const lower = body.toLowerCase();
|
|
3273
|
-
for (const tag of [
|
|
3274
|
-
"script",
|
|
3275
|
-
"pre",
|
|
3276
|
-
"style",
|
|
3277
|
-
"textarea"
|
|
3278
|
-
]) if (lower.startsWith(`<${tag}`) && (lower.length === tag.length + 1 || /[ \t>]/.test(lower[tag.length + 1]))) return {
|
|
3228
|
+
for (const tag of htmlRawNames) if (lower.startsWith(`<${tag}`) && (lower.length === tag.length + 1 || /[ \t>]/.test(lower[tag.length + 1]))) return {
|
|
3279
3229
|
interruptParagraph: true,
|
|
3280
3230
|
terminator: `</${tag}>`
|
|
3281
3231
|
};
|
|
@@ -3299,11 +3249,6 @@ function htmlStartAt(source, lines, index, contentOffset) {
|
|
|
3299
3249
|
if (tag && htmlBlockTags.has(tag)) return { interruptParagraph: true };
|
|
3300
3250
|
if (completeHtmlTag.test(body)) return { interruptParagraph: false };
|
|
3301
3251
|
}
|
|
3302
|
-
function htmlBlockUnterminated(token, context) {
|
|
3303
|
-
const result = context.structure.tokens.value(token);
|
|
3304
|
-
if (context.structure.tokens.kind(token) !== 21 || result === void 0) throw new Error("HTML block lacks termination state");
|
|
3305
|
-
return result;
|
|
3306
|
-
}
|
|
3307
3252
|
const buildInlineHtml = (tokenIndex, sourceSpan, context) => {
|
|
3308
3253
|
return {
|
|
3309
3254
|
type: "html",
|
|
@@ -3317,21 +3262,20 @@ const feature$6 = {
|
|
|
3317
3262
|
rule: 10,
|
|
3318
3263
|
syntax: {
|
|
3319
3264
|
kind: "leaf",
|
|
3320
|
-
token:
|
|
3265
|
+
token: 259
|
|
3321
3266
|
},
|
|
3322
3267
|
build(tokenStart, context) {
|
|
3323
|
-
const
|
|
3324
|
-
const
|
|
3325
|
-
const
|
|
3326
|
-
|
|
3268
|
+
const tokens = context.structure.tokens;
|
|
3269
|
+
const offset = tokens.start(tokenStart);
|
|
3270
|
+
const end = tokens.end(tokenStart);
|
|
3271
|
+
const unterminated = tokens.value(tokenStart);
|
|
3272
|
+
if (tokens.kind(tokenStart) !== 259 || unterminated === void 0) throw new Error("HTML block lacks termination state");
|
|
3273
|
+
let html = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
|
|
3327
3274
|
if (!unterminated && html.endsWith("\n")) html = html.slice(0, -1);
|
|
3328
3275
|
return {
|
|
3329
3276
|
type: "html",
|
|
3330
3277
|
value: html,
|
|
3331
|
-
position:
|
|
3332
|
-
start: offset,
|
|
3333
|
-
end: html.endsWith("\n") ? end : blockEnd(tokenStart, context)
|
|
3334
|
-
}
|
|
3278
|
+
position: context.locator.positionAt(offset, html.endsWith("\n") ? end : blockEnd(tokenStart, context))
|
|
3335
3279
|
};
|
|
3336
3280
|
}
|
|
3337
3281
|
}],
|
|
@@ -3350,7 +3294,7 @@ const feature$6 = {
|
|
|
3350
3294
|
if (end < lines.length) end++;
|
|
3351
3295
|
else unterminated = true;
|
|
3352
3296
|
} else if (!htmlStart.terminator) while (end < lines.length && !isBlank(source, lines, end)) end++;
|
|
3353
|
-
appendLogicalToken(out,
|
|
3297
|
+
appendLogicalToken(out, 259, source, lines, start, end, unterminated);
|
|
3354
3298
|
return end;
|
|
3355
3299
|
}
|
|
3356
3300
|
}]
|
|
@@ -3360,14 +3304,14 @@ const feature$6 = {
|
|
|
3360
3304
|
marker: 60,
|
|
3361
3305
|
scan(source, start, tokens) {
|
|
3362
3306
|
let end = matchInlinePatternEnd(htmlComment, source, start);
|
|
3363
|
-
let kind =
|
|
3307
|
+
let kind = 130;
|
|
3364
3308
|
if (end < 0) {
|
|
3365
3309
|
end = matchInlinePatternEnd(autolink, source, start);
|
|
3366
|
-
kind =
|
|
3310
|
+
kind = 132;
|
|
3367
3311
|
}
|
|
3368
3312
|
if (end < 0) {
|
|
3369
3313
|
end = matchInlinePatternEnd(inlineHtml, source, start);
|
|
3370
|
-
kind =
|
|
3314
|
+
kind = 131;
|
|
3371
3315
|
}
|
|
3372
3316
|
if (end < 0) return start + 1;
|
|
3373
3317
|
appendInlineToken(tokens, kind, start, end);
|
|
@@ -3376,11 +3320,11 @@ const feature$6 = {
|
|
|
3376
3320
|
}],
|
|
3377
3321
|
build: [{
|
|
3378
3322
|
kind: "leaf",
|
|
3379
|
-
token:
|
|
3323
|
+
token: 131,
|
|
3380
3324
|
build: buildInlineHtml
|
|
3381
3325
|
}, {
|
|
3382
3326
|
kind: "leaf",
|
|
3383
|
-
token:
|
|
3327
|
+
token: 130,
|
|
3384
3328
|
build: buildInlineHtml
|
|
3385
3329
|
}]
|
|
3386
3330
|
}
|
|
@@ -3451,7 +3395,14 @@ function linkTitleEnd(source, start) {
|
|
|
3451
3395
|
}
|
|
3452
3396
|
return -1;
|
|
3453
3397
|
}
|
|
3398
|
+
const simpleLinkTail = /\([^<\\()\t\n\r ]+\)/y;
|
|
3454
3399
|
function scanLinkTail(source, start, tokens) {
|
|
3400
|
+
simpleLinkTail.lastIndex = start + 1;
|
|
3401
|
+
if (simpleLinkTail.test(source)) {
|
|
3402
|
+
const end = simpleLinkTail.lastIndex;
|
|
3403
|
+
appendInlineToken(tokens, 73, start, end, end - start - 1);
|
|
3404
|
+
return end;
|
|
3405
|
+
}
|
|
3455
3406
|
if (source.charCodeAt(start + 1) !== 40) return -1;
|
|
3456
3407
|
let offset = skipWhitespace(source, start + 2);
|
|
3457
3408
|
let destinationEnd = offset;
|
|
@@ -3463,13 +3414,12 @@ function scanLinkTail(source, start, tokens) {
|
|
|
3463
3414
|
if (whitespaceEnd > offset && source.charCodeAt(whitespaceEnd) !== 41) {
|
|
3464
3415
|
const titleEnd = linkTitleEnd(source, whitespaceEnd);
|
|
3465
3416
|
if (titleEnd < 0) return -1;
|
|
3466
|
-
offset = titleEnd;
|
|
3417
|
+
offset = skipWhitespace(source, titleEnd);
|
|
3467
3418
|
} else offset = whitespaceEnd;
|
|
3468
|
-
offset = skipWhitespace(source, offset);
|
|
3469
3419
|
if (source.charCodeAt(offset) !== 41) return -1;
|
|
3470
3420
|
}
|
|
3471
3421
|
const end = offset + 1;
|
|
3472
|
-
appendInlineToken(tokens,
|
|
3422
|
+
appendInlineToken(tokens, 73, start, end, destinationEnd - start);
|
|
3473
3423
|
return end;
|
|
3474
3424
|
}
|
|
3475
3425
|
function isLinkWhitespace(code) {
|
|
@@ -3507,7 +3457,7 @@ function reference(close, syntaxStart, syntaxEnd, context, image) {
|
|
|
3507
3457
|
const full = closeText.startsWith("][") && closeText !== "][]";
|
|
3508
3458
|
const labelSource = full ? closeText.slice(2, -1) : content;
|
|
3509
3459
|
return {
|
|
3510
|
-
identifier: normalizeAssociationLabel(labelSource)
|
|
3460
|
+
identifier: normalizeAssociationLabel(labelSource),
|
|
3511
3461
|
label: semanticText(labelSource),
|
|
3512
3462
|
referenceType: full ? "full" : closeText === "][]" ? "collapsed" : "shortcut"
|
|
3513
3463
|
};
|
|
@@ -3563,7 +3513,7 @@ const feature$5 = { inline: {
|
|
|
3563
3513
|
scan(source, start, tokens) {
|
|
3564
3514
|
if (source.charCodeAt(start + 1) !== 91) return start + 1;
|
|
3565
3515
|
const end = start + 2;
|
|
3566
|
-
appendInlineToken(tokens,
|
|
3516
|
+
appendInlineToken(tokens, 71, start, end);
|
|
3567
3517
|
return end;
|
|
3568
3518
|
}
|
|
3569
3519
|
},
|
|
@@ -3571,7 +3521,7 @@ const feature$5 = { inline: {
|
|
|
3571
3521
|
marker: 91,
|
|
3572
3522
|
scan(source, start, tokens) {
|
|
3573
3523
|
const end = start + 1;
|
|
3574
|
-
appendInlineToken(tokens,
|
|
3524
|
+
appendInlineToken(tokens, 72, start, end);
|
|
3575
3525
|
return end;
|
|
3576
3526
|
}
|
|
3577
3527
|
},
|
|
@@ -3580,7 +3530,7 @@ const feature$5 = { inline: {
|
|
|
3580
3530
|
scan(source, start, tokens) {
|
|
3581
3531
|
const end = scanLinkTail(source, start, tokens);
|
|
3582
3532
|
if (end >= 0) return end;
|
|
3583
|
-
appendInlineToken(tokens,
|
|
3533
|
+
appendInlineToken(tokens, 74, start, start + 1);
|
|
3584
3534
|
return start + 1;
|
|
3585
3535
|
}
|
|
3586
3536
|
}
|
|
@@ -3588,31 +3538,27 @@ const feature$5 = { inline: {
|
|
|
3588
3538
|
build: [
|
|
3589
3539
|
{
|
|
3590
3540
|
kind: "pair",
|
|
3591
|
-
|
|
3592
|
-
close: 24,
|
|
3541
|
+
token: 198,
|
|
3593
3542
|
build: buildInlineLink
|
|
3594
3543
|
},
|
|
3595
3544
|
{
|
|
3596
3545
|
kind: "pair",
|
|
3597
|
-
|
|
3598
|
-
close: 26,
|
|
3546
|
+
token: 200,
|
|
3599
3547
|
build: buildInlineImage
|
|
3600
3548
|
},
|
|
3601
3549
|
{
|
|
3602
3550
|
kind: "pair",
|
|
3603
|
-
|
|
3604
|
-
close: 28,
|
|
3551
|
+
token: 202,
|
|
3605
3552
|
build: buildInlineReferenceLink
|
|
3606
3553
|
},
|
|
3607
3554
|
{
|
|
3608
3555
|
kind: "pair",
|
|
3609
|
-
|
|
3610
|
-
close: 30,
|
|
3556
|
+
token: 204,
|
|
3611
3557
|
build: buildInlineReferenceImage
|
|
3612
3558
|
},
|
|
3613
3559
|
{
|
|
3614
3560
|
kind: "leaf",
|
|
3615
|
-
token:
|
|
3561
|
+
token: 132,
|
|
3616
3562
|
build(tokenIndex, sourceSpan, context) {
|
|
3617
3563
|
const label = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(1, -1);
|
|
3618
3564
|
return {
|
|
@@ -3623,8 +3569,16 @@ const feature$5 = { inline: {
|
|
|
3623
3569
|
type: "text",
|
|
3624
3570
|
value: label,
|
|
3625
3571
|
position: {
|
|
3626
|
-
start:
|
|
3627
|
-
|
|
3572
|
+
start: {
|
|
3573
|
+
line: sourceSpan.start.line,
|
|
3574
|
+
column: sourceSpan.start.column + 1,
|
|
3575
|
+
offset: sourceSpan.start.offset + 1
|
|
3576
|
+
},
|
|
3577
|
+
end: {
|
|
3578
|
+
line: sourceSpan.end.line,
|
|
3579
|
+
column: sourceSpan.end.column - 1,
|
|
3580
|
+
offset: sourceSpan.end.offset - 1
|
|
3581
|
+
}
|
|
3628
3582
|
}
|
|
3629
3583
|
}],
|
|
3630
3584
|
position: sourceSpan
|
|
@@ -3632,23 +3586,23 @@ const feature$5 = { inline: {
|
|
|
3632
3586
|
}
|
|
3633
3587
|
},
|
|
3634
3588
|
{
|
|
3635
|
-
kind: "
|
|
3636
|
-
token:
|
|
3589
|
+
kind: "text",
|
|
3590
|
+
token: 72,
|
|
3637
3591
|
build: buildInlineText
|
|
3638
3592
|
},
|
|
3639
3593
|
{
|
|
3640
|
-
kind: "
|
|
3641
|
-
token:
|
|
3594
|
+
kind: "text",
|
|
3595
|
+
token: 71,
|
|
3642
3596
|
build: buildInlineText
|
|
3643
3597
|
},
|
|
3644
3598
|
{
|
|
3645
|
-
kind: "
|
|
3646
|
-
token:
|
|
3599
|
+
kind: "text",
|
|
3600
|
+
token: 73,
|
|
3647
3601
|
build: buildDecodedInlineText
|
|
3648
3602
|
},
|
|
3649
3603
|
{
|
|
3650
|
-
kind: "
|
|
3651
|
-
token:
|
|
3604
|
+
kind: "text",
|
|
3605
|
+
token: 74,
|
|
3652
3606
|
build: buildInlineText
|
|
3653
3607
|
}
|
|
3654
3608
|
]
|
|
@@ -3660,48 +3614,57 @@ function listMarkerPadding(source, lines, index, markerEnd, markerColumn) {
|
|
|
3660
3614
|
if (markerEnd === lineEnd) return {
|
|
3661
3615
|
offset: markerEnd,
|
|
3662
3616
|
columns: 1,
|
|
3617
|
+
hasContent: false,
|
|
3663
3618
|
prefixColumns: 0
|
|
3664
3619
|
};
|
|
3665
3620
|
let offset = markerEnd;
|
|
3666
3621
|
let column = markerColumn;
|
|
3667
|
-
while (offset < lineEnd
|
|
3668
|
-
|
|
3622
|
+
while (offset < lineEnd) {
|
|
3623
|
+
const code = source.charCodeAt(offset);
|
|
3624
|
+
if (code === 32) column++;
|
|
3625
|
+
else if (code === 9) column += 4 - column % 4;
|
|
3626
|
+
else break;
|
|
3669
3627
|
offset++;
|
|
3670
3628
|
}
|
|
3629
|
+
const hasContent = offset < lineEnd;
|
|
3671
3630
|
const whitespaceColumns = column - markerColumn;
|
|
3672
|
-
if (
|
|
3631
|
+
if (hasContent && whitespaceColumns <= 4) return {
|
|
3673
3632
|
offset,
|
|
3674
3633
|
columns: whitespaceColumns,
|
|
3634
|
+
hasContent: true,
|
|
3675
3635
|
prefixColumns: 0
|
|
3676
3636
|
};
|
|
3677
|
-
const
|
|
3637
|
+
const firstPaddingColumns = source.charCodeAt(markerEnd) === 9 ? 4 - markerColumn % 4 : 1;
|
|
3678
3638
|
return {
|
|
3679
3639
|
offset: markerEnd + 1,
|
|
3680
3640
|
columns: 1,
|
|
3681
|
-
|
|
3641
|
+
hasContent,
|
|
3642
|
+
prefixColumns: firstPaddingColumns - 1
|
|
3682
3643
|
};
|
|
3683
3644
|
}
|
|
3684
|
-
function listMarkerAt(source, lines, index, contentOffset
|
|
3645
|
+
function listMarkerAt(source, lines, index, contentOffset) {
|
|
3685
3646
|
if (contentOffset < 0) return;
|
|
3686
3647
|
const indent = lines.prefixColumns(index) + contentOffset - lines.start(index);
|
|
3687
|
-
const marker = source
|
|
3648
|
+
const marker = source.charCodeAt(contentOffset);
|
|
3688
3649
|
const markerEnd = contentOffset + 1;
|
|
3689
3650
|
const lineEnd = lines.end(index);
|
|
3690
|
-
if (
|
|
3651
|
+
if (marker === 45 || marker === 43 || marker === 42) {
|
|
3652
|
+
const following = source.charCodeAt(markerEnd);
|
|
3653
|
+
if (markerEnd !== lineEnd && following !== 32 && following !== 9 || isThematicBreak(source, lines, index, contentOffset)) return;
|
|
3691
3654
|
const padding = listMarkerPadding(source, lines, index, markerEnd, indent + 1);
|
|
3692
3655
|
return {
|
|
3693
3656
|
kind: "unordered",
|
|
3694
3657
|
indent,
|
|
3695
3658
|
offset: contentOffset,
|
|
3696
3659
|
end: markerEnd,
|
|
3660
|
+
hasContent: padding.hasContent,
|
|
3697
3661
|
contentOffset: padding.offset,
|
|
3698
3662
|
contentIndent: indent + 1 + padding.columns,
|
|
3699
3663
|
contentPrefixColumns: padding.prefixColumns,
|
|
3700
|
-
delimiter: marker
|
|
3664
|
+
delimiter: String.fromCharCode(marker)
|
|
3701
3665
|
};
|
|
3702
3666
|
}
|
|
3703
|
-
|
|
3704
|
-
if (markerCode < 48 || markerCode > 57) return;
|
|
3667
|
+
if (marker < 48 || marker > 57) return;
|
|
3705
3668
|
let startNumber = 0;
|
|
3706
3669
|
let orderedEnd = contentOffset;
|
|
3707
3670
|
while (orderedEnd < lineEnd && orderedEnd - contentOffset < 9) {
|
|
@@ -3711,7 +3674,11 @@ function listMarkerAt(source, lines, index, contentOffset = lineIndentOffset(sou
|
|
|
3711
3674
|
orderedEnd++;
|
|
3712
3675
|
}
|
|
3713
3676
|
const delimiter = source[orderedEnd];
|
|
3714
|
-
if (delimiter !== "." && delimiter !== ")"
|
|
3677
|
+
if (delimiter !== "." && delimiter !== ")") return;
|
|
3678
|
+
if (orderedEnd + 1 < lineEnd) {
|
|
3679
|
+
const code = source.charCodeAt(orderedEnd + 1);
|
|
3680
|
+
if (code !== 32 && code !== 9) return;
|
|
3681
|
+
}
|
|
3715
3682
|
orderedEnd++;
|
|
3716
3683
|
const markerWidth = orderedEnd - contentOffset;
|
|
3717
3684
|
const padding = listMarkerPadding(source, lines, index, orderedEnd, indent + markerWidth);
|
|
@@ -3720,6 +3687,7 @@ function listMarkerAt(source, lines, index, contentOffset = lineIndentOffset(sou
|
|
|
3720
3687
|
indent,
|
|
3721
3688
|
offset: contentOffset,
|
|
3722
3689
|
end: orderedEnd,
|
|
3690
|
+
hasContent: padding.hasContent,
|
|
3723
3691
|
contentOffset: padding.offset,
|
|
3724
3692
|
contentIndent: indent + markerWidth + padding.columns,
|
|
3725
3693
|
contentPrefixColumns: padding.prefixColumns,
|
|
@@ -3730,9 +3698,6 @@ function listMarkerAt(source, lines, index, contentOffset = lineIndentOffset(sou
|
|
|
3730
3698
|
function sameList(a, b) {
|
|
3731
3699
|
return a.kind === b.kind && a.delimiter === b.delimiter;
|
|
3732
3700
|
}
|
|
3733
|
-
function hasListContent(source, lines, index, marker) {
|
|
3734
|
-
return !!marker && /\S/.test(source.slice(marker.contentOffset, lines.end(index)));
|
|
3735
|
-
}
|
|
3736
3701
|
function isTaskListWhitespace(code) {
|
|
3737
3702
|
return code === 32 || code >= 9 && code <= 13;
|
|
3738
3703
|
}
|
|
@@ -3763,30 +3728,27 @@ function hasTaskListContent(source, tokens, firstChunk, contentStart) {
|
|
|
3763
3728
|
const buildListItem = (tokenStart, context) => {
|
|
3764
3729
|
const tokens = context.structure.tokens;
|
|
3765
3730
|
const markerKind = tokens.kind(tokenStart);
|
|
3731
|
+
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
3766
3732
|
const children = buildBlockChildren(tokenStart, context);
|
|
3767
3733
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
3768
3734
|
return {
|
|
3769
3735
|
type: "listItem",
|
|
3770
3736
|
spread: tokens.value(close) === true,
|
|
3771
|
-
checked: markerKind ===
|
|
3737
|
+
checked: markerKind === 130 ? true : markerKind === 129 ? false : null,
|
|
3772
3738
|
children,
|
|
3773
3739
|
position: {
|
|
3774
|
-
start
|
|
3775
|
-
end: lastChildEnd(children
|
|
3740
|
+
start,
|
|
3741
|
+
end: lastChildEnd(children) ?? context.locator.locationAt(tokens.end(close))
|
|
3776
3742
|
}
|
|
3777
3743
|
};
|
|
3778
3744
|
};
|
|
3779
3745
|
function createBuildList(ordered) {
|
|
3780
3746
|
return (tokenStart, context) => {
|
|
3781
|
-
const
|
|
3782
|
-
const
|
|
3747
|
+
const tokens = context.structure.tokens;
|
|
3748
|
+
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
3783
3749
|
const items = [];
|
|
3784
3750
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
3785
|
-
for (let child = tokenStart + 1; child < close;)
|
|
3786
|
-
const length = tokens.nodeLength(child);
|
|
3787
|
-
if (length > 0 && structure.ruleOf(child).rule === 5) items.push(buildListItem(child, context));
|
|
3788
|
-
child += length || 1;
|
|
3789
|
-
}
|
|
3751
|
+
for (let child = tokenStart + 1; child < close; child += tokens.nodeLength(child)) items.push(buildBlockNode(child, context));
|
|
3790
3752
|
return {
|
|
3791
3753
|
type: "list",
|
|
3792
3754
|
ordered,
|
|
@@ -3794,8 +3756,8 @@ function createBuildList(ordered) {
|
|
|
3794
3756
|
spread: tokens.value(close) === true,
|
|
3795
3757
|
children: items,
|
|
3796
3758
|
position: {
|
|
3797
|
-
start
|
|
3798
|
-
end: lastChildEnd(items
|
|
3759
|
+
start,
|
|
3760
|
+
end: lastChildEnd(items) ?? context.locator.locationAt(tokens.end(tokenStart))
|
|
3799
3761
|
}
|
|
3800
3762
|
};
|
|
3801
3763
|
};
|
|
@@ -3805,76 +3767,79 @@ const listStart = (source, lines, start, contentOffset, out, context) => {
|
|
|
3805
3767
|
if (!marker) return;
|
|
3806
3768
|
const listMarker = marker;
|
|
3807
3769
|
const kind = listMarker.kind;
|
|
3808
|
-
const listOpen = kind === "ordered" ?
|
|
3809
|
-
const listClose = kind === "ordered" ?
|
|
3770
|
+
const listOpen = kind === "ordered" ? 70 : 69;
|
|
3771
|
+
const listClose = kind === "ordered" ? 196 : 195;
|
|
3810
3772
|
out.push(listOpen, listMarker.offset, listMarker.end, kind === "ordered" ? { value: listMarker.startNumber } : void 0);
|
|
3811
3773
|
let index = start;
|
|
3812
3774
|
let listEnd = listMarker.end;
|
|
3813
3775
|
let listSpread = false;
|
|
3814
3776
|
let trailingBlank = false;
|
|
3815
3777
|
while (marker && sameList(marker, listMarker)) {
|
|
3778
|
+
let sibling;
|
|
3816
3779
|
listSpread ||= trailingBlank;
|
|
3817
3780
|
trailingBlank = false;
|
|
3818
|
-
out.push(
|
|
3781
|
+
out.push(128, marker.offset, marker.end);
|
|
3819
3782
|
const itemLines = new BlockLines();
|
|
3820
3783
|
itemLines.pushFrom(lines, index, marker.contentOffset, marker.contentPrefixColumns);
|
|
3821
|
-
let hasContent =
|
|
3822
|
-
let
|
|
3784
|
+
let hasContent = marker.hasContent;
|
|
3785
|
+
let paragraphLeaf = hasContent ? 2 : 0;
|
|
3823
3786
|
index++;
|
|
3824
3787
|
while (index < lines.length) {
|
|
3825
|
-
const
|
|
3826
|
-
if (
|
|
3827
|
-
if (isBlank(source, lines, index)) {
|
|
3788
|
+
const line = itemLines.pushAfterColumns(source, lines, index, marker.contentIndent);
|
|
3789
|
+
if (line === 0) {
|
|
3828
3790
|
if (!hasContent) {
|
|
3829
3791
|
trailingBlank = true;
|
|
3830
3792
|
index++;
|
|
3793
|
+
sibling = index < lines.length ? listMarkerAt(source, lines, index, lineIndentOffset(source, lines, index)) : void 0;
|
|
3831
3794
|
break;
|
|
3832
3795
|
}
|
|
3833
3796
|
itemLines.pushFrom(lines, index);
|
|
3834
3797
|
trailingBlank = true;
|
|
3835
|
-
|
|
3798
|
+
paragraphLeaf = 0;
|
|
3836
3799
|
index++;
|
|
3837
3800
|
continue;
|
|
3838
3801
|
}
|
|
3839
|
-
|
|
3840
|
-
if (content) {
|
|
3841
|
-
itemLines.pushFrom(lines, index, content.offset, content.prefixColumns);
|
|
3802
|
+
if (line === 1) {
|
|
3842
3803
|
trailingBlank = false;
|
|
3843
3804
|
hasContent = true;
|
|
3844
|
-
|
|
3805
|
+
paragraphLeaf = 2;
|
|
3845
3806
|
index++;
|
|
3846
3807
|
continue;
|
|
3847
3808
|
}
|
|
3848
|
-
|
|
3809
|
+
const candidate = listMarkerAt(source, lines, index, lineIndentOffset(source, lines, index));
|
|
3810
|
+
if (candidate) {
|
|
3811
|
+
sibling = candidate;
|
|
3812
|
+
break;
|
|
3813
|
+
}
|
|
3814
|
+
if (paragraphLeaf === 2) paragraphLeaf = context.endsWithParagraphLeaf(source, itemLines, itemLines.length - 1) ? 1 : 0;
|
|
3815
|
+
if (paragraphLeaf === 0 || context.startsInterruptingBlock(source, lines, index)) break;
|
|
3849
3816
|
itemLines.pushLazy(lines, index);
|
|
3850
|
-
trailingBlank = false;
|
|
3851
3817
|
index++;
|
|
3852
3818
|
}
|
|
3853
3819
|
const itemSpread = context.scanLines(source, itemLines, out);
|
|
3854
3820
|
listEnd = itemLines.next(itemLines.length - 1);
|
|
3855
|
-
out.push(
|
|
3856
|
-
marker =
|
|
3821
|
+
out.push(197, listEnd, listEnd, itemSpread ? { value: true } : void 0);
|
|
3822
|
+
marker = sibling;
|
|
3857
3823
|
}
|
|
3858
3824
|
out.push(listClose, listEnd, listEnd, listSpread ? { value: true } : void 0);
|
|
3859
3825
|
return index;
|
|
3860
3826
|
};
|
|
3861
3827
|
const taskListStart = (source, lines, start, contentOffset, out, context) => {
|
|
3862
|
-
const
|
|
3828
|
+
const listToken = out.length;
|
|
3863
3829
|
const nextLine = listStart(source, lines, start, contentOffset, out, context);
|
|
3864
3830
|
if (nextLine === void 0) return;
|
|
3865
|
-
for (let item =
|
|
3866
|
-
if (out.kind(item) !== 15) continue;
|
|
3831
|
+
for (let item = listToken + 1; item < out.length - 1; item += out.nodeLength(item)) {
|
|
3867
3832
|
let paragraph = item + 1;
|
|
3868
3833
|
let contentKind = out.kind(paragraph);
|
|
3869
|
-
while (contentKind ===
|
|
3834
|
+
while (contentKind === 71 || contentKind === 2 || contentKind === 198) {
|
|
3870
3835
|
paragraph++;
|
|
3871
3836
|
contentKind = out.kind(paragraph);
|
|
3872
3837
|
}
|
|
3873
|
-
if (contentKind !==
|
|
3838
|
+
if (contentKind !== 68) continue;
|
|
3874
3839
|
const firstChunk = paragraph + 1;
|
|
3875
3840
|
const marker = taskListMarkerAt(source, out.start(firstChunk), out.end(firstChunk));
|
|
3876
3841
|
if (!marker || !hasTaskListContent(source, out, firstChunk, marker.contentStart)) continue;
|
|
3877
|
-
out.setKind(item, marker.checked ?
|
|
3842
|
+
out.setKind(item, marker.checked ? 130 : 129);
|
|
3878
3843
|
out.setStart(firstChunk, marker.contentStart);
|
|
3879
3844
|
}
|
|
3880
3845
|
return nextLine;
|
|
@@ -3886,20 +3851,19 @@ function feature$4(taskList = false) {
|
|
|
3886
3851
|
rule: 5,
|
|
3887
3852
|
syntax: {
|
|
3888
3853
|
kind: "frame",
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
]
|
|
3894
|
-
|
|
3895
|
-
|
|
3854
|
+
token: [
|
|
3855
|
+
128,
|
|
3856
|
+
129,
|
|
3857
|
+
130
|
|
3858
|
+
]
|
|
3859
|
+
},
|
|
3860
|
+
build: buildListItem
|
|
3896
3861
|
},
|
|
3897
3862
|
{
|
|
3898
3863
|
rule: 6,
|
|
3899
3864
|
syntax: {
|
|
3900
3865
|
kind: "block",
|
|
3901
|
-
|
|
3902
|
-
close: 12
|
|
3866
|
+
token: 69
|
|
3903
3867
|
},
|
|
3904
3868
|
build: createBuildList(false)
|
|
3905
3869
|
},
|
|
@@ -3907,8 +3871,7 @@ function feature$4(taskList = false) {
|
|
|
3907
3871
|
rule: 7,
|
|
3908
3872
|
syntax: {
|
|
3909
3873
|
kind: "block",
|
|
3910
|
-
|
|
3911
|
-
close: 14
|
|
3874
|
+
token: 70
|
|
3912
3875
|
},
|
|
3913
3876
|
build: createBuildList(true)
|
|
3914
3877
|
}
|
|
@@ -3937,7 +3900,7 @@ function feature$4(taskList = false) {
|
|
|
3937
3900
|
},
|
|
3938
3901
|
interrupt(source, lines, index, contentOffset) {
|
|
3939
3902
|
const marker = listMarkerAt(source, lines, index, contentOffset);
|
|
3940
|
-
return
|
|
3903
|
+
return marker?.hasContent === true && (marker.kind === "unordered" || marker.kind === "ordered" && marker.startNumber === 1);
|
|
3941
3904
|
},
|
|
3942
3905
|
start: taskList ? taskListStart : listStart
|
|
3943
3906
|
}]
|
|
@@ -3954,22 +3917,18 @@ const blockRules = [{
|
|
|
3954
3917
|
rule: 14,
|
|
3955
3918
|
syntax: {
|
|
3956
3919
|
kind: "leaf",
|
|
3957
|
-
token:
|
|
3920
|
+
token: 261
|
|
3958
3921
|
},
|
|
3959
3922
|
build(tokenStart, context) {
|
|
3960
|
-
const
|
|
3961
|
-
const
|
|
3962
|
-
const value = context.structure.tokens.text(context.source, tokenStart);
|
|
3963
|
-
const block = context.structure.tokens.value(tokenStart);
|
|
3923
|
+
const tokens = context.structure.tokens;
|
|
3924
|
+
const block = tokens.value(tokenStart);
|
|
3964
3925
|
if (!block) throw new Error("Math block lacks fence metadata");
|
|
3926
|
+
const value = block.content ?? tokens.text(context.source, tokenStart);
|
|
3965
3927
|
return {
|
|
3966
3928
|
type: "math",
|
|
3967
3929
|
meta: semanticText(block.info) || null,
|
|
3968
|
-
value:
|
|
3969
|
-
position:
|
|
3970
|
-
start: offset + block.markerOffset,
|
|
3971
|
-
end: block.closed || end < context.structure.tokens.sourceLength ? blockEnd(tokenStart, context) : end
|
|
3972
|
-
}
|
|
3930
|
+
value: sourceColumnFenceContent(value, block),
|
|
3931
|
+
position: fencedBlockPosition(tokenStart, block, context)
|
|
3973
3932
|
};
|
|
3974
3933
|
}
|
|
3975
3934
|
}];
|
|
@@ -3985,7 +3944,7 @@ const blockStarts = [{
|
|
|
3985
3944
|
while (end < lines.length && !closesFence(source, lines, end, fence)) end++;
|
|
3986
3945
|
const closed = end < lines.length;
|
|
3987
3946
|
if (end < lines.length) end++;
|
|
3988
|
-
appendLogicalToken(out,
|
|
3947
|
+
appendLogicalToken(out, 261, source, lines, start, end, fencedBlock(source, lines, start, end, fence, closed));
|
|
3989
3948
|
return end;
|
|
3990
3949
|
}
|
|
3991
3950
|
}];
|
|
@@ -4013,14 +3972,14 @@ function createMathScanRule(singleDollarTextMath) {
|
|
|
4013
3972
|
}
|
|
4014
3973
|
}
|
|
4015
3974
|
if (end < 0) return openEnd;
|
|
4016
|
-
appendInlineToken(tokens,
|
|
3975
|
+
appendInlineToken(tokens, 134, start, end, markerLength);
|
|
4017
3976
|
return end;
|
|
4018
3977
|
}
|
|
4019
3978
|
};
|
|
4020
3979
|
}
|
|
4021
3980
|
const inlineBuilds = [{
|
|
4022
3981
|
kind: "leaf",
|
|
4023
|
-
token:
|
|
3982
|
+
token: 134,
|
|
4024
3983
|
build(tokenIndex, sourceSpan, context) {
|
|
4025
3984
|
const markerLength = inlineTokenData(context.tokens, tokenIndex);
|
|
4026
3985
|
let value = inlineTokenText(context.view.text, context.tokens, tokenIndex).slice(markerLength, -markerLength);
|
|
@@ -4051,61 +4010,56 @@ function feature$3(options) {
|
|
|
4051
4010
|
}
|
|
4052
4011
|
//#endregion
|
|
4053
4012
|
//#region src/profile/features/paragraph.ts
|
|
4054
|
-
function emitInlineChunks(source, lines, start, end, out) {
|
|
4055
|
-
while (start < end) {
|
|
4056
|
-
const line = start++;
|
|
4057
|
-
const offset = indentOffset(source, lines, line);
|
|
4058
|
-
const chunkEnd = start < end ? lines.next(line) : lines.end(line);
|
|
4059
|
-
if (chunkEnd > offset) out.push(1, offset, chunkEnd);
|
|
4060
|
-
}
|
|
4061
|
-
}
|
|
4062
4013
|
const feature$2 = { block: {
|
|
4063
4014
|
fallbacks: [(source, lines, start, contentOffset, out, context) => {
|
|
4015
|
+
const openToken = out.length;
|
|
4016
|
+
const offset = lines.start(start);
|
|
4017
|
+
out.push(68, offset, offset);
|
|
4018
|
+
let chunkOffset = contentOffset;
|
|
4064
4019
|
let index = start + 1;
|
|
4065
4020
|
while (index < lines.length) {
|
|
4066
|
-
|
|
4067
|
-
if (
|
|
4068
|
-
index
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
return index + 1;
|
|
4021
|
+
const lineOffset = lines.lazy(index) ? -1 : lineIndentOffset(source, lines, index);
|
|
4022
|
+
if (lineOffset < 0) {
|
|
4023
|
+
if (isBlank(source, lines, index)) break;
|
|
4024
|
+
} else {
|
|
4025
|
+
const setext = setextMarkerAt(source, lines, index, lineOffset);
|
|
4026
|
+
if (setext) {
|
|
4027
|
+
out.setKind(openToken, setext === "=" ? 66 : 67);
|
|
4028
|
+
out.push(1, chunkOffset, lines.end(index - 1));
|
|
4029
|
+
const lineEnd = lines.end(index);
|
|
4030
|
+
out.push(193, lineEnd, lineEnd);
|
|
4031
|
+
return index + 1;
|
|
4032
|
+
}
|
|
4033
|
+
if (context.startsInterruptingBlock(source, lines, index, lineOffset)) break;
|
|
4080
4034
|
}
|
|
4081
|
-
|
|
4035
|
+
out.push(1, chunkOffset, lines.next(index - 1));
|
|
4036
|
+
chunkOffset = lineOffset < 0 ? indentOffset(source, lines, index) : lineOffset;
|
|
4082
4037
|
index++;
|
|
4083
4038
|
}
|
|
4084
|
-
const offset = lines.start(start);
|
|
4085
|
-
out.push(9, offset, offset);
|
|
4086
|
-
emitInlineChunks(source, lines, start, index, out);
|
|
4087
4039
|
const close = lines.end(index - 1);
|
|
4088
|
-
out.push(
|
|
4040
|
+
out.push(1, chunkOffset, close);
|
|
4041
|
+
out.push(194, close, close);
|
|
4089
4042
|
return index;
|
|
4090
4043
|
}],
|
|
4091
4044
|
rules: [{
|
|
4092
4045
|
rule: 4,
|
|
4093
4046
|
syntax: {
|
|
4094
4047
|
kind: "block",
|
|
4095
|
-
|
|
4096
|
-
close: 10
|
|
4048
|
+
token: 68
|
|
4097
4049
|
},
|
|
4098
4050
|
inlineContent: true,
|
|
4099
|
-
build(tokenStart, context
|
|
4100
|
-
const
|
|
4101
|
-
|
|
4051
|
+
build(tokenStart, context) {
|
|
4052
|
+
const inline = buildInlineFragment(tokenStart, 4, context);
|
|
4053
|
+
const result = {
|
|
4102
4054
|
type: "paragraph",
|
|
4103
|
-
children,
|
|
4055
|
+
children: inline.children,
|
|
4104
4056
|
position: {
|
|
4105
|
-
start: firstChildStart(children),
|
|
4106
|
-
end: blockEnd(tokenStart, context)
|
|
4057
|
+
start: firstChildStart(inline.children),
|
|
4058
|
+
end: context.locator.locationAt(blockEnd(tokenStart, context))
|
|
4107
4059
|
}
|
|
4108
4060
|
};
|
|
4061
|
+
if (inline.attributes) result.attributes = inline.attributes;
|
|
4062
|
+
return result;
|
|
4109
4063
|
}
|
|
4110
4064
|
}]
|
|
4111
4065
|
} };
|
|
@@ -4113,13 +4067,19 @@ const feature$2 = { block: {
|
|
|
4113
4067
|
//#region src/profile/features/reference.ts
|
|
4114
4068
|
function linkDefinitionFields(tokens, token) {
|
|
4115
4069
|
const fields = tokens.value(token);
|
|
4116
|
-
if (tokens.kind(token) !==
|
|
4070
|
+
if (tokens.kind(token) !== 71 || !fields) throw new Error("Expected LinkDefinitionOpen token to contain parsed fields");
|
|
4117
4071
|
return fields;
|
|
4118
4072
|
}
|
|
4119
4073
|
function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
|
|
4074
|
+
let offset = contentOffset + 1;
|
|
4075
|
+
const labelClose = source.indexOf("]", offset);
|
|
4076
|
+
if (labelClose >= 0 && labelClose < lines.end(startIndex) && source.charCodeAt(labelClose + 1) !== 58) {
|
|
4077
|
+
let escapeStart = labelClose;
|
|
4078
|
+
while (escapeStart > offset && source.charCodeAt(escapeStart - 1) === 92) escapeStart--;
|
|
4079
|
+
if ((labelClose - escapeStart & 1) === 0) return;
|
|
4080
|
+
}
|
|
4120
4081
|
let lineIndex = startIndex;
|
|
4121
4082
|
let lookaheadEnd = -1;
|
|
4122
|
-
let offset = contentOffset + 1;
|
|
4123
4083
|
let label = "";
|
|
4124
4084
|
let labelLength = 0;
|
|
4125
4085
|
let labelHasContent = false;
|
|
@@ -4278,8 +4238,7 @@ const feature$1 = { block: {
|
|
|
4278
4238
|
rule: 11,
|
|
4279
4239
|
syntax: {
|
|
4280
4240
|
kind: "block",
|
|
4281
|
-
|
|
4282
|
-
close: 24
|
|
4241
|
+
token: 71
|
|
4283
4242
|
},
|
|
4284
4243
|
build(tokenStart, context) {
|
|
4285
4244
|
const tokens = context.structure.tokens;
|
|
@@ -4288,14 +4247,11 @@ const feature$1 = { block: {
|
|
|
4288
4247
|
if (definitionKey === void 0) throw new Error("Expected LinkDefinitionOpen token to contain a definition key");
|
|
4289
4248
|
return {
|
|
4290
4249
|
type: "definition",
|
|
4291
|
-
identifier: definitionKey
|
|
4250
|
+
identifier: definitionKey,
|
|
4292
4251
|
label: semanticText(fields.label),
|
|
4293
4252
|
url: semanticText(fields.destination),
|
|
4294
4253
|
title: fields.title === void 0 ? null : semanticText(fields.title),
|
|
4295
|
-
position:
|
|
4296
|
-
start: context.structure.tokens.start(tokenStart),
|
|
4297
|
-
end: blockEnd(tokenStart, context)
|
|
4298
|
-
}
|
|
4254
|
+
position: leafBlockPosition(tokenStart, context)
|
|
4299
4255
|
};
|
|
4300
4256
|
}
|
|
4301
4257
|
}],
|
|
@@ -4304,16 +4260,16 @@ const feature$1 = { block: {
|
|
|
4304
4260
|
start(source, lines, start, contentOffset, out, context) {
|
|
4305
4261
|
const definition = linkDefinitionAt(source, lines, start, contentOffset, context);
|
|
4306
4262
|
if (!definition) return;
|
|
4307
|
-
out.push(
|
|
4263
|
+
out.push(71, contentOffset, contentOffset, {
|
|
4308
4264
|
definitionKey: definition.definitionKey,
|
|
4309
4265
|
value: definition.fields
|
|
4310
4266
|
});
|
|
4311
4267
|
let definitionEnd = contentOffset;
|
|
4312
4268
|
for (let definitionLine = start; definitionLine < definition.end; definitionLine++) {
|
|
4313
4269
|
definitionEnd = definitionLine + 1 < definition.end ? lines.next(definitionLine) : lines.end(definitionLine);
|
|
4314
|
-
out.push(
|
|
4270
|
+
out.push(2, lines.start(definitionLine), definitionEnd);
|
|
4315
4271
|
}
|
|
4316
|
-
out.push(
|
|
4272
|
+
out.push(198, definitionEnd, definitionEnd);
|
|
4317
4273
|
return definition.end;
|
|
4318
4274
|
}
|
|
4319
4275
|
}]
|
|
@@ -4321,8 +4277,16 @@ const feature$1 = { block: {
|
|
|
4321
4277
|
//#endregion
|
|
4322
4278
|
//#region src/profile/features/table.ts
|
|
4323
4279
|
function appendTableCell(cells, source, start, contentStart, contentEnd) {
|
|
4324
|
-
while (contentStart < contentEnd
|
|
4325
|
-
|
|
4280
|
+
while (contentStart < contentEnd) {
|
|
4281
|
+
const code = source.charCodeAt(contentStart);
|
|
4282
|
+
if (code !== 32 && code !== 9) break;
|
|
4283
|
+
contentStart++;
|
|
4284
|
+
}
|
|
4285
|
+
while (contentEnd > contentStart) {
|
|
4286
|
+
const code = source.charCodeAt(contentEnd - 1);
|
|
4287
|
+
if (code !== 32 && code !== 9) break;
|
|
4288
|
+
contentEnd--;
|
|
4289
|
+
}
|
|
4326
4290
|
cells.push(start, contentStart, contentEnd);
|
|
4327
4291
|
}
|
|
4328
4292
|
function tableCellsAt(source, lines, index, requirePipe, contentOffset) {
|
|
@@ -4331,17 +4295,21 @@ function tableCellsAt(source, lines, index, requirePipe, contentOffset) {
|
|
|
4331
4295
|
let backslashes = 0;
|
|
4332
4296
|
const lineEnd = lines.end(index);
|
|
4333
4297
|
for (let offset = contentOffset; offset < lineEnd; offset++) {
|
|
4334
|
-
const
|
|
4335
|
-
if (
|
|
4298
|
+
const code = source.charCodeAt(offset);
|
|
4299
|
+
if (code === 92) {
|
|
4336
4300
|
backslashes++;
|
|
4337
4301
|
continue;
|
|
4338
4302
|
}
|
|
4339
|
-
if (
|
|
4303
|
+
if (code === 124 && backslashes % 2 === 0) pipes.push(offset);
|
|
4340
4304
|
backslashes = 0;
|
|
4341
4305
|
}
|
|
4342
4306
|
if (requirePipe && pipes.length === 0) return;
|
|
4343
4307
|
let visibleEnd = lineEnd;
|
|
4344
|
-
while (visibleEnd > contentOffset
|
|
4308
|
+
while (visibleEnd > contentOffset) {
|
|
4309
|
+
const code = source.charCodeAt(visibleEnd - 1);
|
|
4310
|
+
if (code !== 32 && code !== 9) break;
|
|
4311
|
+
visibleEnd--;
|
|
4312
|
+
}
|
|
4345
4313
|
const trailingPipe = pipes.at(-1) === visibleEnd - 1;
|
|
4346
4314
|
const leadingPipe = pipes[0] === contentOffset;
|
|
4347
4315
|
const cells = [];
|
|
@@ -4364,17 +4332,17 @@ function tableCellsAt(source, lines, index, requirePipe, contentOffset) {
|
|
|
4364
4332
|
function alignmentAt(source, cells, cell) {
|
|
4365
4333
|
let start = cells[cell + 1];
|
|
4366
4334
|
let end = cells[cell + 2];
|
|
4367
|
-
const left = source
|
|
4335
|
+
const left = source.charCodeAt(start) === 58;
|
|
4368
4336
|
if (left) start++;
|
|
4369
|
-
const right = source
|
|
4337
|
+
const right = source.charCodeAt(end - 1) === 58;
|
|
4370
4338
|
if (right) end--;
|
|
4371
4339
|
if (start === end) return;
|
|
4372
|
-
for (let offset = start; offset < end; offset++) if (source
|
|
4373
|
-
return left ? right ?
|
|
4340
|
+
for (let offset = start; offset < end; offset++) if (source.charCodeAt(offset) !== 45) return;
|
|
4341
|
+
return left ? right ? 323 : 321 : right ? 322 : 320;
|
|
4374
4342
|
}
|
|
4375
4343
|
function delimiterAt(source, lines, index, contentOffset) {
|
|
4376
|
-
const first = source
|
|
4377
|
-
if (first !==
|
|
4344
|
+
const first = source.charCodeAt(contentOffset);
|
|
4345
|
+
if (first !== 45 && first !== 58 && first !== 124) return;
|
|
4378
4346
|
const cells = tableCellsAt(source, lines, index, false, contentOffset);
|
|
4379
4347
|
if (!cells) return;
|
|
4380
4348
|
for (let cell = 0; cell < cells.length; cell += 3) {
|
|
@@ -4385,37 +4353,39 @@ function delimiterAt(source, lines, index, contentOffset) {
|
|
|
4385
4353
|
return cells;
|
|
4386
4354
|
}
|
|
4387
4355
|
function emitTableRow(lines, index, cells, out) {
|
|
4388
|
-
out.push(
|
|
4356
|
+
out.push(131, cells[0], cells[0]);
|
|
4389
4357
|
for (let cell = 0; cell < cells.length; cell += 3) {
|
|
4390
4358
|
const start = cells[cell];
|
|
4391
|
-
out.push(
|
|
4392
|
-
out.push(1, cells[cell + 1], cells[cell + 2]);
|
|
4359
|
+
out.push(132, start, start);
|
|
4360
|
+
out.push(1, cells[cell + 1], cells[cell + 2], void 0, 192);
|
|
4393
4361
|
}
|
|
4394
4362
|
const lineEnd = lines.end(index);
|
|
4395
|
-
out.push(
|
|
4363
|
+
out.push(201, lineEnd, lineEnd);
|
|
4396
4364
|
}
|
|
4397
|
-
const buildTableCell = (tokenStart, context
|
|
4365
|
+
const buildTableCell = (tokenStart, context) => {
|
|
4398
4366
|
const tokens = context.structure.tokens;
|
|
4367
|
+
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
4399
4368
|
return {
|
|
4400
4369
|
type: "tableCell",
|
|
4401
|
-
children:
|
|
4370
|
+
children: buildInlineFragment(tokenStart, 17, context).children,
|
|
4402
4371
|
position: {
|
|
4403
|
-
start
|
|
4404
|
-
end: tokens.start(tokenStart + tokens.nodeLength(tokenStart))
|
|
4372
|
+
start,
|
|
4373
|
+
end: context.locator.locationAt(tokens.start(tokenStart + tokens.nodeLength(tokenStart)))
|
|
4405
4374
|
}
|
|
4406
4375
|
};
|
|
4407
4376
|
};
|
|
4408
4377
|
const buildTableRow = (tokenStart, context) => {
|
|
4409
4378
|
const tokens = context.structure.tokens;
|
|
4410
4379
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
4380
|
+
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
4411
4381
|
const children = [];
|
|
4412
|
-
for (let cell = tokenStart + 1; cell < close; cell += tokens.nodeLength(cell)) children.push(
|
|
4382
|
+
for (let cell = tokenStart + 1; cell < close; cell += tokens.nodeLength(cell)) children.push(buildBlockNode(cell, context));
|
|
4413
4383
|
return {
|
|
4414
4384
|
type: "tableRow",
|
|
4415
4385
|
children,
|
|
4416
4386
|
position: {
|
|
4417
|
-
start
|
|
4418
|
-
end: tokens.start(close)
|
|
4387
|
+
start,
|
|
4388
|
+
end: context.locator.locationAt(tokens.start(close))
|
|
4419
4389
|
}
|
|
4420
4390
|
};
|
|
4421
4391
|
};
|
|
@@ -4425,7 +4395,7 @@ function tableAlignment(tokenStart, context) {
|
|
|
4425
4395
|
const result = [];
|
|
4426
4396
|
for (let token = tokenStart; token < tokenEnd; token++) {
|
|
4427
4397
|
const kind = tokens.kind(token);
|
|
4428
|
-
result.push(kind ===
|
|
4398
|
+
result.push(kind === 321 ? "left" : kind === 322 ? "right" : kind === 323 ? "center" : null);
|
|
4429
4399
|
}
|
|
4430
4400
|
return result;
|
|
4431
4401
|
}
|
|
@@ -4439,13 +4409,12 @@ const feature = { block: {
|
|
|
4439
4409
|
if (!delimiter) return;
|
|
4440
4410
|
const header = tableCellsAt(source, lines, start, true, contentOffset);
|
|
4441
4411
|
if (header?.length !== delimiter.length) return;
|
|
4442
|
-
out.push(
|
|
4412
|
+
out.push(73, header[0], header[0]);
|
|
4443
4413
|
emitTableRow(lines, start, header, out);
|
|
4444
4414
|
const delimiterEnd = lines.end(delimiterLine);
|
|
4445
4415
|
for (let cell = 0; cell < delimiter.length; cell += 3) out.push(delimiter[cell + 1], delimiter[cell], delimiter[cell + 3] ?? delimiterEnd);
|
|
4446
4416
|
let end = start + 2;
|
|
4447
4417
|
while (end < lines.length) {
|
|
4448
|
-
if (isBlank(source, lines, end)) break;
|
|
4449
4418
|
const contentOffset = lineIndentOffset(source, lines, end);
|
|
4450
4419
|
if (contentOffset < 0 || context.startsInterruptingBlock(source, lines, end, contentOffset)) break;
|
|
4451
4420
|
const cells = tableCellsAt(source, lines, end, false, contentOffset);
|
|
@@ -4454,7 +4423,7 @@ const feature = { block: {
|
|
|
4454
4423
|
end++;
|
|
4455
4424
|
}
|
|
4456
4425
|
const tableEnd = lines.end(end - 1);
|
|
4457
|
-
out.push(
|
|
4426
|
+
out.push(200, tableEnd, tableEnd);
|
|
4458
4427
|
return end;
|
|
4459
4428
|
}],
|
|
4460
4429
|
rules: [
|
|
@@ -4462,28 +4431,28 @@ const feature = { block: {
|
|
|
4462
4431
|
rule: 17,
|
|
4463
4432
|
syntax: {
|
|
4464
4433
|
kind: "frame",
|
|
4465
|
-
|
|
4466
|
-
close: 1
|
|
4434
|
+
token: 132
|
|
4467
4435
|
},
|
|
4468
|
-
inlineContent: true
|
|
4436
|
+
inlineContent: true,
|
|
4437
|
+
build: buildTableCell
|
|
4469
4438
|
},
|
|
4470
4439
|
{
|
|
4471
4440
|
rule: 16,
|
|
4472
4441
|
syntax: {
|
|
4473
4442
|
kind: "frame",
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4443
|
+
token: 131
|
|
4444
|
+
},
|
|
4445
|
+
build: buildTableRow
|
|
4477
4446
|
},
|
|
4478
4447
|
{
|
|
4479
4448
|
rule: 18,
|
|
4480
4449
|
syntax: {
|
|
4481
4450
|
kind: "group",
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4451
|
+
token: [
|
|
4452
|
+
320,
|
|
4453
|
+
321,
|
|
4454
|
+
322,
|
|
4455
|
+
323
|
|
4487
4456
|
]
|
|
4488
4457
|
}
|
|
4489
4458
|
},
|
|
@@ -4491,23 +4460,23 @@ const feature = { block: {
|
|
|
4491
4460
|
rule: 15,
|
|
4492
4461
|
syntax: {
|
|
4493
4462
|
kind: "block",
|
|
4494
|
-
|
|
4495
|
-
close: 30
|
|
4463
|
+
token: 73
|
|
4496
4464
|
},
|
|
4497
4465
|
build(tokenStart, context) {
|
|
4498
4466
|
const tokens = context.structure.tokens;
|
|
4499
4467
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
4468
|
+
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
4500
4469
|
const header = tokenStart + 1;
|
|
4501
4470
|
const delimiter = header + tokens.nodeLength(header);
|
|
4502
|
-
const rows = [
|
|
4503
|
-
for (let row = delimiter + tokens.nodeLength(delimiter); row < close; row += tokens.nodeLength(row)) rows.push(
|
|
4471
|
+
const rows = [buildBlockNode(header, context)];
|
|
4472
|
+
for (let row = delimiter + tokens.nodeLength(delimiter); row < close; row += tokens.nodeLength(row)) rows.push(buildBlockNode(row, context));
|
|
4504
4473
|
return {
|
|
4505
4474
|
type: "table",
|
|
4506
4475
|
align: tableAlignment(delimiter, context),
|
|
4507
4476
|
children: rows,
|
|
4508
4477
|
position: {
|
|
4509
|
-
start
|
|
4510
|
-
end: tokens.start(close)
|
|
4478
|
+
start,
|
|
4479
|
+
end: context.locator.locationAt(tokens.start(close))
|
|
4511
4480
|
}
|
|
4512
4481
|
};
|
|
4513
4482
|
}
|
|
@@ -4665,7 +4634,7 @@ function compileDelimiterConfigs(delimiterConfigs) {
|
|
|
4665
4634
|
return delimiterByKind;
|
|
4666
4635
|
}
|
|
4667
4636
|
//#endregion
|
|
4668
|
-
//#region src/profile/
|
|
4637
|
+
//#region src/profile/resolve.ts
|
|
4669
4638
|
const frameHeaderSize = 1;
|
|
4670
4639
|
const noBracketFrames = Object.freeze([0]);
|
|
4671
4640
|
const delimiterOnlyFrames = Object.freeze([2]);
|
|
@@ -4673,56 +4642,35 @@ const noDelimiterReplacements = [];
|
|
|
4673
4642
|
function frameClaim(frames, frame) {
|
|
4674
4643
|
return frames[frame + 5] & 7;
|
|
4675
4644
|
}
|
|
4676
|
-
function
|
|
4677
|
-
frames[frame + 5] =
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
frames[owner + 3] = candidate;
|
|
4685
|
-
}
|
|
4686
|
-
function promoteCandidates(frames, owner, source) {
|
|
4687
|
-
if (owner < 0) return;
|
|
4688
|
-
const first = frames[source + 2];
|
|
4689
|
-
if (first < 0) return;
|
|
4690
|
-
const last = frames[source + 3];
|
|
4691
|
-
const ownerLast = frames[owner + 3];
|
|
4692
|
-
if (ownerLast >= 0) frames[ownerLast + 4] = first;
|
|
4693
|
-
else frames[owner + 2] = first;
|
|
4694
|
-
frames[owner + 3] = last;
|
|
4695
|
-
}
|
|
4696
|
-
function rewriteLinkCandidates(frames, owner) {
|
|
4697
|
-
let candidate = frames[owner + 2];
|
|
4698
|
-
frames[owner + 2] = -1;
|
|
4699
|
-
frames[owner + 3] = -1;
|
|
4700
|
-
while (candidate >= 0) {
|
|
4701
|
-
const next = frames[candidate + 4];
|
|
4702
|
-
rewriteLinkCandidates(frames, candidate);
|
|
4645
|
+
function setFrameState(frames, frame, state) {
|
|
4646
|
+
frames[frame + 5] = state;
|
|
4647
|
+
frames[0] |= 4;
|
|
4648
|
+
}
|
|
4649
|
+
function rewriteLinkCandidates(frames, candidates, start) {
|
|
4650
|
+
let write = start;
|
|
4651
|
+
for (let read = start; read < candidates.length; read++) {
|
|
4652
|
+
const candidate = candidates[read];
|
|
4703
4653
|
const state = frames[candidate + 5];
|
|
4704
|
-
if ((state & 7) === 3 && !(state & 8))
|
|
4705
|
-
|
|
4706
|
-
promoteCandidates(frames, owner, candidate);
|
|
4707
|
-
} else {
|
|
4654
|
+
if ((state & 7) === 3 && !(state & 8)) frames[candidate + 5] = 0;
|
|
4655
|
+
else {
|
|
4708
4656
|
frames[candidate + 5] = state | 16;
|
|
4709
|
-
|
|
4657
|
+
candidates[write++] = candidate;
|
|
4710
4658
|
}
|
|
4711
|
-
candidate = next;
|
|
4712
4659
|
}
|
|
4660
|
+
candidates.length = write;
|
|
4713
4661
|
}
|
|
4714
|
-
function allocateFrame(frames, openToken, parent) {
|
|
4662
|
+
function allocateFrame(frames, openToken, parent, candidateStart) {
|
|
4715
4663
|
const frame = frames.length;
|
|
4716
|
-
frames.push(openToken, -1,
|
|
4664
|
+
frames.push(openToken, -1, candidateStart, -1, parent, 0, 0);
|
|
4717
4665
|
return frame;
|
|
4718
4666
|
}
|
|
4719
4667
|
function isImageFrame(tokens, frames, frame) {
|
|
4720
|
-
return inlineTokenKind(tokens, frames[frame + 0]) ===
|
|
4668
|
+
return inlineTokenKind(tokens, frames[frame + 0]) === 71;
|
|
4721
4669
|
}
|
|
4722
4670
|
function hasAdjacentComponent(tokens, frames, frame) {
|
|
4723
4671
|
const openToken = frames[frame + 0];
|
|
4724
4672
|
const componentToken = openToken - 1;
|
|
4725
|
-
return componentToken >= 0 && inlineTokenKind(tokens, componentToken) ===
|
|
4673
|
+
return componentToken >= 0 && inlineTokenKind(tokens, componentToken) === 137 && inlineTokenEnd(tokens, componentToken) === inlineTokenStart(tokens, openToken);
|
|
4726
4674
|
}
|
|
4727
4675
|
function referenceLabelEnd(source, start) {
|
|
4728
4676
|
if (source.charCodeAt(start) !== 91) return -1;
|
|
@@ -4760,73 +4708,60 @@ function acceptsShortcutLabel(source, start, end) {
|
|
|
4760
4708
|
}
|
|
4761
4709
|
return hasContent;
|
|
4762
4710
|
}
|
|
4763
|
-
function analyzeBrackets(source, tokens, delimiterByKind,
|
|
4764
|
-
let
|
|
4711
|
+
function analyzeBrackets(source, tokens, delimiterByKind, definitions, options) {
|
|
4712
|
+
let hasDelimiter = false;
|
|
4765
4713
|
let frames;
|
|
4714
|
+
let candidates;
|
|
4766
4715
|
let stackTop = -1;
|
|
4767
4716
|
const count = inlineTokenCount(tokens);
|
|
4768
4717
|
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
4769
4718
|
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
4770
|
-
if (delimiterByKind[kind])
|
|
4771
|
-
if (kind ===
|
|
4772
|
-
|
|
4773
|
-
frames
|
|
4774
|
-
stackTop = allocateFrame(frames, tokenIndex, stackTop);
|
|
4719
|
+
if (delimiterByKind[kind]) hasDelimiter = true;
|
|
4720
|
+
if (kind === 72 || kind === 71) {
|
|
4721
|
+
frames ??= [1];
|
|
4722
|
+
stackTop = allocateFrame(frames, tokenIndex, stackTop, candidates?.length ?? 0);
|
|
4775
4723
|
continue;
|
|
4776
4724
|
}
|
|
4777
|
-
if (kind !==
|
|
4725
|
+
if (kind !== 74 && kind !== 73) continue;
|
|
4778
4726
|
if (stackTop < 0) continue;
|
|
4779
4727
|
const frame = stackTop;
|
|
4780
4728
|
const arena = frames;
|
|
4781
|
-
|
|
4782
|
-
stackTop = parent;
|
|
4729
|
+
stackTop = arena[frame + 4];
|
|
4783
4730
|
arena[frame + 1] = tokenIndex;
|
|
4784
4731
|
const image = isImageFrame(tokens, arena, frame);
|
|
4785
|
-
if (options.footnote && kind ===
|
|
4732
|
+
if (options.footnote && kind === 74) {
|
|
4786
4733
|
const openToken = arena[frame + 0];
|
|
4787
4734
|
const label = footnoteLabelAt(source, inlineTokenStart(tokens, openToken) + (image ? 1 : 0), source.length);
|
|
4788
|
-
if (label && label.end === inlineTokenEnd(tokens, tokenIndex) &&
|
|
4789
|
-
|
|
4735
|
+
if (label && label.end === inlineTokenEnd(tokens, tokenIndex) && definitions.hasDefinition(label.definitionKey)) {
|
|
4736
|
+
setFrameState(arena, frame, 1);
|
|
4737
|
+
if (candidates) candidates.length = arena[frame + 2];
|
|
4790
4738
|
continue;
|
|
4791
4739
|
}
|
|
4792
4740
|
}
|
|
4793
|
-
if (!options.component) continue;
|
|
4794
|
-
if (
|
|
4795
|
-
|
|
4796
|
-
continue;
|
|
4741
|
+
if (!options.component || image) continue;
|
|
4742
|
+
if (kind === 73) {
|
|
4743
|
+
if (candidates) rewriteLinkCandidates(arena, candidates, arena[frame + 2]);
|
|
4797
4744
|
}
|
|
4798
|
-
if (kind === 21) rewriteLinkCandidates(arena, frame);
|
|
4799
4745
|
if (hasAdjacentComponent(tokens, arena, frame)) {
|
|
4800
|
-
|
|
4801
|
-
|
|
4746
|
+
setFrameState(arena, frame, 2);
|
|
4747
|
+
(candidates ??= []).push(frame);
|
|
4802
4748
|
continue;
|
|
4803
4749
|
}
|
|
4804
4750
|
const close = inlineTokenStart(tokens, tokenIndex);
|
|
4805
4751
|
const trailing = source.charCodeAt(close + 1);
|
|
4806
|
-
if (trailing === 40 || trailing === 91)
|
|
4807
|
-
promoteCandidates(arena, parent, frame);
|
|
4808
|
-
continue;
|
|
4809
|
-
}
|
|
4752
|
+
if (trailing === 40 || trailing === 91) continue;
|
|
4810
4753
|
const attributesStart = close + 1;
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
if (parent >= 0) appendCandidate(arena, parent, frame);
|
|
4814
|
-
}
|
|
4815
|
-
if (options.component && stackTop >= 0) {
|
|
4816
|
-
const arena = frames;
|
|
4817
|
-
while (stackTop >= 0) {
|
|
4818
|
-
const frame = stackTop;
|
|
4819
|
-
stackTop = arena[frame + 4];
|
|
4820
|
-
promoteCandidates(arena, stackTop, frame);
|
|
4821
|
-
}
|
|
4754
|
+
setFrameState(arena, frame, 3 | (source.charCodeAt(attributesStart) === 123 && attributesEnd(source, attributesStart) !== void 0 ? 8 : 0));
|
|
4755
|
+
(candidates ??= []).push(frame);
|
|
4822
4756
|
}
|
|
4823
4757
|
if (frames) {
|
|
4824
|
-
frames[0]
|
|
4758
|
+
frames[0] |= hasDelimiter ? 2 : 0;
|
|
4825
4759
|
return frames;
|
|
4826
4760
|
}
|
|
4827
|
-
return
|
|
4761
|
+
return hasDelimiter ? delimiterOnlyFrames : noBracketFrames;
|
|
4828
4762
|
}
|
|
4829
|
-
function resolveReferences(source, tokens, frames,
|
|
4763
|
+
function resolveReferences(source, tokens, frames, definitions) {
|
|
4764
|
+
const hasDefinitions = definitions.hasDefinitions();
|
|
4830
4765
|
let rawTop = -1;
|
|
4831
4766
|
let logicalTop = -1;
|
|
4832
4767
|
let frameCursor = frameHeaderSize;
|
|
@@ -4844,13 +4779,12 @@ function resolveReferences(source, tokens, frames, context) {
|
|
|
4844
4779
|
consumeFrames = false;
|
|
4845
4780
|
}
|
|
4846
4781
|
const consuming = consumedEnd >= 0;
|
|
4847
|
-
if (kind ===
|
|
4782
|
+
if (kind === 72 || kind === 71) {
|
|
4848
4783
|
const frame = frameCursor;
|
|
4849
4784
|
frameCursor += 7;
|
|
4850
|
-
frames[frame + 2] = rawTop;
|
|
4851
4785
|
rawTop = frame;
|
|
4852
4786
|
if (consuming) {
|
|
4853
|
-
if (consumeFrames)
|
|
4787
|
+
if (consumeFrames) setFrameState(frames, frame, 6);
|
|
4854
4788
|
continue;
|
|
4855
4789
|
}
|
|
4856
4790
|
const claim = frameClaim(frames, frame);
|
|
@@ -4863,48 +4797,48 @@ function resolveReferences(source, tokens, frames, context) {
|
|
|
4863
4797
|
if (frames[frame + 5] & 16) literalDepth++;
|
|
4864
4798
|
continue;
|
|
4865
4799
|
}
|
|
4866
|
-
if (literalDepth > 0 && !(kind ===
|
|
4800
|
+
if (literalDepth > 0 && !(kind === 71)) continue;
|
|
4867
4801
|
frames[frame + 3] = logicalTop;
|
|
4868
4802
|
logicalTop = frame;
|
|
4869
4803
|
lastVisibleOpener = tokenIndex;
|
|
4870
4804
|
continue;
|
|
4871
4805
|
}
|
|
4872
|
-
if (kind !==
|
|
4806
|
+
if (kind !== 74 && kind !== 73) continue;
|
|
4873
4807
|
const rawFrame = rawTop;
|
|
4874
|
-
if (rawFrame >= 0) rawTop = frames[rawFrame +
|
|
4808
|
+
if (rawFrame >= 0) rawTop = frames[rawFrame + 4];
|
|
4875
4809
|
if (consuming) {
|
|
4876
|
-
if (consumeFrames && rawFrame >= 0)
|
|
4810
|
+
if (consumeFrames && rawFrame >= 0) setFrameState(frames, rawFrame, 6);
|
|
4877
4811
|
continue;
|
|
4878
4812
|
}
|
|
4879
4813
|
const rawClaim = rawFrame < 0 ? 0 : frameClaim(frames, rawFrame);
|
|
4880
4814
|
if (!(rawClaim === 1 || rawClaim === 2 || rawClaim === 3) && (literalDepth <= 0 || rawFrame < 0 || isImageFrame(tokens, frames, rawFrame))) {
|
|
4881
4815
|
const frame = logicalTop;
|
|
4882
|
-
if (frame >= 0)
|
|
4883
|
-
|
|
4816
|
+
if (frame >= 0) logicalTop = frames[frame + 3];
|
|
4817
|
+
if (frame >= 0 && (kind === 73 || hasDefinitions)) {
|
|
4884
4818
|
const openToken = frames[frame + 0];
|
|
4885
4819
|
const image = isImageFrame(tokens, frames, frame);
|
|
4886
|
-
if (
|
|
4820
|
+
if (image || openToken + 1 >= inactiveBefore) {
|
|
4887
4821
|
const contentStart = inlineTokenEnd(tokens, openToken);
|
|
4888
4822
|
const contentEnd = tokenStart;
|
|
4889
4823
|
let closeEnd = inlineTokenEnd(tokens, tokenIndex);
|
|
4890
4824
|
let reference = false;
|
|
4891
|
-
let matched = kind ===
|
|
4825
|
+
let matched = kind === 73;
|
|
4892
4826
|
if (!matched) {
|
|
4893
4827
|
const labelEnd = referenceLabelEnd(source, closeEnd);
|
|
4894
4828
|
if (labelEnd > 0) {
|
|
4895
4829
|
const label = source.slice(closeEnd + 1, labelEnd - 1) || source.slice(contentStart, contentEnd);
|
|
4896
|
-
matched =
|
|
4830
|
+
matched = definitions.hasDefinition(normalizeAssociationLabel(label));
|
|
4897
4831
|
if (matched) {
|
|
4898
4832
|
closeEnd = labelEnd;
|
|
4899
4833
|
reference = true;
|
|
4900
4834
|
}
|
|
4901
|
-
} else if (lastVisibleOpener <= openToken && acceptsShortcutLabel(source, contentStart, contentEnd) &&
|
|
4835
|
+
} else if (lastVisibleOpener <= openToken && acceptsShortcutLabel(source, contentStart, contentEnd) && definitions.hasDefinition(normalizeAssociationLabel(source.slice(contentStart, contentEnd)))) {
|
|
4902
4836
|
matched = true;
|
|
4903
4837
|
reference = true;
|
|
4904
4838
|
}
|
|
4905
4839
|
}
|
|
4906
4840
|
if (matched) {
|
|
4907
|
-
|
|
4841
|
+
setFrameState(frames, frame, reference ? 5 : 4);
|
|
4908
4842
|
frames[frame + 1] = tokenIndex;
|
|
4909
4843
|
frames[frame + 6] = closeEnd;
|
|
4910
4844
|
if (!image) inactiveBefore = Math.max(inactiveBefore, openToken + 1);
|
|
@@ -4916,7 +4850,7 @@ function resolveReferences(source, tokens, frames, context) {
|
|
|
4916
4850
|
}
|
|
4917
4851
|
}
|
|
4918
4852
|
}
|
|
4919
|
-
if (rawFrame >= 0 &&
|
|
4853
|
+
if (rawFrame >= 0 && frames[rawFrame + 5] & 16) literalDepth--;
|
|
4920
4854
|
}
|
|
4921
4855
|
}
|
|
4922
4856
|
function assignDelimiterScopes(source, tokens, frames, delimiterByKind) {
|
|
@@ -4937,7 +4871,7 @@ function assignDelimiterScopes(source, tokens, frames, delimiterByKind) {
|
|
|
4937
4871
|
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
4938
4872
|
const tokenStart = inlineTokenStart(tokens, tokenIndex);
|
|
4939
4873
|
if (skipEnd >= 0 && tokenStart >= skipEnd) skipEnd = -1;
|
|
4940
|
-
if (kind ===
|
|
4874
|
+
if (kind === 72 || kind === 71) {
|
|
4941
4875
|
const frame = frameCursor;
|
|
4942
4876
|
frameCursor += 7;
|
|
4943
4877
|
const claim = frameClaim(frames, frame);
|
|
@@ -4948,33 +4882,29 @@ function assignDelimiterScopes(source, tokens, frames, delimiterByKind) {
|
|
|
4948
4882
|
if (claim === 3 || claim === 4 || claim === 5 || claim === 2 && inlineTokenEnd(tokens, frames[frame + 0]) < inlineTokenStart(tokens, frames[frame + 1])) {
|
|
4949
4883
|
workspace[frame + 2] = activeTop;
|
|
4950
4884
|
activeTop = frame;
|
|
4951
|
-
workspace[frame +
|
|
4885
|
+
workspace[frame + 3] = -1;
|
|
4952
4886
|
}
|
|
4953
4887
|
}
|
|
4954
4888
|
if (skipEnd < 0) {
|
|
4955
4889
|
const run = delimiterRunAt(source, tokens, tokenIndex, delimiterByKind);
|
|
4956
4890
|
if (run) {
|
|
4957
4891
|
const runIndex = runs?.length ?? 0;
|
|
4958
|
-
const previous = activeTop < 0 ? rootLastRun : frames[activeTop +
|
|
4892
|
+
const previous = activeTop < 0 ? rootLastRun : frames[activeTop + 3];
|
|
4959
4893
|
if (previous >= 0) {
|
|
4960
4894
|
run.previous = previous;
|
|
4961
4895
|
runs[previous].next = runIndex;
|
|
4962
4896
|
}
|
|
4963
4897
|
if (activeTop < 0) rootLastRun = runIndex;
|
|
4964
|
-
else workspace[activeTop +
|
|
4898
|
+
else workspace[activeTop + 3] = runIndex;
|
|
4965
4899
|
(runs ??= []).push(run);
|
|
4966
4900
|
}
|
|
4967
4901
|
}
|
|
4968
4902
|
}
|
|
4969
4903
|
return runs;
|
|
4970
4904
|
}
|
|
4971
|
-
function hasBracketRewrite(frames) {
|
|
4972
|
-
for (let frame = frameHeaderSize; frame < frames.length; frame += 7) if (frameClaim(frames, frame) !== 0) return true;
|
|
4973
|
-
return false;
|
|
4974
|
-
}
|
|
4975
4905
|
function appendReferenceBoundary(result, tokens, frames, frame, close) {
|
|
4976
4906
|
const token = frames[frame + (close ? 1 : 0)];
|
|
4977
|
-
const kind = (frameClaim(frames, frame) === 5 ?
|
|
4907
|
+
const kind = (frameClaim(frames, frame) === 5 ? 202 : 198) + (isImageFrame(tokens, frames, frame) ? 2 : 0) + (close ? 1 : 0);
|
|
4978
4908
|
const end = close ? frames[frame + 6] : inlineTokenEnd(tokens, token);
|
|
4979
4909
|
appendInlineToken(result, kind, inlineTokenStart(tokens, token), end, inlineTokenData(tokens, token));
|
|
4980
4910
|
return end;
|
|
@@ -4993,35 +4923,34 @@ function emitResolvedTokens(tokens, frames, replacements) {
|
|
|
4993
4923
|
const tokenStart = inlineTokenStart(tokens, tokenIndex);
|
|
4994
4924
|
if (skipEnd >= 0 && tokenStart >= skipEnd) skipEnd = -1;
|
|
4995
4925
|
const skipping = skipEnd >= 0;
|
|
4996
|
-
if (kind ===
|
|
4926
|
+
if (kind === 72 || kind === 71) {
|
|
4997
4927
|
const frame = frameCursor;
|
|
4998
4928
|
frameCursor += 7;
|
|
4999
|
-
workspace[frame + 2] = rawTop;
|
|
5000
4929
|
rawTop = frame;
|
|
5001
4930
|
const claim = frameClaim(frames, frame);
|
|
5002
4931
|
if (!skipping) {
|
|
5003
4932
|
if (claim === 1) {
|
|
5004
4933
|
const closeToken = frames[frame + 1];
|
|
5005
|
-
const start = inlineTokenStart(tokens, tokenIndex) + (kind ===
|
|
4934
|
+
const start = inlineTokenStart(tokens, tokenIndex) + (kind === 71 ? 1 : 0);
|
|
5006
4935
|
skipEnd = inlineTokenEnd(tokens, closeToken);
|
|
5007
|
-
appendInlineToken(result,
|
|
4936
|
+
appendInlineToken(result, 133, start, skipEnd);
|
|
5008
4937
|
} else if (claim === 2) {
|
|
5009
4938
|
const closeToken = frames[frame + 1];
|
|
5010
|
-
if (inlineTokenEnd(tokens, tokenIndex) < inlineTokenStart(tokens, closeToken))
|
|
5011
|
-
} else if (claim === 3) appendInlineToken(result,
|
|
4939
|
+
if (inlineTokenEnd(tokens, tokenIndex) < inlineTokenStart(tokens, closeToken)) rewriteInlineTokenTail(result, 208, inlineTokenEnd(tokens, tokenIndex));
|
|
4940
|
+
} else if (claim === 3) appendInlineToken(result, 206, inlineTokenStart(tokens, tokenIndex), inlineTokenEnd(tokens, tokenIndex));
|
|
5012
4941
|
else if (claim === 4 || claim === 5) {
|
|
5013
4942
|
appendReferenceBoundary(result, tokens, frames, frame, false);
|
|
5014
4943
|
workspace[frame + 3] = referenceTop;
|
|
5015
4944
|
referenceTop = frame;
|
|
5016
4945
|
} else if (claim === 6) skipEnd = inlineTokenEnd(tokens, frames[frame + 1]);
|
|
5017
|
-
else if (!(literalDepth > 0 && kind !==
|
|
4946
|
+
else if (!(literalDepth > 0 && kind !== 71)) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
5018
4947
|
}
|
|
5019
|
-
if (
|
|
4948
|
+
if (frames[frame + 5] & 16) literalDepth++;
|
|
5020
4949
|
continue;
|
|
5021
4950
|
}
|
|
5022
|
-
if (kind ===
|
|
4951
|
+
if (kind === 74 || kind === 73) {
|
|
5023
4952
|
const rawFrame = rawTop;
|
|
5024
|
-
if (rawFrame >= 0) rawTop = frames[rawFrame +
|
|
4953
|
+
if (rawFrame >= 0) rawTop = frames[rawFrame + 4];
|
|
5025
4954
|
const referenceFrame = referenceTop;
|
|
5026
4955
|
const closesReference = referenceFrame >= 0 && frames[referenceFrame + 1] === tokenIndex;
|
|
5027
4956
|
if (!skipping) {
|
|
@@ -5032,8 +4961,8 @@ function emitResolvedTokens(tokens, frames, replacements) {
|
|
|
5032
4961
|
const claim = frameClaim(frames, rawFrame);
|
|
5033
4962
|
if (claim === 2) {
|
|
5034
4963
|
const openToken = frames[rawFrame + 0];
|
|
5035
|
-
if (inlineTokenEnd(tokens, openToken) < tokenStart) appendInlineToken(result,
|
|
5036
|
-
} else if (claim === 3) appendInlineToken(result,
|
|
4964
|
+
if (inlineTokenEnd(tokens, openToken) < tokenStart) appendInlineToken(result, 209, tokenStart, tokenStart + 1);
|
|
4965
|
+
} else if (claim === 3) appendInlineToken(result, 207, tokenStart, tokenStart + 1);
|
|
5037
4966
|
else if (claim === 0 || claim === 4 || claim === 5) {
|
|
5038
4967
|
const image = isImageFrame(tokens, frames, rawFrame);
|
|
5039
4968
|
if (literalDepth === 0 || image) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
@@ -5042,26 +4971,26 @@ function emitResolvedTokens(tokens, frames, replacements) {
|
|
|
5042
4971
|
}
|
|
5043
4972
|
} else appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
5044
4973
|
}
|
|
5045
|
-
if (rawFrame >= 0 &&
|
|
4974
|
+
if (rawFrame >= 0 && frames[rawFrame + 5] & 16) literalDepth--;
|
|
5046
4975
|
continue;
|
|
5047
4976
|
}
|
|
5048
4977
|
if (!skipping) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
5049
4978
|
}
|
|
5050
4979
|
return result;
|
|
5051
4980
|
}
|
|
5052
|
-
function
|
|
4981
|
+
function compileInlineResolver(options) {
|
|
5053
4982
|
return (delimiterConfigs) => {
|
|
5054
4983
|
const delimiterByKind = compileDelimiterConfigs(delimiterConfigs);
|
|
5055
|
-
return (source, tokens,
|
|
5056
|
-
const frames = analyzeBrackets(source, tokens, delimiterByKind,
|
|
5057
|
-
const
|
|
5058
|
-
if (
|
|
4984
|
+
return (source, tokens, definitions) => {
|
|
4985
|
+
const frames = analyzeBrackets(source, tokens, delimiterByKind, definitions, options);
|
|
4986
|
+
const flags = frames[0];
|
|
4987
|
+
if (flags & 1) resolveReferences(source, tokens, frames, definitions);
|
|
5059
4988
|
let replacements = noDelimiterReplacements;
|
|
5060
|
-
if (
|
|
4989
|
+
if (flags & 2) {
|
|
5061
4990
|
const runs = assignDelimiterScopes(source, tokens, frames, delimiterByKind);
|
|
5062
4991
|
if (runs) replacements = resolveDelimiterMatches(runs);
|
|
5063
4992
|
}
|
|
5064
|
-
return
|
|
4993
|
+
return frames[0] & 4 || replacements.length > 0 ? emitResolvedTokens(tokens, frames, replacements) : tokens;
|
|
5065
4994
|
};
|
|
5066
4995
|
};
|
|
5067
4996
|
}
|
|
@@ -5094,7 +5023,7 @@ function compileProfile(options = {}) {
|
|
|
5094
5023
|
}
|
|
5095
5024
|
return {
|
|
5096
5025
|
block: compileBlockProfile(blockFeatures),
|
|
5097
|
-
inline: compileInlineProfile(inlineFeatures,
|
|
5026
|
+
inline: compileInlineProfile(inlineFeatures, compileInlineResolver({
|
|
5098
5027
|
component: options.component === true,
|
|
5099
5028
|
footnote: options.footnote === true
|
|
5100
5029
|
}))
|