@p-buddy/parkdown 0.0.3 → 0.0.5
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 +325 -94
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +293 -217
- package/dist/index.umd.cjs +11 -14
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,66 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
var ae = Object.defineProperty;
|
|
2
|
+
var pe = (e, t, n) => t in e ? ae(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var q = (e, t, n) => pe(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { writeFileSync as z, readFileSync as me } from "node:fs";
|
|
5
|
+
import { basename as ue, dirname as O, join as S, resolve as X } from "node:path";
|
|
6
|
+
import { URLSearchParams as he } from "node:url";
|
|
7
|
+
import { unified as ge } from "unified";
|
|
8
|
+
import fe from "remark-parse";
|
|
9
|
+
import { visit as de } from "unist-util-visit";
|
|
10
|
+
import ve from "stable-hash";
|
|
11
|
+
import { dedent as T } from "ts-dedent";
|
|
12
|
+
import we from "extract-comments";
|
|
13
|
+
const g = (e, t) => e.position.start.offset - t.position.start.offset;
|
|
14
|
+
g.reverse = (e, t) => g(t, e);
|
|
15
|
+
const D = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, $e = ge().use(fe), I = {
|
|
16
|
+
md: (e) => $e.parse(e)
|
|
17
|
+
}, b = (e, t) => {
|
|
18
|
+
const n = [];
|
|
19
|
+
return de(e, (s, o, r) => {
|
|
17
20
|
if (s.type !== "root") {
|
|
18
|
-
if (
|
|
19
|
-
if (
|
|
20
|
-
const i =
|
|
21
|
-
|
|
21
|
+
if (t && s.type !== t) return;
|
|
22
|
+
if (D(s)) {
|
|
23
|
+
const i = ve(r), c = ((r == null ? void 0 : r.children.length) ?? 0) - 1;
|
|
24
|
+
n.push({ ...s, parentID: i, siblingIndex: o, siblingCount: c });
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
|
-
}),
|
|
25
|
-
},
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
const s =
|
|
29
|
-
return e.slice(0, s.position.start.offset) +
|
|
30
|
-
},
|
|
31
|
-
const s = Math.min(
|
|
27
|
+
}), n;
|
|
28
|
+
}, Ce = (e) => e.children.length === 0, J = (e, t, ...n) => {
|
|
29
|
+
if (n.length === 0) throw new Error("No nodes to replace content from");
|
|
30
|
+
n.sort(g);
|
|
31
|
+
const s = n.at(0), o = n.at(-1);
|
|
32
|
+
return e.slice(0, s.position.start.offset) + t + e.slice(o.position.end.offset);
|
|
33
|
+
}, ye = (e, t, n) => {
|
|
34
|
+
const s = Math.min(t.position.end.offset, n.position.end.offset), o = Math.max(t.position.start.offset, n.position.start.offset);
|
|
32
35
|
return e.slice(s, o);
|
|
33
|
-
},
|
|
34
|
-
`),
|
|
35
|
-
const
|
|
36
|
-
return
|
|
37
|
-
},
|
|
36
|
+
}, E = (...e) => e.join(" "), Ee = (...e) => e.join(`
|
|
37
|
+
`), Se = (e) => {
|
|
38
|
+
const t = e.split("?");
|
|
39
|
+
return t.length > 1 ? [t.slice(0, -1).join("?"), t.at(-1)] : [e, ""];
|
|
40
|
+
}, be = (e) => Se(e)[0];
|
|
38
41
|
class d {
|
|
39
42
|
constructor() {
|
|
40
|
-
this
|
|
43
|
+
q(this, "intervals", []);
|
|
41
44
|
}
|
|
42
|
-
push(
|
|
43
|
-
this.intervals.push([Math.min(
|
|
45
|
+
push(t, n) {
|
|
46
|
+
this.intervals.push([Math.min(t, n), Math.max(t, n)]);
|
|
44
47
|
}
|
|
45
|
-
combine(
|
|
46
|
-
this.intervals.push(...
|
|
48
|
+
combine(t) {
|
|
49
|
+
this.intervals.push(...t.intervals);
|
|
47
50
|
}
|
|
48
51
|
collapse() {
|
|
49
|
-
const { intervals:
|
|
50
|
-
if (!
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
let [s, o] =
|
|
54
|
-
for (let r = 1; r <
|
|
55
|
-
const [i, c] =
|
|
56
|
-
i <= o ? o = Math.max(o, c) : (
|
|
52
|
+
const { intervals: t } = this;
|
|
53
|
+
if (!t.length) return this.intervals = [];
|
|
54
|
+
t.sort((r, i) => r[0] - i[0]);
|
|
55
|
+
const n = [];
|
|
56
|
+
let [s, o] = t[0];
|
|
57
|
+
for (let r = 1; r < t.length; r++) {
|
|
58
|
+
const [i, c] = t[r];
|
|
59
|
+
i <= o ? o = Math.max(o, c) : (n.push([s, o]), s = i, o = c);
|
|
57
60
|
}
|
|
58
|
-
return
|
|
61
|
+
return n.push([s, o]), this.intervals = n;
|
|
59
62
|
}
|
|
60
|
-
subtract(
|
|
61
|
-
const { intervals:
|
|
62
|
-
if (!
|
|
63
|
-
let o = [...
|
|
63
|
+
subtract(t) {
|
|
64
|
+
const { intervals: n } = this, { intervals: s } = t;
|
|
65
|
+
if (!n.length || !s.length) return n;
|
|
66
|
+
let o = [...n];
|
|
64
67
|
for (const [r, i] of s) {
|
|
65
68
|
const c = [];
|
|
66
69
|
for (const [l, a] of o) {
|
|
@@ -75,62 +78,94 @@ class d {
|
|
|
75
78
|
return this.intervals = o;
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
81
|
+
const L = /,\s*(?![^()]*\))/, W = {
|
|
82
|
+
reserved: {
|
|
83
|
+
semi: ";",
|
|
84
|
+
slash: "/",
|
|
85
|
+
question: "?",
|
|
86
|
+
colon: ":",
|
|
87
|
+
at: "@",
|
|
88
|
+
equal: "=",
|
|
89
|
+
and: "&"
|
|
90
|
+
},
|
|
91
|
+
unsafe: {
|
|
92
|
+
quote: '"',
|
|
93
|
+
angle: "<",
|
|
94
|
+
unangle: ">",
|
|
95
|
+
hash: "#",
|
|
96
|
+
percent: "%",
|
|
97
|
+
curly: "{",
|
|
98
|
+
uncurly: "}",
|
|
99
|
+
pipe: "|",
|
|
100
|
+
back: "\\",
|
|
101
|
+
carrot: "^",
|
|
102
|
+
tilde: "~",
|
|
103
|
+
square: "[",
|
|
104
|
+
unsquare: "]",
|
|
105
|
+
tick: "`"
|
|
106
|
+
}
|
|
107
|
+
}, Ne = "-", B = {
|
|
108
|
+
static: [
|
|
109
|
+
["'''", '"'],
|
|
110
|
+
["''", "'"],
|
|
111
|
+
[/parkdown:\s+/g, ""],
|
|
112
|
+
[/p↓:\s+/g, ""]
|
|
113
|
+
],
|
|
114
|
+
url: [
|
|
115
|
+
...Object.entries(W.unsafe),
|
|
116
|
+
...Object.entries(W.reserved)
|
|
117
|
+
]
|
|
118
|
+
}, F = (e, [t, n]) => e.replaceAll(t, n), V = (e, t = Ne) => {
|
|
119
|
+
const n = B.static.reduce(F, e);
|
|
120
|
+
return B.url.map(([s, o]) => [t + s + t, o]).reduce(F, n).replaceAll(t, " ");
|
|
121
|
+
}, ke = ["string", "number", "boolean"], xe = (e) => ke.includes(e), Me = /^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/, _e = (e) => {
|
|
122
|
+
const t = e.match(Me);
|
|
123
|
+
if (!t) throw new Error(`Invalid invocation: ${e}`);
|
|
124
|
+
const [, n, s = ""] = t;
|
|
125
|
+
if (!s.trim()) return { name: n, parameters: [] };
|
|
126
|
+
const o = Te(s);
|
|
127
|
+
return { name: n, parameters: o };
|
|
128
|
+
}, Oe = (e, t) => {
|
|
129
|
+
for (let n = t + 1; n < e.length; n++)
|
|
130
|
+
if (e[n] !== void 0) return !1;
|
|
96
131
|
return !0;
|
|
97
|
-
},
|
|
98
|
-
const
|
|
99
|
-
let
|
|
132
|
+
}, Te = (e) => {
|
|
133
|
+
const t = [];
|
|
134
|
+
let n = "", s = !1;
|
|
100
135
|
for (let o = 0; o < e.length; o++) {
|
|
101
136
|
const r = e[o], i = r === "'";
|
|
102
137
|
if (i && e.at(o + 1) === "'") {
|
|
103
138
|
const c = e.at(o + 2) === "'";
|
|
104
|
-
s = !s,
|
|
105
|
-
} else i ? (s = !s,
|
|
139
|
+
s = !s, n += c ? "'''" : "''", o += c ? 2 : 1;
|
|
140
|
+
} else i ? (s = !s, n += r) : r === "," && !s ? (t.push(n.trim()), n = "") : n += r;
|
|
106
141
|
}
|
|
107
|
-
return
|
|
108
|
-
},
|
|
109
|
-
const
|
|
110
|
-
return !
|
|
111
|
-
},
|
|
112
|
-
const
|
|
113
|
-
if (!
|
|
114
|
-
const [, s, o] =
|
|
142
|
+
return t.push(n.trim()), t.map((o) => o === "" ? void 0 : o ? De(o) : void 0).filter((o, r, i) => o !== void 0 || !Oe(i, r));
|
|
143
|
+
}, De = (e) => {
|
|
144
|
+
const t = e.length >= 2 && e[0] === "'" && e.at(-1) === "'", n = t && e.length >= 4 && e[1] === "'" && e.at(-2) === "'";
|
|
145
|
+
return !t || n ? e : e.slice(1, -1);
|
|
146
|
+
}, Ie = (e) => {
|
|
147
|
+
const t = /^(\w+)(?:\(([^)]*)\))?/, n = e.match(t);
|
|
148
|
+
if (!n) return { name: e };
|
|
149
|
+
const [, s, o] = n;
|
|
115
150
|
if (!o) return { name: s };
|
|
116
151
|
const r = /(\w+)(\?)?:\s*([^,]+)/g, i = [];
|
|
117
152
|
let c;
|
|
118
153
|
for (; (c = r.exec(o)) !== null; ) {
|
|
119
154
|
const [, l, a, p] = c, m = p.trim();
|
|
120
|
-
if (!
|
|
155
|
+
if (!xe(m)) throw new Error(`Unsupported type: ${m}`);
|
|
121
156
|
i.push({ name: l, optional: a === "?", type: m });
|
|
122
157
|
}
|
|
123
158
|
return { name: s, parameters: i };
|
|
124
|
-
},
|
|
125
|
-
const
|
|
126
|
-
(
|
|
159
|
+
}, Z = (e) => {
|
|
160
|
+
const t = e.map(Ie).reduce(
|
|
161
|
+
(n, { name: s, parameters: o }) => n.set(s, o),
|
|
127
162
|
/* @__PURE__ */ new Map()
|
|
128
163
|
);
|
|
129
|
-
return (
|
|
130
|
-
const { name: s, parameters: o } =
|
|
131
|
-
if (!
|
|
164
|
+
return (n) => {
|
|
165
|
+
const { name: s, parameters: o } = _e(n);
|
|
166
|
+
if (!t.has(s))
|
|
132
167
|
throw new Error(`Unknown method: ${s}`);
|
|
133
|
-
const r =
|
|
168
|
+
const r = t.get(s);
|
|
134
169
|
if (r === void 0)
|
|
135
170
|
return { name: s };
|
|
136
171
|
if (o.length > r.length) {
|
|
@@ -157,7 +192,7 @@ const P = /,\s*(?![^()]*\))/, fe = [
|
|
|
157
192
|
return i;
|
|
158
193
|
}, { name: s });
|
|
159
194
|
};
|
|
160
|
-
},
|
|
195
|
+
}, U = (e) => Object.entries(e).filter(([t]) => t !== "name" && !isNaN(Number(t))).map(([t, n]) => n), je = [
|
|
161
196
|
/**
|
|
162
197
|
* Wraps the content in a markdown-formatted code block.
|
|
163
198
|
* @param lang The language of the code block (defaults to the file extension).
|
|
@@ -187,210 +222,251 @@ const P = /,\s*(?![^()]*\))/, fe = [
|
|
|
187
222
|
* @example [](<url>?wrap=dropdown(hello_world,,_))
|
|
188
223
|
*/
|
|
189
224
|
"dropdown(summary: string, open?: boolean, space?: string)"
|
|
190
|
-
],
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
225
|
+
], Re = Z(je), f = (e, t = 1) => `
|
|
226
|
+
`.repeat(t) + e + `
|
|
227
|
+
`.repeat(t), _ = (e, t, n) => `<${t}${n ? ` ${n}` : ""}>${f(e)}</${t}>`, G = (e, t, n) => {
|
|
228
|
+
const s = Re(t);
|
|
194
229
|
switch (s.name) {
|
|
195
230
|
case "code":
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
${
|
|
199
|
-
|
|
231
|
+
if (!s.lang && !s.meta && (n == null ? void 0 : n.inline) && !e.includes(`
|
|
232
|
+
`)) return `\`${e}\``;
|
|
233
|
+
const r = s.lang ?? (n == null ? void 0 : n.extension) ?? "", i = s.meta ? ` ${s.meta}` : "";
|
|
234
|
+
return f(`\`\`\`${r}${i}${f(e)}\`\`\``);
|
|
200
235
|
case "quote":
|
|
201
|
-
return
|
|
236
|
+
return n != null && n.inline && !e.includes(`
|
|
202
237
|
|
|
203
|
-
${e}
|
|
204
|
-
|
|
205
|
-
</blockquote>
|
|
206
|
-
`;
|
|
238
|
+
`) ? `> ${e}` : f(_(f(e), "blockquote"));
|
|
207
239
|
case "dropdown":
|
|
208
|
-
const c =
|
|
209
|
-
return [
|
|
210
|
-
`);
|
|
240
|
+
const c = _(V(s.summary), "summary");
|
|
241
|
+
return f(_([c, e].join(`
|
|
242
|
+
`), "details", s.open ? "open" : void 0));
|
|
211
243
|
}
|
|
212
|
-
},
|
|
244
|
+
}, Ae = [
|
|
245
|
+
/**
|
|
246
|
+
* Extract regions from the retrieved content between comments that INCLUDE the specified ids.
|
|
247
|
+
* @param id The id of the comment to extract.
|
|
248
|
+
* @param 0 An optional additional id to extract.
|
|
249
|
+
* @param 1 An optional additional id to extract.
|
|
250
|
+
* @param 2 An optional additional id to extract.
|
|
251
|
+
* @example [](<url>?region=extract(specifier))
|
|
252
|
+
* @example [](<url>?region=extract(specifier,other-specifier,some-other-specifier))
|
|
253
|
+
*/
|
|
213
254
|
"extract(id: string, 0?: string, 1?: string, 2?: string)",
|
|
255
|
+
/**
|
|
256
|
+
* Remove regions from the retrieved content between comments that INCLUDE the specified ids.
|
|
257
|
+
* @param id The id of the comment to remove.
|
|
258
|
+
* @param 0 An optional additional id to remove.
|
|
259
|
+
* @param 1 An optional additional id to remove.
|
|
260
|
+
* @param 2 An optional additional id to remove.
|
|
261
|
+
* @example [](<url>?region=remove(specifier))
|
|
262
|
+
* @example [](<url>?region=remove(specifier,other-specifier,some-other-specifier))
|
|
263
|
+
*/
|
|
214
264
|
"remove(id: string, 0?: string, 1?: string, 2?: string)",
|
|
265
|
+
/**
|
|
266
|
+
* Replace regions from the retrieved content between comments that INCLUDE the specified ids.
|
|
267
|
+
* @param id The id of the comment to replace.
|
|
268
|
+
* @param with The replacement content (if ommitted, the content of the detected comment will be used).
|
|
269
|
+
* @param space The space character to use between words in the replacement content (defaults to `-`).
|
|
270
|
+
* @example [](<url>?region=replace(specifier))
|
|
271
|
+
* @example [](<url>?region=replace(specifier,new-content))
|
|
272
|
+
* @example [](<url>?region=replace(specifier,new_content,_)
|
|
273
|
+
*/
|
|
215
274
|
"replace(id: string, with?: string, space?: string)"
|
|
216
|
-
],
|
|
217
|
-
if (
|
|
218
|
-
const
|
|
219
|
-
for (const i of
|
|
275
|
+
], Pe = Z(Ae), j = (e) => we(e), H = (e, t) => j(e).filter(({ value: n }) => n.includes(t)).sort((n, s) => n.range[0] - s.range[0]), qe = (e, ...t) => {
|
|
276
|
+
if (t.length === 0) return e;
|
|
277
|
+
const n = ([i, c]) => e.slice(i, c), s = j(e), o = new d(), r = new d();
|
|
278
|
+
for (const i of t) {
|
|
220
279
|
const c = s.filter(({ value: l }) => l.includes(i)).sort((l, a) => l.range[0] - a.range[0]);
|
|
221
280
|
for (let l = 0; l < c.length - 1; l += 2) {
|
|
222
281
|
const a = c[l], p = c[l + 1];
|
|
223
282
|
o.push(a.range[1], p.range[0]);
|
|
224
|
-
const [m, ...
|
|
225
|
-
r.push(a.range[0], a.range[1] + (m.trim() ? 0 : 1)), r.push(p.range[0], p.range[1] + (
|
|
283
|
+
const [m, ...y] = n([a.range[1], p.range[0]]), v = y[y.length - 1];
|
|
284
|
+
r.push(a.range[0], a.range[1] + (m.trim() ? 0 : 1)), r.push(p.range[0], p.range[1] + (v.trim() ? 0 : 1));
|
|
226
285
|
}
|
|
227
286
|
}
|
|
228
|
-
return o.collapse(), r.collapse(),
|
|
229
|
-
o.subtract(r).map(
|
|
287
|
+
return o.collapse(), r.collapse(), T(
|
|
288
|
+
o.subtract(r).map(n).filter(Boolean).join("")
|
|
230
289
|
).trim();
|
|
231
|
-
},
|
|
232
|
-
if (
|
|
233
|
-
const
|
|
234
|
-
for (const i of
|
|
290
|
+
}, Le = (e, ...t) => {
|
|
291
|
+
if (t.length === 0) return e;
|
|
292
|
+
const n = ([i, c]) => e.slice(i, c), s = j(e), o = new d();
|
|
293
|
+
for (const i of t) {
|
|
235
294
|
const c = s.filter(({ value: l }) => l.includes(i)).sort((l, a) => l.range[0] - a.range[0]);
|
|
236
295
|
for (let l = 0; l < c.length - 1; l += 2) {
|
|
237
|
-
const a = c[l], p = c[l + 1], m =
|
|
296
|
+
const a = c[l], p = c[l + 1], m = n([p.range[1], p.range[1] + 1]).at(-1);
|
|
238
297
|
o.push(a.range[0], m === `
|
|
239
298
|
` ? p.range[1] + 1 : p.range[1]);
|
|
240
299
|
}
|
|
241
300
|
}
|
|
242
301
|
o.collapse();
|
|
243
302
|
const r = new d();
|
|
244
|
-
return r.push(0, e.length), r.subtract(o),
|
|
245
|
-
r.collapse().map(
|
|
303
|
+
return r.push(0, e.length), r.subtract(o), T(
|
|
304
|
+
r.collapse().map(n).filter(Boolean).join("")
|
|
246
305
|
).trim();
|
|
247
|
-
},
|
|
248
|
-
if (!
|
|
249
|
-
const o =
|
|
306
|
+
}, We = (e, t, n, s) => {
|
|
307
|
+
if (!t) return e;
|
|
308
|
+
const o = H(e, t);
|
|
250
309
|
if (o.length < 2) return e;
|
|
251
310
|
let r = "", i = 0;
|
|
252
311
|
for (let l = 0; l < o.length - 1; l += 2) {
|
|
253
312
|
const a = o[l], p = o[l + 1];
|
|
254
|
-
r += e.slice(i, a.range[1]), r +=
|
|
313
|
+
r += e.slice(i, a.range[1]), r += V(n ?? a.value, s), i = p.range[0];
|
|
255
314
|
}
|
|
256
315
|
r += e.slice(i);
|
|
257
316
|
const c = new d();
|
|
258
317
|
return c.push(0, r.length), c.subtract(
|
|
259
|
-
|
|
260
|
-
),
|
|
318
|
+
H(r, t).reduce((l, { range: a }) => (l.push(...a), l), new d())
|
|
319
|
+
), T(
|
|
261
320
|
c.collapse().map(([l, a]) => r.slice(l, a)).filter(Boolean).join("")
|
|
262
321
|
).trim();
|
|
263
|
-
},
|
|
264
|
-
const
|
|
265
|
-
switch (
|
|
322
|
+
}, Be = (e, t) => {
|
|
323
|
+
const n = Pe(t);
|
|
324
|
+
switch (n.name) {
|
|
266
325
|
case "extract":
|
|
267
|
-
|
|
326
|
+
e = qe(e, n.id, ...U(n));
|
|
327
|
+
break;
|
|
268
328
|
case "remove":
|
|
269
|
-
|
|
329
|
+
e = Le(e, n.id, ...U(n));
|
|
330
|
+
break;
|
|
270
331
|
case "replace":
|
|
271
|
-
|
|
332
|
+
e = We(e, n.id, n.with, n.space);
|
|
333
|
+
break;
|
|
272
334
|
}
|
|
273
|
-
|
|
335
|
+
return e;
|
|
336
|
+
}, Fe = ["http", "./", "../"], Ue = ({ url: e }) => Fe.some((t) => e.startsWith(t)), Ge = (e) => D(e) && Ce(e) && Ue(e), K = ({ url: e }, t) => `[](${t ? S(t, e) : e})`, u = {
|
|
274
337
|
_open: "<!--",
|
|
275
338
|
_close: "-->",
|
|
276
|
-
_flag: "p
|
|
339
|
+
_flag: "p↓",
|
|
277
340
|
get begin() {
|
|
278
|
-
return
|
|
341
|
+
return E(u._open, u._flag, "BEGIN", u._close);
|
|
279
342
|
},
|
|
280
343
|
get end() {
|
|
281
|
-
return
|
|
344
|
+
return E(u._open, u._flag, "END", u._close);
|
|
345
|
+
},
|
|
346
|
+
lengthOf(e) {
|
|
347
|
+
const t = `lines: ${e.split(`
|
|
348
|
+
`).length}`, n = `chars: ${e.length}`;
|
|
349
|
+
return E(u._open, u._flag, "length", t, n, u._close);
|
|
282
350
|
}
|
|
283
|
-
},
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
351
|
+
}, Q = (e) => (t) => D(t) && t.value === u[e], He = ({ position: e, url: t, siblingCount: n }, s) => ({ position: e, url: t, headingDepth: s, inline: n >= 1 }), Qe = ({ position: { start: e }, url: t, siblingCount: n }, { position: { end: s } }, o) => ({ position: { start: e, end: s }, url: t, headingDepth: o, inline: n >= 1 }), ze = (e, t, n) => (e.inline ? E : Ee)(
|
|
352
|
+
K(e, n),
|
|
353
|
+
u.begin,
|
|
354
|
+
u.lengthOf(t),
|
|
355
|
+
t,
|
|
356
|
+
u.end
|
|
357
|
+
), Xe = (e) => {
|
|
358
|
+
const t = b(e, "heading").reduce((n, { position: s, depth: o }) => n.set(s.start.line, o), /* @__PURE__ */ new Map());
|
|
359
|
+
return (n) => {
|
|
360
|
+
for (let s = n.position.start.line; s >= 1; s--) {
|
|
361
|
+
const o = t.get(s);
|
|
288
362
|
if (o) return o;
|
|
289
363
|
}
|
|
290
364
|
return 0;
|
|
291
365
|
};
|
|
292
|
-
},
|
|
366
|
+
}, N = {
|
|
293
367
|
openingCommentDoesNotFollowLink: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),
|
|
294
368
|
closingCommentNotMatchedToOpening: ({ position: { start: e } }) => new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),
|
|
295
369
|
openingCommentNotClosed: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)
|
|
296
|
-
},
|
|
297
|
-
const
|
|
370
|
+
}, Je = (e, t) => {
|
|
371
|
+
const n = [], s = [
|
|
298
372
|
...e.map((r) => ({ node: r, type: "open" })),
|
|
299
|
-
...
|
|
373
|
+
...t.map((r) => ({ node: r, type: "close" }))
|
|
300
374
|
].sort((r, i) => g(r.node, i.node)), o = [];
|
|
301
375
|
for (const r of s)
|
|
302
376
|
if (r.type === "open") o.push(r);
|
|
303
377
|
else {
|
|
304
378
|
const i = r.node;
|
|
305
379
|
if (o.length === 0)
|
|
306
|
-
throw
|
|
380
|
+
throw N.closingCommentNotMatchedToOpening(i);
|
|
307
381
|
const c = o.pop().node;
|
|
308
382
|
if (o.length > 0) continue;
|
|
309
|
-
|
|
383
|
+
n.push({ open: c, close: i });
|
|
310
384
|
}
|
|
311
385
|
if (o.length > 0)
|
|
312
|
-
throw
|
|
313
|
-
return
|
|
314
|
-
},
|
|
315
|
-
const s = [...
|
|
316
|
-
return [...
|
|
386
|
+
throw N.openingCommentNotClosed(o[0].node);
|
|
387
|
+
return n;
|
|
388
|
+
}, Ve = (e, t, n) => {
|
|
389
|
+
const s = [...t].sort(g), o = [];
|
|
390
|
+
return [...n].sort((r, i) => g.reverse(r.open, i.open)).forEach((r) => {
|
|
317
391
|
for (; s.length > 0; ) {
|
|
318
392
|
const i = s.pop();
|
|
319
393
|
if (i.position.start.offset < r.open.position.start.offset) {
|
|
320
|
-
if (
|
|
321
|
-
throw
|
|
394
|
+
if (ye(e, i, r.open).trim() !== "")
|
|
395
|
+
throw N.openingCommentDoesNotFollowLink(r.open);
|
|
322
396
|
return o.push([i, r]);
|
|
323
397
|
}
|
|
324
398
|
o.push(i);
|
|
325
399
|
}
|
|
326
|
-
throw
|
|
400
|
+
throw N.openingCommentDoesNotFollowLink(r.open);
|
|
327
401
|
}), o.push(...s.reverse()), o.reverse();
|
|
328
|
-
},
|
|
329
|
-
n ?? (n = I.md(e));
|
|
330
|
-
const t = Be(n), s = y(n, "link").filter(Le), o = y(n, "html").sort(g), r = o.filter(F("begin")), i = o.filter(F("end")), c = Fe(r, i);
|
|
331
|
-
return qe(e, s, c).map((a) => Array.isArray(a) ? Re(a[0], a[1].close, t(a[0])) : Pe(a, t(a)));
|
|
332
|
-
}, Ue = (e, { url: n }) => (t) => e(C(_(n), t)), z = (...e) => {
|
|
333
|
-
const n = e.reduce((t, s) => t + s, 0);
|
|
334
|
-
return Math.min(Math.max(n, 1), 6);
|
|
335
|
-
}, Ge = (e, n, t) => {
|
|
336
|
-
if (n === 0) return e;
|
|
402
|
+
}, Y = (e, t) => {
|
|
337
403
|
t ?? (t = I.md(e));
|
|
338
|
-
const s =
|
|
404
|
+
const n = Xe(t), s = b(t, "link").filter(Ge), o = b(t, "html").sort(g), r = o.filter(Q("begin")), i = o.filter(Q("end")), c = Je(r, i);
|
|
405
|
+
return Ve(e, s, c).map((a) => Array.isArray(a) ? Qe(a[0], a[1].close, n(a[0])) : He(a, n(a)));
|
|
406
|
+
}, Ze = (e, { url: t }) => (n) => e(S(O(t), n)), ee = (...e) => {
|
|
407
|
+
const t = e.reduce((n, s) => n + s, 0);
|
|
408
|
+
return Math.min(Math.max(t, 1), 6);
|
|
409
|
+
}, Ke = (e, t, n) => {
|
|
410
|
+
if (t === 0) return e;
|
|
411
|
+
n ?? (n = I.md(e));
|
|
412
|
+
const s = b(n, "heading"), o = e.split(`
|
|
339
413
|
`);
|
|
340
414
|
for (const r of s) {
|
|
341
|
-
const { depth: i, position: { start: c, end: l } } = r, a =
|
|
415
|
+
const { depth: i, position: { start: c, end: l } } = r, a = ee(i, t), p = o[c.line - 1].slice(i, l.column), m = "#".repeat(a) + p;
|
|
342
416
|
o[c.line - 1] = m, r.depth = a;
|
|
343
417
|
}
|
|
344
418
|
return o.join(`
|
|
345
419
|
`);
|
|
346
|
-
},
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
420
|
+
}, te = (e) => Y(e).reverse().sort(g.reverse).reduce((t, n) => J(t, K(n), n), e), ne = (e, t, n, s, o) => {
|
|
421
|
+
try {
|
|
422
|
+
e = te(e), e = Ke(e, t);
|
|
423
|
+
const r = I.md(e);
|
|
424
|
+
return Y(e, r).sort(g).reverse().map((i) => {
|
|
425
|
+
var A, P;
|
|
426
|
+
const { url: c, headingDepth: l } = i, [a, ...p] = ue(c).split("?"), m = a.split(".").pop() ?? "", y = p.join("?"), v = O(c), R = S(v, a);
|
|
427
|
+
if (c.startsWith("./") || c.startsWith("../")) {
|
|
428
|
+
let h = n(R);
|
|
429
|
+
const w = new he(y), k = (A = w.get("region")) == null ? void 0 : A.split(L);
|
|
430
|
+
h = (k == null ? void 0 : k.reduce(($, C) => Be($, C), h)) ?? h;
|
|
431
|
+
const re = w.has("skip"), ie = w.get("heading") ?? 0, ce = w.has("inline");
|
|
432
|
+
let { inline: x } = i;
|
|
433
|
+
if (ce && (x = !0), !re)
|
|
434
|
+
if (m === "md") {
|
|
435
|
+
const $ = Ze(n, i), C = o ? S(o, v) : v, le = ee(l, Number(ie));
|
|
436
|
+
h = ne(
|
|
437
|
+
h,
|
|
438
|
+
/** p↓: ... */
|
|
439
|
+
le,
|
|
440
|
+
$,
|
|
441
|
+
R,
|
|
442
|
+
C
|
|
443
|
+
/** p↓: ... */
|
|
444
|
+
);
|
|
445
|
+
} else /^(js|ts)x?|svelte$/i.test(m) && (h = G(
|
|
446
|
+
h,
|
|
447
|
+
"code",
|
|
448
|
+
/** p↓: ... */
|
|
449
|
+
{ extension: m, inline: x }
|
|
450
|
+
/** p↓: ... */
|
|
451
|
+
));
|
|
452
|
+
const M = (P = w.get("wrap")) == null ? void 0 : P.split(L);
|
|
453
|
+
return h = (M == null ? void 0 : M.reduce(($, C) => G($, C, { extension: m, inline: x }), h)) ?? h, { target: i, content: ze(i, h, o) };
|
|
454
|
+
} else throw c.startsWith("http") ? new Error("External web links are not implemented yet") : new Error(`Unsupported link type: ${c}`);
|
|
455
|
+
}).reduce((i, { target: c, content: l }) => J(i, l, c), e);
|
|
456
|
+
} catch (r) {
|
|
457
|
+
throw new Error(`Error populating inclusions in file ${s}: ${r}`);
|
|
458
|
+
}
|
|
459
|
+
}, oe = (e) => me(e, "utf-8"), se = (e) => {
|
|
460
|
+
const t = X(e), n = O(t);
|
|
461
|
+
return { markdown: oe(t), dir: n, path: t };
|
|
462
|
+
}, at = (e, t = !0) => {
|
|
463
|
+
const { dir: n, path: s, markdown: o } = se(e), i = ne(o, 0, (c) => oe(X(n, be(c))), s);
|
|
464
|
+
return t && z(s, i), i;
|
|
465
|
+
}, pt = (e, t = !0) => {
|
|
466
|
+
const { path: n, markdown: s } = se(e), o = te(s);
|
|
467
|
+
return t && z(n, o), o;
|
|
391
468
|
};
|
|
392
469
|
export {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
nt as remapImportSpecifiers
|
|
470
|
+
pt as depopulateMarkdownInclusions,
|
|
471
|
+
at as populateMarkdownInclusions
|
|
396
472
|
};
|