@p-buddy/parkdown 0.0.28 → 0.0.34

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/index.js CHANGED
@@ -1,41 +1,41 @@
1
- var Ce = Object.defineProperty;
2
- var Ee = (e, t, n) => t in e ? Ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var _ = (e, t, n) => Ee(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { writeFileSync as ae, readFileSync as Se } from "node:fs";
5
- import { basename as xe, dirname as Q, join as T, resolve as ce } from "node:path";
6
- import { URLSearchParams as _e } from "node:url";
7
- import { unified as Ne } from "unified";
8
- import ke from "remark-parse";
9
- import { visit as Me } from "unist-util-visit";
10
- import { dedent as Te } 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 G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, Ae = Ne().use(ke), z = {
14
- md: (e) => Ae.parse(e)
15
- }, A = (e, t) => {
1
+ var Se = Object.defineProperty;
2
+ var xe = (e, t, n) => t in e ? Se(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var _ = (e, t, n) => xe(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { writeFileSync as pe, readFileSync as _e } from "node:fs";
5
+ import { basename as ke, dirname as Q, join as A, resolve as me } from "node:path";
6
+ import { URLSearchParams as Ne } from "node:url";
7
+ import { unified as Me } from "unified";
8
+ import Te from "remark-parse";
9
+ import { visit as Ae } from "unist-util-visit";
10
+ import { dedent as Oe } from "ts-dedent";
11
+ const d = (e, t) => e.position.start.offset - t.position.start.offset;
12
+ d.reverse = (e, t) => d(t, e);
13
+ const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, Re = Me().use(Te), z = {
14
+ md: (e) => Re.parse(e)
15
+ }, O = (e, t) => {
16
16
  const n = [];
17
- return Me(e, (s, r, o) => {
18
- if (s.type !== "root") {
19
- if (t && s.type !== t) return;
20
- if (G(s)) {
21
- const i = ((o == null ? void 0 : o.children.length) ?? 0) - 1;
22
- n.push({ ...s, siblingIndex: r, siblingCount: i });
17
+ return Ae(e, (o, s, r) => {
18
+ if (o.type !== "root") {
19
+ if (t && o.type !== t) return;
20
+ if (G(o)) {
21
+ const i = ((r == null ? void 0 : r.children.length) ?? 0) - 1;
22
+ n.push({ ...o, siblingIndex: s, siblingCount: i });
23
23
  }
24
24
  }
25
25
  }), n;
26
- }, Oe = (e) => e.children.length === 0, pe = (e, t, ...n) => {
26
+ }, We = (e) => e.children.length === 0, ge = (e, t, ...n) => {
27
27
  if (n.length === 0) throw new Error("No nodes to replace content from");
28
- n.sort(f);
29
- const s = n.at(0), r = n.at(-1);
30
- return e.slice(0, s.position.start.offset) + t + e.slice(r.position.end.offset);
31
- }, Re = (e, t, n) => {
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
- return e.slice(s, r);
34
- }, M = (...e) => e.join(" "), We = (...e) => e.join(`
35
- `), Ie = (e) => {
28
+ n.sort(d);
29
+ const o = n.at(0), s = n.at(-1);
30
+ return e.slice(0, o.position.start.offset) + t + e.slice(s.position.end.offset);
31
+ }, Ie = (e, t, n) => {
32
+ const o = Math.min(t.position.end.offset, n.position.end.offset), s = Math.max(t.position.start.offset, n.position.start.offset);
33
+ return e.slice(o, s);
34
+ }, M = (...e) => e.join(" "), Pe = (...e) => e.join(`
35
+ `), je = (e) => {
36
36
  const t = e.split("?");
37
37
  return t.length > 1 ? [t.slice(0, -1).join("?"), t.at(-1)] : [e, ""];
38
- }, Pe = (e) => Ie(e)[0], J = /,\s*(?![^()]*\))/, Z = {
38
+ }, De = (e) => je(e)[0], Z = /,\s*(?![^()]*\))/, K = {
39
39
  reserved: {
40
40
  semi: ";",
41
41
  slash: "/",
@@ -63,7 +63,7 @@ const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
63
63
  line: `
64
64
  `
65
65
  }
66
- }, je = "-", K = {
66
+ }, Le = "-", Y = {
67
67
  static: [
68
68
  ["'''", '"'],
69
69
  ["''", "'"],
@@ -71,71 +71,71 @@ const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
71
71
  [/p↓:\s+/g, ""]
72
72
  ],
73
73
  url: [
74
- ...Object.entries(Z.unsafe),
75
- ...Object.entries(Z.reserved)
74
+ ...Object.entries(K.unsafe),
75
+ ...Object.entries(K.reserved)
76
76
  ]
77
- }, Y = (e, [t, n]) => e.replaceAll(t, n), W = (e, t = je) => {
78
- const n = K.static.reduce(Y, e);
79
- return K.url.map(([s, r]) => [t + s + t, r]).reduce(Y, n).replaceAll(t, " ");
80
- }, De = ["string", "number", "boolean"], Le = (e) => De.includes(e), Ue = /^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/, qe = (e) => {
81
- const t = e.match(Ue);
77
+ }, ee = (e, [t, n]) => e.replaceAll(t, n), I = (e, t = Le) => {
78
+ const n = Y.static.reduce(ee, e);
79
+ return Y.url.map(([o, s]) => [t + o + t, s]).reduce(ee, n).replaceAll(t, " ");
80
+ }, Ue = ["string", "number", "boolean"], qe = (e) => Ue.includes(e), Be = /^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/, Fe = (e) => {
81
+ const t = e.match(Be);
82
82
  if (!t) throw new Error(`Invalid invocation: ${e}`);
83
- const [, n, s = ""] = t;
84
- if (!s.trim()) return { name: n, parameters: [] };
85
- const r = Fe(s);
86
- return { name: n, parameters: r };
87
- }, Be = (e, t) => {
83
+ const [, n, o = ""] = t;
84
+ if (!o.trim()) return { name: n, parameters: [] };
85
+ const s = Qe(o);
86
+ return { name: n, parameters: s };
87
+ }, He = (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
- }, Fe = (e) => {
91
+ }, Qe = (e) => {
92
92
  const t = [];
93
- let n = "", s = !1;
94
- for (let r = 0; r < e.length; r++) {
95
- const o = e[r], i = o === "'";
96
- if (i && e.at(r + 1) === "'") {
97
- const l = e.at(r + 2) === "'";
98
- s = !s, n += l ? "'''" : "''", r += l ? 2 : 1;
99
- } else i ? (s = !s, n += o) : o === "," && !s ? (t.push(n.trim()), n = "") : n += o;
93
+ let n = "", o = !1;
94
+ for (let s = 0; s < e.length; s++) {
95
+ const r = e[s], i = r === "'";
96
+ if (i && e.at(s + 1) === "'") {
97
+ const l = e.at(s + 2) === "'";
98
+ o = !o, n += l ? "'''" : "''", s += l ? 2 : 1;
99
+ } else i ? (o = !o, n += r) : r === "," && !o ? (t.push(n.trim()), n = "") : n += r;
100
100
  }
101
- return t.push(n.trim()), t.map((r) => r === "" ? void 0 : r ? He(r) : void 0).filter((r, o, i) => r !== void 0 || !Be(i, o));
102
- }, He = (e) => {
101
+ return t.push(n.trim()), t.map((s) => s === "" ? void 0 : s ? Ge(s) : void 0).filter((s, r, i) => s !== void 0 || !He(i, r));
102
+ }, Ge = (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
- }, Qe = (e) => {
105
+ }, ze = (e) => {
106
106
  const t = /^([\w-_]+)(?:\(([^)]*)\))?/, n = e.match(t);
107
107
  if (!n) return { name: e };
108
- const [, s, r] = n;
109
- if (!r) return { name: s };
110
- const o = /([\w-_]+)(\?)?:\s*([^,]+)/g, i = [];
108
+ const [, o, s] = n;
109
+ if (!s) return { name: o };
110
+ const r = /([\w-_]+)(\?)?:\s*([^,]+)/g, i = [];
111
111
  let l;
112
- for (; (l = o.exec(r)) !== null; ) {
113
- const [, c, a, u] = l, p = u.trim();
114
- if (!Le(p)) throw new Error(`Unsupported type: ${p}`);
112
+ for (; (l = r.exec(s)) !== null; ) {
113
+ const [, c, a, m] = l, p = m.trim();
114
+ if (!qe(p)) throw new Error(`Unsupported type: ${p}`);
115
115
  i.push({ name: c, optional: a === "?", type: p });
116
116
  }
117
- return { name: s, parameters: i };
118
- }, O = (e) => {
119
- const t = e.map(Qe).reduce(
120
- (n, { name: s, parameters: r }) => n.set(s, r),
117
+ return { name: o, parameters: i };
118
+ }, R = (e) => {
119
+ const t = e.map(ze).reduce(
120
+ (n, { name: o, parameters: s }) => n.set(o, s),
121
121
  /* @__PURE__ */ new Map()
122
122
  );
123
123
  return (n) => {
124
- const { name: s, parameters: r } = qe(n);
125
- if (!t.has(s))
126
- throw new Error(`Unknown method: ${s}`);
127
- const o = t.get(s);
128
- if (o === void 0)
129
- return { name: s };
130
- if (r.length > o.length) {
131
- const i = o.filter(({ optional: c }) => !c).length, l = i === o.length ? i.toString() : `${i} - ${o.length}`;
132
- throw new Error(`Too many parameters: ${r.length} for method '${s}' (expected: ${l})`);
124
+ const { name: o, parameters: s } = Fe(n);
125
+ if (!t.has(o))
126
+ throw new Error(`Unknown method: ${o}`);
127
+ const r = t.get(o);
128
+ if (r === void 0)
129
+ return { name: o };
130
+ if (s.length > r.length) {
131
+ const i = r.filter(({ optional: c }) => !c).length, l = i === r.length ? i.toString() : `${i} - ${r.length}`;
132
+ throw new Error(`Too many parameters: ${s.length} for method '${o}' (expected: ${l})`);
133
133
  }
134
- return o.reduce((i, { name: l, optional: c, type: a }, u) => {
135
- const p = r[u];
134
+ return r.reduce((i, { name: l, optional: c, type: a }, m) => {
135
+ const p = s[m];
136
136
  if (p === void 0) {
137
137
  if (c) return i;
138
- throw new Error(`Missing required parameter: ${l} for method '${s}'`);
138
+ throw new Error(`Missing required parameter: ${l} for method '${o}'`);
139
139
  }
140
140
  switch (a) {
141
141
  case "string":
@@ -147,11 +147,11 @@ const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
147
147
  break;
148
148
  }
149
149
  if (typeof i[l] !== a)
150
- throw new Error(`Invalid type: ${l} must be ${a}, got ${typeof i[l]} for method '${s}'`);
150
+ throw new Error(`Invalid type: ${l} must be ${a}, got ${typeof i[l]} for method '${o}'`);
151
151
  return i;
152
- }, { name: s });
152
+ }, { name: o });
153
153
  };
154
- }, F = (e) => Object.entries(e).filter(([t]) => t !== "name" && !isNaN(Number(t))).map(([t, n]) => n), Ge = [
154
+ }, T = (e) => Object.entries(e).filter(([t]) => t !== "name" && !isNaN(Number(t))).map(([t, n]) => n), Xe = [
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,32 +181,32 @@ const G = (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
- ], ze = O(Ge), E = (e, t = 1) => `
184
+ ], Ve = R(Xe), E = (e, t = 1) => `
185
185
  `.repeat(t) + e + `
186
- `.repeat(t), B = (e, t, n) => `<${t}${n ? ` ${n}` : ""}>${E(e)}</${t}>`, ee = (e, t, n) => {
187
- const s = ze(t);
188
- switch (s.name) {
186
+ `.repeat(t), F = (e, t, n) => `<${t}${n ? ` ${n}` : ""}>${E(e)}</${t}>`, te = (e, t, n) => {
187
+ const o = Ve(t);
188
+ switch (o.name) {
189
189
  case "code":
190
- if (!s.lang && !s.meta && (n == null ? void 0 : n.inline) && !e.includes(`
190
+ if (!o.lang && !o.meta && (n == null ? void 0 : n.inline) && !e.includes(`
191
191
  `)) return `\`${e}\``;
192
- const o = s.lang ?? (n == null ? void 0 : n.extension) ?? "", i = s.meta ? ` ${s.meta}` : "";
193
- return E(`\`\`\`${o}${i}${E(e)}\`\`\``);
192
+ const r = o.lang ?? (n == null ? void 0 : n.extension) ?? "", i = o.meta ? ` ${o.meta}` : "";
193
+ return E(`\`\`\`${r}${i}${E(e)}\`\`\``);
194
194
  case "quote":
195
195
  return n != null && n.inline && !e.includes(`
196
196
 
197
- `) ? `> ${e}` : E(B(E(e), "blockquote"));
197
+ `) ? `> ${e}` : E(F(E(e), "blockquote"));
198
198
  case "dropdown":
199
- const l = B(W(s.summary), "summary");
200
- return E(B([l, e].join(`
201
- `), "details", s.open ? "open" : void 0));
199
+ const l = F(I(o.summary), "summary");
200
+ return E(F([l, e].join(`
201
+ `), "details", o.open ? "open" : void 0));
202
202
  }
203
203
  };
204
- class d {
204
+ class u {
205
205
  constructor(...t) {
206
206
  _(this, "_intervals", []);
207
207
  _(this, "collapsed", !0);
208
- for (const [n, s] of t)
209
- this.push(n, s);
208
+ for (const [n, o] of t)
209
+ this.push(n, o);
210
210
  }
211
211
  get intervals() {
212
212
  return this._intervals;
@@ -215,58 +215,58 @@ class d {
215
215
  return n ?? (n = t + 1), this._intervals.push([Math.min(t, n), Math.max(t, n)]), this.collapsed = !1, this;
216
216
  }
217
217
  combine(t) {
218
- for (const [n, s] of t.intervals)
219
- this.push(n, s);
218
+ for (const [n, o] of t.intervals)
219
+ this.push(n, o);
220
220
  return this;
221
221
  }
222
222
  collapse(t = !1) {
223
- const { _intervals: n, collapsed: s } = this;
224
- if (s && !t || !n.length) return this;
223
+ const { _intervals: n, collapsed: o } = this;
224
+ if (o && !t || !n.length) return this;
225
225
  n.sort((l, c) => l[0] - c[0]);
226
- const r = [];
227
- let [o, i] = n[0];
226
+ const s = [];
227
+ let [r, i] = n[0];
228
228
  for (let l = 1; l < n.length; l++) {
229
229
  const [c, a] = n[l];
230
- c <= i ? i = Math.max(i, a) : (r.push([o, i]), o = c, i = a);
230
+ c <= i ? i = Math.max(i, a) : (s.push([r, i]), r = c, i = a);
231
231
  }
232
- return r.push([o, i]), this._intervals = r, this.collapsed = !0, this;
232
+ return s.push([r, i]), this._intervals = s, this.collapsed = !0, this;
233
233
  }
234
234
  subtract(t) {
235
235
  this.collapse(), t.collapse();
236
- const { _intervals: n } = this, { _intervals: s } = t;
237
- if (!n.length || !s.length) return this;
238
- let r = [...n];
239
- for (const [o, i] of s) {
236
+ const { _intervals: n } = this, { _intervals: o } = t;
237
+ if (!n.length || !o.length) return this;
238
+ let s = [...n];
239
+ for (const [r, i] of o) {
240
240
  const l = [];
241
- for (const [c, a] of r) {
242
- if (i <= c || o >= a) {
241
+ for (const [c, a] of s) {
242
+ if (i <= c || r >= a) {
243
243
  l.push([c, a]);
244
244
  continue;
245
245
  }
246
- o > c && l.push([c, o]), i < a && l.push([i, a]);
246
+ r > c && l.push([c, r]), i < a && l.push([i, a]);
247
247
  }
248
- r = l;
248
+ s = l;
249
249
  }
250
- return this._intervals = r, this.collapse(!0), this;
250
+ return this._intervals = s, this.collapse(!0), this;
251
251
  }
252
252
  test(t, n = "head") {
253
- const { _intervals: s } = this;
253
+ const { _intervals: o } = this;
254
254
  switch (n) {
255
255
  case "head":
256
- return s.some(([r, o]) => t >= r && t < o);
256
+ return o.some(([s, r]) => t >= s && t < r);
257
257
  case "tail":
258
- return s.some(([r, o]) => t > r && t <= o);
258
+ return o.some(([s, r]) => t > s && t <= r);
259
259
  case "both":
260
- return s.some(([r, o]) => t >= r && t <= o);
260
+ return o.some(([s, r]) => t >= s && t <= r);
261
261
  case "none":
262
- return s.some(([r, o]) => t > r && t < o);
262
+ return o.some(([s, r]) => t > s && t < r);
263
263
  }
264
264
  }
265
265
  slice(t) {
266
266
  this.collapse();
267
267
  const n = [];
268
- for (const [s, r] of this._intervals)
269
- n.push(t.slice(s, r));
268
+ for (const [o, s] of this._intervals)
269
+ n.push(t.slice(o, s));
270
270
  return n.filter(Boolean).join("");
271
271
  }
272
272
  offset(t) {
@@ -275,42 +275,78 @@ class d {
275
275
  return this;
276
276
  }
277
277
  }
278
- const I = (e) => {
278
+ const P = (e) => {
279
279
  const t = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm, n = [];
280
- let s;
281
- for (; (s = t.exec(e)) !== null; ) {
282
- const r = [s.index, s.index + s[0].length], o = Xe(s[0]).trim();
283
- n.push({ range: r, value: o });
280
+ let o;
281
+ for (; (o = t.exec(e)) !== null; ) {
282
+ const s = [o.index, o.index + o[0].length], r = Je(o[0]).trim();
283
+ n.push({ range: s, value: r });
284
284
  }
285
285
  return n;
286
- }, Xe = (e) => e.startsWith("//") ? e.slice(2) : e.startsWith("/*") ? e.slice(2, -2) : e.startsWith("<!--") ? e.slice(4, -3) : e, Ve = [
286
+ }, Je = (e) => e.startsWith("//") ? e.slice(2) : e.startsWith("/*") ? e.slice(2, -2) : e.startsWith("<!--") ? e.slice(4, -3) : e, Ze = [
287
287
  "(pd)",
288
288
  "(p↓)",
289
289
  "(parkdown)",
290
290
  "pd:",
291
291
  "p↓:",
292
292
  "parkdown:"
293
- ], ue = (e, t) => e.range[0] - t.range[0], X = (e, t, n) => (n ?? I(e)).filter(({ value: s }) => s.split(" ").includes(t)).sort(ue), te = (e) => ({
293
+ ], he = (e, t) => e.range[0] - t.range[0], X = (e, t, n) => (n ?? P(e)).filter(({ value: o }) => o.split(" ").includes(t)).sort(he), ne = (e) => ({
294
294
  isSpace: e === " ",
295
295
  isNewline: e === `
296
296
  ` || e === void 0
297
- }), ne = (e) => Ve.flatMap((t) => X(e, t)).sort((t, n) => t.range[0] - n.range[0]).reverse().reduce((t, { range: [n, s], value: r }) => {
298
- const o = (b, y) => t.slice(0, b) + t.slice(y), i = te(t[n - 1]), l = te(t[s]), c = s === t.length;
297
+ }), se = (e) => Ze.flatMap((t) => X(e, t)).sort((t, n) => t.range[0] - n.range[0]).reverse().reduce((t, { range: [n, o], value: s }) => {
298
+ const r = (b, y) => t.slice(0, b) + t.slice(y), i = ne(t[n - 1]), l = ne(t[o]), c = o === t.length;
299
299
  let a = n;
300
300
  for (; a > 0 && t[a - 1] !== `
301
301
  `; ) a--;
302
- let u = s;
303
- for (; u < t.length && t[u] !== `
304
- `; ) u++;
305
- const p = t.slice(a, n).trim() === "" && t.slice(s, u).trim() === "";
306
- return i.isNewline && l.isNewline ? o(n - (c ? 1 : 0), s + 1) : i.isNewline || p ? o(a, s + (l.isSpace || l.isNewline ? 1 : 0)) : o(n - (i.isSpace ? 1 : 0), s);
307
- }, e), Je = [
302
+ let m = o;
303
+ for (; m < t.length && t[m] !== `
304
+ `; ) m++;
305
+ const p = t.slice(a, n).trim() === "" && t.slice(o, m).trim() === "";
306
+ return i.isNewline && l.isNewline ? r(n - (c ? 1 : 0), o + 1) : i.isNewline || p ? r(a, o + (l.isSpace || l.isNewline ? 1 : 0)) : r(n - (i.isSpace ? 1 : 0), o);
307
+ }, e), Ke = [
308
+ /**
309
+ * Include all content between comments that INCLUDE the specified ids.
310
+ *
311
+ * This is similar to `extract`, but instead of removing all other content, it appends the specified regions.
312
+ *
313
+ * @param id The id of the comment to include.
314
+ * @param 0 An optional additional id to include.
315
+ * @param 1 An optional additional id to include.
316
+ * @param 2 An optional additional id to include.
317
+ * @param 3 An optional additional id to include.
318
+ * @param 4 An optional additional id to include.
319
+ * @param 5 An optional additional id to include.
320
+ * @param 6 An optional additional id to include.
321
+ * @param 7 An optional additional id to include.
322
+ * @param 8 An optional additional id to include.
323
+ * @param 9 An optional additional id to include.
324
+ * @param 10 An optional additional id to include.
325
+ * @example [](<url>?region=include(specifier))
326
+ * @example [](<url>?region=include(specifier,other-specifier,some-other-specifier))
327
+ */
328
+ "include(id: string, 0?: string, 1?: string, 2?: string, 3?: string, 4?: string, 5?: string, 6?: string, 7?: string, 8?: string, 9?: string, 10?: string)",
308
329
  /**
309
330
  * Extract regions from the retrieved content between comments that INCLUDE the specified ids.
331
+ *
332
+ * NOTE: This method is deprecated in favor of `include`, which has more intuitive behavior.
333
+ * `extract` effectively behaves destructively, removing all content outside of the specified regions,
334
+ * thus you can't chain multiple `extract` calls to build up content from different regions
335
+ * (like you can with `include`).
336
+ *
337
+ * @deprecated Use `include` instead (usage is more intuitive).
310
338
  * @param id The id of the comment to extract.
311
- * @param 0 An optional additional id to extract.
312
- * @param 1 An optional additional id to extract.
313
- * @param 2 An optional additional id to extract.
339
+ * @param 0 An optional additional id to include.
340
+ * @param 1 An optional additional id to include.
341
+ * @param 2 An optional additional id to include.
342
+ * @param 3 An optional additional id to include.
343
+ * @param 4 An optional additional id to include.
344
+ * @param 5 An optional additional id to include.
345
+ * @param 6 An optional additional id to include.
346
+ * @param 7 An optional additional id to include.
347
+ * @param 8 An optional additional id to include.
348
+ * @param 9 An optional additional id to include.
349
+ * @param 10 An optional additional id to include.
314
350
  * @example [](<url>?region=extract(specifier))
315
351
  * @example [](<url>?region=extract(specifier,other-specifier,some-other-specifier))
316
352
  */
@@ -388,7 +424,7 @@ const I = (e) => {
388
424
  * Specifying undefined or a number less than 0 indicates the action should be taken at the beginning of the comment boundary (i.e to the left of the comment).
389
425
  * @param insert The content to insert.
390
426
  * @param space The space character to use between words in the content to insert (defaults to `-`).
391
- *
427
+ *
392
428
  * **NOTE:** Content within comments will not be acted upon.
393
429
  */
394
430
  "splice-start(id: string, deleteCount?: number, insert?: string, space?: string)",
@@ -400,155 +436,219 @@ const I = (e) => {
400
436
  * Specifying undefined or a number less than 0 indicates the action should be taken at the beginning of the comment boundary (i.e to the left of the comment).
401
437
  * @param insert The content to insert.
402
438
  * @param space The space character to use between words in the content to insert (defaults to `-`).
403
- *
439
+ *
404
440
  * **NOTE:** Content within comments will not be acted upon.
405
441
  */
406
442
  "splice-end(id: string, deleteCount?: number, insert?: string, space?: string)",
407
443
  /**
408
- * If included at the end of a query, parkdown comments will not be removed from the content after processing.
444
+ * If included at the end of a query, parkdown comments will not be removed from the content after processing.
409
445
  * Helpful when trying to determine fine-grained edits (e.g. trimming, splicing, etc.).
410
446
  */
411
447
  "debug()"
412
- ], Ze = O(Je), $ = (e, t, n) => {
413
- const s = X(e, t, n), r = [];
414
- for (let o = 0; o < s.length - 1; o += 2)
415
- r.push([s[o], s[o + 1]]);
416
- return r;
417
- }, Ke = (e, t, n) => new d(...X(e, t, n).map(({ range: s }) => s)), P = (e) => Te(e).trim(), se = (e, t) => e[t] !== void 0 && /[^\S\r\n]/.test(e[t]), re = (e, t) => Math.max(0, Math.min(e.length, t)), Ye = (e, ...t) => {
448
+ ], Ye = R(Ke), $ = (e, t, n) => {
449
+ const o = X(e, t, n), s = [];
450
+ for (let r = 0; r < o.length - 1; r += 2)
451
+ s.push([o[r], o[r + 1]]);
452
+ return s;
453
+ }, et = (e, t, n) => new u(
454
+ ...X(e, t, n).map(
455
+ ({ range: o }) => o
456
+ )
457
+ ), j = (e) => Oe(e).trim(), oe = (e, t) => e[t] !== void 0 && /[^\S\r\n]/.test(e[t]), re = (e, t) => Math.max(0, Math.min(e.length, t)), ie = (e, ...t) => {
418
458
  if (t.length === 0) return e;
419
- const n = I(e);
420
- return P(
421
- new d(...t.flatMap(
422
- (s) => $(e, s, n).map(([{ range: [r] }, { range: [, o] }]) => {
423
- for (; se(e, r); ) r--;
424
- for (; se(e, o); ) o++;
425
- return [re(e, r), re(e, o)];
426
- })
427
- )).slice(e)
459
+ const n = P(e);
460
+ return j(
461
+ new u(
462
+ ...t.flatMap(
463
+ (o) => $(e, o, n).map(
464
+ ([
465
+ {
466
+ range: [s]
467
+ },
468
+ {
469
+ range: [, r]
470
+ }
471
+ ]) => {
472
+ for (; oe(e, s); ) s--;
473
+ for (; oe(e, r); ) r++;
474
+ return [re(e, s), re(e, r)];
475
+ }
476
+ )
477
+ )
478
+ ).slice(e)
428
479
  );
429
- }, et = (e, ...t) => {
480
+ }, tt = (e, ...t) => {
430
481
  if (t.length === 0) return e;
431
- const n = I(e);
432
- return P(
433
- new d([0, e.length]).subtract(
434
- new d(...t.flatMap(
435
- (s) => $(e, s, n).map(([{ range: [, r] }, { range: [o] }]) => [r, o])
436
- ))
482
+ const n = P(e);
483
+ return j(
484
+ new u([0, e.length]).subtract(
485
+ new u(
486
+ ...t.flatMap(
487
+ (o) => $(e, o, n).map(
488
+ ([
489
+ {
490
+ range: [, s]
491
+ },
492
+ {
493
+ range: [r]
494
+ }
495
+ ]) => [s, r]
496
+ )
497
+ )
498
+ )
437
499
  ).slice(e)
438
500
  );
439
- }, tt = (e, t, n, s) => {
501
+ }, nt = (e, t, n, o) => {
440
502
  if (!t) return e;
441
- let r = "", o = 0;
503
+ let s = "", r = 0;
442
504
  for (const [i, l] of $(e, t))
443
- r += e.slice(o, i.range[1]), r += W(n ?? i.value, s), o = l.range[0];
444
- return r += e.slice(o), P(
445
- new d([0, r.length]).subtract(Ke(r, t)).slice(r)
505
+ s += e.slice(r, i.range[1]), s += I(n ?? i.value, o), r = l.range[0];
506
+ return s += e.slice(r), j(
507
+ new u([0, s.length]).subtract(et(s, t)).slice(s)
446
508
  );
447
- }, nt = (e, t, n, s, r, o) => {
509
+ }, st = (e, t, n, o, s, r) => {
448
510
  if (!t) return e;
449
- const i = !(s === void 0 || s < 0), l = r ? W(r, o) : "", c = s ?? 0, a = I(e), u = new d(...a.map(({ range: p }) => p));
450
- return $(e, t, a).map((p) => p[n === "start" ? 0 : 1]).sort(ue).reverse().reduce((p, { range: b }) => {
451
- const y = new d(), k = i ? 1 : -1;
452
- let S = Math.abs(c), m = i ? b[1] : b[0];
453
- for (; S > 0 && m < p.length && m >= 0; )
454
- u.test(m) || (y.push(m), S--), m += k;
455
- 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(y.offset(i ? 0 : l.length)).slice(p);
511
+ const i = !(o === void 0 || o < 0), l = s ? I(s, r) : "", c = o ?? 0, a = P(e), m = new u(...a.map(({ range: p }) => p));
512
+ return $(e, t, a).map((p) => p[n === "start" ? 0 : 1]).sort(he).reverse().reduce((p, { range: b }) => {
513
+ const y = new u(), N = i ? 1 : -1;
514
+ let S = Math.abs(c), g = i ? b[1] : b[0];
515
+ for (; S > 0 && g < p.length && g >= 0; )
516
+ m.test(g) || (y.push(g), S--), g += N;
517
+ return g = Math.min(Math.max(0, g), p.length), p = p.slice(0, g) + l + p.slice(g), new u([0, p.length]).subtract(y.offset(i ? 0 : l.length)).slice(p);
456
518
  }, e);
457
- }, st = (e, t, n, s, r) => {
458
- let o = "", i = 0;
459
- [n, s] = [n, s ?? ""].map((c) => W(c, r));
460
- const l = t ? $(e, t) : [[{ range: [0, 0] }, { range: [e.length, e.length] }]];
519
+ }, ot = (e, t, n, o, s) => {
520
+ let r = "", i = 0;
521
+ [n, o] = [n, o ?? ""].map((c) => I(c, s));
522
+ const l = t ? $(e, t) : [
523
+ [{ range: [0, 0] }, { range: [e.length, e.length] }]
524
+ ];
461
525
  for (const [c, a] of l)
462
- o += e.slice(i, c.range[1]), o += e.slice(c.range[1], a.range[0]).replaceAll(n, s), i = a.range[0];
463
- return o += e.slice(i), o;
526
+ r += e.slice(i, c.range[1]), r += e.slice(c.range[1], a.range[0]).replaceAll(n, o), i = a.range[0];
527
+ return r += e.slice(i), r;
464
528
  }, rt = (e, t) => {
465
529
  if (!t) return e;
466
- let n = "", s = 0;
467
- for (const [r, o] of $(e, t))
468
- n += e.slice(s, r.range[1]), n += e.slice(r.range[1], o.range[0]).replaceAll(/[\s\n]+/g, " "), s = o.range[0];
469
- return n += e.slice(s), n;
470
- }, oe = (e, t, n) => {
471
- var o, i, l, c;
530
+ let n = "", o = 0;
531
+ for (const [s, r] of $(e, t))
532
+ n += e.slice(o, s.range[1]), n += e.slice(s.range[1], r.range[0]).replaceAll(/[\s\n]+/g, " "), o = r.range[0];
533
+ return n += e.slice(o), n;
534
+ }, le = (e, t, n) => {
535
+ var r, i, l, c;
472
536
  if (!t) return e;
473
- const s = (a) => /\s/.test(e[a]), r = new d();
474
- for (const [a, u] of $(e, t)) {
475
- if ((o = n.start) != null && o.left) {
537
+ const o = (a) => /\s/.test(e[a]), s = new u();
538
+ for (const [a, m] of $(e, t)) {
539
+ if ((r = n.start) != null && r.left) {
476
540
  let p = a.range[0] - 1;
477
- for (; s(p); ) r.push(p--);
541
+ for (; o(p); ) s.push(p--);
478
542
  }
479
543
  if ((i = n.start) != null && i.right) {
480
544
  let p = a.range[1];
481
- for (; s(p); ) r.push(p++);
545
+ for (; o(p); ) s.push(p++);
482
546
  }
483
547
  if ((l = n.end) != null && l.left) {
484
- let p = u.range[0] - 1;
485
- for (; s(p); ) r.push(p--);
548
+ let p = m.range[0] - 1;
549
+ for (; o(p); ) s.push(p--);
486
550
  }
487
551
  if ((c = n.end) != null && c.right) {
488
- let p = u.range[1];
489
- for (; s(p); ) r.push(p++);
552
+ let p = m.range[1];
553
+ for (; o(p); ) s.push(p++);
490
554
  }
491
555
  }
492
- return new d([0, e.length]).subtract(r).slice(e);
493
- }, ot = (e, t, n) => {
494
- if (!t) return ne(e);
495
- const s = Ze(t);
556
+ return new u([0, e.length]).subtract(s).slice(e);
557
+ }, it = (e, t, n, o) => {
558
+ if (!n) return se(e);
559
+ const s = Ye(n);
496
560
  switch (s.name) {
561
+ case "include":
562
+ for (const r of [s.id, ...T(s)])
563
+ e += ie(t, r);
564
+ break;
497
565
  case "extract":
498
- e = Ye(e, s.id, ...F(s));
566
+ e = ie(
567
+ e || t,
568
+ s.id,
569
+ ...T(s)
570
+ );
499
571
  break;
500
572
  case "remove":
501
- e = et(e, s.id, ...F(s));
573
+ e = tt(
574
+ e,
575
+ s.id,
576
+ ...T(s)
577
+ );
502
578
  break;
503
579
  case "replace":
504
- e = tt(e, s.id, s.with, s.space);
580
+ e = nt(
581
+ e,
582
+ s.id,
583
+ s.with,
584
+ s.space
585
+ );
505
586
  break;
506
587
  case "splice-start":
507
588
  case "splice-end": {
508
- const { deleteCount: r, insert: o, space: i, id: l } = s, c = s.name === "splice-start" ? "start" : "end";
509
- e = nt(e, l, c, r, o, i);
589
+ const { deleteCount: r, insert: i, space: l, id: c } = s, a = s.name === "splice-start" ? "start" : "end";
590
+ e = st(
591
+ e,
592
+ c,
593
+ a,
594
+ r,
595
+ i,
596
+ l
597
+ );
510
598
  break;
511
599
  }
512
600
  case "trim-start":
513
601
  case "trim-end": {
514
602
  s.left ?? (s.left = !0), s.right ?? (s.right = !0);
515
- const r = s.name === "trim-start" ? "start" : "end", { length: o } = e;
516
- e = oe(e, s.id, { [r]: s }), console.log(`Trimmed ${o - e.length} characters from ${r} of "${s.id}" region`);
603
+ const r = s.name === "trim-start" ? "start" : "end", { length: i } = e;
604
+ e = le(e, s.id, {
605
+ [r]: s
606
+ }), console.log(
607
+ `Trimmed ${i - e.length} characters from ${r} of "${s.id}" region`
608
+ );
517
609
  break;
518
610
  }
519
611
  case "trim": {
520
- const { inside: r, outside: o, id: i } = s, l = { left: o ?? !0, right: r ?? !0 }, c = { left: r ?? !0, right: o ?? !0 }, { length: a } = e;
521
- e = oe(e, i, { start: l, end: c }), console.log(`Trimmed ${a - e.length} characters around "${s.id}" region`);
612
+ const { inside: r, outside: i, id: l } = s, c = { left: i ?? !0, right: r ?? !0 }, a = { left: r ?? !0, right: i ?? !0 }, { length: m } = e;
613
+ e = le(e, l, { start: c, end: a }), console.log(
614
+ `Trimmed ${m - e.length} characters around "${s.id}" region`
615
+ );
522
616
  break;
523
617
  }
524
618
  case "single-line":
525
619
  e = rt(e, s.id);
526
620
  break;
527
621
  case "remap":
528
- e = st(e, s.id, s.from, s.to, s.space);
622
+ e = ot(
623
+ e,
624
+ s.id,
625
+ s.from,
626
+ s.to,
627
+ s.space
628
+ );
529
629
  break;
530
630
  }
531
- return s.name === "debug" && console.log("debug!!!", s), e = n && s.name !== "debug" ? ne(e) : e, n ? P(e) : e;
532
- }, it = [
631
+ return s.name === "debug" && console.log("debug!!!", s), e = o && s.name !== "debug" ? se(e) : e, o ? j(e) : e;
632
+ }, lt = [
533
633
  "recipe(id: string)"
534
- ], lt = [
634
+ ], at = [
535
635
  "recipe(id: string, 0?: string, 1?: string, 2?: string)"
536
- ], ie = {
537
- register: O(it),
538
- apply: O(lt)
539
- }, N = class N {
636
+ ], ae = {
637
+ register: R(lt),
638
+ apply: R(at)
639
+ }, k = class k {
540
640
  constructor() {
541
641
  _(this, "recipes", /* @__PURE__ */ new Map());
542
642
  }
543
643
  tryStore(t) {
544
- const n = N.Entries(this.apply(t));
545
- for (let s = 0; s < n.length; s++) {
546
- const [r, o] = n[s];
547
- if (r !== "register") continue;
548
- const i = ie.register(o);
644
+ const n = k.Entries(this.apply(t));
645
+ for (let o = 0; o < n.length; o++) {
646
+ const [s, r] = n[o];
647
+ if (s !== "register") continue;
648
+ const i = ae.register(r);
549
649
  switch (i.name) {
550
650
  case "recipe":
551
- const l = n.slice(s + 1).filter(([c]) => c !== "register").map(([c, a]) => `${c}=${a}`).join("&");
651
+ const l = n.slice(o + 1).filter(([c]) => c !== "register").map(([c, a]) => `${c}=${a}`).join("&");
552
652
  this.recipes.set(i.id, l);
553
653
  break;
554
654
  default:
@@ -557,137 +657,190 @@ const I = (e) => {
557
657
  }
558
658
  }
559
659
  apply(t) {
560
- const n = N.Entries(t), s = [];
561
- for (let r = 0; r < n.length; r++) {
562
- const [o, i] = n[r];
563
- if (o !== "apply") {
564
- s.push(`${o}=${i}`);
660
+ const n = k.Entries(t), o = [];
661
+ for (let s = 0; s < n.length; s++) {
662
+ const [r, i] = n[s];
663
+ if (r !== "apply") {
664
+ o.push(`${r}=${i}`);
565
665
  continue;
566
666
  }
567
- const l = ie.apply(i);
667
+ const l = ae.apply(i);
568
668
  switch (l.name) {
569
669
  case "recipe":
570
- s.push(this.recipes.get(l.id)), s.push(...F(l).map((c) => this.recipes.get(c)));
670
+ o.push(this.recipes.get(l.id)), o.push(...T(l).map((c) => this.recipes.get(c)));
571
671
  break;
572
672
  default:
573
673
  throw new Error(`Unknown registration: ${l.name}`);
574
674
  }
575
675
  }
576
- return s.join("&");
676
+ return o.join("&");
577
677
  }
578
678
  };
579
- _(N, "Entries", (t) => Array.from(new URLSearchParams(t).entries()));
580
- let H = N;
581
- const at = ["http", "./", "../", "?"], ct = ({ url: e }) => at.some((t) => e.startsWith(t)), pt = (e) => G(e) && Oe(e) && ct(e), me = ({ url: e }, t) => `[](${t ? T(t, e) : e})`, g = {
679
+ _(k, "Entries", (t) => Array.from(new URLSearchParams(t).entries()));
680
+ let H = k;
681
+ const ct = ["http", "./", "../", "?"], pt = ({ url: e }) => ct.some((t) => e.startsWith(t)), mt = (e) => G(e) && We(e) && pt(e), ue = ({ url: e }, t) => `[](${t ? A(t, e) : e})`, h = {
582
682
  _open: "<!--",
583
683
  _close: "-->",
584
684
  _flag: "p↓",
585
685
  get begin() {
586
- return M(g._open, g._flag, "BEGIN", g._close);
686
+ return M(
687
+ h._open,
688
+ h._flag,
689
+ "BEGIN",
690
+ h._close
691
+ );
587
692
  },
588
693
  get end() {
589
- return M(g._open, g._flag, "END", g._close);
694
+ return M(
695
+ h._open,
696
+ h._flag,
697
+ "END",
698
+ h._close
699
+ );
590
700
  },
591
701
  lengthOf(e) {
592
702
  const t = `lines: ${e.split(`
593
703
  `).length}`, n = `chars: ${e.length}`;
594
- return M(g._open, g._flag, "length", t, n, g._close);
704
+ return M(
705
+ h._open,
706
+ h._flag,
707
+ "length",
708
+ t,
709
+ n,
710
+ h._close
711
+ );
595
712
  }
596
- }, le = (e) => (t) => G(t) && t.value === g[e], ut = ({ position: e, url: t, siblingCount: n }, s) => ({ position: e, url: t, headingDepth: s, inline: n >= 1 }), mt = ({ position: { start: e }, url: t, siblingCount: n }, { position: { end: s } }, r) => ({ position: { start: e, end: s }, url: t, headingDepth: r, inline: n >= 1 }), gt = (e, t, n) => (e.inline ? M : We)(
597
- me(e, n),
598
- g.begin,
599
- g.lengthOf(t),
713
+ }, ce = (e) => (t) => G(t) && t.value === h[e], gt = ({ position: e, url: t, siblingCount: n }, o) => ({
714
+ position: e,
715
+ url: t,
716
+ headingDepth: o,
717
+ inline: n >= 1
718
+ }), ht = ({ position: { start: e }, url: t, siblingCount: n }, { position: { end: o } }, s) => ({
719
+ position: { start: e, end: o },
720
+ url: t,
721
+ headingDepth: s,
722
+ inline: n >= 1
723
+ }), ut = (e, t, n) => (e.inline ? M : Pe)(
724
+ ue(e, n),
725
+ h.begin,
726
+ h.lengthOf(t),
600
727
  t,
601
- g.end
602
- ), ht = (e) => {
603
- const t = A(e, "heading").reduce((n, { position: s, depth: r }) => n.set(s.start.line, r), /* @__PURE__ */ new Map());
728
+ h.end
729
+ ), dt = (e) => {
730
+ const t = O(e, "heading").reduce(
731
+ (n, { position: o, depth: s }) => n.set(o.start.line, s),
732
+ /* @__PURE__ */ new Map()
733
+ );
604
734
  return (n) => {
605
- for (let s = n.position.start.line; s >= 1; s--) {
606
- const r = t.get(s);
607
- if (r) return r;
735
+ for (let o = n.position.start.line; o >= 1; o--) {
736
+ const s = t.get(o);
737
+ if (s) return s;
608
738
  }
609
739
  return 0;
610
740
  };
611
- }, R = {
612
- openingCommentDoesNotFollowLink: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),
613
- closingCommentNotMatchedToOpening: ({ position: { start: e } }) => new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),
614
- openingCommentNotClosed: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)
615
- }, dt = (e, t) => {
616
- const n = [], s = [
617
- ...e.map((o) => ({ node: o, type: "open" })),
618
- ...t.map((o) => ({ node: o, type: "close" }))
619
- ].sort((o, i) => f(o.node, i.node)), r = [];
620
- for (const o of s)
621
- if (o.type === "open") r.push(o);
741
+ }, W = {
742
+ openingCommentDoesNotFollowLink: ({
743
+ position: { start: e }
744
+ }) => new Error(
745
+ `Opening comment (@${e.line}:${e.column}) does not follow link`
746
+ ),
747
+ closingCommentNotMatchedToOpening: ({
748
+ position: { start: e }
749
+ }) => new Error(
750
+ `Closing comment (@${e.line}:${e.column}) does not match to opening comment`
751
+ ),
752
+ openingCommentNotClosed: ({ position: { start: e } }) => new Error(
753
+ `Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`
754
+ )
755
+ }, ft = (e, t) => {
756
+ const n = [], o = [
757
+ ...e.map((r) => ({ node: r, type: "open" })),
758
+ ...t.map((r) => ({ node: r, type: "close" }))
759
+ ].sort((r, i) => d(r.node, i.node)), s = [];
760
+ for (const r of o)
761
+ if (r.type === "open") s.push(r);
622
762
  else {
623
- const i = o.node;
624
- if (r.length === 0)
625
- throw R.closingCommentNotMatchedToOpening(i);
626
- const l = r.pop().node;
627
- if (r.length > 0) continue;
763
+ const i = r.node;
764
+ if (s.length === 0)
765
+ throw W.closingCommentNotMatchedToOpening(i);
766
+ const l = s.pop().node;
767
+ if (s.length > 0) continue;
628
768
  n.push({ open: l, close: i });
629
769
  }
630
- if (r.length > 0)
631
- throw R.openingCommentNotClosed(r[0].node);
770
+ if (s.length > 0) throw W.openingCommentNotClosed(s[0].node);
632
771
  return n;
633
- }, ft = (e, t, n) => {
634
- const s = [...t].sort(f), r = [];
635
- return [...n].sort((o, i) => f.reverse(o.open, i.open)).forEach((o) => {
636
- for (; s.length > 0; ) {
637
- const i = s.pop();
638
- if (i.position.start.offset < o.open.position.start.offset) {
639
- if (Re(e, i, o.open).trim() !== "")
640
- throw R.openingCommentDoesNotFollowLink(o.open);
641
- return r.push([i, o]);
772
+ }, vt = (e, t, n) => {
773
+ const o = [...t].sort(d), s = [];
774
+ return [...n].sort((r, i) => d.reverse(r.open, i.open)).forEach((r) => {
775
+ for (; o.length > 0; ) {
776
+ const i = o.pop();
777
+ if (i.position.start.offset < r.open.position.start.offset) {
778
+ if (Ie(e, i, r.open).trim() !== "")
779
+ throw W.openingCommentDoesNotFollowLink(r.open);
780
+ return s.push([i, r]);
642
781
  }
643
- r.push(i);
782
+ s.push(i);
644
783
  }
645
- throw R.openingCommentDoesNotFollowLink(o.open);
646
- }), r.push(...s.reverse()), r.reverse();
647
- }, ge = (e, t) => {
784
+ throw W.openingCommentDoesNotFollowLink(r.open);
785
+ }), s.push(...o.reverse()), s.reverse();
786
+ }, de = (e, t) => {
648
787
  t ?? (t = z.md(e));
649
- const n = ht(t), s = A(t, "link").filter(pt), r = A(t, "html").sort(f), o = r.filter(le("begin")), i = r.filter(le("end")), l = dt(o, i);
650
- return ft(e, s, l).map((a) => Array.isArray(a) ? mt(a[0], a[1].close, n(a[0])) : ut(a, n(a)));
651
- }, vt = (e, { url: t }) => (n) => e(T(Q(t), n)), he = (...e) => {
652
- const t = e.reduce((n, s) => n + s, 0);
788
+ const n = dt(t), o = O(t, "link").filter(mt), s = O(t, "html").sort(d), r = s.filter(ce("begin")), i = s.filter(ce("end")), l = ft(r, i);
789
+ return vt(e, o, l).map(
790
+ (a) => Array.isArray(a) ? ht(a[0], a[1].close, n(a[0])) : gt(a, n(a))
791
+ );
792
+ }, wt = (e, { url: t }) => ((n) => e(
793
+ A(Q(t), n)
794
+ )), fe = (...e) => {
795
+ const t = e.reduce((n, o) => n + o, 0);
653
796
  return Math.min(Math.max(t, 1), 6);
654
- }, wt = (e, t, n) => {
797
+ }, $t = (e, t, n) => {
655
798
  if (t === 0) return e;
656
799
  n ?? (n = z.md(e));
657
- const s = A(n, "heading"), r = e.split(`
800
+ const o = O(n, "heading"), s = e.split(`
658
801
  `);
659
- for (const o of s) {
660
- const { depth: i, position: { start: l, end: c } } = o, a = he(i, t), u = r[l.line - 1].slice(i, c.column), p = "#".repeat(a) + u;
661
- r[l.line - 1] = p, o.depth = a;
802
+ for (const r of o) {
803
+ const {
804
+ depth: i,
805
+ position: { start: l, end: c }
806
+ } = r, a = fe(i, t), m = s[l.line - 1].slice(i, c.column), p = "#".repeat(a) + m;
807
+ s[l.line - 1] = p, r.depth = a;
662
808
  }
663
- return r.join(`
809
+ return s.join(`
664
810
  `);
665
- }, de = (e) => ge(e).reverse().sort(f.reverse).reduce((t, n) => pe(t, me(n), n), e), fe = (e, t, n, s, r) => {
811
+ }, ve = (e) => de(e).reverse().sort(d.reverse).reduce(
812
+ (t, n) => ge(t, ue(n), n),
813
+ e
814
+ ), we = (e, t, n, o, s) => {
666
815
  try {
667
- e = de(e), e = wt(e, t);
668
- const o = z.md(e), i = new H(), l = ge(e, o).sort(f);
816
+ e = ve(e), e = $t(e, t);
817
+ const r = z.md(e), i = new H(), l = de(e, r).sort(d);
669
818
  return l.filter(({ url: c }) => c.startsWith("?")).forEach(({ url: c }) => i.tryStore(c)), l.reverse().map((c) => {
670
- var k, S;
671
- const { url: a, headingDepth: u } = c, [p, ...b] = xe(a).split("?"), y = i.apply(b.join("?"));
819
+ var N, S;
820
+ const { url: a, headingDepth: m } = c, [p, ...b] = ke(a).split("?"), y = i.apply(b.join("?"));
672
821
  if (!a.startsWith("?"))
673
822
  if (a.startsWith("./") || a.startsWith("../")) {
674
- const m = p.split(".").pop() ?? "", j = Q(a), V = T(j, p);
675
- let h = n(V);
676
- const x = new _e(y), D = (k = ((w) => {
677
- const v = Array.from(x.entries()).filter(([C]) => C === w).map(([C, q]) => q);
823
+ const g = p.split(".").pop() ?? "", D = Q(a), V = A(D, p), J = n(V), x = new Ne(y), L = (N = ((w) => {
824
+ const v = Array.from(x.entries()).filter(([C]) => C === w).map(([C, B]) => B);
678
825
  return v.length >= 1 ? v.join(",") : void 0;
679
- })("region")) == null ? void 0 : k.split(J);
680
- h = (D == null ? void 0 : D.reduce(
681
- (w, v, C, { length: q }) => ot(w, v, C === q - 1),
682
- h
683
- )) ?? h;
684
- const $e = x.has("skip"), be = x.get("heading") ?? 0, ye = x.has("inline");
685
- let { inline: L } = c;
686
- if (ye && (L = !0), !$e)
687
- if (m === "md") {
688
- const w = vt(n, c), v = r ? T(r, j) : j, C = he(u, Number(be));
689
- h = fe(
690
- h,
826
+ })("region")) == null ? void 0 : N.split(Z);
827
+ let f = (L == null ? void 0 : L.reduce(
828
+ (w, v, C, { length: B }) => it(w, J, v, C === B - 1),
829
+ ""
830
+ )) ?? J;
831
+ const ye = x.has("skip"), Ce = x.get("heading") ?? 0, Ee = x.has("inline");
832
+ let { inline: U } = c;
833
+ if (Ee && (U = !0), !ye)
834
+ if (g === "md") {
835
+ const w = wt(
836
+ n,
837
+ c
838
+ ), v = s ? A(s, D) : D, C = fe(
839
+ m,
840
+ Number(Ce)
841
+ );
842
+ f = we(
843
+ f,
691
844
  /** p↓: ... */
692
845
  C,
693
846
  w,
@@ -695,38 +848,49 @@ const at = ["http", "./", "../", "?"], ct = ({ url: e }) => at.some((t) => e.sta
695
848
  v
696
849
  /** p↓: ... */
697
850
  );
698
- } else /^(js|ts)x?|svelte$/i.test(m) && (h = ee(
699
- h,
851
+ } else /^(js|ts)x?|svelte$/i.test(g) && (f = te(
852
+ f,
700
853
  "code",
701
854
  /** p↓: ... */
702
- { extension: m, inline: L }
855
+ { extension: g, inline: U }
703
856
  /** p↓: ... */
704
857
  ));
705
- const U = (S = x.get("wrap")) == null ? void 0 : S.split(J);
706
- return h = (U == null ? void 0 : U.reduce((w, v) => ee(w, v, { extension: m, inline: L }), h)) ?? h, { target: c, content: gt(c, h, r) };
858
+ const q = (S = x.get("wrap")) == null ? void 0 : S.split(Z);
859
+ return f = (q == null ? void 0 : q.reduce(
860
+ (w, v) => te(w, v, { extension: g, inline: U }),
861
+ f
862
+ )) ?? f, {
863
+ target: c,
864
+ content: ut(c, f, s)
865
+ };
707
866
  } else throw a.startsWith("http") ? new Error("External web links are not implemented yet") : new Error(`Unsupported link type: ${a}`);
708
- }).filter(Boolean).reduce((c, { target: a, content: u }) => pe(c, u, a), e);
709
- } catch (o) {
710
- throw new Error(`Error populating inclusions in file ${s ?? "(unknown)"}: ${o}`);
867
+ }).filter(Boolean).reduce(
868
+ (c, { target: a, content: m }) => ge(c, m, a),
869
+ e
870
+ );
871
+ } catch (r) {
872
+ throw new Error(
873
+ `Error populating inclusions in file ${o ?? "(unknown)"}: ${r}`
874
+ );
711
875
  }
712
- }, ve = (e) => Se(e, "utf-8"), we = (e) => {
713
- const t = ce(e), n = Q(t);
714
- return { content: ve(t), dir: n, path: t };
715
- }, $t = (e, t = !0, n) => {
716
- const { dir: s, path: r, content: o } = we(e);
717
- n == null || n.unwatch(r), n == null || n.once("change", (c, a) => {
718
- console.log(`Change detected in "${c}". Regenerating "${r}"...`), $t(e, t, n);
876
+ }, $e = (e) => _e(e, "utf-8"), be = (e) => {
877
+ const t = me(e), n = Q(t);
878
+ return { content: $e(t), dir: n, path: t };
879
+ }, bt = (e, t = !0, n) => {
880
+ const { dir: o, path: s, content: r } = be(e);
881
+ n == null || n.unwatch(s), n == null || n.once("change", (c, a) => {
882
+ console.log(`Change detected in "${c}". Regenerating "${s}"...`), bt(e, t, n);
719
883
  });
720
- const l = fe(o, 0, (c) => {
721
- const a = ce(s, Pe(c));
722
- return n == null || n.add(a), ve(a);
723
- }, r);
724
- return t && ae(r, l), n == null || n.add(r), l;
725
- }, Mt = (e, t = !0, n) => {
726
- const { path: s, content: r } = we(e), o = de(r);
727
- return t && ae(s, o), o;
884
+ const l = we(r, 0, (c) => {
885
+ const a = me(o, De(c));
886
+ return n == null || n.add(a), $e(a);
887
+ }, s);
888
+ return t && pe(s, l), n == null || n.add(s), l;
889
+ }, Tt = (e, t = !0, n) => {
890
+ const { path: o, content: s } = be(e), r = ve(s);
891
+ return t && pe(o, r), r;
728
892
  };
729
893
  export {
730
- Mt as depopulateMarkdownInclusions,
731
- $t as populateMarkdownInclusions
894
+ Tt as depopulateMarkdownInclusions,
895
+ bt as populateMarkdownInclusions
732
896
  };