@p-buddy/parkdown 0.0.27 → 0.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -33
- package/dist/cli.js +1 -1
- package/dist/index.js +493 -328
- package/dist/index.umd.cjs +13 -13
- package/package.json +53 -50
- package/src/cli.ts +33 -0
- package/src/index.ts +45 -0
package/dist/index.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var _ = (e, t, n) =>
|
|
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 G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0,
|
|
14
|
-
md: (e) =>
|
|
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
15
|
}, O = (e, t) => {
|
|
16
16
|
const n = [];
|
|
17
|
-
return
|
|
18
|
-
if (
|
|
19
|
-
if (t &&
|
|
20
|
-
if (G(
|
|
21
|
-
const i = ((
|
|
22
|
-
n.push({ ...
|
|
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
|
-
},
|
|
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(
|
|
29
|
-
const
|
|
30
|
-
return e.slice(0,
|
|
31
|
-
},
|
|
32
|
-
const
|
|
33
|
-
return e.slice(
|
|
34
|
-
}, M = (...e) => e.join(" "),
|
|
35
|
-
`),
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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(
|
|
75
|
-
...Object.entries(
|
|
74
|
+
...Object.entries(K.unsafe),
|
|
75
|
+
...Object.entries(K.reserved)
|
|
76
76
|
]
|
|
77
|
-
},
|
|
78
|
-
const n =
|
|
79
|
-
return
|
|
80
|
-
},
|
|
81
|
-
const t = e.match(
|
|
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,
|
|
84
|
-
if (!
|
|
85
|
-
const
|
|
86
|
-
return { name: n, parameters:
|
|
87
|
-
},
|
|
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
|
-
},
|
|
91
|
+
}, Qe = (e) => {
|
|
92
92
|
const t = [];
|
|
93
|
-
let n = "",
|
|
94
|
-
for (let
|
|
95
|
-
const
|
|
96
|
-
if (i && e.at(
|
|
97
|
-
const l = e.at(
|
|
98
|
-
|
|
99
|
-
} else i ? (
|
|
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((
|
|
102
|
-
},
|
|
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
|
-
},
|
|
105
|
+
}, ze = (e) => {
|
|
106
106
|
const t = /^([\w-_]+)(?:\(([^)]*)\))?/, n = e.match(t);
|
|
107
107
|
if (!n) return { name: e };
|
|
108
|
-
const [,
|
|
109
|
-
if (!
|
|
110
|
-
const
|
|
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 =
|
|
113
|
-
const [, c, a,
|
|
114
|
-
if (!
|
|
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:
|
|
117
|
+
return { name: o, parameters: i };
|
|
118
118
|
}, R = (e) => {
|
|
119
|
-
const t = e.map(
|
|
120
|
-
(n, { name:
|
|
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:
|
|
125
|
-
if (!t.has(
|
|
126
|
-
throw new Error(`Unknown method: ${
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
129
|
-
return { name:
|
|
130
|
-
if (
|
|
131
|
-
const i =
|
|
132
|
-
throw new Error(`Too many parameters: ${
|
|
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
|
|
135
|
-
const p =
|
|
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 '${
|
|
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 '${
|
|
150
|
+
throw new Error(`Invalid type: ${l} must be ${a}, got ${typeof i[l]} for method '${o}'`);
|
|
151
151
|
return i;
|
|
152
|
-
}, { name:
|
|
152
|
+
}, { name: o });
|
|
153
153
|
};
|
|
154
|
-
},
|
|
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
|
-
],
|
|
184
|
+
], Ve = R(Xe), E = (e, t = 1) => `
|
|
185
185
|
`.repeat(t) + e + `
|
|
186
|
-
`.repeat(t),
|
|
187
|
-
const
|
|
188
|
-
switch (
|
|
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 (!
|
|
190
|
+
if (!o.lang && !o.meta && (n == null ? void 0 : n.inline) && !e.includes(`
|
|
191
191
|
`)) return `\`${e}\``;
|
|
192
|
-
const
|
|
193
|
-
return 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(
|
|
197
|
+
`) ? `> ${e}` : E(F(E(e), "blockquote"));
|
|
198
198
|
case "dropdown":
|
|
199
|
-
const l =
|
|
200
|
-
return E(
|
|
201
|
-
`), "details",
|
|
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
|
|
204
|
+
class u {
|
|
205
205
|
constructor(...t) {
|
|
206
206
|
_(this, "_intervals", []);
|
|
207
207
|
_(this, "collapsed", !0);
|
|
208
|
-
for (const [n,
|
|
209
|
-
this.push(n,
|
|
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,
|
|
219
|
-
this.push(n,
|
|
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:
|
|
224
|
-
if (
|
|
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
|
|
227
|
-
let [
|
|
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) : (
|
|
230
|
+
c <= i ? i = Math.max(i, a) : (s.push([r, i]), r = c, i = a);
|
|
231
231
|
}
|
|
232
|
-
return
|
|
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:
|
|
237
|
-
if (!n.length || !
|
|
238
|
-
let
|
|
239
|
-
for (const [
|
|
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
|
|
242
|
-
if (i <= c ||
|
|
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
|
-
|
|
246
|
+
r > c && l.push([c, r]), i < a && l.push([i, a]);
|
|
247
247
|
}
|
|
248
|
-
|
|
248
|
+
s = l;
|
|
249
249
|
}
|
|
250
|
-
return this._intervals =
|
|
250
|
+
return this._intervals = s, this.collapse(!0), this;
|
|
251
251
|
}
|
|
252
252
|
test(t, n = "head") {
|
|
253
|
-
const { _intervals:
|
|
253
|
+
const { _intervals: o } = this;
|
|
254
254
|
switch (n) {
|
|
255
255
|
case "head":
|
|
256
|
-
return
|
|
256
|
+
return o.some(([s, r]) => t >= s && t < r);
|
|
257
257
|
case "tail":
|
|
258
|
-
return
|
|
258
|
+
return o.some(([s, r]) => t > s && t <= r);
|
|
259
259
|
case "both":
|
|
260
|
-
return
|
|
260
|
+
return o.some(([s, r]) => t >= s && t <= r);
|
|
261
261
|
case "none":
|
|
262
|
-
return
|
|
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 [
|
|
269
|
-
n.push(t.slice(
|
|
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
|
|
278
|
+
const P = (e) => {
|
|
279
279
|
const t = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm, n = [];
|
|
280
|
-
let
|
|
281
|
-
for (; (
|
|
282
|
-
const
|
|
283
|
-
n.push({ range:
|
|
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
|
-
},
|
|
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
|
-
],
|
|
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
|
-
}),
|
|
298
|
-
const
|
|
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
|
|
303
|
-
for (;
|
|
304
|
-
`; )
|
|
305
|
-
const p = t.slice(a, n).trim() === "" && t.slice(
|
|
306
|
-
return i.isNewline && l.isNewline ?
|
|
307
|
-
}, e),
|
|
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
|
|
312
|
-
* @param 1 An optional additional id to
|
|
313
|
-
* @param 2 An optional additional id to
|
|
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,154 +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
|
-
],
|
|
413
|
-
const
|
|
414
|
-
for (let
|
|
415
|
-
|
|
416
|
-
return
|
|
417
|
-
},
|
|
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 =
|
|
420
|
-
return
|
|
421
|
-
new
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
-
},
|
|
480
|
+
}, tt = (e, ...t) => {
|
|
430
481
|
if (t.length === 0) return e;
|
|
431
|
-
const n =
|
|
432
|
-
return
|
|
433
|
-
new
|
|
434
|
-
new
|
|
435
|
-
|
|
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
|
-
},
|
|
501
|
+
}, nt = (e, t, n, o) => {
|
|
440
502
|
if (!t) return e;
|
|
441
|
-
let
|
|
503
|
+
let s = "", r = 0;
|
|
442
504
|
for (const [i, l] of $(e, t))
|
|
443
|
-
|
|
444
|
-
return
|
|
445
|
-
new
|
|
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
|
-
},
|
|
509
|
+
}, st = (e, t, n, o, s, r) => {
|
|
448
510
|
if (!t) return e;
|
|
449
|
-
const i = !(
|
|
450
|
-
return $(e, t, a).map((p) => p[n === "start" ? 0 : 1]).sort(
|
|
451
|
-
const y = new
|
|
452
|
-
let S = Math.abs(c),
|
|
453
|
-
for (; S > 0 &&
|
|
454
|
-
|
|
455
|
-
return
|
|
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
|
-
},
|
|
458
|
-
let
|
|
459
|
-
[n,
|
|
460
|
-
const l = t ? $(e, t) : [
|
|
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
|
-
|
|
463
|
-
return
|
|
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 = "",
|
|
467
|
-
for (const [
|
|
468
|
-
n += e.slice(
|
|
469
|
-
return n += e.slice(
|
|
470
|
-
},
|
|
471
|
-
var
|
|
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
|
|
474
|
-
for (const [a,
|
|
475
|
-
if ((
|
|
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 (;
|
|
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 (;
|
|
545
|
+
for (; o(p); ) s.push(p++);
|
|
482
546
|
}
|
|
483
547
|
if ((l = n.end) != null && l.left) {
|
|
484
|
-
let p =
|
|
485
|
-
for (;
|
|
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 =
|
|
489
|
-
for (;
|
|
552
|
+
let p = m.range[1];
|
|
553
|
+
for (; o(p); ) s.push(p++);
|
|
490
554
|
}
|
|
491
555
|
}
|
|
492
|
-
return new
|
|
493
|
-
},
|
|
494
|
-
if (!
|
|
495
|
-
const s =
|
|
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 =
|
|
566
|
+
e = ie(
|
|
567
|
+
e || t,
|
|
568
|
+
s.id,
|
|
569
|
+
...T(s)
|
|
570
|
+
);
|
|
499
571
|
break;
|
|
500
572
|
case "remove":
|
|
501
|
-
e =
|
|
573
|
+
e = tt(
|
|
574
|
+
e,
|
|
575
|
+
s.id,
|
|
576
|
+
...T(s)
|
|
577
|
+
);
|
|
502
578
|
break;
|
|
503
579
|
case "replace":
|
|
504
|
-
e =
|
|
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:
|
|
509
|
-
e =
|
|
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
|
-
|
|
515
|
-
|
|
602
|
+
s.left ?? (s.left = !0), s.right ?? (s.right = !0);
|
|
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
|
+
);
|
|
516
609
|
break;
|
|
517
610
|
}
|
|
518
611
|
case "trim": {
|
|
519
|
-
const { inside: r, outside:
|
|
520
|
-
e =
|
|
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
|
+
);
|
|
521
616
|
break;
|
|
522
617
|
}
|
|
523
618
|
case "single-line":
|
|
524
619
|
e = rt(e, s.id);
|
|
525
620
|
break;
|
|
526
621
|
case "remap":
|
|
527
|
-
e =
|
|
622
|
+
e = ot(
|
|
623
|
+
e,
|
|
624
|
+
s.id,
|
|
625
|
+
s.from,
|
|
626
|
+
s.to,
|
|
627
|
+
s.space
|
|
628
|
+
);
|
|
528
629
|
break;
|
|
529
630
|
}
|
|
530
|
-
return s.name === "debug" && console.log("debug!!!", s), e =
|
|
531
|
-
},
|
|
631
|
+
return s.name === "debug" && console.log("debug!!!", s), e = o && s.name !== "debug" ? se(e) : e, o ? j(e) : e;
|
|
632
|
+
}, lt = [
|
|
532
633
|
"recipe(id: string)"
|
|
533
|
-
],
|
|
634
|
+
], at = [
|
|
534
635
|
"recipe(id: string, 0?: string, 1?: string, 2?: string)"
|
|
535
|
-
],
|
|
536
|
-
register: R(
|
|
537
|
-
apply: R(
|
|
538
|
-
},
|
|
636
|
+
], ae = {
|
|
637
|
+
register: R(lt),
|
|
638
|
+
apply: R(at)
|
|
639
|
+
}, k = class k {
|
|
539
640
|
constructor() {
|
|
540
641
|
_(this, "recipes", /* @__PURE__ */ new Map());
|
|
541
642
|
}
|
|
542
643
|
tryStore(t) {
|
|
543
|
-
const n =
|
|
544
|
-
for (let
|
|
545
|
-
const [
|
|
546
|
-
if (
|
|
547
|
-
const i =
|
|
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);
|
|
548
649
|
switch (i.name) {
|
|
549
650
|
case "recipe":
|
|
550
|
-
const l = n.slice(
|
|
651
|
+
const l = n.slice(o + 1).filter(([c]) => c !== "register").map(([c, a]) => `${c}=${a}`).join("&");
|
|
551
652
|
this.recipes.set(i.id, l);
|
|
552
653
|
break;
|
|
553
654
|
default:
|
|
@@ -556,137 +657,190 @@ const I = (e) => {
|
|
|
556
657
|
}
|
|
557
658
|
}
|
|
558
659
|
apply(t) {
|
|
559
|
-
const n =
|
|
560
|
-
for (let
|
|
561
|
-
const [
|
|
562
|
-
if (
|
|
563
|
-
|
|
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}`);
|
|
564
665
|
continue;
|
|
565
666
|
}
|
|
566
|
-
const l =
|
|
667
|
+
const l = ae.apply(i);
|
|
567
668
|
switch (l.name) {
|
|
568
669
|
case "recipe":
|
|
569
|
-
|
|
670
|
+
o.push(this.recipes.get(l.id)), o.push(...T(l).map((c) => this.recipes.get(c)));
|
|
570
671
|
break;
|
|
571
672
|
default:
|
|
572
673
|
throw new Error(`Unknown registration: ${l.name}`);
|
|
573
674
|
}
|
|
574
675
|
}
|
|
575
|
-
return
|
|
676
|
+
return o.join("&");
|
|
576
677
|
}
|
|
577
678
|
};
|
|
578
|
-
_(
|
|
579
|
-
let H =
|
|
580
|
-
const
|
|
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 = {
|
|
581
682
|
_open: "<!--",
|
|
582
683
|
_close: "-->",
|
|
583
684
|
_flag: "p↓",
|
|
584
685
|
get begin() {
|
|
585
|
-
return M(
|
|
686
|
+
return M(
|
|
687
|
+
h._open,
|
|
688
|
+
h._flag,
|
|
689
|
+
"BEGIN",
|
|
690
|
+
h._close
|
|
691
|
+
);
|
|
586
692
|
},
|
|
587
693
|
get end() {
|
|
588
|
-
return M(
|
|
694
|
+
return M(
|
|
695
|
+
h._open,
|
|
696
|
+
h._flag,
|
|
697
|
+
"END",
|
|
698
|
+
h._close
|
|
699
|
+
);
|
|
589
700
|
},
|
|
590
701
|
lengthOf(e) {
|
|
591
702
|
const t = `lines: ${e.split(`
|
|
592
703
|
`).length}`, n = `chars: ${e.length}`;
|
|
593
|
-
return M(
|
|
704
|
+
return M(
|
|
705
|
+
h._open,
|
|
706
|
+
h._flag,
|
|
707
|
+
"length",
|
|
708
|
+
t,
|
|
709
|
+
n,
|
|
710
|
+
h._close
|
|
711
|
+
);
|
|
594
712
|
}
|
|
595
|
-
},
|
|
596
|
-
|
|
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),
|
|
597
725
|
h.begin,
|
|
598
726
|
h.lengthOf(t),
|
|
599
727
|
t,
|
|
600
728
|
h.end
|
|
601
|
-
),
|
|
602
|
-
const t = O(e, "heading").reduce(
|
|
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
|
+
);
|
|
603
734
|
return (n) => {
|
|
604
|
-
for (let
|
|
605
|
-
const
|
|
606
|
-
if (
|
|
735
|
+
for (let o = n.position.start.line; o >= 1; o--) {
|
|
736
|
+
const s = t.get(o);
|
|
737
|
+
if (s) return s;
|
|
607
738
|
}
|
|
608
739
|
return 0;
|
|
609
740
|
};
|
|
610
|
-
},
|
|
611
|
-
openingCommentDoesNotFollowLink: ({
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
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);
|
|
621
762
|
else {
|
|
622
|
-
const i =
|
|
623
|
-
if (
|
|
624
|
-
throw
|
|
625
|
-
const l =
|
|
626
|
-
if (
|
|
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;
|
|
627
768
|
n.push({ open: l, close: i });
|
|
628
769
|
}
|
|
629
|
-
if (
|
|
630
|
-
throw T.openingCommentNotClosed(r[0].node);
|
|
770
|
+
if (s.length > 0) throw W.openingCommentNotClosed(s[0].node);
|
|
631
771
|
return n;
|
|
632
|
-
},
|
|
633
|
-
const
|
|
634
|
-
return [...n].sort((
|
|
635
|
-
for (;
|
|
636
|
-
const i =
|
|
637
|
-
if (i.position.start.offset <
|
|
638
|
-
if (
|
|
639
|
-
throw
|
|
640
|
-
return
|
|
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]);
|
|
641
781
|
}
|
|
642
|
-
|
|
782
|
+
s.push(i);
|
|
643
783
|
}
|
|
644
|
-
throw
|
|
645
|
-
}),
|
|
646
|
-
},
|
|
784
|
+
throw W.openingCommentDoesNotFollowLink(r.open);
|
|
785
|
+
}), s.push(...o.reverse()), s.reverse();
|
|
786
|
+
}, de = (e, t) => {
|
|
647
787
|
t ?? (t = z.md(e));
|
|
648
|
-
const n =
|
|
649
|
-
return
|
|
650
|
-
|
|
651
|
-
|
|
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);
|
|
652
796
|
return Math.min(Math.max(t, 1), 6);
|
|
653
|
-
},
|
|
797
|
+
}, $t = (e, t, n) => {
|
|
654
798
|
if (t === 0) return e;
|
|
655
799
|
n ?? (n = z.md(e));
|
|
656
|
-
const
|
|
800
|
+
const o = O(n, "heading"), s = e.split(`
|
|
657
801
|
`);
|
|
658
|
-
for (const
|
|
659
|
-
const {
|
|
660
|
-
|
|
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;
|
|
661
808
|
}
|
|
662
|
-
return
|
|
809
|
+
return s.join(`
|
|
663
810
|
`);
|
|
664
|
-
},
|
|
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) => {
|
|
665
815
|
try {
|
|
666
|
-
e =
|
|
667
|
-
const
|
|
816
|
+
e = ve(e), e = $t(e, t);
|
|
817
|
+
const r = z.md(e), i = new H(), l = de(e, r).sort(d);
|
|
668
818
|
return l.filter(({ url: c }) => c.startsWith("?")).forEach(({ url: c }) => i.tryStore(c)), l.reverse().map((c) => {
|
|
669
|
-
var
|
|
670
|
-
const { url: a, headingDepth:
|
|
819
|
+
var N, S;
|
|
820
|
+
const { url: a, headingDepth: m } = c, [p, ...b] = ke(a).split("?"), y = i.apply(b.join("?"));
|
|
671
821
|
if (!a.startsWith("?"))
|
|
672
822
|
if (a.startsWith("./") || a.startsWith("../")) {
|
|
673
|
-
const
|
|
674
|
-
|
|
675
|
-
const x = new _e(y), D = (k = ((w) => {
|
|
676
|
-
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);
|
|
677
825
|
return v.length >= 1 ? v.join(",") : void 0;
|
|
678
|
-
})("region")) == null ? void 0 :
|
|
679
|
-
|
|
680
|
-
(w, v, C, { length:
|
|
681
|
-
|
|
682
|
-
)) ??
|
|
683
|
-
const
|
|
684
|
-
let { inline:
|
|
685
|
-
if (
|
|
686
|
-
if (
|
|
687
|
-
const w =
|
|
688
|
-
|
|
689
|
-
|
|
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,
|
|
690
844
|
/** p↓: ... */
|
|
691
845
|
C,
|
|
692
846
|
w,
|
|
@@ -694,38 +848,49 @@ const at = ["http", "./", "../", "?"], ct = ({ url: e }) => at.some((t) => e.sta
|
|
|
694
848
|
v
|
|
695
849
|
/** p↓: ... */
|
|
696
850
|
);
|
|
697
|
-
} else /^(js|ts)x?|svelte$/i.test(
|
|
698
|
-
|
|
851
|
+
} else /^(js|ts)x?|svelte$/i.test(g) && (f = te(
|
|
852
|
+
f,
|
|
699
853
|
"code",
|
|
700
854
|
/** p↓: ... */
|
|
701
|
-
{ extension:
|
|
855
|
+
{ extension: g, inline: U }
|
|
702
856
|
/** p↓: ... */
|
|
703
857
|
));
|
|
704
|
-
const
|
|
705
|
-
return
|
|
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
|
+
};
|
|
706
866
|
} else throw a.startsWith("http") ? new Error("External web links are not implemented yet") : new Error(`Unsupported link type: ${a}`);
|
|
707
|
-
}).filter(Boolean).reduce(
|
|
708
|
-
|
|
709
|
-
|
|
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
|
+
);
|
|
710
875
|
}
|
|
711
|
-
},
|
|
712
|
-
const t =
|
|
713
|
-
return { content:
|
|
714
|
-
},
|
|
715
|
-
const { dir:
|
|
716
|
-
n == null || n.unwatch(
|
|
717
|
-
console.log(`Change detected in "${c}". Regenerating "${
|
|
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);
|
|
718
883
|
});
|
|
719
|
-
const l =
|
|
720
|
-
const a =
|
|
721
|
-
return n == null || n.add(a),
|
|
722
|
-
},
|
|
723
|
-
return t &&
|
|
724
|
-
},
|
|
725
|
-
const { path:
|
|
726
|
-
return t &&
|
|
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;
|
|
727
892
|
};
|
|
728
893
|
export {
|
|
729
|
-
|
|
730
|
-
|
|
894
|
+
Tt as depopulateMarkdownInclusions,
|
|
895
|
+
bt as populateMarkdownInclusions
|
|
731
896
|
};
|