@opendikw/web-client 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/document/index.d.ts +1 -0
- package/dist/document/index.js +1 -0
- package/dist/document/markdown-blocks.js +2 -2
- package/dist/document/markdown.d.ts +1 -2
- package/dist/document/markdown.js +34 -4
- package/dist/document/raw-details.d.ts +1 -0
- package/dist/document/raw-details.js +97 -0
- package/dist/document/scientific-inline.d.ts +3 -0
- package/dist/document/scientific-inline.js +75 -0
- package/dist/document/wikilink-scan.d.ts +8 -0
- package/dist/document/wikilink-scan.js +42 -0
- package/dist/import/md-asset-refs.js +85 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,12 @@ Browser operations are provided by `/import` (archive and asset helpers),
|
|
|
18
18
|
`/document` (Markdown parsing, references and formatting), and `/connection`
|
|
19
19
|
(the default development Core URL). They do not own application routes or storage keys.
|
|
20
20
|
|
|
21
|
+
Markdown image extraction, heading wikilink normalization and details matching
|
|
22
|
+
use forward delimiter scans to avoid repeated searches on unclosed input. Image
|
|
23
|
+
paths, aliases and UTF-16 source offsets retain the Core-compatible grammar.
|
|
24
|
+
`rawDetailsPattern` supports `exec`, `matchAll` and `replace` directly; cloning
|
|
25
|
+
its `.source` only reproduces the opener, not the complete details scanner.
|
|
26
|
+
|
|
21
27
|
Conversion and translation caches accept `{ namespace }`. Omit it to retain
|
|
22
28
|
the existing cache database names and TTL. Applications may use an identity
|
|
23
29
|
and Core-specific namespace to keep local caches separate.
|
package/dist/document/index.d.ts
CHANGED
package/dist/document/index.js
CHANGED
|
@@ -92,8 +92,8 @@ function isImageOnlyLine(line) {
|
|
|
92
92
|
}
|
|
93
93
|
function collectRegexRanges(body, pattern) {
|
|
94
94
|
const ranges = [];
|
|
95
|
-
const
|
|
96
|
-
|
|
95
|
+
const re = pattern;
|
|
96
|
+
re.lastIndex = 0;
|
|
97
97
|
let m;
|
|
98
98
|
while ((m = re.exec(body)) !== null) {
|
|
99
99
|
if (m[0].length === 0) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { rawDetailsPattern } from "./raw-details.js";
|
|
1
2
|
export interface FrontmatterMeta {
|
|
2
3
|
title?: string;
|
|
3
4
|
id?: string;
|
|
@@ -26,7 +27,5 @@ export declare function parseMarkdownDocument(source: string, options?: ParseMar
|
|
|
26
27
|
export declare function getMarkdownTitle(source: string): string | null;
|
|
27
28
|
export declare function slugifyHeading(value: string): string;
|
|
28
29
|
export declare function uniqueHeadingSlug(env: Record<string, unknown>, value: string): string;
|
|
29
|
-
export declare const rawDetailsPattern: RegExp;
|
|
30
30
|
export declare function parseDetailsOpenAttribute(attributes: string): boolean | null;
|
|
31
31
|
export declare function extractHeadingsWithSlugs(body: string): HeadingEntry[];
|
|
32
|
-
export {};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import MarkdownIt from "markdown-it";
|
|
2
|
+
import { installScientificInline } from "./scientific-inline.js";
|
|
3
|
+
import { scanWikilinks } from "./wikilink-scan.js";
|
|
4
|
+
export { rawDetailsPattern } from "./raw-details.js";
|
|
5
|
+
import { rawDetailsPattern } from "./raw-details.js";
|
|
2
6
|
export function parseMarkdownDocument(source, options = {}) {
|
|
3
7
|
const normalized = source.replace(/\r\n/g, "\n");
|
|
4
8
|
const frontmatter = extractFrontmatter(normalized);
|
|
@@ -107,10 +111,21 @@ function normalizeHeading(value) {
|
|
|
107
111
|
// slugs when one operates on the original body and the other on the enhanced
|
|
108
112
|
// body, and Outline clicks silently no-op.
|
|
109
113
|
function stripWikilinkSyntax(value) {
|
|
110
|
-
|
|
114
|
+
// Keep the two legacy passes: aliases first, then any remaining plain links.
|
|
115
|
+
for (const aliasOnly of [true, false]) {
|
|
116
|
+
const parts = [];
|
|
117
|
+
let cursor = 0;
|
|
118
|
+
for (const link of scanWikilinks(value, false, aliasOnly)) {
|
|
119
|
+
parts.push(value.slice(cursor, link.start), aliasOnly ? link.label : value.slice(link.start + 2, link.end - 2));
|
|
120
|
+
cursor = link.end;
|
|
121
|
+
}
|
|
122
|
+
parts.push(value.slice(cursor));
|
|
123
|
+
value = parts.join("");
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
111
126
|
}
|
|
112
127
|
export function slugifyHeading(value) {
|
|
113
|
-
return stripWikilinkSyntax(value)
|
|
128
|
+
return stripWikilinkSyntax(stripScientificInlineTags(value))
|
|
114
129
|
.trim()
|
|
115
130
|
.toLowerCase()
|
|
116
131
|
.normalize("NFKD")
|
|
@@ -141,7 +156,6 @@ export function uniqueHeadingSlug(env, value) {
|
|
|
141
156
|
// Shared with MarkdownView. Both files use these to identify the same set of
|
|
142
157
|
// <details>...</details> blocks. Keep them here as the single source of truth
|
|
143
158
|
// so heading slug extraction stays aligned with how MarkdownView renders.
|
|
144
|
-
export const rawDetailsPattern = /<details\b([^>]*)>\s*<summary>([\s\S]*?)<\/summary>([\s\S]*?)<\/details>/gi;
|
|
145
159
|
export function parseDetailsOpenAttribute(attributes) {
|
|
146
160
|
const trimmed = attributes.trim();
|
|
147
161
|
if (!trimmed) {
|
|
@@ -153,6 +167,22 @@ export function parseDetailsOpenAttribute(attributes) {
|
|
|
153
167
|
// parser config used by MarkdownView so the slugs produced here match the
|
|
154
168
|
// `id` attributes that MarkdownView writes onto the rendered DOM.
|
|
155
169
|
const headingParser = new MarkdownIt({ html: false, linkify: true, typographer: true });
|
|
170
|
+
installScientificInline(headingParser);
|
|
171
|
+
// Remove only markup that the reader actually accepts; code spans and unsafe
|
|
172
|
+
// HTML remain literal. Keep the existing Markdown/wikilink heading contract.
|
|
173
|
+
function stripScientificInlineTags(value) {
|
|
174
|
+
if (!/<(?:sup|sub)>/i.test(value))
|
|
175
|
+
return value;
|
|
176
|
+
const tokens = headingParser.parseInline(value, {})[0]?.children ?? [];
|
|
177
|
+
let result = value;
|
|
178
|
+
for (const token of [...tokens].reverse()) {
|
|
179
|
+
if (token.type === "scientific_open" || token.type === "scientific_close") {
|
|
180
|
+
const { start, end } = token.meta;
|
|
181
|
+
result = result.slice(0, start) + result.slice(end);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
156
186
|
// MarkdownView renders any details block whose `open` attribute parses as
|
|
157
187
|
// safe inside its own recursive renderMarkdown() call with a fresh slug
|
|
158
188
|
// counter. If extractHeadingsWithSlugs included headings from those blocks in
|
|
@@ -185,7 +215,7 @@ export function extractHeadingsWithSlugs(body) {
|
|
|
185
215
|
if (!inline || inline.type !== "inline") {
|
|
186
216
|
continue;
|
|
187
217
|
}
|
|
188
|
-
const title = (inline.content ?? "").trim();
|
|
218
|
+
const title = stripScientificInlineTags(inline.content ?? "").trim();
|
|
189
219
|
if (!title) {
|
|
190
220
|
continue;
|
|
191
221
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const rawDetailsPattern: RegExp;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
class RawDetailsPattern extends RegExp {
|
|
2
|
+
body;
|
|
3
|
+
matches = [];
|
|
4
|
+
constructor(_source, flags = "gi") {
|
|
5
|
+
super("<details\\b", flags);
|
|
6
|
+
}
|
|
7
|
+
exec(body) {
|
|
8
|
+
if (this.body !== body) {
|
|
9
|
+
this.body = body;
|
|
10
|
+
this.matches = scanDetails(body, this.ignoreCase);
|
|
11
|
+
}
|
|
12
|
+
const start = this.global || this.sticky ? Math.max(0, Math.floor(Number(this.lastIndex) || 0)) : 0;
|
|
13
|
+
// Binary lookup honors arbitrary lastIndex changes without rescanning the
|
|
14
|
+
// document. Symbol.split also uses a sticky copy of this RegExp.
|
|
15
|
+
let low = 0;
|
|
16
|
+
let high = this.matches.length;
|
|
17
|
+
while (low < high) {
|
|
18
|
+
const middle = (low + high) >>> 1;
|
|
19
|
+
if (this.matches[middle].start < start)
|
|
20
|
+
low = middle + 1;
|
|
21
|
+
else
|
|
22
|
+
high = middle;
|
|
23
|
+
}
|
|
24
|
+
const match = this.matches[low];
|
|
25
|
+
if (match && (!this.sticky || match.start === start)) {
|
|
26
|
+
if (this.global || this.sticky)
|
|
27
|
+
this.lastIndex = match.end;
|
|
28
|
+
// Native RegExp results are fresh arrays; callers may mutate them.
|
|
29
|
+
return Object.assign([
|
|
30
|
+
body.slice(match.start, match.end),
|
|
31
|
+
body.slice(match.attributesStart, match.tagEnd),
|
|
32
|
+
body.slice(match.summaryStart, match.summaryEnd),
|
|
33
|
+
body.slice(match.contentStart, match.end - "</details>".length),
|
|
34
|
+
], {
|
|
35
|
+
index: match.start,
|
|
36
|
+
input: body,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (this.global || this.sticky)
|
|
40
|
+
this.lastIndex = 0;
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function scanDetails(body, ignoreCase) {
|
|
45
|
+
// ASCII folding keeps UTF-16 offsets intact (Unicode lowercasing may expand).
|
|
46
|
+
const folded = ignoreCase ? body.replace(/[A-Z]/g, (letter) => letter.toLowerCase()) : body;
|
|
47
|
+
const openings = new RegExp("<details\\b", ignoreCase ? "gi" : "g");
|
|
48
|
+
const matches = [];
|
|
49
|
+
let tagEnd = -1;
|
|
50
|
+
let summaryTagEnd = -1;
|
|
51
|
+
let summaryStart = -1;
|
|
52
|
+
let summaryEnd = -1;
|
|
53
|
+
let detailsEnd = -1;
|
|
54
|
+
for (let open = openings.exec(body); open; open = openings.exec(body)) {
|
|
55
|
+
const attributesStart = open.index + open[0].length;
|
|
56
|
+
if (tagEnd < attributesStart)
|
|
57
|
+
tagEnd = body.indexOf(">", attributesStart);
|
|
58
|
+
if (tagEnd < 0)
|
|
59
|
+
break;
|
|
60
|
+
if (summaryTagEnd !== tagEnd) {
|
|
61
|
+
summaryTagEnd = tagEnd;
|
|
62
|
+
summaryStart = tagEnd + 1;
|
|
63
|
+
while (/\s/.test(body[summaryStart] ?? ""))
|
|
64
|
+
summaryStart++;
|
|
65
|
+
summaryStart = folded.startsWith("<summary>", summaryStart)
|
|
66
|
+
? summaryStart + "<summary>".length
|
|
67
|
+
: -1;
|
|
68
|
+
}
|
|
69
|
+
if (summaryStart < 0) {
|
|
70
|
+
openings.lastIndex = tagEnd + 1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (summaryEnd < summaryStart)
|
|
74
|
+
summaryEnd = folded.indexOf("</summary>", summaryStart);
|
|
75
|
+
if (summaryEnd < 0)
|
|
76
|
+
break;
|
|
77
|
+
const contentStart = summaryEnd + "</summary>".length;
|
|
78
|
+
if (detailsEnd < contentStart)
|
|
79
|
+
detailsEnd = folded.indexOf("</details>", contentStart);
|
|
80
|
+
if (detailsEnd < 0)
|
|
81
|
+
break;
|
|
82
|
+
const end = detailsEnd + "</details>".length;
|
|
83
|
+
// Keep numeric bounds for every opener, including nested ones. Arbitrary
|
|
84
|
+
// lastIndex searches can select them without storing overlapping strings.
|
|
85
|
+
matches.push({
|
|
86
|
+
start: open.index,
|
|
87
|
+
attributesStart,
|
|
88
|
+
tagEnd,
|
|
89
|
+
summaryStart,
|
|
90
|
+
summaryEnd,
|
|
91
|
+
contentStart,
|
|
92
|
+
end,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return matches;
|
|
96
|
+
}
|
|
97
|
+
export const rawDetailsPattern = new RawDetailsPattern();
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Index balanced pairs once per inline source. Repeated unclosed tags must not
|
|
2
|
+
// repeatedly scan the line tail, and rejected nested pairs must stay literal.
|
|
3
|
+
function indexPairs(source) {
|
|
4
|
+
const pairs = new Map();
|
|
5
|
+
const stack = [];
|
|
6
|
+
for (const match of source.matchAll(/\n|<(\/?)(sup|sub)>/gi)) {
|
|
7
|
+
if (match[0] === "\n") {
|
|
8
|
+
stack.length = 0;
|
|
9
|
+
}
|
|
10
|
+
else if (!match[1]) {
|
|
11
|
+
stack.push({ start: match.index, tag: match[2].toLowerCase() });
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const open = stack.pop();
|
|
15
|
+
if (open?.tag === match[2].toLowerCase())
|
|
16
|
+
pairs.set(open.start, match.index);
|
|
17
|
+
else
|
|
18
|
+
stack.length = 0;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return pairs;
|
|
22
|
+
}
|
|
23
|
+
/** Attribute-free, single-line scientific marks without enabling raw HTML. */
|
|
24
|
+
export function installScientificInline(md) {
|
|
25
|
+
const sources = new WeakMap();
|
|
26
|
+
md.inline.ruler.before("html_inline", "scientific_inline", (state, silent) => {
|
|
27
|
+
const start = state.pos;
|
|
28
|
+
// Link-label lookahead must still inspect inner brackets for nested links.
|
|
29
|
+
if (silent || state.src[start] !== "<")
|
|
30
|
+
return false;
|
|
31
|
+
const opener = /^<(sup|sub)>/i.exec(state.src.slice(start, start + 5));
|
|
32
|
+
if (!opener)
|
|
33
|
+
return false;
|
|
34
|
+
let source = sources.get(state);
|
|
35
|
+
if (!source) {
|
|
36
|
+
source = { pairs: indexPairs(state.src), rejectedUntil: -1 };
|
|
37
|
+
sources.set(state, source);
|
|
38
|
+
}
|
|
39
|
+
if (start < source.rejectedUntil)
|
|
40
|
+
return false;
|
|
41
|
+
const contentEnd = source.pairs.get(start);
|
|
42
|
+
if (contentEnd === undefined || contentEnd + 6 > state.posMax) {
|
|
43
|
+
// An actual unbalanced opener keeps its remainder literal, including any
|
|
44
|
+
// otherwise balanced descendants. Code-span lookalikes never call here.
|
|
45
|
+
const newline = state.src.indexOf("\n", start);
|
|
46
|
+
source.rejectedUntil = newline < 0 ? state.posMax : Math.min(newline, state.posMax);
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const end = contentEnd + 6;
|
|
50
|
+
const content = state.src.slice(start + 5, contentEnd);
|
|
51
|
+
// Consume rejected pairs as text too, so a nested tag cannot become live.
|
|
52
|
+
if (/[<>]/.test(content)) {
|
|
53
|
+
state.push("text", "", 0).content = state.src.slice(start, end);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const inner = new md.inline.State(content, md, state.env, []);
|
|
57
|
+
inner.linkLevel = state.linkLevel;
|
|
58
|
+
inner.level = state.level + 1;
|
|
59
|
+
// A bounded src also confines custom rules that search past posMax.
|
|
60
|
+
md.inline.tokenize(inner);
|
|
61
|
+
for (const rule of md.inline.ruler2.getRules(""))
|
|
62
|
+
rule(inner);
|
|
63
|
+
const tag = opener[1].toLowerCase();
|
|
64
|
+
state.push("scientific_open", tag, 1).meta = { start, end: start + 5 };
|
|
65
|
+
// Keep ordinary tokens visible to image-alt, linkify and typography rules.
|
|
66
|
+
for (const child of inner.tokens) {
|
|
67
|
+
const token = state.push(child.type, child.tag, child.nesting);
|
|
68
|
+
Object.assign(token, child, { level: token.level });
|
|
69
|
+
}
|
|
70
|
+
state.push("scientific_close", tag, -1).meta = { start: contentEnd, end };
|
|
71
|
+
}
|
|
72
|
+
state.pos = end;
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Cache the next delimiters, including failed searches. Repeated openers must
|
|
2
|
+
// not search the same unclosed suffix again. Spans retain the legacy grammar:
|
|
3
|
+
// '[' is allowed in the target, '|' in aliases, and ']' ends either field.
|
|
4
|
+
export function* scanWikilinks(text, image, aliasOnly = false) {
|
|
5
|
+
const opener = image ? "![[" : "[[";
|
|
6
|
+
let cursor = 0;
|
|
7
|
+
let close = -1;
|
|
8
|
+
let pipe = -1;
|
|
9
|
+
while (cursor < text.length) {
|
|
10
|
+
const start = text.indexOf(opener, cursor);
|
|
11
|
+
if (start < 0)
|
|
12
|
+
return;
|
|
13
|
+
const contentStart = start + opener.length;
|
|
14
|
+
if (close < contentStart)
|
|
15
|
+
close = text.indexOf("]", contentStart);
|
|
16
|
+
if (close < 0)
|
|
17
|
+
return;
|
|
18
|
+
if (text[close + 1] !== "]") {
|
|
19
|
+
cursor = close + 1;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (pipe < contentStart) {
|
|
23
|
+
const next = text.indexOf("|", contentStart);
|
|
24
|
+
pipe = next < 0 ? Infinity : next;
|
|
25
|
+
}
|
|
26
|
+
const hasAlias = pipe < close;
|
|
27
|
+
const validAlias = hasAlias && pipe > contentStart && pipe + 1 < close;
|
|
28
|
+
if (close === contentStart ||
|
|
29
|
+
(aliasOnly && !validAlias) ||
|
|
30
|
+
(image && hasAlias && !validAlias)) {
|
|
31
|
+
cursor = contentStart;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
yield {
|
|
35
|
+
start,
|
|
36
|
+
end: close + 2,
|
|
37
|
+
target: text.slice(contentStart, hasAlias ? pipe : close),
|
|
38
|
+
label: hasAlias ? text.slice(pipe + 1, close) : null,
|
|
39
|
+
};
|
|
40
|
+
cursor = close + 2;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -2,31 +2,104 @@
|
|
|
2
2
|
// _is_remote, _resolve_local}. The web importer must agree byte-for-byte
|
|
3
3
|
// on which paths are picked up — divergence shows up as missing assets
|
|
4
4
|
// after import.
|
|
5
|
-
|
|
6
|
-
const WIKILINK_IMG_RE = /!\[\[([^\]|]+?)(?:\|([^\]]+))?\]\]/g;
|
|
5
|
+
import { scanWikilinks } from "../document/wikilink-scan.js";
|
|
7
6
|
export function extractAssetRefs(body) {
|
|
8
7
|
const refs = [];
|
|
9
|
-
|
|
8
|
+
const scanDestination = destinationScanner(body);
|
|
9
|
+
let cursor = 0;
|
|
10
|
+
while (cursor < body.length) {
|
|
11
|
+
const start = body.indexOf("![", cursor);
|
|
12
|
+
if (start < 0)
|
|
13
|
+
break;
|
|
14
|
+
const labelEnd = body.indexOf("]", start + 2);
|
|
15
|
+
if (labelEnd < 0)
|
|
16
|
+
break;
|
|
17
|
+
// All openers before this ']' share the same destination. If it is invalid,
|
|
18
|
+
// skip the group rather than retrying the same tail for every nested '!['.
|
|
19
|
+
const destination = body[labelEnd + 1] === "(" ? scanDestination(labelEnd + 2) : null;
|
|
20
|
+
cursor = destination?.end ?? labelEnd + 1;
|
|
21
|
+
if (!destination)
|
|
22
|
+
continue;
|
|
10
23
|
refs.push({
|
|
11
|
-
originalPath:
|
|
12
|
-
alt:
|
|
13
|
-
start
|
|
14
|
-
end:
|
|
24
|
+
originalPath: destination.path,
|
|
25
|
+
alt: body.slice(start + 2, labelEnd),
|
|
26
|
+
start,
|
|
27
|
+
end: destination.end,
|
|
15
28
|
syntax: "markdown",
|
|
16
29
|
});
|
|
17
30
|
}
|
|
18
|
-
for (const
|
|
31
|
+
for (const link of scanWikilinks(body, true)) {
|
|
19
32
|
refs.push({
|
|
20
|
-
originalPath:
|
|
21
|
-
alt:
|
|
22
|
-
start:
|
|
23
|
-
end:
|
|
33
|
+
originalPath: link.target,
|
|
34
|
+
alt: link.label ?? "",
|
|
35
|
+
start: link.start,
|
|
36
|
+
end: link.end,
|
|
24
37
|
syntax: "wikilink",
|
|
25
38
|
});
|
|
26
39
|
}
|
|
27
40
|
refs.sort((a, b) => a.start - b.start);
|
|
28
41
|
return refs;
|
|
29
42
|
}
|
|
43
|
+
function destinationScanner(body) {
|
|
44
|
+
// Index possible endings once. Distinct '](' openers can otherwise retry the
|
|
45
|
+
// same unterminated path/title suffix, even without a backtracking regex.
|
|
46
|
+
const stops = Array.from(body.matchAll(/[)\n]/g), (match) => match.index);
|
|
47
|
+
const quotes = Array.from(body.matchAll(/["\n]/g));
|
|
48
|
+
const titles = [];
|
|
49
|
+
for (let i = 0; i + 1 < quotes.length; i++) {
|
|
50
|
+
const quote = quotes[i];
|
|
51
|
+
const close = quotes[i + 1];
|
|
52
|
+
if (quote[0] !== '"' || close[0] !== '"')
|
|
53
|
+
continue;
|
|
54
|
+
let pathEnd = quote.index;
|
|
55
|
+
while (pathEnd > 0 && /\s/.test(body[pathEnd - 1]))
|
|
56
|
+
pathEnd--;
|
|
57
|
+
if (pathEnd === quote.index)
|
|
58
|
+
continue;
|
|
59
|
+
let end = close.index + 1;
|
|
60
|
+
while (/\s/.test(body[end] ?? ""))
|
|
61
|
+
end++;
|
|
62
|
+
if (body[end] === ")")
|
|
63
|
+
titles.push({ pathEnd, end: end + 1 });
|
|
64
|
+
}
|
|
65
|
+
let stopIndex = 0;
|
|
66
|
+
let titleIndex = 0;
|
|
67
|
+
let whitespaceStop = -1;
|
|
68
|
+
let whitespaceEnd = -1;
|
|
69
|
+
return (start) => {
|
|
70
|
+
let pathStart = start;
|
|
71
|
+
while (/\s/.test(body[pathStart] ?? ""))
|
|
72
|
+
pathStart++;
|
|
73
|
+
if (body[pathStart] === ")" && pathStart > start) {
|
|
74
|
+
// Core's legacy grammar accepts a single whitespace path (except LF).
|
|
75
|
+
let last = pathStart - 1;
|
|
76
|
+
while (last >= start && body[last] === "\n")
|
|
77
|
+
last--;
|
|
78
|
+
return last < start ? null : { path: body[last], end: pathStart + 1 };
|
|
79
|
+
}
|
|
80
|
+
while (stopIndex < stops.length && stops[stopIndex] < pathStart)
|
|
81
|
+
stopIndex++;
|
|
82
|
+
while (titleIndex < titles.length && titles[titleIndex].pathEnd <= pathStart)
|
|
83
|
+
titleIndex++;
|
|
84
|
+
const stop = stops[stopIndex] ?? body.length;
|
|
85
|
+
const title = titles[titleIndex];
|
|
86
|
+
if (title && title.pathEnd <= stop)
|
|
87
|
+
return { path: body.slice(pathStart, title.pathEnd), end: title.end };
|
|
88
|
+
if (body[stop] === "\n") {
|
|
89
|
+
if (whitespaceStop !== stop) {
|
|
90
|
+
whitespaceStop = stop;
|
|
91
|
+
whitespaceEnd = stop;
|
|
92
|
+
while (/\s/.test(body[whitespaceEnd] ?? ""))
|
|
93
|
+
whitespaceEnd++;
|
|
94
|
+
}
|
|
95
|
+
if (body[whitespaceEnd] === ")")
|
|
96
|
+
return { path: body.slice(pathStart, stop).trimEnd(), end: whitespaceEnd + 1 };
|
|
97
|
+
}
|
|
98
|
+
if (body[stop] !== ")" || stop === pathStart)
|
|
99
|
+
return null;
|
|
100
|
+
return { path: body.slice(pathStart, stop).trimEnd(), end: stop + 1 };
|
|
101
|
+
};
|
|
102
|
+
}
|
|
30
103
|
const REMOTE_SCHEMES = /^([a-zA-Z][a-zA-Z0-9+\-.]*):/;
|
|
31
104
|
export function isRemoteRef(originalPath) {
|
|
32
105
|
const m = originalPath.match(REMOTE_SCHEMES);
|