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