@p-buddy/parkdown 0.0.8 → 0.0.10
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 +206 -170
- package/dist/index.umd.cjs +11 -11
- 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.10", 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,46 @@
|
|
|
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
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
md: (e) =>
|
|
15
|
-
},
|
|
1
|
+
var we = Object.defineProperty;
|
|
2
|
+
var ve = (e, t, n) => t in e ? we(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var U = (e, t, n) => ve(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { writeFileSync as ee, readFileSync as $e } from "node:fs";
|
|
5
|
+
import { basename as Ce, dirname as O, join as S, resolve as te } from "node:path";
|
|
6
|
+
import { URLSearchParams as ye } from "node:url";
|
|
7
|
+
import { unified as Ee } from "unified";
|
|
8
|
+
import xe from "remark-parse";
|
|
9
|
+
import { visit as Se } from "unist-util-visit";
|
|
10
|
+
import { dedent as A } from "ts-dedent";
|
|
11
|
+
const f = (e, t) => e.position.start.offset - t.position.start.offset;
|
|
12
|
+
f.reverse = (e, t) => f(t, e);
|
|
13
|
+
const j = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, be = Ee().use(xe), D = {
|
|
14
|
+
md: (e) => be.parse(e)
|
|
15
|
+
}, b = (e, t) => {
|
|
16
16
|
const n = [];
|
|
17
|
-
return
|
|
17
|
+
return Se(e, (s, o, r) => {
|
|
18
18
|
if (s.type !== "root") {
|
|
19
19
|
if (t && s.type !== t) return;
|
|
20
|
-
if (
|
|
20
|
+
if (j(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
|
+
}, Ne = (e) => e.children.length === 0, ne = (e, t, ...n) => {
|
|
27
27
|
if (n.length === 0) throw new Error("No nodes to replace content from");
|
|
28
|
-
n.sort(
|
|
28
|
+
n.sort(f);
|
|
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
|
+
}, ke = (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
|
-
},
|
|
35
|
-
`),
|
|
34
|
+
}, x = (...e) => e.join(" "), Me = (...e) => e.join(`
|
|
35
|
+
`), _e = (e) => {
|
|
36
36
|
const t = e.split("?");
|
|
37
37
|
return t.length > 1 ? [t.slice(0, -1).join("?"), t.at(-1)] : [e, ""];
|
|
38
|
-
},
|
|
39
|
-
class
|
|
40
|
-
constructor() {
|
|
41
|
-
|
|
38
|
+
}, Re = (e) => _e(e)[0];
|
|
39
|
+
class v {
|
|
40
|
+
constructor(...t) {
|
|
41
|
+
U(this, "intervals", []);
|
|
42
|
+
for (const [n, s] of t)
|
|
43
|
+
this.push(n, s);
|
|
42
44
|
}
|
|
43
45
|
push(t, n) {
|
|
44
46
|
this.intervals.push([Math.min(t, n), Math.max(t, n)]);
|
|
@@ -76,7 +78,7 @@ class d {
|
|
|
76
78
|
return this.intervals = o;
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
const
|
|
81
|
+
const T = /,\s*(?![^()]*\))/, Q = {
|
|
80
82
|
reserved: {
|
|
81
83
|
semi: ";",
|
|
82
84
|
slash: "/",
|
|
@@ -102,7 +104,7 @@ const B = /,\s*(?![^()]*\))/, F = {
|
|
|
102
104
|
unsquare: "]",
|
|
103
105
|
tick: "`"
|
|
104
106
|
}
|
|
105
|
-
},
|
|
107
|
+
}, Pe = "-", G = {
|
|
106
108
|
static: [
|
|
107
109
|
["'''", '"'],
|
|
108
110
|
["''", "'"],
|
|
@@ -110,24 +112,24 @@ const B = /,\s*(?![^()]*\))/, F = {
|
|
|
110
112
|
[/p↓:\s+/g, ""]
|
|
111
113
|
],
|
|
112
114
|
url: [
|
|
113
|
-
...Object.entries(
|
|
114
|
-
...Object.entries(
|
|
115
|
+
...Object.entries(Q.unsafe),
|
|
116
|
+
...Object.entries(Q.reserved)
|
|
115
117
|
]
|
|
116
|
-
},
|
|
117
|
-
const n =
|
|
118
|
-
return
|
|
119
|
-
},
|
|
120
|
-
const t = e.match(
|
|
118
|
+
}, H = (e, [t, n]) => e.replaceAll(t, n), se = (e, t = Pe) => {
|
|
119
|
+
const n = G.static.reduce(H, e);
|
|
120
|
+
return G.url.map(([s, o]) => [t + s + t, o]).reduce(H, n).replaceAll(t, " ");
|
|
121
|
+
}, Te = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), Oe = ["string", "number", "boolean"], Ae = (e) => Oe.includes(e), je = /^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/, De = (e) => {
|
|
122
|
+
const t = e.match(je);
|
|
121
123
|
if (!t) throw new Error(`Invalid invocation: ${e}`);
|
|
122
124
|
const [, n, s = ""] = t;
|
|
123
125
|
if (!s.trim()) return { name: n, parameters: [] };
|
|
124
|
-
const o =
|
|
126
|
+
const o = Le(s);
|
|
125
127
|
return { name: n, parameters: o };
|
|
126
|
-
},
|
|
128
|
+
}, Ie = (e, t) => {
|
|
127
129
|
for (let n = t + 1; n < e.length; n++)
|
|
128
130
|
if (e[n] !== void 0) return !1;
|
|
129
131
|
return !0;
|
|
130
|
-
},
|
|
132
|
+
}, Le = (e) => {
|
|
131
133
|
const t = [];
|
|
132
134
|
let n = "", s = !1;
|
|
133
135
|
for (let o = 0; o < e.length; o++) {
|
|
@@ -137,11 +139,11 @@ const B = /,\s*(?![^()]*\))/, F = {
|
|
|
137
139
|
s = !s, n += c ? "'''" : "''", o += c ? 2 : 1;
|
|
138
140
|
} else i ? (s = !s, n += r) : r === "," && !s ? (t.push(n.trim()), n = "") : n += r;
|
|
139
141
|
}
|
|
140
|
-
return t.push(n.trim()), t.map((o) => o === "" ? void 0 : o ?
|
|
141
|
-
},
|
|
142
|
+
return t.push(n.trim()), t.map((o) => o === "" ? void 0 : o ? qe(o) : void 0).filter((o, r, i) => o !== void 0 || !Ie(i, r));
|
|
143
|
+
}, qe = (e) => {
|
|
142
144
|
const t = e.length >= 2 && e[0] === "'" && e.at(-1) === "'", n = t && e.length >= 4 && e[1] === "'" && e.at(-2) === "'";
|
|
143
145
|
return !t || n ? e : e.slice(1, -1);
|
|
144
|
-
},
|
|
146
|
+
}, We = (e) => {
|
|
145
147
|
const t = /^(\w+)(?:\(([^)]*)\))?/, n = e.match(t);
|
|
146
148
|
if (!n) return { name: e };
|
|
147
149
|
const [, s, o] = n;
|
|
@@ -150,17 +152,17 @@ const B = /,\s*(?![^()]*\))/, F = {
|
|
|
150
152
|
let c;
|
|
151
153
|
for (; (c = r.exec(o)) !== null; ) {
|
|
152
154
|
const [, l, a, p] = c, m = p.trim();
|
|
153
|
-
if (!
|
|
155
|
+
if (!Ae(m)) throw new Error(`Unsupported type: ${m}`);
|
|
154
156
|
i.push({ name: l, optional: a === "?", type: m });
|
|
155
157
|
}
|
|
156
158
|
return { name: s, parameters: i };
|
|
157
|
-
},
|
|
158
|
-
const t = e.map(
|
|
159
|
+
}, I = (e) => {
|
|
160
|
+
const t = e.map(We).reduce(
|
|
159
161
|
(n, { name: s, parameters: o }) => n.set(s, o),
|
|
160
162
|
/* @__PURE__ */ new Map()
|
|
161
163
|
);
|
|
162
164
|
return (n) => {
|
|
163
|
-
const { name: s, parameters: o } =
|
|
165
|
+
const { name: s, parameters: o } = De(n);
|
|
164
166
|
if (!t.has(s))
|
|
165
167
|
throw new Error(`Unknown method: ${s}`);
|
|
166
168
|
const r = t.get(s);
|
|
@@ -190,7 +192,7 @@ const B = /,\s*(?![^()]*\))/, F = {
|
|
|
190
192
|
return i;
|
|
191
193
|
}, { name: s });
|
|
192
194
|
};
|
|
193
|
-
},
|
|
195
|
+
}, z = (e) => Object.entries(e).filter(([t]) => t !== "name" && !isNaN(Number(t))).map(([t, n]) => n), Be = [
|
|
194
196
|
/**
|
|
195
197
|
* Wraps the content in a markdown-formatted code block.
|
|
196
198
|
* @param lang The language of the code block (defaults to the file extension).
|
|
@@ -220,34 +222,65 @@ const B = /,\s*(?![^()]*\))/, F = {
|
|
|
220
222
|
* @example [](<url>?wrap=dropdown(hello_world,,_))
|
|
221
223
|
*/
|
|
222
224
|
"dropdown(summary: string, open?: boolean, space?: string)"
|
|
223
|
-
],
|
|
225
|
+
], Fe = I(Be), w = (e, t = 1) => `
|
|
224
226
|
`.repeat(t) + e + `
|
|
225
|
-
`.repeat(t),
|
|
226
|
-
const s =
|
|
227
|
+
`.repeat(t), P = (e, t, n) => `<${t}${n ? ` ${n}` : ""}>${w(e)}</${t}>`, X = (e, t, n) => {
|
|
228
|
+
const s = Fe(t);
|
|
227
229
|
switch (s.name) {
|
|
228
230
|
case "code":
|
|
229
231
|
if (!s.lang && !s.meta && (n == null ? void 0 : n.inline) && !e.includes(`
|
|
230
232
|
`)) return `\`${e}\``;
|
|
231
233
|
const r = s.lang ?? (n == null ? void 0 : n.extension) ?? "", i = s.meta ? ` ${s.meta}` : "";
|
|
232
|
-
return
|
|
234
|
+
return w(`\`\`\`${r}${i}${w(e)}\`\`\``);
|
|
233
235
|
case "quote":
|
|
234
236
|
return n != null && n.inline && !e.includes(`
|
|
235
237
|
|
|
236
|
-
`) ? `> ${e}` :
|
|
238
|
+
`) ? `> ${e}` : w(P(w(e), "blockquote"));
|
|
237
239
|
case "dropdown":
|
|
238
|
-
const c =
|
|
239
|
-
return
|
|
240
|
+
const c = P(se(s.summary), "summary");
|
|
241
|
+
return w(P([c, e].join(`
|
|
240
242
|
`), "details", s.open ? "open" : void 0));
|
|
241
243
|
}
|
|
242
|
-
},
|
|
244
|
+
}, L = (e) => {
|
|
243
245
|
const t = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm, n = [];
|
|
244
246
|
let s;
|
|
245
247
|
for (; (s = t.exec(e)) !== null; ) {
|
|
246
|
-
const o = [s.index, s.index + s[0].length], r =
|
|
248
|
+
const o = [s.index, s.index + s[0].length], r = Ue(s[0]).trim();
|
|
247
249
|
n.push({ range: o, value: r });
|
|
248
250
|
}
|
|
249
251
|
return n;
|
|
250
|
-
},
|
|
252
|
+
}, Ue = (e) => e.startsWith("//") ? e.slice(2) : e.startsWith("/*") ? e.slice(2, -2) : e.startsWith("<!--") ? e.slice(4, -3) : e, oe = [
|
|
253
|
+
"p↓:",
|
|
254
|
+
"pd:",
|
|
255
|
+
"parkdown:"
|
|
256
|
+
], Qe = [
|
|
257
|
+
"splice(delete?: number, insert?: string)"
|
|
258
|
+
], V = I(Qe), d = (e, t, n) => (n ?? L(e)).filter(({ value: s }) => s.includes(t)).sort((s, o) => s.range[0] - o.range[0]), J = (e) => ({
|
|
259
|
+
isSpace: e === " ",
|
|
260
|
+
isNewline: e === `
|
|
261
|
+
` || e === void 0
|
|
262
|
+
}), Z = (e) => oe.flatMap((t) => d(e, t)).sort((t, n) => t.range[0] - n.range[0]).reverse().reduce((t, { range: [n, s], value: o }) => {
|
|
263
|
+
const r = (a, p) => t.slice(0, a) + t.slice(p), i = J(t[n - 1]), c = J(t[s]), l = s === t.length;
|
|
264
|
+
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);
|
|
265
|
+
}, e), re = oe.map((e) => new RegExp(`^${Te(e)}(\\?[^\\s]+)`)), Ge = (e) => re.map((t) => {
|
|
266
|
+
var n;
|
|
267
|
+
return (n = t.exec(e)) == null ? void 0 : n[1];
|
|
268
|
+
}).filter(Boolean).map((t) => new URLSearchParams(t))[0], q = (e, t) => (Array.isArray(t) ? t.flatMap((n) => d(e, n)) : d(e, t)).filter(({ value: n }) => re.some((s) => s.test(n))).sort((n, s) => n.range[0] - s.range[0]).reverse().reduce((n, { range: [s, o], value: r }) => {
|
|
269
|
+
var l, a;
|
|
270
|
+
const i = Ge(r), c = ["back", "front"].map((p) => [p, i.get(p)]).filter(([p, m]) => !!m).reduce(
|
|
271
|
+
(p, [m, u]) => p.set(m, u.split(T)),
|
|
272
|
+
/* @__PURE__ */ new Map()
|
|
273
|
+
);
|
|
274
|
+
return n = ((l = c.get("back")) == null ? void 0 : l.reduce((p, m) => {
|
|
275
|
+
const u = V(m);
|
|
276
|
+
if (u.name === "splice")
|
|
277
|
+
return p.slice(0, o) + (u.insert ?? "") + p.slice(o + (u.delete ?? 0));
|
|
278
|
+
}, n)) ?? n, n = ((a = c.get("front")) == null ? void 0 : a.reduce((p, m) => {
|
|
279
|
+
const u = V(m);
|
|
280
|
+
if (u.name === "splice")
|
|
281
|
+
return p.slice(0, s - (u.delete ?? 0)) + (u.insert ?? "") + p.slice(s);
|
|
282
|
+
}, n)) ?? n, n;
|
|
283
|
+
}, e), He = [
|
|
251
284
|
/**
|
|
252
285
|
* Extract regions from the retrieved content between comments that INCLUDE the specified ids.
|
|
253
286
|
* @param id The id of the comment to extract.
|
|
@@ -273,103 +306,106 @@ const B = /,\s*(?![^()]*\))/, F = {
|
|
|
273
306
|
* @param id The id of the comment to replace.
|
|
274
307
|
* @param with The replacement content (if ommitted, the content of the detected comment will be used).
|
|
275
308
|
* @param space The space character to use between words in the replacement content (defaults to `-`).
|
|
309
|
+
* @param expandLeft ADVANCED: The number of characters to expand the left side of the comment.
|
|
310
|
+
* @param expandRight ADVANCED: The number of characters to expand the right side of the comment.
|
|
276
311
|
* @example [](<url>?region=replace(specifier))
|
|
277
312
|
* @example [](<url>?region=replace(specifier,new-content))
|
|
278
313
|
* @example [](<url>?region=replace(specifier,new_content,_)
|
|
279
314
|
*/
|
|
280
|
-
"replace(id: string, with?: string, space?: string)"
|
|
281
|
-
],
|
|
315
|
+
"replace(id: string, with?: string, space?: string, expandLeft?: number, expandRight?: number)"
|
|
316
|
+
], ze = I(He), Xe = (e, ...t) => {
|
|
282
317
|
if (t.length === 0) return e;
|
|
283
|
-
|
|
318
|
+
e = q(e, t);
|
|
319
|
+
const n = L(e), s = ([i, c]) => e.slice(i, c), o = new v(), r = new v();
|
|
284
320
|
for (const i of t) {
|
|
285
|
-
const c =
|
|
321
|
+
const c = d(e, i, n);
|
|
286
322
|
for (let l = 0; l < c.length - 1; l += 2) {
|
|
287
323
|
const a = c[l], p = c[l + 1];
|
|
288
324
|
o.push(a.range[1], p.range[0]);
|
|
289
|
-
const [m, ...
|
|
290
|
-
r.push(a.range[0], a.range[1] + (m.trim() ? 0 : 1)), r.push(p.range[0], p.range[1] + (
|
|
325
|
+
const [m, ...u] = s([a.range[1], p.range[0]]), $ = u[u.length - 1];
|
|
326
|
+
r.push(a.range[0], a.range[1] + (m.trim() ? 0 : 1)), r.push(p.range[0], p.range[1] + ($.trim() ? 0 : 1));
|
|
291
327
|
}
|
|
292
328
|
}
|
|
293
|
-
return o.collapse(), r.collapse(),
|
|
294
|
-
o.subtract(r).map(
|
|
329
|
+
return o.collapse(), r.collapse(), A(
|
|
330
|
+
o.subtract(r).map(s).filter(Boolean).join("")
|
|
295
331
|
).trim();
|
|
296
|
-
},
|
|
332
|
+
}, Ve = (e, ...t) => {
|
|
297
333
|
if (t.length === 0) return e;
|
|
298
|
-
|
|
334
|
+
e = q(e, t);
|
|
335
|
+
const n = L(e), s = ([i, c]) => e.slice(i, c), o = new v();
|
|
299
336
|
for (const i of t) {
|
|
300
|
-
const c =
|
|
337
|
+
const c = d(e, i, n);
|
|
301
338
|
for (let l = 0; l < c.length - 1; l += 2) {
|
|
302
|
-
const a = c[l], p = c[l + 1], m =
|
|
339
|
+
const a = c[l], p = c[l + 1], m = s([p.range[1], p.range[1] + 1]).at(-1);
|
|
303
340
|
o.push(a.range[0], m === `
|
|
304
341
|
` ? p.range[1] + 1 : p.range[1]);
|
|
305
342
|
}
|
|
306
343
|
}
|
|
307
344
|
o.collapse();
|
|
308
|
-
const r = new
|
|
309
|
-
return r.push(0, e.length), r.subtract(o),
|
|
310
|
-
r.collapse().map(
|
|
345
|
+
const r = new v();
|
|
346
|
+
return r.push(0, e.length), r.subtract(o), A(
|
|
347
|
+
r.collapse().map(s).filter(Boolean).join("")
|
|
311
348
|
).trim();
|
|
312
|
-
},
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
349
|
+
}, K = (e, t) => {
|
|
350
|
+
const n = d(e, t), s = [];
|
|
351
|
+
for (let o = 0; o < n.length - 1; o += 2)
|
|
352
|
+
s.push([n[o], n[o + 1]]);
|
|
353
|
+
return s;
|
|
354
|
+
}, Je = (e, t, n) => {
|
|
355
|
+
const [s, o] = n;
|
|
356
|
+
return e && (s.range[0] -= e), t && (o.range[1] += t), n;
|
|
357
|
+
}, Ze = (e, t, n, s, o, r) => {
|
|
358
|
+
if (!t || (e = q(e, t), d(e, t).length < 2)) return e;
|
|
359
|
+
let c = "", l = 0;
|
|
360
|
+
const a = Je.bind(null, o, r);
|
|
361
|
+
for (const [m, u] of K(e, t).map(a))
|
|
362
|
+
c += e.slice(l, m.range[1]), c += se(n ?? m.value, s), l = u.range[0];
|
|
363
|
+
c += e.slice(l);
|
|
364
|
+
const p = new v();
|
|
365
|
+
return p.push(0, c.length), p.subtract(new v(
|
|
366
|
+
...K(c, t).map(a).flatMap(([m, u]) => [m.range, u.range])
|
|
367
|
+
)), A(
|
|
368
|
+
p.collapse().map(([m, u]) => c.slice(m, u)).filter(Boolean).join("")
|
|
327
369
|
).trim();
|
|
328
|
-
},
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
...x(e, "parkdown:")
|
|
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 = z(t[n - 1]), c = z(t[s]), l = s === t.length;
|
|
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), Ue = (e, t, n) => {
|
|
336
|
-
if (!t) return X(e);
|
|
337
|
-
const s = Le(t);
|
|
370
|
+
}, Ke = (e, t, n) => {
|
|
371
|
+
if (!t) return Z(e);
|
|
372
|
+
const s = ze(t);
|
|
338
373
|
switch (s.name) {
|
|
339
374
|
case "extract":
|
|
340
|
-
e =
|
|
375
|
+
e = Xe(e, s.id, ...z(s));
|
|
341
376
|
break;
|
|
342
377
|
case "remove":
|
|
343
|
-
e =
|
|
378
|
+
e = Ve(e, s.id, ...z(s));
|
|
344
379
|
break;
|
|
345
380
|
case "replace":
|
|
346
|
-
|
|
381
|
+
const { with: o, id: r, space: i, expandLeft: c, expandRight: l } = s;
|
|
382
|
+
e = Ze(e, r, o, i, c, l);
|
|
347
383
|
break;
|
|
348
384
|
}
|
|
349
|
-
return n ?
|
|
350
|
-
},
|
|
385
|
+
return n ? Z(e) : e;
|
|
386
|
+
}, Ye = ["http", "./", "../"], et = ({ url: e }) => Ye.some((t) => e.startsWith(t)), tt = (e) => j(e) && Ne(e) && et(e), ie = ({ url: e }, t) => `[](${t ? S(t, e) : e})`, h = {
|
|
351
387
|
_open: "<!--",
|
|
352
388
|
_close: "-->",
|
|
353
389
|
_flag: "p↓",
|
|
354
390
|
get begin() {
|
|
355
|
-
return
|
|
391
|
+
return x(h._open, h._flag, "BEGIN", h._close);
|
|
356
392
|
},
|
|
357
393
|
get end() {
|
|
358
|
-
return
|
|
394
|
+
return x(h._open, h._flag, "END", h._close);
|
|
359
395
|
},
|
|
360
396
|
lengthOf(e) {
|
|
361
397
|
const t = `lines: ${e.split(`
|
|
362
398
|
`).length}`, n = `chars: ${e.length}`;
|
|
363
|
-
return
|
|
399
|
+
return x(h._open, h._flag, "length", t, n, h._close);
|
|
364
400
|
}
|
|
365
|
-
},
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
401
|
+
}, Y = (e) => (t) => j(t) && t.value === h[e], nt = ({ position: e, url: t, siblingCount: n }, s) => ({ position: e, url: t, headingDepth: s, inline: n >= 1 }), st = ({ position: { start: e }, url: t, siblingCount: n }, { position: { end: s } }, o) => ({ position: { start: e, end: s }, url: t, headingDepth: o, inline: n >= 1 }), ot = (e, t, n) => (e.inline ? x : Me)(
|
|
402
|
+
ie(e, n),
|
|
403
|
+
h.begin,
|
|
404
|
+
h.lengthOf(t),
|
|
369
405
|
t,
|
|
370
|
-
|
|
371
|
-
),
|
|
372
|
-
const t =
|
|
406
|
+
h.end
|
|
407
|
+
), rt = (e) => {
|
|
408
|
+
const t = b(e, "heading").reduce((n, { position: s, depth: o }) => n.set(s.start.line, o), /* @__PURE__ */ new Map());
|
|
373
409
|
return (n) => {
|
|
374
410
|
for (let s = n.position.start.line; s >= 1; s--) {
|
|
375
411
|
const o = t.get(s);
|
|
@@ -377,113 +413,113 @@ const B = /,\s*(?![^()]*\))/, F = {
|
|
|
377
413
|
}
|
|
378
414
|
return 0;
|
|
379
415
|
};
|
|
380
|
-
},
|
|
416
|
+
}, N = {
|
|
381
417
|
openingCommentDoesNotFollowLink: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),
|
|
382
418
|
closingCommentNotMatchedToOpening: ({ position: { start: e } }) => new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),
|
|
383
419
|
openingCommentNotClosed: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)
|
|
384
|
-
},
|
|
420
|
+
}, it = (e, t) => {
|
|
385
421
|
const n = [], s = [
|
|
386
422
|
...e.map((r) => ({ node: r, type: "open" })),
|
|
387
423
|
...t.map((r) => ({ node: r, type: "close" }))
|
|
388
|
-
].sort((r, i) =>
|
|
424
|
+
].sort((r, i) => f(r.node, i.node)), o = [];
|
|
389
425
|
for (const r of s)
|
|
390
426
|
if (r.type === "open") o.push(r);
|
|
391
427
|
else {
|
|
392
428
|
const i = r.node;
|
|
393
429
|
if (o.length === 0)
|
|
394
|
-
throw
|
|
430
|
+
throw N.closingCommentNotMatchedToOpening(i);
|
|
395
431
|
const c = o.pop().node;
|
|
396
432
|
if (o.length > 0) continue;
|
|
397
433
|
n.push({ open: c, close: i });
|
|
398
434
|
}
|
|
399
435
|
if (o.length > 0)
|
|
400
|
-
throw
|
|
436
|
+
throw N.openingCommentNotClosed(o[0].node);
|
|
401
437
|
return n;
|
|
402
|
-
},
|
|
403
|
-
const s = [...t].sort(
|
|
404
|
-
return [...n].sort((r, i) =>
|
|
438
|
+
}, ct = (e, t, n) => {
|
|
439
|
+
const s = [...t].sort(f), o = [];
|
|
440
|
+
return [...n].sort((r, i) => f.reverse(r.open, i.open)).forEach((r) => {
|
|
405
441
|
for (; s.length > 0; ) {
|
|
406
442
|
const i = s.pop();
|
|
407
443
|
if (i.position.start.offset < r.open.position.start.offset) {
|
|
408
|
-
if (
|
|
409
|
-
throw
|
|
444
|
+
if (ke(e, i, r.open).trim() !== "")
|
|
445
|
+
throw N.openingCommentDoesNotFollowLink(r.open);
|
|
410
446
|
return o.push([i, r]);
|
|
411
447
|
}
|
|
412
448
|
o.push(i);
|
|
413
449
|
}
|
|
414
|
-
throw
|
|
450
|
+
throw N.openingCommentDoesNotFollowLink(r.open);
|
|
415
451
|
}), o.push(...s.reverse()), o.reverse();
|
|
416
|
-
},
|
|
417
|
-
t ?? (t =
|
|
418
|
-
const n =
|
|
419
|
-
return
|
|
420
|
-
},
|
|
452
|
+
}, ce = (e, t) => {
|
|
453
|
+
t ?? (t = D.md(e));
|
|
454
|
+
const n = rt(t), s = b(t, "link").filter(tt), o = b(t, "html").sort(f), r = o.filter(Y("begin")), i = o.filter(Y("end")), c = it(r, i);
|
|
455
|
+
return ct(e, s, c).map((a) => Array.isArray(a) ? st(a[0], a[1].close, n(a[0])) : nt(a, n(a)));
|
|
456
|
+
}, lt = (e, { url: t }) => (n) => e(S(O(t), n)), le = (...e) => {
|
|
421
457
|
const t = e.reduce((n, s) => n + s, 0);
|
|
422
458
|
return Math.min(Math.max(t, 1), 6);
|
|
423
|
-
},
|
|
459
|
+
}, at = (e, t, n) => {
|
|
424
460
|
if (t === 0) return e;
|
|
425
|
-
n ?? (n =
|
|
426
|
-
const s =
|
|
461
|
+
n ?? (n = D.md(e));
|
|
462
|
+
const s = b(n, "heading"), o = e.split(`
|
|
427
463
|
`);
|
|
428
464
|
for (const r of s) {
|
|
429
|
-
const { depth: i, position: { start: c, end: l } } = r, a =
|
|
465
|
+
const { depth: i, position: { start: c, end: l } } = r, a = le(i, t), p = o[c.line - 1].slice(i, l.column), m = "#".repeat(a) + p;
|
|
430
466
|
o[c.line - 1] = m, r.depth = a;
|
|
431
467
|
}
|
|
432
468
|
return o.join(`
|
|
433
469
|
`);
|
|
434
|
-
},
|
|
470
|
+
}, ae = (e) => ce(e).reverse().sort(f.reverse).reduce((t, n) => ne(t, ie(n), n), e), pe = (e, t, n, s, o) => {
|
|
435
471
|
try {
|
|
436
|
-
e =
|
|
437
|
-
const r =
|
|
438
|
-
return
|
|
439
|
-
var
|
|
440
|
-
const { url: c, headingDepth: l } = i, [a, ...p] =
|
|
472
|
+
e = ae(e), e = at(e, t);
|
|
473
|
+
const r = D.md(e);
|
|
474
|
+
return ce(e, r).sort(f).reverse().map((i) => {
|
|
475
|
+
var B, F;
|
|
476
|
+
const { url: c, headingDepth: l } = i, [a, ...p] = Ce(c).split("?"), m = a.split(".").pop() ?? "", u = p.join("?"), $ = O(c), W = S($, a);
|
|
441
477
|
if (c.startsWith("./") || c.startsWith("../")) {
|
|
442
|
-
let
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
(
|
|
446
|
-
|
|
447
|
-
)) ??
|
|
448
|
-
const
|
|
449
|
-
let { inline:
|
|
450
|
-
if (
|
|
478
|
+
let g = n(W);
|
|
479
|
+
const C = new ye(u), k = (B = C.get("region")) == null ? void 0 : B.split(T);
|
|
480
|
+
g = (k == null ? void 0 : k.reduce(
|
|
481
|
+
(y, E, R, { length: de }) => Ke(y, E, R === de - 1),
|
|
482
|
+
g
|
|
483
|
+
)) ?? g;
|
|
484
|
+
const he = C.has("skip"), ge = C.get("heading") ?? 0, fe = C.has("inline");
|
|
485
|
+
let { inline: M } = i;
|
|
486
|
+
if (fe && (M = !0), !he)
|
|
451
487
|
if (m === "md") {
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
488
|
+
const y = lt(n, i), E = o ? S(o, $) : $, R = le(l, Number(ge));
|
|
489
|
+
g = pe(
|
|
490
|
+
g,
|
|
455
491
|
/** p↓: ... */
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
492
|
+
R,
|
|
493
|
+
y,
|
|
494
|
+
W,
|
|
495
|
+
E
|
|
460
496
|
/** p↓: ... */
|
|
461
497
|
);
|
|
462
|
-
} else /^(js|ts)x?|svelte$/i.test(m) && (
|
|
463
|
-
|
|
498
|
+
} else /^(js|ts)x?|svelte$/i.test(m) && (g = X(
|
|
499
|
+
g,
|
|
464
500
|
"code",
|
|
465
501
|
/** p↓: ... */
|
|
466
|
-
{ extension: m, inline:
|
|
502
|
+
{ extension: m, inline: M }
|
|
467
503
|
/** p↓: ... */
|
|
468
504
|
));
|
|
469
|
-
const
|
|
470
|
-
return
|
|
505
|
+
const _ = (F = C.get("wrap")) == null ? void 0 : F.split(T);
|
|
506
|
+
return g = (_ == null ? void 0 : _.reduce((y, E) => X(y, E, { extension: m, inline: M }), g)) ?? g, { target: i, content: ot(i, g, o) };
|
|
471
507
|
} else throw c.startsWith("http") ? new Error("External web links are not implemented yet") : new Error(`Unsupported link type: ${c}`);
|
|
472
|
-
}).reduce((i, { target: c, content: l }) =>
|
|
508
|
+
}).reduce((i, { target: c, content: l }) => ne(i, l, c), e);
|
|
473
509
|
} catch (r) {
|
|
474
510
|
throw new Error(`Error populating inclusions in file ${s ?? "(unknown)"}: ${r}`);
|
|
475
511
|
}
|
|
476
|
-
},
|
|
477
|
-
const t =
|
|
478
|
-
return { markdown:
|
|
479
|
-
},
|
|
480
|
-
const { dir: n, path: s, markdown: o } =
|
|
481
|
-
return t &&
|
|
482
|
-
},
|
|
483
|
-
const { path: n, markdown: s } =
|
|
484
|
-
return t &&
|
|
512
|
+
}, me = (e) => $e(e, "utf-8"), ue = (e) => {
|
|
513
|
+
const t = te(e), n = O(t);
|
|
514
|
+
return { markdown: me(t), dir: n, path: t };
|
|
515
|
+
}, vt = (e, t = !0) => {
|
|
516
|
+
const { dir: n, path: s, markdown: o } = ue(e), i = pe(o, 0, (c) => me(te(n, Re(c))), s);
|
|
517
|
+
return t && ee(s, i), i;
|
|
518
|
+
}, $t = (e, t = !0) => {
|
|
519
|
+
const { path: n, markdown: s } = ue(e), o = ae(s);
|
|
520
|
+
return t && ee(n, o), o;
|
|
485
521
|
};
|
|
486
522
|
export {
|
|
487
|
-
|
|
488
|
-
|
|
523
|
+
$t as depopulateMarkdownInclusions,
|
|
524
|
+
vt as populateMarkdownInclusions
|
|
489
525
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`),
|
|
1
|
+
(function(m,h){typeof exports=="object"&&typeof module<"u"?h(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"],h):(m=typeof globalThis<"u"?globalThis:m||self,h(m.index={},m.node_fs,m.node_path,m.node_url,m.unified,m.remarkParse,m.unistUtilVisit,m.tsDedent))})(this,function(m,h,g,me,de,he,ge,T){"use strict";var on=Object.defineProperty;var rn=(m,h,g)=>h in m?on(m,h,{enumerable:!0,configurable:!0,writable:!0,value:g}):m[h]=g;var ue=(m,h,g)=>rn(m,typeof h!="symbol"?h+"":h,g);const v=(e,n)=>e.position.start.offset-n.position.start.offset;v.reverse=(e,n)=>v(n,e);const j=e=>e.position!==void 0&&e.position.start.offset!==void 0&&e.position.end.offset!==void 0,fe=de.unified().use(he),q={md:e=>fe.parse(e)},N=(e,n)=>{const t=[];return ge.visit(e,(s,o,r)=>{if(s.type!=="root"){if(n&&s.type!==n)return;if(j(s)){const i=((r==null?void 0:r.children.length)??0)-1;t.push({...s,siblingIndex:o,siblingCount:i})}}}),t},we=e=>e.children.length===0,B=(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)},ve=(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)},b=(...e)=>e.join(" "),$e=(...e)=>e.join(`
|
|
2
|
+
`),ye=e=>{const n=e.split("?");return n.length>1?[n.slice(0,-1).join("?"),n.at(-1)]:[e,""]},Ce=e=>ye(e)[0];class y{constructor(...n){ue(this,"intervals",[]);for(const[t,s]of n)this.push(t,s)}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 O=/,\s*(?![^()]*\))/,F={reserved:{semi:";",slash:"/",question:"?",colon:":",at:"@",equal:"=",and:"&"},unsafe:{quote:'"',angle:"<",unangle:">",hash:"#",percent:"%",curly:"{",uncurly:"}",pipe:"|",back:"\\",carrot:"^",tilde:"~",square:"[",unsquare:"]",tick:"`"}},xe="-",U={static:[["'''",'"'],["''","'"],[/parkdown:\s+/g,""],[/p↓:\s+/g,""]],url:[...Object.entries(F.unsafe),...Object.entries(F.reserved)]},Q=(e,[n,t])=>e.replaceAll(n,t),G=(e,n=xe)=>{const t=U.static.reduce(Q,e);return U.url.map(([s,o])=>[n+s+n,o]).reduce(Q,t).replaceAll(n," ")},Ee=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Se=["string","number","boolean"],ke=e=>Se.includes(e),Ne=/^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/,be=e=>{const n=e.match(Ne);if(!n)throw new Error(`Invalid invocation: ${e}`);const[,t,s=""]=n;if(!s.trim())return{name:t,parameters:[]};const o=Te(s);return{name:t,parameters:o}},Me=(e,n)=>{for(let t=n+1;t<e.length;t++)if(e[t]!==void 0)return!1;return!0},Te=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?je(o):void 0).filter((o,r,i)=>o!==void 0||!Me(i,r))},je=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)},qe=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,u=p.trim();if(!ke(u))throw new Error(`Unsupported type: ${u}`);i.push({name:l,optional:a==="?",type:u})}return{name:s,parameters:i}},P=e=>{const n=e.map(qe).reduce((t,{name:s,parameters:o})=>t.set(s,o),new Map);return t=>{const{name:s,parameters:o}=be(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 u=o[p];if(u===void 0){if(l)return i;throw new Error(`Missing required parameter: ${c} for method '${s}'`)}switch(a){case"string":i[c]=u;break;case"number":case"boolean":i[c]=JSON.parse(u);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),Oe=P(["code(lang?: string, meta?: string)","quote()","dropdown(summary: string, open?: boolean, space?: string)"]),C=(e,n=1)=>`
|
|
3
3
|
`.repeat(n)+e+`
|
|
4
|
-
`.repeat(n),
|
|
5
|
-
`))return`\`${e}\``;const r=s.lang??(t==null?void 0:t.extension)??"",i=s.meta?` ${s.meta}`:"";return
|
|
4
|
+
`.repeat(n),R=(e,n,t)=>`<${n}${t?` ${t}`:""}>${C(e)}</${n}>`,z=(e,n,t)=>{const s=Oe(n);switch(s.name){case"code":if(!s.lang&&!s.meta&&(t==null?void 0:t.inline)&&!e.includes(`
|
|
5
|
+
`))return`\`${e}\``;const r=s.lang??(t==null?void 0:t.extension)??"",i=s.meta?` ${s.meta}`:"";return C(`\`\`\`${r}${i}${C(e)}\`\`\``);case"quote":return t!=null&&t.inline&&!e.includes(`
|
|
6
6
|
|
|
7
|
-
`)?`> ${e}
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
`).length}`,t=`chars: ${e.length}`;return
|
|
12
|
-
`);for(const r of s){const{depth:i,position:{start:c,end:l}}=r,a=
|
|
13
|
-
`)},
|
|
7
|
+
`)?`> ${e}`:C(R(C(e),"blockquote"));case"dropdown":const c=R(G(s.summary),"summary");return C(R([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=Pe(s[0]).trim();t.push({range:o,value:r})}return t},Pe=e=>e.startsWith("//")?e.slice(2):e.startsWith("/*")?e.slice(2,-2):e.startsWith("<!--")?e.slice(4,-3):e,V=["p↓:","pd:","parkdown:"],X=P(["splice(delete?: number, insert?: string)"]),$=(e,n,t)=>(t??I(e)).filter(({value:s})=>s.includes(n)).sort((s,o)=>s.range[0]-o.range[0]),J=e=>({isSpace:e===" ",isNewline:e===`
|
|
9
|
+
`||e===void 0}),Z=e=>V.flatMap(n=>$(e,n)).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=J(n[t-1]),c=J(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),K=V.map(e=>new RegExp(`^${Ee(e)}(\\?[^\\s]+)`)),Re=e=>K.map(n=>{var t;return(t=n.exec(e))==null?void 0:t[1]}).filter(Boolean).map(n=>new URLSearchParams(n))[0],A=(e,n)=>(Array.isArray(n)?n.flatMap(t=>$(e,t)):$(e,n)).filter(({value:t})=>K.some(s=>s.test(t))).sort((t,s)=>t.range[0]-s.range[0]).reverse().reduce((t,{range:[s,o],value:r})=>{var l,a;const i=Re(r),c=["back","front"].map(p=>[p,i.get(p)]).filter(([p,u])=>!!u).reduce((p,[u,d])=>p.set(u,d.split(O)),new Map);return t=((l=c.get("back"))==null?void 0:l.reduce((p,u)=>{const d=X(u);if(d.name==="splice")return p.slice(0,o)+(d.insert??"")+p.slice(o+(d.delete??0))},t))??t,t=((a=c.get("front"))==null?void 0:a.reduce((p,u)=>{const d=X(u);if(d.name==="splice")return p.slice(0,s-(d.delete??0))+(d.insert??"")+p.slice(s)},t))??t,t},e),Ie=P(["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, expandLeft?: number, expandRight?: number)"]),Ae=(e,...n)=>{if(n.length===0)return e;e=A(e,n);const t=I(e),s=([i,c])=>e.slice(i,c),o=new y,r=new y;for(const i of n){const c=$(e,i,t);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[u,...d]=s([a.range[1],p.range[0]]),x=d[d.length-1];r.push(a.range[0],a.range[1]+(u.trim()?0:1)),r.push(p.range[0],p.range[1]+(x.trim()?0:1))}}return o.collapse(),r.collapse(),T.dedent(o.subtract(r).map(s).filter(Boolean).join("")).trim()},De=(e,...n)=>{if(n.length===0)return e;e=A(e,n);const t=I(e),s=([i,c])=>e.slice(i,c),o=new y;for(const i of n){const c=$(e,i,t);for(let l=0;l<c.length-1;l+=2){const a=c[l],p=c[l+1],u=s([p.range[1],p.range[1]+1]).at(-1);o.push(a.range[0],u===`
|
|
10
|
+
`?p.range[1]+1:p.range[1])}}o.collapse();const r=new y;return r.push(0,e.length),r.subtract(o),T.dedent(r.collapse().map(s).filter(Boolean).join("")).trim()},Y=(e,n)=>{const t=$(e,n),s=[];for(let o=0;o<t.length-1;o+=2)s.push([t[o],t[o+1]]);return s},Le=(e,n,t)=>{const[s,o]=t;return e&&(s.range[0]-=e),n&&(o.range[1]+=n),t},We=(e,n,t,s,o,r)=>{if(!n||(e=A(e,n),$(e,n).length<2))return e;let c="",l=0;const a=Le.bind(null,o,r);for(const[u,d]of Y(e,n).map(a))c+=e.slice(l,u.range[1]),c+=G(t??u.value,s),l=d.range[0];c+=e.slice(l);const p=new y;return p.push(0,c.length),p.subtract(new y(...Y(c,n).map(a).flatMap(([u,d])=>[u.range,d.range]))),T.dedent(p.collapse().map(([u,d])=>c.slice(u,d)).filter(Boolean).join("")).trim()},_e=(e,n,t)=>{if(!n)return Z(e);const s=Ie(n);switch(s.name){case"extract":e=Ae(e,s.id,...H(s));break;case"remove":e=De(e,s.id,...H(s));break;case"replace":const{with:o,id:r,space:i,expandLeft:c,expandRight:l}=s;e=We(e,r,o,i,c,l);break}return t?Z(e):e},Be=["http","./","../"],Fe=({url:e})=>Be.some(n=>e.startsWith(n)),Ue=e=>j(e)&&we(e)&&Fe(e),ee=({url:e},n)=>`[](${n?g.join(n,e):e})`,f={_open:"<!--",_close:"-->",_flag:"p↓",get begin(){return b(f._open,f._flag,"BEGIN",f._close)},get end(){return b(f._open,f._flag,"END",f._close)},lengthOf(e){const n=`lines: ${e.split(`
|
|
11
|
+
`).length}`,t=`chars: ${e.length}`;return b(f._open,f._flag,"length",n,t,f._close)}},ne=e=>n=>j(n)&&n.value===f[e],Qe=({position:e,url:n,siblingCount:t},s)=>({position:e,url:n,headingDepth:s,inline:t>=1}),Ge=({position:{start:e},url:n,siblingCount:t},{position:{end:s}},o)=>({position:{start:e,end:s},url:n,headingDepth:o,inline:t>=1}),He=(e,n,t)=>(e.inline?b:$e)(ee(e,t),f.begin,f.lengthOf(n),n,f.end),ze=e=>{const n=N(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}},M={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`)},Ve=(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 M.closingCommentNotMatchedToOpening(i);const c=o.pop().node;if(o.length>0)continue;t.push({open:c,close:i})}if(o.length>0)throw M.openingCommentNotClosed(o[0].node);return t},Xe=(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(ve(e,i,r.open).trim()!=="")throw M.openingCommentDoesNotFollowLink(r.open);return o.push([i,r])}o.push(i)}throw M.openingCommentDoesNotFollowLink(r.open)}),o.push(...s.reverse()),o.reverse()},te=(e,n)=>{n??(n=q.md(e));const t=ze(n),s=N(n,"link").filter(Ue),o=N(n,"html").sort(v),r=o.filter(ne("begin")),i=o.filter(ne("end")),c=Ve(r,i);return Xe(e,s,c).map(a=>Array.isArray(a)?Ge(a[0],a[1].close,t(a[0])):Qe(a,t(a)))},Je=(e,{url:n})=>t=>e(g.join(g.dirname(n),t)),se=(...e)=>{const n=e.reduce((t,s)=>t+s,0);return Math.min(Math.max(n,1),6)},Ze=(e,n,t)=>{if(n===0)return e;t??(t=q.md(e));const s=N(t,"heading"),o=e.split(`
|
|
12
|
+
`);for(const r of s){const{depth:i,position:{start:c,end:l}}=r,a=se(i,n),p=o[c.line-1].slice(i,l.column),u="#".repeat(a)+p;o[c.line-1]=u,r.depth=a}return o.join(`
|
|
13
|
+
`)},oe=e=>te(e).reverse().sort(v.reverse).reduce((n,t)=>B(n,ee(t),t),e),re=(e,n,t,s,o)=>{try{e=oe(e),e=Ze(e,n);const r=q.md(e);return te(e,r).sort(v).reverse().map(i=>{var ae,pe;const{url:c,headingDepth:l}=i,[a,...p]=g.basename(c).split("?"),u=a.split(".").pop()??"",d=p.join("?"),x=g.dirname(c),le=g.join(x,a);if(c.startsWith("./")||c.startsWith("../")){let w=t(le);const E=new me.URLSearchParams(d),D=(ae=E.get("region"))==null?void 0:ae.split(O);w=(D==null?void 0:D.reduce((S,k,_,{length:sn})=>_e(S,k,_===sn-1),w))??w;const en=E.has("skip"),nn=E.get("heading")??0,tn=E.has("inline");let{inline:L}=i;if(tn&&(L=!0),!en)if(u==="md"){const S=Je(t,i),k=o?g.join(o,x):x,_=se(l,Number(nn));w=re(w,_,S,le,k)}else/^(js|ts)x?|svelte$/i.test(u)&&(w=z(w,"code",{extension:u,inline:L}));const W=(pe=E.get("wrap"))==null?void 0:pe.split(O);return w=(W==null?void 0:W.reduce((S,k)=>z(S,k,{extension:u,inline:L}),w))??w,{target:i,content:He(i,w,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})=>B(i,l,c),e)}catch(r){throw new Error(`Error populating inclusions in file ${s??"(unknown)"}: ${r}`)}},ie=e=>h.readFileSync(e,"utf-8"),ce=e=>{const n=g.resolve(e),t=g.dirname(n);return{markdown:ie(n),dir:t,path:n}},Ke=(e,n=!0)=>{const{dir:t,path:s,markdown:o}=ce(e),i=re(o,0,c=>ie(g.resolve(t,Ce(c))),s);return n&&h.writeFileSync(s,i),i},Ye=(e,n=!0)=>{const{path:t,markdown:s}=ce(e),o=oe(s);return n&&h.writeFileSync(t,o),o};m.depopulateMarkdownInclusions=Ye,m.populateMarkdownInclusions=Ke,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|