satorigear 0.0.7 → 0.0.9
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 +13 -13
- package/dist/index.mjs +1315 -1608
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,8 +2,8 @@ import { decodeString } from "micromark-util-decode-string";
|
|
|
2
2
|
import { htmlBlockNames, htmlRawNames } from "micromark-util-html-tag-name";
|
|
3
3
|
//#region src/block/lines.ts
|
|
4
4
|
var BlockLines = class BlockLines {
|
|
5
|
-
#fieldLength = 0;
|
|
6
5
|
#fields;
|
|
6
|
+
#length = 0;
|
|
7
7
|
#locatorField = 0;
|
|
8
8
|
#relativeStart = Infinity;
|
|
9
9
|
#sourceLength;
|
|
@@ -16,10 +16,19 @@ var BlockLines = class BlockLines {
|
|
|
16
16
|
const sourceLength = source.length;
|
|
17
17
|
if (start > 0 || limit < sourceLength) source = source.slice(start, limit);
|
|
18
18
|
const lines = new BlockLines(sourceLength, Math.min(source.length + 15 >>> 4, 16384));
|
|
19
|
-
lines.#
|
|
19
|
+
lines.#length = BlockLines.#scan(source, lines);
|
|
20
20
|
if (start !== 0) lines.#shiftPositions(0, start);
|
|
21
21
|
return lines;
|
|
22
22
|
}
|
|
23
|
+
scan(source) {
|
|
24
|
+
this.#sourceLength = source.length;
|
|
25
|
+
this.#locatorField = 0;
|
|
26
|
+
this.#relativeStart = Infinity;
|
|
27
|
+
const lineCapacity = Math.min(source.length + 15 >>> 4, 16384);
|
|
28
|
+
this.#ensureCapacity(lineCapacity * 4);
|
|
29
|
+
this.#length = BlockLines.#scan(source, this);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
23
32
|
static #scan(source, lines) {
|
|
24
33
|
const limit = source.length;
|
|
25
34
|
let start = 0;
|
|
@@ -42,16 +51,16 @@ var BlockLines = class BlockLines {
|
|
|
42
51
|
lines.#ensureCapacity(field + 4);
|
|
43
52
|
fields = lines.#fields;
|
|
44
53
|
}
|
|
45
|
-
fields[field
|
|
46
|
-
fields[field
|
|
47
|
-
fields[field
|
|
48
|
-
field
|
|
54
|
+
fields[field++] = start;
|
|
55
|
+
fields[field++] = end;
|
|
56
|
+
fields[field++] = next;
|
|
57
|
+
fields[field++] = 0;
|
|
49
58
|
start = next;
|
|
50
59
|
}
|
|
51
|
-
return field;
|
|
60
|
+
return field / 4;
|
|
52
61
|
}
|
|
53
62
|
get length() {
|
|
54
|
-
return this.#
|
|
63
|
+
return this.#length;
|
|
55
64
|
}
|
|
56
65
|
start(index) {
|
|
57
66
|
return this.#position(this.#fields[index * 4 + 0]);
|
|
@@ -86,7 +95,7 @@ var BlockLines = class BlockLines {
|
|
|
86
95
|
return this.#lineEndingsNormalized || !value.includes("\r") ? value : value.replace(/\r\n|\r/g, "\n");
|
|
87
96
|
}
|
|
88
97
|
locationAt(offset) {
|
|
89
|
-
const fieldLength = this.#
|
|
98
|
+
const fieldLength = this.#length * 4;
|
|
90
99
|
if (fieldLength === 0) return {
|
|
91
100
|
line: 1,
|
|
92
101
|
column: 1,
|
|
@@ -120,8 +129,11 @@ var BlockLines = class BlockLines {
|
|
|
120
129
|
end: this.locationAt(end)
|
|
121
130
|
};
|
|
122
131
|
}
|
|
132
|
+
physicallyContiguous() {
|
|
133
|
+
return this.#sourceLength > 0;
|
|
134
|
+
}
|
|
123
135
|
push(start, end, next, prefixColumns = 0, lazy = false) {
|
|
124
|
-
const field = this.#
|
|
136
|
+
const field = this.#length * 4;
|
|
125
137
|
let fields = this.#fields;
|
|
126
138
|
if (field >= fields.length) {
|
|
127
139
|
this.#ensureCapacity(field + 4);
|
|
@@ -132,18 +144,39 @@ var BlockLines = class BlockLines {
|
|
|
132
144
|
fields[field + 1] = end;
|
|
133
145
|
fields[field + 2] = next;
|
|
134
146
|
fields[field + 3] = state;
|
|
135
|
-
this.#
|
|
147
|
+
this.#length++;
|
|
136
148
|
}
|
|
137
149
|
pushFrom(lines, index, start = lines.start(index), prefixColumns = lines.prefixColumns(index), lazy = lines.lazy(index)) {
|
|
138
150
|
this.push(start, lines.end(index), lines.next(index), prefixColumns, lazy);
|
|
139
151
|
}
|
|
152
|
+
pushAfterColumns(source, lines, index, columns) {
|
|
153
|
+
let offset = lines.start(index);
|
|
154
|
+
let consumed = lines.prefixColumns(index);
|
|
155
|
+
const end = lines.end(index);
|
|
156
|
+
while (offset < end && consumed < columns) {
|
|
157
|
+
const code = source.charCodeAt(offset);
|
|
158
|
+
if (code === 32) consumed++;
|
|
159
|
+
else if (code === 9) consumed += 4 - consumed % 4;
|
|
160
|
+
else break;
|
|
161
|
+
offset++;
|
|
162
|
+
}
|
|
163
|
+
if (offset === end) return 0;
|
|
164
|
+
if (consumed < columns) return -1;
|
|
165
|
+
const contentOffset = offset;
|
|
166
|
+
const prefixColumns = consumed - columns;
|
|
167
|
+
if (skipLineWhitespace(source, offset, end) < end) {
|
|
168
|
+
this.pushFrom(lines, index, contentOffset, prefixColumns);
|
|
169
|
+
return 1;
|
|
170
|
+
}
|
|
171
|
+
return 0;
|
|
172
|
+
}
|
|
140
173
|
pushLazy(lines, index) {
|
|
141
174
|
this.pushFrom(lines, index, void 0, void 0, true);
|
|
142
175
|
}
|
|
143
176
|
resetFrom(lines, index, start = lines.start(index), prefixColumns = lines.prefixColumns(index), lazy = lines.lazy(index)) {
|
|
144
177
|
const end = lines.end(index);
|
|
145
178
|
const next = lines.next(index);
|
|
146
|
-
this.#
|
|
179
|
+
this.#length = 0;
|
|
147
180
|
this.#relativeStart = Infinity;
|
|
148
181
|
this.push(start, end, next, prefixColumns, lazy);
|
|
149
182
|
}
|
|
@@ -152,7 +185,7 @@ var BlockLines = class BlockLines {
|
|
|
152
185
|
const fieldStart = start * 4;
|
|
153
186
|
const fieldEnd = end * 4;
|
|
154
187
|
result.#fields = this.#fields.slice(fieldStart, fieldEnd);
|
|
155
|
-
result.#
|
|
188
|
+
result.#length = end - start;
|
|
156
189
|
result.#lineEndingsNormalized = this.#lineEndingsNormalized;
|
|
157
190
|
if (this.#relativeStart < end) result.#relativeStart = Math.max(0, this.#relativeStart - start);
|
|
158
191
|
return result;
|
|
@@ -177,8 +210,8 @@ var BlockLines = class BlockLines {
|
|
|
177
210
|
return next;
|
|
178
211
|
}
|
|
179
212
|
pop() {
|
|
180
|
-
if (this.#
|
|
181
|
-
this.#
|
|
213
|
+
if (this.#length > 0) {
|
|
214
|
+
this.#length--;
|
|
182
215
|
if (this.#relativeStart >= this.length) this.#relativeStart = Infinity;
|
|
183
216
|
}
|
|
184
217
|
}
|
|
@@ -210,11 +243,11 @@ var BlockLines = class BlockLines {
|
|
|
210
243
|
if (start >= end) return;
|
|
211
244
|
const sourceStart = start * 4;
|
|
212
245
|
const sourceEnd = end * 4;
|
|
213
|
-
const targetStart = this.#
|
|
246
|
+
const targetStart = this.#length * 4;
|
|
214
247
|
const targetEnd = targetStart + sourceEnd - sourceStart;
|
|
215
248
|
this.#ensureCapacity(targetEnd);
|
|
216
249
|
this.#fields.set(lines.#fields.subarray(sourceStart, sourceEnd), targetStart);
|
|
217
|
-
this.#
|
|
250
|
+
this.#length += end - start;
|
|
218
251
|
}
|
|
219
252
|
#ensureCapacity(fieldLength) {
|
|
220
253
|
const fields = this.#fields;
|
|
@@ -231,7 +264,7 @@ var BlockLines = class BlockLines {
|
|
|
231
264
|
}
|
|
232
265
|
#shiftPositions(start, delta) {
|
|
233
266
|
const fields = this.#fields;
|
|
234
|
-
const fieldLength = this.#
|
|
267
|
+
const fieldLength = this.#length * 4;
|
|
235
268
|
for (let field = start * 4; field < fieldLength; field += 4) {
|
|
236
269
|
fields[field + 0] += delta;
|
|
237
270
|
fields[field + 1] += delta;
|
|
@@ -256,16 +289,21 @@ function lineIndentOffset(source, lines, index) {
|
|
|
256
289
|
const limit = offset + 3 - lines.prefixColumns(index);
|
|
257
290
|
const end = lines.end(index);
|
|
258
291
|
while (offset < end && offset < limit && source.charCodeAt(offset) === 32) offset++;
|
|
259
|
-
if (offset > limit) return -1;
|
|
292
|
+
if (offset > limit || offset === end) return -1;
|
|
260
293
|
const code = source.charCodeAt(offset);
|
|
261
294
|
return code === 32 || code === 9 ? -1 : offset;
|
|
262
295
|
}
|
|
263
|
-
function
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
296
|
+
function isBlankLine(source, lines, index) {
|
|
297
|
+
const end = lines.end(index);
|
|
298
|
+
return skipLineWhitespace(source, lines.start(index), end) === end;
|
|
299
|
+
}
|
|
300
|
+
function skipLineWhitespace(source, start, end) {
|
|
301
|
+
while (start < end) {
|
|
302
|
+
const code = source.charCodeAt(start);
|
|
303
|
+
if (code !== 32 && code !== 9) break;
|
|
304
|
+
start++;
|
|
267
305
|
}
|
|
268
|
-
return
|
|
306
|
+
return start;
|
|
269
307
|
}
|
|
270
308
|
function physicalColumnAt(source, offset) {
|
|
271
309
|
let start = offset;
|
|
@@ -300,58 +338,40 @@ function logicalLine(source, lines, index) {
|
|
|
300
338
|
}
|
|
301
339
|
return result + source.slice(offset, lines.next(index));
|
|
302
340
|
}
|
|
303
|
-
function contentAfterColumns(source, lines, index, columns) {
|
|
304
|
-
let offset = lines.start(index);
|
|
305
|
-
let consumed = lines.prefixColumns(index);
|
|
306
|
-
const end = lines.end(index);
|
|
307
|
-
while (offset < end && consumed < columns) {
|
|
308
|
-
if (source[offset] === " ") consumed++;
|
|
309
|
-
else if (source[offset] === " ") consumed += 4 - consumed % 4;
|
|
310
|
-
else break;
|
|
311
|
-
offset++;
|
|
312
|
-
}
|
|
313
|
-
if (consumed >= columns) return {
|
|
314
|
-
offset,
|
|
315
|
-
prefixColumns: consumed - columns
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
function removeIndent(value, columns) {
|
|
319
|
-
let offset = 0;
|
|
320
|
-
let consumed = 0;
|
|
321
|
-
while (offset < value.length && consumed < columns) {
|
|
322
|
-
if (value[offset] === " ") consumed++;
|
|
323
|
-
else if (value[offset] === " ") consumed += 4 - consumed % 4;
|
|
324
|
-
else break;
|
|
325
|
-
offset++;
|
|
326
|
-
}
|
|
327
|
-
return " ".repeat(Math.max(0, consumed - columns)) + value.slice(offset);
|
|
328
|
-
}
|
|
329
341
|
//#endregion
|
|
330
342
|
//#region src/primitives.ts
|
|
331
343
|
const emptyArray = [];
|
|
332
344
|
const emptySet = new Set();
|
|
333
345
|
//#endregion
|
|
334
346
|
//#region src/block/tokens.ts
|
|
347
|
+
function copyMetadata(target, source, start, end, targetStart) {
|
|
348
|
+
end = Math.min(end, source.length);
|
|
349
|
+
for (let read = start, write = targetStart; read < end; read++, write++) {
|
|
350
|
+
const value = source[read];
|
|
351
|
+
if (value) target[write] = value;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
335
354
|
var BlockTokenStream = class {
|
|
336
355
|
#definitionCounts;
|
|
337
356
|
#definitionMembershipChanges;
|
|
338
|
-
#fieldLength;
|
|
339
|
-
#fields;
|
|
357
|
+
#fieldLength = 0;
|
|
358
|
+
#fields = new Int32Array();
|
|
359
|
+
#groupField = -1;
|
|
340
360
|
#metadata;
|
|
341
|
-
#
|
|
361
|
+
#opens = [];
|
|
362
|
+
#relativeStart = Infinity;
|
|
342
363
|
#sourceLength;
|
|
343
364
|
constructor(sourceLength = 0) {
|
|
344
|
-
this.#fieldLength = 0;
|
|
345
|
-
this.#fields = new Int32Array();
|
|
346
|
-
this.#relativeStart = Number.POSITIVE_INFINITY;
|
|
347
365
|
this.#sourceLength = sourceLength;
|
|
348
366
|
}
|
|
349
367
|
reset(sourceLength) {
|
|
350
368
|
this.#definitionCounts?.clear();
|
|
351
369
|
this.#definitionMembershipChanges?.clear();
|
|
352
370
|
this.#fieldLength = 0;
|
|
371
|
+
this.#groupField = -1;
|
|
353
372
|
this.#metadata = void 0;
|
|
354
|
-
this.#
|
|
373
|
+
this.#opens.length = 0;
|
|
374
|
+
this.#relativeStart = Infinity;
|
|
355
375
|
this.#sourceLength = sourceLength;
|
|
356
376
|
}
|
|
357
377
|
get length() {
|
|
@@ -363,53 +383,43 @@ var BlockTokenStream = class {
|
|
|
363
383
|
hasDefinition(key) {
|
|
364
384
|
return this.#definitionCounts?.has(key) === true;
|
|
365
385
|
}
|
|
366
|
-
|
|
386
|
+
hasDefinitions() {
|
|
387
|
+
return !!this.#definitionCounts?.size;
|
|
388
|
+
}
|
|
389
|
+
push(kind, start, end, meta, role) {
|
|
390
|
+
const encodedRole = role ?? kind;
|
|
367
391
|
const field = this.#fieldLength;
|
|
368
392
|
this.#ensureCapacity(field + 4);
|
|
369
393
|
this.#fields[field + 0] = kind;
|
|
370
394
|
this.#fields[field + 1] = start;
|
|
371
395
|
this.#fields[field + 2] = end;
|
|
372
|
-
this.#fields[field + 3] = 0;
|
|
396
|
+
this.#fields[field + 3] = encodedRole < 64 ? 0 : this.#indexToken(field, encodedRole);
|
|
373
397
|
this.#fieldLength += 4;
|
|
374
398
|
if (meta) {
|
|
375
|
-
this.#metadata ??=
|
|
376
|
-
this.#metadata
|
|
399
|
+
this.#metadata ??= [];
|
|
400
|
+
this.#metadata[field / 4] = meta;
|
|
377
401
|
const definitionKey = meta.definitionKey;
|
|
378
402
|
if (definitionKey !== void 0) this.#updateDefinitionCount(definitionKey, 1, false);
|
|
379
403
|
}
|
|
380
404
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
opens.push(field);
|
|
391
|
-
fields[field + 3] = close;
|
|
392
|
-
close = rule.close;
|
|
393
|
-
continue;
|
|
394
|
-
}
|
|
395
|
-
if (rule && !rule.block) {
|
|
396
|
-
const start = field;
|
|
397
|
-
do
|
|
398
|
-
field += 4;
|
|
399
|
-
while (field < fieldLength && rules[fields[field]] === rule);
|
|
400
|
-
fields[start + 3] = (field - start) / 4;
|
|
401
|
-
field -= 4;
|
|
402
|
-
continue;
|
|
403
|
-
}
|
|
404
|
-
if (close === kind) {
|
|
405
|
-
const open = opens.pop();
|
|
406
|
-
close = fields[open + 3];
|
|
407
|
-
fields[open + 3] = (field - open) / 4 + 1;
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
if (rule) fields[field + 3] = 1;
|
|
405
|
+
#indexToken(field, encodedRole) {
|
|
406
|
+
if (encodedRole < 192) {
|
|
407
|
+
this.#opens.push(field);
|
|
408
|
+
return 0;
|
|
409
|
+
}
|
|
410
|
+
if (encodedRole < 256) {
|
|
411
|
+
const open = this.#opens.pop();
|
|
412
|
+
this.#fields[open + 3] = (field - open) / 4 + 1;
|
|
413
|
+
return 0;
|
|
411
414
|
}
|
|
412
|
-
if (
|
|
415
|
+
if (encodedRole < 320) return 1;
|
|
416
|
+
const previous = field - 4;
|
|
417
|
+
if (this.#groupField >= 0 && this.#fields[previous + 0] >= 320) {
|
|
418
|
+
this.#fields[this.#groupField + 3]++;
|
|
419
|
+
return 0;
|
|
420
|
+
}
|
|
421
|
+
this.#groupField = field;
|
|
422
|
+
return 1;
|
|
413
423
|
}
|
|
414
424
|
nodeLength(index) {
|
|
415
425
|
return this.#fields[index * 4 + 3];
|
|
@@ -420,8 +430,8 @@ var BlockTokenStream = class {
|
|
|
420
430
|
const nextStart = next.start(nextIndex);
|
|
421
431
|
const nextEnd = next.end(nextIndex);
|
|
422
432
|
if (this.kind(index) !== next.kind(nextIndex) || start + delta !== nextStart || end + delta !== nextEnd) return false;
|
|
423
|
-
const metadata = this.#metadata?.
|
|
424
|
-
const nextMetadata = next.#metadata?.
|
|
433
|
+
const metadata = this.#metadata?.[index];
|
|
434
|
+
const nextMetadata = next.#metadata?.[nextIndex];
|
|
425
435
|
if (metadata !== nextMetadata) {
|
|
426
436
|
if (metadata?.definitionKey !== nextMetadata?.definitionKey) return false;
|
|
427
437
|
const value = metadata?.value;
|
|
@@ -448,8 +458,8 @@ var BlockTokenStream = class {
|
|
|
448
458
|
const oldEnd = end - stableSuffixLength;
|
|
449
459
|
const newEnd = start + replacementLength - stableSuffixLength;
|
|
450
460
|
this.#definitionMembershipChanges?.clear();
|
|
451
|
-
for (let index = oldStart; index < oldEnd; index++) this.#updateDefinitionCount(this.#metadata?.
|
|
452
|
-
for (let index = stablePrefixLength; index < replacementLength - stableSuffixLength; index++) this.#updateDefinitionCount(replacement.#metadata?.
|
|
461
|
+
for (let index = oldStart; index < oldEnd; index++) this.#updateDefinitionCount(this.#metadata?.[index]?.definitionKey, -1, true);
|
|
462
|
+
for (let index = stablePrefixLength; index < replacementLength - stableSuffixLength; index++) this.#updateDefinitionCount(replacement.#metadata?.[index]?.definitionKey, 1, true);
|
|
453
463
|
const change = {
|
|
454
464
|
definitionMembershipChanges: this.#definitionMembershipChanges ?? emptySet,
|
|
455
465
|
newEnd,
|
|
@@ -490,35 +500,37 @@ var BlockTokenStream = class {
|
|
|
490
500
|
}
|
|
491
501
|
const indexDelta = replacementLength - replacedLength;
|
|
492
502
|
if (end === previousLength || indexDelta === 0) {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
if (
|
|
498
|
-
const metadata = this.#metadata ??= new Map();
|
|
499
|
-
for (const [index, value] of replacement.#metadata) metadata.set(start + index, value);
|
|
500
|
-
}
|
|
501
|
-
if (this.#metadata?.size === 0) this.#metadata = void 0;
|
|
503
|
+
const metadata = this.#metadata;
|
|
504
|
+
if (metadata) metadata.fill(void 0, start, end);
|
|
505
|
+
const replacementMetadata = replacement.#metadata;
|
|
506
|
+
if (replacementMetadata) copyMetadata(this.#metadata ??= [], replacementMetadata, 0, replacementMetadata.length, start);
|
|
507
|
+
if (end === previousLength && this.#metadata) this.#metadata.length = Math.min(this.#metadata.length, start + replacementLength);
|
|
502
508
|
} else {
|
|
503
|
-
const metadata =
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
509
|
+
const metadata = [];
|
|
510
|
+
const previousMetadata = this.#metadata;
|
|
511
|
+
if (previousMetadata) {
|
|
512
|
+
copyMetadata(metadata, previousMetadata, 0, start, 0);
|
|
513
|
+
copyMetadata(metadata, previousMetadata, end, previousMetadata.length, end + indexDelta);
|
|
514
|
+
}
|
|
515
|
+
const replacementMetadata = replacement.#metadata;
|
|
516
|
+
if (replacementMetadata) copyMetadata(metadata, replacementMetadata, 0, replacementMetadata.length, start);
|
|
517
|
+
this.#metadata = metadata.length > 0 ? metadata : void 0;
|
|
508
518
|
}
|
|
509
519
|
const newSuffixStart = start + replacementLength;
|
|
510
|
-
this.#relativeStart = newSuffixStart < this.length ? newSuffixStart :
|
|
520
|
+
this.#relativeStart = newSuffixStart < this.length ? newSuffixStart : Infinity;
|
|
511
521
|
this.#sourceLength = replacement.#sourceLength;
|
|
512
522
|
return change;
|
|
513
523
|
}
|
|
514
524
|
truncate(length) {
|
|
525
|
+
this.#groupField = -1;
|
|
515
526
|
this.#fieldLength = length * 4;
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
527
|
+
const metadata = this.#metadata;
|
|
528
|
+
if (metadata) {
|
|
529
|
+
for (let index = length; index < metadata.length; index++) {
|
|
530
|
+
const value = metadata[index];
|
|
531
|
+
if (value) this.#updateDefinitionCount(value.definitionKey, -1, false);
|
|
520
532
|
}
|
|
521
|
-
|
|
533
|
+
metadata.length = Math.min(metadata.length, length);
|
|
522
534
|
}
|
|
523
535
|
}
|
|
524
536
|
kind(index) {
|
|
@@ -542,13 +554,13 @@ var BlockTokenStream = class {
|
|
|
542
554
|
return last === 10 ? end - (source.charCodeAt(end - 2) === 13 ? 2 : 1) : last === 13 ? end - 1 : end;
|
|
543
555
|
}
|
|
544
556
|
text(source, index) {
|
|
545
|
-
return this.#metadata?.
|
|
557
|
+
return this.#metadata?.[index]?.text ?? source.slice(this.start(index), this.end(index));
|
|
546
558
|
}
|
|
547
559
|
value(index) {
|
|
548
|
-
return this.#metadata?.
|
|
560
|
+
return this.#metadata?.[index]?.value;
|
|
549
561
|
}
|
|
550
562
|
definitionKey(index) {
|
|
551
|
-
return this.#metadata?.
|
|
563
|
+
return this.#metadata?.[index]?.definitionKey;
|
|
552
564
|
}
|
|
553
565
|
#updateDefinitionCount(key, delta, trackMembership) {
|
|
554
566
|
if (key === void 0) return;
|
|
@@ -579,15 +591,18 @@ function appendLogicalToken(out, kind, source, lines, start, end, value) {
|
|
|
579
591
|
const tokenStart = lines.start(start);
|
|
580
592
|
const lastLine = end - 1;
|
|
581
593
|
const tokenEnd = lines.next(lastLine);
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
594
|
+
let canSliceSource = lines.physicallyContiguous();
|
|
595
|
+
if (!canSliceSource) {
|
|
596
|
+
const previous = source[tokenStart - 1];
|
|
597
|
+
canSliceSource = lines.prefixColumns(start) === 0 && (tokenStart === 0 || previous === "\n" || previous === "\r");
|
|
598
|
+
let previousLineEnd = lines.next(start);
|
|
599
|
+
for (let line = start + 1; canSliceSource && line < end; line++) {
|
|
600
|
+
if (lines.prefixColumns(line) !== 0 || lines.start(line) !== previousLineEnd) {
|
|
601
|
+
canSliceSource = false;
|
|
602
|
+
break;
|
|
603
|
+
}
|
|
604
|
+
previousLineEnd = lines.next(line);
|
|
589
605
|
}
|
|
590
|
-
previousLineEnd = lines.next(line);
|
|
591
606
|
}
|
|
592
607
|
let text;
|
|
593
608
|
if (!canSliceSource) {
|
|
@@ -602,40 +617,6 @@ function appendLogicalToken(out, kind, source, lines, start, end, value) {
|
|
|
602
617
|
}
|
|
603
618
|
//#endregion
|
|
604
619
|
//#region src/block/scanner.ts
|
|
605
|
-
function scanBlock(profile, context, source, lines, start, contentOffset, out) {
|
|
606
|
-
const starts = profile.starts[contentOffset < 0 ? -1 : source.charCodeAt(contentOffset)];
|
|
607
|
-
if (starts) for (const resolve of starts) {
|
|
608
|
-
const end = resolve(source, lines, start, contentOffset, out, context);
|
|
609
|
-
if (end !== void 0) return end;
|
|
610
|
-
}
|
|
611
|
-
for (const fallback of profile.fallbacks) {
|
|
612
|
-
const fallbackEnd = fallback(source, lines, start, contentOffset, out, context);
|
|
613
|
-
if (fallbackEnd !== void 0) return fallbackEnd;
|
|
614
|
-
}
|
|
615
|
-
throw new Error("Syntax profile did not provide a block fallback");
|
|
616
|
-
}
|
|
617
|
-
function scanBlockLines(profile, context, source, lines, out, visit) {
|
|
618
|
-
for (let index = 0; index < lines.length;) {
|
|
619
|
-
let contentOffset = lines.start(index);
|
|
620
|
-
const lineEnd = lines.end(index);
|
|
621
|
-
let columns = lines.prefixColumns(index);
|
|
622
|
-
while (contentOffset < lineEnd) {
|
|
623
|
-
const code = source.charCodeAt(contentOffset);
|
|
624
|
-
if (code !== 32 && code !== 9) break;
|
|
625
|
-
columns += code === 32 ? 1 : 4 - columns % 4;
|
|
626
|
-
contentOffset++;
|
|
627
|
-
}
|
|
628
|
-
if (contentOffset === lineEnd) {
|
|
629
|
-
index++;
|
|
630
|
-
continue;
|
|
631
|
-
}
|
|
632
|
-
if (columns > 3) contentOffset = -1;
|
|
633
|
-
const lineStart = index;
|
|
634
|
-
const tokenStart = out.length;
|
|
635
|
-
index = scanBlock(profile, context, source, lines, index, contentOffset, out);
|
|
636
|
-
if (visit(lineStart, index, tokenStart, out.length)) return;
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
620
|
function sameShiftedBlock(previous, record, next, tokenStart, tokenEnd, delta) {
|
|
640
621
|
const length = previous.nodeLength(record.tokenStart);
|
|
641
622
|
if (length !== tokenEnd - tokenStart) return false;
|
|
@@ -643,6 +624,8 @@ function sameShiftedBlock(previous, record, next, tokenStart, tokenEnd, delta) {
|
|
|
643
624
|
return true;
|
|
644
625
|
}
|
|
645
626
|
var BlockScanContext = class {
|
|
627
|
+
#lineViewDepth = 0;
|
|
628
|
+
#lineViews = [];
|
|
646
629
|
#lookaheadEnd = 0;
|
|
647
630
|
#profile;
|
|
648
631
|
#unwrappedLine = new BlockLines();
|
|
@@ -665,7 +648,7 @@ var BlockScanContext = class {
|
|
|
665
648
|
contentIndex = 0;
|
|
666
649
|
continue;
|
|
667
650
|
}
|
|
668
|
-
return !
|
|
651
|
+
return !this.startsInterruptingBlock(source, contentLines, contentIndex, contentOffset);
|
|
669
652
|
}
|
|
670
653
|
}
|
|
671
654
|
retainLookahead(end) {
|
|
@@ -679,14 +662,44 @@ var BlockScanContext = class {
|
|
|
679
662
|
this.#lookaheadEnd = 0;
|
|
680
663
|
return end;
|
|
681
664
|
}
|
|
665
|
+
createLineView(lines, index, start, prefixColumns) {
|
|
666
|
+
const depth = this.#lineViewDepth++;
|
|
667
|
+
const view = this.#lineViews[depth] ??= new BlockLines();
|
|
668
|
+
view.resetFrom(lines, index, start, prefixColumns);
|
|
669
|
+
return view;
|
|
670
|
+
}
|
|
671
|
+
scanBlockLines(source, lines, out, visit) {
|
|
672
|
+
const profile = this.#profile;
|
|
673
|
+
for (let index = 0; index < lines.length;) {
|
|
674
|
+
let contentOffset = lines.start(index);
|
|
675
|
+
const lineEnd = lines.end(index);
|
|
676
|
+
let columns = lines.prefixColumns(index);
|
|
677
|
+
while (contentOffset < lineEnd) {
|
|
678
|
+
const code = source.charCodeAt(contentOffset);
|
|
679
|
+
if (code !== 32 && code !== 9) break;
|
|
680
|
+
columns += code === 32 ? 1 : 4 - columns % 4;
|
|
681
|
+
contentOffset++;
|
|
682
|
+
}
|
|
683
|
+
if (contentOffset === lineEnd) {
|
|
684
|
+
index++;
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
if (columns > 3) contentOffset = -1;
|
|
688
|
+
const lineStart = index;
|
|
689
|
+
const tokenStart = out.length;
|
|
690
|
+
index = profile.dispatch(source, lines, index, contentOffset, out, this);
|
|
691
|
+
if (visit(lineStart, index, tokenStart, out.length)) return;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
682
694
|
scanLines(source, lines, out) {
|
|
683
695
|
let blankSeparated = false;
|
|
684
696
|
let previousContentEnd = -1;
|
|
685
|
-
scanBlockLines(
|
|
697
|
+
this.scanBlockLines(source, lines, out, (lineStart, lineEnd) => {
|
|
686
698
|
blankSeparated ||= previousContentEnd >= 0 && lineStart > previousContentEnd;
|
|
687
699
|
previousContentEnd = lineEnd;
|
|
688
|
-
while (previousContentEnd > lineStart &&
|
|
700
|
+
while (previousContentEnd > lineStart && isBlankLine(source, lines, previousContentEnd - 1)) previousContentEnd--;
|
|
689
701
|
});
|
|
702
|
+
if (lines === this.#lineViews[this.#lineViewDepth - 1]) this.#lineViewDepth--;
|
|
690
703
|
return blankSeparated;
|
|
691
704
|
}
|
|
692
705
|
startsInterruptingBlock(source, lines, index, contentOffset = lineIndentOffset(source, lines, index)) {
|
|
@@ -699,26 +712,23 @@ var BlockScanContext = class {
|
|
|
699
712
|
};
|
|
700
713
|
var BlockScanner = class {
|
|
701
714
|
#context;
|
|
702
|
-
#lines;
|
|
703
|
-
#
|
|
704
|
-
#
|
|
705
|
-
|
|
715
|
+
#lines = new BlockLines();
|
|
716
|
+
#records = [];
|
|
717
|
+
#tokens = new BlockTokenStream();
|
|
718
|
+
builds;
|
|
706
719
|
constructor(profile) {
|
|
707
720
|
this.#context = new BlockScanContext(profile);
|
|
708
|
-
this
|
|
709
|
-
this.#lines = new BlockLines();
|
|
710
|
-
this.#records = [];
|
|
711
|
-
this.#tokens = new BlockTokenStream();
|
|
721
|
+
this.builds = profile.builds;
|
|
712
722
|
}
|
|
713
723
|
scan(source) {
|
|
714
|
-
const lines =
|
|
724
|
+
const lines = this.#lines.scan(source);
|
|
715
725
|
const tokens = this.#tokens;
|
|
716
726
|
tokens.reset(source.length);
|
|
717
727
|
const records = this.#records;
|
|
718
728
|
const context = this.#context;
|
|
719
729
|
let recordIndex = 0;
|
|
720
730
|
context.resetLookahead();
|
|
721
|
-
scanBlockLines(
|
|
731
|
+
context.scanBlockLines(source, lines, tokens, (lineStart, lineEnd, tokenStart) => {
|
|
722
732
|
const end = lines.next(lineEnd - 1);
|
|
723
733
|
const dependencyEnd = Math.max(end, context.consumeLookahead());
|
|
724
734
|
const record = records[recordIndex++];
|
|
@@ -734,9 +744,7 @@ var BlockScanner = class {
|
|
|
734
744
|
tokenStart
|
|
735
745
|
});
|
|
736
746
|
});
|
|
737
|
-
tokens.indexStructure(this.#profile.rules);
|
|
738
747
|
records.length = recordIndex;
|
|
739
|
-
this.#lines = lines;
|
|
740
748
|
}
|
|
741
749
|
get tokens() {
|
|
742
750
|
return this.#tokens;
|
|
@@ -744,10 +752,6 @@ var BlockScanner = class {
|
|
|
744
752
|
get records() {
|
|
745
753
|
return this.#records;
|
|
746
754
|
}
|
|
747
|
-
ruleOf(tokenStart) {
|
|
748
|
-
const kind = this.#tokens.kind(tokenStart);
|
|
749
|
-
return this.#profile.rules[kind];
|
|
750
|
-
}
|
|
751
755
|
locator() {
|
|
752
756
|
return this.#lines.locator();
|
|
753
757
|
}
|
|
@@ -776,7 +780,7 @@ var BlockScanner = class {
|
|
|
776
780
|
const scanLines = nextLines.slice(scanLineStart, scanLineEnd);
|
|
777
781
|
let convergenceIndex = affectedIndex;
|
|
778
782
|
context.resetLookahead();
|
|
779
|
-
scanBlockLines(
|
|
783
|
+
context.scanBlockLines(nextSource, scanLines, replacement, (lineStart, lineEnd, tokenStart, tokenEnd) => {
|
|
780
784
|
const blockStart = scanLines.start(lineStart);
|
|
781
785
|
const blockEnd = scanLines.next(lineEnd - 1);
|
|
782
786
|
const observedEnd = context.consumeLookahead();
|
|
@@ -805,7 +809,6 @@ var BlockScanner = class {
|
|
|
805
809
|
const expandedEnd = Math.min(nextSource.length, restartOffset + (scanEnd - restartOffset) * 2);
|
|
806
810
|
scanLineEnd = nextLines.indexAtOrAfter(expandedEnd);
|
|
807
811
|
}
|
|
808
|
-
replacement.indexStructure(this.#profile.rules);
|
|
809
812
|
const oldTokenLength = this.#tokens.length;
|
|
810
813
|
const oldTokenEnd = convergedIndex < 0 ? oldTokenLength : previousRecords[convergedIndex].tokenStart;
|
|
811
814
|
const tokenChange = this.#tokens.replace(oldTokenStart, oldTokenEnd, replacement, changedSpan.start, oldChangedEnd);
|
|
@@ -845,7 +848,7 @@ var BlockScanner = class {
|
|
|
845
848
|
function blockEnd(tokenStart, context) {
|
|
846
849
|
const tokens = context.structure.tokens;
|
|
847
850
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
848
|
-
return
|
|
851
|
+
return close === tokenStart ? tokens.contentEnd(context.source, close) : tokens.end(close);
|
|
849
852
|
}
|
|
850
853
|
function leafBlockPosition(tokenStart, context) {
|
|
851
854
|
const tokens = context.structure.tokens;
|
|
@@ -859,133 +862,130 @@ function fencedBlockPosition(tokenStart, block, context) {
|
|
|
859
862
|
return context.locator.positionAt(tokens.start(tokenStart) + block.markerOffset, positionEnd);
|
|
860
863
|
}
|
|
861
864
|
function buildBlockNode(tokenStart, context) {
|
|
862
|
-
|
|
865
|
+
const kind = context.structure.tokens.kind(tokenStart);
|
|
866
|
+
return context.structure.builds[kind](tokenStart, context);
|
|
863
867
|
}
|
|
864
868
|
function buildBlockChildren(tokenStart, context) {
|
|
865
|
-
const
|
|
866
|
-
const tokens = structure.tokens;
|
|
869
|
+
const builds = context.structure.builds;
|
|
870
|
+
const tokens = context.structure.tokens;
|
|
867
871
|
const children = [];
|
|
868
872
|
const tokenEnd = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
869
873
|
for (let child = tokenStart + 1; child < tokenEnd;) {
|
|
870
874
|
const length = tokens.nodeLength(child);
|
|
871
|
-
if (length > 0
|
|
875
|
+
if (length > 0) {
|
|
876
|
+
const kind = tokens.kind(child);
|
|
877
|
+
const role = kind & 448;
|
|
878
|
+
if (role === 64 || role === 256) children.push(builds[kind](child, context));
|
|
879
|
+
}
|
|
872
880
|
child += length || 1;
|
|
873
881
|
}
|
|
874
882
|
return children;
|
|
875
883
|
}
|
|
876
884
|
//#endregion
|
|
877
885
|
//#region src/source-view.ts
|
|
878
|
-
|
|
879
|
-
|
|
886
|
+
function containingSegment(segments, offset) {
|
|
887
|
+
let low = 0;
|
|
888
|
+
let high = segments.length >>> 1;
|
|
889
|
+
while (low < high) {
|
|
890
|
+
const middle = low + high >>> 1;
|
|
891
|
+
if (offset < segments[middle * 2 + 1]) high = middle;
|
|
892
|
+
else low = middle + 1;
|
|
893
|
+
}
|
|
894
|
+
return low * 2;
|
|
895
|
+
}
|
|
896
|
+
var SourceView = class {
|
|
897
|
+
#offset = 0;
|
|
898
|
+
#segments;
|
|
880
899
|
text;
|
|
881
|
-
constructor(source,
|
|
882
|
-
|
|
883
|
-
|
|
900
|
+
constructor(source, tokens, tokenStart, nodeLength) {
|
|
901
|
+
let token = tokenStart + 1;
|
|
902
|
+
const firstStart = tokens.start(token);
|
|
903
|
+
const tokenEnd = tokenStart + nodeLength;
|
|
904
|
+
let segmentStart = firstStart;
|
|
905
|
+
let end = tokens.end(token++);
|
|
906
|
+
let parts;
|
|
907
|
+
let segments;
|
|
908
|
+
let viewEnd = 0;
|
|
909
|
+
while (token < tokenEnd && tokens.kind(token) === 1) {
|
|
910
|
+
const start = tokens.start(token);
|
|
911
|
+
if (start !== end) {
|
|
912
|
+
(parts ??= []).push(source.slice(segmentStart, end));
|
|
913
|
+
(segments ??= []).push(segmentStart - viewEnd, viewEnd += end - segmentStart);
|
|
914
|
+
segmentStart = start;
|
|
915
|
+
}
|
|
916
|
+
end = tokens.end(token);
|
|
917
|
+
token++;
|
|
918
|
+
}
|
|
919
|
+
if (parts && segments) {
|
|
920
|
+
parts.push(source.slice(segmentStart, end));
|
|
921
|
+
segments.push(segmentStart - viewEnd, viewEnd + end - segmentStart);
|
|
922
|
+
this.#segments = segments;
|
|
923
|
+
this.text = parts.join("");
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
this.#offset = firstStart;
|
|
927
|
+
this.text = source.slice(firstStart, end);
|
|
884
928
|
}
|
|
885
|
-
|
|
886
|
-
|
|
929
|
+
mapOffset(offset) {
|
|
930
|
+
const segments = this.#segments;
|
|
931
|
+
if (!segments) return this.#offset + offset;
|
|
932
|
+
if (offset === this.text.length) return segments[segments.length - 2] + offset;
|
|
933
|
+
return segments[containingSegment(segments, offset)] + offset;
|
|
887
934
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
};
|
|
935
|
+
mapEnd(offset) {
|
|
936
|
+
const segments = this.#segments;
|
|
937
|
+
if (!segments) return this.#offset + offset;
|
|
938
|
+
return segments[containingSegment(segments, Math.max(0, offset - 1))] + offset;
|
|
893
939
|
}
|
|
894
940
|
shift(delta) {
|
|
895
|
-
this.#
|
|
941
|
+
const segments = this.#segments;
|
|
942
|
+
if (!segments) {
|
|
943
|
+
this.#offset += delta;
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
for (let index = 0; index < segments.length; index += 2) segments[index] += delta;
|
|
896
947
|
}
|
|
897
948
|
};
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
const start = ranges[read];
|
|
907
|
-
const end = ranges[read + 1];
|
|
908
|
-
if (start === end) continue;
|
|
909
|
-
const write = segmentCount * 2;
|
|
910
|
-
ranges[write] = start - viewOffset;
|
|
911
|
-
viewOffset += end - start;
|
|
912
|
-
parts.push(source.slice(start, end));
|
|
913
|
-
ranges[write + 1] = viewOffset;
|
|
914
|
-
segmentCount++;
|
|
915
|
-
}
|
|
916
|
-
ranges.length = segmentCount * 2;
|
|
917
|
-
this.#segments = ranges;
|
|
918
|
-
this.text = parts.join("");
|
|
919
|
-
}
|
|
920
|
-
mapPoint(offset) {
|
|
921
|
-
if (this.#segments.length === 0) return 0;
|
|
922
|
-
if (offset === this.text.length) return this.#segments[this.#segments.length - 2] + offset;
|
|
923
|
-
const segment = this.#containingSegment(offset);
|
|
924
|
-
return this.#segments[segment] + offset;
|
|
925
|
-
}
|
|
926
|
-
mapSpan(start, end) {
|
|
927
|
-
if (this.#segments.length === 0) return {
|
|
928
|
-
start: 0,
|
|
929
|
-
end: 0
|
|
930
|
-
};
|
|
931
|
-
if (start === end) {
|
|
932
|
-
const point = this.mapPoint(start);
|
|
933
|
-
return {
|
|
934
|
-
start: point,
|
|
935
|
-
end: point
|
|
936
|
-
};
|
|
937
|
-
}
|
|
938
|
-
const first = this.#containingSegment(start);
|
|
939
|
-
const last = this.#containingSegment(end - 1);
|
|
940
|
-
return {
|
|
941
|
-
start: this.#segments[first] + start,
|
|
942
|
-
end: this.#segments[last] + end
|
|
943
|
-
};
|
|
949
|
+
//#endregion
|
|
950
|
+
//#region src/inline/region.ts
|
|
951
|
+
const definitionAny = Symbol();
|
|
952
|
+
var TrackedDefinitionLookup = class {
|
|
953
|
+
definitions;
|
|
954
|
+
dependencies;
|
|
955
|
+
constructor(definitions) {
|
|
956
|
+
this.definitions = definitions;
|
|
944
957
|
}
|
|
945
|
-
|
|
946
|
-
|
|
958
|
+
hasDefinition(key) {
|
|
959
|
+
(this.dependencies ??= new Set()).add(key);
|
|
960
|
+
return this.definitions.hasDefinition(key);
|
|
947
961
|
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
const middle = low + high >>> 1;
|
|
953
|
-
if (offset < this.#segments[middle * 2 + 1]) high = middle;
|
|
954
|
-
else low = middle + 1;
|
|
955
|
-
}
|
|
956
|
-
return low * 2;
|
|
962
|
+
hasDefinitions() {
|
|
963
|
+
const hasAny = this.definitions.hasDefinitions();
|
|
964
|
+
if (!hasAny) (this.dependencies ??= new Set()).add(definitionAny);
|
|
965
|
+
return hasAny;
|
|
957
966
|
}
|
|
958
967
|
};
|
|
959
|
-
//#endregion
|
|
960
|
-
//#region src/inline/region.ts
|
|
961
|
-
function hasDefinition(key) {
|
|
962
|
-
(this.dependencies ??= new Set()).add(key);
|
|
963
|
-
return this.definitionContext.hasDefinition(key);
|
|
964
|
-
}
|
|
965
968
|
var InlineRegion = class {
|
|
966
969
|
#definitionDependencies;
|
|
967
970
|
#rawTokens;
|
|
968
971
|
#profile;
|
|
969
|
-
|
|
972
|
+
tokens;
|
|
970
973
|
tokenStart;
|
|
971
974
|
view;
|
|
972
|
-
constructor(profile, binding,
|
|
975
|
+
constructor(profile, binding, definitions) {
|
|
973
976
|
this.#profile = profile;
|
|
974
977
|
this.tokenStart = binding.tokenStart;
|
|
975
978
|
this.view = binding.view;
|
|
976
|
-
this.#updateTokens(binding.view.text,
|
|
977
|
-
}
|
|
978
|
-
get tokens() {
|
|
979
|
-
return this.#tokens;
|
|
979
|
+
this.#updateTokens(binding.view.text, definitions, emptySet);
|
|
980
980
|
}
|
|
981
|
-
update(binding,
|
|
982
|
-
this.#updateTokens(binding.view.text,
|
|
981
|
+
update(binding, definitions, definitionMembershipChanges) {
|
|
982
|
+
this.#updateTokens(binding.view.text, definitions, definitionMembershipChanges);
|
|
983
983
|
this.tokenStart = binding.tokenStart;
|
|
984
984
|
this.view = binding.view;
|
|
985
985
|
return this;
|
|
986
986
|
}
|
|
987
|
-
updateDefinitions(
|
|
988
|
-
return this.#updateTokens(this.view.text,
|
|
987
|
+
updateDefinitions(definitions, definitionMembershipChanges) {
|
|
988
|
+
return this.#updateTokens(this.view.text, definitions, definitionMembershipChanges);
|
|
989
989
|
}
|
|
990
990
|
shift(delta, tokenDelta) {
|
|
991
991
|
this.tokenStart += tokenDelta;
|
|
@@ -993,85 +993,33 @@ var InlineRegion = class {
|
|
|
993
993
|
}
|
|
994
994
|
#dependenciesChanged(definitionMembershipChanges) {
|
|
995
995
|
const dependencies = this.#definitionDependencies;
|
|
996
|
-
if (dependencies.
|
|
997
|
-
|
|
996
|
+
if (dependencies.has(definitionAny)) return definitionMembershipChanges.size > 0;
|
|
997
|
+
const labels = dependencies;
|
|
998
|
+
if (labels.size < definitionMembershipChanges.size) {
|
|
999
|
+
for (const key of labels) if (definitionMembershipChanges.has(key)) return true;
|
|
998
1000
|
} else for (const key of definitionMembershipChanges) if (dependencies.has(key)) return true;
|
|
999
1001
|
return false;
|
|
1000
1002
|
}
|
|
1001
|
-
#updateTokens(source,
|
|
1003
|
+
#updateTokens(source, definitions, definitionMembershipChanges) {
|
|
1002
1004
|
const previousTokens = this.#rawTokens;
|
|
1003
1005
|
const sourceUnchanged = previousTokens !== void 0 && source === this.view.text;
|
|
1004
1006
|
if (sourceUnchanged && !this.#dependenciesChanged(definitionMembershipChanges)) return false;
|
|
1005
|
-
|
|
1006
|
-
definitionContext,
|
|
1007
|
-
hasDefinition
|
|
1008
|
-
};
|
|
1007
|
+
definitions.dependencies = void 0;
|
|
1009
1008
|
const rawTokens = sourceUnchanged ? previousTokens : this.#profile.tokenize(source);
|
|
1010
|
-
const tokens = this.#profile.resolve(source, rawTokens,
|
|
1011
|
-
this.#definitionDependencies =
|
|
1009
|
+
const tokens = this.#profile.resolve(source, rawTokens, definitions);
|
|
1010
|
+
this.#definitionDependencies = definitions.dependencies ?? emptySet;
|
|
1012
1011
|
this.#rawTokens = rawTokens;
|
|
1013
|
-
this
|
|
1012
|
+
this.tokens = tokens;
|
|
1014
1013
|
return true;
|
|
1015
1014
|
}
|
|
1016
1015
|
};
|
|
1017
|
-
var
|
|
1018
|
-
#
|
|
1019
|
-
#regions;
|
|
1020
|
-
constructor(regions = emptyArray) {
|
|
1021
|
-
this.#regions = regions;
|
|
1022
|
-
}
|
|
1023
|
-
reset(regions) {
|
|
1024
|
-
this.#index = 0;
|
|
1025
|
-
this.#regions = regions;
|
|
1026
|
-
}
|
|
1027
|
-
take(tokenStart) {
|
|
1028
|
-
const region = this.#regions[this.#index];
|
|
1029
|
-
if (region?.tokenStart !== tokenStart) return;
|
|
1030
|
-
this.#index++;
|
|
1031
|
-
return region;
|
|
1032
|
-
}
|
|
1033
|
-
};
|
|
1034
|
-
function resolveInlineRegion(source, profile, tokens, tokenStart) {
|
|
1035
|
-
const view = inlineViewOf(source, tokens, tokenStart, tokens.nodeLength(tokenStart));
|
|
1036
|
-
if (!view) return;
|
|
1037
|
-
const text = view.text;
|
|
1038
|
-
return {
|
|
1039
|
-
tokenStart,
|
|
1040
|
-
tokens: profile.resolve(text, profile.tokenize(text), tokens),
|
|
1041
|
-
view
|
|
1042
|
-
};
|
|
1043
|
-
}
|
|
1044
|
-
function inlineViewOf(source, tokens, tokenStart, nodeLength) {
|
|
1045
|
-
let firstStart = -1;
|
|
1046
|
-
let firstEnd = -1;
|
|
1047
|
-
let ranges;
|
|
1048
|
-
const tokenEnd = tokenStart + nodeLength;
|
|
1049
|
-
for (let token = tokenStart + 1; token < tokenEnd; token++) {
|
|
1050
|
-
if (tokens.kind(token) !== 1) continue;
|
|
1051
|
-
const start = tokens.start(token);
|
|
1052
|
-
const end = tokens.end(token);
|
|
1053
|
-
if (firstStart < 0) {
|
|
1054
|
-
firstStart = start;
|
|
1055
|
-
firstEnd = end;
|
|
1056
|
-
} else if (start === firstEnd) {
|
|
1057
|
-
firstEnd = end;
|
|
1058
|
-
if (ranges) ranges[ranges.length - 1] = end;
|
|
1059
|
-
} else {
|
|
1060
|
-
ranges ??= [firstStart, firstEnd];
|
|
1061
|
-
ranges.push(start, end);
|
|
1062
|
-
firstEnd = end;
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
if (ranges) return new SegmentedSourceView(source, ranges);
|
|
1066
|
-
if (firstStart >= 0) return new ContiguousSourceView(source, firstStart, firstEnd);
|
|
1067
|
-
}
|
|
1068
|
-
//#endregion
|
|
1069
|
-
//#region src/syntax-state.ts
|
|
1070
|
-
var SyntaxState = class {
|
|
1016
|
+
var InlineRegionState = class {
|
|
1017
|
+
#lookup;
|
|
1071
1018
|
#profile;
|
|
1072
1019
|
#regionsByBlock = [];
|
|
1073
1020
|
#structure;
|
|
1074
1021
|
constructor(profile, structure) {
|
|
1022
|
+
this.#lookup = new TrackedDefinitionLookup(structure.tokens);
|
|
1075
1023
|
this.#profile = profile;
|
|
1076
1024
|
this.#structure = structure;
|
|
1077
1025
|
}
|
|
@@ -1099,11 +1047,10 @@ var SyntaxState = class {
|
|
|
1099
1047
|
for (let token = tokenStart; token < tokenEnd; token++) {
|
|
1100
1048
|
const nodeLength = tokens.nodeLength(token);
|
|
1101
1049
|
if (nodeLength === 0) continue;
|
|
1102
|
-
if (
|
|
1103
|
-
|
|
1104
|
-
if (inlineView) bindings.push({
|
|
1050
|
+
if (tokens.kind(token) & 32) {
|
|
1051
|
+
if (tokens.kind(token + 1) === 1) bindings.push({
|
|
1105
1052
|
tokenStart: token,
|
|
1106
|
-
view:
|
|
1053
|
+
view: new SourceView(source, tokens, token, nodeLength)
|
|
1107
1054
|
});
|
|
1108
1055
|
token += nodeLength - 1;
|
|
1109
1056
|
}
|
|
@@ -1137,7 +1084,7 @@ var SyntaxState = class {
|
|
|
1137
1084
|
while (displacedIndex < displacedRegions.length && displacedRegions[displacedIndex].tokenStart < previousTokenStart) displacedIndex++;
|
|
1138
1085
|
if (displacedRegions[displacedIndex]?.tokenStart === previousTokenStart) candidate = displacedRegions[displacedIndex++];
|
|
1139
1086
|
}
|
|
1140
|
-
regions[regionIndex] = candidate
|
|
1087
|
+
regions[regionIndex] = candidate?.update(binding, this.#lookup, definitionMembershipChanges) ?? new InlineRegion(this.#profile, binding, this.#lookup);
|
|
1141
1088
|
}
|
|
1142
1089
|
regionsByBlock[blockIndex] = regions;
|
|
1143
1090
|
}
|
|
@@ -1146,7 +1093,7 @@ var SyntaxState = class {
|
|
|
1146
1093
|
for (let index = start; index < end; index++) {
|
|
1147
1094
|
const regions = regionsByBlock[index];
|
|
1148
1095
|
let changed = false;
|
|
1149
|
-
for (const region of regions) if (region.updateDefinitions(
|
|
1096
|
+
for (const region of regions) if (region.updateDefinitions(this.#lookup, definitionMembershipChanges)) changed = true;
|
|
1150
1097
|
if (changed) (invalidatedBlocks ??= []).push(index);
|
|
1151
1098
|
}
|
|
1152
1099
|
};
|
|
@@ -1157,6 +1104,20 @@ var SyntaxState = class {
|
|
|
1157
1104
|
return invalidatedBlocks ?? emptyArray;
|
|
1158
1105
|
}
|
|
1159
1106
|
};
|
|
1107
|
+
var InlineRegionCursor = class {
|
|
1108
|
+
#index = 0;
|
|
1109
|
+
#regions = emptyArray;
|
|
1110
|
+
reset(regions) {
|
|
1111
|
+
this.#index = 0;
|
|
1112
|
+
this.#regions = regions;
|
|
1113
|
+
}
|
|
1114
|
+
take(tokenStart) {
|
|
1115
|
+
const region = this.#regions[this.#index];
|
|
1116
|
+
if (region?.tokenStart !== tokenStart) return;
|
|
1117
|
+
this.#index++;
|
|
1118
|
+
return region;
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1160
1121
|
//#endregion
|
|
1161
1122
|
//#region src/document.ts
|
|
1162
1123
|
function applyEdits(source, edits) {
|
|
@@ -1199,7 +1160,7 @@ var DocumentImpl = class {
|
|
|
1199
1160
|
#blockScanner;
|
|
1200
1161
|
#profile;
|
|
1201
1162
|
#source;
|
|
1202
|
-
#
|
|
1163
|
+
#regionState;
|
|
1203
1164
|
#tree = {
|
|
1204
1165
|
type: "root",
|
|
1205
1166
|
children: []
|
|
@@ -1209,8 +1170,8 @@ var DocumentImpl = class {
|
|
|
1209
1170
|
this.#source = source;
|
|
1210
1171
|
this.#blockScanner = new BlockScanner(profile.block);
|
|
1211
1172
|
this.#blockScanner.scan(source);
|
|
1212
|
-
this.#
|
|
1213
|
-
this.#updateTree(this.#
|
|
1173
|
+
this.#regionState = new InlineRegionState(profile.inline, this.#blockScanner);
|
|
1174
|
+
this.#updateTree(this.#regionState.update(source));
|
|
1214
1175
|
}
|
|
1215
1176
|
get source() {
|
|
1216
1177
|
return this.#source;
|
|
@@ -1225,14 +1186,14 @@ var DocumentImpl = class {
|
|
|
1225
1186
|
} };
|
|
1226
1187
|
const change = applyEdits(this.source, edits);
|
|
1227
1188
|
const blockChange = this.#blockScanner.edit(change);
|
|
1228
|
-
const invalidatedBlocks = this.#
|
|
1189
|
+
const invalidatedBlocks = this.#regionState.update(change.nextSource, blockChange);
|
|
1229
1190
|
this.#source = change.nextSource;
|
|
1230
1191
|
this.#updateTree(invalidatedBlocks, blockChange);
|
|
1231
1192
|
return { changedSpan: change.changedSpan };
|
|
1232
1193
|
}
|
|
1233
1194
|
#updateTree(invalidatedBlocks, change) {
|
|
1234
1195
|
const records = this.#blockScanner.records;
|
|
1235
|
-
const regionsByBlock = this.#
|
|
1196
|
+
const regionsByBlock = this.#regionState.regionsByBlock();
|
|
1236
1197
|
const locator = this.#blockScanner.locator();
|
|
1237
1198
|
const context = {
|
|
1238
1199
|
inlineContext: void 0,
|
|
@@ -1321,15 +1282,50 @@ var DocumentImpl = class {
|
|
|
1321
1282
|
};
|
|
1322
1283
|
//#endregion
|
|
1323
1284
|
//#region src/block/profile.ts
|
|
1285
|
+
function generateBlockDispatch(starts, fallbacks) {
|
|
1286
|
+
try {
|
|
1287
|
+
const resolvers = [];
|
|
1288
|
+
const call = (resolve) => {
|
|
1289
|
+
return `e=r${resolvers.push(resolve) - 1}(s,l,i,o,t,c);if(e!==void 0)return e;`;
|
|
1290
|
+
};
|
|
1291
|
+
let cases = "";
|
|
1292
|
+
for (const code in starts) cases += `case ${code}:${starts[code].map(call).join("")}break;`;
|
|
1293
|
+
const source = [
|
|
1294
|
+
`return(s,l,i,o,t,c)=>{`,
|
|
1295
|
+
`let e;switch(o<0?-1:s.charCodeAt(o)){${cases}}`,
|
|
1296
|
+
...fallbacks.map(call),
|
|
1297
|
+
`throw new Error("Syntax profile did not provide a block fallback")}`
|
|
1298
|
+
].join("");
|
|
1299
|
+
const names = resolvers.map((resolver, index) => `r${index}`);
|
|
1300
|
+
return Function(...names, source)(...resolvers);
|
|
1301
|
+
} catch {
|
|
1302
|
+
return (source, lines, start, contentOffset, out, context) => {
|
|
1303
|
+
const resolvers = starts[contentOffset < 0 ? -1 : source.charCodeAt(contentOffset)];
|
|
1304
|
+
if (resolvers) for (const resolve of resolvers) {
|
|
1305
|
+
const end = resolve(source, lines, start, contentOffset, out, context);
|
|
1306
|
+
if (end !== void 0) return end;
|
|
1307
|
+
}
|
|
1308
|
+
for (const fallback of fallbacks) {
|
|
1309
|
+
const end = fallback(source, lines, start, contentOffset, out, context);
|
|
1310
|
+
if (end !== void 0) return end;
|
|
1311
|
+
}
|
|
1312
|
+
throw new Error("Syntax profile did not provide a block fallback");
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1324
1316
|
function compileBlockProfile(features) {
|
|
1317
|
+
const builds = [];
|
|
1325
1318
|
const decorators = [];
|
|
1326
1319
|
const fallbacks = [];
|
|
1327
1320
|
const interrupts = [];
|
|
1328
1321
|
const lazyContinuationUnwrappers = [];
|
|
1329
|
-
const ruleByBlockRule = [];
|
|
1330
|
-
const rules = [];
|
|
1331
1322
|
const starts = [];
|
|
1332
1323
|
for (const feature of features) {
|
|
1324
|
+
if (feature.builds) for (const registration of feature.builds) {
|
|
1325
|
+
const token = registration.token;
|
|
1326
|
+
const tokens = typeof token === "number" ? [token] : token;
|
|
1327
|
+
for (const token of tokens) builds[token] = registration.build;
|
|
1328
|
+
}
|
|
1333
1329
|
if (feature.decorators) decorators.push(...feature.decorators);
|
|
1334
1330
|
if (feature.fallbacks) fallbacks.push(...feature.fallbacks);
|
|
1335
1331
|
if (feature.starts) for (const registration of feature.starts) {
|
|
@@ -1339,39 +1335,26 @@ function compileBlockProfile(features) {
|
|
|
1339
1335
|
if (registration.interrupt) (interrupts[code] ??= []).push(registration.interrupt);
|
|
1340
1336
|
}
|
|
1341
1337
|
}
|
|
1342
|
-
if (feature.rules) for (const registration of feature.rules) {
|
|
1343
|
-
const syntax = registration.syntax;
|
|
1344
|
-
const rule = {
|
|
1345
|
-
block: syntax.kind === "block" || syntax.kind === "leaf",
|
|
1346
|
-
close: syntax.kind === "block" || syntax.kind === "frame" ? syntax.close : 0,
|
|
1347
|
-
inlineContent: registration.inlineContent === true,
|
|
1348
|
-
build: registration.build
|
|
1349
|
-
};
|
|
1350
|
-
ruleByBlockRule[registration.rule] = rule;
|
|
1351
|
-
if (syntax.kind === "block" || syntax.kind === "frame") {
|
|
1352
|
-
const opens = typeof syntax.open === "number" ? [syntax.open] : syntax.open;
|
|
1353
|
-
for (const open of opens) rules[open] = rule;
|
|
1354
|
-
} else if (syntax.kind === "group") for (const token of syntax.tokens) rules[token] = rule;
|
|
1355
|
-
else if (syntax.kind === "leaf") rules[syntax.token] = rule;
|
|
1356
|
-
}
|
|
1357
1338
|
}
|
|
1358
1339
|
for (const registration of decorators) {
|
|
1359
|
-
const
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1362
|
-
|
|
1340
|
+
const token = registration.token;
|
|
1341
|
+
const tokens = typeof token === "number" ? [token] : token;
|
|
1342
|
+
for (const token of tokens) {
|
|
1343
|
+
const build = builds[token];
|
|
1344
|
+
if (!build) throw new Error(`Cannot decorate unknown block token ${token}`);
|
|
1345
|
+
builds[token] = registration.decorate(build);
|
|
1346
|
+
}
|
|
1363
1347
|
}
|
|
1364
1348
|
return {
|
|
1365
|
-
|
|
1349
|
+
builds,
|
|
1350
|
+
dispatch: generateBlockDispatch(starts, fallbacks),
|
|
1366
1351
|
interrupts,
|
|
1367
|
-
lazyContinuationUnwrappers
|
|
1368
|
-
rules,
|
|
1369
|
-
starts
|
|
1352
|
+
lazyContinuationUnwrappers
|
|
1370
1353
|
};
|
|
1371
1354
|
}
|
|
1372
1355
|
//#endregion
|
|
1373
1356
|
//#region src/inline/lexer.ts
|
|
1374
|
-
const
|
|
1357
|
+
const tokenizerFactories = new Map();
|
|
1375
1358
|
function matchInlinePatternEnd(pattern, source, start) {
|
|
1376
1359
|
pattern.lastIndex = start;
|
|
1377
1360
|
return pattern.test(source) ? pattern.lastIndex : -1;
|
|
@@ -1382,51 +1365,59 @@ function inlineMarkerRunEnd(source, start) {
|
|
|
1382
1365
|
while (source.charCodeAt(end) === marker) end++;
|
|
1383
1366
|
return end;
|
|
1384
1367
|
}
|
|
1385
|
-
function tokenize(source, textBoundary,
|
|
1368
|
+
function tokenize(source, textBoundary, scannerByCode) {
|
|
1386
1369
|
const tokens = [];
|
|
1387
1370
|
const end = source.length;
|
|
1388
|
-
let lineStart = 0;
|
|
1389
1371
|
let offset = 0;
|
|
1390
|
-
while (offset
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
offset = content;
|
|
1396
|
-
if (lineStart > 0) tokens.push(5, offset, offset, lineStart);
|
|
1397
|
-
lineStart = -1;
|
|
1398
|
-
}
|
|
1372
|
+
while (source.charCodeAt(offset) === 32) offset++;
|
|
1373
|
+
for (; offset < end;) {
|
|
1374
|
+
textBoundary.lastIndex = offset;
|
|
1375
|
+
if (!textBoundary.test(source)) break;
|
|
1376
|
+
offset = textBoundary.lastIndex - 1;
|
|
1399
1377
|
const code = source.charCodeAt(offset);
|
|
1400
1378
|
if (code === 10 || code === 13) {
|
|
1401
1379
|
if (source.charCodeAt(offset - 1) === 32 && source.charCodeAt(offset - 2) === 32) {
|
|
1402
1380
|
let spaces = offset - 2;
|
|
1403
1381
|
while (source.charCodeAt(spaces - 1) === 32) spaces--;
|
|
1404
|
-
tokens.push(
|
|
1382
|
+
tokens.push(128, spaces, offset, 0);
|
|
1405
1383
|
}
|
|
1406
|
-
offset++;
|
|
1384
|
+
const endingStart = offset++;
|
|
1407
1385
|
if (code === 13 && source.charCodeAt(offset) === 10) offset++;
|
|
1408
|
-
lineStart = offset;
|
|
1386
|
+
const lineStart = offset;
|
|
1387
|
+
while (source.charCodeAt(offset) === 32) offset++;
|
|
1388
|
+
tokens.push(67, endingStart, offset, lineStart);
|
|
1409
1389
|
continue;
|
|
1410
1390
|
}
|
|
1411
|
-
const scannedEnd =
|
|
1391
|
+
const scannedEnd = scannerByCode[code]?.(source, offset, tokens) ?? offset;
|
|
1412
1392
|
offset = scannedEnd > offset ? scannedEnd : offset + 1;
|
|
1413
|
-
textBoundary.lastIndex = offset;
|
|
1414
|
-
offset = textBoundary.test(source) ? textBoundary.lastIndex - 1 : end;
|
|
1415
1393
|
}
|
|
1416
1394
|
return tokens;
|
|
1417
1395
|
}
|
|
1418
|
-
function
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1396
|
+
function generateInlineTokenizer(boundaryCodes, textBoundary, scannerByCode) {
|
|
1397
|
+
const key = String.fromCharCode(...boundaryCodes);
|
|
1398
|
+
let factory = tokenizerFactories.get(key);
|
|
1399
|
+
if (factory === void 0) {
|
|
1400
|
+
const names = boundaryCodes.map((code, index) => `scan${index}`);
|
|
1401
|
+
const source = [
|
|
1402
|
+
`return source=>{`,
|
|
1403
|
+
`const tokens=[],end=source.length;let offset=0;`,
|
|
1404
|
+
`while(source.charCodeAt(offset)===32)offset++;for(;offset<end;){`,
|
|
1405
|
+
`textBoundary.lastIndex=offset;if(!textBoundary.test(source))break;offset=textBoundary.lastIndex-1;`,
|
|
1406
|
+
`const code=source.charCodeAt(offset);`,
|
|
1407
|
+
`if(code===10||code===13){`,
|
|
1408
|
+
`if(source.charCodeAt(offset-1)===32&&source.charCodeAt(offset-2)===32){`,
|
|
1409
|
+
`let spaces=offset-2;while(source.charCodeAt(spaces-1)===32)spaces--;`,
|
|
1410
|
+
`tokens.push(128,spaces,offset,0)}`,
|
|
1411
|
+
`const endingStart=offset++;if(code===13&&source.charCodeAt(offset)===10)offset++;`,
|
|
1412
|
+
`const lineStart=offset;while(source.charCodeAt(offset)===32)offset++;`,
|
|
1413
|
+
`tokens.push(67,endingStart,offset,lineStart);continue}`,
|
|
1414
|
+
`let scannedEnd;switch(code){${boundaryCodes.map((code, index) => `case ${code}:scannedEnd=scan${index}(source,offset,tokens);break;`).join("")}default:scannedEnd=offset}`,
|
|
1415
|
+
`offset=scannedEnd>offset?scannedEnd:offset+1}`,
|
|
1416
|
+
`return tokens}`
|
|
1417
|
+
].join("");
|
|
1418
|
+
tokenizerFactories.set(key, factory = Function("textBoundary", ...names, source));
|
|
1419
|
+
}
|
|
1420
|
+
return factory(textBoundary, ...boundaryCodes.map((code) => scannerByCode[code]));
|
|
1430
1421
|
}
|
|
1431
1422
|
function compileInlineTokenizer(rules) {
|
|
1432
1423
|
const scannerByCode = [];
|
|
@@ -1442,56 +1433,70 @@ function compileInlineTokenizer(rules) {
|
|
|
1442
1433
|
}
|
|
1443
1434
|
const boundaries = String.fromCharCode(...boundaryCodes).replaceAll(/[\\\]-]/g, "\\$&");
|
|
1444
1435
|
const textBoundary = new RegExp(`${boundaryCodes.length > 9 ? " {2,}[\\n\\r]|" : ""}[\\n\\r${boundaries}]`, "g");
|
|
1445
|
-
|
|
1446
|
-
|
|
1436
|
+
try {
|
|
1437
|
+
return generateInlineTokenizer(boundaryCodes, textBoundary, scannerByCode);
|
|
1438
|
+
} catch {
|
|
1439
|
+
return (source) => tokenize(source, textBoundary, scannerByCode);
|
|
1440
|
+
}
|
|
1447
1441
|
}
|
|
1448
1442
|
//#endregion
|
|
1449
1443
|
//#region src/inline/profile.ts
|
|
1450
1444
|
function compileInlineProfile(features, compileInlineResolver) {
|
|
1451
1445
|
const buildByKind = [];
|
|
1452
|
-
const decorateByKind = [];
|
|
1453
1446
|
const delimiters = [];
|
|
1454
1447
|
const scanRules = [];
|
|
1455
|
-
const syntaxByKind = [];
|
|
1456
|
-
const textByKind = [];
|
|
1457
1448
|
for (const feature of features) {
|
|
1458
|
-
if (feature.
|
|
1449
|
+
if (feature.scans) scanRules.push(...feature.scans);
|
|
1459
1450
|
if (feature.delimiters) delimiters.push(...feature.delimiters);
|
|
1460
|
-
const build = feature.
|
|
1451
|
+
const build = feature.builds;
|
|
1461
1452
|
if (!build) continue;
|
|
1462
1453
|
for (const rule of build) switch (rule.kind) {
|
|
1463
1454
|
case "decorate":
|
|
1464
1455
|
buildByKind[rule.token] = rule.apply;
|
|
1465
|
-
decorateByKind[rule.token] = true;
|
|
1466
1456
|
break;
|
|
1467
1457
|
case "leaf":
|
|
1468
|
-
buildByKind[rule.token] = rule.build;
|
|
1469
|
-
break;
|
|
1470
1458
|
case "text":
|
|
1471
|
-
|
|
1472
|
-
textByKind[rule.token] = true;
|
|
1473
|
-
break;
|
|
1474
|
-
case "container":
|
|
1475
|
-
buildByKind[rule.token] = rule.build;
|
|
1476
|
-
syntaxByKind[rule.token * 2] = rule.close;
|
|
1477
|
-
syntaxByKind[rule.token * 2 + 1] = rule.contentOpen;
|
|
1478
|
-
break;
|
|
1479
|
-
case "pair":
|
|
1480
|
-
buildByKind[rule.open] = rule.build;
|
|
1481
|
-
syntaxByKind[rule.open * 2] = rule.close;
|
|
1482
|
-
syntaxByKind[rule.open * 2 + 1] = 0;
|
|
1459
|
+
case "pair": buildByKind[rule.token] = rule.build;
|
|
1483
1460
|
}
|
|
1484
1461
|
}
|
|
1485
1462
|
return {
|
|
1486
1463
|
buildByKind,
|
|
1487
|
-
decorateByKind,
|
|
1488
1464
|
resolve: compileInlineResolver(delimiters),
|
|
1489
|
-
syntaxByKind,
|
|
1490
|
-
textByKind,
|
|
1491
1465
|
tokenize: compileInlineTokenizer(scanRules)
|
|
1492
1466
|
};
|
|
1493
1467
|
}
|
|
1494
1468
|
//#endregion
|
|
1469
|
+
//#region src/profile/features/attributes/block.ts
|
|
1470
|
+
const blockDecorators = [{
|
|
1471
|
+
token: [65, 66],
|
|
1472
|
+
decorate(build) {
|
|
1473
|
+
return (tokenStart, context) => {
|
|
1474
|
+
const result = build(tokenStart, context);
|
|
1475
|
+
if (!result.spread) for (const item of result.children) {
|
|
1476
|
+
const paragraph = !item.spread && item.children.length === 1 && item.children[0].type === "paragraph" ? item.children[0] : void 0;
|
|
1477
|
+
if (paragraph?.attributes) {
|
|
1478
|
+
item.attributes = paragraph.attributes;
|
|
1479
|
+
delete paragraph.attributes;
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
return result;
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
}, {
|
|
1486
|
+
token: 64,
|
|
1487
|
+
decorate(build) {
|
|
1488
|
+
return (tokenStart, context) => {
|
|
1489
|
+
const result = build(tokenStart, context);
|
|
1490
|
+
const paragraph = result.children.length === 1 && result.children[0].type === "paragraph" ? result.children[0] : void 0;
|
|
1491
|
+
if (paragraph?.attributes) {
|
|
1492
|
+
result.attributes = paragraph.attributes;
|
|
1493
|
+
delete paragraph.attributes;
|
|
1494
|
+
}
|
|
1495
|
+
return result;
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
}];
|
|
1499
|
+
//#endregion
|
|
1495
1500
|
//#region src/inline/tokens.ts
|
|
1496
1501
|
function inlineTokenCount(tokens) {
|
|
1497
1502
|
return tokens.length / 4;
|
|
@@ -1511,8 +1516,13 @@ function inlineTokenData(tokens, index) {
|
|
|
1511
1516
|
function setInlineTokenData(tokens, index, data) {
|
|
1512
1517
|
tokens[index * 4 + 3] = data;
|
|
1513
1518
|
}
|
|
1514
|
-
function
|
|
1515
|
-
|
|
1519
|
+
function rewriteInlineTokenTail(tokens, kind, end) {
|
|
1520
|
+
const offset = tokens.length - 4;
|
|
1521
|
+
tokens[offset + 0] = kind;
|
|
1522
|
+
tokens[offset + 2] = end;
|
|
1523
|
+
}
|
|
1524
|
+
function inlineTokenText(source, tokens, index, startPadding = 0, endPadding = startPadding) {
|
|
1525
|
+
return source.slice(inlineTokenStart(tokens, index) + startPadding, inlineTokenEnd(tokens, index) - endPadding);
|
|
1516
1526
|
}
|
|
1517
1527
|
function appendInlineToken(target, kind, start, end, data = 0) {
|
|
1518
1528
|
target.push(kind, start, end, data);
|
|
@@ -1522,60 +1532,50 @@ function copyInlineToken(target, tokens, index) {
|
|
|
1522
1532
|
target.push(tokens[offset], tokens[offset + 1], tokens[offset + 2], tokens[offset + 3]);
|
|
1523
1533
|
}
|
|
1524
1534
|
//#endregion
|
|
1525
|
-
//#region src/profile/
|
|
1526
|
-
const
|
|
1527
|
-
|
|
1528
|
-
"{": "}",
|
|
1529
|
-
"(": ")"
|
|
1530
|
-
};
|
|
1531
|
-
function isAsciiLetter(character) {
|
|
1532
|
-
if (!character) return false;
|
|
1533
|
-
const code = character.charCodeAt(0);
|
|
1535
|
+
//#region src/profile/utils.ts
|
|
1536
|
+
const inlineColonBoundary = /[ \t\n\r\p{sc=Han}\p{sc=Hira}\p{sc=Kana}\p{sc=Hang}\p{P}]/u;
|
|
1537
|
+
function isAsciiLetter(code) {
|
|
1534
1538
|
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
1535
1539
|
}
|
|
1536
|
-
function isAsciiDigit(
|
|
1537
|
-
if (!character) return false;
|
|
1538
|
-
const code = character.charCodeAt(0);
|
|
1540
|
+
function isAsciiDigit(code) {
|
|
1539
1541
|
return code >= 48 && code <= 57;
|
|
1540
1542
|
}
|
|
1541
|
-
function
|
|
1542
|
-
return
|
|
1543
|
+
function isMarkdownWhitespace(code) {
|
|
1544
|
+
return code === 9 || code === 10 || code === 13 || code === 32;
|
|
1543
1545
|
}
|
|
1544
|
-
function
|
|
1545
|
-
if (
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
const character = source[end];
|
|
1549
|
-
if (!isAsciiLetter(character) && !isAsciiDigit(character) && character !== "$" && character !== "_" && character !== "-" && (!block || character !== ".")) break;
|
|
1550
|
-
end++;
|
|
1551
|
-
}
|
|
1552
|
-
return end;
|
|
1546
|
+
function hasInlineColonBoundary(source, start) {
|
|
1547
|
+
if (start <= 0) return true;
|
|
1548
|
+
const previous = source[start - 1];
|
|
1549
|
+
return previous !== ":" && inlineColonBoundary.test(previous);
|
|
1553
1550
|
}
|
|
1554
|
-
function
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1551
|
+
function semanticText(value) {
|
|
1552
|
+
return value.includes("\\") || value.includes("&") ? decodeString(value) : value;
|
|
1553
|
+
}
|
|
1554
|
+
function normalizeAssociationLabel(label) {
|
|
1555
|
+
scan: {
|
|
1556
|
+
let hasUppercase = false;
|
|
1557
|
+
for (let index = 0; index < label.length; index++) {
|
|
1558
|
+
const code = label.charCodeAt(index);
|
|
1559
|
+
if (code === 32) {
|
|
1560
|
+
if (index === 0 || index + 1 === label.length || label.charCodeAt(index + 1) === 32) break scan;
|
|
1561
|
+
continue;
|
|
1563
1562
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1563
|
+
if (code < 32 || code > 126) break scan;
|
|
1564
|
+
if (code >= 65 && code <= 90) hasUppercase = true;
|
|
1566
1565
|
}
|
|
1567
|
-
|
|
1568
|
-
if (previousUpper === false && upper === true) {
|
|
1569
|
-
parts.push(part);
|
|
1570
|
-
part = character;
|
|
1571
|
-
} else if (previousUpper === true && upper === false && part.length > 1) {
|
|
1572
|
-
parts.push(part.slice(0, -1));
|
|
1573
|
-
part = part.at(-1) + character;
|
|
1574
|
-
} else part += character;
|
|
1575
|
-
previousUpper = upper;
|
|
1566
|
+
return hasUppercase ? label.toLowerCase() : label;
|
|
1576
1567
|
}
|
|
1577
|
-
|
|
1578
|
-
|
|
1568
|
+
return label.trim().replace(/[ \t\r\n]+/g, " ").toLowerCase().toUpperCase().toLowerCase();
|
|
1569
|
+
}
|
|
1570
|
+
//#endregion
|
|
1571
|
+
//#region src/profile/features/attributes/shared.ts
|
|
1572
|
+
const brackets = {
|
|
1573
|
+
"[": "]",
|
|
1574
|
+
"{": "}",
|
|
1575
|
+
"(": ")"
|
|
1576
|
+
};
|
|
1577
|
+
function isHorizontalWhitespace(character) {
|
|
1578
|
+
return character === " " || character === " ";
|
|
1579
1579
|
}
|
|
1580
1580
|
function assignAttribute(attributes, name, value) {
|
|
1581
1581
|
if (name === "class" && typeof value === "string" && typeof attributes.class === "string") attributes.class += ` ${value}`;
|
|
@@ -1584,46 +1584,39 @@ function assignAttribute(attributes, name, value) {
|
|
|
1584
1584
|
function mergeAttributes(target, source) {
|
|
1585
1585
|
for (const key in source) assignAttribute(target, key, source[key]);
|
|
1586
1586
|
}
|
|
1587
|
-
function closingBracket(source, start, limit = source.length) {
|
|
1588
|
-
if (source[start] !== "[") return;
|
|
1589
|
-
let depth = 0;
|
|
1590
|
-
for (let offset = start + 1; offset < limit; offset++) if (source[offset] === "\\" && offset + 1 < limit) offset++;
|
|
1591
|
-
else if (source[offset] === "[") depth++;
|
|
1592
|
-
else if (source[offset] === "]") {
|
|
1593
|
-
if (depth === 0) return offset;
|
|
1594
|
-
depth--;
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
1587
|
function scanAttributes(source, start, attributes, limit = source.length) {
|
|
1598
1588
|
if (source[start] !== "{" || source[start + 1] === "{") return;
|
|
1599
1589
|
let offset = start + 1;
|
|
1600
|
-
const
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1590
|
+
const scanUntil = (stops) => {
|
|
1591
|
+
while (offset < limit) {
|
|
1592
|
+
const character = source[offset];
|
|
1593
|
+
if (character === "\n" || character === "\r" || stops.includes(character)) break;
|
|
1594
|
+
offset += character === "\\" && offset + 1 < limit ? 2 : 1;
|
|
1595
|
+
}
|
|
1605
1596
|
};
|
|
1606
|
-
const
|
|
1607
|
-
|
|
1608
|
-
while (offset < limit
|
|
1609
|
-
|
|
1610
|
-
|
|
1597
|
+
const scanQuoted = (quote) => {
|
|
1598
|
+
offset++;
|
|
1599
|
+
while (offset < limit) {
|
|
1600
|
+
const character = source[offset];
|
|
1601
|
+
if (character === "\n" || character === "\r" || character === quote) break;
|
|
1602
|
+
offset += character === "\\" && offset + 1 < limit ? 2 : 1;
|
|
1603
|
+
}
|
|
1604
|
+
if (source[offset] !== quote) return false;
|
|
1611
1605
|
offset++;
|
|
1612
|
-
return
|
|
1606
|
+
return true;
|
|
1613
1607
|
};
|
|
1614
|
-
const
|
|
1615
|
-
const valueStart = offset;
|
|
1608
|
+
const scanBracketed = (close) => {
|
|
1616
1609
|
const stack = [close];
|
|
1617
1610
|
offset++;
|
|
1618
1611
|
while (offset < limit && stack.length > 0) {
|
|
1619
1612
|
const character = source[offset];
|
|
1620
|
-
if (character === "\n" || character === "\r") return;
|
|
1613
|
+
if (character === "\n" || character === "\r") return false;
|
|
1621
1614
|
if (character === "\\" && offset + 1 < limit) {
|
|
1622
1615
|
offset += 2;
|
|
1623
1616
|
continue;
|
|
1624
1617
|
}
|
|
1625
1618
|
if (character === "\"" || character === "'" || character === "`") {
|
|
1626
|
-
if (
|
|
1619
|
+
if (!scanQuoted(character)) return false;
|
|
1627
1620
|
continue;
|
|
1628
1621
|
}
|
|
1629
1622
|
const nestedClose = brackets[character];
|
|
@@ -1631,7 +1624,7 @@ function scanAttributes(source, start, attributes, limit = source.length) {
|
|
|
1631
1624
|
else if (character === stack.at(-1)) stack.pop();
|
|
1632
1625
|
offset++;
|
|
1633
1626
|
}
|
|
1634
|
-
return stack.length === 0
|
|
1627
|
+
return stack.length === 0;
|
|
1635
1628
|
};
|
|
1636
1629
|
while (offset < limit) {
|
|
1637
1630
|
while (isHorizontalWhitespace(source[offset])) offset++;
|
|
@@ -1639,31 +1632,49 @@ function scanAttributes(source, start, attributes, limit = source.length) {
|
|
|
1639
1632
|
const marker = source[offset];
|
|
1640
1633
|
if (marker === "." || marker === "#") {
|
|
1641
1634
|
offset++;
|
|
1642
|
-
const
|
|
1643
|
-
|
|
1644
|
-
if (
|
|
1635
|
+
const valueStart = offset;
|
|
1636
|
+
scanUntil(" #.}");
|
|
1637
|
+
if (offset === valueStart) return;
|
|
1638
|
+
if (attributes) assignAttribute(attributes, marker === "." ? "class" : "id", source.slice(valueStart, offset));
|
|
1645
1639
|
continue;
|
|
1646
1640
|
}
|
|
1647
1641
|
const nameStart = offset;
|
|
1648
|
-
if (source
|
|
1649
|
-
|
|
1642
|
+
if (source.charCodeAt(offset) === 58) offset++;
|
|
1643
|
+
let code = source.charCodeAt(offset);
|
|
1644
|
+
if (!isAsciiLetter(code) && code !== 95) return;
|
|
1650
1645
|
offset++;
|
|
1651
|
-
while (
|
|
1652
|
-
|
|
1646
|
+
while (true) {
|
|
1647
|
+
code = source.charCodeAt(offset);
|
|
1648
|
+
if (!isAsciiLetter(code) && !isAsciiDigit(code) && code !== 95 && code !== 45) break;
|
|
1649
|
+
offset++;
|
|
1650
|
+
}
|
|
1651
|
+
const nameEnd = offset;
|
|
1653
1652
|
while (isHorizontalWhitespace(source[offset])) offset++;
|
|
1654
1653
|
if (source[offset] !== "=") {
|
|
1655
|
-
if (attributes)
|
|
1654
|
+
if (attributes) {
|
|
1655
|
+
const name = source.slice(nameStart, nameEnd);
|
|
1656
|
+
assignAttribute(attributes, source.charCodeAt(nameStart) === 58 ? name : `:${name}`, "true");
|
|
1657
|
+
}
|
|
1656
1658
|
continue;
|
|
1657
1659
|
}
|
|
1658
1660
|
offset++;
|
|
1659
1661
|
while (isHorizontalWhitespace(source[offset])) offset++;
|
|
1660
1662
|
const character = source[offset];
|
|
1661
|
-
let
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1663
|
+
let valueStart = offset;
|
|
1664
|
+
let valueEnd;
|
|
1665
|
+
if (character === "\"" || character === "'" || character === "`") {
|
|
1666
|
+
if (!scanQuoted(character)) return;
|
|
1667
|
+
valueStart++;
|
|
1668
|
+
valueEnd = offset - 1;
|
|
1669
|
+
} else if (brackets[character]) {
|
|
1670
|
+
if (!scanBracketed(brackets[character])) return;
|
|
1671
|
+
valueEnd = offset;
|
|
1672
|
+
} else {
|
|
1673
|
+
scanUntil(" }");
|
|
1674
|
+
valueEnd = offset;
|
|
1675
|
+
if (valueEnd === valueStart) return;
|
|
1676
|
+
}
|
|
1677
|
+
if (attributes) assignAttribute(attributes, source.slice(nameStart, nameEnd), source.slice(valueStart, valueEnd));
|
|
1667
1678
|
}
|
|
1668
1679
|
}
|
|
1669
1680
|
function attributesEnd(source, start, limit = source.length) {
|
|
@@ -1671,37 +1682,11 @@ function attributesEnd(source, start, limit = source.length) {
|
|
|
1671
1682
|
}
|
|
1672
1683
|
function parseAttributes(source, start) {
|
|
1673
1684
|
const attributes = {};
|
|
1674
|
-
|
|
1675
|
-
return
|
|
1676
|
-
attributes,
|
|
1677
|
-
end
|
|
1678
|
-
};
|
|
1685
|
+
scanAttributes(source, start, attributes);
|
|
1686
|
+
return attributes;
|
|
1679
1687
|
}
|
|
1680
1688
|
//#endregion
|
|
1681
|
-
//#region src/profile/features/attributes/
|
|
1682
|
-
const decorateList = (build) => (tokenStart, context) => {
|
|
1683
|
-
const result = build(tokenStart, context);
|
|
1684
|
-
if (!result.spread) for (const item of result.children) {
|
|
1685
|
-
const paragraph = !item.spread && item.children.length === 1 && item.children[0].type === "paragraph" ? item.children[0] : void 0;
|
|
1686
|
-
if (paragraph?.attributes) {
|
|
1687
|
-
item.attributes = paragraph.attributes;
|
|
1688
|
-
delete paragraph.attributes;
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
return result;
|
|
1692
|
-
};
|
|
1693
|
-
const decorateBlockquote = (build) => (tokenStart, context) => {
|
|
1694
|
-
const result = build(tokenStart, context);
|
|
1695
|
-
const paragraph = result.children.length === 1 && result.children[0].type === "paragraph" ? result.children[0] : void 0;
|
|
1696
|
-
if (paragraph?.attributes) {
|
|
1697
|
-
result.attributes = paragraph.attributes;
|
|
1698
|
-
delete paragraph.attributes;
|
|
1699
|
-
}
|
|
1700
|
-
return result;
|
|
1701
|
-
};
|
|
1702
|
-
function isMarkdownWhitespace(code) {
|
|
1703
|
-
return code === 9 || code === 10 || code === 13 || code === 32;
|
|
1704
|
-
}
|
|
1689
|
+
//#region src/profile/features/attributes/inline.ts
|
|
1705
1690
|
function hasVisibleText(source, start, end) {
|
|
1706
1691
|
for (let offset = start; offset < end; offset++) if (!isMarkdownWhitespace(source.charCodeAt(offset))) return true;
|
|
1707
1692
|
return false;
|
|
@@ -1709,72 +1694,60 @@ function hasVisibleText(source, start, end) {
|
|
|
1709
1694
|
function attributeEndAt(source, start) {
|
|
1710
1695
|
return source[start + 1] === "{" || source[start - 1] === "{" || source[start - 1] === "$" ? void 0 : attributesEnd(source, start);
|
|
1711
1696
|
}
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
if (end === void 0) return -1;
|
|
1715
|
-
if (tokens.length === 0 && !hasVisibleText(source, 0, start)) {
|
|
1716
|
-
let textEnd = end;
|
|
1717
|
-
while (true) {
|
|
1718
|
-
let next = textEnd;
|
|
1719
|
-
while (source.charCodeAt(next) === 9 || source.charCodeAt(next) === 32) next++;
|
|
1720
|
-
const nextEnd = source.charCodeAt(next) === 123 ? attributeEndAt(source, next) : void 0;
|
|
1721
|
-
if (nextEnd === void 0) break;
|
|
1722
|
-
textEnd = nextEnd;
|
|
1723
|
-
}
|
|
1724
|
-
return textEnd;
|
|
1725
|
-
}
|
|
1726
|
-
const previous = inlineTokenCount(tokens) - 1;
|
|
1727
|
-
const previousEnd = previous >= 0 ? inlineTokenEnd(tokens, previous) : 0;
|
|
1728
|
-
if (previousEnd < start && (previous >= 0 && inlineTokenKind(tokens, previous) === 40 || hasVisibleText(source, previousEnd, start))) appendInlineToken(tokens, 1, previousEnd, start);
|
|
1729
|
-
appendInlineToken(tokens, 40, start, end, start > 0 && isMarkdownWhitespace(source.charCodeAt(start - 1)) ? 1 : 0);
|
|
1730
|
-
let next = end;
|
|
1731
|
-
while (isMarkdownWhitespace(source.charCodeAt(next))) next++;
|
|
1732
|
-
if (next === source.length) for (let index = inlineTokenCount(tokens) - 1; index >= 0; index--) {
|
|
1733
|
-
const kind = inlineTokenKind(tokens, index);
|
|
1734
|
-
if (kind === 1 && !hasVisibleText(source, inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index))) continue;
|
|
1735
|
-
if (kind !== 40) break;
|
|
1736
|
-
setInlineTokenData(tokens, index, inlineTokenData(tokens, index) | 2);
|
|
1737
|
-
}
|
|
1738
|
-
return end;
|
|
1739
|
-
}
|
|
1697
|
+
//#endregion
|
|
1698
|
+
//#region src/profile/features/attributes/index.ts
|
|
1740
1699
|
const feature$18 = {
|
|
1741
|
-
block: { decorators:
|
|
1742
|
-
{
|
|
1743
|
-
rule: 6,
|
|
1744
|
-
decorate: decorateList
|
|
1745
|
-
},
|
|
1746
|
-
{
|
|
1747
|
-
rule: 7,
|
|
1748
|
-
decorate: decorateList
|
|
1749
|
-
},
|
|
1750
|
-
{
|
|
1751
|
-
rule: 1,
|
|
1752
|
-
decorate: decorateBlockquote
|
|
1753
|
-
}
|
|
1754
|
-
] },
|
|
1700
|
+
block: { decorators: blockDecorators },
|
|
1755
1701
|
inline: {
|
|
1756
|
-
|
|
1702
|
+
scans: [{
|
|
1757
1703
|
marker: 123,
|
|
1758
|
-
scan
|
|
1704
|
+
scan(source, start, tokens) {
|
|
1705
|
+
const end = attributeEndAt(source, start);
|
|
1706
|
+
if (end === void 0) return -1;
|
|
1707
|
+
if (tokens.length === 0 && !hasVisibleText(source, 0, start)) {
|
|
1708
|
+
let textEnd = end;
|
|
1709
|
+
while (true) {
|
|
1710
|
+
let next = textEnd;
|
|
1711
|
+
while (source.charCodeAt(next) === 9 || source.charCodeAt(next) === 32) next++;
|
|
1712
|
+
const nextEnd = source.charCodeAt(next) === 123 ? attributeEndAt(source, next) : void 0;
|
|
1713
|
+
if (nextEnd === void 0) break;
|
|
1714
|
+
textEnd = nextEnd;
|
|
1715
|
+
}
|
|
1716
|
+
return textEnd;
|
|
1717
|
+
}
|
|
1718
|
+
const previous = inlineTokenCount(tokens) - 1;
|
|
1719
|
+
const previousEnd = previous >= 0 ? inlineTokenEnd(tokens, previous) : 0;
|
|
1720
|
+
if (previousEnd < start && (previous >= 0 && inlineTokenKind(tokens, previous) === 256 || hasVisibleText(source, previousEnd, start))) appendInlineToken(tokens, 64, previousEnd, start);
|
|
1721
|
+
appendInlineToken(tokens, 256, start, end, start > 0 && isMarkdownWhitespace(source.charCodeAt(start - 1)) ? 1 : 0);
|
|
1722
|
+
let next = end;
|
|
1723
|
+
while (isMarkdownWhitespace(source.charCodeAt(next))) next++;
|
|
1724
|
+
if (next === source.length) for (let index = inlineTokenCount(tokens) - 1; index >= 0; index--) {
|
|
1725
|
+
const kind = inlineTokenKind(tokens, index);
|
|
1726
|
+
if (kind === 64 && !hasVisibleText(source, inlineTokenStart(tokens, index), inlineTokenEnd(tokens, index))) continue;
|
|
1727
|
+
if (kind !== 256) break;
|
|
1728
|
+
setInlineTokenData(tokens, index, inlineTokenData(tokens, index) | 2);
|
|
1729
|
+
}
|
|
1730
|
+
return end;
|
|
1731
|
+
}
|
|
1759
1732
|
}],
|
|
1760
|
-
|
|
1733
|
+
builds: [{
|
|
1761
1734
|
kind: "decorate",
|
|
1762
|
-
token:
|
|
1735
|
+
token: 256,
|
|
1763
1736
|
apply(tokenIndex, sourceSpan, context, target) {
|
|
1764
1737
|
const previous = target.children.at(-1);
|
|
1738
|
+
if (!previous) return false;
|
|
1765
1739
|
const parsed = parseAttributes(context.view.text, inlineTokenStart(context.tokens, tokenIndex));
|
|
1766
|
-
if (!previous || !parsed) return false;
|
|
1767
1740
|
const flags = inlineTokenData(context.tokens, tokenIndex);
|
|
1768
1741
|
const terminal = Boolean(flags & 2);
|
|
1769
1742
|
const detached = Boolean(flags & 1);
|
|
1770
1743
|
if (terminal && (detached || previous.type === "text" || target.attributes !== void 0)) {
|
|
1771
|
-
if (target.attributes) mergeAttributes(target.attributes, parsed
|
|
1772
|
-
else target.attributes = parsed
|
|
1744
|
+
if (target.attributes) mergeAttributes(target.attributes, parsed);
|
|
1745
|
+
else target.attributes = parsed;
|
|
1773
1746
|
return true;
|
|
1774
1747
|
}
|
|
1775
1748
|
const attributes = previous.attributes;
|
|
1776
|
-
if (attributes) mergeAttributes(attributes, parsed
|
|
1777
|
-
else previous.attributes = parsed
|
|
1749
|
+
if (attributes) mergeAttributes(attributes, parsed);
|
|
1750
|
+
else previous.attributes = parsed;
|
|
1778
1751
|
previous.position.end = context.locator.locationAt(sourceSpan.end);
|
|
1779
1752
|
return true;
|
|
1780
1753
|
}
|
|
@@ -1784,7 +1757,7 @@ const feature$18 = {
|
|
|
1784
1757
|
//#endregion
|
|
1785
1758
|
//#region src/profile/features/binding.ts
|
|
1786
1759
|
const feature$17 = { inline: {
|
|
1787
|
-
|
|
1760
|
+
scans: [{
|
|
1788
1761
|
marker: 123,
|
|
1789
1762
|
scan(source, start, tokens) {
|
|
1790
1763
|
if (source.charCodeAt(start + 1) !== 123) return -1;
|
|
@@ -1794,13 +1767,13 @@ const feature$17 = { inline: {
|
|
|
1794
1767
|
const valueEnd = separator < 0 || separator > close ? close : separator;
|
|
1795
1768
|
if (!source.slice(start + 2, valueEnd).trim()) return -1;
|
|
1796
1769
|
const end = close + 2;
|
|
1797
|
-
appendInlineToken(tokens,
|
|
1770
|
+
appendInlineToken(tokens, 135, start, end, valueEnd - start);
|
|
1798
1771
|
return end;
|
|
1799
1772
|
}
|
|
1800
1773
|
}],
|
|
1801
|
-
|
|
1774
|
+
builds: [{
|
|
1802
1775
|
kind: "leaf",
|
|
1803
|
-
token:
|
|
1776
|
+
token: 135,
|
|
1804
1777
|
build(tokenIndex, sourceSpan, context) {
|
|
1805
1778
|
const source = context.view.text;
|
|
1806
1779
|
const tokenStart = inlineTokenStart(context.tokens, tokenIndex);
|
|
@@ -1838,13 +1811,8 @@ function blockQuoteOffset(source, lines, index, markerOffset) {
|
|
|
1838
1811
|
};
|
|
1839
1812
|
}
|
|
1840
1813
|
const feature$16 = { block: {
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
syntax: {
|
|
1844
|
-
kind: "block",
|
|
1845
|
-
open: 3,
|
|
1846
|
-
close: 4
|
|
1847
|
-
},
|
|
1814
|
+
builds: [{
|
|
1815
|
+
token: 64,
|
|
1848
1816
|
build(tokenStart, context) {
|
|
1849
1817
|
const tokens = context.structure.tokens;
|
|
1850
1818
|
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
@@ -1870,24 +1838,25 @@ const feature$16 = { block: {
|
|
|
1870
1838
|
return true;
|
|
1871
1839
|
},
|
|
1872
1840
|
start(source, lines, start, contentOffset, out, context) {
|
|
1873
|
-
const
|
|
1874
|
-
|
|
1875
|
-
let
|
|
1841
|
+
const firstMarker = blockQuoteOffset(source, lines, start, contentOffset);
|
|
1842
|
+
const quoteLines = context.createLineView(lines, start, firstMarker.offset, firstMarker.prefixColumns);
|
|
1843
|
+
let index = start + 1;
|
|
1844
|
+
let lazyParagraph = context.endsWithParagraphLeaf(source, quoteLines, 0);
|
|
1876
1845
|
for (; index < lines.length; index++) {
|
|
1877
|
-
const markerOffset =
|
|
1846
|
+
const markerOffset = lineIndentOffset(source, lines, index);
|
|
1878
1847
|
const marker = blockQuoteOffset(source, lines, index, markerOffset);
|
|
1879
1848
|
if (marker) {
|
|
1880
1849
|
quoteLines.pushFrom(lines, index, marker.offset, marker.prefixColumns);
|
|
1881
1850
|
lazyParagraph = context.endsWithParagraphLeaf(source, quoteLines, quoteLines.length - 1);
|
|
1882
1851
|
continue;
|
|
1883
1852
|
}
|
|
1884
|
-
if (!lazyParagraph ||
|
|
1853
|
+
if (!lazyParagraph || markerOffset < 0 && isBlankLine(source, lines, index) || !lines.lazy(index) && context.startsInterruptingBlock(source, lines, index, markerOffset)) break;
|
|
1885
1854
|
quoteLines.pushLazy(lines, index);
|
|
1886
1855
|
}
|
|
1887
|
-
out.push(
|
|
1856
|
+
out.push(64, contentOffset, contentOffset + 1);
|
|
1888
1857
|
context.scanLines(source, quoteLines, out);
|
|
1889
1858
|
const end = quoteLines.next(quoteLines.length - 1);
|
|
1890
|
-
out.push(
|
|
1859
|
+
out.push(192, end, end);
|
|
1891
1860
|
return index;
|
|
1892
1861
|
}
|
|
1893
1862
|
}]
|
|
@@ -1907,12 +1876,8 @@ function isThematicBreak(source, lines, index, contentOffset) {
|
|
|
1907
1876
|
}
|
|
1908
1877
|
const feature$15 = {
|
|
1909
1878
|
block: {
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
syntax: {
|
|
1913
|
-
kind: "leaf",
|
|
1914
|
-
token: 2
|
|
1915
|
-
},
|
|
1879
|
+
builds: [{
|
|
1880
|
+
token: 256,
|
|
1916
1881
|
build(tokenStart, context) {
|
|
1917
1882
|
return {
|
|
1918
1883
|
type: "thematicBreak",
|
|
@@ -1931,26 +1896,20 @@ const feature$15 = {
|
|
|
1931
1896
|
},
|
|
1932
1897
|
start(source, lines, start, contentOffset, out) {
|
|
1933
1898
|
if (!isThematicBreak(source, lines, start, contentOffset)) return;
|
|
1934
|
-
out.push(
|
|
1899
|
+
out.push(256, contentOffset, lines.end(start));
|
|
1935
1900
|
return start + 1;
|
|
1936
1901
|
}
|
|
1937
1902
|
}]
|
|
1938
1903
|
},
|
|
1939
|
-
inline: {
|
|
1904
|
+
inline: { builds: [{
|
|
1940
1905
|
kind: "leaf",
|
|
1941
|
-
token:
|
|
1906
|
+
token: 128,
|
|
1942
1907
|
build(tokenIndex, sourceSpan) {
|
|
1943
1908
|
return {
|
|
1944
1909
|
type: "break",
|
|
1945
1910
|
position: sourceSpan
|
|
1946
1911
|
};
|
|
1947
1912
|
}
|
|
1948
|
-
}, {
|
|
1949
|
-
kind: "text",
|
|
1950
|
-
token: 5,
|
|
1951
|
-
build() {
|
|
1952
|
-
return "\n";
|
|
1953
|
-
}
|
|
1954
1913
|
}] }
|
|
1955
1914
|
};
|
|
1956
1915
|
//#endregion
|
|
@@ -1988,15 +1947,20 @@ function closesFence(source, lines, index, fence) {
|
|
|
1988
1947
|
while (source.charCodeAt(offset) === fence.marker) offset++;
|
|
1989
1948
|
if (offset < markerEnd) return false;
|
|
1990
1949
|
const lineEnd = lines.end(index);
|
|
1991
|
-
|
|
1992
|
-
return offset === lineEnd;
|
|
1950
|
+
return skipLineWhitespace(source, offset, lineEnd) === lineEnd;
|
|
1993
1951
|
}
|
|
1994
|
-
function fencedBlock(source, lines, index, fence, closed) {
|
|
1995
|
-
let infoStart = fence.offset + fence.length;
|
|
1952
|
+
function fencedBlock(source, lines, index, end, fence, closed) {
|
|
1996
1953
|
const lineEnd = lines.end(index);
|
|
1997
|
-
|
|
1954
|
+
const infoStart = skipLineWhitespace(source, fence.offset + fence.length, lineEnd);
|
|
1955
|
+
let content;
|
|
1956
|
+
if (lines.physicallyContiguous()) {
|
|
1957
|
+
const contentStart = lines.next(index);
|
|
1958
|
+
const lastContentLine = end - (closed ? 2 : 1);
|
|
1959
|
+
content = source.slice(contentStart, lastContentLine > index ? lines.end(lastContentLine) : contentStart);
|
|
1960
|
+
}
|
|
1998
1961
|
return {
|
|
1999
1962
|
closed,
|
|
1963
|
+
content,
|
|
2000
1964
|
indent: fence.indent,
|
|
2001
1965
|
info: source.slice(infoStart, lineEnd),
|
|
2002
1966
|
markerOffset: fence.offset - lines.start(index)
|
|
@@ -2013,23 +1977,28 @@ const sourceColumnFenceTabIndent = [
|
|
|
2013
1977
|
/^(?<![\u2028\u2029]) {0,2}\t/gm
|
|
2014
1978
|
];
|
|
2015
1979
|
function normalizedFenceContent(source, block) {
|
|
2016
|
-
|
|
2017
|
-
if (
|
|
2018
|
-
|
|
2019
|
-
|
|
1980
|
+
let content = source;
|
|
1981
|
+
if (block.content === void 0) {
|
|
1982
|
+
const contentStart = source.indexOf("\n") + 1;
|
|
1983
|
+
if (!contentStart) return "";
|
|
1984
|
+
const limit = block.closed ? source.lastIndexOf("\n", source.length - 2) + 1 : source.length;
|
|
1985
|
+
content = source.slice(contentStart, lineContentEnd(source, contentStart, limit));
|
|
1986
|
+
}
|
|
2020
1987
|
return block.indent ? content.replace(fenceSpaceIndent[block.indent - 1], "") : content;
|
|
2021
1988
|
}
|
|
2022
1989
|
function sourceColumnFenceContent(source, block) {
|
|
2023
|
-
let
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
limit =
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
1990
|
+
let content = block.content;
|
|
1991
|
+
if (content === void 0) {
|
|
1992
|
+
let contentStart = 0;
|
|
1993
|
+
while (contentStart < source.length && source[contentStart] !== "\n" && source[contentStart] !== "\r") contentStart++;
|
|
1994
|
+
if (contentStart < source.length) contentStart += source[contentStart] === "\r" && source[contentStart + 1] === "\n" ? 2 : 1;
|
|
1995
|
+
let limit = source.length;
|
|
1996
|
+
if (block.closed) {
|
|
1997
|
+
limit = lineContentEnd(source, contentStart, limit);
|
|
1998
|
+
while (limit > contentStart && source[limit - 1] !== "\n" && source[limit - 1] !== "\r") limit--;
|
|
1999
|
+
}
|
|
2000
|
+
content = source.slice(contentStart, lineContentEnd(source, contentStart, limit));
|
|
2001
|
+
}
|
|
2033
2002
|
if (block.indent) {
|
|
2034
2003
|
if (content.includes(" ")) content = content.replace(sourceColumnFenceTabIndent[block.indent - 1], " ");
|
|
2035
2004
|
content = content.replace(fenceSpaceIndent[block.indent - 1], "");
|
|
@@ -2037,64 +2006,6 @@ function sourceColumnFenceContent(source, block) {
|
|
|
2037
2006
|
return content;
|
|
2038
2007
|
}
|
|
2039
2008
|
//#endregion
|
|
2040
|
-
//#region src/profile/features/text.ts
|
|
2041
|
-
const entity = /&(?:#x[0-9A-F]{1,6}|#\d{1,7}|[A-Z][A-Z0-9]{0,30});/iy;
|
|
2042
|
-
function isAsciiPunctuation(code) {
|
|
2043
|
-
return code >= 33 && code <= 47 || code >= 58 && code <= 64 || code >= 91 && code <= 96 || code >= 123 && code <= 126;
|
|
2044
|
-
}
|
|
2045
|
-
function semanticText(value) {
|
|
2046
|
-
return value.includes("\\") || value.includes("&") ? decodeString(value) : value;
|
|
2047
|
-
}
|
|
2048
|
-
const buildInlineText = (tokenIndex, context) => {
|
|
2049
|
-
return inlineTokenText(context.view.text, context.tokens, tokenIndex);
|
|
2050
|
-
};
|
|
2051
|
-
const buildDecodedInlineText = (tokenIndex, context) => {
|
|
2052
|
-
return semanticText(inlineTokenText(context.view.text, context.tokens, tokenIndex));
|
|
2053
|
-
};
|
|
2054
|
-
const feature$14 = { inline: {
|
|
2055
|
-
scan: [{
|
|
2056
|
-
marker: 38,
|
|
2057
|
-
scan(source, start, tokens) {
|
|
2058
|
-
const matchEnd = matchInlinePatternEnd(entity, source, start);
|
|
2059
|
-
if (matchEnd < 0) return start + 1;
|
|
2060
|
-
appendInlineToken(tokens, 3, start, matchEnd);
|
|
2061
|
-
return matchEnd;
|
|
2062
|
-
}
|
|
2063
|
-
}, {
|
|
2064
|
-
marker: 92,
|
|
2065
|
-
scan(source, start, tokens) {
|
|
2066
|
-
const next = source.charCodeAt(start + 1);
|
|
2067
|
-
if (next === 10 || next === 13) {
|
|
2068
|
-
appendInlineToken(tokens, 4, start, start + 1);
|
|
2069
|
-
return start + 1;
|
|
2070
|
-
}
|
|
2071
|
-
if (isAsciiPunctuation(next)) {
|
|
2072
|
-
const end = start + 2;
|
|
2073
|
-
appendInlineToken(tokens, 2, start, end);
|
|
2074
|
-
return end;
|
|
2075
|
-
}
|
|
2076
|
-
return start + (next === 32 || next === 9 ? 2 : 1);
|
|
2077
|
-
}
|
|
2078
|
-
}],
|
|
2079
|
-
build: [
|
|
2080
|
-
{
|
|
2081
|
-
kind: "text",
|
|
2082
|
-
token: 1,
|
|
2083
|
-
build: buildInlineText
|
|
2084
|
-
},
|
|
2085
|
-
{
|
|
2086
|
-
kind: "text",
|
|
2087
|
-
token: 2,
|
|
2088
|
-
build: buildDecodedInlineText
|
|
2089
|
-
},
|
|
2090
|
-
{
|
|
2091
|
-
kind: "text",
|
|
2092
|
-
token: 3,
|
|
2093
|
-
build: buildDecodedInlineText
|
|
2094
|
-
}
|
|
2095
|
-
]
|
|
2096
|
-
} };
|
|
2097
|
-
//#endregion
|
|
2098
2009
|
//#region src/profile/features/code.ts
|
|
2099
2010
|
const codeFenceRule = {
|
|
2100
2011
|
alternateMarker: 126,
|
|
@@ -2105,19 +2016,14 @@ const codeFenceRule = {
|
|
|
2105
2016
|
function codeFenceAt(source, lines, index, markerOffset) {
|
|
2106
2017
|
return fenceAt$1(source, lines, index, codeFenceRule, markerOffset);
|
|
2107
2018
|
}
|
|
2108
|
-
const feature$
|
|
2019
|
+
const feature$14 = {
|
|
2109
2020
|
block: {
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
syntax: {
|
|
2113
|
-
kind: "leaf",
|
|
2114
|
-
token: 19
|
|
2115
|
-
},
|
|
2021
|
+
builds: [{
|
|
2022
|
+
token: 257,
|
|
2116
2023
|
build(tokenStart, context) {
|
|
2117
2024
|
const tokens = context.structure.tokens;
|
|
2118
|
-
const source = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
|
|
2119
2025
|
const block = tokens.value(tokenStart);
|
|
2120
|
-
|
|
2026
|
+
const source = context.locator.normalizeLineEndings(block.content ?? tokens.text(context.source, tokenStart));
|
|
2121
2027
|
const rawInfo = semanticText(block.info);
|
|
2122
2028
|
const langEnd = rawInfo.search(/[ \t]/);
|
|
2123
2029
|
const lang = rawInfo ? langEnd < 0 ? rawInfo : rawInfo.slice(0, langEnd) : null;
|
|
@@ -2131,22 +2037,16 @@ const feature$13 = {
|
|
|
2131
2037
|
};
|
|
2132
2038
|
}
|
|
2133
2039
|
}, {
|
|
2134
|
-
|
|
2135
|
-
syntax: {
|
|
2136
|
-
kind: "leaf",
|
|
2137
|
-
token: 20
|
|
2138
|
-
},
|
|
2040
|
+
token: 258,
|
|
2139
2041
|
build(tokenStart, context) {
|
|
2140
2042
|
const tokens = context.structure.tokens;
|
|
2141
2043
|
const offset = tokens.start(tokenStart);
|
|
2142
2044
|
const contentLength = tokens.value(tokenStart);
|
|
2143
|
-
const lines = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart)).split("\n").map((line) => removeIndent(line, 4));
|
|
2144
|
-
while (lines.length && /^[ \t]*$/.test(lines[lines.length - 1])) lines.pop();
|
|
2145
2045
|
return {
|
|
2146
2046
|
type: "code",
|
|
2147
2047
|
lang: null,
|
|
2148
2048
|
meta: null,
|
|
2149
|
-
value:
|
|
2049
|
+
value: context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart)).replace(/^(?: {0,3}\t| {4}| {1,3}$)/gm, "").replace(/\n(?:[ \t]*\n)*[ \t]*$/, ""),
|
|
2150
2050
|
position: context.locator.positionAt(offset, offset + contentLength)
|
|
2151
2051
|
};
|
|
2152
2052
|
}
|
|
@@ -2155,11 +2055,11 @@ const feature$13 = {
|
|
|
2155
2055
|
codes: [-1],
|
|
2156
2056
|
start(source, lines, start, _contentOffset, out) {
|
|
2157
2057
|
let end = start + 1;
|
|
2158
|
-
while (end < lines.length &&
|
|
2058
|
+
while (end < lines.length && lineIndentOffset(source, lines, end) < 0) end++;
|
|
2159
2059
|
let contentEnd = end;
|
|
2160
|
-
while (contentEnd > start &&
|
|
2060
|
+
while (contentEnd > start && isBlankLine(source, lines, contentEnd - 1)) contentEnd--;
|
|
2161
2061
|
const contentLength = lines.end(contentEnd - 1) - lines.start(start);
|
|
2162
|
-
appendLogicalToken(out,
|
|
2062
|
+
appendLogicalToken(out, 258, source, lines, start, end, contentLength);
|
|
2163
2063
|
return end;
|
|
2164
2064
|
}
|
|
2165
2065
|
}, {
|
|
@@ -2174,13 +2074,13 @@ const feature$13 = {
|
|
|
2174
2074
|
while (end < lines.length && !closesFence(source, lines, end, fence)) end++;
|
|
2175
2075
|
const closed = end < lines.length;
|
|
2176
2076
|
if (end < lines.length) end++;
|
|
2177
|
-
appendLogicalToken(out,
|
|
2077
|
+
appendLogicalToken(out, 257, source, lines, start, end, fencedBlock(source, lines, start, end, fence, closed));
|
|
2178
2078
|
return end;
|
|
2179
2079
|
}
|
|
2180
2080
|
}]
|
|
2181
2081
|
},
|
|
2182
2082
|
inline: {
|
|
2183
|
-
|
|
2083
|
+
scans: [{
|
|
2184
2084
|
marker: 96,
|
|
2185
2085
|
scan(source, start, tokens) {
|
|
2186
2086
|
if (source.charCodeAt(start - 1) === 96) return start + 1;
|
|
@@ -2192,7 +2092,7 @@ const feature$13 = {
|
|
|
2192
2092
|
if (offset < 0) break;
|
|
2193
2093
|
const closeEnd = inlineMarkerRunEnd(source, offset);
|
|
2194
2094
|
if (closeEnd - offset === markerLength) {
|
|
2195
|
-
appendInlineToken(tokens,
|
|
2095
|
+
appendInlineToken(tokens, 129, start, closeEnd, markerLength);
|
|
2196
2096
|
return closeEnd;
|
|
2197
2097
|
}
|
|
2198
2098
|
offset = closeEnd;
|
|
@@ -2200,17 +2100,16 @@ const feature$13 = {
|
|
|
2200
2100
|
return start + 1;
|
|
2201
2101
|
}
|
|
2202
2102
|
}],
|
|
2203
|
-
|
|
2103
|
+
builds: [{
|
|
2204
2104
|
kind: "leaf",
|
|
2205
|
-
token:
|
|
2105
|
+
token: 129,
|
|
2206
2106
|
build: (tokenIndex, sourceSpan, context) => {
|
|
2207
|
-
const text = inlineTokenText(context.view.text, context.tokens, tokenIndex);
|
|
2208
2107
|
const markerLength = inlineTokenData(context.tokens, tokenIndex);
|
|
2209
|
-
let value = context.locator.normalizeLineEndings(text.
|
|
2108
|
+
let value = context.locator.normalizeLineEndings(inlineTokenText(context.view.text, context.tokens, tokenIndex, markerLength));
|
|
2210
2109
|
if (/^[ \n]/.test(value) && /[ \n]$/.test(value) && /[^ \n]/.test(value)) value = value.slice(1, -1);
|
|
2211
2110
|
return {
|
|
2212
2111
|
type: "inlineCode",
|
|
2213
|
-
value: context.
|
|
2112
|
+
value: context.tableCell ? value.replace(/\\\|/g, "|") : value,
|
|
2214
2113
|
position: sourceSpan
|
|
2215
2114
|
};
|
|
2216
2115
|
}
|
|
@@ -2228,9 +2127,6 @@ function createInlineOutput(children, cursor) {
|
|
|
2228
2127
|
trailingSpaces: 0
|
|
2229
2128
|
};
|
|
2230
2129
|
}
|
|
2231
|
-
function lineEndingStart(source, lineStart) {
|
|
2232
|
-
return source.charCodeAt(lineStart - 1) === 10 && source.charCodeAt(lineStart - 2) === 13 ? lineStart - 2 : lineStart - 1;
|
|
2233
|
-
}
|
|
2234
2130
|
function trimTrailingText(output) {
|
|
2235
2131
|
const text = output.lastText;
|
|
2236
2132
|
const removed = text ? output.trailingSpaces : 0;
|
|
@@ -2275,62 +2171,65 @@ function finishText(output, context) {
|
|
|
2275
2171
|
}
|
|
2276
2172
|
}
|
|
2277
2173
|
function appendGap(output, context, start, end) {
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
const
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
const viewLineStart = inlineTokenData(context.tokens, tokenIndex);
|
|
2288
|
-
const viewLineEndingStart = lineEndingStart(context.view.text, viewLineStart);
|
|
2289
|
-
if (viewStart > cursor) {
|
|
2290
|
-
if (viewLineEndingStart > cursor) appendGap(output, context, cursor, viewLineEndingStart);
|
|
2291
|
-
}
|
|
2292
|
-
const previous = output.children.at(-1);
|
|
2293
|
-
if (previous?.type === "break") {
|
|
2294
|
-
previous.position.end = context.locator.locationAt(context.view.mapPoint(viewLineStart - 1) + 1);
|
|
2295
|
-
return;
|
|
2296
|
-
}
|
|
2297
|
-
viewStart = viewLineEndingStart;
|
|
2298
|
-
trimTrailingText(output);
|
|
2299
|
-
}
|
|
2300
|
-
const sourceSpan = context.view.mapSpan(viewStart, viewEnd);
|
|
2301
|
-
if (textToken) appendText(output, build(tokenIndex, context), sourceSpan.start, sourceSpan.end, context);
|
|
2302
|
-
else {
|
|
2303
|
-
finishText(output, context);
|
|
2304
|
-
output.children.push(build(tokenIndex, context.locator.positionAt(sourceSpan.start, sourceSpan.end), context));
|
|
2305
|
-
output.lastText = void 0;
|
|
2306
|
-
}
|
|
2174
|
+
appendText(output, context.view.text.slice(start, end), context.view.mapOffset(start), context.view.mapEnd(end), context);
|
|
2175
|
+
}
|
|
2176
|
+
function appendLeafToken(output, context, token, start, end, build) {
|
|
2177
|
+
if (start > output.cursor) appendGap(output, context, output.cursor, start);
|
|
2178
|
+
const sourceStart = context.view.mapOffset(start);
|
|
2179
|
+
const sourceEnd = start === end ? sourceStart : context.view.mapEnd(end);
|
|
2180
|
+
finishText(output, context);
|
|
2181
|
+
output.children.push(build(token, context.locator.positionAt(sourceStart, sourceEnd), context));
|
|
2182
|
+
output.lastText = void 0;
|
|
2307
2183
|
}
|
|
2308
2184
|
function appendRange(startToken, endToken, profile, context, output, closeKind = 0) {
|
|
2309
2185
|
let index = startToken;
|
|
2310
2186
|
while (index < endToken) {
|
|
2311
2187
|
const kind = inlineTokenKind(context.tokens, index);
|
|
2188
|
+
if (kind === 67) {
|
|
2189
|
+
const endingStart = inlineTokenStart(context.tokens, index);
|
|
2190
|
+
const lineStart = inlineTokenData(context.tokens, index);
|
|
2191
|
+
const contentStart = inlineTokenEnd(context.tokens, index);
|
|
2192
|
+
if (endingStart > output.cursor) appendGap(output, context, output.cursor, endingStart);
|
|
2193
|
+
const previous = output.children.at(-1);
|
|
2194
|
+
if (previous?.type === "break") previous.position.end = context.locator.locationAt(context.view.mapOffset(lineStart - 1) + 1);
|
|
2195
|
+
else {
|
|
2196
|
+
trimTrailingText(output);
|
|
2197
|
+
appendText(output, "\n", context.view.mapOffset(endingStart), context.view.mapEnd(contentStart), context);
|
|
2198
|
+
}
|
|
2199
|
+
output.cursor = contentStart;
|
|
2200
|
+
index++;
|
|
2201
|
+
continue;
|
|
2202
|
+
}
|
|
2312
2203
|
if (kind === closeKind) break;
|
|
2313
|
-
const syntaxOffset = kind * 2;
|
|
2314
|
-
const semanticCloseKind = profile.syntaxByKind[syntaxOffset];
|
|
2315
2204
|
const build = profile.buildByKind[kind];
|
|
2316
2205
|
const childStart = inlineTokenStart(context.tokens, index);
|
|
2317
|
-
if (
|
|
2206
|
+
if (kind < 192) {
|
|
2207
|
+
const childEnd = inlineTokenEnd(context.tokens, index);
|
|
2208
|
+
if (kind < 128) {
|
|
2209
|
+
if (childStart > output.cursor) appendGap(output, context, output.cursor, childStart);
|
|
2210
|
+
const sourceStart = context.view.mapOffset(childStart);
|
|
2211
|
+
appendText(output, build(index, context), sourceStart, childStart === childEnd ? sourceStart : context.view.mapEnd(childEnd), context);
|
|
2212
|
+
} else appendLeafToken(output, context, index, childStart, childEnd, build);
|
|
2213
|
+
output.cursor = childEnd;
|
|
2214
|
+
index++;
|
|
2215
|
+
continue;
|
|
2216
|
+
}
|
|
2217
|
+
if (kind < 256) {
|
|
2318
2218
|
if (childStart > output.cursor) appendGap(output, context, output.cursor, childStart);
|
|
2319
2219
|
finishText(output, context);
|
|
2320
|
-
index = appendSemantic(index, endToken, profile, context, output, build,
|
|
2220
|
+
index = appendSemantic(index, endToken, profile, context, output, build, kind + 1);
|
|
2321
2221
|
continue;
|
|
2322
2222
|
}
|
|
2323
2223
|
const childEnd = inlineTokenEnd(context.tokens, index);
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
appendToken(output, context, index, childStart, childEnd, build, profile.textByKind[kind], kind === 5);
|
|
2224
|
+
finishText(output, context);
|
|
2225
|
+
const sourceStart = context.view.mapOffset(childStart);
|
|
2226
|
+
const sourceSpan = {
|
|
2227
|
+
start: sourceStart,
|
|
2228
|
+
end: childStart === childEnd ? sourceStart : context.view.mapEnd(childEnd)
|
|
2229
|
+
};
|
|
2230
|
+
if (build(index, sourceSpan, context, output)) {
|
|
2231
|
+
const previous = output.children.at(-1);
|
|
2232
|
+
output.lastText = previous?.type === "text" ? previous : void 0;
|
|
2334
2233
|
output.cursor = childEnd;
|
|
2335
2234
|
}
|
|
2336
2235
|
index++;
|
|
@@ -2342,38 +2241,43 @@ function appendRange(startToken, endToken, profile, context, output, closeKind =
|
|
|
2342
2241
|
finishText(output, context);
|
|
2343
2242
|
return index;
|
|
2344
2243
|
}
|
|
2345
|
-
function appendSemantic(openToken, endToken, profile, context, output, build, closeKind
|
|
2244
|
+
function appendSemantic(openToken, endToken, profile, context, output, build, closeKind) {
|
|
2346
2245
|
const childStart = inlineTokenStart(context.tokens, openToken);
|
|
2347
|
-
const positionStart = context.locator.locationAt(context.view.
|
|
2348
|
-
let closeToken = openToken;
|
|
2349
|
-
let next = openToken + 1;
|
|
2246
|
+
const positionStart = context.locator.locationAt(context.view.mapOffset(childStart));
|
|
2350
2247
|
const children = [];
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
closeToken = appendRange(next, endToken, profile, context, childOutput, closeKind);
|
|
2354
|
-
}
|
|
2248
|
+
const childOutput = createInlineOutput(children, inlineTokenEnd(context.tokens, openToken));
|
|
2249
|
+
const closeToken = appendRange(openToken + 1, endToken, profile, context, childOutput, closeKind);
|
|
2355
2250
|
const childEnd = inlineTokenEnd(context.tokens, closeToken);
|
|
2356
|
-
const sourceSpan = context.view.mapSpan(childStart, childEnd);
|
|
2357
2251
|
const value = build(openToken, closeToken, {
|
|
2358
2252
|
start: positionStart,
|
|
2359
|
-
end: context.locator.locationAt(
|
|
2253
|
+
end: context.locator.locationAt(context.view.mapEnd(childEnd))
|
|
2360
2254
|
}, children, context);
|
|
2361
2255
|
output.children.push(value);
|
|
2362
2256
|
output.lastText = void 0;
|
|
2363
2257
|
output.cursor = childEnd;
|
|
2364
2258
|
return closeToken + 1;
|
|
2365
2259
|
}
|
|
2366
|
-
function buildInlineFragment(tokenStart,
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2260
|
+
function buildInlineFragment(tokenStart, tableCell, context) {
|
|
2261
|
+
let tokens;
|
|
2262
|
+
let view;
|
|
2263
|
+
if (context.cursor) {
|
|
2264
|
+
const region = context.cursor.take(tokenStart);
|
|
2265
|
+
if (!region) return { children: [] };
|
|
2266
|
+
tokens = region.tokens;
|
|
2267
|
+
view = region.view;
|
|
2268
|
+
} else {
|
|
2269
|
+
const blockTokens = context.structure.tokens;
|
|
2270
|
+
if (blockTokens.kind(tokenStart + 1) !== 1) return { children: [] };
|
|
2271
|
+
view = new SourceView(context.source, blockTokens, tokenStart, blockTokens.nodeLength(tokenStart));
|
|
2272
|
+
tokens = context.profile.resolve(view.text, context.profile.tokenize(view.text), blockTokens);
|
|
2273
|
+
}
|
|
2370
2274
|
const inlineContext = context.inlineContext ??= {
|
|
2371
|
-
blockRule,
|
|
2372
2275
|
locator: context.locator,
|
|
2276
|
+
tableCell,
|
|
2373
2277
|
tokens,
|
|
2374
2278
|
view
|
|
2375
2279
|
};
|
|
2376
|
-
inlineContext.
|
|
2280
|
+
inlineContext.tableCell = tableCell;
|
|
2377
2281
|
inlineContext.tokens = tokens;
|
|
2378
2282
|
inlineContext.view = view;
|
|
2379
2283
|
const result = createInlineOutput([], 0);
|
|
@@ -2394,39 +2298,33 @@ function buildInlineFragment(tokenStart, blockRule, context) {
|
|
|
2394
2298
|
function frontmatterFenceAt(source, lines, index, marker) {
|
|
2395
2299
|
const start = lines.start(index);
|
|
2396
2300
|
if (source[start] !== marker || source[start + 1] !== marker || source[start + 2] !== marker) return false;
|
|
2397
|
-
|
|
2398
|
-
return
|
|
2301
|
+
const end = lines.end(index);
|
|
2302
|
+
return skipLineWhitespace(source, start + 3, end) === end;
|
|
2399
2303
|
}
|
|
2400
|
-
const
|
|
2304
|
+
const buildYamlBlock = (tokenStart, context) => {
|
|
2401
2305
|
const tokens = context.structure.tokens;
|
|
2402
2306
|
const text = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
|
|
2403
2307
|
const contentStart = text.indexOf("\n") + 1;
|
|
2404
2308
|
const closingEnd = text.endsWith("\n") ? text.length - 1 : text.length;
|
|
2405
2309
|
const closingStart = text.lastIndexOf("\n", closingEnd - 1) + 1;
|
|
2406
|
-
let value = text.slice(contentStart, closingStart);
|
|
2407
|
-
if (value.endsWith("\n")) value = value.slice(0, -1);
|
|
2408
2310
|
return {
|
|
2409
2311
|
type: "yaml",
|
|
2410
|
-
value,
|
|
2312
|
+
value: text.slice(contentStart, Math.max(contentStart, closingStart - 1)),
|
|
2411
2313
|
position: leafBlockPosition(tokenStart, context)
|
|
2412
2314
|
};
|
|
2413
2315
|
};
|
|
2414
|
-
function feature$
|
|
2316
|
+
function feature$13(marker) {
|
|
2415
2317
|
return { block: {
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
kind: "leaf",
|
|
2420
|
-
token: 27
|
|
2421
|
-
},
|
|
2422
|
-
build: buildFrontmatter
|
|
2318
|
+
builds: [{
|
|
2319
|
+
token: 260,
|
|
2320
|
+
build: buildYamlBlock
|
|
2423
2321
|
}],
|
|
2424
2322
|
starts: [{
|
|
2425
2323
|
codes: [marker.charCodeAt(0)],
|
|
2426
2324
|
start(source, lines, start, contentOffset, out, context) {
|
|
2427
2325
|
if (lines.start(start) !== 0 || !frontmatterFenceAt(source, lines, start, marker)) return;
|
|
2428
2326
|
for (let end = start + 1; end < lines.length; end++) if (frontmatterFenceAt(source, lines, end, marker)) {
|
|
2429
|
-
appendLogicalToken(out,
|
|
2327
|
+
appendLogicalToken(out, 260, source, lines, start, end + 1);
|
|
2430
2328
|
return end + 1;
|
|
2431
2329
|
}
|
|
2432
2330
|
context.retainLookahead(lines.next(lines.length - 1));
|
|
@@ -2435,10 +2333,49 @@ function feature$12(marker) {
|
|
|
2435
2333
|
} };
|
|
2436
2334
|
}
|
|
2437
2335
|
//#endregion
|
|
2336
|
+
//#region src/profile/features/component/shared.ts
|
|
2337
|
+
function componentNameEnd(source, start, block) {
|
|
2338
|
+
let code = source.charCodeAt(start);
|
|
2339
|
+
if (!isAsciiLetter(code) && code !== 36) return;
|
|
2340
|
+
let end = start + 1;
|
|
2341
|
+
while (end < source.length) {
|
|
2342
|
+
code = source.charCodeAt(end);
|
|
2343
|
+
if (!isAsciiLetter(code) && !isAsciiDigit(code) && code !== 36 && code !== 95 && code !== 45 && (!block || code !== 46)) break;
|
|
2344
|
+
end++;
|
|
2345
|
+
}
|
|
2346
|
+
return end;
|
|
2347
|
+
}
|
|
2348
|
+
function normalizeComponentName(value) {
|
|
2349
|
+
let result = "";
|
|
2350
|
+
let partLength = 0;
|
|
2351
|
+
let previousUpper;
|
|
2352
|
+
for (let index = 0; index < value.length; index++) {
|
|
2353
|
+
const character = value[index];
|
|
2354
|
+
const code = value.charCodeAt(index);
|
|
2355
|
+
if (code === 45 || code === 95 || code === 47 || code === 46) {
|
|
2356
|
+
partLength = 0;
|
|
2357
|
+
previousUpper = void 0;
|
|
2358
|
+
continue;
|
|
2359
|
+
}
|
|
2360
|
+
const upper = isAsciiLetter(code) ? code <= 90 : void 0;
|
|
2361
|
+
const next = value.charCodeAt(index + 1);
|
|
2362
|
+
if (result && (partLength === 0 || upper === true && (previousUpper === false || next >= 97 && next <= 122))) result += "-";
|
|
2363
|
+
result += character;
|
|
2364
|
+
partLength++;
|
|
2365
|
+
previousUpper = upper;
|
|
2366
|
+
}
|
|
2367
|
+
return result.toLowerCase();
|
|
2368
|
+
}
|
|
2369
|
+
//#endregion
|
|
2438
2370
|
//#region src/profile/features/component/block.ts
|
|
2439
|
-
function
|
|
2440
|
-
|
|
2441
|
-
|
|
2371
|
+
function closingBracket(source, start, limit) {
|
|
2372
|
+
let depth = 0;
|
|
2373
|
+
for (let offset = start + 1; offset < limit; offset++) if (source[offset] === "\\" && offset + 1 < limit) offset++;
|
|
2374
|
+
else if (source[offset] === "[") depth++;
|
|
2375
|
+
else if (source[offset] === "]") {
|
|
2376
|
+
if (depth === 0) return offset;
|
|
2377
|
+
depth--;
|
|
2378
|
+
}
|
|
2442
2379
|
}
|
|
2443
2380
|
function lineValue(source, lines, index) {
|
|
2444
2381
|
const offset = lineIndentOffset(source, lines, index);
|
|
@@ -2463,7 +2400,7 @@ function slotOpeningAt(source, lines, index, contentOffset) {
|
|
|
2463
2400
|
const nameEnd = componentNameEnd(source, contentOffset + 1, true);
|
|
2464
2401
|
const lineEnd = lines.end(index);
|
|
2465
2402
|
if (nameEnd === void 0 || nameEnd > lineEnd) return;
|
|
2466
|
-
let offset =
|
|
2403
|
+
let offset = skipLineWhitespace(source, nameEnd, lineEnd);
|
|
2467
2404
|
let attributesStart;
|
|
2468
2405
|
let parsedAttributesEnd;
|
|
2469
2406
|
if (source[offset] === "{") {
|
|
@@ -2472,7 +2409,7 @@ function slotOpeningAt(source, lines, index, contentOffset) {
|
|
|
2472
2409
|
attributesStart = offset;
|
|
2473
2410
|
offset = parsedAttributesEnd;
|
|
2474
2411
|
}
|
|
2475
|
-
if (
|
|
2412
|
+
if (skipLineWhitespace(source, offset, lineEnd) !== lineEnd) return;
|
|
2476
2413
|
return {
|
|
2477
2414
|
attributesEnd: parsedAttributesEnd,
|
|
2478
2415
|
attributesStart,
|
|
@@ -2486,10 +2423,10 @@ function blockOpeningAt(source, lines, index, contentOffset, shorthand) {
|
|
|
2486
2423
|
const fenceSize = offset - contentOffset;
|
|
2487
2424
|
if (shorthand ? fenceSize !== 1 : fenceSize < 2) return;
|
|
2488
2425
|
const lineEnd = lines.end(index);
|
|
2489
|
-
if (!shorthand) offset =
|
|
2426
|
+
if (!shorthand) offset = skipLineWhitespace(source, offset, lineEnd);
|
|
2490
2427
|
const nameEnd = componentNameEnd(source, offset, true);
|
|
2491
2428
|
if (nameEnd === void 0 || nameEnd > lineEnd) return;
|
|
2492
|
-
offset =
|
|
2429
|
+
offset = skipLineWhitespace(source, nameEnd, lineEnd);
|
|
2493
2430
|
let labelStart;
|
|
2494
2431
|
let labelEnd;
|
|
2495
2432
|
if (source[offset] === "[") {
|
|
@@ -2497,7 +2434,7 @@ function blockOpeningAt(source, lines, index, contentOffset, shorthand) {
|
|
|
2497
2434
|
if (close === void 0) return;
|
|
2498
2435
|
labelStart = offset;
|
|
2499
2436
|
labelEnd = close + 1;
|
|
2500
|
-
offset =
|
|
2437
|
+
offset = skipLineWhitespace(source, labelEnd, lineEnd);
|
|
2501
2438
|
}
|
|
2502
2439
|
let attributesStart;
|
|
2503
2440
|
let parsedAttributesEnd;
|
|
@@ -2507,7 +2444,7 @@ function blockOpeningAt(source, lines, index, contentOffset, shorthand) {
|
|
|
2507
2444
|
attributesStart = offset;
|
|
2508
2445
|
offset = parsedAttributesEnd;
|
|
2509
2446
|
}
|
|
2510
|
-
if (
|
|
2447
|
+
if (skipLineWhitespace(source, offset, lineEnd) !== lineEnd) return;
|
|
2511
2448
|
return {
|
|
2512
2449
|
attributesEnd: parsedAttributesEnd,
|
|
2513
2450
|
attributesStart,
|
|
@@ -2521,7 +2458,7 @@ function fenceAt(source, lines, index, size, contentOffset) {
|
|
|
2521
2458
|
let offset = contentOffset;
|
|
2522
2459
|
while (source[offset] === ":") offset++;
|
|
2523
2460
|
const lineEnd = lines.end(index);
|
|
2524
|
-
if (offset - contentOffset !== size ||
|
|
2461
|
+
if (offset - contentOffset !== size || skipLineWhitespace(source, offset, lineEnd) !== lineEnd) return;
|
|
2525
2462
|
return contentOffset;
|
|
2526
2463
|
}
|
|
2527
2464
|
function blockClose(source, lines, start, opening) {
|
|
@@ -2568,15 +2505,11 @@ function nextSlot(source, lines, start, end) {
|
|
|
2568
2505
|
if (nested) index = blockClose(source, lines, index, nested)?.index ?? index;
|
|
2569
2506
|
}
|
|
2570
2507
|
}
|
|
2571
|
-
function emitSlotOpening(opening, out) {
|
|
2572
|
-
out.push(44, opening.offset, opening.nameEnd);
|
|
2573
|
-
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(42, opening.attributesStart, opening.attributesEnd);
|
|
2574
|
-
}
|
|
2575
2508
|
function emitComponentBody(source, lines, start, end, closingOffset, out, context) {
|
|
2576
2509
|
let cursor = start;
|
|
2577
2510
|
const yamlEnd = cursor < end ? yamlPropsEnd(source, lines, cursor, end) : void 0;
|
|
2578
2511
|
if (yamlEnd !== void 0) {
|
|
2579
|
-
appendLogicalToken(out,
|
|
2512
|
+
appendLogicalToken(out, 262, source, lines, cursor, yamlEnd);
|
|
2580
2513
|
cursor = yamlEnd;
|
|
2581
2514
|
}
|
|
2582
2515
|
let slot = nextSlot(source, lines, cursor, end);
|
|
@@ -2588,21 +2521,23 @@ function emitComponentBody(source, lines, start, end, closingOffset, out, contex
|
|
|
2588
2521
|
while (slot) {
|
|
2589
2522
|
const following = nextSlot(source, lines, slot.index + 1, end);
|
|
2590
2523
|
const next = following?.index ?? end;
|
|
2591
|
-
|
|
2524
|
+
const opening = slot.opening;
|
|
2525
|
+
out.push(71, opening.offset, opening.nameEnd);
|
|
2526
|
+
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(3, opening.attributesStart, opening.attributesEnd);
|
|
2592
2527
|
context.scanLines(source, lines.slice(slot.index + 1, next), out);
|
|
2593
2528
|
const slotEnd = following ? following.opening.offset : closingOffset;
|
|
2594
|
-
out.push(
|
|
2529
|
+
out.push(204, slotEnd, slotEnd);
|
|
2595
2530
|
slot = following;
|
|
2596
2531
|
}
|
|
2597
2532
|
}
|
|
2598
2533
|
function emitOpening(contentOffset, opening, out) {
|
|
2599
|
-
out.push(
|
|
2534
|
+
out.push(70, contentOffset, opening.nameEnd);
|
|
2600
2535
|
if (opening.labelStart !== void 0 && opening.labelEnd !== void 0) {
|
|
2601
|
-
out.push(
|
|
2536
|
+
out.push(161, opening.labelStart, opening.labelStart + 1);
|
|
2602
2537
|
if (opening.labelEnd > opening.labelStart + 2) out.push(1, opening.labelStart + 1, opening.labelEnd - 1);
|
|
2603
|
-
out.push(
|
|
2538
|
+
out.push(203, opening.labelEnd - 1, opening.labelEnd);
|
|
2604
2539
|
}
|
|
2605
|
-
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(
|
|
2540
|
+
if (opening.attributesStart !== void 0 && opening.attributesEnd !== void 0) out.push(3, opening.attributesStart, opening.attributesEnd);
|
|
2606
2541
|
}
|
|
2607
2542
|
const buildBlockLabel = (tokenStart, context) => {
|
|
2608
2543
|
const tokens = context.structure.tokens;
|
|
@@ -2610,7 +2545,7 @@ const buildBlockLabel = (tokenStart, context) => {
|
|
|
2610
2545
|
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
2611
2546
|
return {
|
|
2612
2547
|
type: "paragraph",
|
|
2613
|
-
children: buildInlineFragment(tokenStart,
|
|
2548
|
+
children: buildInlineFragment(tokenStart, false, context).children,
|
|
2614
2549
|
position: {
|
|
2615
2550
|
start,
|
|
2616
2551
|
end: context.locator.locationAt(tokens.end(close))
|
|
@@ -2624,7 +2559,7 @@ function createBlockStart(shorthand) {
|
|
|
2624
2559
|
if (shorthand) {
|
|
2625
2560
|
emitOpening(contentOffset, opening, out);
|
|
2626
2561
|
const lineEnd = lines.end(start);
|
|
2627
|
-
out.push(
|
|
2562
|
+
out.push(202, lineEnd, lineEnd);
|
|
2628
2563
|
return start + 1;
|
|
2629
2564
|
}
|
|
2630
2565
|
const closing = blockClose(source, lines, start, opening);
|
|
@@ -2634,53 +2569,33 @@ function createBlockStart(shorthand) {
|
|
|
2634
2569
|
}
|
|
2635
2570
|
emitOpening(contentOffset, opening, out);
|
|
2636
2571
|
emitComponentBody(source, lines, start + 1, closing.index, closing.offset, out, context);
|
|
2637
|
-
out.push(
|
|
2572
|
+
out.push(202, closing.offset, lines.end(closing.index));
|
|
2638
2573
|
return closing.index + 1;
|
|
2639
2574
|
};
|
|
2640
2575
|
}
|
|
2641
|
-
const
|
|
2576
|
+
const blockBuilds$2 = [
|
|
2642
2577
|
{
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
kind: "leaf",
|
|
2646
|
-
token: 43
|
|
2647
|
-
},
|
|
2648
|
-
build: buildFrontmatter
|
|
2578
|
+
token: 262,
|
|
2579
|
+
build: buildYamlBlock
|
|
2649
2580
|
},
|
|
2650
2581
|
{
|
|
2651
|
-
|
|
2652
|
-
syntax: {
|
|
2653
|
-
kind: "frame",
|
|
2654
|
-
open: 40,
|
|
2655
|
-
close: 41
|
|
2656
|
-
},
|
|
2657
|
-
inlineContent: true,
|
|
2658
|
-
build: buildBlockLabel
|
|
2659
|
-
},
|
|
2660
|
-
{
|
|
2661
|
-
rule: 19,
|
|
2662
|
-
syntax: {
|
|
2663
|
-
kind: "block",
|
|
2664
|
-
open: 38,
|
|
2665
|
-
close: 39
|
|
2666
|
-
},
|
|
2582
|
+
token: 70,
|
|
2667
2583
|
build(tokenStart, context) {
|
|
2668
2584
|
const tokens = context.structure.tokens;
|
|
2669
2585
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
2670
2586
|
let openingToken = tokenStart + 1;
|
|
2671
|
-
const label = tokens.kind(openingToken) ===
|
|
2587
|
+
const label = tokens.kind(openingToken) === 161 ? openingToken : void 0;
|
|
2672
2588
|
if (label !== void 0) openingToken += tokens.nodeLength(label);
|
|
2673
|
-
const attributesToken = tokens.kind(openingToken) ===
|
|
2589
|
+
const attributesToken = tokens.kind(openingToken) === 3 ? openingToken++ : void 0;
|
|
2674
2590
|
const parsed = attributesToken !== void 0 ? parseAttributes(context.source, tokens.start(attributesToken)) : void 0;
|
|
2675
2591
|
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
2676
|
-
|
|
2677
|
-
if (label) children
|
|
2678
|
-
children.push(...buildBlockChildren(tokenStart, context));
|
|
2592
|
+
let children = buildBlockChildren(tokenStart, context);
|
|
2593
|
+
if (label) children = [buildBlockLabel(label, context), ...children];
|
|
2679
2594
|
const opening = tokens.text(context.source, tokenStart);
|
|
2680
2595
|
return {
|
|
2681
2596
|
type: "blockComponent",
|
|
2682
2597
|
name: normalizeComponentName(opening.slice(opening.lastIndexOf(":") + 1).trim()),
|
|
2683
|
-
attributes: parsed
|
|
2598
|
+
attributes: parsed ?? {},
|
|
2684
2599
|
position: {
|
|
2685
2600
|
start,
|
|
2686
2601
|
end: context.locator.locationAt(tokens.end(close))
|
|
@@ -2690,16 +2605,11 @@ const blockRules$2 = [
|
|
|
2690
2605
|
}
|
|
2691
2606
|
},
|
|
2692
2607
|
{
|
|
2693
|
-
|
|
2694
|
-
syntax: {
|
|
2695
|
-
kind: "block",
|
|
2696
|
-
open: 44,
|
|
2697
|
-
close: 45
|
|
2698
|
-
},
|
|
2608
|
+
token: 71,
|
|
2699
2609
|
build(tokenStart, context) {
|
|
2700
2610
|
const tokens = context.structure.tokens;
|
|
2701
2611
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
2702
|
-
const attributesToken = tokens.kind(tokenStart + 1) ===
|
|
2612
|
+
const attributesToken = tokens.kind(tokenStart + 1) === 3 ? tokenStart + 1 : void 0;
|
|
2703
2613
|
const parsed = attributesToken !== void 0 ? parseAttributes(context.source, tokens.start(attributesToken)) : void 0;
|
|
2704
2614
|
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
2705
2615
|
const children = buildBlockChildren(tokenStart, context);
|
|
@@ -2707,7 +2617,7 @@ const blockRules$2 = [
|
|
|
2707
2617
|
type: "blockComponent",
|
|
2708
2618
|
name: "template",
|
|
2709
2619
|
attributes: {
|
|
2710
|
-
...parsed
|
|
2620
|
+
...parsed,
|
|
2711
2621
|
name: normalizeComponentName(tokens.text(context.source, tokenStart).slice(1).trim())
|
|
2712
2622
|
},
|
|
2713
2623
|
children,
|
|
@@ -2729,85 +2639,86 @@ const blockStarts$2 = [{
|
|
|
2729
2639
|
codes: [58],
|
|
2730
2640
|
start: createBlockStart(true)
|
|
2731
2641
|
}];
|
|
2732
|
-
//#endregion
|
|
2733
|
-
//#region src/profile/features/component/inline.ts
|
|
2734
|
-
const
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
}
|
|
2642
|
+
//#endregion
|
|
2643
|
+
//#region src/profile/features/component/inline.ts
|
|
2644
|
+
const inlineScans = [{
|
|
2645
|
+
marker: 58,
|
|
2646
|
+
scan(source, start, tokens) {
|
|
2647
|
+
const end = hasInlineColonBoundary(source, start) ? componentNameEnd(source, start + 1, false) : void 0;
|
|
2648
|
+
if (end === void 0) return -1;
|
|
2649
|
+
appendInlineToken(tokens, 137, start, end);
|
|
2650
|
+
return end;
|
|
2651
|
+
}
|
|
2652
|
+
}];
|
|
2653
|
+
const buildInlineComponent = (open, close, sourceSpan, children, context) => {
|
|
2654
|
+
const nameEnd = inlineTokenEnd(context.tokens, open) - (inlineTokenKind(context.tokens, open) === 208 ? 1 : 0);
|
|
2655
|
+
return {
|
|
2656
|
+
type: "inlineComponent",
|
|
2657
|
+
name: normalizeComponentName(context.view.text.slice(inlineTokenStart(context.tokens, open) + 1, nameEnd)),
|
|
2658
|
+
attributes: {},
|
|
2659
|
+
children,
|
|
2660
|
+
position: sourceSpan
|
|
2661
|
+
};
|
|
2662
|
+
};
|
|
2743
2663
|
//#endregion
|
|
2744
2664
|
//#region src/profile/features/component/index.ts
|
|
2745
|
-
const feature$
|
|
2665
|
+
const feature$12 = {
|
|
2746
2666
|
block: {
|
|
2747
|
-
|
|
2667
|
+
builds: blockBuilds$2,
|
|
2748
2668
|
starts: blockStarts$2
|
|
2749
2669
|
},
|
|
2750
2670
|
inline: {
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
close: 36,
|
|
2778
|
-
build(open, close, sourceSpan, children) {
|
|
2779
|
-
return {
|
|
2780
|
-
type: "inlineComponent",
|
|
2781
|
-
name: "span",
|
|
2782
|
-
attributes: {},
|
|
2783
|
-
children,
|
|
2784
|
-
position: sourceSpan
|
|
2785
|
-
};
|
|
2671
|
+
scans: inlineScans,
|
|
2672
|
+
builds: [
|
|
2673
|
+
{
|
|
2674
|
+
kind: "leaf",
|
|
2675
|
+
token: 137,
|
|
2676
|
+
build(token, sourceSpan, context) {
|
|
2677
|
+
return buildInlineComponent(token, token, sourceSpan, [], context);
|
|
2678
|
+
}
|
|
2679
|
+
},
|
|
2680
|
+
{
|
|
2681
|
+
kind: "pair",
|
|
2682
|
+
token: 208,
|
|
2683
|
+
build: buildInlineComponent
|
|
2684
|
+
},
|
|
2685
|
+
{
|
|
2686
|
+
kind: "pair",
|
|
2687
|
+
token: 206,
|
|
2688
|
+
build(open, close, sourceSpan, children) {
|
|
2689
|
+
return {
|
|
2690
|
+
type: "inlineComponent",
|
|
2691
|
+
name: "span",
|
|
2692
|
+
attributes: {},
|
|
2693
|
+
children,
|
|
2694
|
+
position: sourceSpan
|
|
2695
|
+
};
|
|
2696
|
+
}
|
|
2786
2697
|
}
|
|
2787
|
-
|
|
2698
|
+
]
|
|
2788
2699
|
}
|
|
2789
2700
|
};
|
|
2790
2701
|
//#endregion
|
|
2791
2702
|
//#region src/profile/features/emoji/index.ts
|
|
2792
2703
|
function isShortcodeCharacter(code) {
|
|
2793
|
-
return code
|
|
2704
|
+
return isAsciiLetter(code) || isAsciiDigit(code) || code === 43 || code === 45 || code === 95;
|
|
2794
2705
|
}
|
|
2795
|
-
const feature$
|
|
2796
|
-
|
|
2706
|
+
const feature$11 = { inline: {
|
|
2707
|
+
scans: [{
|
|
2797
2708
|
marker: 58,
|
|
2798
2709
|
scan(source, start, tokens) {
|
|
2799
|
-
if (!
|
|
2710
|
+
if (!hasInlineColonBoundary(source, start)) return -1;
|
|
2800
2711
|
let end = start + 1;
|
|
2801
2712
|
while (isShortcodeCharacter(source.charCodeAt(end))) end++;
|
|
2802
2713
|
if (end === start + 1 || source.charCodeAt(end) !== 58) return -1;
|
|
2803
2714
|
end++;
|
|
2804
|
-
appendInlineToken(tokens,
|
|
2715
|
+
appendInlineToken(tokens, 136, start, end);
|
|
2805
2716
|
return end;
|
|
2806
2717
|
}
|
|
2807
2718
|
}],
|
|
2808
|
-
|
|
2719
|
+
builds: [{
|
|
2809
2720
|
kind: "leaf",
|
|
2810
|
-
token:
|
|
2721
|
+
token: 136,
|
|
2811
2722
|
build(tokenIndex, sourceSpan, context) {
|
|
2812
2723
|
return {
|
|
2813
2724
|
type: "emoji",
|
|
@@ -2818,29 +2729,8 @@ const feature$10 = { inline: {
|
|
|
2818
2729
|
}]
|
|
2819
2730
|
} };
|
|
2820
2731
|
//#endregion
|
|
2821
|
-
//#region src/profile/utils.ts
|
|
2822
|
-
function normalizeAssociationLabel(label) {
|
|
2823
|
-
scan: {
|
|
2824
|
-
let hasUppercase = false;
|
|
2825
|
-
for (let index = 0; index < label.length; index++) {
|
|
2826
|
-
const code = label.charCodeAt(index);
|
|
2827
|
-
if (code === 32) {
|
|
2828
|
-
if (index === 0 || index + 1 === label.length || label.charCodeAt(index + 1) === 32) break scan;
|
|
2829
|
-
continue;
|
|
2830
|
-
}
|
|
2831
|
-
if (code < 32 || code > 126) break scan;
|
|
2832
|
-
if (code >= 65 && code <= 90) hasUppercase = true;
|
|
2833
|
-
}
|
|
2834
|
-
return hasUppercase ? label.toLowerCase() : label;
|
|
2835
|
-
}
|
|
2836
|
-
return label.trim().replace(/[ \t\r\n]+/g, " ").toLowerCase().toUpperCase().toLowerCase();
|
|
2837
|
-
}
|
|
2838
|
-
//#endregion
|
|
2839
2732
|
//#region src/profile/features/footnote/shared.ts
|
|
2840
2733
|
const footnoteDefinitionPrefix = "footnote\0";
|
|
2841
|
-
function isLabelWhitespace(code) {
|
|
2842
|
-
return code === 32 || code === 9 || code === 10 || code === 13;
|
|
2843
|
-
}
|
|
2844
2734
|
function footnoteLabelAt(source, start, limit) {
|
|
2845
2735
|
if (source.charCodeAt(start) !== 91 || source.charCodeAt(start + 1) !== 94) return;
|
|
2846
2736
|
const labelStart = start + 2;
|
|
@@ -2848,9 +2738,9 @@ function footnoteLabelAt(source, start, limit) {
|
|
|
2848
2738
|
let length = 0;
|
|
2849
2739
|
while (offset < limit) {
|
|
2850
2740
|
const code = source.charCodeAt(offset);
|
|
2851
|
-
if (
|
|
2741
|
+
if (isMarkdownWhitespace(code)) return;
|
|
2852
2742
|
if (code === 92 && offset + 1 < limit) {
|
|
2853
|
-
if (
|
|
2743
|
+
if (isMarkdownWhitespace(source.charCodeAt(offset + 1))) return;
|
|
2854
2744
|
offset += 2;
|
|
2855
2745
|
length += 2;
|
|
2856
2746
|
} else if (code === 93) {
|
|
@@ -2878,37 +2768,22 @@ function definitionAt(source, lines, index, markerStart) {
|
|
|
2878
2768
|
const label = footnoteLabelAt(source, markerStart, lineEnd);
|
|
2879
2769
|
if (!label || source.charCodeAt(label.end) !== 58) return;
|
|
2880
2770
|
const markerEnd = label.end + 1;
|
|
2881
|
-
|
|
2882
|
-
while (contentOffset < lineEnd) {
|
|
2883
|
-
const code = source.charCodeAt(contentOffset);
|
|
2884
|
-
if (code !== 32 && code !== 9) break;
|
|
2885
|
-
contentOffset++;
|
|
2886
|
-
}
|
|
2771
|
+
const contentOffset = skipLineWhitespace(source, markerEnd, lineEnd);
|
|
2887
2772
|
return {
|
|
2888
2773
|
...label,
|
|
2889
2774
|
contentOffset,
|
|
2890
2775
|
markerEnd
|
|
2891
2776
|
};
|
|
2892
2777
|
}
|
|
2893
|
-
function definitionFields(tokens, token) {
|
|
2894
|
-
const fields = tokens.value(token);
|
|
2895
|
-
if (tokens.kind(token) !== 25 || !fields) throw new Error("Expected FootnoteDefinitionOpen token to contain parsed fields");
|
|
2896
|
-
return fields;
|
|
2897
|
-
}
|
|
2898
2778
|
//#endregion
|
|
2899
2779
|
//#region src/profile/features/footnote/index.ts
|
|
2900
|
-
const feature$
|
|
2780
|
+
const feature$10 = {
|
|
2901
2781
|
block: {
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
syntax: {
|
|
2905
|
-
kind: "block",
|
|
2906
|
-
open: 25,
|
|
2907
|
-
close: 26
|
|
2908
|
-
},
|
|
2782
|
+
builds: [{
|
|
2783
|
+
token: 68,
|
|
2909
2784
|
build(tokenStart, context) {
|
|
2910
2785
|
const tokens = context.structure.tokens;
|
|
2911
|
-
const fields =
|
|
2786
|
+
const fields = tokens.value(tokenStart);
|
|
2912
2787
|
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
2913
2788
|
const children = buildBlockChildren(tokenStart, context);
|
|
2914
2789
|
return {
|
|
@@ -2937,20 +2812,18 @@ const feature$9 = {
|
|
|
2937
2812
|
start(source, lines, start, contentOffset, out, context) {
|
|
2938
2813
|
const match = definitionAt(source, lines, start, contentOffset);
|
|
2939
2814
|
if (!match) return;
|
|
2940
|
-
const definitionLines =
|
|
2941
|
-
definitionLines.pushFrom(lines, start, match.contentOffset, 0);
|
|
2815
|
+
const definitionLines = context.createLineView(lines, start, match.contentOffset, 0);
|
|
2942
2816
|
let index = start + 1;
|
|
2943
2817
|
let lazyParagraph = context.endsWithParagraphLeaf(source, definitionLines, 0);
|
|
2944
2818
|
while (index < lines.length) {
|
|
2945
|
-
|
|
2819
|
+
const line = definitionLines.pushAfterColumns(source, lines, index, 4);
|
|
2820
|
+
if (line === 0) {
|
|
2946
2821
|
definitionLines.pushFrom(lines, index);
|
|
2947
2822
|
lazyParagraph = false;
|
|
2948
2823
|
index++;
|
|
2949
2824
|
continue;
|
|
2950
2825
|
}
|
|
2951
|
-
|
|
2952
|
-
if (content) {
|
|
2953
|
-
definitionLines.pushFrom(lines, index, content.offset, content.prefixColumns);
|
|
2826
|
+
if (line === 1) {
|
|
2954
2827
|
lazyParagraph = context.endsWithParagraphLeaf(source, definitionLines, definitionLines.length - 1);
|
|
2955
2828
|
index++;
|
|
2956
2829
|
continue;
|
|
@@ -2959,8 +2832,8 @@ const feature$9 = {
|
|
|
2959
2832
|
definitionLines.pushLazy(lines, index);
|
|
2960
2833
|
index++;
|
|
2961
2834
|
}
|
|
2962
|
-
while (definitionLines.length > 0 &&
|
|
2963
|
-
out.push(
|
|
2835
|
+
while (definitionLines.length > 0 && isBlankLine(source, definitionLines, definitionLines.length - 1)) definitionLines.pop();
|
|
2836
|
+
out.push(68, contentOffset, match.markerEnd, {
|
|
2964
2837
|
definitionKey: match.definitionKey,
|
|
2965
2838
|
value: {
|
|
2966
2839
|
label: match.label,
|
|
@@ -2969,16 +2842,16 @@ const feature$9 = {
|
|
|
2969
2842
|
});
|
|
2970
2843
|
context.scanLines(source, definitionLines, out);
|
|
2971
2844
|
const end = definitionLines.length > 0 ? definitionLines.next(definitionLines.length - 1) : match.markerEnd;
|
|
2972
|
-
out.push(
|
|
2845
|
+
out.push(199, end, end);
|
|
2973
2846
|
return index;
|
|
2974
2847
|
}
|
|
2975
2848
|
}]
|
|
2976
2849
|
},
|
|
2977
|
-
inline: {
|
|
2850
|
+
inline: { builds: [{
|
|
2978
2851
|
kind: "leaf",
|
|
2979
|
-
token:
|
|
2852
|
+
token: 133,
|
|
2980
2853
|
build(tokenIndex, sourceSpan, context) {
|
|
2981
|
-
const label = inlineTokenText(context.view.text, context.tokens, tokenIndex
|
|
2854
|
+
const label = inlineTokenText(context.view.text, context.tokens, tokenIndex, 2, 1);
|
|
2982
2855
|
return {
|
|
2983
2856
|
type: "footnoteReference",
|
|
2984
2857
|
identifier: normalizeAssociationLabel(label),
|
|
@@ -2989,16 +2862,72 @@ const feature$9 = {
|
|
|
2989
2862
|
}] }
|
|
2990
2863
|
};
|
|
2991
2864
|
//#endregion
|
|
2865
|
+
//#region src/profile/features/text.ts
|
|
2866
|
+
const entity = /&(?:#x[0-9A-F]{1,6}|#\d{1,7}|[A-Z][A-Z0-9]{0,30});/iy;
|
|
2867
|
+
function isAsciiPunctuation(code) {
|
|
2868
|
+
return code >= 33 && code <= 47 || code >= 58 && code <= 64 || code >= 91 && code <= 96 || code >= 123 && code <= 126;
|
|
2869
|
+
}
|
|
2870
|
+
const buildInlineText = (tokenIndex, context) => {
|
|
2871
|
+
return inlineTokenText(context.view.text, context.tokens, tokenIndex);
|
|
2872
|
+
};
|
|
2873
|
+
const buildDecodedInlineText = (tokenIndex, context) => {
|
|
2874
|
+
return semanticText(inlineTokenText(context.view.text, context.tokens, tokenIndex));
|
|
2875
|
+
};
|
|
2876
|
+
const feature$9 = { inline: {
|
|
2877
|
+
scans: [{
|
|
2878
|
+
marker: 38,
|
|
2879
|
+
scan(source, start, tokens) {
|
|
2880
|
+
const matchEnd = matchInlinePatternEnd(entity, source, start);
|
|
2881
|
+
if (matchEnd < 0) return start + 1;
|
|
2882
|
+
appendInlineToken(tokens, 66, start, matchEnd);
|
|
2883
|
+
return matchEnd;
|
|
2884
|
+
}
|
|
2885
|
+
}, {
|
|
2886
|
+
marker: 92,
|
|
2887
|
+
scan(source, start, tokens) {
|
|
2888
|
+
const next = source.charCodeAt(start + 1);
|
|
2889
|
+
if (next === 10 || next === 13) {
|
|
2890
|
+
appendInlineToken(tokens, 128, start, start + 1);
|
|
2891
|
+
return start + 1;
|
|
2892
|
+
}
|
|
2893
|
+
if (isAsciiPunctuation(next)) {
|
|
2894
|
+
const end = start + 2;
|
|
2895
|
+
appendInlineToken(tokens, 65, start, end);
|
|
2896
|
+
return end;
|
|
2897
|
+
}
|
|
2898
|
+
return start + (next === 32 || next === 9 ? 2 : 1);
|
|
2899
|
+
}
|
|
2900
|
+
}],
|
|
2901
|
+
builds: [
|
|
2902
|
+
{
|
|
2903
|
+
kind: "text",
|
|
2904
|
+
token: 64,
|
|
2905
|
+
build: buildInlineText
|
|
2906
|
+
},
|
|
2907
|
+
{
|
|
2908
|
+
kind: "text",
|
|
2909
|
+
token: 65,
|
|
2910
|
+
build: buildDecodedInlineText
|
|
2911
|
+
},
|
|
2912
|
+
{
|
|
2913
|
+
kind: "text",
|
|
2914
|
+
token: 66,
|
|
2915
|
+
build: buildDecodedInlineText
|
|
2916
|
+
}
|
|
2917
|
+
]
|
|
2918
|
+
} };
|
|
2919
|
+
//#endregion
|
|
2992
2920
|
//#region src/profile/features/formatting.ts
|
|
2993
2921
|
const scanFormatting = (source, start, tokens) => {
|
|
2994
2922
|
const code = source.charCodeAt(start);
|
|
2995
2923
|
const end = inlineMarkerRunEnd(source, start);
|
|
2996
|
-
appendInlineToken(tokens, code === 42 ?
|
|
2924
|
+
appendInlineToken(tokens, code === 42 ? 68 : code === 95 ? 69 : 70, start, end);
|
|
2997
2925
|
return end;
|
|
2998
2926
|
};
|
|
2999
2927
|
function createFormattingPair(type, open, close) {
|
|
3000
2928
|
return {
|
|
3001
2929
|
kind: "pair",
|
|
2930
|
+
token: open,
|
|
3002
2931
|
open,
|
|
3003
2932
|
close,
|
|
3004
2933
|
build(openToken, closeToken, sourceSpan, children) {
|
|
@@ -3010,11 +2939,11 @@ function createFormattingPair(type, open, close) {
|
|
|
3010
2939
|
}
|
|
3011
2940
|
};
|
|
3012
2941
|
}
|
|
3013
|
-
const emphasisPair = createFormattingPair("emphasis",
|
|
3014
|
-
const strongPair = createFormattingPair("strong",
|
|
3015
|
-
const deletePair = createFormattingPair("delete",
|
|
2942
|
+
const emphasisPair = createFormattingPair("emphasis", 192, 193);
|
|
2943
|
+
const strongPair = createFormattingPair("strong", 194, 195);
|
|
2944
|
+
const deletePair = createFormattingPair("delete", 196, 197);
|
|
3016
2945
|
const asteriskDelimiter = {
|
|
3017
|
-
token:
|
|
2946
|
+
token: 68,
|
|
3018
2947
|
single: emphasisPair,
|
|
3019
2948
|
double: strongPair,
|
|
3020
2949
|
pairing: {
|
|
@@ -3023,7 +2952,7 @@ const asteriskDelimiter = {
|
|
|
3023
2952
|
}
|
|
3024
2953
|
};
|
|
3025
2954
|
const underscoreDelimiter = {
|
|
3026
|
-
token:
|
|
2955
|
+
token: 69,
|
|
3027
2956
|
single: emphasisPair,
|
|
3028
2957
|
double: strongPair,
|
|
3029
2958
|
pairing: {
|
|
@@ -3033,7 +2962,7 @@ const underscoreDelimiter = {
|
|
|
3033
2962
|
allowIntraword: false
|
|
3034
2963
|
};
|
|
3035
2964
|
const strikethroughDelimiter = {
|
|
3036
|
-
token:
|
|
2965
|
+
token: 70,
|
|
3037
2966
|
double: deletePair,
|
|
3038
2967
|
pairing: { kind: "whole" }
|
|
3039
2968
|
};
|
|
@@ -3041,12 +2970,12 @@ function feature$8(strikethroughOptions) {
|
|
|
3041
2970
|
const builds = [
|
|
3042
2971
|
{
|
|
3043
2972
|
kind: "text",
|
|
3044
|
-
token:
|
|
2973
|
+
token: 68,
|
|
3045
2974
|
build: buildInlineText
|
|
3046
2975
|
},
|
|
3047
2976
|
{
|
|
3048
2977
|
kind: "text",
|
|
3049
|
-
token:
|
|
2978
|
+
token: 69,
|
|
3050
2979
|
build: buildInlineText
|
|
3051
2980
|
},
|
|
3052
2981
|
emphasisPair,
|
|
@@ -3063,7 +2992,7 @@ function feature$8(strikethroughOptions) {
|
|
|
3063
2992
|
if (strikethroughOptions) {
|
|
3064
2993
|
builds.push({
|
|
3065
2994
|
kind: "text",
|
|
3066
|
-
token:
|
|
2995
|
+
token: 70,
|
|
3067
2996
|
build: buildInlineText
|
|
3068
2997
|
}, deletePair);
|
|
3069
2998
|
delimiters.push(typeof strikethroughOptions !== "object" || strikethroughOptions.singleTilde !== false ? {
|
|
@@ -3076,9 +3005,9 @@ function feature$8(strikethroughOptions) {
|
|
|
3076
3005
|
});
|
|
3077
3006
|
}
|
|
3078
3007
|
return { inline: {
|
|
3079
|
-
|
|
3008
|
+
scans,
|
|
3080
3009
|
delimiters,
|
|
3081
|
-
|
|
3010
|
+
builds
|
|
3082
3011
|
} };
|
|
3083
3012
|
}
|
|
3084
3013
|
//#endregion
|
|
@@ -3105,8 +3034,7 @@ function atxAt(source, lines, index, markerOffset) {
|
|
|
3105
3034
|
const lineEnd = lines.end(index);
|
|
3106
3035
|
while (markerEnd < lineEnd && markerEnd - markerOffset < 6 && source[markerEnd] === "#") markerEnd++;
|
|
3107
3036
|
if (markerEnd < lineEnd && source[markerEnd] !== " " && source[markerEnd] !== " ") return;
|
|
3108
|
-
|
|
3109
|
-
while (contentOffset < lineEnd && (source[contentOffset] === " " || source[contentOffset] === " ")) contentOffset++;
|
|
3037
|
+
const contentOffset = skipLineWhitespace(source, markerEnd, lineEnd);
|
|
3110
3038
|
let contentEnd = lineEnd;
|
|
3111
3039
|
while (contentEnd > contentOffset && (source[contentEnd - 1] === " " || source[contentEnd - 1] === " ")) contentEnd--;
|
|
3112
3040
|
let closer = contentEnd;
|
|
@@ -3122,28 +3050,21 @@ function atxAt(source, lines, index, markerOffset) {
|
|
|
3122
3050
|
};
|
|
3123
3051
|
}
|
|
3124
3052
|
function setextMarkerAt(source, lines, index, markerOffset) {
|
|
3125
|
-
if (markerOffset < 0) return;
|
|
3126
3053
|
const marker = source[markerOffset];
|
|
3127
3054
|
if (marker !== "=" && marker !== "-") return;
|
|
3128
3055
|
const lineEnd = lines.end(index);
|
|
3129
3056
|
let offset = markerOffset + 1;
|
|
3130
3057
|
while (offset < lineEnd && source[offset] === marker) offset++;
|
|
3131
|
-
|
|
3058
|
+
offset = skipLineWhitespace(source, offset, lineEnd);
|
|
3132
3059
|
return offset === lineEnd ? marker : void 0;
|
|
3133
3060
|
}
|
|
3134
3061
|
const feature$7 = { block: {
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
syntax: {
|
|
3138
|
-
kind: "block",
|
|
3139
|
-
open: 5,
|
|
3140
|
-
close: 8
|
|
3141
|
-
},
|
|
3142
|
-
inlineContent: true,
|
|
3062
|
+
builds: [{
|
|
3063
|
+
token: 96,
|
|
3143
3064
|
build(tokenStart, context) {
|
|
3144
3065
|
const tokens = context.structure.tokens;
|
|
3145
3066
|
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
3146
|
-
const inline = buildInlineFragment(tokenStart,
|
|
3067
|
+
const inline = buildInlineFragment(tokenStart, false, context);
|
|
3147
3068
|
const result = {
|
|
3148
3069
|
type: "heading",
|
|
3149
3070
|
depth: tokens.end(tokenStart) - tokens.start(tokenStart),
|
|
@@ -3157,20 +3078,14 @@ const feature$7 = { block: {
|
|
|
3157
3078
|
return result;
|
|
3158
3079
|
}
|
|
3159
3080
|
}, {
|
|
3160
|
-
|
|
3161
|
-
syntax: {
|
|
3162
|
-
kind: "block",
|
|
3163
|
-
open: [6, 7],
|
|
3164
|
-
close: 8
|
|
3165
|
-
},
|
|
3166
|
-
inlineContent: true,
|
|
3081
|
+
token: [97, 98],
|
|
3167
3082
|
build(tokenStart, context) {
|
|
3168
3083
|
const tokens = context.structure.tokens;
|
|
3169
|
-
const inline = buildInlineFragment(tokenStart,
|
|
3084
|
+
const inline = buildInlineFragment(tokenStart, false, context);
|
|
3170
3085
|
const children = inline.children;
|
|
3171
3086
|
const result = {
|
|
3172
3087
|
type: "heading",
|
|
3173
|
-
depth: tokens.kind(tokenStart) ===
|
|
3088
|
+
depth: tokens.kind(tokenStart) === 97 ? 1 : 2,
|
|
3174
3089
|
children,
|
|
3175
3090
|
position: {
|
|
3176
3091
|
start: firstChildStart(children),
|
|
@@ -3189,10 +3104,10 @@ const feature$7 = { block: {
|
|
|
3189
3104
|
start(source, lines, start, contentOffset, out) {
|
|
3190
3105
|
const atx = atxAt(source, lines, start, contentOffset);
|
|
3191
3106
|
if (!atx) return;
|
|
3192
|
-
out.push(
|
|
3107
|
+
out.push(96, contentOffset, atx.markerEnd);
|
|
3193
3108
|
if (atx.contentEnd > atx.contentOffset) out.push(1, atx.contentOffset, atx.contentEnd);
|
|
3194
3109
|
const lineEnd = lines.end(start);
|
|
3195
|
-
out.push(
|
|
3110
|
+
out.push(193, lineEnd, lineEnd);
|
|
3196
3111
|
return start + 1;
|
|
3197
3112
|
}
|
|
3198
3113
|
}]
|
|
@@ -3207,27 +3122,30 @@ const autolink = /<(?:[A-Z][A-Z0-9+.\-]{1,31}:[^ \t\n\r<>]+|[\w!#$%&'*+\-/=?^`{|
|
|
|
3207
3122
|
const inlineHtml = /<[A-Za-z][A-Za-z0-9-]*(?:[ \t\n\r]+[A-Za-z_:][\w.:-]*(?:[ \t\n\r]*=[ \t\n\r]*(?:[^ \t\n\r"'=<>`]+|'[^']*'|"[^"]*"))?)*[ \t\n\r]*\/?>|<\/[A-Za-z][A-Za-z0-9-]*[ \t\n\r]*>|<\?[\s\S]*?\?>|<![A-Z][\s\S]*?>|<!\[CDATA\[[\s\S]*?\]\]>/y;
|
|
3208
3123
|
function htmlStartAt(source, lines, index, contentOffset) {
|
|
3209
3124
|
const body = source.slice(contentOffset, lines.end(index));
|
|
3125
|
+
switch (body.charCodeAt(1)) {
|
|
3126
|
+
case 63: return {
|
|
3127
|
+
interruptParagraph: true,
|
|
3128
|
+
terminator: "?>"
|
|
3129
|
+
};
|
|
3130
|
+
case 33:
|
|
3131
|
+
if (body.startsWith("<!--")) return {
|
|
3132
|
+
interruptParagraph: true,
|
|
3133
|
+
terminator: "-->"
|
|
3134
|
+
};
|
|
3135
|
+
if (body.startsWith("<![CDATA[")) return {
|
|
3136
|
+
interruptParagraph: true,
|
|
3137
|
+
terminator: "]]>"
|
|
3138
|
+
};
|
|
3139
|
+
if (/[A-Z]/.test(body[2] ?? "")) return {
|
|
3140
|
+
interruptParagraph: true,
|
|
3141
|
+
terminator: ">"
|
|
3142
|
+
};
|
|
3143
|
+
}
|
|
3210
3144
|
const lower = body.toLowerCase();
|
|
3211
3145
|
for (const tag of htmlRawNames) if (lower.startsWith(`<${tag}`) && (lower.length === tag.length + 1 || /[ \t>]/.test(lower[tag.length + 1]))) return {
|
|
3212
3146
|
interruptParagraph: true,
|
|
3213
3147
|
terminator: `</${tag}>`
|
|
3214
3148
|
};
|
|
3215
|
-
if (body.startsWith("<!--")) return {
|
|
3216
|
-
interruptParagraph: true,
|
|
3217
|
-
terminator: "-->"
|
|
3218
|
-
};
|
|
3219
|
-
if (body.startsWith("<?")) return {
|
|
3220
|
-
interruptParagraph: true,
|
|
3221
|
-
terminator: "?>"
|
|
3222
|
-
};
|
|
3223
|
-
if (body.startsWith("<![CDATA[")) return {
|
|
3224
|
-
interruptParagraph: true,
|
|
3225
|
-
terminator: "]]>"
|
|
3226
|
-
};
|
|
3227
|
-
if (body.startsWith("<!") && /[A-Z]/.test(body[2] ?? "")) return {
|
|
3228
|
-
interruptParagraph: true,
|
|
3229
|
-
terminator: ">"
|
|
3230
|
-
};
|
|
3231
3149
|
const tag = /^<\/?([a-z][a-z0-9-]*)(?=[ \t\n\r/>]|$)/i.exec(body)?.[1].toLowerCase();
|
|
3232
3150
|
if (tag && htmlBlockTags.has(tag)) return { interruptParagraph: true };
|
|
3233
3151
|
if (completeHtmlTag.test(body)) return { interruptParagraph: false };
|
|
@@ -3241,18 +3159,13 @@ const buildInlineHtml = (tokenIndex, sourceSpan, context) => {
|
|
|
3241
3159
|
};
|
|
3242
3160
|
const feature$6 = {
|
|
3243
3161
|
block: {
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
syntax: {
|
|
3247
|
-
kind: "leaf",
|
|
3248
|
-
token: 21
|
|
3249
|
-
},
|
|
3162
|
+
builds: [{
|
|
3163
|
+
token: 259,
|
|
3250
3164
|
build(tokenStart, context) {
|
|
3251
3165
|
const tokens = context.structure.tokens;
|
|
3252
3166
|
const offset = tokens.start(tokenStart);
|
|
3253
3167
|
const end = tokens.end(tokenStart);
|
|
3254
3168
|
const unterminated = tokens.value(tokenStart);
|
|
3255
|
-
if (tokens.kind(tokenStart) !== 21 || unterminated === void 0) throw new Error("HTML block lacks termination state");
|
|
3256
3169
|
let html = context.locator.normalizeLineEndings(tokens.text(context.source, tokenStart));
|
|
3257
3170
|
if (!unterminated && html.endsWith("\n")) html = html.slice(0, -1);
|
|
3258
3171
|
return {
|
|
@@ -3270,44 +3183,47 @@ const feature$6 = {
|
|
|
3270
3183
|
start(source, lines, start, contentOffset, out) {
|
|
3271
3184
|
const htmlStart = htmlStartAt(source, lines, start, contentOffset);
|
|
3272
3185
|
if (!htmlStart) return;
|
|
3273
|
-
let end = start
|
|
3186
|
+
let end = start;
|
|
3274
3187
|
let unterminated = false;
|
|
3275
|
-
if (htmlStart.terminator
|
|
3188
|
+
if (htmlStart.terminator) {
|
|
3276
3189
|
while (end < lines.length && !source.slice(lines.start(end), lines.end(end)).toLowerCase().includes(htmlStart.terminator)) end++;
|
|
3277
|
-
if (end
|
|
3278
|
-
else
|
|
3279
|
-
} else
|
|
3280
|
-
|
|
3190
|
+
if (end === lines.length) unterminated = true;
|
|
3191
|
+
else end++;
|
|
3192
|
+
} else {
|
|
3193
|
+
end++;
|
|
3194
|
+
while (end < lines.length && !isBlankLine(source, lines, end)) end++;
|
|
3195
|
+
}
|
|
3196
|
+
appendLogicalToken(out, 259, source, lines, start, end, unterminated);
|
|
3281
3197
|
return end;
|
|
3282
3198
|
}
|
|
3283
3199
|
}]
|
|
3284
3200
|
},
|
|
3285
3201
|
inline: {
|
|
3286
|
-
|
|
3202
|
+
scans: [{
|
|
3287
3203
|
marker: 60,
|
|
3288
3204
|
scan(source, start, tokens) {
|
|
3289
3205
|
let end = matchInlinePatternEnd(htmlComment, source, start);
|
|
3290
|
-
let kind =
|
|
3206
|
+
let kind = 130;
|
|
3291
3207
|
if (end < 0) {
|
|
3292
3208
|
end = matchInlinePatternEnd(autolink, source, start);
|
|
3293
|
-
kind =
|
|
3209
|
+
kind = 132;
|
|
3294
3210
|
}
|
|
3295
3211
|
if (end < 0) {
|
|
3296
3212
|
end = matchInlinePatternEnd(inlineHtml, source, start);
|
|
3297
|
-
kind =
|
|
3213
|
+
kind = 131;
|
|
3298
3214
|
}
|
|
3299
3215
|
if (end < 0) return start + 1;
|
|
3300
3216
|
appendInlineToken(tokens, kind, start, end);
|
|
3301
3217
|
return end;
|
|
3302
3218
|
}
|
|
3303
3219
|
}],
|
|
3304
|
-
|
|
3220
|
+
builds: [{
|
|
3305
3221
|
kind: "leaf",
|
|
3306
|
-
token:
|
|
3222
|
+
token: 131,
|
|
3307
3223
|
build: buildInlineHtml
|
|
3308
3224
|
}, {
|
|
3309
3225
|
kind: "leaf",
|
|
3310
|
-
token:
|
|
3226
|
+
token: 130,
|
|
3311
3227
|
build: buildInlineHtml
|
|
3312
3228
|
}]
|
|
3313
3229
|
}
|
|
@@ -3317,8 +3233,7 @@ const feature$6 = {
|
|
|
3317
3233
|
function skipWhitespace(source, start) {
|
|
3318
3234
|
let end = start;
|
|
3319
3235
|
while (end < source.length) {
|
|
3320
|
-
|
|
3321
|
-
if (code !== 9 && code !== 10 && code !== 13 && code !== 32) break;
|
|
3236
|
+
if (!isMarkdownWhitespace(source.charCodeAt(end))) break;
|
|
3322
3237
|
end++;
|
|
3323
3238
|
}
|
|
3324
3239
|
return end;
|
|
@@ -3359,7 +3274,7 @@ function linkDestinationEnd(source, start) {
|
|
|
3359
3274
|
end++;
|
|
3360
3275
|
continue;
|
|
3361
3276
|
}
|
|
3362
|
-
if (
|
|
3277
|
+
if (isMarkdownWhitespace(code)) break;
|
|
3363
3278
|
consumed = true;
|
|
3364
3279
|
end++;
|
|
3365
3280
|
}
|
|
@@ -3378,7 +3293,14 @@ function linkTitleEnd(source, start) {
|
|
|
3378
3293
|
}
|
|
3379
3294
|
return -1;
|
|
3380
3295
|
}
|
|
3296
|
+
const simpleLinkTail = /\([^<\\()\t\n\r ]+\)/y;
|
|
3381
3297
|
function scanLinkTail(source, start, tokens) {
|
|
3298
|
+
simpleLinkTail.lastIndex = start + 1;
|
|
3299
|
+
if (simpleLinkTail.test(source)) {
|
|
3300
|
+
const end = simpleLinkTail.lastIndex;
|
|
3301
|
+
appendInlineToken(tokens, 73, start, end, end - start - 1);
|
|
3302
|
+
return end;
|
|
3303
|
+
}
|
|
3382
3304
|
if (source.charCodeAt(start + 1) !== 40) return -1;
|
|
3383
3305
|
let offset = skipWhitespace(source, start + 2);
|
|
3384
3306
|
let destinationEnd = offset;
|
|
@@ -3390,25 +3312,21 @@ function scanLinkTail(source, start, tokens) {
|
|
|
3390
3312
|
if (whitespaceEnd > offset && source.charCodeAt(whitespaceEnd) !== 41) {
|
|
3391
3313
|
const titleEnd = linkTitleEnd(source, whitespaceEnd);
|
|
3392
3314
|
if (titleEnd < 0) return -1;
|
|
3393
|
-
offset = titleEnd;
|
|
3315
|
+
offset = skipWhitespace(source, titleEnd);
|
|
3394
3316
|
} else offset = whitespaceEnd;
|
|
3395
|
-
offset = skipWhitespace(source, offset);
|
|
3396
3317
|
if (source.charCodeAt(offset) !== 41) return -1;
|
|
3397
3318
|
}
|
|
3398
3319
|
const end = offset + 1;
|
|
3399
|
-
appendInlineToken(tokens,
|
|
3320
|
+
appendInlineToken(tokens, 73, start, end, destinationEnd - start);
|
|
3400
3321
|
return end;
|
|
3401
3322
|
}
|
|
3402
|
-
function isLinkWhitespace(code) {
|
|
3403
|
-
return code === 9 || code === 10 || code === 13 || code === 32;
|
|
3404
|
-
}
|
|
3405
3323
|
function resourceAt(source, tokens, tokenIndex) {
|
|
3406
3324
|
const tokenStart = inlineTokenStart(tokens, tokenIndex);
|
|
3407
3325
|
const tokenEnd = inlineTokenEnd(tokens, tokenIndex);
|
|
3408
3326
|
let start = tokenStart + 2;
|
|
3409
3327
|
let end = tokenEnd - 1;
|
|
3410
|
-
while (start < end &&
|
|
3411
|
-
while (end > start &&
|
|
3328
|
+
while (start < end && isMarkdownWhitespace(source.charCodeAt(start))) start++;
|
|
3329
|
+
while (end > start && isMarkdownWhitespace(source.charCodeAt(end - 1))) end--;
|
|
3412
3330
|
if (start === end) return {
|
|
3413
3331
|
url: "",
|
|
3414
3332
|
title: null
|
|
@@ -3421,7 +3339,7 @@ function resourceAt(source, tokens, tokenIndex) {
|
|
|
3421
3339
|
destinationEnd--;
|
|
3422
3340
|
}
|
|
3423
3341
|
start = resourceEnd;
|
|
3424
|
-
while (start < end &&
|
|
3342
|
+
while (start < end && isMarkdownWhitespace(source.charCodeAt(start))) start++;
|
|
3425
3343
|
return {
|
|
3426
3344
|
url: semanticText(source.slice(destinationStart, destinationEnd)),
|
|
3427
3345
|
title: start < end ? semanticText(source.slice(start + 1, end - 1)) : null
|
|
@@ -3429,10 +3347,8 @@ function resourceAt(source, tokens, tokenIndex) {
|
|
|
3429
3347
|
}
|
|
3430
3348
|
function reference(close, syntaxStart, syntaxEnd, context, image) {
|
|
3431
3349
|
const closeText = inlineTokenText(context.view.text, context.tokens, close);
|
|
3432
|
-
const text = context.view.text.slice(syntaxStart, syntaxEnd);
|
|
3433
|
-
const content = text.slice(image ? 2 : 1, text.length - closeText.length);
|
|
3434
3350
|
const full = closeText.startsWith("][") && closeText !== "][]";
|
|
3435
|
-
const labelSource = full ? closeText.slice(2, -1) :
|
|
3351
|
+
const labelSource = full ? closeText.slice(2, -1) : context.view.text.slice(syntaxStart + (image ? 2 : 1), syntaxEnd - closeText.length);
|
|
3436
3352
|
return {
|
|
3437
3353
|
identifier: normalizeAssociationLabel(labelSource),
|
|
3438
3354
|
label: semanticText(labelSource),
|
|
@@ -3484,13 +3400,13 @@ const buildInlineReferenceImage = createBuildMedia("image", "reference");
|
|
|
3484
3400
|
const buildInlineLink = createBuildMedia("link", "direct");
|
|
3485
3401
|
const buildInlineReferenceLink = createBuildMedia("link", "reference");
|
|
3486
3402
|
const feature$5 = { inline: {
|
|
3487
|
-
|
|
3403
|
+
scans: [
|
|
3488
3404
|
{
|
|
3489
3405
|
marker: 33,
|
|
3490
3406
|
scan(source, start, tokens) {
|
|
3491
3407
|
if (source.charCodeAt(start + 1) !== 91) return start + 1;
|
|
3492
3408
|
const end = start + 2;
|
|
3493
|
-
appendInlineToken(tokens,
|
|
3409
|
+
appendInlineToken(tokens, 71, start, end);
|
|
3494
3410
|
return end;
|
|
3495
3411
|
}
|
|
3496
3412
|
},
|
|
@@ -3498,7 +3414,7 @@ const feature$5 = { inline: {
|
|
|
3498
3414
|
marker: 91,
|
|
3499
3415
|
scan(source, start, tokens) {
|
|
3500
3416
|
const end = start + 1;
|
|
3501
|
-
appendInlineToken(tokens,
|
|
3417
|
+
appendInlineToken(tokens, 72, start, end);
|
|
3502
3418
|
return end;
|
|
3503
3419
|
}
|
|
3504
3420
|
},
|
|
@@ -3507,41 +3423,37 @@ const feature$5 = { inline: {
|
|
|
3507
3423
|
scan(source, start, tokens) {
|
|
3508
3424
|
const end = scanLinkTail(source, start, tokens);
|
|
3509
3425
|
if (end >= 0) return end;
|
|
3510
|
-
appendInlineToken(tokens,
|
|
3426
|
+
appendInlineToken(tokens, 74, start, start + 1);
|
|
3511
3427
|
return start + 1;
|
|
3512
3428
|
}
|
|
3513
3429
|
}
|
|
3514
3430
|
],
|
|
3515
|
-
|
|
3431
|
+
builds: [
|
|
3516
3432
|
{
|
|
3517
3433
|
kind: "pair",
|
|
3518
|
-
|
|
3519
|
-
close: 24,
|
|
3434
|
+
token: 198,
|
|
3520
3435
|
build: buildInlineLink
|
|
3521
3436
|
},
|
|
3522
3437
|
{
|
|
3523
3438
|
kind: "pair",
|
|
3524
|
-
|
|
3525
|
-
close: 26,
|
|
3439
|
+
token: 200,
|
|
3526
3440
|
build: buildInlineImage
|
|
3527
3441
|
},
|
|
3528
3442
|
{
|
|
3529
3443
|
kind: "pair",
|
|
3530
|
-
|
|
3531
|
-
close: 28,
|
|
3444
|
+
token: 202,
|
|
3532
3445
|
build: buildInlineReferenceLink
|
|
3533
3446
|
},
|
|
3534
3447
|
{
|
|
3535
3448
|
kind: "pair",
|
|
3536
|
-
|
|
3537
|
-
close: 30,
|
|
3449
|
+
token: 204,
|
|
3538
3450
|
build: buildInlineReferenceImage
|
|
3539
3451
|
},
|
|
3540
3452
|
{
|
|
3541
3453
|
kind: "leaf",
|
|
3542
|
-
token:
|
|
3454
|
+
token: 132,
|
|
3543
3455
|
build(tokenIndex, sourceSpan, context) {
|
|
3544
|
-
const label = inlineTokenText(context.view.text, context.tokens, tokenIndex
|
|
3456
|
+
const label = inlineTokenText(context.view.text, context.tokens, tokenIndex, 1);
|
|
3545
3457
|
return {
|
|
3546
3458
|
type: "link",
|
|
3547
3459
|
url: label.includes(":") ? label : `mailto:${label}`,
|
|
@@ -3568,114 +3480,90 @@ const feature$5 = { inline: {
|
|
|
3568
3480
|
},
|
|
3569
3481
|
{
|
|
3570
3482
|
kind: "text",
|
|
3571
|
-
token:
|
|
3483
|
+
token: 72,
|
|
3572
3484
|
build: buildInlineText
|
|
3573
3485
|
},
|
|
3574
3486
|
{
|
|
3575
3487
|
kind: "text",
|
|
3576
|
-
token:
|
|
3488
|
+
token: 71,
|
|
3577
3489
|
build: buildInlineText
|
|
3578
3490
|
},
|
|
3579
3491
|
{
|
|
3580
3492
|
kind: "text",
|
|
3581
|
-
token:
|
|
3493
|
+
token: 73,
|
|
3582
3494
|
build: buildDecodedInlineText
|
|
3583
3495
|
},
|
|
3584
3496
|
{
|
|
3585
3497
|
kind: "text",
|
|
3586
|
-
token:
|
|
3498
|
+
token: 74,
|
|
3587
3499
|
build: buildInlineText
|
|
3588
3500
|
}
|
|
3589
3501
|
]
|
|
3590
3502
|
} };
|
|
3591
3503
|
//#endregion
|
|
3592
3504
|
//#region src/profile/features/list.ts
|
|
3593
|
-
function
|
|
3594
|
-
const lineEnd = lines.end(index);
|
|
3595
|
-
if (markerEnd === lineEnd) return {
|
|
3596
|
-
offset: markerEnd,
|
|
3597
|
-
columns: 1,
|
|
3598
|
-
prefixColumns: 0
|
|
3599
|
-
};
|
|
3600
|
-
let offset = markerEnd;
|
|
3601
|
-
let column = markerColumn;
|
|
3602
|
-
while (offset < lineEnd) {
|
|
3603
|
-
const code = source.charCodeAt(offset);
|
|
3604
|
-
if (code === 32) column++;
|
|
3605
|
-
else if (code === 9) column += 4 - column % 4;
|
|
3606
|
-
else break;
|
|
3607
|
-
offset++;
|
|
3608
|
-
}
|
|
3609
|
-
const whitespaceColumns = column - markerColumn;
|
|
3610
|
-
if (offset < lineEnd && whitespaceColumns <= 4) return {
|
|
3611
|
-
offset,
|
|
3612
|
-
columns: whitespaceColumns,
|
|
3613
|
-
prefixColumns: 0
|
|
3614
|
-
};
|
|
3615
|
-
const firstPaddingColumns = source.charCodeAt(markerEnd) === 9 ? 4 - markerColumn % 4 : 1;
|
|
3616
|
-
return {
|
|
3617
|
-
offset: markerEnd + 1,
|
|
3618
|
-
columns: 1,
|
|
3619
|
-
prefixColumns: firstPaddingColumns - 1
|
|
3620
|
-
};
|
|
3621
|
-
}
|
|
3622
|
-
function listMarkerAt(source, lines, index, contentOffset = lineIndentOffset(source, lines, index)) {
|
|
3505
|
+
function listMarkerAt(source, lines, index, contentOffset) {
|
|
3623
3506
|
if (contentOffset < 0) return;
|
|
3624
3507
|
const indent = lines.prefixColumns(index) + contentOffset - lines.start(index);
|
|
3625
3508
|
const marker = source.charCodeAt(contentOffset);
|
|
3626
|
-
const markerEnd = contentOffset + 1;
|
|
3627
3509
|
const lineEnd = lines.end(index);
|
|
3510
|
+
let delimiter;
|
|
3511
|
+
let markerEnd = contentOffset + 1;
|
|
3512
|
+
let startNumber = 0;
|
|
3628
3513
|
if (marker === 45 || marker === 43 || marker === 42) {
|
|
3629
3514
|
const following = source.charCodeAt(markerEnd);
|
|
3630
3515
|
if (markerEnd !== lineEnd && following !== 32 && following !== 9 || isThematicBreak(source, lines, index, contentOffset)) return;
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3516
|
+
delimiter = marker;
|
|
3517
|
+
} else {
|
|
3518
|
+
if (marker < 48 || marker > 57) return;
|
|
3519
|
+
let orderedEnd = contentOffset;
|
|
3520
|
+
while (orderedEnd < lineEnd && orderedEnd - contentOffset < 9) {
|
|
3521
|
+
const digit = source.charCodeAt(orderedEnd) - 48;
|
|
3522
|
+
if (digit < 0 || digit > 9) break;
|
|
3523
|
+
startNumber = startNumber * 10 + digit;
|
|
3524
|
+
orderedEnd++;
|
|
3525
|
+
}
|
|
3526
|
+
delimiter = source.charCodeAt(orderedEnd);
|
|
3527
|
+
if (delimiter !== 46 && delimiter !== 41) return;
|
|
3528
|
+
if (orderedEnd + 1 < lineEnd) {
|
|
3529
|
+
const code = source.charCodeAt(orderedEnd + 1);
|
|
3530
|
+
if (code !== 32 && code !== 9) return;
|
|
3531
|
+
}
|
|
3532
|
+
markerEnd = orderedEnd + 1;
|
|
3533
|
+
}
|
|
3534
|
+
const markerColumn = indent + markerEnd - contentOffset;
|
|
3535
|
+
let contentIndent = markerColumn + 1;
|
|
3536
|
+
let contentStart = markerEnd;
|
|
3537
|
+
let hasContent = false;
|
|
3538
|
+
let prefixColumns = 0;
|
|
3539
|
+
if (markerEnd < lineEnd) {
|
|
3540
|
+
let column = markerColumn;
|
|
3541
|
+
while (contentStart < lineEnd) {
|
|
3542
|
+
const code = source.charCodeAt(contentStart);
|
|
3543
|
+
if (code === 32) column++;
|
|
3544
|
+
else if (code === 9) column += 4 - column % 4;
|
|
3545
|
+
else break;
|
|
3546
|
+
contentStart++;
|
|
3547
|
+
}
|
|
3548
|
+
hasContent = contentStart < lineEnd;
|
|
3549
|
+
if (hasContent && column - markerColumn <= 4) contentIndent = column;
|
|
3550
|
+
else {
|
|
3551
|
+
const firstPaddingColumns = source.charCodeAt(markerEnd) === 9 ? 4 - markerColumn % 4 : 1;
|
|
3552
|
+
contentStart = markerEnd + 1;
|
|
3553
|
+
prefixColumns = firstPaddingColumns - 1;
|
|
3554
|
+
}
|
|
3642
3555
|
}
|
|
3643
|
-
if (marker < 48 || marker > 57) return;
|
|
3644
|
-
let startNumber = 0;
|
|
3645
|
-
let orderedEnd = contentOffset;
|
|
3646
|
-
while (orderedEnd < lineEnd && orderedEnd - contentOffset < 9) {
|
|
3647
|
-
const digit = source.charCodeAt(orderedEnd) - 48;
|
|
3648
|
-
if (digit < 0 || digit > 9) break;
|
|
3649
|
-
startNumber = startNumber * 10 + digit;
|
|
3650
|
-
orderedEnd++;
|
|
3651
|
-
}
|
|
3652
|
-
const delimiter = source[orderedEnd];
|
|
3653
|
-
if (delimiter !== "." && delimiter !== ")") return;
|
|
3654
|
-
if (orderedEnd + 1 < lineEnd) {
|
|
3655
|
-
const code = source.charCodeAt(orderedEnd + 1);
|
|
3656
|
-
if (code !== 32 && code !== 9) return;
|
|
3657
|
-
}
|
|
3658
|
-
orderedEnd++;
|
|
3659
|
-
const markerWidth = orderedEnd - contentOffset;
|
|
3660
|
-
const padding = listMarkerPadding(source, lines, index, orderedEnd, indent + markerWidth);
|
|
3661
3556
|
return {
|
|
3662
|
-
kind: "ordered",
|
|
3663
|
-
indent,
|
|
3664
3557
|
offset: contentOffset,
|
|
3665
|
-
end:
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3558
|
+
end: markerEnd,
|
|
3559
|
+
hasContent,
|
|
3560
|
+
contentOffset: contentStart,
|
|
3561
|
+
contentIndent,
|
|
3562
|
+
contentPrefixColumns: prefixColumns,
|
|
3669
3563
|
delimiter,
|
|
3670
3564
|
startNumber
|
|
3671
3565
|
};
|
|
3672
3566
|
}
|
|
3673
|
-
function sameList(a, b) {
|
|
3674
|
-
return a.kind === b.kind && a.delimiter === b.delimiter;
|
|
3675
|
-
}
|
|
3676
|
-
function hasListContent(source, lines, index, marker) {
|
|
3677
|
-
return !!marker && /\S/.test(source.slice(marker.contentOffset, lines.end(index)));
|
|
3678
|
-
}
|
|
3679
3567
|
function isTaskListWhitespace(code) {
|
|
3680
3568
|
return code === 32 || code >= 9 && code <= 13;
|
|
3681
3569
|
}
|
|
@@ -3712,7 +3600,7 @@ const buildListItem = (tokenStart, context) => {
|
|
|
3712
3600
|
return {
|
|
3713
3601
|
type: "listItem",
|
|
3714
3602
|
spread: tokens.value(close) === true,
|
|
3715
|
-
checked: markerKind ===
|
|
3603
|
+
checked: markerKind === 130 ? true : markerKind === 129 ? false : null,
|
|
3716
3604
|
children,
|
|
3717
3605
|
position: {
|
|
3718
3606
|
start,
|
|
@@ -3723,10 +3611,9 @@ const buildListItem = (tokenStart, context) => {
|
|
|
3723
3611
|
function createBuildList(ordered) {
|
|
3724
3612
|
return (tokenStart, context) => {
|
|
3725
3613
|
const tokens = context.structure.tokens;
|
|
3726
|
-
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
3727
3614
|
const items = [];
|
|
3728
3615
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
3729
|
-
for (let child = tokenStart + 1; child < close; child += tokens.nodeLength(child)) items.push(
|
|
3616
|
+
for (let child = tokenStart + 1; child < close; child += tokens.nodeLength(child)) items.push(buildListItem(child, context));
|
|
3730
3617
|
return {
|
|
3731
3618
|
type: "list",
|
|
3732
3619
|
ordered,
|
|
@@ -3734,8 +3621,8 @@ function createBuildList(ordered) {
|
|
|
3734
3621
|
spread: tokens.value(close) === true,
|
|
3735
3622
|
children: items,
|
|
3736
3623
|
position: {
|
|
3737
|
-
start,
|
|
3738
|
-
end: lastChildEnd(items)
|
|
3624
|
+
start: firstChildStart(items),
|
|
3625
|
+
end: lastChildEnd(items)
|
|
3739
3626
|
}
|
|
3740
3627
|
};
|
|
3741
3628
|
};
|
|
@@ -3743,36 +3630,31 @@ function createBuildList(ordered) {
|
|
|
3743
3630
|
const listStart = (source, lines, start, contentOffset, out, context) => {
|
|
3744
3631
|
let marker = listMarkerAt(source, lines, start, contentOffset);
|
|
3745
3632
|
if (!marker) return;
|
|
3746
|
-
const
|
|
3747
|
-
const
|
|
3748
|
-
const listOpen =
|
|
3749
|
-
const listClose =
|
|
3750
|
-
out.push(listOpen,
|
|
3633
|
+
const delimiter = marker.delimiter;
|
|
3634
|
+
const ordered = delimiter === 46 || delimiter === 41;
|
|
3635
|
+
const listOpen = ordered ? 66 : 65;
|
|
3636
|
+
const listClose = ordered ? 196 : 195;
|
|
3637
|
+
out.push(listOpen, marker.offset, marker.end, ordered ? { value: marker.startNumber } : void 0);
|
|
3751
3638
|
let index = start;
|
|
3752
|
-
let listEnd =
|
|
3639
|
+
let listEnd = marker.end;
|
|
3753
3640
|
let listSpread = false;
|
|
3754
3641
|
let trailingBlank = false;
|
|
3755
|
-
while (marker
|
|
3642
|
+
while (marker?.delimiter === delimiter) {
|
|
3756
3643
|
let sibling;
|
|
3757
3644
|
listSpread ||= trailingBlank;
|
|
3758
3645
|
trailingBlank = false;
|
|
3759
|
-
out.push(
|
|
3760
|
-
const itemLines =
|
|
3761
|
-
|
|
3762
|
-
let hasContent = !isBlank(source, itemLines, 0);
|
|
3646
|
+
out.push(128, marker.offset, marker.end);
|
|
3647
|
+
const itemLines = context.createLineView(lines, index, marker.contentOffset, marker.contentPrefixColumns);
|
|
3648
|
+
let hasContent = marker.hasContent;
|
|
3763
3649
|
let paragraphLeaf = hasContent ? 2 : 0;
|
|
3764
3650
|
index++;
|
|
3765
3651
|
while (index < lines.length) {
|
|
3766
|
-
const
|
|
3767
|
-
if (
|
|
3768
|
-
sibling = candidate;
|
|
3769
|
-
break;
|
|
3770
|
-
}
|
|
3771
|
-
if (isBlank(source, lines, index)) {
|
|
3652
|
+
const line = itemLines.pushAfterColumns(source, lines, index, marker.contentIndent);
|
|
3653
|
+
if (line === 0) {
|
|
3772
3654
|
if (!hasContent) {
|
|
3773
3655
|
trailingBlank = true;
|
|
3774
3656
|
index++;
|
|
3775
|
-
sibling = index < lines.length ? listMarkerAt(source, lines, index) : void 0;
|
|
3657
|
+
sibling = index < lines.length ? listMarkerAt(source, lines, index, lineIndentOffset(source, lines, index)) : void 0;
|
|
3776
3658
|
break;
|
|
3777
3659
|
}
|
|
3778
3660
|
itemLines.pushFrom(lines, index);
|
|
@@ -3781,84 +3663,61 @@ const listStart = (source, lines, start, contentOffset, out, context) => {
|
|
|
3781
3663
|
index++;
|
|
3782
3664
|
continue;
|
|
3783
3665
|
}
|
|
3784
|
-
|
|
3785
|
-
if (content) {
|
|
3786
|
-
itemLines.pushFrom(lines, index, content.offset, content.prefixColumns);
|
|
3666
|
+
if (line === 1) {
|
|
3787
3667
|
trailingBlank = false;
|
|
3788
3668
|
hasContent = true;
|
|
3789
3669
|
paragraphLeaf = 2;
|
|
3790
3670
|
index++;
|
|
3791
3671
|
continue;
|
|
3792
3672
|
}
|
|
3673
|
+
const contentOffset = lineIndentOffset(source, lines, index);
|
|
3674
|
+
const candidate = listMarkerAt(source, lines, index, contentOffset);
|
|
3675
|
+
if (candidate) {
|
|
3676
|
+
sibling = candidate;
|
|
3677
|
+
break;
|
|
3678
|
+
}
|
|
3793
3679
|
if (paragraphLeaf === 2) paragraphLeaf = context.endsWithParagraphLeaf(source, itemLines, itemLines.length - 1) ? 1 : 0;
|
|
3794
|
-
if (paragraphLeaf === 0 || context.startsInterruptingBlock(source, lines, index)) break;
|
|
3680
|
+
if (paragraphLeaf === 0 || context.startsInterruptingBlock(source, lines, index, contentOffset)) break;
|
|
3795
3681
|
itemLines.pushLazy(lines, index);
|
|
3796
3682
|
index++;
|
|
3797
3683
|
}
|
|
3798
3684
|
const itemSpread = context.scanLines(source, itemLines, out);
|
|
3799
3685
|
listEnd = itemLines.next(itemLines.length - 1);
|
|
3800
|
-
out.push(
|
|
3686
|
+
out.push(197, listEnd, listEnd, itemSpread ? { value: true } : void 0);
|
|
3801
3687
|
marker = sibling;
|
|
3802
3688
|
}
|
|
3803
3689
|
out.push(listClose, listEnd, listEnd, listSpread ? { value: true } : void 0);
|
|
3804
3690
|
return index;
|
|
3805
3691
|
};
|
|
3806
3692
|
const taskListStart = (source, lines, start, contentOffset, out, context) => {
|
|
3807
|
-
const
|
|
3693
|
+
const listToken = out.length;
|
|
3808
3694
|
const nextLine = listStart(source, lines, start, contentOffset, out, context);
|
|
3809
3695
|
if (nextLine === void 0) return;
|
|
3810
|
-
for (let item =
|
|
3811
|
-
if (out.kind(item) !== 15) continue;
|
|
3696
|
+
for (let item = listToken + 1; item < out.length - 1; item += out.nodeLength(item)) {
|
|
3812
3697
|
let paragraph = item + 1;
|
|
3813
3698
|
let contentKind = out.kind(paragraph);
|
|
3814
|
-
while (contentKind ===
|
|
3699
|
+
while (contentKind === 67 || contentKind === 2 || contentKind === 198) {
|
|
3815
3700
|
paragraph++;
|
|
3816
3701
|
contentKind = out.kind(paragraph);
|
|
3817
3702
|
}
|
|
3818
|
-
if (contentKind !==
|
|
3703
|
+
if (contentKind !== 99) continue;
|
|
3819
3704
|
const firstChunk = paragraph + 1;
|
|
3820
3705
|
const marker = taskListMarkerAt(source, out.start(firstChunk), out.end(firstChunk));
|
|
3821
3706
|
if (!marker || !hasTaskListContent(source, out, firstChunk, marker.contentStart)) continue;
|
|
3822
|
-
out.setKind(item, marker.checked ?
|
|
3707
|
+
out.setKind(item, marker.checked ? 130 : 129);
|
|
3823
3708
|
out.setStart(firstChunk, marker.contentStart);
|
|
3824
3709
|
}
|
|
3825
3710
|
return nextLine;
|
|
3826
3711
|
};
|
|
3827
3712
|
function feature$4(taskList = false) {
|
|
3828
3713
|
return { block: {
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
16,
|
|
3837
|
-
17
|
|
3838
|
-
],
|
|
3839
|
-
close: 18
|
|
3840
|
-
},
|
|
3841
|
-
build: buildListItem
|
|
3842
|
-
},
|
|
3843
|
-
{
|
|
3844
|
-
rule: 6,
|
|
3845
|
-
syntax: {
|
|
3846
|
-
kind: "block",
|
|
3847
|
-
open: 11,
|
|
3848
|
-
close: 12
|
|
3849
|
-
},
|
|
3850
|
-
build: createBuildList(false)
|
|
3851
|
-
},
|
|
3852
|
-
{
|
|
3853
|
-
rule: 7,
|
|
3854
|
-
syntax: {
|
|
3855
|
-
kind: "block",
|
|
3856
|
-
open: 13,
|
|
3857
|
-
close: 14
|
|
3858
|
-
},
|
|
3859
|
-
build: createBuildList(true)
|
|
3860
|
-
}
|
|
3861
|
-
],
|
|
3714
|
+
builds: [{
|
|
3715
|
+
token: 65,
|
|
3716
|
+
build: createBuildList(false)
|
|
3717
|
+
}, {
|
|
3718
|
+
token: 66,
|
|
3719
|
+
build: createBuildList(true)
|
|
3720
|
+
}],
|
|
3862
3721
|
starts: [{
|
|
3863
3722
|
codes: [
|
|
3864
3723
|
42,
|
|
@@ -3883,7 +3742,7 @@ function feature$4(taskList = false) {
|
|
|
3883
3742
|
},
|
|
3884
3743
|
interrupt(source, lines, index, contentOffset) {
|
|
3885
3744
|
const marker = listMarkerAt(source, lines, index, contentOffset);
|
|
3886
|
-
return
|
|
3745
|
+
return marker?.hasContent === true && (marker.startNumber === 1 || marker.delimiter !== 46 && marker.delimiter !== 41);
|
|
3887
3746
|
},
|
|
3888
3747
|
start: taskList ? taskListStart : listStart
|
|
3889
3748
|
}]
|
|
@@ -3896,17 +3755,12 @@ const mathFenceRule = {
|
|
|
3896
3755
|
marker: 36,
|
|
3897
3756
|
minimumLength: 2
|
|
3898
3757
|
};
|
|
3899
|
-
const
|
|
3900
|
-
|
|
3901
|
-
syntax: {
|
|
3902
|
-
kind: "leaf",
|
|
3903
|
-
token: 28
|
|
3904
|
-
},
|
|
3758
|
+
const blockBuilds = [{
|
|
3759
|
+
token: 261,
|
|
3905
3760
|
build(tokenStart, context) {
|
|
3906
3761
|
const tokens = context.structure.tokens;
|
|
3907
|
-
const value = tokens.text(context.source, tokenStart);
|
|
3908
3762
|
const block = tokens.value(tokenStart);
|
|
3909
|
-
|
|
3763
|
+
const value = block.content ?? tokens.text(context.source, tokenStart);
|
|
3910
3764
|
return {
|
|
3911
3765
|
type: "math",
|
|
3912
3766
|
meta: semanticText(block.info) || null,
|
|
@@ -3927,7 +3781,7 @@ const blockStarts = [{
|
|
|
3927
3781
|
while (end < lines.length && !closesFence(source, lines, end, fence)) end++;
|
|
3928
3782
|
const closed = end < lines.length;
|
|
3929
3783
|
if (end < lines.length) end++;
|
|
3930
|
-
appendLogicalToken(out,
|
|
3784
|
+
appendLogicalToken(out, 261, source, lines, start, end, fencedBlock(source, lines, start, end, fence, closed));
|
|
3931
3785
|
return end;
|
|
3932
3786
|
}
|
|
3933
3787
|
}];
|
|
@@ -3955,17 +3809,17 @@ function createMathScanRule(singleDollarTextMath) {
|
|
|
3955
3809
|
}
|
|
3956
3810
|
}
|
|
3957
3811
|
if (end < 0) return openEnd;
|
|
3958
|
-
appendInlineToken(tokens,
|
|
3812
|
+
appendInlineToken(tokens, 134, start, end, markerLength);
|
|
3959
3813
|
return end;
|
|
3960
3814
|
}
|
|
3961
3815
|
};
|
|
3962
3816
|
}
|
|
3963
3817
|
const inlineBuilds = [{
|
|
3964
3818
|
kind: "leaf",
|
|
3965
|
-
token:
|
|
3819
|
+
token: 134,
|
|
3966
3820
|
build(tokenIndex, sourceSpan, context) {
|
|
3967
3821
|
const markerLength = inlineTokenData(context.tokens, tokenIndex);
|
|
3968
|
-
let value = inlineTokenText(context.view.text, context.tokens, tokenIndex
|
|
3822
|
+
let value = inlineTokenText(context.view.text, context.tokens, tokenIndex, markerLength);
|
|
3969
3823
|
const startPadding = value.startsWith("\r\n") ? 2 : /^[ \r\n]/.test(value) ? 1 : 0;
|
|
3970
3824
|
const endPadding = value.endsWith("\r\n") ? 2 : /[ \r\n]$/.test(value) ? 1 : 0;
|
|
3971
3825
|
if (startPadding > 0 && endPadding > 0 && /[^ \r\n]/.test(value)) value = value.slice(startPadding, -endPadding);
|
|
@@ -3982,12 +3836,12 @@ function feature$3(options) {
|
|
|
3982
3836
|
const singleDollarTextMath = typeof options !== "object" || options.singleDollarTextMath !== false;
|
|
3983
3837
|
return {
|
|
3984
3838
|
block: {
|
|
3985
|
-
|
|
3839
|
+
builds: blockBuilds,
|
|
3986
3840
|
starts: blockStarts
|
|
3987
3841
|
},
|
|
3988
3842
|
inline: {
|
|
3989
|
-
|
|
3990
|
-
|
|
3843
|
+
scans: [createMathScanRule(singleDollarTextMath)],
|
|
3844
|
+
builds: inlineBuilds
|
|
3991
3845
|
}
|
|
3992
3846
|
};
|
|
3993
3847
|
}
|
|
@@ -3997,44 +3851,37 @@ const feature$2 = { block: {
|
|
|
3997
3851
|
fallbacks: [(source, lines, start, contentOffset, out, context) => {
|
|
3998
3852
|
const openToken = out.length;
|
|
3999
3853
|
const offset = lines.start(start);
|
|
4000
|
-
out.push(
|
|
3854
|
+
out.push(99, offset, offset);
|
|
4001
3855
|
let chunkOffset = contentOffset;
|
|
4002
3856
|
let index = start + 1;
|
|
4003
3857
|
while (index < lines.length) {
|
|
4004
|
-
const
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
const setext = setextMarkerAt(source, lines, index,
|
|
3858
|
+
const lineEnd = lines.end(index);
|
|
3859
|
+
const contentStart = skipLineWhitespace(source, lines.start(index), lineEnd);
|
|
3860
|
+
if (contentStart === lineEnd) break;
|
|
3861
|
+
const chunkStart = indentOffset(source, lines, index);
|
|
3862
|
+
if (!lines.lazy(index) && chunkStart === contentStart) {
|
|
3863
|
+
const setext = setextMarkerAt(source, lines, index, contentStart);
|
|
4010
3864
|
if (setext) {
|
|
4011
|
-
out.setKind(openToken, setext === "=" ?
|
|
3865
|
+
out.setKind(openToken, setext === "=" ? 97 : 98);
|
|
4012
3866
|
out.push(1, chunkOffset, lines.end(index - 1));
|
|
4013
|
-
|
|
4014
|
-
out.push(8, lineEnd, lineEnd);
|
|
3867
|
+
out.push(193, lineEnd, lineEnd);
|
|
4015
3868
|
return index + 1;
|
|
4016
3869
|
}
|
|
4017
|
-
if (context.startsInterruptingBlock(source, lines, index,
|
|
3870
|
+
if (context.startsInterruptingBlock(source, lines, index, contentStart)) break;
|
|
4018
3871
|
}
|
|
4019
3872
|
out.push(1, chunkOffset, lines.next(index - 1));
|
|
4020
|
-
chunkOffset =
|
|
3873
|
+
chunkOffset = chunkStart;
|
|
4021
3874
|
index++;
|
|
4022
3875
|
}
|
|
4023
3876
|
const close = lines.end(index - 1);
|
|
4024
3877
|
out.push(1, chunkOffset, close);
|
|
4025
|
-
out.push(
|
|
3878
|
+
out.push(194, close, close);
|
|
4026
3879
|
return index;
|
|
4027
3880
|
}],
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
syntax: {
|
|
4031
|
-
kind: "block",
|
|
4032
|
-
open: 9,
|
|
4033
|
-
close: 10
|
|
4034
|
-
},
|
|
4035
|
-
inlineContent: true,
|
|
3881
|
+
builds: [{
|
|
3882
|
+
token: 99,
|
|
4036
3883
|
build(tokenStart, context) {
|
|
4037
|
-
const inline = buildInlineFragment(tokenStart,
|
|
3884
|
+
const inline = buildInlineFragment(tokenStart, false, context);
|
|
4038
3885
|
const result = {
|
|
4039
3886
|
type: "paragraph",
|
|
4040
3887
|
children: inline.children,
|
|
@@ -4050,15 +3897,16 @@ const feature$2 = { block: {
|
|
|
4050
3897
|
} };
|
|
4051
3898
|
//#endregion
|
|
4052
3899
|
//#region src/profile/features/reference.ts
|
|
4053
|
-
function linkDefinitionFields(tokens, token) {
|
|
4054
|
-
const fields = tokens.value(token);
|
|
4055
|
-
if (tokens.kind(token) !== 22 || !fields) throw new Error("Expected LinkDefinitionOpen token to contain parsed fields");
|
|
4056
|
-
return fields;
|
|
4057
|
-
}
|
|
4058
3900
|
function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
|
|
3901
|
+
let offset = contentOffset + 1;
|
|
3902
|
+
const labelClose = source.indexOf("]", offset);
|
|
3903
|
+
if (labelClose >= 0 && labelClose < lines.end(startIndex) && source.charCodeAt(labelClose + 1) !== 58) {
|
|
3904
|
+
let escapeStart = labelClose;
|
|
3905
|
+
while (escapeStart > offset && source.charCodeAt(escapeStart - 1) === 92) escapeStart--;
|
|
3906
|
+
if ((labelClose - escapeStart & 1) === 0) return;
|
|
3907
|
+
}
|
|
4059
3908
|
let lineIndex = startIndex;
|
|
4060
3909
|
let lookaheadEnd = -1;
|
|
4061
|
-
let offset = contentOffset + 1;
|
|
4062
3910
|
let label = "";
|
|
4063
3911
|
let labelLength = 0;
|
|
4064
3912
|
let labelHasContent = false;
|
|
@@ -4085,7 +3933,7 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
|
|
|
4085
3933
|
}
|
|
4086
3934
|
const nextLine = lineIndex + 1;
|
|
4087
3935
|
lookaheadEnd = nextLine < lines.length ? lines.end(nextLine) : lines.next(lineIndex);
|
|
4088
|
-
if (nextLine >= lines.length ||
|
|
3936
|
+
if (nextLine >= lines.length || isBlankLine(source, lines, nextLine)) break parseDefinition;
|
|
4089
3937
|
if (++labelLength > 999) break parseDefinition;
|
|
4090
3938
|
label += source.slice(labelStart, lines.next(lineIndex));
|
|
4091
3939
|
lineIndex++;
|
|
@@ -4095,19 +3943,16 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
|
|
|
4095
3943
|
label += source.slice(labelStart, offset);
|
|
4096
3944
|
if (!labelHasContent) break parseDefinition;
|
|
4097
3945
|
offset += 2;
|
|
4098
|
-
const skipSpaces = (lineEnd) => {
|
|
4099
|
-
while (offset < lineEnd && (source[offset] === " " || source[offset] === " ")) offset++;
|
|
4100
|
-
};
|
|
4101
3946
|
let lineEnd = lines.end(lineIndex);
|
|
4102
|
-
|
|
3947
|
+
offset = skipLineWhitespace(source, offset, lineEnd);
|
|
4103
3948
|
if (offset === lineEnd) {
|
|
4104
3949
|
const nextLine = lineIndex + 1;
|
|
4105
3950
|
lookaheadEnd = nextLine < lines.length ? lines.end(nextLine) : lines.next(lineIndex);
|
|
4106
|
-
if (nextLine >= lines.length ||
|
|
3951
|
+
if (nextLine >= lines.length || isBlankLine(source, lines, nextLine)) break parseDefinition;
|
|
4107
3952
|
lineIndex++;
|
|
4108
3953
|
offset = lines.start(lineIndex);
|
|
4109
3954
|
lineEnd = lines.end(lineIndex);
|
|
4110
|
-
|
|
3955
|
+
offset = skipLineWhitespace(source, offset, lineEnd);
|
|
4111
3956
|
}
|
|
4112
3957
|
let destination;
|
|
4113
3958
|
if (source[offset] === "<") {
|
|
@@ -4141,14 +3986,14 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
|
|
|
4141
3986
|
}
|
|
4142
3987
|
const destinationLine = lineIndex;
|
|
4143
3988
|
if (offset < lineEnd && source[offset] !== " " && source[offset] !== " ") break parseDefinition;
|
|
4144
|
-
|
|
3989
|
+
offset = skipLineWhitespace(source, offset, lineEnd);
|
|
4145
3990
|
let titleOnNextLine = false;
|
|
4146
3991
|
if (offset === lineEnd && lineIndex + 1 < lines.length) {
|
|
4147
3992
|
lookaheadEnd = lines.end(lineIndex + 1);
|
|
4148
3993
|
lineIndex++;
|
|
4149
3994
|
offset = lines.start(lineIndex);
|
|
4150
3995
|
lineEnd = lines.end(lineIndex);
|
|
4151
|
-
|
|
3996
|
+
offset = skipLineWhitespace(source, offset, lineEnd);
|
|
4152
3997
|
titleOnNextLine = true;
|
|
4153
3998
|
}
|
|
4154
3999
|
const closer = source[offset] === "(" ? ")" : source[offset] === "\"" || source[offset] === "'" ? source[offset] : void 0;
|
|
@@ -4185,14 +4030,14 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
|
|
|
4185
4030
|
if (closed) break;
|
|
4186
4031
|
const nextLine = lineIndex + 1;
|
|
4187
4032
|
lookaheadEnd = nextLine < lines.length ? lines.end(nextLine) : lines.next(lineIndex);
|
|
4188
|
-
if (nextLine >= lines.length ||
|
|
4033
|
+
if (nextLine >= lines.length || isBlankLine(source, lines, nextLine)) break;
|
|
4189
4034
|
title += source.slice(titleStart, lines.next(lineIndex));
|
|
4190
4035
|
lineIndex++;
|
|
4191
4036
|
offset = lines.start(lineIndex);
|
|
4192
4037
|
titleStart = offset;
|
|
4193
4038
|
}
|
|
4194
4039
|
if (closed) {
|
|
4195
|
-
|
|
4040
|
+
offset = skipLineWhitespace(source, offset, lineEnd);
|
|
4196
4041
|
if (offset === lineEnd) {
|
|
4197
4042
|
fields.title = title;
|
|
4198
4043
|
return {
|
|
@@ -4213,21 +4058,14 @@ function linkDefinitionAt(source, lines, startIndex, contentOffset, context) {
|
|
|
4213
4058
|
if (lookaheadEnd >= 0) context.retainLookahead(lookaheadEnd);
|
|
4214
4059
|
}
|
|
4215
4060
|
const feature$1 = { block: {
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
syntax: {
|
|
4219
|
-
kind: "block",
|
|
4220
|
-
open: 22,
|
|
4221
|
-
close: 24
|
|
4222
|
-
},
|
|
4061
|
+
builds: [{
|
|
4062
|
+
token: 67,
|
|
4223
4063
|
build(tokenStart, context) {
|
|
4224
4064
|
const tokens = context.structure.tokens;
|
|
4225
|
-
const fields =
|
|
4226
|
-
const definitionKey = tokens.definitionKey(tokenStart);
|
|
4227
|
-
if (definitionKey === void 0) throw new Error("Expected LinkDefinitionOpen token to contain a definition key");
|
|
4065
|
+
const fields = tokens.value(tokenStart);
|
|
4228
4066
|
return {
|
|
4229
4067
|
type: "definition",
|
|
4230
|
-
identifier: definitionKey,
|
|
4068
|
+
identifier: tokens.definitionKey(tokenStart),
|
|
4231
4069
|
label: semanticText(fields.label),
|
|
4232
4070
|
url: semanticText(fields.destination),
|
|
4233
4071
|
title: fields.title === void 0 ? null : semanticText(fields.title),
|
|
@@ -4240,16 +4078,16 @@ const feature$1 = { block: {
|
|
|
4240
4078
|
start(source, lines, start, contentOffset, out, context) {
|
|
4241
4079
|
const definition = linkDefinitionAt(source, lines, start, contentOffset, context);
|
|
4242
4080
|
if (!definition) return;
|
|
4243
|
-
out.push(
|
|
4081
|
+
out.push(67, contentOffset, contentOffset, {
|
|
4244
4082
|
definitionKey: definition.definitionKey,
|
|
4245
4083
|
value: definition.fields
|
|
4246
4084
|
});
|
|
4247
4085
|
let definitionEnd = contentOffset;
|
|
4248
4086
|
for (let definitionLine = start; definitionLine < definition.end; definitionLine++) {
|
|
4249
4087
|
definitionEnd = definitionLine + 1 < definition.end ? lines.next(definitionLine) : lines.end(definitionLine);
|
|
4250
|
-
out.push(
|
|
4088
|
+
out.push(2, lines.start(definitionLine), definitionEnd);
|
|
4251
4089
|
}
|
|
4252
|
-
out.push(
|
|
4090
|
+
out.push(198, definitionEnd, definitionEnd);
|
|
4253
4091
|
return definition.end;
|
|
4254
4092
|
}
|
|
4255
4093
|
}]
|
|
@@ -4257,11 +4095,7 @@ const feature$1 = { block: {
|
|
|
4257
4095
|
//#endregion
|
|
4258
4096
|
//#region src/profile/features/table.ts
|
|
4259
4097
|
function appendTableCell(cells, source, start, contentStart, contentEnd) {
|
|
4260
|
-
|
|
4261
|
-
const code = source.charCodeAt(contentStart);
|
|
4262
|
-
if (code !== 32 && code !== 9) break;
|
|
4263
|
-
contentStart++;
|
|
4264
|
-
}
|
|
4098
|
+
contentStart = skipLineWhitespace(source, contentStart, contentEnd);
|
|
4265
4099
|
while (contentEnd > contentStart) {
|
|
4266
4100
|
const code = source.charCodeAt(contentEnd - 1);
|
|
4267
4101
|
if (code !== 32 && code !== 9) break;
|
|
@@ -4318,7 +4152,7 @@ function alignmentAt(source, cells, cell) {
|
|
|
4318
4152
|
if (right) end--;
|
|
4319
4153
|
if (start === end) return;
|
|
4320
4154
|
for (let offset = start; offset < end; offset++) if (source.charCodeAt(offset) !== 45) return;
|
|
4321
|
-
return left ? right ?
|
|
4155
|
+
return left ? right ? 323 : 321 : right ? 322 : 320;
|
|
4322
4156
|
}
|
|
4323
4157
|
function delimiterAt(source, lines, index, contentOffset) {
|
|
4324
4158
|
const first = source.charCodeAt(contentOffset);
|
|
@@ -4333,21 +4167,21 @@ function delimiterAt(source, lines, index, contentOffset) {
|
|
|
4333
4167
|
return cells;
|
|
4334
4168
|
}
|
|
4335
4169
|
function emitTableRow(lines, index, cells, out) {
|
|
4336
|
-
out.push(
|
|
4170
|
+
out.push(131, cells[0], cells[0]);
|
|
4337
4171
|
for (let cell = 0; cell < cells.length; cell += 3) {
|
|
4338
4172
|
const start = cells[cell];
|
|
4339
|
-
out.push(
|
|
4340
|
-
out.push(1, cells[cell + 1], cells[cell + 2]);
|
|
4173
|
+
out.push(160, start, start);
|
|
4174
|
+
out.push(1, cells[cell + 1], cells[cell + 2], void 0, 192);
|
|
4341
4175
|
}
|
|
4342
4176
|
const lineEnd = lines.end(index);
|
|
4343
|
-
out.push(
|
|
4177
|
+
out.push(201, lineEnd, lineEnd);
|
|
4344
4178
|
}
|
|
4345
4179
|
const buildTableCell = (tokenStart, context) => {
|
|
4346
4180
|
const tokens = context.structure.tokens;
|
|
4347
4181
|
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
4348
4182
|
return {
|
|
4349
4183
|
type: "tableCell",
|
|
4350
|
-
children: buildInlineFragment(tokenStart,
|
|
4184
|
+
children: buildInlineFragment(tokenStart, true, context).children,
|
|
4351
4185
|
position: {
|
|
4352
4186
|
start,
|
|
4353
4187
|
end: context.locator.locationAt(tokens.start(tokenStart + tokens.nodeLength(tokenStart)))
|
|
@@ -4359,7 +4193,7 @@ const buildTableRow = (tokenStart, context) => {
|
|
|
4359
4193
|
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
4360
4194
|
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
4361
4195
|
const children = [];
|
|
4362
|
-
for (let cell = tokenStart + 1; cell < close; cell += tokens.nodeLength(cell)) children.push(
|
|
4196
|
+
for (let cell = tokenStart + 1; cell < close; cell += tokens.nodeLength(cell)) children.push(buildTableCell(cell, context));
|
|
4363
4197
|
return {
|
|
4364
4198
|
type: "tableRow",
|
|
4365
4199
|
children,
|
|
@@ -4375,7 +4209,7 @@ function tableAlignment(tokenStart, context) {
|
|
|
4375
4209
|
const result = [];
|
|
4376
4210
|
for (let token = tokenStart; token < tokenEnd; token++) {
|
|
4377
4211
|
const kind = tokens.kind(token);
|
|
4378
|
-
result.push(kind ===
|
|
4212
|
+
result.push(kind === 321 ? "left" : kind === 322 ? "right" : kind === 323 ? "center" : null);
|
|
4379
4213
|
}
|
|
4380
4214
|
return result;
|
|
4381
4215
|
}
|
|
@@ -4389,13 +4223,12 @@ const feature = { block: {
|
|
|
4389
4223
|
if (!delimiter) return;
|
|
4390
4224
|
const header = tableCellsAt(source, lines, start, true, contentOffset);
|
|
4391
4225
|
if (header?.length !== delimiter.length) return;
|
|
4392
|
-
out.push(
|
|
4226
|
+
out.push(69, header[0], header[0]);
|
|
4393
4227
|
emitTableRow(lines, start, header, out);
|
|
4394
4228
|
const delimiterEnd = lines.end(delimiterLine);
|
|
4395
4229
|
for (let cell = 0; cell < delimiter.length; cell += 3) out.push(delimiter[cell + 1], delimiter[cell], delimiter[cell + 3] ?? delimiterEnd);
|
|
4396
4230
|
let end = start + 2;
|
|
4397
4231
|
while (end < lines.length) {
|
|
4398
|
-
if (isBlank(source, lines, end)) break;
|
|
4399
4232
|
const contentOffset = lineIndentOffset(source, lines, end);
|
|
4400
4233
|
if (contentOffset < 0 || context.startsInterruptingBlock(source, lines, end, contentOffset)) break;
|
|
4401
4234
|
const cells = tableCellsAt(source, lines, end, false, contentOffset);
|
|
@@ -4404,68 +4237,30 @@ const feature = { block: {
|
|
|
4404
4237
|
end++;
|
|
4405
4238
|
}
|
|
4406
4239
|
const tableEnd = lines.end(end - 1);
|
|
4407
|
-
out.push(
|
|
4240
|
+
out.push(200, tableEnd, tableEnd);
|
|
4408
4241
|
return end;
|
|
4409
4242
|
}],
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
},
|
|
4430
|
-
{
|
|
4431
|
-
rule: 18,
|
|
4432
|
-
syntax: {
|
|
4433
|
-
kind: "group",
|
|
4434
|
-
tokens: [
|
|
4435
|
-
34,
|
|
4436
|
-
35,
|
|
4437
|
-
36,
|
|
4438
|
-
37
|
|
4439
|
-
]
|
|
4440
|
-
}
|
|
4441
|
-
},
|
|
4442
|
-
{
|
|
4443
|
-
rule: 15,
|
|
4444
|
-
syntax: {
|
|
4445
|
-
kind: "block",
|
|
4446
|
-
open: 29,
|
|
4447
|
-
close: 30
|
|
4448
|
-
},
|
|
4449
|
-
build(tokenStart, context) {
|
|
4450
|
-
const tokens = context.structure.tokens;
|
|
4451
|
-
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
4452
|
-
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
4453
|
-
const header = tokenStart + 1;
|
|
4454
|
-
const delimiter = header + tokens.nodeLength(header);
|
|
4455
|
-
const rows = [buildBlockNode(header, context)];
|
|
4456
|
-
for (let row = delimiter + tokens.nodeLength(delimiter); row < close; row += tokens.nodeLength(row)) rows.push(buildBlockNode(row, context));
|
|
4457
|
-
return {
|
|
4458
|
-
type: "table",
|
|
4459
|
-
align: tableAlignment(delimiter, context),
|
|
4460
|
-
children: rows,
|
|
4461
|
-
position: {
|
|
4462
|
-
start,
|
|
4463
|
-
end: context.locator.locationAt(tokens.start(close))
|
|
4464
|
-
}
|
|
4465
|
-
};
|
|
4466
|
-
}
|
|
4243
|
+
builds: [{
|
|
4244
|
+
token: 69,
|
|
4245
|
+
build(tokenStart, context) {
|
|
4246
|
+
const tokens = context.structure.tokens;
|
|
4247
|
+
const close = tokenStart + tokens.nodeLength(tokenStart) - 1;
|
|
4248
|
+
const start = context.locator.locationAt(tokens.start(tokenStart));
|
|
4249
|
+
const header = tokenStart + 1;
|
|
4250
|
+
const delimiter = header + tokens.nodeLength(header);
|
|
4251
|
+
const rows = [buildTableRow(header, context)];
|
|
4252
|
+
for (let row = delimiter + tokens.nodeLength(delimiter); row < close; row += tokens.nodeLength(row)) rows.push(buildTableRow(row, context));
|
|
4253
|
+
return {
|
|
4254
|
+
type: "table",
|
|
4255
|
+
align: tableAlignment(delimiter, context),
|
|
4256
|
+
children: rows,
|
|
4257
|
+
position: {
|
|
4258
|
+
start,
|
|
4259
|
+
end: context.locator.locationAt(tokens.start(close))
|
|
4260
|
+
}
|
|
4261
|
+
};
|
|
4467
4262
|
}
|
|
4468
|
-
]
|
|
4263
|
+
}]
|
|
4469
4264
|
} };
|
|
4470
4265
|
//#endregion
|
|
4471
4266
|
//#region src/inline/delimiter.ts
|
|
@@ -4507,19 +4302,13 @@ function unlinkRun(runs, runIndex) {
|
|
|
4507
4302
|
if (run.previous >= 0) runs[run.previous].next = run.next;
|
|
4508
4303
|
if (run.next >= 0) runs[run.next].previous = run.previous;
|
|
4509
4304
|
}
|
|
4510
|
-
function
|
|
4511
|
-
const tokenReplacements = replacements[tokenIndex];
|
|
4512
|
-
if (tokenReplacements) tokenReplacements.push(replacement);
|
|
4513
|
-
else replacements[tokenIndex] = [replacement];
|
|
4514
|
-
}
|
|
4515
|
-
function matchDelimiterRuns(runs, first, replacements) {
|
|
4305
|
+
function resolveDelimiterScope(runs, first, replacements = []) {
|
|
4516
4306
|
const openersBottom = [];
|
|
4517
4307
|
let current = first;
|
|
4518
4308
|
while (current >= 0) {
|
|
4519
4309
|
const closer = runs[current];
|
|
4520
4310
|
const next = closer.next;
|
|
4521
4311
|
if (!(closer.state & 2)) {
|
|
4522
|
-
if ((closer.state & 3) === 0) unlinkRun(runs, current);
|
|
4523
4312
|
current = next;
|
|
4524
4313
|
continue;
|
|
4525
4314
|
}
|
|
@@ -4544,12 +4333,12 @@ function matchDelimiterRuns(runs, first, replacements) {
|
|
|
4544
4333
|
const closeStart = closer.start;
|
|
4545
4334
|
const closeEnd = closeStart + use;
|
|
4546
4335
|
const pair = use === 2 ? closer.config.double : closer.config.single;
|
|
4547
|
-
|
|
4336
|
+
(replacements[opener.tokenIndex] ??= []).push({
|
|
4548
4337
|
offset: openStart,
|
|
4549
4338
|
end: openEnd,
|
|
4550
4339
|
kind: pair.open
|
|
4551
4340
|
});
|
|
4552
|
-
|
|
4341
|
+
(replacements[closer.tokenIndex] ??= []).push({
|
|
4553
4342
|
offset: closeStart,
|
|
4554
4343
|
end: closeEnd,
|
|
4555
4344
|
kind: pair.close
|
|
@@ -4565,16 +4354,15 @@ function matchDelimiterRuns(runs, first, replacements) {
|
|
|
4565
4354
|
current = next;
|
|
4566
4355
|
}
|
|
4567
4356
|
}
|
|
4357
|
+
return replacements;
|
|
4568
4358
|
}
|
|
4569
|
-
function delimiterRunAt(source, tokens, tokenIndex,
|
|
4570
|
-
const config = configByKind[inlineTokenKind(tokens, tokenIndex)];
|
|
4571
|
-
if (!config) return;
|
|
4359
|
+
function delimiterRunAt(source, tokens, tokenIndex, config) {
|
|
4572
4360
|
const offset = inlineTokenStart(tokens, tokenIndex);
|
|
4573
4361
|
const end = inlineTokenEnd(tokens, tokenIndex);
|
|
4574
4362
|
const length = end - offset;
|
|
4575
4363
|
if (config.bits & 2 && (length > 2 || (length === 1 ? !config.single : !config.double))) return;
|
|
4576
4364
|
const delimiterFlanking = flanking(source, offset, end, config);
|
|
4577
|
-
if (
|
|
4365
|
+
if (delimiterFlanking !== 0) return {
|
|
4578
4366
|
tokenIndex,
|
|
4579
4367
|
config,
|
|
4580
4368
|
start: offset,
|
|
@@ -4584,11 +4372,6 @@ function delimiterRunAt(source, tokens, tokenIndex, configByKind) {
|
|
|
4584
4372
|
state: delimiterFlanking | length % 3 << 2
|
|
4585
4373
|
};
|
|
4586
4374
|
}
|
|
4587
|
-
function resolveDelimiterMatches(runs) {
|
|
4588
|
-
const replacements = [];
|
|
4589
|
-
for (let runIndex = runs.length - 1; runIndex >= 0; runIndex--) if (runs[runIndex].previous < 0) matchDelimiterRuns(runs, runIndex, replacements);
|
|
4590
|
-
return replacements;
|
|
4591
|
-
}
|
|
4592
4375
|
function appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements) {
|
|
4593
4376
|
const matched = replacements[tokenIndex];
|
|
4594
4377
|
if (!matched) {
|
|
@@ -4620,62 +4403,27 @@ function compileDelimiterConfigs(delimiterConfigs) {
|
|
|
4620
4403
|
//#endregion
|
|
4621
4404
|
//#region src/profile/resolve.ts
|
|
4622
4405
|
const frameHeaderSize = 1;
|
|
4623
|
-
const noBracketFrames =
|
|
4624
|
-
const delimiterOnlyFrames = Object.freeze([2]);
|
|
4406
|
+
const noBracketFrames = [0];
|
|
4625
4407
|
const noDelimiterReplacements = [];
|
|
4626
|
-
function
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
if (last >= 0) frames[last + 4] = candidate;
|
|
4636
|
-
else frames[owner + 2] = candidate;
|
|
4637
|
-
frames[owner + 3] = candidate;
|
|
4638
|
-
}
|
|
4639
|
-
function promoteCandidates(frames, owner, source) {
|
|
4640
|
-
if (owner < 0) return;
|
|
4641
|
-
const first = frames[source + 2];
|
|
4642
|
-
if (first < 0) return;
|
|
4643
|
-
const last = frames[source + 3];
|
|
4644
|
-
const ownerLast = frames[owner + 3];
|
|
4645
|
-
if (ownerLast >= 0) frames[ownerLast + 4] = first;
|
|
4646
|
-
else frames[owner + 2] = first;
|
|
4647
|
-
frames[owner + 3] = last;
|
|
4648
|
-
}
|
|
4649
|
-
function rewriteLinkCandidates(frames, owner) {
|
|
4650
|
-
let candidate = frames[owner + 2];
|
|
4651
|
-
frames[owner + 2] = -1;
|
|
4652
|
-
frames[owner + 3] = -1;
|
|
4653
|
-
while (candidate >= 0) {
|
|
4654
|
-
const next = frames[candidate + 4];
|
|
4655
|
-
rewriteLinkCandidates(frames, candidate);
|
|
4408
|
+
function setFrameState(frames, frame, state) {
|
|
4409
|
+
frames[frame + 5] = state;
|
|
4410
|
+
frames[0] = 1;
|
|
4411
|
+
}
|
|
4412
|
+
function rewriteLinkCandidates(frames, top, bottom) {
|
|
4413
|
+
let candidate = top;
|
|
4414
|
+
top = bottom;
|
|
4415
|
+
while (candidate !== bottom) {
|
|
4416
|
+
const next = frames[candidate + 3];
|
|
4656
4417
|
const state = frames[candidate + 5];
|
|
4657
|
-
if (
|
|
4658
|
-
|
|
4659
|
-
promoteCandidates(frames, owner, candidate);
|
|
4660
|
-
} else {
|
|
4418
|
+
if (state === 3) frames[candidate + 5] = 0;
|
|
4419
|
+
else {
|
|
4661
4420
|
frames[candidate + 5] = state | 16;
|
|
4662
|
-
|
|
4421
|
+
frames[candidate + 3] = top;
|
|
4422
|
+
top = candidate;
|
|
4663
4423
|
}
|
|
4664
4424
|
candidate = next;
|
|
4665
4425
|
}
|
|
4666
|
-
|
|
4667
|
-
function allocateFrame(frames, openToken, parent) {
|
|
4668
|
-
const frame = frames.length;
|
|
4669
|
-
frames.push(openToken, -1, -1, -1, parent, 0, 0);
|
|
4670
|
-
return frame;
|
|
4671
|
-
}
|
|
4672
|
-
function isImageFrame(tokens, frames, frame) {
|
|
4673
|
-
return inlineTokenKind(tokens, frames[frame + 0]) === 19;
|
|
4674
|
-
}
|
|
4675
|
-
function hasAdjacentComponent(tokens, frames, frame) {
|
|
4676
|
-
const openToken = frames[frame + 0];
|
|
4677
|
-
const componentToken = openToken - 1;
|
|
4678
|
-
return componentToken >= 0 && inlineTokenKind(tokens, componentToken) === 32 && inlineTokenEnd(tokens, componentToken) === inlineTokenStart(tokens, openToken);
|
|
4426
|
+
return top;
|
|
4679
4427
|
}
|
|
4680
4428
|
function referenceLabelEnd(source, start) {
|
|
4681
4429
|
if (source.charCodeAt(start) !== 91) return -1;
|
|
@@ -4692,7 +4440,7 @@ function referenceLabelEnd(source, start) {
|
|
|
4692
4440
|
hasContent = true;
|
|
4693
4441
|
offset += 2;
|
|
4694
4442
|
} else {
|
|
4695
|
-
hasContent ||= code
|
|
4443
|
+
hasContent ||= !isMarkdownWhitespace(code);
|
|
4696
4444
|
offset++;
|
|
4697
4445
|
}
|
|
4698
4446
|
characters++;
|
|
@@ -4704,7 +4452,7 @@ function acceptsShortcutLabel(source, start, end) {
|
|
|
4704
4452
|
let characters = 0;
|
|
4705
4453
|
for (let offset = start; offset < end; offset++) {
|
|
4706
4454
|
const code = source.charCodeAt(offset);
|
|
4707
|
-
hasContent ||= code
|
|
4455
|
+
hasContent ||= !isMarkdownWhitespace(code);
|
|
4708
4456
|
if (code >= 55296 && code <= 56319 && offset + 1 < end) {
|
|
4709
4457
|
const trailing = source.charCodeAt(offset + 1);
|
|
4710
4458
|
if (trailing >= 56320 && trailing <= 57343) offset++;
|
|
@@ -4713,73 +4461,60 @@ function acceptsShortcutLabel(source, start, end) {
|
|
|
4713
4461
|
}
|
|
4714
4462
|
return hasContent;
|
|
4715
4463
|
}
|
|
4716
|
-
function analyzeBrackets(source, tokens,
|
|
4717
|
-
let discovery = 0;
|
|
4464
|
+
function analyzeBrackets(source, tokens, definitions, options) {
|
|
4718
4465
|
let frames;
|
|
4466
|
+
let candidateTop = -1;
|
|
4719
4467
|
let stackTop = -1;
|
|
4720
4468
|
const count = inlineTokenCount(tokens);
|
|
4721
4469
|
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
4722
4470
|
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
4723
|
-
if (
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
stackTop =
|
|
4471
|
+
if (kind >= 71 && kind <= 72) {
|
|
4472
|
+
const arena = frames ??= [0];
|
|
4473
|
+
const frame = arena.length;
|
|
4474
|
+
arena.push(tokenIndex, -1, candidateTop, -1, stackTop, kind === 71 ? 8 : 0);
|
|
4475
|
+
stackTop = frame;
|
|
4728
4476
|
continue;
|
|
4729
4477
|
}
|
|
4730
|
-
if (kind
|
|
4478
|
+
if (kind < 73 || kind > 74) continue;
|
|
4731
4479
|
if (stackTop < 0) continue;
|
|
4732
4480
|
const frame = stackTop;
|
|
4733
4481
|
const arena = frames;
|
|
4734
|
-
|
|
4735
|
-
stackTop = parent;
|
|
4482
|
+
stackTop = arena[frame + 4];
|
|
4736
4483
|
arena[frame + 1] = tokenIndex;
|
|
4737
|
-
const image =
|
|
4738
|
-
if (options.footnote && kind ===
|
|
4484
|
+
const image = (arena[frame + 5] & 8) !== 0;
|
|
4485
|
+
if (options.footnote && kind === 74) {
|
|
4739
4486
|
const openToken = arena[frame + 0];
|
|
4740
4487
|
const label = footnoteLabelAt(source, inlineTokenStart(tokens, openToken) + (image ? 1 : 0), source.length);
|
|
4741
|
-
if (label && label.end === inlineTokenEnd(tokens, tokenIndex) &&
|
|
4742
|
-
|
|
4488
|
+
if (label && label.end === inlineTokenEnd(tokens, tokenIndex) && definitions.hasDefinition(label.definitionKey)) {
|
|
4489
|
+
setFrameState(arena, frame, 1);
|
|
4490
|
+
candidateTop = arena[frame + 2];
|
|
4743
4491
|
continue;
|
|
4744
4492
|
}
|
|
4745
4493
|
}
|
|
4746
|
-
if (!options.component) continue;
|
|
4747
|
-
if (
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
if (parent >= 0) appendCandidate(arena, parent, frame);
|
|
4755
|
-
continue;
|
|
4756
|
-
}
|
|
4757
|
-
const close = inlineTokenStart(tokens, tokenIndex);
|
|
4758
|
-
const trailing = source.charCodeAt(close + 1);
|
|
4759
|
-
if (trailing === 40 || trailing === 91) {
|
|
4760
|
-
promoteCandidates(arena, parent, frame);
|
|
4494
|
+
if (!options.component || image) continue;
|
|
4495
|
+
if (kind === 73) candidateTop = rewriteLinkCandidates(arena, candidateTop, arena[frame + 2]);
|
|
4496
|
+
const openToken = arena[frame + 0];
|
|
4497
|
+
const componentToken = openToken - 1;
|
|
4498
|
+
if (componentToken >= 0 && inlineTokenKind(tokens, componentToken) === 137 && inlineTokenEnd(tokens, componentToken) === inlineTokenStart(tokens, openToken)) {
|
|
4499
|
+
setFrameState(arena, frame, 2);
|
|
4500
|
+
arena[frame + 3] = candidateTop;
|
|
4501
|
+
candidateTop = frame;
|
|
4761
4502
|
continue;
|
|
4762
4503
|
}
|
|
4763
|
-
const
|
|
4764
|
-
const
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
const arena = frames;
|
|
4770
|
-
while (stackTop >= 0) {
|
|
4771
|
-
const frame = stackTop;
|
|
4772
|
-
stackTop = arena[frame + 4];
|
|
4773
|
-
promoteCandidates(arena, stackTop, frame);
|
|
4774
|
-
}
|
|
4504
|
+
const suffixStart = inlineTokenStart(tokens, tokenIndex) + 1;
|
|
4505
|
+
const trailing = source.charCodeAt(suffixStart);
|
|
4506
|
+
if (trailing === 40 || trailing === 91) continue;
|
|
4507
|
+
setFrameState(arena, frame, trailing === 123 && attributesEnd(source, suffixStart) !== void 0 ? 4 : 3);
|
|
4508
|
+
arena[frame + 3] = candidateTop;
|
|
4509
|
+
candidateTop = frame;
|
|
4775
4510
|
}
|
|
4776
|
-
|
|
4777
|
-
frames[0] = discovery;
|
|
4778
|
-
return frames;
|
|
4779
|
-
}
|
|
4780
|
-
return discovery & 2 ? delimiterOnlyFrames : noBracketFrames;
|
|
4511
|
+
return frames ?? noBracketFrames;
|
|
4781
4512
|
}
|
|
4782
|
-
function
|
|
4513
|
+
function resolvePairedSyntax(source, tokens, frames, definitions, delimiterByKind) {
|
|
4514
|
+
const hasDefinitions = frames.length > frameHeaderSize && definitions.hasDefinitions();
|
|
4515
|
+
let runs;
|
|
4516
|
+
let runCount = 0;
|
|
4517
|
+
let replacements;
|
|
4783
4518
|
let rawTop = -1;
|
|
4784
4519
|
let logicalTop = -1;
|
|
4785
4520
|
let frameCursor = frameHeaderSize;
|
|
@@ -4797,71 +4532,92 @@ function resolveReferences(source, tokens, frames, context) {
|
|
|
4797
4532
|
consumeFrames = false;
|
|
4798
4533
|
}
|
|
4799
4534
|
const consuming = consumedEnd >= 0;
|
|
4800
|
-
|
|
4535
|
+
const delimiter = delimiterByKind[kind];
|
|
4536
|
+
if (!consuming && delimiter) {
|
|
4537
|
+
const run = delimiterRunAt(source, tokens, tokenIndex, delimiter);
|
|
4538
|
+
if (run) {
|
|
4539
|
+
const arena = runs ??= [];
|
|
4540
|
+
const runIndex = runCount++;
|
|
4541
|
+
if (runIndex > 0) {
|
|
4542
|
+
run.previous = runIndex - 1;
|
|
4543
|
+
arena[runIndex - 1].next = runIndex;
|
|
4544
|
+
}
|
|
4545
|
+
arena[runIndex] = run;
|
|
4546
|
+
}
|
|
4547
|
+
}
|
|
4548
|
+
if (kind >= 71 && kind <= 72) {
|
|
4801
4549
|
const frame = frameCursor;
|
|
4802
|
-
frameCursor +=
|
|
4803
|
-
frames[frame + 2] = rawTop;
|
|
4550
|
+
frameCursor += 6;
|
|
4804
4551
|
rawTop = frame;
|
|
4805
4552
|
if (consuming) {
|
|
4806
|
-
if (consumeFrames)
|
|
4553
|
+
if (consumeFrames) setFrameState(frames, frame, 7);
|
|
4807
4554
|
continue;
|
|
4808
4555
|
}
|
|
4809
|
-
|
|
4556
|
+
frames[frame + 2] = runCount;
|
|
4557
|
+
const state = frames[frame + 5];
|
|
4558
|
+
const claim = state & 7;
|
|
4810
4559
|
if (claim === 1) {
|
|
4811
4560
|
const closeToken = frames[frame + 1];
|
|
4812
4561
|
consumedEnd = inlineTokenEnd(tokens, closeToken);
|
|
4813
4562
|
continue;
|
|
4814
4563
|
}
|
|
4815
|
-
if (claim
|
|
4816
|
-
if (
|
|
4564
|
+
if (claim >= 2 && claim <= 4) {
|
|
4565
|
+
if (state & 16) literalDepth++;
|
|
4566
|
+
continue;
|
|
4567
|
+
}
|
|
4568
|
+
if (literalDepth > 0 && !(kind === 71)) {
|
|
4569
|
+
frames[frame + 5] = state | 32;
|
|
4817
4570
|
continue;
|
|
4818
4571
|
}
|
|
4819
|
-
if (literalDepth > 0 && !(kind === 19)) continue;
|
|
4820
4572
|
frames[frame + 3] = logicalTop;
|
|
4821
4573
|
logicalTop = frame;
|
|
4822
4574
|
lastVisibleOpener = tokenIndex;
|
|
4823
4575
|
continue;
|
|
4824
4576
|
}
|
|
4825
|
-
if (kind
|
|
4577
|
+
if (kind < 73 || kind > 74) continue;
|
|
4826
4578
|
const rawFrame = rawTop;
|
|
4827
|
-
if (rawFrame >= 0) rawTop = frames[rawFrame +
|
|
4579
|
+
if (rawFrame >= 0) rawTop = frames[rawFrame + 4];
|
|
4828
4580
|
if (consuming) {
|
|
4829
|
-
if (consumeFrames && rawFrame >= 0)
|
|
4581
|
+
if (consumeFrames && rawFrame >= 0) setFrameState(frames, rawFrame, 7);
|
|
4830
4582
|
continue;
|
|
4831
4583
|
}
|
|
4832
|
-
const
|
|
4833
|
-
|
|
4584
|
+
const rawState = rawFrame < 0 ? 0 : frames[rawFrame + 5];
|
|
4585
|
+
const rawClaim = rawState & 7;
|
|
4586
|
+
let runStart = rawClaim >= 1 && rawClaim <= 4 ? frames[rawFrame + 2] : -1;
|
|
4587
|
+
if (runStart < 0 && (literalDepth <= 0 || rawFrame < 0 || (rawState & 8) !== 0)) {
|
|
4834
4588
|
const frame = logicalTop;
|
|
4835
|
-
if (frame >= 0)
|
|
4836
|
-
|
|
4589
|
+
if (frame >= 0) logicalTop = frames[frame + 3];
|
|
4590
|
+
if (frame >= 0 && (kind === 73 || hasDefinitions)) {
|
|
4837
4591
|
const openToken = frames[frame + 0];
|
|
4838
|
-
const image =
|
|
4839
|
-
if (
|
|
4592
|
+
const image = (frames[frame + 5] & 8) !== 0;
|
|
4593
|
+
if (image || openToken + 1 >= inactiveBefore) {
|
|
4840
4594
|
const contentStart = inlineTokenEnd(tokens, openToken);
|
|
4841
4595
|
const contentEnd = tokenStart;
|
|
4842
|
-
|
|
4596
|
+
const tokenEnd = inlineTokenEnd(tokens, tokenIndex);
|
|
4597
|
+
let closeEnd = tokenEnd;
|
|
4843
4598
|
let reference = false;
|
|
4844
|
-
let matched = kind ===
|
|
4599
|
+
let matched = kind === 73;
|
|
4845
4600
|
if (!matched) {
|
|
4846
4601
|
const labelEnd = referenceLabelEnd(source, closeEnd);
|
|
4847
4602
|
if (labelEnd > 0) {
|
|
4848
4603
|
const label = source.slice(closeEnd + 1, labelEnd - 1) || source.slice(contentStart, contentEnd);
|
|
4849
|
-
matched =
|
|
4604
|
+
matched = definitions.hasDefinition(normalizeAssociationLabel(label));
|
|
4850
4605
|
if (matched) {
|
|
4851
4606
|
closeEnd = labelEnd;
|
|
4852
4607
|
reference = true;
|
|
4853
4608
|
}
|
|
4854
|
-
} else if (lastVisibleOpener <= openToken && acceptsShortcutLabel(source, contentStart, contentEnd) &&
|
|
4609
|
+
} else if (lastVisibleOpener <= openToken && acceptsShortcutLabel(source, contentStart, contentEnd) && definitions.hasDefinition(normalizeAssociationLabel(source.slice(contentStart, contentEnd)))) {
|
|
4855
4610
|
matched = true;
|
|
4856
4611
|
reference = true;
|
|
4857
4612
|
}
|
|
4858
4613
|
}
|
|
4859
4614
|
if (matched) {
|
|
4860
|
-
|
|
4615
|
+
setFrameState(frames, frame, (reference ? 6 : 5) | (image ? 8 : 0));
|
|
4861
4616
|
frames[frame + 1] = tokenIndex;
|
|
4862
|
-
frames[frame +
|
|
4863
|
-
|
|
4864
|
-
if (
|
|
4617
|
+
runStart = frames[frame + 2];
|
|
4618
|
+
frames[frame + 2] = closeEnd;
|
|
4619
|
+
if (!image) inactiveBefore = openToken + 1;
|
|
4620
|
+
if (closeEnd > tokenEnd) {
|
|
4865
4621
|
consumedEnd = closeEnd;
|
|
4866
4622
|
consumeFrames = true;
|
|
4867
4623
|
}
|
|
@@ -4869,112 +4625,68 @@ function resolveReferences(source, tokens, frames, context) {
|
|
|
4869
4625
|
}
|
|
4870
4626
|
}
|
|
4871
4627
|
}
|
|
4872
|
-
if (
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
let runs;
|
|
4878
|
-
let activeTop = -1;
|
|
4879
|
-
let rootLastRun = -1;
|
|
4880
|
-
let frameCursor = frameHeaderSize;
|
|
4881
|
-
let skipEnd = -1;
|
|
4882
|
-
const count = inlineTokenCount(tokens);
|
|
4883
|
-
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
4884
|
-
while (activeTop >= 0 && frames[activeTop + 1] === tokenIndex) {
|
|
4885
|
-
const frame = activeTop;
|
|
4886
|
-
activeTop = frames[frame + 2];
|
|
4887
|
-
const resolvedEnd = frames[frame + 6];
|
|
4888
|
-
if (resolvedEnd > inlineTokenEnd(tokens, tokenIndex)) skipEnd = resolvedEnd;
|
|
4889
|
-
}
|
|
4890
|
-
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
4891
|
-
const tokenStart = inlineTokenStart(tokens, tokenIndex);
|
|
4892
|
-
if (skipEnd >= 0 && tokenStart >= skipEnd) skipEnd = -1;
|
|
4893
|
-
if (kind === 20 || kind === 19) {
|
|
4894
|
-
const frame = frameCursor;
|
|
4895
|
-
frameCursor += 7;
|
|
4896
|
-
const claim = frameClaim(frames, frame);
|
|
4897
|
-
if (claim === 1) {
|
|
4898
|
-
skipEnd = inlineTokenEnd(tokens, frames[frame + 1]);
|
|
4899
|
-
continue;
|
|
4900
|
-
}
|
|
4901
|
-
if (claim === 3 || claim === 4 || claim === 5 || claim === 2 && inlineTokenEnd(tokens, frames[frame + 0]) < inlineTokenStart(tokens, frames[frame + 1])) {
|
|
4902
|
-
workspace[frame + 2] = activeTop;
|
|
4903
|
-
activeTop = frame;
|
|
4904
|
-
workspace[frame + 4] = -1;
|
|
4905
|
-
}
|
|
4906
|
-
}
|
|
4907
|
-
if (skipEnd < 0) {
|
|
4908
|
-
const run = delimiterRunAt(source, tokens, tokenIndex, delimiterByKind);
|
|
4909
|
-
if (run) {
|
|
4910
|
-
const runIndex = runs?.length ?? 0;
|
|
4911
|
-
const previous = activeTop < 0 ? rootLastRun : frames[activeTop + 4];
|
|
4912
|
-
if (previous >= 0) {
|
|
4913
|
-
run.previous = previous;
|
|
4914
|
-
runs[previous].next = runIndex;
|
|
4915
|
-
}
|
|
4916
|
-
if (activeTop < 0) rootLastRun = runIndex;
|
|
4917
|
-
else workspace[activeTop + 4] = runIndex;
|
|
4918
|
-
(runs ??= []).push(run);
|
|
4628
|
+
if (rawState & 16) literalDepth--;
|
|
4629
|
+
if (runStart >= 0 && runCount > runStart) {
|
|
4630
|
+
if (runStart > 0) {
|
|
4631
|
+
runs[runStart].previous = -1;
|
|
4632
|
+
runs[runStart - 1].next = -1;
|
|
4919
4633
|
}
|
|
4634
|
+
replacements = resolveDelimiterScope(runs, runStart, replacements);
|
|
4635
|
+
runCount = runStart;
|
|
4920
4636
|
}
|
|
4921
4637
|
}
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
function hasBracketRewrite(frames) {
|
|
4925
|
-
for (let frame = frameHeaderSize; frame < frames.length; frame += 7) if (frameClaim(frames, frame) !== 0) return true;
|
|
4926
|
-
return false;
|
|
4638
|
+
if (runCount > 0) replacements = resolveDelimiterScope(runs, 0, replacements);
|
|
4639
|
+
return replacements;
|
|
4927
4640
|
}
|
|
4928
4641
|
function appendReferenceBoundary(result, tokens, frames, frame, close) {
|
|
4929
4642
|
const token = frames[frame + (close ? 1 : 0)];
|
|
4930
|
-
const
|
|
4931
|
-
const
|
|
4643
|
+
const state = frames[frame + 5];
|
|
4644
|
+
const kind = ((state & 7) === 6 ? 202 : 198) + (state & 8 ? 2 : 0) + (close ? 1 : 0);
|
|
4645
|
+
const end = close ? frames[frame + 2] : inlineTokenEnd(tokens, token);
|
|
4932
4646
|
appendInlineToken(result, kind, inlineTokenStart(tokens, token), end, inlineTokenData(tokens, token));
|
|
4933
4647
|
return end;
|
|
4934
4648
|
}
|
|
4935
4649
|
function emitResolvedTokens(tokens, frames, replacements) {
|
|
4936
|
-
const workspace = frames;
|
|
4937
4650
|
const result = [];
|
|
4938
4651
|
let rawTop = -1;
|
|
4939
4652
|
let referenceTop = -1;
|
|
4940
4653
|
let frameCursor = frameHeaderSize;
|
|
4941
4654
|
let skipEnd = -1;
|
|
4942
|
-
let literalDepth = 0;
|
|
4943
4655
|
const count = inlineTokenCount(tokens);
|
|
4944
4656
|
for (let tokenIndex = 0; tokenIndex < count; tokenIndex++) {
|
|
4945
4657
|
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
4946
4658
|
const tokenStart = inlineTokenStart(tokens, tokenIndex);
|
|
4947
4659
|
if (skipEnd >= 0 && tokenStart >= skipEnd) skipEnd = -1;
|
|
4948
4660
|
const skipping = skipEnd >= 0;
|
|
4949
|
-
if (kind
|
|
4661
|
+
if (kind >= 71 && kind <= 72) {
|
|
4950
4662
|
const frame = frameCursor;
|
|
4951
|
-
frameCursor +=
|
|
4952
|
-
workspace[frame + 2] = rawTop;
|
|
4663
|
+
frameCursor += 6;
|
|
4953
4664
|
rawTop = frame;
|
|
4954
|
-
const
|
|
4665
|
+
const state = frames[frame + 5];
|
|
4666
|
+
const claim = state & 7;
|
|
4955
4667
|
if (!skipping) {
|
|
4956
4668
|
if (claim === 1) {
|
|
4957
4669
|
const closeToken = frames[frame + 1];
|
|
4958
|
-
const start = inlineTokenStart(tokens, tokenIndex) + (kind ===
|
|
4670
|
+
const start = inlineTokenStart(tokens, tokenIndex) + (kind === 71 ? 1 : 0);
|
|
4959
4671
|
skipEnd = inlineTokenEnd(tokens, closeToken);
|
|
4960
|
-
appendInlineToken(result,
|
|
4672
|
+
appendInlineToken(result, 133, start, skipEnd);
|
|
4961
4673
|
} else if (claim === 2) {
|
|
4962
4674
|
const closeToken = frames[frame + 1];
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
else if (claim
|
|
4675
|
+
const openEnd = inlineTokenEnd(tokens, tokenIndex);
|
|
4676
|
+
if (openEnd < inlineTokenStart(tokens, closeToken)) rewriteInlineTokenTail(result, 208, openEnd);
|
|
4677
|
+
} else if (claim >= 3 && claim <= 4) appendInlineToken(result, 206, inlineTokenStart(tokens, tokenIndex), inlineTokenEnd(tokens, tokenIndex));
|
|
4678
|
+
else if (claim === 5 || claim === 6) {
|
|
4966
4679
|
appendReferenceBoundary(result, tokens, frames, frame, false);
|
|
4967
|
-
|
|
4680
|
+
frames[frame + 3] = referenceTop;
|
|
4968
4681
|
referenceTop = frame;
|
|
4969
|
-
} else if (claim ===
|
|
4970
|
-
else if (!(
|
|
4682
|
+
} else if (claim === 7) skipEnd = inlineTokenEnd(tokens, frames[frame + 1]);
|
|
4683
|
+
else if (!(state & 32)) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
4971
4684
|
}
|
|
4972
|
-
if ((claim === 2 || claim === 3) && frames[frame + 5] & 16) literalDepth++;
|
|
4973
4685
|
continue;
|
|
4974
4686
|
}
|
|
4975
|
-
if (kind
|
|
4687
|
+
if (kind >= 73 && kind <= 74) {
|
|
4976
4688
|
const rawFrame = rawTop;
|
|
4977
|
-
if (rawFrame >= 0) rawTop = frames[rawFrame +
|
|
4689
|
+
if (rawFrame >= 0) rawTop = frames[rawFrame + 4];
|
|
4978
4690
|
const referenceFrame = referenceTop;
|
|
4979
4691
|
const closesReference = referenceFrame >= 0 && frames[referenceFrame + 1] === tokenIndex;
|
|
4980
4692
|
if (!skipping) {
|
|
@@ -4982,20 +4694,15 @@ function emitResolvedTokens(tokens, frames, replacements) {
|
|
|
4982
4694
|
referenceTop = frames[referenceFrame + 3];
|
|
4983
4695
|
skipEnd = appendReferenceBoundary(result, tokens, frames, referenceFrame, true);
|
|
4984
4696
|
} else if (rawFrame >= 0) {
|
|
4985
|
-
const
|
|
4697
|
+
const state = frames[rawFrame + 5];
|
|
4698
|
+
const claim = state & 7;
|
|
4986
4699
|
if (claim === 2) {
|
|
4987
4700
|
const openToken = frames[rawFrame + 0];
|
|
4988
|
-
if (inlineTokenEnd(tokens, openToken) < tokenStart) appendInlineToken(result,
|
|
4989
|
-
} else if (claim
|
|
4990
|
-
else if (claim
|
|
4991
|
-
const image = isImageFrame(tokens, frames, rawFrame);
|
|
4992
|
-
if (literalDepth === 0 || image) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
4993
|
-
} else if (claim === 6) {
|
|
4994
|
-
if (literalDepth === 0 || isImageFrame(tokens, frames, rawFrame)) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
4995
|
-
}
|
|
4701
|
+
if (inlineTokenEnd(tokens, openToken) < tokenStart) appendInlineToken(result, 209, tokenStart, tokenStart + 1);
|
|
4702
|
+
} else if (claim >= 3 && claim <= 4) appendInlineToken(result, 207, tokenStart, tokenStart + 1);
|
|
4703
|
+
else if (claim !== 1 && !(state & 32)) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
4996
4704
|
} else appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
4997
4705
|
}
|
|
4998
|
-
if (rawFrame >= 0 && (frameClaim(frames, rawFrame) === 2 || frameClaim(frames, rawFrame) === 3) && frames[rawFrame + 5] & 16) literalDepth--;
|
|
4999
4706
|
continue;
|
|
5000
4707
|
}
|
|
5001
4708
|
if (!skipping) appendResolvedDelimiterToken(result, tokens, tokenIndex, replacements);
|
|
@@ -5005,16 +4712,16 @@ function emitResolvedTokens(tokens, frames, replacements) {
|
|
|
5005
4712
|
function compileInlineResolver(options) {
|
|
5006
4713
|
return (delimiterConfigs) => {
|
|
5007
4714
|
const delimiterByKind = compileDelimiterConfigs(delimiterConfigs);
|
|
5008
|
-
return (source, tokens,
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
if (discovery & 2) {
|
|
5014
|
-
const runs = assignDelimiterScopes(source, tokens, frames, delimiterByKind);
|
|
5015
|
-
if (runs) replacements = resolveDelimiterMatches(runs);
|
|
4715
|
+
return (source, tokens, definitions) => {
|
|
4716
|
+
let tokenIndex = inlineTokenCount(tokens) - 1;
|
|
4717
|
+
for (; tokenIndex >= 0; tokenIndex--) {
|
|
4718
|
+
const kind = inlineTokenKind(tokens, tokenIndex);
|
|
4719
|
+
if (kind >= 68 && kind <= 74) break;
|
|
5016
4720
|
}
|
|
5017
|
-
|
|
4721
|
+
if (tokenIndex < 0) return tokens;
|
|
4722
|
+
const frames = analyzeBrackets(source, tokens, definitions, options);
|
|
4723
|
+
const replacements = resolvePairedSyntax(source, tokens, frames, definitions, delimiterByKind) ?? noDelimiterReplacements;
|
|
4724
|
+
return frames[0] & 1 || replacements.length > 0 ? emitResolvedTokens(tokens, frames, replacements) : tokens;
|
|
5018
4725
|
};
|
|
5019
4726
|
};
|
|
5020
4727
|
}
|
|
@@ -5026,18 +4733,18 @@ function compileProfile(options = {}) {
|
|
|
5026
4733
|
feature$15,
|
|
5027
4734
|
feature$16,
|
|
5028
4735
|
feature$4(options.taskList),
|
|
5029
|
-
feature$
|
|
4736
|
+
feature$14,
|
|
5030
4737
|
feature$6
|
|
5031
4738
|
];
|
|
5032
|
-
if (options.footnote) features.push(feature$
|
|
5033
|
-
if (options.frontmatter) features.unshift(feature$
|
|
4739
|
+
if (options.footnote) features.push(feature$10);
|
|
4740
|
+
if (options.frontmatter) features.unshift(feature$13(typeof options.frontmatter === "object" ? options.frontmatter.marker : "-"));
|
|
5034
4741
|
if (options.table) features.push(feature);
|
|
5035
4742
|
if (options.math) features.push(feature$3(options.math));
|
|
5036
|
-
features.push(feature$2, feature$
|
|
4743
|
+
features.push(feature$2, feature$9, feature$8(options.strikethrough), feature$5);
|
|
5037
4744
|
if (options.attributes) features.push(feature$18);
|
|
5038
4745
|
if (options.binding) features.push(feature$17);
|
|
5039
|
-
if (options.emoji) features.push(feature$
|
|
5040
|
-
if (options.component) features.push(feature$
|
|
4746
|
+
if (options.emoji) features.push(feature$11);
|
|
4747
|
+
if (options.component) features.push(feature$12);
|
|
5041
4748
|
features.push(feature$1);
|
|
5042
4749
|
const blockFeatures = [];
|
|
5043
4750
|
const inlineFeatures = [];
|