@p-buddy/parkdown 0.0.23 → 0.0.24
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 +4 -4
- package/dist/cli.js +1 -1
- package/dist/index.js +174 -176
- package/dist/index.umd.cjs +13 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ populateMarkdownInclusions(file, writeFile);
|
|
|
44
44
|
|
|
45
45
|
[](./.assets/authoring.md)
|
|
46
46
|
<!-- p↓ BEGIN -->
|
|
47
|
-
<!-- p↓ length lines: 663 chars:
|
|
47
|
+
<!-- p↓ length lines: 663 chars: 22786 -->
|
|
48
48
|
## Authoring
|
|
49
49
|
|
|
50
50
|
You author inclusions in your markdown files using a link with no text i.e. `[](<url>)`, where `<url>` points to some local or remote text resource (e.g.`./other.md`, `https://example.com/remote.md`).
|
|
@@ -256,7 +256,7 @@ Before...
|
|
|
256
256
|
|
|
257
257
|
[](.assets/query.md?heading=-1)
|
|
258
258
|
<!-- p↓ BEGIN -->
|
|
259
|
-
<!-- p↓ length lines: 450 chars:
|
|
259
|
+
<!-- p↓ length lines: 450 chars: 18080 -->
|
|
260
260
|
### Query parameters
|
|
261
261
|
|
|
262
262
|
You can pass query parameters to your inclusion links to control how their content is processed and included within your markdown.
|
|
@@ -320,7 +320,7 @@ Please see the [full explanation](#query-parameters-with-function-like-apis) to
|
|
|
320
320
|
|
|
321
321
|
[](src/region.ts?region=extract(definition))
|
|
322
322
|
<!-- p↓ BEGIN -->
|
|
323
|
-
<!-- p↓ length lines: 122 chars:
|
|
323
|
+
<!-- p↓ length lines: 122 chars: 6242 -->
|
|
324
324
|
|
|
325
325
|
```ts
|
|
326
326
|
const definitions = [
|
|
@@ -367,7 +367,7 @@ const definitions = [
|
|
|
367
367
|
* @example [](<url>?region=remap(specifier,hello-world,hello-universe))
|
|
368
368
|
* @example [](<url>?region=remap(specifier,hello_world,hello_universe,_)
|
|
369
369
|
*/
|
|
370
|
-
"remap(id
|
|
370
|
+
"remap(id?: string, from: string, to?: string, space?: string)",
|
|
371
371
|
|
|
372
372
|
/**
|
|
373
373
|
* Make the content of the region a single line (where all whitespace characters, including newlines, are converted to a single space).
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Command as r } from "@commander-js/extra-typings";
|
|
3
3
|
import { populateMarkdownInclusions as l, depopulateMarkdownInclusions as a } from "@p-buddy/parkdown";
|
|
4
4
|
import f from "chokidar";
|
|
5
|
-
const c = "0.0.
|
|
5
|
+
const c = "0.0.24", p = new r().version(c).option("--nw, --no-write", "Do NOT write result to file (defaults to false)", !1).option("--ni, --no-inclusions", "Do NOT process file inclusions (defaults to false)", !1).option("-d, --depopulate", "Remove populated inclusions from the file", !1).option("-f, --file <flag>", "The file(s) to process", (e, o) => (o.push(e), o), new Array()).option("-w, --watch", "Watch the file(s) for changes and update automatically", !1).parse(), { inclusions: u, depopulate: d, file: t, write: n, watch: h } = p.opts();
|
|
6
6
|
t.length === 0 && t.push("README.md");
|
|
7
7
|
const m = [
|
|
8
8
|
[l, !u],
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { writeFileSync as
|
|
5
|
-
import { basename as
|
|
6
|
-
import { URLSearchParams as
|
|
7
|
-
import { unified as
|
|
8
|
-
import
|
|
9
|
-
import { visit as
|
|
10
|
-
import { dedent as
|
|
1
|
+
var $e = Object.defineProperty;
|
|
2
|
+
var be = (e, t, n) => t in e ? $e(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var k = (e, t, n) => be(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { writeFileSync as oe, readFileSync as ye } from "node:fs";
|
|
5
|
+
import { basename as Ce, dirname as H, join as O, resolve as ie } from "node:path";
|
|
6
|
+
import { URLSearchParams as Ee } from "node:url";
|
|
7
|
+
import { unified as Se } from "unified";
|
|
8
|
+
import xe from "remark-parse";
|
|
9
|
+
import { visit as ke } from "unist-util-visit";
|
|
10
|
+
import { dedent as _e } from "ts-dedent";
|
|
11
11
|
const f = (e, t) => e.position.start.offset - t.position.start.offset;
|
|
12
12
|
f.reverse = (e, t) => f(t, e);
|
|
13
|
-
const
|
|
14
|
-
md: (e) =>
|
|
15
|
-
},
|
|
13
|
+
const Q = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, Ne = Se().use(xe), G = {
|
|
14
|
+
md: (e) => Ne.parse(e)
|
|
15
|
+
}, R = (e, t) => {
|
|
16
16
|
const n = [];
|
|
17
|
-
return
|
|
17
|
+
return ke(e, (s, r, o) => {
|
|
18
18
|
if (s.type !== "root") {
|
|
19
19
|
if (t && s.type !== t) return;
|
|
20
|
-
if (
|
|
20
|
+
if (Q(s)) {
|
|
21
21
|
const i = ((o == null ? void 0 : o.children.length) ?? 0) - 1;
|
|
22
22
|
n.push({ ...s, siblingIndex: r, siblingCount: i });
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}), n;
|
|
26
|
-
}, Me = (e) => e.children.length === 0,
|
|
26
|
+
}, Me = (e) => e.children.length === 0, le = (e, t, ...n) => {
|
|
27
27
|
if (n.length === 0) throw new Error("No nodes to replace content from");
|
|
28
28
|
n.sort(f);
|
|
29
29
|
const s = n.at(0), r = n.at(-1);
|
|
@@ -31,11 +31,11 @@ const X = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
31
31
|
}, Ae = (e, t, n) => {
|
|
32
32
|
const s = Math.min(t.position.end.offset, n.position.end.offset), r = Math.max(t.position.start.offset, n.position.start.offset);
|
|
33
33
|
return e.slice(s, r);
|
|
34
|
-
},
|
|
35
|
-
`),
|
|
34
|
+
}, A = (...e) => e.join(" "), Oe = (...e) => e.join(`
|
|
35
|
+
`), Re = (e) => {
|
|
36
36
|
const t = e.split("?");
|
|
37
37
|
return t.length > 1 ? [t.slice(0, -1).join("?"), t.at(-1)] : [e, ""];
|
|
38
|
-
},
|
|
38
|
+
}, Te = (e) => Re(e)[0], V = /,\s*(?![^()]*\))/, J = {
|
|
39
39
|
reserved: {
|
|
40
40
|
semi: ";",
|
|
41
41
|
slash: "/",
|
|
@@ -63,7 +63,7 @@ const X = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
63
63
|
line: `
|
|
64
64
|
`
|
|
65
65
|
}
|
|
66
|
-
},
|
|
66
|
+
}, Ie = "-", Z = {
|
|
67
67
|
static: [
|
|
68
68
|
["'''", '"'],
|
|
69
69
|
["''", "'"],
|
|
@@ -71,24 +71,24 @@ const X = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
71
71
|
[/p↓:\s+/g, ""]
|
|
72
72
|
],
|
|
73
73
|
url: [
|
|
74
|
-
...Object.entries(
|
|
75
|
-
...Object.entries(
|
|
74
|
+
...Object.entries(J.unsafe),
|
|
75
|
+
...Object.entries(J.reserved)
|
|
76
76
|
]
|
|
77
|
-
},
|
|
78
|
-
const n =
|
|
79
|
-
return
|
|
80
|
-
},
|
|
81
|
-
const t = e.match(
|
|
77
|
+
}, K = (e, [t, n]) => e.replaceAll(t, n), I = (e, t = Ie) => {
|
|
78
|
+
const n = Z.static.reduce(K, e);
|
|
79
|
+
return Z.url.map(([s, r]) => [t + s + t, r]).reduce(K, n).replaceAll(t, " ");
|
|
80
|
+
}, Pe = ["string", "number", "boolean"], je = (e) => Pe.includes(e), We = /^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/, De = (e) => {
|
|
81
|
+
const t = e.match(We);
|
|
82
82
|
if (!t) throw new Error(`Invalid invocation: ${e}`);
|
|
83
83
|
const [, n, s = ""] = t;
|
|
84
84
|
if (!s.trim()) return { name: n, parameters: [] };
|
|
85
|
-
const r =
|
|
85
|
+
const r = Ue(s);
|
|
86
86
|
return { name: n, parameters: r };
|
|
87
|
-
},
|
|
87
|
+
}, Le = (e, t) => {
|
|
88
88
|
for (let n = t + 1; n < e.length; n++)
|
|
89
89
|
if (e[n] !== void 0) return !1;
|
|
90
90
|
return !0;
|
|
91
|
-
},
|
|
91
|
+
}, Ue = (e) => {
|
|
92
92
|
const t = [];
|
|
93
93
|
let n = "", s = !1;
|
|
94
94
|
for (let r = 0; r < e.length; r++) {
|
|
@@ -98,11 +98,11 @@ const X = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
98
98
|
s = !s, n += l ? "'''" : "''", r += l ? 2 : 1;
|
|
99
99
|
} else i ? (s = !s, n += o) : o === "," && !s ? (t.push(n.trim()), n = "") : n += o;
|
|
100
100
|
}
|
|
101
|
-
return t.push(n.trim()), t.map((r) => r === "" ? void 0 : r ?
|
|
102
|
-
},
|
|
101
|
+
return t.push(n.trim()), t.map((r) => r === "" ? void 0 : r ? qe(r) : void 0).filter((r, o, i) => r !== void 0 || !Le(i, o));
|
|
102
|
+
}, qe = (e) => {
|
|
103
103
|
const t = e.length >= 2 && e[0] === "'" && e.at(-1) === "'", n = t && e.length >= 4 && e[1] === "'" && e.at(-2) === "'";
|
|
104
104
|
return !t || n ? e : e.slice(1, -1);
|
|
105
|
-
},
|
|
105
|
+
}, Be = (e) => {
|
|
106
106
|
const t = /^(\w+)(?:\(([^)]*)\))?/, n = e.match(t);
|
|
107
107
|
if (!n) return { name: e };
|
|
108
108
|
const [, s, r] = n;
|
|
@@ -111,17 +111,17 @@ const X = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
111
111
|
let l;
|
|
112
112
|
for (; (l = o.exec(r)) !== null; ) {
|
|
113
113
|
const [, a, c, u] = l, p = u.trim();
|
|
114
|
-
if (!
|
|
114
|
+
if (!je(p)) throw new Error(`Unsupported type: ${p}`);
|
|
115
115
|
i.push({ name: a, optional: c === "?", type: p });
|
|
116
116
|
}
|
|
117
117
|
return { name: s, parameters: i };
|
|
118
|
-
},
|
|
119
|
-
const t = e.map(
|
|
118
|
+
}, N = (e) => {
|
|
119
|
+
const t = e.map(Be).reduce(
|
|
120
120
|
(n, { name: s, parameters: r }) => n.set(s, r),
|
|
121
121
|
/* @__PURE__ */ new Map()
|
|
122
122
|
);
|
|
123
123
|
return (n) => {
|
|
124
|
-
const { name: s, parameters: r } =
|
|
124
|
+
const { name: s, parameters: r } = De(n);
|
|
125
125
|
if (!t.has(s))
|
|
126
126
|
throw new Error(`Unknown method: ${s}`);
|
|
127
127
|
const o = t.get(s);
|
|
@@ -151,7 +151,7 @@ const X = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
151
151
|
return i;
|
|
152
152
|
}, { name: s });
|
|
153
153
|
};
|
|
154
|
-
},
|
|
154
|
+
}, B = (e) => Object.entries(e).filter(([t]) => t !== "name" && !isNaN(Number(t))).map(([t, n]) => n), Fe = [
|
|
155
155
|
/**
|
|
156
156
|
* Wraps the content in a markdown-formatted code block.
|
|
157
157
|
* @param lang The language of the code block (defaults to the file extension).
|
|
@@ -181,10 +181,10 @@ const X = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
181
181
|
* @example [](<url>?wrap=dropdown(hello_world,,_))
|
|
182
182
|
*/
|
|
183
183
|
"dropdown(summary: string, open?: boolean, space?: string)"
|
|
184
|
-
],
|
|
184
|
+
], He = N(Fe), S = (e, t = 1) => `
|
|
185
185
|
`.repeat(t) + e + `
|
|
186
|
-
`.repeat(t),
|
|
187
|
-
const s =
|
|
186
|
+
`.repeat(t), q = (e, t, n) => `<${t}${n ? ` ${n}` : ""}>${S(e)}</${t}>`, Y = (e, t, n) => {
|
|
187
|
+
const s = He(t);
|
|
188
188
|
switch (s.name) {
|
|
189
189
|
case "code":
|
|
190
190
|
if (!s.lang && !s.meta && (n == null ? void 0 : n.inline) && !e.includes(`
|
|
@@ -194,17 +194,17 @@ const X = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
194
194
|
case "quote":
|
|
195
195
|
return n != null && n.inline && !e.includes(`
|
|
196
196
|
|
|
197
|
-
`) ? `> ${e}` : S(
|
|
197
|
+
`) ? `> ${e}` : S(q(S(e), "blockquote"));
|
|
198
198
|
case "dropdown":
|
|
199
|
-
const l =
|
|
200
|
-
return S(
|
|
199
|
+
const l = q(I(s.summary), "summary");
|
|
200
|
+
return S(q([l, e].join(`
|
|
201
201
|
`), "details", s.open ? "open" : void 0));
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
class d {
|
|
205
205
|
constructor(...t) {
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
k(this, "_intervals", []);
|
|
207
|
+
k(this, "collapsed", !0);
|
|
208
208
|
for (const [n, s] of t)
|
|
209
209
|
this.push(n, s);
|
|
210
210
|
}
|
|
@@ -275,28 +275,28 @@ class d {
|
|
|
275
275
|
return this;
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
|
-
const
|
|
278
|
+
const P = (e) => {
|
|
279
279
|
const t = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm, n = [];
|
|
280
280
|
let s;
|
|
281
281
|
for (; (s = t.exec(e)) !== null; ) {
|
|
282
|
-
const r = [s.index, s.index + s[0].length], o =
|
|
282
|
+
const r = [s.index, s.index + s[0].length], o = Qe(s[0]).trim();
|
|
283
283
|
n.push({ range: r, value: o });
|
|
284
284
|
}
|
|
285
285
|
return n;
|
|
286
|
-
},
|
|
286
|
+
}, Qe = (e) => e.startsWith("//") ? e.slice(2) : e.startsWith("/*") ? e.slice(2, -2) : e.startsWith("<!--") ? e.slice(4, -3) : e, Ge = [
|
|
287
287
|
"p↓:",
|
|
288
288
|
"pd:",
|
|
289
289
|
"parkdown:"
|
|
290
|
-
],
|
|
290
|
+
], ze = [
|
|
291
291
|
"splice(delete?: number, insert?: string)"
|
|
292
292
|
];
|
|
293
|
-
|
|
294
|
-
const
|
|
293
|
+
N(ze);
|
|
294
|
+
const ae = (e, t) => e.range[0] - t.range[0], z = (e, t, n) => (n ?? P(e)).filter(({ value: s }) => s.split(" ").includes(t)).sort(ae), ee = (e) => ({
|
|
295
295
|
isSpace: e === " ",
|
|
296
296
|
isNewline: e === `
|
|
297
297
|
` || e === void 0
|
|
298
|
-
}),
|
|
299
|
-
const o = (w, $) => t.slice(0, w) + t.slice($), i =
|
|
298
|
+
}), te = (e) => Ge.flatMap((t) => z(e, t)).sort((t, n) => t.range[0] - n.range[0]).reverse().reduce((t, { range: [n, s], value: r }) => {
|
|
299
|
+
const o = (w, $) => t.slice(0, w) + t.slice($), i = ee(t[n - 1]), l = ee(t[s]), a = s === t.length;
|
|
300
300
|
let c = n;
|
|
301
301
|
for (; c > 0 && t[c - 1] !== `
|
|
302
302
|
`; ) c--;
|
|
@@ -305,7 +305,7 @@ const pe = (e, t) => e.range[0] - t.range[0], J = (e, t, n) => (n ?? D(e)).filte
|
|
|
305
305
|
`; ) u++;
|
|
306
306
|
const p = t.slice(c, n).trim() === "" && t.slice(s, u).trim() === "";
|
|
307
307
|
return i.isNewline && l.isNewline ? o(n - (a ? 1 : 0), s + 1) : i.isNewline || p ? o(c, s + (l.isSpace || l.isNewline ? 1 : 0)) : o(n - (i.isSpace ? 1 : 0), s);
|
|
308
|
-
}, e),
|
|
308
|
+
}, e), Xe = [
|
|
309
309
|
/**
|
|
310
310
|
* Extract regions from the retrieved content between comments that INCLUDE the specified ids.
|
|
311
311
|
* @param id The id of the comment to extract.
|
|
@@ -345,7 +345,7 @@ const pe = (e, t) => e.range[0] - t.range[0], J = (e, t, n) => (n ?? D(e)).filte
|
|
|
345
345
|
* @example [](<url>?region=remap(specifier,hello-world,hello-universe))
|
|
346
346
|
* @example [](<url>?region=remap(specifier,hello_world,hello_universe,_)
|
|
347
347
|
*/
|
|
348
|
-
"remap(id
|
|
348
|
+
"remap(id?: string, from: string, to?: string, space?: string)",
|
|
349
349
|
/**
|
|
350
350
|
* Make the content of the region a single line (where all whitespace characters, including newlines, are converted to a single space).
|
|
351
351
|
* @param id The id of the comment regions to act on.
|
|
@@ -410,63 +410,63 @@ const pe = (e, t) => e.range[0] - t.range[0], J = (e, t, n) => (n ?? D(e)).filte
|
|
|
410
410
|
* Helpful when trying to determine fine-grained edits (e.g. trimming, splicing, etc.).
|
|
411
411
|
*/
|
|
412
412
|
"debug()"
|
|
413
|
-
],
|
|
414
|
-
const s =
|
|
413
|
+
], Ve = N(Xe), C = (e, t, n) => {
|
|
414
|
+
const s = z(e, t, n), r = [];
|
|
415
415
|
for (let o = 0; o < s.length - 1; o += 2)
|
|
416
416
|
r.push([s[o], s[o + 1]]);
|
|
417
417
|
return r;
|
|
418
|
-
},
|
|
418
|
+
}, Je = (e, t, n) => new d(...z(e, t, n).map(({ range: s }) => s)), j = (e) => _e(e).trim(), Ze = (e, ...t) => {
|
|
419
419
|
if (t.length === 0) return e;
|
|
420
|
-
const n =
|
|
420
|
+
const n = P(e), s = new d(), r = new d();
|
|
421
421
|
for (const o of t)
|
|
422
422
|
for (const [i, l] of C(e, o, n)) {
|
|
423
423
|
s.push(i.range[1], l.range[0]);
|
|
424
424
|
const [a, ...c] = e.slice(i.range[1], l.range[0]), u = c[c.length - 1];
|
|
425
425
|
r.push(i.range[0], i.range[1] + (a.trim() ? 0 : 1)), r.push(l.range[0], l.range[1] + (u.trim() ? 0 : 1));
|
|
426
426
|
}
|
|
427
|
-
return
|
|
428
|
-
},
|
|
427
|
+
return j(s.subtract(r).slice(e));
|
|
428
|
+
}, Ke = (e, ...t) => {
|
|
429
429
|
if (t.length === 0) return e;
|
|
430
|
-
const n =
|
|
430
|
+
const n = P(e), s = ([o, i]) => e.slice(o, i), r = new d();
|
|
431
431
|
for (const o of t)
|
|
432
432
|
for (const [i, l] of C(e, o, n)) {
|
|
433
433
|
const a = s([l.range[1], l.range[1] + 1]).at(-1);
|
|
434
434
|
r.push(i.range[0], a === `
|
|
435
435
|
` ? l.range[1] + 1 : l.range[1]);
|
|
436
436
|
}
|
|
437
|
-
return
|
|
438
|
-
},
|
|
437
|
+
return j(new d([0, e.length]).subtract(r).slice(e));
|
|
438
|
+
}, Ye = (e, t, n, s) => {
|
|
439
439
|
if (!t) return e;
|
|
440
440
|
let r = "", o = 0;
|
|
441
441
|
for (const [i, l] of C(e, t))
|
|
442
|
-
r += e.slice(o, i.range[1]), r +=
|
|
443
|
-
return r += e.slice(o),
|
|
444
|
-
new d([0, r.length]).subtract(
|
|
442
|
+
r += e.slice(o, i.range[1]), r += I(n ?? i.value, s), o = l.range[0];
|
|
443
|
+
return r += e.slice(o), j(
|
|
444
|
+
new d([0, r.length]).subtract(Je(r, t)).slice(r)
|
|
445
445
|
);
|
|
446
|
-
},
|
|
446
|
+
}, et = (e, t, n, s, r, o) => {
|
|
447
447
|
if (!t) return e;
|
|
448
|
-
const i = !(s === void 0 || s < 0), l = r ?
|
|
449
|
-
return C(e, t, c).map((p) => p[n === "start" ? 0 : 1]).sort(
|
|
448
|
+
const i = !(s === void 0 || s < 0), l = r ? I(r, o) : "", a = s ?? 0, c = P(e), u = new d(...c.map(({ range: p }) => p));
|
|
449
|
+
return C(e, t, c).map((p) => p[n === "start" ? 0 : 1]).sort(ae).reverse().reduce((p, { range: w }) => {
|
|
450
450
|
const $ = new d(), M = i ? 1 : -1;
|
|
451
|
-
let
|
|
452
|
-
for (;
|
|
453
|
-
u.test(m) || ($.push(m),
|
|
451
|
+
let b = Math.abs(a), m = i ? w[1] : w[0];
|
|
452
|
+
for (; b > 0 && m < p.length && m >= 0; )
|
|
453
|
+
u.test(m) || ($.push(m), b--), m += M;
|
|
454
454
|
return m = Math.min(Math.max(0, m), p.length), p = p.slice(0, m) + l + p.slice(m), new d([0, p.length]).subtract($.offset(i ? 0 : l.length)).slice(p);
|
|
455
455
|
}, e);
|
|
456
|
-
},
|
|
457
|
-
if (!t) return e;
|
|
456
|
+
}, tt = (e, t, n, s, r) => {
|
|
458
457
|
let o = "", i = 0;
|
|
459
|
-
[n, s] = [n, s ?? ""].map((
|
|
460
|
-
|
|
461
|
-
|
|
458
|
+
[n, s] = [n, s ?? ""].map((a) => I(a, r));
|
|
459
|
+
const l = t ? C(e, t) : [[{ range: [0, 0] }, { range: [e.length, e.length] }]];
|
|
460
|
+
for (const [a, c] of l)
|
|
461
|
+
o += e.slice(i, a.range[1]), o += e.slice(a.range[1], c.range[0]).replaceAll(n, s), i = c.range[0];
|
|
462
462
|
return o += e.slice(i), o;
|
|
463
|
-
},
|
|
463
|
+
}, nt = (e, t) => {
|
|
464
464
|
if (!t) return e;
|
|
465
465
|
let n = "", s = 0;
|
|
466
466
|
for (const [r, o] of C(e, t))
|
|
467
467
|
n += e.slice(s, r.range[1]), n += e.slice(r.range[1], o.range[0]).replaceAll(/[\s\n]+/g, " "), s = o.range[0];
|
|
468
468
|
return n += e.slice(s), n;
|
|
469
|
-
},
|
|
469
|
+
}, ne = (e, t, n) => {
|
|
470
470
|
var o, i, l, a;
|
|
471
471
|
if (!t) return e;
|
|
472
472
|
const s = (c) => /\s/.test(e[c]), r = new d();
|
|
@@ -489,61 +489,61 @@ const pe = (e, t) => e.range[0] - t.range[0], J = (e, t, n) => (n ?? D(e)).filte
|
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
491
|
return new d([0, e.length]).subtract(r).slice(e);
|
|
492
|
-
},
|
|
493
|
-
if (!t) return
|
|
494
|
-
const s =
|
|
492
|
+
}, st = (e, t, n) => {
|
|
493
|
+
if (!t) return te(e);
|
|
494
|
+
const s = Ve(t);
|
|
495
495
|
switch (s.name) {
|
|
496
496
|
case "extract":
|
|
497
|
-
e =
|
|
497
|
+
e = Ze(e, s.id, ...B(s));
|
|
498
498
|
break;
|
|
499
499
|
case "remove":
|
|
500
|
-
e =
|
|
500
|
+
e = Ke(e, s.id, ...B(s));
|
|
501
501
|
break;
|
|
502
502
|
case "replace":
|
|
503
|
-
e =
|
|
503
|
+
e = Ye(e, s.id, s.with, s.space);
|
|
504
504
|
break;
|
|
505
505
|
case "splice-start":
|
|
506
506
|
case "splice-end": {
|
|
507
507
|
const { deleteCount: r, insert: o, space: i, id: l } = s, a = s.name === "splice-start" ? "start" : "end";
|
|
508
|
-
e =
|
|
508
|
+
e = et(e, l, a, r, o, i);
|
|
509
509
|
break;
|
|
510
510
|
}
|
|
511
511
|
case "trim-start":
|
|
512
512
|
case "trim-end": {
|
|
513
513
|
const { left: r, right: o, id: i } = s, l = s.name === "trim-start" ? "start" : "end";
|
|
514
|
-
e =
|
|
514
|
+
e = ne(e, i, { [l]: { left: r ?? !0, right: o ?? !0 } });
|
|
515
515
|
break;
|
|
516
516
|
}
|
|
517
517
|
case "trim": {
|
|
518
518
|
const { inside: r, outside: o, id: i } = s;
|
|
519
|
-
e =
|
|
519
|
+
e = ne(e, i, { start: { left: o ?? !0, right: r ?? !0 }, end: { left: r ?? !0, right: o ?? !0 } });
|
|
520
520
|
break;
|
|
521
521
|
}
|
|
522
522
|
case "single-line":
|
|
523
|
-
e =
|
|
523
|
+
e = nt(e, s.id);
|
|
524
524
|
break;
|
|
525
525
|
case "remap":
|
|
526
|
-
e =
|
|
526
|
+
e = tt(e, s.id, s.from, s.to, s.space);
|
|
527
527
|
break;
|
|
528
528
|
}
|
|
529
|
-
return e = n && s.name !== "debug" ?
|
|
530
|
-
},
|
|
529
|
+
return e = n && s.name !== "debug" ? te(e) : e, n ? j(e) : e;
|
|
530
|
+
}, rt = [
|
|
531
531
|
"recipe(id: string)"
|
|
532
|
-
],
|
|
532
|
+
], ot = [
|
|
533
533
|
"recipe(id: string, 0?: string, 1?: string, 2?: string)"
|
|
534
|
-
],
|
|
535
|
-
register:
|
|
536
|
-
apply:
|
|
537
|
-
},
|
|
534
|
+
], se = {
|
|
535
|
+
register: N(rt),
|
|
536
|
+
apply: N(ot)
|
|
537
|
+
}, _ = class _ {
|
|
538
538
|
constructor() {
|
|
539
|
-
|
|
539
|
+
k(this, "recipes", /* @__PURE__ */ new Map());
|
|
540
540
|
}
|
|
541
|
-
|
|
542
|
-
const n =
|
|
541
|
+
tryStore(t) {
|
|
542
|
+
const n = _.Entries(t);
|
|
543
543
|
for (let s = 0; s < n.length; s++) {
|
|
544
544
|
const [r, o] = n[s];
|
|
545
545
|
if (r !== "register") continue;
|
|
546
|
-
const i =
|
|
546
|
+
const i = se.register(o);
|
|
547
547
|
switch (i.name) {
|
|
548
548
|
case "recipe":
|
|
549
549
|
const l = n.slice(s + 1).filter(([a]) => a !== "register").map(([a, c]) => `${a}=${c}`).join("&");
|
|
@@ -555,17 +555,17 @@ const pe = (e, t) => e.range[0] - t.range[0], J = (e, t, n) => (n ?? D(e)).filte
|
|
|
555
555
|
}
|
|
556
556
|
}
|
|
557
557
|
apply(t) {
|
|
558
|
-
const n =
|
|
558
|
+
const n = _.Entries(t), s = [];
|
|
559
559
|
for (let r = 0; r < n.length; r++) {
|
|
560
560
|
const [o, i] = n[r];
|
|
561
561
|
if (o !== "apply") {
|
|
562
562
|
s.push(`${o}=${i}`);
|
|
563
563
|
continue;
|
|
564
564
|
}
|
|
565
|
-
const l =
|
|
565
|
+
const l = se.apply(i);
|
|
566
566
|
switch (l.name) {
|
|
567
567
|
case "recipe":
|
|
568
|
-
s.push(this.recipes.get(l.id)), s.push(...
|
|
568
|
+
s.push(this.recipes.get(l.id)), s.push(...B(l).map((a) => this.recipes.get(a)));
|
|
569
569
|
break;
|
|
570
570
|
default:
|
|
571
571
|
throw new Error(`Unknown registration: ${l.name}`);
|
|
@@ -574,31 +574,31 @@ const pe = (e, t) => e.range[0] - t.range[0], J = (e, t, n) => (n ?? D(e)).filte
|
|
|
574
574
|
return s.join("&");
|
|
575
575
|
}
|
|
576
576
|
};
|
|
577
|
-
_
|
|
578
|
-
let
|
|
579
|
-
const
|
|
577
|
+
k(_, "Entries", (t) => Array.from(new URLSearchParams(t).entries()));
|
|
578
|
+
let F = _;
|
|
579
|
+
const it = ["http", "./", "../", "?"], lt = ({ url: e }) => it.some((t) => e.startsWith(t)), at = (e) => Q(e) && Me(e) && lt(e), ce = ({ url: e }, t) => `[](${t ? O(t, e) : e})`, g = {
|
|
580
580
|
_open: "<!--",
|
|
581
581
|
_close: "-->",
|
|
582
582
|
_flag: "p↓",
|
|
583
583
|
get begin() {
|
|
584
|
-
return
|
|
584
|
+
return A(g._open, g._flag, "BEGIN", g._close);
|
|
585
585
|
},
|
|
586
586
|
get end() {
|
|
587
|
-
return
|
|
587
|
+
return A(g._open, g._flag, "END", g._close);
|
|
588
588
|
},
|
|
589
589
|
lengthOf(e) {
|
|
590
590
|
const t = `lines: ${e.split(`
|
|
591
591
|
`).length}`, n = `chars: ${e.length}`;
|
|
592
|
-
return
|
|
592
|
+
return A(g._open, g._flag, "length", t, n, g._close);
|
|
593
593
|
}
|
|
594
|
-
},
|
|
595
|
-
|
|
594
|
+
}, re = (e) => (t) => Q(t) && t.value === g[e], ct = ({ position: e, url: t, siblingCount: n }, s) => ({ position: e, url: t, headingDepth: s, inline: n >= 1 }), pt = ({ position: { start: e }, url: t, siblingCount: n }, { position: { end: s } }, r) => ({ position: { start: e, end: s }, url: t, headingDepth: r, inline: n >= 1 }), ut = (e, t, n) => (e.inline ? A : Oe)(
|
|
595
|
+
ce(e, n),
|
|
596
596
|
g.begin,
|
|
597
597
|
g.lengthOf(t),
|
|
598
598
|
t,
|
|
599
599
|
g.end
|
|
600
|
-
),
|
|
601
|
-
const t =
|
|
600
|
+
), mt = (e) => {
|
|
601
|
+
const t = R(e, "heading").reduce((n, { position: s, depth: r }) => n.set(s.start.line, r), /* @__PURE__ */ new Map());
|
|
602
602
|
return (n) => {
|
|
603
603
|
for (let s = n.position.start.line; s >= 1; s--) {
|
|
604
604
|
const r = t.get(s);
|
|
@@ -606,11 +606,11 @@ const lt = ["http", "./", "../", "?"], at = ({ url: e }) => lt.some((t) => e.sta
|
|
|
606
606
|
}
|
|
607
607
|
return 0;
|
|
608
608
|
};
|
|
609
|
-
},
|
|
609
|
+
}, T = {
|
|
610
610
|
openingCommentDoesNotFollowLink: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),
|
|
611
611
|
closingCommentNotMatchedToOpening: ({ position: { start: e } }) => new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),
|
|
612
612
|
openingCommentNotClosed: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)
|
|
613
|
-
},
|
|
613
|
+
}, gt = (e, t) => {
|
|
614
614
|
const n = [], s = [
|
|
615
615
|
...e.map((o) => ({ node: o, type: "open" })),
|
|
616
616
|
...t.map((o) => ({ node: o, type: "close" }))
|
|
@@ -620,113 +620,111 @@ const lt = ["http", "./", "../", "?"], at = ({ url: e }) => lt.some((t) => e.sta
|
|
|
620
620
|
else {
|
|
621
621
|
const i = o.node;
|
|
622
622
|
if (r.length === 0)
|
|
623
|
-
throw
|
|
623
|
+
throw T.closingCommentNotMatchedToOpening(i);
|
|
624
624
|
const l = r.pop().node;
|
|
625
625
|
if (r.length > 0) continue;
|
|
626
626
|
n.push({ open: l, close: i });
|
|
627
627
|
}
|
|
628
628
|
if (r.length > 0)
|
|
629
|
-
throw
|
|
629
|
+
throw T.openingCommentNotClosed(r[0].node);
|
|
630
630
|
return n;
|
|
631
|
-
},
|
|
631
|
+
}, ht = (e, t, n) => {
|
|
632
632
|
const s = [...t].sort(f), r = [];
|
|
633
633
|
return [...n].sort((o, i) => f.reverse(o.open, i.open)).forEach((o) => {
|
|
634
634
|
for (; s.length > 0; ) {
|
|
635
635
|
const i = s.pop();
|
|
636
636
|
if (i.position.start.offset < o.open.position.start.offset) {
|
|
637
637
|
if (Ae(e, i, o.open).trim() !== "")
|
|
638
|
-
throw
|
|
638
|
+
throw T.openingCommentDoesNotFollowLink(o.open);
|
|
639
639
|
return r.push([i, o]);
|
|
640
640
|
}
|
|
641
641
|
r.push(i);
|
|
642
642
|
}
|
|
643
|
-
throw
|
|
643
|
+
throw T.openingCommentDoesNotFollowLink(o.open);
|
|
644
644
|
}), r.push(...s.reverse()), r.reverse();
|
|
645
|
-
},
|
|
646
|
-
t ?? (t =
|
|
647
|
-
const n =
|
|
648
|
-
return
|
|
649
|
-
},
|
|
645
|
+
}, pe = (e, t) => {
|
|
646
|
+
t ?? (t = G.md(e));
|
|
647
|
+
const n = mt(t), s = R(t, "link").filter(at), r = R(t, "html").sort(f), o = r.filter(re("begin")), i = r.filter(re("end")), l = gt(o, i);
|
|
648
|
+
return ht(e, s, l).map((c) => Array.isArray(c) ? pt(c[0], c[1].close, n(c[0])) : ct(c, n(c)));
|
|
649
|
+
}, dt = (e, { url: t }) => (n) => e(O(H(t), n)), ue = (...e) => {
|
|
650
650
|
const t = e.reduce((n, s) => n + s, 0);
|
|
651
651
|
return Math.min(Math.max(t, 1), 6);
|
|
652
|
-
},
|
|
652
|
+
}, ft = (e, t, n) => {
|
|
653
653
|
if (t === 0) return e;
|
|
654
|
-
n ?? (n =
|
|
655
|
-
const s =
|
|
654
|
+
n ?? (n = G.md(e));
|
|
655
|
+
const s = R(n, "heading"), r = e.split(`
|
|
656
656
|
`);
|
|
657
657
|
for (const o of s) {
|
|
658
|
-
const { depth: i, position: { start: l, end: a } } = o, c =
|
|
658
|
+
const { depth: i, position: { start: l, end: a } } = o, c = ue(i, t), u = r[l.line - 1].slice(i, a.column), p = "#".repeat(c) + u;
|
|
659
659
|
r[l.line - 1] = p, o.depth = c;
|
|
660
660
|
}
|
|
661
661
|
return r.join(`
|
|
662
662
|
`);
|
|
663
|
-
},
|
|
663
|
+
}, me = (e) => pe(e).reverse().sort(f.reverse).reduce((t, n) => le(t, ce(n), n), e), ge = (e, t, n, s, r) => {
|
|
664
664
|
try {
|
|
665
|
-
e =
|
|
666
|
-
const o =
|
|
667
|
-
return
|
|
668
|
-
var $, M
|
|
669
|
-
const { url: a, headingDepth: c } = l, [u, ...p] =
|
|
670
|
-
if (a.startsWith("?"))
|
|
671
|
-
|
|
672
|
-
b
|
|
673
|
-
|
|
674
|
-
const
|
|
675
|
-
|
|
676
|
-
const k = new Z(w), L = (M = ((y) => {
|
|
677
|
-
const v = Array.from(k.entries()).filter(([E]) => E === y).map(([E, B]) => B);
|
|
665
|
+
e = me(e), e = ft(e, t);
|
|
666
|
+
const o = G.md(e), i = new F();
|
|
667
|
+
return pe(e, o).sort(f).reverse().map((l) => {
|
|
668
|
+
var $, M;
|
|
669
|
+
const { url: a, headingDepth: c } = l, [u, ...p] = Ce(a).split("?"), w = i.apply(p.join("?"));
|
|
670
|
+
if (a.startsWith("?")) i.tryStore(w);
|
|
671
|
+
else if (a.startsWith("./") || a.startsWith("../")) {
|
|
672
|
+
const b = u.split(".").pop() ?? "", m = H(a), X = O(m, u);
|
|
673
|
+
let h = n(X);
|
|
674
|
+
const x = new Ee(w), W = ($ = ((y) => {
|
|
675
|
+
const v = Array.from(x.entries()).filter(([E]) => E === y).map(([E, U]) => U);
|
|
678
676
|
return v.length >= 1 ? v.join(",") : void 0;
|
|
679
|
-
})("region")) == null ? void 0 :
|
|
680
|
-
h = (
|
|
681
|
-
(y, v, E, { length:
|
|
677
|
+
})("region")) == null ? void 0 : $.split(V);
|
|
678
|
+
h = (W == null ? void 0 : W.reduce(
|
|
679
|
+
(y, v, E, { length: U }) => st(y, v, E === U - 1),
|
|
682
680
|
h
|
|
683
681
|
)) ?? h;
|
|
684
|
-
const
|
|
685
|
-
let { inline:
|
|
686
|
-
if (
|
|
687
|
-
if (
|
|
688
|
-
const y =
|
|
689
|
-
h =
|
|
682
|
+
const fe = x.has("skip"), ve = x.get("heading") ?? 0, we = x.has("inline");
|
|
683
|
+
let { inline: D } = l;
|
|
684
|
+
if (we && (D = !0), !fe)
|
|
685
|
+
if (b === "md") {
|
|
686
|
+
const y = dt(n, l), v = r ? O(r, m) : m, E = ue(c, Number(ve));
|
|
687
|
+
h = ge(
|
|
690
688
|
h,
|
|
691
689
|
/** p↓: ... */
|
|
692
690
|
E,
|
|
693
691
|
y,
|
|
694
|
-
|
|
692
|
+
X,
|
|
695
693
|
v
|
|
696
694
|
/** p↓: ... */
|
|
697
695
|
);
|
|
698
|
-
} else /^(js|ts)x?|svelte$/i.test(
|
|
696
|
+
} else /^(js|ts)x?|svelte$/i.test(b) && (h = Y(
|
|
699
697
|
h,
|
|
700
698
|
"code",
|
|
701
699
|
/** p↓: ... */
|
|
702
|
-
{ extension:
|
|
700
|
+
{ extension: b, inline: D }
|
|
703
701
|
/** p↓: ... */
|
|
704
702
|
));
|
|
705
|
-
const
|
|
706
|
-
return h = (
|
|
703
|
+
const L = (M = x.get("wrap")) == null ? void 0 : M.split(V);
|
|
704
|
+
return h = (L == null ? void 0 : L.reduce((y, v) => Y(y, v, { extension: b, inline: D }), h)) ?? h, { target: l, content: ut(l, h, r) };
|
|
707
705
|
} else throw a.startsWith("http") ? new Error("External web links are not implemented yet") : new Error(`Unsupported link type: ${a}`);
|
|
708
|
-
}).filter(Boolean).reduce((l, { target: a, content: c }) =>
|
|
706
|
+
}).filter(Boolean).reduce((l, { target: a, content: c }) => le(l, c, a), e);
|
|
709
707
|
} catch (o) {
|
|
710
708
|
throw new Error(`Error populating inclusions in file ${s ?? "(unknown)"}: ${o}`);
|
|
711
709
|
}
|
|
712
|
-
},
|
|
713
|
-
const t =
|
|
714
|
-
return { content:
|
|
715
|
-
},
|
|
716
|
-
const { dir: s, path: r, content: o } =
|
|
710
|
+
}, he = (e) => ye(e, "utf-8"), de = (e) => {
|
|
711
|
+
const t = ie(e), n = H(t);
|
|
712
|
+
return { content: he(t), dir: n, path: t };
|
|
713
|
+
}, vt = (e, t = !0, n) => {
|
|
714
|
+
const { dir: s, path: r, content: o } = de(e);
|
|
717
715
|
n == null || n.unwatch(r), n == null || n.once("change", (a, c) => {
|
|
718
|
-
console.log(`Change detected in "${a}". Regenerating "${r}"...`),
|
|
716
|
+
console.log(`Change detected in "${a}". Regenerating "${r}"...`), vt(e, t, n);
|
|
719
717
|
});
|
|
720
|
-
const l =
|
|
721
|
-
const c =
|
|
722
|
-
return n == null || n.add(c),
|
|
718
|
+
const l = ge(o, 0, (a) => {
|
|
719
|
+
const c = ie(s, Te(a));
|
|
720
|
+
return n == null || n.add(c), he(c);
|
|
723
721
|
}, r);
|
|
724
|
-
return t &&
|
|
725
|
-
},
|
|
726
|
-
const { path: s, content: r } =
|
|
727
|
-
return t &&
|
|
722
|
+
return t && oe(r, l), n == null || n.add(r), l;
|
|
723
|
+
}, _t = (e, t = !0, n) => {
|
|
724
|
+
const { path: s, content: r } = de(e), o = me(r);
|
|
725
|
+
return t && oe(s, o), o;
|
|
728
726
|
};
|
|
729
727
|
export {
|
|
730
|
-
|
|
731
|
-
|
|
728
|
+
_t as depopulateMarkdownInclusions,
|
|
729
|
+
vt as populateMarkdownInclusions
|
|
732
730
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
(function(u,
|
|
2
|
-
`),
|
|
3
|
-
`}},
|
|
1
|
+
(function(u,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("node:fs"),require("node:path"),require("node:url"),require("unified"),require("remark-parse"),require("unist-util-visit"),require("ts-dedent")):typeof define=="function"&&define.amd?define(["exports","node:fs","node:path","node:url","unified","remark-parse","unist-util-visit","ts-dedent"],m):(u=typeof globalThis<"u"?globalThis:u||self,m(u.index={},u.node_fs,u.node_path,u.node_url,u.unified,u.remarkParse,u.unistUtilVisit,u.tsDedent))})(this,function(u,m,g,fe,ve,we,$e,ye){"use strict";var ut=Object.defineProperty;var dt=(u,m,g)=>m in u?ut(u,m,{enumerable:!0,configurable:!0,writable:!0,value:g}):u[m]=g;var j=(u,m,g)=>dt(u,typeof m!="symbol"?m+"":m,g);const $=(e,t)=>e.position.start.offset-t.position.start.offset;$.reverse=(e,t)=>$(t,e);const W=e=>e.position!==void 0&&e.position.start.offset!==void 0&&e.position.end.offset!==void 0,Ce=ve.unified().use(we),L={md:e=>Ce.parse(e)},A=(e,t)=>{const n=[];return $e.visit(e,(s,r,i)=>{if(s.type!=="root"){if(t&&s.type!==t)return;if(W(s)){const o=((i==null?void 0:i.children.length)??0)-1;n.push({...s,siblingIndex:r,siblingCount:o})}}}),n},be=e=>e.children.length===0,X=(e,t,...n)=>{if(n.length===0)throw new Error("No nodes to replace content from");n.sort($);const s=n.at(0),r=n.at(-1);return e.slice(0,s.position.start.offset)+t+e.slice(r.position.end.offset)},Ee=(e,t,n)=>{const s=Math.min(t.position.end.offset,n.position.end.offset),r=Math.max(t.position.start.offset,n.position.start.offset);return e.slice(s,r)},O=(...e)=>e.join(" "),Se=(...e)=>e.join(`
|
|
2
|
+
`),ke=e=>{const t=e.split("?");return t.length>1?[t.slice(0,-1).join("?"),t.at(-1)]:[e,""]},xe=e=>ke(e)[0],J=/,\s*(?![^()]*\))/,Z={reserved:{semi:";",slash:"/",question:"?",colon:":",at:"@",equal:"=",and:"&"},unsafe:{quote:'"',angle:"<",unangle:">",hash:"#",percent:"%",curly:"{",uncurly:"}",pipe:"|",back:"\\",carrot:"^",tilde:"~",square:"[",unsquare:"]",tick:"`",line:`
|
|
3
|
+
`}},Ne="-",K={static:[["'''",'"'],["''","'"],[/parkdown:\s+/g,""],[/p↓:\s+/g,""]],url:[...Object.entries(Z.unsafe),...Object.entries(Z.reserved)]},Y=(e,[t,n])=>e.replaceAll(t,n),I=(e,t=Ne)=>{const n=K.static.reduce(Y,e);return K.url.map(([s,r])=>[t+s+t,r]).reduce(Y,n).replaceAll(t," ")},Me=["string","number","boolean"],Te=e=>Me.includes(e),_e=/^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/,je=e=>{const t=e.match(_e);if(!t)throw new Error(`Invalid invocation: ${e}`);const[,n,s=""]=t;if(!s.trim())return{name:n,parameters:[]};const r=Oe(s);return{name:n,parameters:r}},Ae=(e,t)=>{for(let n=t+1;n<e.length;n++)if(e[n]!==void 0)return!1;return!0},Oe=e=>{const t=[];let n="",s=!1;for(let r=0;r<e.length;r++){const i=e[r],o=i==="'";if(o&&e.at(r+1)==="'"){const l=e.at(r+2)==="'";s=!s,n+=l?"'''":"''",r+=l?2:1}else o?(s=!s,n+=i):i===","&&!s?(t.push(n.trim()),n=""):n+=i}return t.push(n.trim()),t.map(r=>r===""?void 0:r?Ie(r):void 0).filter((r,i,o)=>r!==void 0||!Ae(o,i))},Ie=e=>{const t=e.length>=2&&e[0]==="'"&&e.at(-1)==="'",n=t&&e.length>=4&&e[1]==="'"&&e.at(-2)==="'";return!t||n?e:e.slice(1,-1)},qe=e=>{const t=/^(\w+)(?:\(([^)]*)\))?/,n=e.match(t);if(!n)return{name:e};const[,s,r]=n;if(!r)return{name:s};const i=/(\w+)(\?)?:\s*([^,]+)/g,o=[];let l;for(;(l=i.exec(r))!==null;){const[,c,a,d]=l,p=d.trim();if(!Te(p))throw new Error(`Unsupported type: ${p}`);o.push({name:c,optional:a==="?",type:p})}return{name:s,parameters:o}},M=e=>{const t=e.map(qe).reduce((n,{name:s,parameters:r})=>n.set(s,r),new Map);return n=>{const{name:s,parameters:r}=je(n);if(!t.has(s))throw new Error(`Unknown method: ${s}`);const i=t.get(s);if(i===void 0)return{name:s};if(r.length>i.length){const o=i.filter(({optional:c})=>!c).length,l=o===i.length?o.toString():`${o} - ${i.length}`;throw new Error(`Too many parameters: ${r.length} for method '${s}' (expected: ${l})`)}return i.reduce((o,{name:l,optional:c,type:a},d)=>{const p=r[d];if(p===void 0){if(c)return o;throw new Error(`Missing required parameter: ${l} for method '${s}'`)}switch(a){case"string":o[l]=p;break;case"number":case"boolean":o[l]=JSON.parse(p);break}if(typeof o[l]!==a)throw new Error(`Invalid type: ${l} must be ${a}, got ${typeof o[l]} for method '${s}'`);return o},{name:s})}},U=e=>Object.entries(e).filter(([t])=>t!=="name"&&!isNaN(Number(t))).map(([t,n])=>n),Re=M(["code(lang?: string, meta?: string)","quote()","dropdown(summary: string, open?: boolean, space?: string)"]),x=(e,t=1)=>`
|
|
4
4
|
`.repeat(t)+e+`
|
|
5
|
-
`.repeat(t),
|
|
5
|
+
`.repeat(t),B=(e,t,n)=>`<${t}${n?` ${n}`:""}>${x(e)}</${t}>`,ee=(e,t,n)=>{const s=Re(t);switch(s.name){case"code":if(!s.lang&&!s.meta&&(n==null?void 0:n.inline)&&!e.includes(`
|
|
6
6
|
`))return`\`${e}\``;const i=s.lang??(n==null?void 0:n.extension)??"",o=s.meta?` ${s.meta}`:"";return x(`\`\`\`${i}${o}${x(e)}\`\`\``);case"quote":return n!=null&&n.inline&&!e.includes(`
|
|
7
7
|
|
|
8
|
-
`)?`> ${e}`:x(
|
|
9
|
-
`),"details",s.open?"open":void 0))}};class v{constructor(...t){
|
|
10
|
-
`||e===void 0}),
|
|
11
|
-
`;)a--;let
|
|
12
|
-
`;)
|
|
13
|
-
`?l.range[1]+1:l.range[1])}return
|
|
14
|
-
`).length}`,n=`chars: ${e.length}`;return O(
|
|
15
|
-
`);for(const i of s){const{depth:o,position:{start:l,end:c}}=i,a=
|
|
16
|
-
`)},
|
|
8
|
+
`)?`> ${e}`:x(B(x(e),"blockquote"));case"dropdown":const l=B(I(s.summary),"summary");return x(B([l,e].join(`
|
|
9
|
+
`),"details",s.open?"open":void 0))}};class v{constructor(...t){j(this,"_intervals",[]);j(this,"collapsed",!0);for(const[n,s]of t)this.push(n,s)}get intervals(){return this._intervals}push(t,n){return n??(n=t+1),this._intervals.push([Math.min(t,n),Math.max(t,n)]),this.collapsed=!1,this}combine(t){for(const[n,s]of t.intervals)this.push(n,s);return this}collapse(t=!1){const{_intervals:n,collapsed:s}=this;if(s&&!t||!n.length)return this;n.sort((l,c)=>l[0]-c[0]);const r=[];let[i,o]=n[0];for(let l=1;l<n.length;l++){const[c,a]=n[l];c<=o?o=Math.max(o,a):(r.push([i,o]),i=c,o=a)}return r.push([i,o]),this._intervals=r,this.collapsed=!0,this}subtract(t){this.collapse(),t.collapse();const{_intervals:n}=this,{_intervals:s}=t;if(!n.length||!s.length)return this;let r=[...n];for(const[i,o]of s){const l=[];for(const[c,a]of r){if(o<=c||i>=a){l.push([c,a]);continue}i>c&&l.push([c,i]),o<a&&l.push([o,a])}r=l}return this._intervals=r,this.collapse(!0),this}test(t,n="head"){const{_intervals:s}=this;switch(n){case"head":return s.some(([r,i])=>t>=r&&t<i);case"tail":return s.some(([r,i])=>t>r&&t<=i);case"both":return s.some(([r,i])=>t>=r&&t<=i);case"none":return s.some(([r,i])=>t>r&&t<i)}}slice(t){this.collapse();const n=[];for(const[s,r]of this._intervals)n.push(t.slice(s,r));return n.filter(Boolean).join("")}offset(t){for(const n of this._intervals)n[0]+=t,n[1]+=t;return this}}const q=e=>{const t=/(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm,n=[];let s;for(;(s=t.exec(e))!==null;){const r=[s.index,s.index+s[0].length],i=Pe(s[0]).trim();n.push({range:r,value:i})}return n},Pe=e=>e.startsWith("//")?e.slice(2):e.startsWith("/*")?e.slice(2,-2):e.startsWith("<!--")?e.slice(4,-3):e,De=["p↓:","pd:","parkdown:"];M(["splice(delete?: number, insert?: string)"]);const te=(e,t)=>e.range[0]-t.range[0],F=(e,t,n)=>(n??q(e)).filter(({value:s})=>s.split(" ").includes(t)).sort(te),ne=e=>({isSpace:e===" ",isNewline:e===`
|
|
10
|
+
`||e===void 0}),se=e=>De.flatMap(t=>F(e,t)).sort((t,n)=>t.range[0]-n.range[0]).reverse().reduce((t,{range:[n,s],value:r})=>{const i=(b,E)=>t.slice(0,b)+t.slice(E),o=ne(t[n-1]),l=ne(t[s]),c=s===t.length;let a=n;for(;a>0&&t[a-1]!==`
|
|
11
|
+
`;)a--;let d=s;for(;d<t.length&&t[d]!==`
|
|
12
|
+
`;)d++;const p=t.slice(a,n).trim()===""&&t.slice(s,d).trim()==="";return o.isNewline&&l.isNewline?i(n-(c?1:0),s+1):o.isNewline||p?i(a,s+(l.isSpace||l.isNewline?1:0)):i(n-(o.isSpace?1:0),s)},e),We=M(["extract(id: string, 0?: string, 1?: string, 2?: string)","remove(id: string, 0?: string, 1?: string, 2?: string)","replace(id: string, with?: string, space?: string)","remap(id?: string, from: string, to?: string, space?: string)","single-line(id: string, includeBoundaries?: boolean)","trim(id: string, inside?: boolean, outside?: boolean)","trim-start(id: string, left?: boolean, right?: boolean)","trim-end(id: string, left?: boolean, right?: boolean)","splice-start(id: string, deleteCount?: number, insert?: string, space?: string)","splice-end(id: string, deleteCount?: number, insert?: string, space?: string)","debug()"]),C=(e,t,n)=>{const s=F(e,t,n),r=[];for(let i=0;i<s.length-1;i+=2)r.push([s[i],s[i+1]]);return r},Le=(e,t,n)=>new v(...F(e,t,n).map(({range:s})=>s)),R=e=>ye.dedent(e).trim(),Ue=(e,...t)=>{if(t.length===0)return e;const n=q(e),s=new v,r=new v;for(const i of t)for(const[o,l]of C(e,i,n)){s.push(o.range[1],l.range[0]);const[c,...a]=e.slice(o.range[1],l.range[0]),d=a[a.length-1];r.push(o.range[0],o.range[1]+(c.trim()?0:1)),r.push(l.range[0],l.range[1]+(d.trim()?0:1))}return R(s.subtract(r).slice(e))},Be=(e,...t)=>{if(t.length===0)return e;const n=q(e),s=([i,o])=>e.slice(i,o),r=new v;for(const i of t)for(const[o,l]of C(e,i,n)){const c=s([l.range[1],l.range[1]+1]).at(-1);r.push(o.range[0],c===`
|
|
13
|
+
`?l.range[1]+1:l.range[1])}return R(new v([0,e.length]).subtract(r).slice(e))},Fe=(e,t,n,s)=>{if(!t)return e;let r="",i=0;for(const[o,l]of C(e,t))r+=e.slice(i,o.range[1]),r+=I(n??o.value,s),i=l.range[0];return r+=e.slice(i),R(new v([0,r.length]).subtract(Le(r,t)).slice(r))},He=(e,t,n,s,r,i)=>{if(!t)return e;const o=!(s===void 0||s<0),l=r?I(r,i):"",c=s??0,a=q(e),d=new v(...a.map(({range:p})=>p));return C(e,t,a).map(p=>p[n==="start"?0:1]).sort(te).reverse().reduce((p,{range:b})=>{const E=new v,D=o?1:-1;let S=Math.abs(c),f=o?b[1]:b[0];for(;S>0&&f<p.length&&f>=0;)d.test(f)||(E.push(f),S--),f+=D;return f=Math.min(Math.max(0,f),p.length),p=p.slice(0,f)+l+p.slice(f),new v([0,p.length]).subtract(E.offset(o?0:l.length)).slice(p)},e)},Qe=(e,t,n,s,r)=>{let i="",o=0;[n,s]=[n,s??""].map(c=>I(c,r));const l=t?C(e,t):[[{range:[0,0]},{range:[e.length,e.length]}]];for(const[c,a]of l)i+=e.slice(o,c.range[1]),i+=e.slice(c.range[1],a.range[0]).replaceAll(n,s),o=a.range[0];return i+=e.slice(o),i},Ge=(e,t)=>{if(!t)return e;let n="",s=0;for(const[r,i]of C(e,t))n+=e.slice(s,r.range[1]),n+=e.slice(r.range[1],i.range[0]).replaceAll(/[\s\n]+/g," "),s=i.range[0];return n+=e.slice(s),n},re=(e,t,n)=>{var i,o,l,c;if(!t)return e;const s=a=>/\s/.test(e[a]),r=new v;for(const[a,d]of C(e,t)){if((i=n.start)!=null&&i.left){let p=a.range[0]-1;for(;s(p);)r.push(p--)}if((o=n.start)!=null&&o.right){let p=a.range[1];for(;s(p);)r.push(p++)}if((l=n.end)!=null&&l.left){let p=d.range[0]-1;for(;s(p);)r.push(p--)}if((c=n.end)!=null&&c.right){let p=d.range[1];for(;s(p);)r.push(p++)}}return new v([0,e.length]).subtract(r).slice(e)},ze=(e,t,n)=>{if(!t)return se(e);const s=We(t);switch(s.name){case"extract":e=Ue(e,s.id,...U(s));break;case"remove":e=Be(e,s.id,...U(s));break;case"replace":e=Fe(e,s.id,s.with,s.space);break;case"splice-start":case"splice-end":{const{deleteCount:r,insert:i,space:o,id:l}=s,c=s.name==="splice-start"?"start":"end";e=He(e,l,c,r,i,o);break}case"trim-start":case"trim-end":{const{left:r,right:i,id:o}=s,l=s.name==="trim-start"?"start":"end";e=re(e,o,{[l]:{left:r??!0,right:i??!0}});break}case"trim":{const{inside:r,outside:i,id:o}=s;e=re(e,o,{start:{left:i??!0,right:r??!0},end:{left:r??!0,right:i??!0}});break}case"single-line":e=Ge(e,s.id);break;case"remap":e=Qe(e,s.id,s.from,s.to,s.space);break}return e=n&&s.name!=="debug"?se(e):e,n?R(e):e},Ve=["recipe(id: string)"],Xe=["recipe(id: string, 0?: string, 1?: string, 2?: string)"],ie={register:M(Ve),apply:M(Xe)},T=class T{constructor(){j(this,"recipes",new Map)}tryStore(t){const n=T.Entries(t);for(let s=0;s<n.length;s++){const[r,i]=n[s];if(r!=="register")continue;const o=ie.register(i);switch(o.name){case"recipe":const l=n.slice(s+1).filter(([c])=>c!=="register").map(([c,a])=>`${c}=${a}`).join("&");this.recipes.set(o.id,l);break;default:throw new Error(`Unknown registration: ${o.name}`)}}}apply(t){const n=T.Entries(t),s=[];for(let r=0;r<n.length;r++){const[i,o]=n[r];if(i!=="apply"){s.push(`${i}=${o}`);continue}const l=ie.apply(o);switch(l.name){case"recipe":s.push(this.recipes.get(l.id)),s.push(...U(l).map(c=>this.recipes.get(c)));break;default:throw new Error(`Unknown registration: ${l.name}`)}}return s.join("&")}};j(T,"Entries",t=>Array.from(new URLSearchParams(t).entries()));let H=T;const Je=["http","./","../","?"],Ze=({url:e})=>Je.some(t=>e.startsWith(t)),Ke=e=>W(e)&&be(e)&&Ze(e),oe=({url:e},t)=>`[](${t?g.join(t,e):e})`,h={_open:"<!--",_close:"-->",_flag:"p↓",get begin(){return O(h._open,h._flag,"BEGIN",h._close)},get end(){return O(h._open,h._flag,"END",h._close)},lengthOf(e){const t=`lines: ${e.split(`
|
|
14
|
+
`).length}`,n=`chars: ${e.length}`;return O(h._open,h._flag,"length",t,n,h._close)}},le=e=>t=>W(t)&&t.value===h[e],Ye=({position:e,url:t,siblingCount:n},s)=>({position:e,url:t,headingDepth:s,inline:n>=1}),et=({position:{start:e},url:t,siblingCount:n},{position:{end:s}},r)=>({position:{start:e,end:s},url:t,headingDepth:r,inline:n>=1}),tt=(e,t,n)=>(e.inline?O:Se)(oe(e,n),h.begin,h.lengthOf(t),t,h.end),nt=e=>{const t=A(e,"heading").reduce((n,{position:s,depth:r})=>n.set(s.start.line,r),new Map);return n=>{for(let s=n.position.start.line;s>=1;s--){const r=t.get(s);if(r)return r}return 0}},P={openingCommentDoesNotFollowLink:({position:{start:e}})=>new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),closingCommentNotMatchedToOpening:({position:{start:e}})=>new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),openingCommentNotClosed:({position:{start:e}})=>new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)},st=(e,t)=>{const n=[],s=[...e.map(i=>({node:i,type:"open"})),...t.map(i=>({node:i,type:"close"}))].sort((i,o)=>$(i.node,o.node)),r=[];for(const i of s)if(i.type==="open")r.push(i);else{const o=i.node;if(r.length===0)throw P.closingCommentNotMatchedToOpening(o);const l=r.pop().node;if(r.length>0)continue;n.push({open:l,close:o})}if(r.length>0)throw P.openingCommentNotClosed(r[0].node);return n},rt=(e,t,n)=>{const s=[...t].sort($),r=[];return[...n].sort((i,o)=>$.reverse(i.open,o.open)).forEach(i=>{for(;s.length>0;){const o=s.pop();if(o.position.start.offset<i.open.position.start.offset){if(Ee(e,o,i.open).trim()!=="")throw P.openingCommentDoesNotFollowLink(i.open);return r.push([o,i])}r.push(o)}throw P.openingCommentDoesNotFollowLink(i.open)}),r.push(...s.reverse()),r.reverse()},ce=(e,t)=>{t??(t=L.md(e));const n=nt(t),s=A(t,"link").filter(Ke),r=A(t,"html").sort($),i=r.filter(le("begin")),o=r.filter(le("end")),l=st(i,o);return rt(e,s,l).map(a=>Array.isArray(a)?et(a[0],a[1].close,n(a[0])):Ye(a,n(a)))},it=(e,{url:t})=>n=>e(g.join(g.dirname(t),n)),ae=(...e)=>{const t=e.reduce((n,s)=>n+s,0);return Math.min(Math.max(t,1),6)},ot=(e,t,n)=>{if(t===0)return e;n??(n=L.md(e));const s=A(n,"heading"),r=e.split(`
|
|
15
|
+
`);for(const i of s){const{depth:o,position:{start:l,end:c}}=i,a=ae(o,t),d=r[l.line-1].slice(o,c.column),p="#".repeat(a)+d;r[l.line-1]=p,i.depth=a}return r.join(`
|
|
16
|
+
`)},pe=e=>ce(e).reverse().sort($.reverse).reduce((t,n)=>X(t,oe(n),n),e),ue=(e,t,n,s,r)=>{try{e=pe(e),e=ot(e,t);const i=L.md(e),o=new H;return ce(e,i).sort($).reverse().map(l=>{var E,D;const{url:c,headingDepth:a}=l,[d,...p]=g.basename(c).split("?"),b=o.apply(p.join("?"));if(c.startsWith("?"))o.tryStore(b);else if(c.startsWith("./")||c.startsWith("../")){const S=d.split(".").pop()??"",f=g.dirname(c),he=g.join(f,d);let w=n(he);const _=new fe.URLSearchParams(b),Q=(E=(k=>{const y=Array.from(_.entries()).filter(([N])=>N===k).map(([N,V])=>V);return y.length>=1?y.join(","):void 0})("region"))==null?void 0:E.split(J);w=(Q==null?void 0:Q.reduce((k,y,N,{length:V})=>ze(k,y,N===V-1),w))??w;const ct=_.has("skip"),at=_.get("heading")??0,pt=_.has("inline");let{inline:G}=l;if(pt&&(G=!0),!ct)if(S==="md"){const k=it(n,l),y=r?g.join(r,f):f,N=ae(a,Number(at));w=ue(w,N,k,he,y)}else/^(js|ts)x?|svelte$/i.test(S)&&(w=ee(w,"code",{extension:S,inline:G}));const z=(D=_.get("wrap"))==null?void 0:D.split(J);return w=(z==null?void 0:z.reduce((k,y)=>ee(k,y,{extension:S,inline:G}),w))??w,{target:l,content:tt(l,w,r)}}else throw c.startsWith("http")?new Error("External web links are not implemented yet"):new Error(`Unsupported link type: ${c}`)}).filter(Boolean).reduce((l,{target:c,content:a})=>X(l,a,c),e)}catch(i){throw new Error(`Error populating inclusions in file ${s??"(unknown)"}: ${i}`)}},de=e=>m.readFileSync(e,"utf-8"),me=e=>{const t=g.resolve(e),n=g.dirname(t);return{content:de(t),dir:n,path:t}},ge=(e,t=!0,n)=>{const{dir:s,path:r,content:i}=me(e);n==null||n.unwatch(r),n==null||n.once("change",(c,a)=>{console.log(`Change detected in "${c}". Regenerating "${r}"...`),ge(e,t,n)});const l=ue(i,0,c=>{const a=g.resolve(s,xe(c));return n==null||n.add(a),de(a)},r);return t&&m.writeFileSync(r,l),n==null||n.add(r),l},lt=(e,t=!0,n)=>{const{path:s,content:r}=me(e),i=pe(r);return t&&m.writeFileSync(s,i),i};u.depopulateMarkdownInclusions=lt,u.populateMarkdownInclusions=ge,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|