flashtrace 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/flashtrace.mjs +40 -14
- package/package.json +1 -1
package/dist/flashtrace.mjs
CHANGED
|
@@ -317,13 +317,22 @@ function isParagraphLine(line) {
|
|
|
317
317
|
}
|
|
318
318
|
var isParagraphAt = (lines, inTable, j) => !inTable[j] && isParagraphLine(lines[j]);
|
|
319
319
|
var isSetextHeading = (lines, inTable, titleIndex) => titleIndex + 1 < lines.length && SETEXT_UNDERLINE_RE.test(lines[titleIndex + 1]) && isParagraphAt(lines, inTable, titleIndex);
|
|
320
|
-
function
|
|
321
|
-
|
|
322
|
-
let
|
|
323
|
-
while (
|
|
324
|
-
|
|
320
|
+
function scanSetextHeadings(lines, inTable) {
|
|
321
|
+
const opensHeading = new Array(lines.length).fill(false);
|
|
322
|
+
let j = 0;
|
|
323
|
+
while (j < lines.length) {
|
|
324
|
+
if (!isParagraphAt(lines, inTable, j)) {
|
|
325
|
+
j++;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const start = j;
|
|
329
|
+
while (j + 1 < lines.length && isParagraphAt(lines, inTable, j + 1)) j++;
|
|
330
|
+
if (isSetextHeading(lines, inTable, j)) opensHeading.fill(true, start, j + 1);
|
|
331
|
+
j++;
|
|
332
|
+
}
|
|
333
|
+
return opensHeading;
|
|
325
334
|
}
|
|
326
|
-
var isBoundary = (lines, inTable, j) => !inTable[j] && DEFINITION_RE.test(lines[j]) || HEADING_RE.test(lines[j]) ||
|
|
335
|
+
var isBoundary = (lines, inTable, opensHeading, j) => !inTable[j] && DEFINITION_RE.test(lines[j]) || HEADING_RE.test(lines[j]) || opensHeading[j];
|
|
327
336
|
function foldSetextTitle(lines, inTable, lastIndex) {
|
|
328
337
|
let first = lastIndex;
|
|
329
338
|
while (first > 0 && isParagraphAt(lines, inTable, first - 1)) first--;
|
|
@@ -444,10 +453,11 @@ function applyKeyword(item, keyword, entries, file, keywordLine, problems, sourc
|
|
|
444
453
|
});
|
|
445
454
|
}
|
|
446
455
|
}
|
|
447
|
-
function parseItemBody(lines,
|
|
456
|
+
function parseItemBody(lines, boundary, start, item, file, problems, forwards) {
|
|
457
|
+
const { inTable, opensHeading } = boundary;
|
|
448
458
|
let j = start;
|
|
449
459
|
let descriptionDone = false;
|
|
450
|
-
while (j < lines.length && !isBoundary(lines, inTable, j)) {
|
|
460
|
+
while (j < lines.length && !isBoundary(lines, inTable, opensHeading, j)) {
|
|
451
461
|
const line = lines[j];
|
|
452
462
|
if (takeForward(line, file, j, forwards)) {
|
|
453
463
|
j++;
|
|
@@ -483,10 +493,12 @@ function parseItemBody(lines, inTable, start, item, file, problems, forwards) {
|
|
|
483
493
|
function parseMarkdown(file, text, problems, forwards = []) {
|
|
484
494
|
const lines = text.split(/\r?\n/);
|
|
485
495
|
const inTable = scanTables(lines, file, problems);
|
|
496
|
+
const opensHeading = scanSetextHeadings(lines, inTable);
|
|
497
|
+
const boundary = { inTable, opensHeading };
|
|
486
498
|
const items = [];
|
|
487
499
|
let i = 0;
|
|
488
500
|
while (i < lines.length) {
|
|
489
|
-
const startsHeading =
|
|
501
|
+
const startsHeading = opensHeading[i];
|
|
490
502
|
if (!startsHeading && takeForward(lines[i], file, i, forwards)) {
|
|
491
503
|
i++;
|
|
492
504
|
continue;
|
|
@@ -507,7 +519,7 @@ function parseMarkdown(file, text, problems, forwards = []) {
|
|
|
507
519
|
}
|
|
508
520
|
const item = newItem(makeId(definition[1], definition[2], definition[3], definition[4]), "markdown", file, i + 1);
|
|
509
521
|
item.title = titleAbove(lines, inTable, i);
|
|
510
|
-
i = parseItemBody(lines,
|
|
522
|
+
i = parseItemBody(lines, boundary, i + 1, item, file, problems, forwards);
|
|
511
523
|
items.push(item);
|
|
512
524
|
}
|
|
513
525
|
return items;
|
|
@@ -520,6 +532,19 @@ var TAG_RE = new RegExp(
|
|
|
520
532
|
"g"
|
|
521
533
|
);
|
|
522
534
|
var FORWARD_RE = new RegExp(FORWARD_SRC, "g");
|
|
535
|
+
var URL_RE = /[A-Za-z][A-Za-z0-9+.-]{0,63}:\/\/[^\s"'`<>[\]]*/g;
|
|
536
|
+
function urlSpans(line) {
|
|
537
|
+
if (!line.includes("://")) return [];
|
|
538
|
+
return [...line.matchAll(URL_RE)].map((m) => ({ start: m.index, end: m.index + m[0].length }));
|
|
539
|
+
}
|
|
540
|
+
function markerIndex(line, marker, pos, spans) {
|
|
541
|
+
let idx = line.indexOf(marker, pos);
|
|
542
|
+
for (const span of spans) {
|
|
543
|
+
if (idx === -1 || idx < span.start) break;
|
|
544
|
+
if (idx < span.end) idx = line.indexOf(marker, span.end);
|
|
545
|
+
}
|
|
546
|
+
return idx;
|
|
547
|
+
}
|
|
523
548
|
function activeLeaf(grammar, state) {
|
|
524
549
|
if (state.region) return state.region.grammar;
|
|
525
550
|
return grammar.regions ? grammar.default : grammar;
|
|
@@ -543,7 +568,7 @@ function* regionEvents(line, pos, grammar, state) {
|
|
|
543
568
|
}
|
|
544
569
|
}
|
|
545
570
|
}
|
|
546
|
-
function nextEvent(line, pos, grammar, state) {
|
|
571
|
+
function nextEvent(line, pos, grammar, state, spans) {
|
|
547
572
|
const leaf = activeLeaf(grammar, state);
|
|
548
573
|
let best = null;
|
|
549
574
|
const consider = (idx, event) => {
|
|
@@ -553,10 +578,10 @@ function nextEvent(line, pos, grammar, state) {
|
|
|
553
578
|
}
|
|
554
579
|
};
|
|
555
580
|
for (const marker of leaf.line) {
|
|
556
|
-
consider(line
|
|
581
|
+
consider(markerIndex(line, marker, pos, spans), { kind: "line", len: marker.length });
|
|
557
582
|
}
|
|
558
583
|
for (const [open, close, nestable] of leaf.block) {
|
|
559
|
-
consider(line
|
|
584
|
+
consider(markerIndex(line, open, pos, spans), {
|
|
560
585
|
kind: "block",
|
|
561
586
|
len: open.length,
|
|
562
587
|
open,
|
|
@@ -611,6 +636,7 @@ function consumeLine(line, pos, state, exit) {
|
|
|
611
636
|
return { text: line.slice(pos) + " ", pos: line.length, done: true };
|
|
612
637
|
}
|
|
613
638
|
function commentText(line, state, grammar) {
|
|
639
|
+
const spans = urlSpans(line);
|
|
614
640
|
let comment = "";
|
|
615
641
|
let pos = 0;
|
|
616
642
|
while (pos < line.length) {
|
|
@@ -621,7 +647,7 @@ function commentText(line, state, grammar) {
|
|
|
621
647
|
pos = consumed.pos;
|
|
622
648
|
continue;
|
|
623
649
|
}
|
|
624
|
-
const event = nextEvent(line, pos, grammar, state);
|
|
650
|
+
const event = nextEvent(line, pos, grammar, state, spans);
|
|
625
651
|
if (!event) break;
|
|
626
652
|
pos = event.idx + event.len;
|
|
627
653
|
if (event.kind === "line") {
|