@p-buddy/parkdown 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/index.js +116 -113
- package/dist/index.umd.cjs +10 -10
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command as t } from "@commander-js/extra-typings";
|
|
3
3
|
import { populateMarkdownInclusions as l, depopulateMarkdownInclusions as r } from "@p-buddy/parkdown";
|
|
4
|
-
const f = "0.0.
|
|
4
|
+
const f = "0.0.8", p = new t().version(f).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", (s, o) => (o.push(s), o), new Array()).parse(), { inclusions: c, depopulate: u, file: n, write: i } = p.opts();
|
|
5
5
|
n.length === 0 && n.push("README.md");
|
|
6
6
|
const a = [
|
|
7
7
|
[l, !c],
|
package/dist/index.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
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 ue = Object.defineProperty;
|
|
2
|
+
var he = (e, t, n) => t in e ? ue(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var q = (e, t, n) => he(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { writeFileSync as J, readFileSync as ge } from "node:fs";
|
|
5
|
+
import { basename as fe, dirname as j, join as S, resolve as Z } from "node:path";
|
|
6
|
+
import { URLSearchParams as de } from "node:url";
|
|
7
|
+
import { unified as we } from "unified";
|
|
8
|
+
import ve from "remark-parse";
|
|
9
|
+
import { visit as $e } from "unist-util-visit";
|
|
10
|
+
import { dedent as D } from "ts-dedent";
|
|
11
11
|
const g = (e, t) => e.position.start.offset - t.position.start.offset;
|
|
12
12
|
g.reverse = (e, t) => g(t, e);
|
|
13
|
-
const
|
|
14
|
-
md: (e) =>
|
|
13
|
+
const I = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, Ce = we().use(ve), R = {
|
|
14
|
+
md: (e) => Ce.parse(e)
|
|
15
15
|
}, N = (e, t) => {
|
|
16
16
|
const n = [];
|
|
17
|
-
return
|
|
17
|
+
return $e(e, (s, o, r) => {
|
|
18
18
|
if (s.type !== "root") {
|
|
19
19
|
if (t && s.type !== t) return;
|
|
20
|
-
if (
|
|
20
|
+
if (I(s)) {
|
|
21
21
|
const i = ((r == null ? void 0 : r.children.length) ?? 0) - 1;
|
|
22
22
|
n.push({ ...s, siblingIndex: o, siblingCount: i });
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}), n;
|
|
26
|
-
},
|
|
26
|
+
}, ye = (e) => e.children.length === 0, K = (e, t, ...n) => {
|
|
27
27
|
if (n.length === 0) throw new Error("No nodes to replace content from");
|
|
28
28
|
n.sort(g);
|
|
29
29
|
const s = n.at(0), o = n.at(-1);
|
|
30
30
|
return e.slice(0, s.position.start.offset) + t + e.slice(o.position.end.offset);
|
|
31
|
-
},
|
|
31
|
+
}, Ee = (e, t, n) => {
|
|
32
32
|
const s = Math.min(t.position.end.offset, n.position.end.offset), o = Math.max(t.position.start.offset, n.position.start.offset);
|
|
33
33
|
return e.slice(s, o);
|
|
34
|
-
}, E = (...e) => e.join(" "),
|
|
35
|
-
`),
|
|
34
|
+
}, E = (...e) => e.join(" "), Se = (...e) => e.join(`
|
|
35
|
+
`), Ne = (e) => {
|
|
36
36
|
const t = e.split("?");
|
|
37
37
|
return t.length > 1 ? [t.slice(0, -1).join("?"), t.at(-1)] : [e, ""];
|
|
38
|
-
},
|
|
38
|
+
}, xe = (e) => Ne(e)[0];
|
|
39
39
|
class d {
|
|
40
40
|
constructor() {
|
|
41
|
-
|
|
41
|
+
q(this, "intervals", []);
|
|
42
42
|
}
|
|
43
43
|
push(t, n) {
|
|
44
44
|
this.intervals.push([Math.min(t, n), Math.max(t, n)]);
|
|
@@ -76,7 +76,7 @@ class d {
|
|
|
76
76
|
return this.intervals = o;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
const
|
|
79
|
+
const B = /,\s*(?![^()]*\))/, F = {
|
|
80
80
|
reserved: {
|
|
81
81
|
semi: ";",
|
|
82
82
|
slash: "/",
|
|
@@ -102,7 +102,7 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
102
102
|
unsquare: "]",
|
|
103
103
|
tick: "`"
|
|
104
104
|
}
|
|
105
|
-
},
|
|
105
|
+
}, ke = "-", U = {
|
|
106
106
|
static: [
|
|
107
107
|
["'''", '"'],
|
|
108
108
|
["''", "'"],
|
|
@@ -110,24 +110,24 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
110
110
|
[/p↓:\s+/g, ""]
|
|
111
111
|
],
|
|
112
112
|
url: [
|
|
113
|
-
...Object.entries(
|
|
114
|
-
...Object.entries(
|
|
113
|
+
...Object.entries(F.unsafe),
|
|
114
|
+
...Object.entries(F.reserved)
|
|
115
115
|
]
|
|
116
|
-
},
|
|
117
|
-
const n =
|
|
118
|
-
return
|
|
119
|
-
},
|
|
120
|
-
const t = e.match(
|
|
116
|
+
}, G = (e, [t, n]) => e.replaceAll(t, n), Y = (e, t = ke) => {
|
|
117
|
+
const n = U.static.reduce(G, e);
|
|
118
|
+
return U.url.map(([s, o]) => [t + s + t, o]).reduce(G, n).replaceAll(t, " ");
|
|
119
|
+
}, be = ["string", "number", "boolean"], _e = (e) => be.includes(e), Te = /^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/, Oe = (e) => {
|
|
120
|
+
const t = e.match(Te);
|
|
121
121
|
if (!t) throw new Error(`Invalid invocation: ${e}`);
|
|
122
122
|
const [, n, s = ""] = t;
|
|
123
123
|
if (!s.trim()) return { name: n, parameters: [] };
|
|
124
|
-
const o =
|
|
124
|
+
const o = je(s);
|
|
125
125
|
return { name: n, parameters: o };
|
|
126
|
-
},
|
|
126
|
+
}, Me = (e, t) => {
|
|
127
127
|
for (let n = t + 1; n < e.length; n++)
|
|
128
128
|
if (e[n] !== void 0) return !1;
|
|
129
129
|
return !0;
|
|
130
|
-
},
|
|
130
|
+
}, je = (e) => {
|
|
131
131
|
const t = [];
|
|
132
132
|
let n = "", s = !1;
|
|
133
133
|
for (let o = 0; o < e.length; o++) {
|
|
@@ -137,11 +137,11 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
137
137
|
s = !s, n += c ? "'''" : "''", o += c ? 2 : 1;
|
|
138
138
|
} else i ? (s = !s, n += r) : r === "," && !s ? (t.push(n.trim()), n = "") : n += r;
|
|
139
139
|
}
|
|
140
|
-
return t.push(n.trim()), t.map((o) => o === "" ? void 0 : o ?
|
|
141
|
-
},
|
|
140
|
+
return t.push(n.trim()), t.map((o) => o === "" ? void 0 : o ? De(o) : void 0).filter((o, r, i) => o !== void 0 || !Me(i, r));
|
|
141
|
+
}, De = (e) => {
|
|
142
142
|
const t = e.length >= 2 && e[0] === "'" && e.at(-1) === "'", n = t && e.length >= 4 && e[1] === "'" && e.at(-2) === "'";
|
|
143
143
|
return !t || n ? e : e.slice(1, -1);
|
|
144
|
-
},
|
|
144
|
+
}, Ie = (e) => {
|
|
145
145
|
const t = /^(\w+)(?:\(([^)]*)\))?/, n = e.match(t);
|
|
146
146
|
if (!n) return { name: e };
|
|
147
147
|
const [, s, o] = n;
|
|
@@ -150,17 +150,17 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
150
150
|
let c;
|
|
151
151
|
for (; (c = r.exec(o)) !== null; ) {
|
|
152
152
|
const [, l, a, p] = c, m = p.trim();
|
|
153
|
-
if (!
|
|
153
|
+
if (!_e(m)) throw new Error(`Unsupported type: ${m}`);
|
|
154
154
|
i.push({ name: l, optional: a === "?", type: m });
|
|
155
155
|
}
|
|
156
156
|
return { name: s, parameters: i };
|
|
157
|
-
},
|
|
158
|
-
const t = e.map(
|
|
157
|
+
}, ee = (e) => {
|
|
158
|
+
const t = e.map(Ie).reduce(
|
|
159
159
|
(n, { name: s, parameters: o }) => n.set(s, o),
|
|
160
160
|
/* @__PURE__ */ new Map()
|
|
161
161
|
);
|
|
162
162
|
return (n) => {
|
|
163
|
-
const { name: s, parameters: o } =
|
|
163
|
+
const { name: s, parameters: o } = Oe(n);
|
|
164
164
|
if (!t.has(s))
|
|
165
165
|
throw new Error(`Unknown method: ${s}`);
|
|
166
166
|
const r = t.get(s);
|
|
@@ -190,7 +190,7 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
190
190
|
return i;
|
|
191
191
|
}, { name: s });
|
|
192
192
|
};
|
|
193
|
-
},
|
|
193
|
+
}, H = (e) => Object.entries(e).filter(([t]) => t !== "name" && !isNaN(Number(t))).map(([t, n]) => n), Re = [
|
|
194
194
|
/**
|
|
195
195
|
* Wraps the content in a markdown-formatted code block.
|
|
196
196
|
* @param lang The language of the code block (defaults to the file extension).
|
|
@@ -220,10 +220,10 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
220
220
|
* @example [](<url>?wrap=dropdown(hello_world,,_))
|
|
221
221
|
*/
|
|
222
222
|
"dropdown(summary: string, open?: boolean, space?: string)"
|
|
223
|
-
],
|
|
223
|
+
], Ae = ee(Re), f = (e, t = 1) => `
|
|
224
224
|
`.repeat(t) + e + `
|
|
225
|
-
`.repeat(t),
|
|
226
|
-
const s =
|
|
225
|
+
`.repeat(t), M = (e, t, n) => `<${t}${n ? ` ${n}` : ""}>${f(e)}</${t}>`, Q = (e, t, n) => {
|
|
226
|
+
const s = Ae(t);
|
|
227
227
|
switch (s.name) {
|
|
228
228
|
case "code":
|
|
229
229
|
if (!s.lang && !s.meta && (n == null ? void 0 : n.inline) && !e.includes(`
|
|
@@ -233,21 +233,21 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
233
233
|
case "quote":
|
|
234
234
|
return n != null && n.inline && !e.includes(`
|
|
235
235
|
|
|
236
|
-
`) ? `> ${e}` : f(
|
|
236
|
+
`) ? `> ${e}` : f(M(f(e), "blockquote"));
|
|
237
237
|
case "dropdown":
|
|
238
|
-
const c =
|
|
239
|
-
return f(
|
|
238
|
+
const c = M(Y(s.summary), "summary");
|
|
239
|
+
return f(M([c, e].join(`
|
|
240
240
|
`), "details", s.open ? "open" : void 0));
|
|
241
241
|
}
|
|
242
|
-
},
|
|
242
|
+
}, A = (e) => {
|
|
243
243
|
const t = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm, n = [];
|
|
244
244
|
let s;
|
|
245
245
|
for (; (s = t.exec(e)) !== null; ) {
|
|
246
|
-
const o = [s.index, s.index + s[0].length], r =
|
|
246
|
+
const o = [s.index, s.index + s[0].length], r = Pe(s[0]).trim();
|
|
247
247
|
n.push({ range: o, value: r });
|
|
248
248
|
}
|
|
249
249
|
return n;
|
|
250
|
-
},
|
|
250
|
+
}, Pe = (e) => e.startsWith("//") ? e.slice(2) : e.startsWith("/*") ? e.slice(2, -2) : e.startsWith("<!--") ? e.slice(4, -3) : e, We = [
|
|
251
251
|
/**
|
|
252
252
|
* Extract regions from the retrieved content between comments that INCLUDE the specified ids.
|
|
253
253
|
* @param id The id of the comment to extract.
|
|
@@ -278,9 +278,9 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
278
278
|
* @example [](<url>?region=replace(specifier,new_content,_)
|
|
279
279
|
*/
|
|
280
280
|
"replace(id: string, with?: string, space?: string)"
|
|
281
|
-
],
|
|
281
|
+
], Le = ee(We), x = (e, t) => A(e).filter(({ value: n }) => n.includes(t)).sort((n, s) => n.range[0] - s.range[0]), qe = (e, ...t) => {
|
|
282
282
|
if (t.length === 0) return e;
|
|
283
|
-
const n = ([i, c]) => e.slice(i, c), s =
|
|
283
|
+
const n = ([i, c]) => e.slice(i, c), s = A(e), o = new d(), r = new d();
|
|
284
284
|
for (const i of t) {
|
|
285
285
|
const c = s.filter(({ value: l }) => l.includes(i)).sort((l, a) => l.range[0] - a.range[0]);
|
|
286
286
|
for (let l = 0; l < c.length - 1; l += 2) {
|
|
@@ -290,12 +290,12 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
290
290
|
r.push(a.range[0], a.range[1] + (m.trim() ? 0 : 1)), r.push(p.range[0], p.range[1] + (w.trim() ? 0 : 1));
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
-
return o.collapse(), r.collapse(),
|
|
293
|
+
return o.collapse(), r.collapse(), D(
|
|
294
294
|
o.subtract(r).map(n).filter(Boolean).join("")
|
|
295
295
|
).trim();
|
|
296
|
-
},
|
|
296
|
+
}, Be = (e, ...t) => {
|
|
297
297
|
if (t.length === 0) return e;
|
|
298
|
-
const n = ([i, c]) => e.slice(i, c), s =
|
|
298
|
+
const n = ([i, c]) => e.slice(i, c), s = A(e), o = new d();
|
|
299
299
|
for (const i of t) {
|
|
300
300
|
const c = s.filter(({ value: l }) => l.includes(i)).sort((l, a) => l.range[0] - a.range[0]);
|
|
301
301
|
for (let l = 0; l < c.length - 1; l += 2) {
|
|
@@ -306,48 +306,48 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
306
306
|
}
|
|
307
307
|
o.collapse();
|
|
308
308
|
const r = new d();
|
|
309
|
-
return r.push(0, e.length), r.subtract(o),
|
|
309
|
+
return r.push(0, e.length), r.subtract(o), D(
|
|
310
310
|
r.collapse().map(n).filter(Boolean).join("")
|
|
311
311
|
).trim();
|
|
312
|
-
},
|
|
312
|
+
}, Fe = (e, t, n, s) => {
|
|
313
313
|
if (!t) return e;
|
|
314
314
|
const o = x(e, t);
|
|
315
315
|
if (o.length < 2) return e;
|
|
316
316
|
let r = "", i = 0;
|
|
317
317
|
for (let l = 0; l < o.length - 1; l += 2) {
|
|
318
318
|
const a = o[l], p = o[l + 1];
|
|
319
|
-
r += e.slice(i, a.range[1]), r +=
|
|
319
|
+
r += e.slice(i, a.range[1]), r += Y(n ?? a.value, s), i = p.range[0];
|
|
320
320
|
}
|
|
321
321
|
r += e.slice(i);
|
|
322
322
|
const c = new d();
|
|
323
323
|
return c.push(0, r.length), c.subtract(
|
|
324
324
|
x(r, t).reduce((l, { range: a }) => (l.push(...a), l), new d())
|
|
325
|
-
),
|
|
325
|
+
), D(
|
|
326
326
|
c.collapse().map(([l, a]) => r.slice(l, a)).filter(Boolean).join("")
|
|
327
327
|
).trim();
|
|
328
|
-
},
|
|
329
|
-
` || e === void 0 }),
|
|
328
|
+
}, z = (e) => ({ isSpace: e === " ", isNewline: e === `
|
|
329
|
+
` || e === void 0 }), X = (e) => [
|
|
330
330
|
...x(e, "p↓:"),
|
|
331
331
|
...x(e, "parkdown:")
|
|
332
332
|
].sort((t, n) => t.range[0] - n.range[0]).reverse().reduce((t, { range: [n, s], value: o }) => {
|
|
333
|
-
const r = (a, p) => t.slice(0, a) + t.slice(p), i =
|
|
333
|
+
const r = (a, p) => t.slice(0, a) + t.slice(p), i = z(t[n - 1]), c = z(t[s]), l = s === t.length;
|
|
334
334
|
return i.isNewline && c.isNewline ? r(n - (l ? 1 : 0), s + 1) : i.isNewline ? r(n, s + (c.isSpace ? 1 : 0)) : r(n - (i.isSpace ? 1 : 0), s);
|
|
335
|
-
}, e),
|
|
336
|
-
if (!t) return
|
|
337
|
-
const
|
|
338
|
-
switch (
|
|
335
|
+
}, e), Ue = (e, t, n) => {
|
|
336
|
+
if (!t) return X(e);
|
|
337
|
+
const s = Le(t);
|
|
338
|
+
switch (s.name) {
|
|
339
339
|
case "extract":
|
|
340
|
-
e =
|
|
340
|
+
e = qe(e, s.id, ...H(s));
|
|
341
341
|
break;
|
|
342
342
|
case "remove":
|
|
343
|
-
e =
|
|
343
|
+
e = Be(e, s.id, ...H(s));
|
|
344
344
|
break;
|
|
345
345
|
case "replace":
|
|
346
|
-
e =
|
|
346
|
+
e = Fe(e, s.id, s.with, s.space);
|
|
347
347
|
break;
|
|
348
348
|
}
|
|
349
|
-
return
|
|
350
|
-
},
|
|
349
|
+
return n ? X(e) : e;
|
|
350
|
+
}, Ge = ["http", "./", "../"], He = ({ url: e }) => Ge.some((t) => e.startsWith(t)), Qe = (e) => I(e) && ye(e) && He(e), te = ({ url: e }, t) => `[](${t ? S(t, e) : e})`, u = {
|
|
351
351
|
_open: "<!--",
|
|
352
352
|
_close: "-->",
|
|
353
353
|
_flag: "p↓",
|
|
@@ -362,13 +362,13 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
362
362
|
`).length}`, n = `chars: ${e.length}`;
|
|
363
363
|
return E(u._open, u._flag, "length", t, n, u._close);
|
|
364
364
|
}
|
|
365
|
-
},
|
|
366
|
-
|
|
365
|
+
}, V = (e) => (t) => I(t) && t.value === u[e], ze = ({ position: e, url: t, siblingCount: n }, s) => ({ position: e, url: t, headingDepth: s, inline: n >= 1 }), Xe = ({ position: { start: e }, url: t, siblingCount: n }, { position: { end: s } }, o) => ({ position: { start: e, end: s }, url: t, headingDepth: o, inline: n >= 1 }), Ve = (e, t, n) => (e.inline ? E : Se)(
|
|
366
|
+
te(e, n),
|
|
367
367
|
u.begin,
|
|
368
368
|
u.lengthOf(t),
|
|
369
369
|
t,
|
|
370
370
|
u.end
|
|
371
|
-
),
|
|
371
|
+
), Je = (e) => {
|
|
372
372
|
const t = N(e, "heading").reduce((n, { position: s, depth: o }) => n.set(s.start.line, o), /* @__PURE__ */ new Map());
|
|
373
373
|
return (n) => {
|
|
374
374
|
for (let s = n.position.start.line; s >= 1; s--) {
|
|
@@ -381,7 +381,7 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
381
381
|
openingCommentDoesNotFollowLink: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),
|
|
382
382
|
closingCommentNotMatchedToOpening: ({ position: { start: e } }) => new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),
|
|
383
383
|
openingCommentNotClosed: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)
|
|
384
|
-
},
|
|
384
|
+
}, Ze = (e, t) => {
|
|
385
385
|
const n = [], s = [
|
|
386
386
|
...e.map((r) => ({ node: r, type: "open" })),
|
|
387
387
|
...t.map((r) => ({ node: r, type: "close" }))
|
|
@@ -399,13 +399,13 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
399
399
|
if (o.length > 0)
|
|
400
400
|
throw k.openingCommentNotClosed(o[0].node);
|
|
401
401
|
return n;
|
|
402
|
-
},
|
|
402
|
+
}, Ke = (e, t, n) => {
|
|
403
403
|
const s = [...t].sort(g), o = [];
|
|
404
404
|
return [...n].sort((r, i) => g.reverse(r.open, i.open)).forEach((r) => {
|
|
405
405
|
for (; s.length > 0; ) {
|
|
406
406
|
const i = s.pop();
|
|
407
407
|
if (i.position.start.offset < r.open.position.start.offset) {
|
|
408
|
-
if (
|
|
408
|
+
if (Ee(e, i, r.open).trim() !== "")
|
|
409
409
|
throw k.openingCommentDoesNotFollowLink(r.open);
|
|
410
410
|
return o.push([i, r]);
|
|
411
411
|
}
|
|
@@ -413,74 +413,77 @@ const q = /,\s*(?![^()]*\))/, B = {
|
|
|
413
413
|
}
|
|
414
414
|
throw k.openingCommentDoesNotFollowLink(r.open);
|
|
415
415
|
}), o.push(...s.reverse()), o.reverse();
|
|
416
|
-
},
|
|
417
|
-
t ?? (t =
|
|
418
|
-
const n =
|
|
419
|
-
return
|
|
420
|
-
},
|
|
416
|
+
}, ne = (e, t) => {
|
|
417
|
+
t ?? (t = R.md(e));
|
|
418
|
+
const n = Je(t), s = N(t, "link").filter(Qe), o = N(t, "html").sort(g), r = o.filter(V("begin")), i = o.filter(V("end")), c = Ze(r, i);
|
|
419
|
+
return Ke(e, s, c).map((a) => Array.isArray(a) ? Xe(a[0], a[1].close, n(a[0])) : ze(a, n(a)));
|
|
420
|
+
}, Ye = (e, { url: t }) => (n) => e(S(j(t), n)), se = (...e) => {
|
|
421
421
|
const t = e.reduce((n, s) => n + s, 0);
|
|
422
422
|
return Math.min(Math.max(t, 1), 6);
|
|
423
|
-
},
|
|
423
|
+
}, et = (e, t, n) => {
|
|
424
424
|
if (t === 0) return e;
|
|
425
|
-
n ?? (n =
|
|
425
|
+
n ?? (n = R.md(e));
|
|
426
426
|
const s = N(n, "heading"), o = e.split(`
|
|
427
427
|
`);
|
|
428
428
|
for (const r of s) {
|
|
429
|
-
const { depth: i, position: { start: c, end: l } } = r, a =
|
|
429
|
+
const { depth: i, position: { start: c, end: l } } = r, a = se(i, t), p = o[c.line - 1].slice(i, l.column), m = "#".repeat(a) + p;
|
|
430
430
|
o[c.line - 1] = m, r.depth = a;
|
|
431
431
|
}
|
|
432
432
|
return o.join(`
|
|
433
433
|
`);
|
|
434
|
-
},
|
|
434
|
+
}, oe = (e) => ne(e).reverse().sort(g.reverse).reduce((t, n) => K(t, te(n), n), e), re = (e, t, n, s, o) => {
|
|
435
435
|
try {
|
|
436
|
-
e =
|
|
437
|
-
const r =
|
|
438
|
-
return
|
|
439
|
-
var
|
|
440
|
-
const { url: c, headingDepth: l } = i, [a, ...p] =
|
|
436
|
+
e = oe(e), e = et(e, t);
|
|
437
|
+
const r = R.md(e);
|
|
438
|
+
return ne(e, r).sort(g).reverse().map((i) => {
|
|
439
|
+
var W, L;
|
|
440
|
+
const { url: c, headingDepth: l } = i, [a, ...p] = fe(c).split("?"), m = a.split(".").pop() ?? "", y = p.join("?"), w = j(c), P = S(w, a);
|
|
441
441
|
if (c.startsWith("./") || c.startsWith("../")) {
|
|
442
|
-
let h = n(
|
|
443
|
-
const v = new
|
|
444
|
-
h = (b == null ? void 0 : b.reduce(
|
|
445
|
-
|
|
442
|
+
let h = n(P);
|
|
443
|
+
const v = new de(y), b = (W = v.get("region")) == null ? void 0 : W.split(B);
|
|
444
|
+
h = (b == null ? void 0 : b.reduce(
|
|
445
|
+
($, C, O, { length: me }) => Ue($, C, O === me - 1),
|
|
446
|
+
h
|
|
447
|
+
)) ?? h;
|
|
448
|
+
const le = v.has("skip"), ae = v.get("heading") ?? 0, pe = v.has("inline");
|
|
446
449
|
let { inline: _ } = i;
|
|
447
|
-
if (
|
|
450
|
+
if (pe && (_ = !0), !le)
|
|
448
451
|
if (m === "md") {
|
|
449
|
-
const $ =
|
|
450
|
-
h =
|
|
452
|
+
const $ = Ye(n, i), C = o ? S(o, w) : w, O = se(l, Number(ae));
|
|
453
|
+
h = re(
|
|
451
454
|
h,
|
|
452
455
|
/** p↓: ... */
|
|
453
|
-
|
|
456
|
+
O,
|
|
454
457
|
$,
|
|
455
|
-
|
|
458
|
+
P,
|
|
456
459
|
C
|
|
457
460
|
/** p↓: ... */
|
|
458
461
|
);
|
|
459
|
-
} else /^(js|ts)x?|svelte$/i.test(m) && (h =
|
|
462
|
+
} else /^(js|ts)x?|svelte$/i.test(m) && (h = Q(
|
|
460
463
|
h,
|
|
461
464
|
"code",
|
|
462
465
|
/** p↓: ... */
|
|
463
466
|
{ extension: m, inline: _ }
|
|
464
467
|
/** p↓: ... */
|
|
465
468
|
));
|
|
466
|
-
const T = (
|
|
467
|
-
return h = (T == null ? void 0 : T.reduce(($, C) =>
|
|
469
|
+
const T = (L = v.get("wrap")) == null ? void 0 : L.split(B);
|
|
470
|
+
return h = (T == null ? void 0 : T.reduce(($, C) => Q($, C, { extension: m, inline: _ }), h)) ?? h, { target: i, content: Ve(i, h, o) };
|
|
468
471
|
} else throw c.startsWith("http") ? new Error("External web links are not implemented yet") : new Error(`Unsupported link type: ${c}`);
|
|
469
|
-
}).reduce((i, { target: c, content: l }) =>
|
|
472
|
+
}).reduce((i, { target: c, content: l }) => K(i, l, c), e);
|
|
470
473
|
} catch (r) {
|
|
471
474
|
throw new Error(`Error populating inclusions in file ${s ?? "(unknown)"}: ${r}`);
|
|
472
475
|
}
|
|
473
|
-
},
|
|
474
|
-
const t =
|
|
475
|
-
return { markdown:
|
|
476
|
-
}, lt = (e, t = !0) => {
|
|
477
|
-
const { dir: n, path: s, markdown: o } = ie(e), i = oe(o, 0, (c) => re(J(n, Ne(c))), s);
|
|
478
|
-
return t && V(s, i), i;
|
|
476
|
+
}, ie = (e) => ge(e, "utf-8"), ce = (e) => {
|
|
477
|
+
const t = Z(e), n = j(t);
|
|
478
|
+
return { markdown: ie(t), dir: n, path: t };
|
|
479
479
|
}, at = (e, t = !0) => {
|
|
480
|
-
const {
|
|
481
|
-
return t &&
|
|
480
|
+
const { dir: n, path: s, markdown: o } = ce(e), i = re(o, 0, (c) => ie(Z(n, xe(c))), s);
|
|
481
|
+
return t && J(s, i), i;
|
|
482
|
+
}, pt = (e, t = !0) => {
|
|
483
|
+
const { path: n, markdown: s } = ce(e), o = oe(s);
|
|
484
|
+
return t && J(n, o), o;
|
|
482
485
|
};
|
|
483
486
|
export {
|
|
484
|
-
|
|
485
|
-
|
|
487
|
+
pt as depopulateMarkdownInclusions,
|
|
488
|
+
at as populateMarkdownInclusions
|
|
486
489
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
(function(u,d){typeof exports=="object"&&typeof module<"u"?d(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"],d):(u=typeof globalThis<"u"?globalThis:u||self,d(u.index={},u.node_fs,u.node_path,u.node_url,u.unified,u.remarkParse,u.unistUtilVisit,u.tsDedent))})(this,function(u,d,h,
|
|
2
|
-
`),
|
|
1
|
+
(function(u,d){typeof exports=="object"&&typeof module<"u"?d(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"],d):(u=typeof globalThis<"u"?globalThis:u||self,d(u.index={},u.node_fs,u.node_path,u.node_url,u.unified,u.remarkParse,u.unistUtilVisit,u.tsDedent))})(this,function(u,d,h,ce,le,ae,pe,j){"use strict";var Je=Object.defineProperty;var Ze=(u,d,h)=>d in u?Je(u,d,{enumerable:!0,configurable:!0,writable:!0,value:h}):u[d]=h;var ie=(u,d,h)=>Ze(u,typeof d!="symbol"?d+"":d,h);const v=(e,n)=>e.position.start.offset-n.position.start.offset;v.reverse=(e,n)=>v(n,e);const M=e=>e.position!==void 0&&e.position.start.offset!==void 0&&e.position.end.offset!==void 0,ue=le.unified().use(ae),O={md:e=>ue.parse(e)},k=(e,n)=>{const t=[];return pe.visit(e,(s,o,r)=>{if(s.type!=="root"){if(n&&s.type!==n)return;if(M(s)){const i=((r==null?void 0:r.children.length)??0)-1;t.push({...s,siblingIndex:o,siblingCount:i})}}}),t},me=e=>e.children.length===0,W=(e,n,...t)=>{if(t.length===0)throw new Error("No nodes to replace content from");t.sort(v);const s=t.at(0),o=t.at(-1);return e.slice(0,s.position.start.offset)+n+e.slice(o.position.end.offset)},de=(e,n,t)=>{const s=Math.min(n.position.end.offset,t.position.end.offset),o=Math.max(n.position.start.offset,t.position.start.offset);return e.slice(s,o)},N=(...e)=>e.join(" "),he=(...e)=>e.join(`
|
|
2
|
+
`),fe=e=>{const n=e.split("?");return n.length>1?[n.slice(0,-1).join("?"),n.at(-1)]:[e,""]},ge=e=>fe(e)[0];class w{constructor(){ie(this,"intervals",[])}push(n,t){this.intervals.push([Math.min(n,t),Math.max(n,t)])}combine(n){this.intervals.push(...n.intervals)}collapse(){const{intervals:n}=this;if(!n.length)return this.intervals=[];n.sort((r,i)=>r[0]-i[0]);const t=[];let[s,o]=n[0];for(let r=1;r<n.length;r++){const[i,c]=n[r];i<=o?o=Math.max(o,c):(t.push([s,o]),s=i,o=c)}return t.push([s,o]),this.intervals=t}subtract(n){const{intervals:t}=this,{intervals:s}=n;if(!t.length||!s.length)return t;let o=[...t];for(const[r,i]of s){const c=[];for(const[l,a]of o){if(i<=l||r>=a){c.push([l,a]);continue}r>l&&c.push([l,r]),i<a&&c.push([i,a])}o=c}return this.intervals=o}}const _=/,\s*(?![^()]*\))/,L={reserved:{semi:";",slash:"/",question:"?",colon:":",at:"@",equal:"=",and:"&"},unsafe:{quote:'"',angle:"<",unangle:">",hash:"#",percent:"%",curly:"{",uncurly:"}",pipe:"|",back:"\\",carrot:"^",tilde:"~",square:"[",unsquare:"]",tick:"`"}},ve="-",B={static:[["'''",'"'],["''","'"],[/parkdown:\s+/g,""],[/p↓:\s+/g,""]],url:[...Object.entries(L.unsafe),...Object.entries(L.reserved)]},F=(e,[n,t])=>e.replaceAll(n,t),U=(e,n=ve)=>{const t=B.static.reduce(F,e);return B.url.map(([s,o])=>[n+s+n,o]).reduce(F,t).replaceAll(n," ")},we=["string","number","boolean"],$e=e=>we.includes(e),Ce=/^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/,ye=e=>{const n=e.match(Ce);if(!n)throw new Error(`Invalid invocation: ${e}`);const[,t,s=""]=n;if(!s.trim())return{name:t,parameters:[]};const o=Ee(s);return{name:t,parameters:o}},Se=(e,n)=>{for(let t=n+1;t<e.length;t++)if(e[t]!==void 0)return!1;return!0},Ee=e=>{const n=[];let t="",s=!1;for(let o=0;o<e.length;o++){const r=e[o],i=r==="'";if(i&&e.at(o+1)==="'"){const c=e.at(o+2)==="'";s=!s,t+=c?"'''":"''",o+=c?2:1}else i?(s=!s,t+=r):r===","&&!s?(n.push(t.trim()),t=""):t+=r}return n.push(t.trim()),n.map(o=>o===""?void 0:o?ke(o):void 0).filter((o,r,i)=>o!==void 0||!Se(i,r))},ke=e=>{const n=e.length>=2&&e[0]==="'"&&e.at(-1)==="'",t=n&&e.length>=4&&e[1]==="'"&&e.at(-2)==="'";return!n||t?e:e.slice(1,-1)},Ne=e=>{const n=/^(\w+)(?:\(([^)]*)\))?/,t=e.match(n);if(!t)return{name:e};const[,s,o]=t;if(!o)return{name:s};const r=/(\w+)(\?)?:\s*([^,]+)/g,i=[];let c;for(;(c=r.exec(o))!==null;){const[,l,a,p]=c,m=p.trim();if(!$e(m))throw new Error(`Unsupported type: ${m}`);i.push({name:l,optional:a==="?",type:m})}return{name:s,parameters:i}},G=e=>{const n=e.map(Ne).reduce((t,{name:s,parameters:o})=>t.set(s,o),new Map);return t=>{const{name:s,parameters:o}=ye(t);if(!n.has(s))throw new Error(`Unknown method: ${s}`);const r=n.get(s);if(r===void 0)return{name:s};if(o.length>r.length){const i=r.filter(({optional:l})=>!l).length,c=i===r.length?i.toString():`${i} - ${r.length}`;throw new Error(`Too many parameters: ${o.length} for method '${s}' (expected: ${c})`)}return r.reduce((i,{name:c,optional:l,type:a},p)=>{const m=o[p];if(m===void 0){if(l)return i;throw new Error(`Missing required parameter: ${c} for method '${s}'`)}switch(a){case"string":i[c]=m;break;case"number":case"boolean":i[c]=JSON.parse(m);break}if(typeof i[c]!==a)throw new Error(`Invalid type: ${c} must be ${a}, got ${typeof i[c]} for method '${s}'`);return i},{name:s})}},H=e=>Object.entries(e).filter(([n])=>n!=="name"&&!isNaN(Number(n))).map(([n,t])=>t),xe=G(["code(lang?: string, meta?: string)","quote()","dropdown(summary: string, open?: boolean, space?: string)"]),$=(e,n=1)=>`
|
|
3
3
|
`.repeat(n)+e+`
|
|
4
|
-
`.repeat(n),q=(e,n,t)=>`<${n}${t?` ${t}`:""}>${$(e)}</${n}>`,
|
|
4
|
+
`.repeat(n),q=(e,n,t)=>`<${n}${t?` ${t}`:""}>${$(e)}</${n}>`,Q=(e,n,t)=>{const s=xe(n);switch(s.name){case"code":if(!s.lang&&!s.meta&&(t==null?void 0:t.inline)&&!e.includes(`
|
|
5
5
|
`))return`\`${e}\``;const r=s.lang??(t==null?void 0:t.extension)??"",i=s.meta?` ${s.meta}`:"";return $(`\`\`\`${r}${i}${$(e)}\`\`\``);case"quote":return t!=null&&t.inline&&!e.includes(`
|
|
6
6
|
|
|
7
|
-
`)?`> ${e}`:$(q($(e),"blockquote"));case"dropdown":const c=q(
|
|
8
|
-
`),"details",s.open?"open":void 0))}},I=e=>{const n=/(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm,t=[];let s;for(;(s=n.exec(e))!==null;){const o=[s.index,s.index+s[0].length],r=
|
|
9
|
-
`?p.range[1]+1:p.range[1])}}o.collapse();const r=new w;return r.push(0,e.length),r.subtract(o),j.dedent(r.collapse().map(t).filter(Boolean).join("")).trim()},
|
|
10
|
-
`||e===void 0}),
|
|
11
|
-
`).length}`,t=`chars: ${e.length}`;return N(f._open,f._flag,"length",n,t,f._close)}},
|
|
12
|
-
`);for(const r of s){const{depth:i,position:{start:c,end:l}}=r,a=
|
|
13
|
-
`)},
|
|
7
|
+
`)?`> ${e}`:$(q($(e),"blockquote"));case"dropdown":const c=q(U(s.summary),"summary");return $(q([c,e].join(`
|
|
8
|
+
`),"details",s.open?"open":void 0))}},I=e=>{const n=/(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm,t=[];let s;for(;(s=n.exec(e))!==null;){const o=[s.index,s.index+s[0].length],r=Te(s[0]).trim();t.push({range:o,value:r})}return t},Te=e=>e.startsWith("//")?e.slice(2):e.startsWith("/*")?e.slice(2,-2):e.startsWith("<!--")?e.slice(4,-3):e,be=G(["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)"]),x=(e,n)=>I(e).filter(({value:t})=>t.includes(n)).sort((t,s)=>t.range[0]-s.range[0]),je=(e,...n)=>{if(n.length===0)return e;const t=([i,c])=>e.slice(i,c),s=I(e),o=new w,r=new w;for(const i of n){const c=s.filter(({value:l})=>l.includes(i)).sort((l,a)=>l.range[0]-a.range[0]);for(let l=0;l<c.length-1;l+=2){const a=c[l],p=c[l+1];o.push(a.range[1],p.range[0]);const[m,...b]=t([a.range[1],p.range[0]]),C=b[b.length-1];r.push(a.range[0],a.range[1]+(m.trim()?0:1)),r.push(p.range[0],p.range[1]+(C.trim()?0:1))}}return o.collapse(),r.collapse(),j.dedent(o.subtract(r).map(t).filter(Boolean).join("")).trim()},Me=(e,...n)=>{if(n.length===0)return e;const t=([i,c])=>e.slice(i,c),s=I(e),o=new w;for(const i of n){const c=s.filter(({value:l})=>l.includes(i)).sort((l,a)=>l.range[0]-a.range[0]);for(let l=0;l<c.length-1;l+=2){const a=c[l],p=c[l+1],m=t([p.range[1],p.range[1]+1]).at(-1);o.push(a.range[0],m===`
|
|
9
|
+
`?p.range[1]+1:p.range[1])}}o.collapse();const r=new w;return r.push(0,e.length),r.subtract(o),j.dedent(r.collapse().map(t).filter(Boolean).join("")).trim()},Oe=(e,n,t,s)=>{if(!n)return e;const o=x(e,n);if(o.length<2)return e;let r="",i=0;for(let l=0;l<o.length-1;l+=2){const a=o[l],p=o[l+1];r+=e.slice(i,a.range[1]),r+=U(t??a.value,s),i=p.range[0]}r+=e.slice(i);const c=new w;return c.push(0,r.length),c.subtract(x(r,n).reduce((l,{range:a})=>(l.push(...a),l),new w)),j.dedent(c.collapse().map(([l,a])=>r.slice(l,a)).filter(Boolean).join("")).trim()},z=e=>({isSpace:e===" ",isNewline:e===`
|
|
10
|
+
`||e===void 0}),V=e=>[...x(e,"p↓:"),...x(e,"parkdown:")].sort((n,t)=>n.range[0]-t.range[0]).reverse().reduce((n,{range:[t,s],value:o})=>{const r=(a,p)=>n.slice(0,a)+n.slice(p),i=z(n[t-1]),c=z(n[s]),l=s===n.length;return i.isNewline&&c.isNewline?r(t-(l?1:0),s+1):i.isNewline?r(t,s+(c.isSpace?1:0)):r(t-(i.isSpace?1:0),s)},e),qe=(e,n,t)=>{if(!n)return V(e);const s=be(n);switch(s.name){case"extract":e=je(e,s.id,...H(s));break;case"remove":e=Me(e,s.id,...H(s));break;case"replace":e=Oe(e,s.id,s.with,s.space);break}return t?V(e):e},Ie=["http","./","../"],Pe=({url:e})=>Ie.some(n=>e.startsWith(n)),Re=e=>M(e)&&me(e)&&Pe(e),X=({url:e},n)=>`[](${n?h.join(n,e):e})`,f={_open:"<!--",_close:"-->",_flag:"p↓",get begin(){return N(f._open,f._flag,"BEGIN",f._close)},get end(){return N(f._open,f._flag,"END",f._close)},lengthOf(e){const n=`lines: ${e.split(`
|
|
11
|
+
`).length}`,t=`chars: ${e.length}`;return N(f._open,f._flag,"length",n,t,f._close)}},J=e=>n=>M(n)&&n.value===f[e],Ae=({position:e,url:n,siblingCount:t},s)=>({position:e,url:n,headingDepth:s,inline:t>=1}),De=({position:{start:e},url:n,siblingCount:t},{position:{end:s}},o)=>({position:{start:e,end:s},url:n,headingDepth:o,inline:t>=1}),We=(e,n,t)=>(e.inline?N:he)(X(e,t),f.begin,f.lengthOf(n),n,f.end),_e=e=>{const n=k(e,"heading").reduce((t,{position:s,depth:o})=>t.set(s.start.line,o),new Map);return t=>{for(let s=t.position.start.line;s>=1;s--){const o=n.get(s);if(o)return o}return 0}},T={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`)},Le=(e,n)=>{const t=[],s=[...e.map(r=>({node:r,type:"open"})),...n.map(r=>({node:r,type:"close"}))].sort((r,i)=>v(r.node,i.node)),o=[];for(const r of s)if(r.type==="open")o.push(r);else{const i=r.node;if(o.length===0)throw T.closingCommentNotMatchedToOpening(i);const c=o.pop().node;if(o.length>0)continue;t.push({open:c,close:i})}if(o.length>0)throw T.openingCommentNotClosed(o[0].node);return t},Be=(e,n,t)=>{const s=[...n].sort(v),o=[];return[...t].sort((r,i)=>v.reverse(r.open,i.open)).forEach(r=>{for(;s.length>0;){const i=s.pop();if(i.position.start.offset<r.open.position.start.offset){if(de(e,i,r.open).trim()!=="")throw T.openingCommentDoesNotFollowLink(r.open);return o.push([i,r])}o.push(i)}throw T.openingCommentDoesNotFollowLink(r.open)}),o.push(...s.reverse()),o.reverse()},Z=(e,n)=>{n??(n=O.md(e));const t=_e(n),s=k(n,"link").filter(Re),o=k(n,"html").sort(v),r=o.filter(J("begin")),i=o.filter(J("end")),c=Le(r,i);return Be(e,s,c).map(a=>Array.isArray(a)?De(a[0],a[1].close,t(a[0])):Ae(a,t(a)))},Fe=(e,{url:n})=>t=>e(h.join(h.dirname(n),t)),K=(...e)=>{const n=e.reduce((t,s)=>t+s,0);return Math.min(Math.max(n,1),6)},Ue=(e,n,t)=>{if(n===0)return e;t??(t=O.md(e));const s=k(t,"heading"),o=e.split(`
|
|
12
|
+
`);for(const r of s){const{depth:i,position:{start:c,end:l}}=r,a=K(i,n),p=o[c.line-1].slice(i,l.column),m="#".repeat(a)+p;o[c.line-1]=m,r.depth=a}return o.join(`
|
|
13
|
+
`)},Y=e=>Z(e).reverse().sort(v.reverse).reduce((n,t)=>W(n,X(t),t),e),ee=(e,n,t,s,o)=>{try{e=Y(e),e=Ue(e,n);const r=O.md(e);return Z(e,r).sort(v).reverse().map(i=>{var oe,re;const{url:c,headingDepth:l}=i,[a,...p]=h.basename(c).split("?"),m=a.split(".").pop()??"",b=p.join("?"),C=h.dirname(c),se=h.join(C,a);if(c.startsWith("./")||c.startsWith("../")){let g=t(se);const y=new ce.URLSearchParams(b),P=(oe=y.get("region"))==null?void 0:oe.split(_);g=(P==null?void 0:P.reduce((S,E,D,{length:Xe})=>qe(S,E,D===Xe-1),g))??g;const Qe=y.has("skip"),ze=y.get("heading")??0,Ve=y.has("inline");let{inline:R}=i;if(Ve&&(R=!0),!Qe)if(m==="md"){const S=Fe(t,i),E=o?h.join(o,C):C,D=K(l,Number(ze));g=ee(g,D,S,se,E)}else/^(js|ts)x?|svelte$/i.test(m)&&(g=Q(g,"code",{extension:m,inline:R}));const A=(re=y.get("wrap"))==null?void 0:re.split(_);return g=(A==null?void 0:A.reduce((S,E)=>Q(S,E,{extension:m,inline:R}),g))??g,{target:i,content:We(i,g,o)}}else throw c.startsWith("http")?new Error("External web links are not implemented yet"):new Error(`Unsupported link type: ${c}`)}).reduce((i,{target:c,content:l})=>W(i,l,c),e)}catch(r){throw new Error(`Error populating inclusions in file ${s??"(unknown)"}: ${r}`)}},ne=e=>d.readFileSync(e,"utf-8"),te=e=>{const n=h.resolve(e),t=h.dirname(n);return{markdown:ne(n),dir:t,path:n}},Ge=(e,n=!0)=>{const{dir:t,path:s,markdown:o}=te(e),i=ee(o,0,c=>ne(h.resolve(t,ge(c))),s);return n&&d.writeFileSync(s,i),i},He=(e,n=!0)=>{const{path:t,markdown:s}=te(e),o=Y(s);return n&&d.writeFileSync(t,o),o};u.depopulateMarkdownInclusions=He,u.populateMarkdownInclusions=Ge,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|