@p-buddy/parkdown 0.0.25 → 0.0.27
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 +40 -13
- package/dist/cli.js +1 -1
- package/dist/index.js +205 -204
- package/dist/index.umd.cjs +12 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ populateMarkdownInclusions(file, writeFile);
|
|
|
44
44
|
|
|
45
45
|
[](./.assets/authoring.md)
|
|
46
46
|
<!-- p↓ BEGIN -->
|
|
47
|
-
<!-- p↓ length lines:
|
|
47
|
+
<!-- p↓ length lines: 690 chars: 23471 -->
|
|
48
48
|
## Authoring
|
|
49
49
|
|
|
50
50
|
You author inclusions in your markdown files using a link with no text i.e. `[](<url>)`, where `<url>` points to some local or remote text resource (e.g.`./other.md`, `https://example.com/remote.md`).
|
|
@@ -55,7 +55,7 @@ These links can be rendered either [inline](#inline) or [block](#block), dependi
|
|
|
55
55
|
|
|
56
56
|
Inline inclusions occur when your _text-less_ link has 1 or more siblings (meaning it's **not** the only node in a [paragraph](https://www.markdownguide.org/basic-syntax/#paragraphs-1)).
|
|
57
57
|
|
|
58
|
-
> **CAUTION:** [parkdown](https://www.npmjs.com/package/@p-buddy/parkdown) will not protect you from authoring inline inclusions that should
|
|
58
|
+
> **CAUTION:** [parkdown](https://www.npmjs.com/package/@p-buddy/parkdown) will not protect you from authoring inline inclusions that create invalid markdown (and thus should instead be [block](#block) inclusions).
|
|
59
59
|
|
|
60
60
|
There are two equivalent ways to author inline inclusions, [single-line](#single-line) or [multi-line](#multi-line), and which you choose depends solely on how you want your raw markdown to look (it will **not** affect the rendered output).
|
|
61
61
|
|
|
@@ -256,7 +256,7 @@ Before...
|
|
|
256
256
|
|
|
257
257
|
[](.assets/query.md?heading=-1)
|
|
258
258
|
<!-- p↓ BEGIN -->
|
|
259
|
-
<!-- p↓ length lines:
|
|
259
|
+
<!-- p↓ length lines: 477 chars: 18752 -->
|
|
260
260
|
### Query parameters
|
|
261
261
|
|
|
262
262
|
You can pass query parameters to your inclusion links to control how their content is processed and included within your markdown.
|
|
@@ -265,28 +265,33 @@ You can pass query parameters to your inclusion links to control how their conte
|
|
|
265
265
|
|
|
266
266
|
[](src/include.ts?®ion=extract(query))
|
|
267
267
|
<!-- p↓ BEGIN -->
|
|
268
|
-
<!-- p↓ length lines:
|
|
268
|
+
<!-- p↓ length lines: 16 chars: 520 -->
|
|
269
269
|
|
|
270
270
|
```ts
|
|
271
271
|
const params = new URLSearchParams(query);
|
|
272
272
|
const entries = (key: string) => {
|
|
273
|
-
const values = Array.from(params.entries())
|
|
273
|
+
const values = Array.from(params.entries())
|
|
274
|
+
.filter(([k]) => k === key)
|
|
275
|
+
.map(([_, v]) => v);
|
|
274
276
|
return values.length >= 1 ? values.join(",") : undefined;
|
|
275
277
|
};
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
278
|
+
const regions = entries("region")?.split(COMMA_NOT_IN_PARENTHESIS);
|
|
279
|
+
const skip = params.has("skip");
|
|
280
|
+
const headingModfiier = params.get("heading") ?? 0;
|
|
281
|
+
const inlineOverride = params.has("inline");
|
|
282
|
+
const wraps = params.get("wrap")?.split(COMMA_NOT_IN_PARENTHESIS);
|
|
281
283
|
```
|
|
282
284
|
|
|
283
285
|
<!-- p↓ END -->
|
|
284
286
|
|
|
287
|
+
[](.assets/region.md?heading=-1)
|
|
288
|
+
<!-- p↓ BEGIN -->
|
|
289
|
+
<!-- p↓ length lines: 183 chars: 8530 -->
|
|
285
290
|
#### `region`
|
|
286
291
|
|
|
287
|
-
|
|
292
|
+
Modify content from the included file based on regions designated by comments.
|
|
288
293
|
|
|
289
|
-
|
|
294
|
+
Comments that act as region boundaries will be identified by their specifiers, and are expected to come in pairs / bookend the desired region, like so:
|
|
290
295
|
|
|
291
296
|
```ts
|
|
292
297
|
/** some-specifier */
|
|
@@ -294,10 +299,31 @@ Specifiers will be searched for within the file's comments, and are expected to
|
|
|
294
299
|
/** some-specifier */
|
|
295
300
|
```
|
|
296
301
|
|
|
297
|
-
|
|
302
|
+
> **NOTE:** Because comments are expected to come in consecutive pairs, nesting regions that are retrieved with the _same_ specifier will *NOT* work as expected (since the nesting will not be respected).
|
|
298
303
|
|
|
299
304
|
Identifiers will be searched for within the text of a comment, split by spaces (i.e. `/* some-specifier */` has a single identifier, but `/* some specifier */` can be identified by either `some` or `specifier`).
|
|
300
305
|
|
|
306
|
+
It is generally **BEST PRACTICE** to include a _parkdown prefix_ in your comment text, as all parkdown-prefixed comments will be stripped as a post-processing step. Otherwise, non-prefixed comment boundaries will be left in the included content, regardless of how they are processed.
|
|
307
|
+
|
|
308
|
+
The supported prefixes are:
|
|
309
|
+
|
|
310
|
+
[](src/comments.ts?region=extract(prefixes))
|
|
311
|
+
<!-- p↓ BEGIN -->
|
|
312
|
+
<!-- p↓ length lines: 12 chars: 101 -->
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
const prefixes = [
|
|
316
|
+
"(pd)",
|
|
317
|
+
"(p↓)",
|
|
318
|
+
"(parkdown)",
|
|
319
|
+
"pd:",
|
|
320
|
+
"p↓:",
|
|
321
|
+
"parkdown:",
|
|
322
|
+
]
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
<!-- p↓ END -->
|
|
326
|
+
|
|
301
327
|
Below is the currently supported API for the `region` query parameter, where each defined method signature can be _invoked_ as a value for the `region` parameter, for example:
|
|
302
328
|
|
|
303
329
|
- `[](<url>?region=method(argument))`
|
|
@@ -443,6 +469,7 @@ const definitions = [
|
|
|
443
469
|
]
|
|
444
470
|
```
|
|
445
471
|
|
|
472
|
+
<!-- p↓ END -->
|
|
446
473
|
<!-- p↓ END -->
|
|
447
474
|
|
|
448
475
|
#### `skip`
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Command as r } from "@commander-js/extra-typings";
|
|
3
3
|
import { populateMarkdownInclusions as l, depopulateMarkdownInclusions as a } from "@p-buddy/parkdown";
|
|
4
4
|
import f from "chokidar";
|
|
5
|
-
const c = "0.0.
|
|
5
|
+
const c = "0.0.27", p = new r().version(c).option("--nw, --no-write", "Do NOT write result to file (defaults to false)", !1).option("--ni, --no-inclusions", "Do NOT process file inclusions (defaults to false)", !1).option("-d, --depopulate", "Remove populated inclusions from the file", !1).option("-f, --file <flag>", "The file(s) to process", (e, o) => (o.push(e), o), new Array()).option("-w, --watch", "Watch the file(s) for changes and update automatically", !1).parse(), { inclusions: u, depopulate: d, file: t, write: n, watch: h } = p.opts();
|
|
6
6
|
t.length === 0 && t.push("README.md");
|
|
7
7
|
const m = [
|
|
8
8
|
[l, !u],
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { writeFileSync as
|
|
5
|
-
import { basename as
|
|
6
|
-
import { URLSearchParams as
|
|
7
|
-
import { unified as
|
|
1
|
+
var Ce = Object.defineProperty;
|
|
2
|
+
var Ee = (e, t, n) => t in e ? Ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var _ = (e, t, n) => Ee(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { writeFileSync as ae, readFileSync as Se } from "node:fs";
|
|
5
|
+
import { basename as xe, dirname as Q, join as A, resolve as ce } from "node:path";
|
|
6
|
+
import { URLSearchParams as _e } from "node:url";
|
|
7
|
+
import { unified as Ne } from "unified";
|
|
8
8
|
import ke from "remark-parse";
|
|
9
|
-
import { visit as
|
|
10
|
-
import { dedent as
|
|
9
|
+
import { visit as Me } from "unist-util-visit";
|
|
10
|
+
import { dedent as Ae } from "ts-dedent";
|
|
11
11
|
const f = (e, t) => e.position.start.offset - t.position.start.offset;
|
|
12
12
|
f.reverse = (e, t) => f(t, e);
|
|
13
|
-
const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0,
|
|
14
|
-
md: (e) =>
|
|
15
|
-
},
|
|
13
|
+
const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, Oe = Ne().use(ke), z = {
|
|
14
|
+
md: (e) => Oe.parse(e)
|
|
15
|
+
}, O = (e, t) => {
|
|
16
16
|
const n = [];
|
|
17
|
-
return
|
|
17
|
+
return Me(e, (s, r, o) => {
|
|
18
18
|
if (s.type !== "root") {
|
|
19
19
|
if (t && s.type !== t) return;
|
|
20
20
|
if (G(s)) {
|
|
@@ -23,19 +23,19 @@ const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}), n;
|
|
26
|
-
},
|
|
26
|
+
}, Re = (e) => e.children.length === 0, pe = (e, t, ...n) => {
|
|
27
27
|
if (n.length === 0) throw new Error("No nodes to replace content from");
|
|
28
28
|
n.sort(f);
|
|
29
29
|
const s = n.at(0), r = n.at(-1);
|
|
30
30
|
return e.slice(0, s.position.start.offset) + t + e.slice(r.position.end.offset);
|
|
31
|
-
},
|
|
31
|
+
}, Te = (e, t, n) => {
|
|
32
32
|
const s = Math.min(t.position.end.offset, n.position.end.offset), r = Math.max(t.position.start.offset, n.position.start.offset);
|
|
33
33
|
return e.slice(s, r);
|
|
34
|
-
},
|
|
35
|
-
`),
|
|
34
|
+
}, M = (...e) => e.join(" "), We = (...e) => e.join(`
|
|
35
|
+
`), Ie = (e) => {
|
|
36
36
|
const t = e.split("?");
|
|
37
37
|
return t.length > 1 ? [t.slice(0, -1).join("?"), t.at(-1)] : [e, ""];
|
|
38
|
-
},
|
|
38
|
+
}, Pe = (e) => Ie(e)[0], J = /,\s*(?![^()]*\))/, Z = {
|
|
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
|
+
}, je = "-", K = {
|
|
67
67
|
static: [
|
|
68
68
|
["'''", '"'],
|
|
69
69
|
["''", "'"],
|
|
@@ -74,21 +74,21 @@ const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
74
74
|
...Object.entries(Z.unsafe),
|
|
75
75
|
...Object.entries(Z.reserved)
|
|
76
76
|
]
|
|
77
|
-
}, Y = (e, [t, n]) => e.replaceAll(t, n),
|
|
77
|
+
}, Y = (e, [t, n]) => e.replaceAll(t, n), W = (e, t = je) => {
|
|
78
78
|
const n = K.static.reduce(Y, e);
|
|
79
79
|
return K.url.map(([s, r]) => [t + s + t, r]).reduce(Y, n).replaceAll(t, " ");
|
|
80
|
-
},
|
|
81
|
-
const t = e.match(
|
|
80
|
+
}, De = ["string", "number", "boolean"], Le = (e) => De.includes(e), Ue = /^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/, qe = (e) => {
|
|
81
|
+
const t = e.match(Ue);
|
|
82
82
|
if (!t) throw new Error(`Invalid invocation: ${e}`);
|
|
83
83
|
const [, n, s = ""] = t;
|
|
84
84
|
if (!s.trim()) return { name: n, parameters: [] };
|
|
85
|
-
const r =
|
|
85
|
+
const r = Fe(s);
|
|
86
86
|
return { name: n, parameters: r };
|
|
87
|
-
},
|
|
87
|
+
}, Be = (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
|
+
}, Fe = (e) => {
|
|
92
92
|
const t = [];
|
|
93
93
|
let n = "", s = !1;
|
|
94
94
|
for (let r = 0; r < e.length; r++) {
|
|
@@ -98,46 +98,46 @@ const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
98
98
|
s = !s, n += l ? "'''" : "''", r += l ? 2 : 1;
|
|
99
99
|
} else i ? (s = !s, n += o) : o === "," && !s ? (t.push(n.trim()), n = "") : n += o;
|
|
100
100
|
}
|
|
101
|
-
return t.push(n.trim()), t.map((r) => r === "" ? void 0 : r ?
|
|
102
|
-
},
|
|
101
|
+
return t.push(n.trim()), t.map((r) => r === "" ? void 0 : r ? He(r) : void 0).filter((r, o, i) => r !== void 0 || !Be(i, o));
|
|
102
|
+
}, He = (e) => {
|
|
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
|
-
},
|
|
106
|
-
const t = /^(\w+)(?:\(([^)]*)\))?/, n = e.match(t);
|
|
105
|
+
}, Qe = (e) => {
|
|
106
|
+
const t = /^([\w-_]+)(?:\(([^)]*)\))?/, n = e.match(t);
|
|
107
107
|
if (!n) return { name: e };
|
|
108
108
|
const [, s, r] = n;
|
|
109
109
|
if (!r) return { name: s };
|
|
110
|
-
const o = /(\w+)(\?)?:\s*([^,]+)/g, i = [];
|
|
110
|
+
const o = /([\w-_]+)(\?)?:\s*([^,]+)/g, i = [];
|
|
111
111
|
let l;
|
|
112
112
|
for (; (l = o.exec(r)) !== null; ) {
|
|
113
|
-
const [,
|
|
114
|
-
if (!
|
|
115
|
-
i.push({ name:
|
|
113
|
+
const [, c, a, u] = l, p = u.trim();
|
|
114
|
+
if (!Le(p)) throw new Error(`Unsupported type: ${p}`);
|
|
115
|
+
i.push({ name: c, optional: a === "?", type: p });
|
|
116
116
|
}
|
|
117
117
|
return { name: s, parameters: i };
|
|
118
|
-
},
|
|
119
|
-
const t = e.map(
|
|
118
|
+
}, R = (e) => {
|
|
119
|
+
const t = e.map(Qe).reduce(
|
|
120
120
|
(n, { name: s, parameters: r }) => n.set(s, r),
|
|
121
121
|
/* @__PURE__ */ new Map()
|
|
122
122
|
);
|
|
123
123
|
return (n) => {
|
|
124
|
-
const { name: s, parameters: r } =
|
|
124
|
+
const { name: s, parameters: r } = qe(n);
|
|
125
125
|
if (!t.has(s))
|
|
126
126
|
throw new Error(`Unknown method: ${s}`);
|
|
127
127
|
const o = t.get(s);
|
|
128
128
|
if (o === void 0)
|
|
129
129
|
return { name: s };
|
|
130
130
|
if (r.length > o.length) {
|
|
131
|
-
const i = o.filter(({ optional:
|
|
131
|
+
const i = o.filter(({ optional: c }) => !c).length, l = i === o.length ? i.toString() : `${i} - ${o.length}`;
|
|
132
132
|
throw new Error(`Too many parameters: ${r.length} for method '${s}' (expected: ${l})`);
|
|
133
133
|
}
|
|
134
|
-
return o.reduce((i, { name: l, optional:
|
|
134
|
+
return o.reduce((i, { name: l, optional: c, type: a }, u) => {
|
|
135
135
|
const p = r[u];
|
|
136
136
|
if (p === void 0) {
|
|
137
|
-
if (
|
|
137
|
+
if (c) return i;
|
|
138
138
|
throw new Error(`Missing required parameter: ${l} for method '${s}'`);
|
|
139
139
|
}
|
|
140
|
-
switch (
|
|
140
|
+
switch (a) {
|
|
141
141
|
case "string":
|
|
142
142
|
i[l] = p;
|
|
143
143
|
break;
|
|
@@ -146,12 +146,12 @@ const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
146
146
|
i[l] = JSON.parse(p);
|
|
147
147
|
break;
|
|
148
148
|
}
|
|
149
|
-
if (typeof i[l] !==
|
|
150
|
-
throw new Error(`Invalid type: ${l} must be ${
|
|
149
|
+
if (typeof i[l] !== a)
|
|
150
|
+
throw new Error(`Invalid type: ${l} must be ${a}, got ${typeof i[l]} for method '${s}'`);
|
|
151
151
|
return i;
|
|
152
152
|
}, { name: s });
|
|
153
153
|
};
|
|
154
|
-
}, F = (e) => Object.entries(e).filter(([t]) => t !== "name" && !isNaN(Number(t))).map(([t, n]) => n),
|
|
154
|
+
}, F = (e) => Object.entries(e).filter(([t]) => t !== "name" && !isNaN(Number(t))).map(([t, n]) => n), Ge = [
|
|
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,10 +181,10 @@ 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
|
+
], ze = R(Ge), E = (e, t = 1) => `
|
|
185
185
|
`.repeat(t) + e + `
|
|
186
186
|
`.repeat(t), B = (e, t, n) => `<${t}${n ? ` ${n}` : ""}>${E(e)}</${t}>`, ee = (e, t, n) => {
|
|
187
|
-
const s =
|
|
187
|
+
const s = ze(t);
|
|
188
188
|
switch (s.name) {
|
|
189
189
|
case "code":
|
|
190
190
|
if (!s.lang && !s.meta && (n == null ? void 0 : n.inline) && !e.includes(`
|
|
@@ -196,15 +196,15 @@ const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
196
196
|
|
|
197
197
|
`) ? `> ${e}` : E(B(E(e), "blockquote"));
|
|
198
198
|
case "dropdown":
|
|
199
|
-
const l = B(
|
|
199
|
+
const l = B(W(s.summary), "summary");
|
|
200
200
|
return E(B([l, e].join(`
|
|
201
201
|
`), "details", s.open ? "open" : void 0));
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
class d {
|
|
205
205
|
constructor(...t) {
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
_(this, "_intervals", []);
|
|
207
|
+
_(this, "collapsed", !0);
|
|
208
208
|
for (const [n, s] of t)
|
|
209
209
|
this.push(n, s);
|
|
210
210
|
}
|
|
@@ -222,12 +222,12 @@ class d {
|
|
|
222
222
|
collapse(t = !1) {
|
|
223
223
|
const { _intervals: n, collapsed: s } = this;
|
|
224
224
|
if (s && !t || !n.length) return this;
|
|
225
|
-
n.sort((l,
|
|
225
|
+
n.sort((l, c) => l[0] - c[0]);
|
|
226
226
|
const r = [];
|
|
227
227
|
let [o, i] = n[0];
|
|
228
228
|
for (let l = 1; l < n.length; l++) {
|
|
229
|
-
const [
|
|
230
|
-
|
|
229
|
+
const [c, a] = n[l];
|
|
230
|
+
c <= i ? i = Math.max(i, a) : (r.push([o, i]), o = c, i = a);
|
|
231
231
|
}
|
|
232
232
|
return r.push([o, i]), this._intervals = r, this.collapsed = !0, this;
|
|
233
233
|
}
|
|
@@ -238,12 +238,12 @@ class d {
|
|
|
238
238
|
let r = [...n];
|
|
239
239
|
for (const [o, i] of s) {
|
|
240
240
|
const l = [];
|
|
241
|
-
for (const [
|
|
242
|
-
if (i <=
|
|
243
|
-
l.push([
|
|
241
|
+
for (const [c, a] of r) {
|
|
242
|
+
if (i <= c || o >= a) {
|
|
243
|
+
l.push([c, a]);
|
|
244
244
|
continue;
|
|
245
245
|
}
|
|
246
|
-
o >
|
|
246
|
+
o > c && l.push([c, o]), i < a && l.push([i, a]);
|
|
247
247
|
}
|
|
248
248
|
r = l;
|
|
249
249
|
}
|
|
@@ -275,37 +275,36 @@ class d {
|
|
|
275
275
|
return this;
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
|
-
const
|
|
278
|
+
const I = (e) => {
|
|
279
279
|
const t = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm, n = [];
|
|
280
280
|
let s;
|
|
281
281
|
for (; (s = t.exec(e)) !== null; ) {
|
|
282
|
-
const r = [s.index, s.index + s[0].length], o =
|
|
282
|
+
const r = [s.index, s.index + s[0].length], o = Xe(s[0]).trim();
|
|
283
283
|
n.push({ range: r, value: o });
|
|
284
284
|
}
|
|
285
285
|
return n;
|
|
286
|
-
},
|
|
287
|
-
"
|
|
286
|
+
}, Xe = (e) => e.startsWith("//") ? e.slice(2) : e.startsWith("/*") ? e.slice(2, -2) : e.startsWith("<!--") ? e.slice(4, -3) : e, Ve = [
|
|
287
|
+
"(pd)",
|
|
288
|
+
"(p↓)",
|
|
289
|
+
"(parkdown)",
|
|
288
290
|
"pd:",
|
|
291
|
+
"p↓:",
|
|
289
292
|
"parkdown:"
|
|
290
|
-
],
|
|
291
|
-
"splice(delete?: number, insert?: string)"
|
|
292
|
-
];
|
|
293
|
-
N(Xe);
|
|
294
|
-
const ce = (e, t) => e.range[0] - t.range[0], X = (e, t, n) => (n ?? P(e)).filter(({ value: s }) => s.split(" ").includes(t)).sort(ce), te = (e) => ({
|
|
293
|
+
], ue = (e, t) => e.range[0] - t.range[0], X = (e, t, n) => (n ?? I(e)).filter(({ value: s }) => s.split(" ").includes(t)).sort(ue), te = (e) => ({
|
|
295
294
|
isSpace: e === " ",
|
|
296
295
|
isNewline: e === `
|
|
297
296
|
` || e === void 0
|
|
298
|
-
}), ne = (e) =>
|
|
299
|
-
const o = (b, y) => t.slice(0, b) + t.slice(y), i = te(t[n - 1]), l = te(t[s]),
|
|
300
|
-
let
|
|
301
|
-
for (;
|
|
302
|
-
`; )
|
|
297
|
+
}), ne = (e) => Ve.flatMap((t) => X(e, t)).sort((t, n) => t.range[0] - n.range[0]).reverse().reduce((t, { range: [n, s], value: r }) => {
|
|
298
|
+
const o = (b, y) => t.slice(0, b) + t.slice(y), i = te(t[n - 1]), l = te(t[s]), c = s === t.length;
|
|
299
|
+
let a = n;
|
|
300
|
+
for (; a > 0 && t[a - 1] !== `
|
|
301
|
+
`; ) a--;
|
|
303
302
|
let u = s;
|
|
304
303
|
for (; u < t.length && t[u] !== `
|
|
305
304
|
`; ) u++;
|
|
306
|
-
const p = t.slice(
|
|
307
|
-
return i.isNewline && l.isNewline ? o(n - (
|
|
308
|
-
}, e),
|
|
305
|
+
const p = t.slice(a, n).trim() === "" && t.slice(s, u).trim() === "";
|
|
306
|
+
return i.isNewline && l.isNewline ? o(n - (c ? 1 : 0), s + 1) : i.isNewline || p ? o(a, s + (l.isSpace || l.isNewline ? 1 : 0)) : o(n - (i.isSpace ? 1 : 0), s);
|
|
307
|
+
}, e), Je = [
|
|
309
308
|
/**
|
|
310
309
|
* Extract regions from the retrieved content between comments that INCLUDE the specified ids.
|
|
311
310
|
* @param id The id of the comment to extract.
|
|
@@ -410,143 +409,145 @@ const ce = (e, t) => e.range[0] - t.range[0], X = (e, t, n) => (n ?? P(e)).filte
|
|
|
410
409
|
* Helpful when trying to determine fine-grained edits (e.g. trimming, splicing, etc.).
|
|
411
410
|
*/
|
|
412
411
|
"debug()"
|
|
413
|
-
],
|
|
412
|
+
], Ze = R(Je), $ = (e, t, n) => {
|
|
414
413
|
const s = X(e, t, n), r = [];
|
|
415
414
|
for (let o = 0; o < s.length - 1; o += 2)
|
|
416
415
|
r.push([s[o], s[o + 1]]);
|
|
417
416
|
return r;
|
|
418
|
-
},
|
|
417
|
+
}, Ke = (e, t, n) => new d(...X(e, t, n).map(({ range: s }) => s)), P = (e) => Ae(e).trim(), se = (e, t) => e[t] !== void 0 && /[^\S\r\n]/.test(e[t]), re = (e, t) => Math.max(0, Math.min(e.length, t)), Ye = (e, ...t) => {
|
|
419
418
|
if (t.length === 0) return e;
|
|
420
|
-
const n =
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
s.
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
419
|
+
const n = I(e);
|
|
420
|
+
return P(
|
|
421
|
+
new d(...t.flatMap(
|
|
422
|
+
(s) => $(e, s, n).map(([{ range: [r] }, { range: [, o] }]) => {
|
|
423
|
+
for (; se(e, r); ) r--;
|
|
424
|
+
for (; se(e, o); ) o++;
|
|
425
|
+
return [re(e, r), re(e, o)];
|
|
426
|
+
})
|
|
427
|
+
)).slice(e)
|
|
428
|
+
);
|
|
429
|
+
}, et = (e, ...t) => {
|
|
429
430
|
if (t.length === 0) return e;
|
|
430
|
-
const n =
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
},
|
|
431
|
+
const n = I(e);
|
|
432
|
+
return P(
|
|
433
|
+
new d([0, e.length]).subtract(
|
|
434
|
+
new d(...t.flatMap(
|
|
435
|
+
(s) => $(e, s, n).map(([{ range: [, r] }, { range: [o] }]) => [r, o])
|
|
436
|
+
))
|
|
437
|
+
).slice(e)
|
|
438
|
+
);
|
|
439
|
+
}, tt = (e, t, n, s) => {
|
|
439
440
|
if (!t) return e;
|
|
440
441
|
let r = "", o = 0;
|
|
441
442
|
for (const [i, l] of $(e, t))
|
|
442
|
-
r += e.slice(o, i.range[1]), r +=
|
|
443
|
-
return r += e.slice(o),
|
|
444
|
-
new d([0, r.length]).subtract(
|
|
443
|
+
r += e.slice(o, i.range[1]), r += W(n ?? i.value, s), o = l.range[0];
|
|
444
|
+
return r += e.slice(o), P(
|
|
445
|
+
new d([0, r.length]).subtract(Ke(r, t)).slice(r)
|
|
445
446
|
);
|
|
446
|
-
},
|
|
447
|
+
}, nt = (e, t, n, s, r, o) => {
|
|
447
448
|
if (!t) return e;
|
|
448
|
-
const i = !(s === void 0 || s < 0), l = r ?
|
|
449
|
-
return $(e, t,
|
|
450
|
-
const y = new d(),
|
|
451
|
-
let S = Math.abs(
|
|
449
|
+
const i = !(s === void 0 || s < 0), l = r ? W(r, o) : "", c = s ?? 0, a = I(e), u = new d(...a.map(({ range: p }) => p));
|
|
450
|
+
return $(e, t, a).map((p) => p[n === "start" ? 0 : 1]).sort(ue).reverse().reduce((p, { range: b }) => {
|
|
451
|
+
const y = new d(), k = i ? 1 : -1;
|
|
452
|
+
let S = Math.abs(c), m = i ? b[1] : b[0];
|
|
452
453
|
for (; S > 0 && m < p.length && m >= 0; )
|
|
453
|
-
u.test(m) || (y.push(m), S--), m +=
|
|
454
|
+
u.test(m) || (y.push(m), S--), m += k;
|
|
454
455
|
return m = Math.min(Math.max(0, m), p.length), p = p.slice(0, m) + l + p.slice(m), new d([0, p.length]).subtract(y.offset(i ? 0 : l.length)).slice(p);
|
|
455
456
|
}, e);
|
|
456
|
-
},
|
|
457
|
+
}, st = (e, t, n, s, r) => {
|
|
457
458
|
let o = "", i = 0;
|
|
458
|
-
[n, s] = [n, s ?? ""].map((
|
|
459
|
+
[n, s] = [n, s ?? ""].map((c) => W(c, r));
|
|
459
460
|
const l = t ? $(e, t) : [[{ range: [0, 0] }, { range: [e.length, e.length] }]];
|
|
460
|
-
for (const [
|
|
461
|
-
o += e.slice(i,
|
|
461
|
+
for (const [c, a] of l)
|
|
462
|
+
o += e.slice(i, c.range[1]), o += e.slice(c.range[1], a.range[0]).replaceAll(n, s), i = a.range[0];
|
|
462
463
|
return o += e.slice(i), o;
|
|
463
|
-
},
|
|
464
|
+
}, rt = (e, t) => {
|
|
464
465
|
if (!t) return e;
|
|
465
466
|
let n = "", s = 0;
|
|
466
467
|
for (const [r, o] of $(e, t))
|
|
467
468
|
n += e.slice(s, r.range[1]), n += e.slice(r.range[1], o.range[0]).replaceAll(/[\s\n]+/g, " "), s = o.range[0];
|
|
468
469
|
return n += e.slice(s), n;
|
|
469
|
-
},
|
|
470
|
-
var o, i, l,
|
|
470
|
+
}, oe = (e, t, n) => {
|
|
471
|
+
var o, i, l, c;
|
|
471
472
|
if (!t) return e;
|
|
472
|
-
const s = (
|
|
473
|
-
for (const [
|
|
473
|
+
const s = (a) => /\s/.test(e[a]), r = new d();
|
|
474
|
+
for (const [a, u] of $(e, t)) {
|
|
474
475
|
if ((o = n.start) != null && o.left) {
|
|
475
|
-
let p =
|
|
476
|
+
let p = a.range[0] - 1;
|
|
476
477
|
for (; s(p); ) r.push(p--);
|
|
477
478
|
}
|
|
478
479
|
if ((i = n.start) != null && i.right) {
|
|
479
|
-
let p =
|
|
480
|
+
let p = a.range[1];
|
|
480
481
|
for (; s(p); ) r.push(p++);
|
|
481
482
|
}
|
|
482
483
|
if ((l = n.end) != null && l.left) {
|
|
483
484
|
let p = u.range[0] - 1;
|
|
484
485
|
for (; s(p); ) r.push(p--);
|
|
485
486
|
}
|
|
486
|
-
if ((
|
|
487
|
+
if ((c = n.end) != null && c.right) {
|
|
487
488
|
let p = u.range[1];
|
|
488
489
|
for (; s(p); ) r.push(p++);
|
|
489
490
|
}
|
|
490
491
|
}
|
|
491
492
|
return new d([0, e.length]).subtract(r).slice(e);
|
|
492
|
-
},
|
|
493
|
+
}, ot = (e, t, n) => {
|
|
493
494
|
if (!t) return ne(e);
|
|
494
|
-
const s =
|
|
495
|
+
const s = Ze(t);
|
|
495
496
|
switch (s.name) {
|
|
496
497
|
case "extract":
|
|
497
|
-
e =
|
|
498
|
+
e = Ye(e, s.id, ...F(s));
|
|
498
499
|
break;
|
|
499
500
|
case "remove":
|
|
500
|
-
e =
|
|
501
|
+
e = et(e, s.id, ...F(s));
|
|
501
502
|
break;
|
|
502
503
|
case "replace":
|
|
503
|
-
e =
|
|
504
|
+
e = tt(e, s.id, s.with, s.space);
|
|
504
505
|
break;
|
|
505
506
|
case "splice-start":
|
|
506
507
|
case "splice-end": {
|
|
507
|
-
const { deleteCount: r, insert: o, space: i, id: l } = s,
|
|
508
|
-
e =
|
|
508
|
+
const { deleteCount: r, insert: o, space: i, id: l } = s, c = s.name === "splice-start" ? "start" : "end";
|
|
509
|
+
e = nt(e, l, c, r, o, i);
|
|
509
510
|
break;
|
|
510
511
|
}
|
|
511
512
|
case "trim-start":
|
|
512
513
|
case "trim-end": {
|
|
513
514
|
const { left: r, right: o, id: i } = s, l = s.name === "trim-start" ? "start" : "end";
|
|
514
|
-
e =
|
|
515
|
+
e = oe(e, i, { [l]: { left: r ?? !0, right: o ?? !0 } });
|
|
515
516
|
break;
|
|
516
517
|
}
|
|
517
518
|
case "trim": {
|
|
518
519
|
const { inside: r, outside: o, id: i } = s;
|
|
519
|
-
e =
|
|
520
|
+
e = oe(e, i, { start: { left: o ?? !0, right: r ?? !0 }, end: { left: r ?? !0, right: o ?? !0 } });
|
|
520
521
|
break;
|
|
521
522
|
}
|
|
522
523
|
case "single-line":
|
|
523
|
-
e =
|
|
524
|
+
e = rt(e, s.id);
|
|
524
525
|
break;
|
|
525
526
|
case "remap":
|
|
526
|
-
e =
|
|
527
|
+
e = st(e, s.id, s.from, s.to, s.space);
|
|
527
528
|
break;
|
|
528
529
|
}
|
|
529
|
-
return e = n && s.name !== "debug" ? ne(e) : e, n ?
|
|
530
|
-
},
|
|
530
|
+
return s.name === "debug" && console.log("debug!!!", s), e = n && s.name !== "debug" ? ne(e) : e, n ? P(e) : e;
|
|
531
|
+
}, it = [
|
|
531
532
|
"recipe(id: string)"
|
|
532
|
-
],
|
|
533
|
+
], lt = [
|
|
533
534
|
"recipe(id: string, 0?: string, 1?: string, 2?: string)"
|
|
534
|
-
],
|
|
535
|
-
register:
|
|
536
|
-
apply:
|
|
537
|
-
},
|
|
535
|
+
], ie = {
|
|
536
|
+
register: R(it),
|
|
537
|
+
apply: R(lt)
|
|
538
|
+
}, N = class N {
|
|
538
539
|
constructor() {
|
|
539
|
-
|
|
540
|
+
_(this, "recipes", /* @__PURE__ */ new Map());
|
|
540
541
|
}
|
|
541
542
|
tryStore(t) {
|
|
542
|
-
const n =
|
|
543
|
+
const n = N.Entries(this.apply(t));
|
|
543
544
|
for (let s = 0; s < n.length; s++) {
|
|
544
545
|
const [r, o] = n[s];
|
|
545
546
|
if (r !== "register") continue;
|
|
546
|
-
const i =
|
|
547
|
+
const i = ie.register(o);
|
|
547
548
|
switch (i.name) {
|
|
548
549
|
case "recipe":
|
|
549
|
-
const l = n.slice(s + 1).filter(([
|
|
550
|
+
const l = n.slice(s + 1).filter(([c]) => c !== "register").map(([c, a]) => `${c}=${a}`).join("&");
|
|
550
551
|
this.recipes.set(i.id, l);
|
|
551
552
|
break;
|
|
552
553
|
default:
|
|
@@ -555,17 +556,17 @@ const ce = (e, t) => e.range[0] - t.range[0], X = (e, t, n) => (n ?? P(e)).filte
|
|
|
555
556
|
}
|
|
556
557
|
}
|
|
557
558
|
apply(t) {
|
|
558
|
-
const n =
|
|
559
|
+
const n = N.Entries(t), s = [];
|
|
559
560
|
for (let r = 0; r < n.length; r++) {
|
|
560
561
|
const [o, i] = n[r];
|
|
561
562
|
if (o !== "apply") {
|
|
562
563
|
s.push(`${o}=${i}`);
|
|
563
564
|
continue;
|
|
564
565
|
}
|
|
565
|
-
const l =
|
|
566
|
+
const l = ie.apply(i);
|
|
566
567
|
switch (l.name) {
|
|
567
568
|
case "recipe":
|
|
568
|
-
s.push(this.recipes.get(l.id)), s.push(...F(l).map((
|
|
569
|
+
s.push(this.recipes.get(l.id)), s.push(...F(l).map((c) => this.recipes.get(c)));
|
|
569
570
|
break;
|
|
570
571
|
default:
|
|
571
572
|
throw new Error(`Unknown registration: ${l.name}`);
|
|
@@ -574,31 +575,31 @@ const ce = (e, t) => e.range[0] - t.range[0], X = (e, t, n) => (n ?? P(e)).filte
|
|
|
574
575
|
return s.join("&");
|
|
575
576
|
}
|
|
576
577
|
};
|
|
577
|
-
|
|
578
|
-
let H =
|
|
579
|
-
const
|
|
578
|
+
_(N, "Entries", (t) => Array.from(new URLSearchParams(t).entries()));
|
|
579
|
+
let H = N;
|
|
580
|
+
const at = ["http", "./", "../", "?"], ct = ({ url: e }) => at.some((t) => e.startsWith(t)), pt = (e) => G(e) && Re(e) && ct(e), me = ({ url: e }, t) => `[](${t ? A(t, e) : e})`, h = {
|
|
580
581
|
_open: "<!--",
|
|
581
582
|
_close: "-->",
|
|
582
583
|
_flag: "p↓",
|
|
583
584
|
get begin() {
|
|
584
|
-
return
|
|
585
|
+
return M(h._open, h._flag, "BEGIN", h._close);
|
|
585
586
|
},
|
|
586
587
|
get end() {
|
|
587
|
-
return
|
|
588
|
+
return M(h._open, h._flag, "END", h._close);
|
|
588
589
|
},
|
|
589
590
|
lengthOf(e) {
|
|
590
591
|
const t = `lines: ${e.split(`
|
|
591
592
|
`).length}`, n = `chars: ${e.length}`;
|
|
592
|
-
return
|
|
593
|
+
return M(h._open, h._flag, "length", t, n, h._close);
|
|
593
594
|
}
|
|
594
|
-
},
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
595
|
+
}, le = (e) => (t) => G(t) && t.value === h[e], ut = ({ position: e, url: t, siblingCount: n }, s) => ({ position: e, url: t, headingDepth: s, inline: n >= 1 }), mt = ({ position: { start: e }, url: t, siblingCount: n }, { position: { end: s } }, r) => ({ position: { start: e, end: s }, url: t, headingDepth: r, inline: n >= 1 }), ht = (e, t, n) => (e.inline ? M : We)(
|
|
596
|
+
me(e, n),
|
|
597
|
+
h.begin,
|
|
598
|
+
h.lengthOf(t),
|
|
598
599
|
t,
|
|
599
|
-
|
|
600
|
+
h.end
|
|
600
601
|
), gt = (e) => {
|
|
601
|
-
const t =
|
|
602
|
+
const t = O(e, "heading").reduce((n, { position: s, depth: r }) => n.set(s.start.line, r), /* @__PURE__ */ new Map());
|
|
602
603
|
return (n) => {
|
|
603
604
|
for (let s = n.position.start.line; s >= 1; s--) {
|
|
604
605
|
const r = t.get(s);
|
|
@@ -610,7 +611,7 @@ const lt = ["http", "./", "../", "?"], at = ({ url: e }) => lt.some((t) => e.sta
|
|
|
610
611
|
openingCommentDoesNotFollowLink: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),
|
|
611
612
|
closingCommentNotMatchedToOpening: ({ position: { start: e } }) => new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),
|
|
612
613
|
openingCommentNotClosed: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)
|
|
613
|
-
},
|
|
614
|
+
}, dt = (e, t) => {
|
|
614
615
|
const n = [], s = [
|
|
615
616
|
...e.map((o) => ({ node: o, type: "open" })),
|
|
616
617
|
...t.map((o) => ({ node: o, type: "close" }))
|
|
@@ -628,13 +629,13 @@ const lt = ["http", "./", "../", "?"], at = ({ url: e }) => lt.some((t) => e.sta
|
|
|
628
629
|
if (r.length > 0)
|
|
629
630
|
throw T.openingCommentNotClosed(r[0].node);
|
|
630
631
|
return n;
|
|
631
|
-
},
|
|
632
|
+
}, ft = (e, t, n) => {
|
|
632
633
|
const s = [...t].sort(f), r = [];
|
|
633
634
|
return [...n].sort((o, i) => f.reverse(o.open, i.open)).forEach((o) => {
|
|
634
635
|
for (; s.length > 0; ) {
|
|
635
636
|
const i = s.pop();
|
|
636
637
|
if (i.position.start.offset < o.open.position.start.offset) {
|
|
637
|
-
if (
|
|
638
|
+
if (Te(e, i, o.open).trim() !== "")
|
|
638
639
|
throw T.openingCommentDoesNotFollowLink(o.open);
|
|
639
640
|
return r.push([i, o]);
|
|
640
641
|
}
|
|
@@ -642,50 +643,50 @@ const lt = ["http", "./", "../", "?"], at = ({ url: e }) => lt.some((t) => e.sta
|
|
|
642
643
|
}
|
|
643
644
|
throw T.openingCommentDoesNotFollowLink(o.open);
|
|
644
645
|
}), r.push(...s.reverse()), r.reverse();
|
|
645
|
-
},
|
|
646
|
+
}, he = (e, t) => {
|
|
646
647
|
t ?? (t = z.md(e));
|
|
647
|
-
const n = gt(t), s =
|
|
648
|
-
return
|
|
649
|
-
},
|
|
648
|
+
const n = gt(t), s = O(t, "link").filter(pt), r = O(t, "html").sort(f), o = r.filter(le("begin")), i = r.filter(le("end")), l = dt(o, i);
|
|
649
|
+
return ft(e, s, l).map((a) => Array.isArray(a) ? mt(a[0], a[1].close, n(a[0])) : ut(a, n(a)));
|
|
650
|
+
}, vt = (e, { url: t }) => (n) => e(A(Q(t), n)), ge = (...e) => {
|
|
650
651
|
const t = e.reduce((n, s) => n + s, 0);
|
|
651
652
|
return Math.min(Math.max(t, 1), 6);
|
|
652
|
-
},
|
|
653
|
+
}, wt = (e, t, n) => {
|
|
653
654
|
if (t === 0) return e;
|
|
654
655
|
n ?? (n = z.md(e));
|
|
655
|
-
const s =
|
|
656
|
+
const s = O(n, "heading"), r = e.split(`
|
|
656
657
|
`);
|
|
657
658
|
for (const o of s) {
|
|
658
|
-
const { depth: i, position: { start: l, end:
|
|
659
|
-
r[l.line - 1] = p, o.depth =
|
|
659
|
+
const { depth: i, position: { start: l, end: c } } = o, a = ge(i, t), u = r[l.line - 1].slice(i, c.column), p = "#".repeat(a) + u;
|
|
660
|
+
r[l.line - 1] = p, o.depth = a;
|
|
660
661
|
}
|
|
661
662
|
return r.join(`
|
|
662
663
|
`);
|
|
663
|
-
},
|
|
664
|
+
}, de = (e) => he(e).reverse().sort(f.reverse).reduce((t, n) => pe(t, me(n), n), e), fe = (e, t, n, s, r) => {
|
|
664
665
|
try {
|
|
665
|
-
e =
|
|
666
|
-
const o = z.md(e), i = new H(), l =
|
|
667
|
-
return l.filter(({ url:
|
|
668
|
-
var
|
|
669
|
-
const { url:
|
|
670
|
-
if (!
|
|
671
|
-
if (
|
|
672
|
-
const m = p.split(".").pop() ?? "", j = Q(
|
|
673
|
-
let
|
|
674
|
-
const x = new
|
|
666
|
+
e = de(e), e = wt(e, t);
|
|
667
|
+
const o = z.md(e), i = new H(), l = he(e, o).sort(f);
|
|
668
|
+
return l.filter(({ url: c }) => c.startsWith("?")).forEach(({ url: c }) => i.tryStore(c)), l.reverse().map((c) => {
|
|
669
|
+
var k, S;
|
|
670
|
+
const { url: a, headingDepth: u } = c, [p, ...b] = xe(a).split("?"), y = i.apply(b.join("?"));
|
|
671
|
+
if (!a.startsWith("?"))
|
|
672
|
+
if (a.startsWith("./") || a.startsWith("../")) {
|
|
673
|
+
const m = p.split(".").pop() ?? "", j = Q(a), V = A(j, p);
|
|
674
|
+
let g = n(V);
|
|
675
|
+
const x = new _e(y), D = (k = ((w) => {
|
|
675
676
|
const v = Array.from(x.entries()).filter(([C]) => C === w).map(([C, q]) => q);
|
|
676
677
|
return v.length >= 1 ? v.join(",") : void 0;
|
|
677
|
-
})("region")) == null ? void 0 :
|
|
678
|
-
|
|
679
|
-
(w, v, C, { length: q }) =>
|
|
680
|
-
|
|
681
|
-
)) ??
|
|
682
|
-
const
|
|
683
|
-
let { inline: L } =
|
|
684
|
-
if (
|
|
678
|
+
})("region")) == null ? void 0 : k.split(J);
|
|
679
|
+
g = (D == null ? void 0 : D.reduce(
|
|
680
|
+
(w, v, C, { length: q }) => ot(w, v, C === q - 1),
|
|
681
|
+
g
|
|
682
|
+
)) ?? g;
|
|
683
|
+
const $e = x.has("skip"), be = x.get("heading") ?? 0, ye = x.has("inline");
|
|
684
|
+
let { inline: L } = c;
|
|
685
|
+
if (ye && (L = !0), !$e)
|
|
685
686
|
if (m === "md") {
|
|
686
|
-
const w =
|
|
687
|
-
|
|
688
|
-
|
|
687
|
+
const w = vt(n, c), v = r ? A(r, j) : j, C = ge(u, Number(be));
|
|
688
|
+
g = fe(
|
|
689
|
+
g,
|
|
689
690
|
/** p↓: ... */
|
|
690
691
|
C,
|
|
691
692
|
w,
|
|
@@ -693,38 +694,38 @@ const lt = ["http", "./", "../", "?"], at = ({ url: e }) => lt.some((t) => e.sta
|
|
|
693
694
|
v
|
|
694
695
|
/** p↓: ... */
|
|
695
696
|
);
|
|
696
|
-
} else /^(js|ts)x?|svelte$/i.test(m) && (
|
|
697
|
-
|
|
697
|
+
} else /^(js|ts)x?|svelte$/i.test(m) && (g = ee(
|
|
698
|
+
g,
|
|
698
699
|
"code",
|
|
699
700
|
/** p↓: ... */
|
|
700
701
|
{ extension: m, inline: L }
|
|
701
702
|
/** p↓: ... */
|
|
702
703
|
));
|
|
703
704
|
const U = (S = x.get("wrap")) == null ? void 0 : S.split(J);
|
|
704
|
-
return
|
|
705
|
-
} else throw
|
|
706
|
-
}).filter(Boolean).reduce((
|
|
705
|
+
return g = (U == null ? void 0 : U.reduce((w, v) => ee(w, v, { extension: m, inline: L }), g)) ?? g, { target: c, content: ht(c, g, r) };
|
|
706
|
+
} else throw a.startsWith("http") ? new Error("External web links are not implemented yet") : new Error(`Unsupported link type: ${a}`);
|
|
707
|
+
}).filter(Boolean).reduce((c, { target: a, content: u }) => pe(c, u, a), e);
|
|
707
708
|
} catch (o) {
|
|
708
709
|
throw new Error(`Error populating inclusions in file ${s ?? "(unknown)"}: ${o}`);
|
|
709
710
|
}
|
|
710
|
-
},
|
|
711
|
-
const t =
|
|
712
|
-
return { content:
|
|
713
|
-
},
|
|
714
|
-
const { dir: s, path: r, content: o } =
|
|
715
|
-
n == null || n.unwatch(r), n == null || n.once("change", (
|
|
716
|
-
console.log(`Change detected in "${
|
|
711
|
+
}, ve = (e) => Se(e, "utf-8"), we = (e) => {
|
|
712
|
+
const t = ce(e), n = Q(t);
|
|
713
|
+
return { content: ve(t), dir: n, path: t };
|
|
714
|
+
}, $t = (e, t = !0, n) => {
|
|
715
|
+
const { dir: s, path: r, content: o } = we(e);
|
|
716
|
+
n == null || n.unwatch(r), n == null || n.once("change", (c, a) => {
|
|
717
|
+
console.log(`Change detected in "${c}". Regenerating "${r}"...`), $t(e, t, n);
|
|
717
718
|
});
|
|
718
|
-
const l =
|
|
719
|
-
const
|
|
720
|
-
return n == null || n.add(
|
|
719
|
+
const l = fe(o, 0, (c) => {
|
|
720
|
+
const a = ce(s, Pe(c));
|
|
721
|
+
return n == null || n.add(a), ve(a);
|
|
721
722
|
}, r);
|
|
722
|
-
return t &&
|
|
723
|
-
},
|
|
724
|
-
const { path: s, content: r } =
|
|
725
|
-
return t &&
|
|
723
|
+
return t && ae(r, l), n == null || n.add(r), l;
|
|
724
|
+
}, Mt = (e, t = !0, n) => {
|
|
725
|
+
const { path: s, content: r } = we(e), o = de(r);
|
|
726
|
+
return t && ae(s, o), o;
|
|
726
727
|
};
|
|
727
728
|
export {
|
|
728
|
-
|
|
729
|
-
|
|
729
|
+
Mt as depopulateMarkdownInclusions,
|
|
730
|
+
$t as populateMarkdownInclusions
|
|
730
731
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
(function(d
|
|
2
|
-
`),
|
|
3
|
-
`}},
|
|
1
|
+
(function(u,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("node:fs"),require("node:path"),require("node:url"),require("unified"),require("remark-parse"),require("unist-util-visit"),require("ts-dedent")):typeof define=="function"&&define.amd?define(["exports","node:fs","node:path","node:url","unified","remark-parse","unist-util-visit","ts-dedent"],d):(u=typeof globalThis<"u"?globalThis:u||self,d(u.index={},u.node_fs,u.node_path,u.node_url,u.unified,u.remarkParse,u.unistUtilVisit,u.tsDedent))})(this,function(u,d,h,ye,$e,Ce,be,Ee){"use strict";var ht=Object.defineProperty;var gt=(u,d,h)=>d in u?ht(u,d,{enumerable:!0,configurable:!0,writable:!0,value:h}):u[d]=h;var T=(u,d,h)=>gt(u,typeof d!="symbol"?d+"":d,h);const y=(e,t)=>e.position.start.offset-t.position.start.offset;y.reverse=(e,t)=>y(t,e);const D=e=>e.position!==void 0&&e.position.start.offset!==void 0&&e.position.end.offset!==void 0,Se=$e.unified().use(Ce),L={md:e=>Se.parse(e)},j=(e,t)=>{const n=[];return be.visit(e,(s,r,i)=>{if(s.type!=="root"){if(t&&s.type!==t)return;if(D(s)){const o=((i==null?void 0:i.children.length)??0)-1;n.push({...s,siblingIndex:r,siblingCount:o})}}}),n},ke=e=>e.children.length===0,J=(e,t,...n)=>{if(n.length===0)throw new Error("No nodes to replace content from");n.sort(y);const s=n.at(0),r=n.at(-1);return e.slice(0,s.position.start.offset)+t+e.slice(r.position.end.offset)},xe=(e,t,n)=>{const s=Math.min(t.position.end.offset,n.position.end.offset),r=Math.max(t.position.start.offset,n.position.start.offset);return e.slice(s,r)},A=(...e)=>e.join(" "),Ne=(...e)=>e.join(`
|
|
2
|
+
`),Me=e=>{const t=e.split("?");return t.length>1?[t.slice(0,-1).join("?"),t.at(-1)]:[e,""]},_e=e=>Me(e)[0],Z=/,\s*(?![^()]*\))/,K={reserved:{semi:";",slash:"/",question:"?",colon:":",at:"@",equal:"=",and:"&"},unsafe:{quote:'"',angle:"<",unangle:">",hash:"#",percent:"%",curly:"{",uncurly:"}",pipe:"|",back:"\\",carrot:"^",tilde:"~",square:"[",unsquare:"]",tick:"`",line:`
|
|
3
|
+
`}},Te="-",Y={static:[["'''",'"'],["''","'"],[/parkdown:\s+/g,""],[/p↓:\s+/g,""]],url:[...Object.entries(K.unsafe),...Object.entries(K.reserved)]},ee=(e,[t,n])=>e.replaceAll(t,n),O=(e,t=Te)=>{const n=Y.static.reduce(ee,e);return Y.url.map(([s,r])=>[t+s+t,r]).reduce(ee,n).replaceAll(t," ")},je=["string","number","boolean"],Ae=e=>je.includes(e),Oe=/^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/,Ie=e=>{const t=e.match(Oe);if(!t)throw new Error(`Invalid invocation: ${e}`);const[,n,s=""]=t;if(!s.trim())return{name:n,parameters:[]};const r=Re(s);return{name:n,parameters:r}},qe=(e,t)=>{for(let n=t+1;n<e.length;n++)if(e[n]!==void 0)return!1;return!0},Re=e=>{const t=[];let n="",s=!1;for(let r=0;r<e.length;r++){const i=e[r],o=i==="'";if(o&&e.at(r+1)==="'"){const l=e.at(r+2)==="'";s=!s,n+=l?"'''":"''",r+=l?2:1}else o?(s=!s,n+=i):i===","&&!s?(t.push(n.trim()),n=""):n+=i}return t.push(n.trim()),t.map(r=>r===""?void 0:r?We(r):void 0).filter((r,i,o)=>r!==void 0||!qe(o,i))},We=e=>{const t=e.length>=2&&e[0]==="'"&&e.at(-1)==="'",n=t&&e.length>=4&&e[1]==="'"&&e.at(-2)==="'";return!t||n?e:e.slice(1,-1)},Pe=e=>{const t=/^([\w-_]+)(?:\(([^)]*)\))?/,n=e.match(t);if(!n)return{name:e};const[,s,r]=n;if(!r)return{name:s};const i=/([\w-_]+)(\?)?:\s*([^,]+)/g,o=[];let l;for(;(l=i.exec(r))!==null;){const[,c,a,m]=l,p=m.trim();if(!Ae(p))throw new Error(`Unsupported type: ${p}`);o.push({name:c,optional:a==="?",type:p})}return{name:s,parameters:o}},I=e=>{const t=e.map(Pe).reduce((n,{name:s,parameters:r})=>n.set(s,r),new Map);return n=>{const{name:s,parameters:r}=Ie(n);if(!t.has(s))throw new Error(`Unknown method: ${s}`);const i=t.get(s);if(i===void 0)return{name:s};if(r.length>i.length){const o=i.filter(({optional:c})=>!c).length,l=o===i.length?o.toString():`${o} - ${i.length}`;throw new Error(`Too many parameters: ${r.length} for method '${s}' (expected: ${l})`)}return i.reduce((o,{name:l,optional:c,type:a},m)=>{const p=r[m];if(p===void 0){if(c)return o;throw new Error(`Missing required parameter: ${l} for method '${s}'`)}switch(a){case"string":o[l]=p;break;case"number":case"boolean":o[l]=JSON.parse(p);break}if(typeof o[l]!==a)throw new Error(`Invalid type: ${l} must be ${a}, got ${typeof o[l]} for method '${s}'`);return o},{name:s})}},U=e=>Object.entries(e).filter(([t])=>t!=="name"&&!isNaN(Number(t))).map(([t,n])=>n),De=I(["code(lang?: string, meta?: string)","quote()","dropdown(summary: string, open?: boolean, space?: string)"]),E=(e,t=1)=>`
|
|
4
4
|
`.repeat(t)+e+`
|
|
5
|
-
`.repeat(t),B=(e,t,n)=>`<${t}${n?` ${n}`:""}>${E(e)}</${t}>`,te=(e,t,n)=>{const s=
|
|
5
|
+
`.repeat(t),B=(e,t,n)=>`<${t}${n?` ${n}`:""}>${E(e)}</${t}>`,te=(e,t,n)=>{const s=De(t);switch(s.name){case"code":if(!s.lang&&!s.meta&&(n==null?void 0:n.inline)&&!e.includes(`
|
|
6
6
|
`))return`\`${e}\``;const i=s.lang??(n==null?void 0:n.extension)??"",o=s.meta?` ${s.meta}`:"";return E(`\`\`\`${i}${o}${E(e)}\`\`\``);case"quote":return n!=null&&n.inline&&!e.includes(`
|
|
7
7
|
|
|
8
|
-
`)?`> ${e}`:E(B(E(e),"blockquote"));case"dropdown":const l=B(
|
|
9
|
-
`),"details",s.open?"open":void 0))}};class
|
|
10
|
-
`||e===void 0}),re=e=>
|
|
11
|
-
`;)
|
|
12
|
-
`;)
|
|
13
|
-
|
|
14
|
-
`)
|
|
15
|
-
`);
|
|
16
|
-
`)},ue=e=>ce(e).reverse().sort($.reverse).reduce((t,n)=>J(t,le(n),n),e),de=(e,t,n,s,r)=>{try{e=ue(e),e=lt(e,t);const i=L.md(e),o=new H,l=ce(e,i).sort($);return l.filter(({url:a})=>a.startsWith("?")).forEach(({url:a})=>o.tryStore(a)),l.reverse().map(a=>{var W,T;const{url:c,headingDepth:u}=a,[p,...S]=g.basename(c).split("?"),k=o.apply(S.join("?"));if(!c.startsWith("?"))if(c.startsWith("./")||c.startsWith("../")){const h=p.split(".").pop()??"",Q=g.dirname(c),fe=g.join(Q,p);let w=n(fe);const _=new ve.URLSearchParams(k),G=(W=(b=>{const y=Array.from(_.entries()).filter(([x])=>x===b).map(([x,X])=>X);return y.length>=1?y.join(","):void 0})("region"))==null?void 0:W.split(Z);w=(G==null?void 0:G.reduce((b,y,x,{length:X})=>Ve(b,y,x===X-1),w))??w;const ct=_.has("skip"),pt=_.get("heading")??0,ut=_.has("inline");let{inline:z}=a;if(ut&&(z=!0),!ct)if(h==="md"){const b=ot(n,a),y=r?g.join(r,Q):Q,x=pe(u,Number(pt));w=de(w,x,b,fe,y)}else/^(js|ts)x?|svelte$/i.test(h)&&(w=te(w,"code",{extension:h,inline:z}));const V=(T=_.get("wrap"))==null?void 0:T.split(Z);return w=(V==null?void 0:V.reduce((b,y)=>te(b,y,{extension:h,inline:z}),w))??w,{target:a,content:nt(a,w,r)}}else throw c.startsWith("http")?new Error("External web links are not implemented yet"):new Error(`Unsupported link type: ${c}`)}).filter(Boolean).reduce((a,{target:c,content:u})=>J(a,u,c),e)}catch(i){throw new Error(`Error populating inclusions in file ${s??"(unknown)"}: ${i}`)}},me=e=>m.readFileSync(e,"utf-8"),ge=e=>{const t=g.resolve(e),n=g.dirname(t);return{content:me(t),dir:n,path:t}},he=(e,t=!0,n)=>{const{dir:s,path:r,content:i}=ge(e);n==null||n.unwatch(r),n==null||n.once("change",(a,c)=>{console.log(`Change detected in "${a}". Regenerating "${r}"...`),he(e,t,n)});const l=de(i,0,a=>{const c=g.resolve(s,Ne(a));return n==null||n.add(c),me(c)},r);return t&&m.writeFileSync(r,l),n==null||n.add(r),l},at=(e,t=!0,n)=>{const{path:s,content:r}=ge(e),i=ue(r);return t&&m.writeFileSync(s,i),i};d.depopulateMarkdownInclusions=at,d.populateMarkdownInclusions=he,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
8
|
+
`)?`> ${e}`:E(B(E(e),"blockquote"));case"dropdown":const l=B(O(s.summary),"summary");return E(B([l,e].join(`
|
|
9
|
+
`),"details",s.open?"open":void 0))}};class w{constructor(...t){T(this,"_intervals",[]);T(this,"collapsed",!0);for(const[n,s]of t)this.push(n,s)}get intervals(){return this._intervals}push(t,n){return n??(n=t+1),this._intervals.push([Math.min(t,n),Math.max(t,n)]),this.collapsed=!1,this}combine(t){for(const[n,s]of t.intervals)this.push(n,s);return this}collapse(t=!1){const{_intervals:n,collapsed:s}=this;if(s&&!t||!n.length)return this;n.sort((l,c)=>l[0]-c[0]);const r=[];let[i,o]=n[0];for(let l=1;l<n.length;l++){const[c,a]=n[l];c<=o?o=Math.max(o,a):(r.push([i,o]),i=c,o=a)}return r.push([i,o]),this._intervals=r,this.collapsed=!0,this}subtract(t){this.collapse(),t.collapse();const{_intervals:n}=this,{_intervals:s}=t;if(!n.length||!s.length)return this;let r=[...n];for(const[i,o]of s){const l=[];for(const[c,a]of r){if(o<=c||i>=a){l.push([c,a]);continue}i>c&&l.push([c,i]),o<a&&l.push([o,a])}r=l}return this._intervals=r,this.collapse(!0),this}test(t,n="head"){const{_intervals:s}=this;switch(n){case"head":return s.some(([r,i])=>t>=r&&t<i);case"tail":return s.some(([r,i])=>t>r&&t<=i);case"both":return s.some(([r,i])=>t>=r&&t<=i);case"none":return s.some(([r,i])=>t>r&&t<i)}}slice(t){this.collapse();const n=[];for(const[s,r]of this._intervals)n.push(t.slice(s,r));return n.filter(Boolean).join("")}offset(t){for(const n of this._intervals)n[0]+=t,n[1]+=t;return this}}const q=e=>{const t=/(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm,n=[];let s;for(;(s=t.exec(e))!==null;){const r=[s.index,s.index+s[0].length],i=Le(s[0]).trim();n.push({range:r,value:i})}return n},Le=e=>e.startsWith("//")?e.slice(2):e.startsWith("/*")?e.slice(2,-2):e.startsWith("<!--")?e.slice(4,-3):e,Ue=["(pd)","(p↓)","(parkdown)","pd:","p↓:","parkdown:"],ne=(e,t)=>e.range[0]-t.range[0],F=(e,t,n)=>(n??q(e)).filter(({value:s})=>s.split(" ").includes(t)).sort(ne),se=e=>({isSpace:e===" ",isNewline:e===`
|
|
10
|
+
`||e===void 0}),re=e=>Ue.flatMap(t=>F(e,t)).sort((t,n)=>t.range[0]-n.range[0]).reverse().reduce((t,{range:[n,s],value:r})=>{const i=(S,k)=>t.slice(0,S)+t.slice(k),o=se(t[n-1]),l=se(t[s]),c=s===t.length;let a=n;for(;a>0&&t[a-1]!==`
|
|
11
|
+
`;)a--;let m=s;for(;m<t.length&&t[m]!==`
|
|
12
|
+
`;)m++;const p=t.slice(a,n).trim()===""&&t.slice(s,m).trim()==="";return o.isNewline&&l.isNewline?i(n-(c?1:0),s+1):o.isNewline||p?i(a,s+(l.isSpace||l.isNewline?1:0)):i(n-(o.isSpace?1:0),s)},e),Be=I(["extract(id: string, 0?: string, 1?: string, 2?: string)","remove(id: string, 0?: string, 1?: string, 2?: string)","replace(id: string, with?: string, space?: string)","remap(id?: string, from: string, to?: string, space?: string)","single-line(id: string, includeBoundaries?: boolean)","trim(id: string, inside?: boolean, outside?: boolean)","trim-start(id: string, left?: boolean, right?: boolean)","trim-end(id: string, left?: boolean, right?: boolean)","splice-start(id: string, deleteCount?: number, insert?: string, space?: string)","splice-end(id: string, deleteCount?: number, insert?: string, space?: string)","debug()"]),C=(e,t,n)=>{const s=F(e,t,n),r=[];for(let i=0;i<s.length-1;i+=2)r.push([s[i],s[i+1]]);return r},Fe=(e,t,n)=>new w(...F(e,t,n).map(({range:s})=>s)),R=e=>Ee.dedent(e).trim(),ie=(e,t)=>e[t]!==void 0&&/[^\S\r\n]/.test(e[t]),oe=(e,t)=>Math.max(0,Math.min(e.length,t)),He=(e,...t)=>{if(t.length===0)return e;const n=q(e);return R(new w(...t.flatMap(s=>C(e,s,n).map(([{range:[r]},{range:[,i]}])=>{for(;ie(e,r);)r--;for(;ie(e,i);)i++;return[oe(e,r),oe(e,i)]}))).slice(e))},Qe=(e,...t)=>{if(t.length===0)return e;const n=q(e);return R(new w([0,e.length]).subtract(new w(...t.flatMap(s=>C(e,s,n).map(([{range:[,r]},{range:[i]}])=>[r,i])))).slice(e))},Ge=(e,t,n,s)=>{if(!t)return e;let r="",i=0;for(const[o,l]of C(e,t))r+=e.slice(i,o.range[1]),r+=O(n??o.value,s),i=l.range[0];return r+=e.slice(i),R(new w([0,r.length]).subtract(Fe(r,t)).slice(r))},ze=(e,t,n,s,r,i)=>{if(!t)return e;const o=!(s===void 0||s<0),l=r?O(r,i):"",c=s??0,a=q(e),m=new w(...a.map(({range:p})=>p));return C(e,t,a).map(p=>p[n==="start"?0:1]).sort(ne).reverse().reduce((p,{range:S})=>{const k=new w,P=o?1:-1;let M=Math.abs(c),g=o?S[1]:S[0];for(;M>0&&g<p.length&&g>=0;)m.test(g)||(k.push(g),M--),g+=P;return g=Math.min(Math.max(0,g),p.length),p=p.slice(0,g)+l+p.slice(g),new w([0,p.length]).subtract(k.offset(o?0:l.length)).slice(p)},e)},Ve=(e,t,n,s,r)=>{let i="",o=0;[n,s]=[n,s??""].map(c=>O(c,r));const l=t?C(e,t):[[{range:[0,0]},{range:[e.length,e.length]}]];for(const[c,a]of l)i+=e.slice(o,c.range[1]),i+=e.slice(c.range[1],a.range[0]).replaceAll(n,s),o=a.range[0];return i+=e.slice(o),i},Xe=(e,t)=>{if(!t)return e;let n="",s=0;for(const[r,i]of C(e,t))n+=e.slice(s,r.range[1]),n+=e.slice(r.range[1],i.range[0]).replaceAll(/[\s\n]+/g," "),s=i.range[0];return n+=e.slice(s),n},le=(e,t,n)=>{var i,o,l,c;if(!t)return e;const s=a=>/\s/.test(e[a]),r=new w;for(const[a,m]of C(e,t)){if((i=n.start)!=null&&i.left){let p=a.range[0]-1;for(;s(p);)r.push(p--)}if((o=n.start)!=null&&o.right){let p=a.range[1];for(;s(p);)r.push(p++)}if((l=n.end)!=null&&l.left){let p=m.range[0]-1;for(;s(p);)r.push(p--)}if((c=n.end)!=null&&c.right){let p=m.range[1];for(;s(p);)r.push(p++)}}return new w([0,e.length]).subtract(r).slice(e)},Je=(e,t,n)=>{if(!t)return re(e);const s=Be(t);switch(s.name){case"extract":e=He(e,s.id,...U(s));break;case"remove":e=Qe(e,s.id,...U(s));break;case"replace":e=Ge(e,s.id,s.with,s.space);break;case"splice-start":case"splice-end":{const{deleteCount:r,insert:i,space:o,id:l}=s,c=s.name==="splice-start"?"start":"end";e=ze(e,l,c,r,i,o);break}case"trim-start":case"trim-end":{const{left:r,right:i,id:o}=s,l=s.name==="trim-start"?"start":"end";e=le(e,o,{[l]:{left:r??!0,right:i??!0}});break}case"trim":{const{inside:r,outside:i,id:o}=s;e=le(e,o,{start:{left:i??!0,right:r??!0},end:{left:r??!0,right:i??!0}});break}case"single-line":e=Xe(e,s.id);break;case"remap":e=Ve(e,s.id,s.from,s.to,s.space);break}return s.name==="debug"&&console.log("debug!!!",s),e=n&&s.name!=="debug"?re(e):e,n?R(e):e},Ze=["recipe(id: string)"],Ke=["recipe(id: string, 0?: string, 1?: string, 2?: string)"],ae={register:I(Ze),apply:I(Ke)},N=class N{constructor(){T(this,"recipes",new Map)}tryStore(t){const n=N.Entries(this.apply(t));for(let s=0;s<n.length;s++){const[r,i]=n[s];if(r!=="register")continue;const o=ae.register(i);switch(o.name){case"recipe":const l=n.slice(s+1).filter(([c])=>c!=="register").map(([c,a])=>`${c}=${a}`).join("&");this.recipes.set(o.id,l);break;default:throw new Error(`Unknown registration: ${o.name}`)}}}apply(t){const n=N.Entries(t),s=[];for(let r=0;r<n.length;r++){const[i,o]=n[r];if(i!=="apply"){s.push(`${i}=${o}`);continue}const l=ae.apply(o);switch(l.name){case"recipe":s.push(this.recipes.get(l.id)),s.push(...U(l).map(c=>this.recipes.get(c)));break;default:throw new Error(`Unknown registration: ${l.name}`)}}return s.join("&")}};T(N,"Entries",t=>Array.from(new URLSearchParams(t).entries()));let H=N;const Ye=["http","./","../","?"],et=({url:e})=>Ye.some(t=>e.startsWith(t)),tt=e=>D(e)&&ke(e)&&et(e),ce=({url:e},t)=>`[](${t?h.join(t,e):e})`,f={_open:"<!--",_close:"-->",_flag:"p↓",get begin(){return A(f._open,f._flag,"BEGIN",f._close)},get end(){return A(f._open,f._flag,"END",f._close)},lengthOf(e){const t=`lines: ${e.split(`
|
|
13
|
+
`).length}`,n=`chars: ${e.length}`;return A(f._open,f._flag,"length",t,n,f._close)}},pe=e=>t=>D(t)&&t.value===f[e],nt=({position:e,url:t,siblingCount:n},s)=>({position:e,url:t,headingDepth:s,inline:n>=1}),st=({position:{start:e},url:t,siblingCount:n},{position:{end:s}},r)=>({position:{start:e,end:s},url:t,headingDepth:r,inline:n>=1}),rt=(e,t,n)=>(e.inline?A:Ne)(ce(e,n),f.begin,f.lengthOf(t),t,f.end),it=e=>{const t=j(e,"heading").reduce((n,{position:s,depth:r})=>n.set(s.start.line,r),new Map);return n=>{for(let s=n.position.start.line;s>=1;s--){const r=t.get(s);if(r)return r}return 0}},W={openingCommentDoesNotFollowLink:({position:{start:e}})=>new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),closingCommentNotMatchedToOpening:({position:{start:e}})=>new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),openingCommentNotClosed:({position:{start:e}})=>new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)},ot=(e,t)=>{const n=[],s=[...e.map(i=>({node:i,type:"open"})),...t.map(i=>({node:i,type:"close"}))].sort((i,o)=>y(i.node,o.node)),r=[];for(const i of s)if(i.type==="open")r.push(i);else{const o=i.node;if(r.length===0)throw W.closingCommentNotMatchedToOpening(o);const l=r.pop().node;if(r.length>0)continue;n.push({open:l,close:o})}if(r.length>0)throw W.openingCommentNotClosed(r[0].node);return n},lt=(e,t,n)=>{const s=[...t].sort(y),r=[];return[...n].sort((i,o)=>y.reverse(i.open,o.open)).forEach(i=>{for(;s.length>0;){const o=s.pop();if(o.position.start.offset<i.open.position.start.offset){if(xe(e,o,i.open).trim()!=="")throw W.openingCommentDoesNotFollowLink(i.open);return r.push([o,i])}r.push(o)}throw W.openingCommentDoesNotFollowLink(i.open)}),r.push(...s.reverse()),r.reverse()},ue=(e,t)=>{t??(t=L.md(e));const n=it(t),s=j(t,"link").filter(tt),r=j(t,"html").sort(y),i=r.filter(pe("begin")),o=r.filter(pe("end")),l=ot(i,o);return lt(e,s,l).map(a=>Array.isArray(a)?st(a[0],a[1].close,n(a[0])):nt(a,n(a)))},at=(e,{url:t})=>n=>e(h.join(h.dirname(t),n)),me=(...e)=>{const t=e.reduce((n,s)=>n+s,0);return Math.min(Math.max(t,1),6)},ct=(e,t,n)=>{if(t===0)return e;n??(n=L.md(e));const s=j(n,"heading"),r=e.split(`
|
|
14
|
+
`);for(const i of s){const{depth:o,position:{start:l,end:c}}=i,a=me(o,t),m=r[l.line-1].slice(o,c.column),p="#".repeat(a)+m;r[l.line-1]=p,i.depth=a}return r.join(`
|
|
15
|
+
`)},de=e=>ue(e).reverse().sort(y.reverse).reduce((t,n)=>J(t,ce(n),n),e),he=(e,t,n,s,r)=>{try{e=de(e),e=ct(e,t);const i=L.md(e),o=new H,l=ue(e,i).sort(y);return l.filter(({url:c})=>c.startsWith("?")).forEach(({url:c})=>o.tryStore(c)),l.reverse().map(c=>{var P,M;const{url:a,headingDepth:m}=c,[p,...S]=h.basename(a).split("?"),k=o.apply(S.join("?"));if(!a.startsWith("?"))if(a.startsWith("./")||a.startsWith("../")){const g=p.split(".").pop()??"",Q=h.dirname(a),we=h.join(Q,p);let v=n(we);const _=new ye.URLSearchParams(k),G=(P=(b=>{const $=Array.from(_.entries()).filter(([x])=>x===b).map(([x,X])=>X);return $.length>=1?$.join(","):void 0})("region"))==null?void 0:P.split(Z);v=(G==null?void 0:G.reduce((b,$,x,{length:X})=>Je(b,$,x===X-1),v))??v;const ut=_.has("skip"),mt=_.get("heading")??0,dt=_.has("inline");let{inline:z}=c;if(dt&&(z=!0),!ut)if(g==="md"){const b=at(n,c),$=r?h.join(r,Q):Q,x=me(m,Number(mt));v=he(v,x,b,we,$)}else/^(js|ts)x?|svelte$/i.test(g)&&(v=te(v,"code",{extension:g,inline:z}));const V=(M=_.get("wrap"))==null?void 0:M.split(Z);return v=(V==null?void 0:V.reduce((b,$)=>te(b,$,{extension:g,inline:z}),v))??v,{target:c,content:rt(c,v,r)}}else throw a.startsWith("http")?new Error("External web links are not implemented yet"):new Error(`Unsupported link type: ${a}`)}).filter(Boolean).reduce((c,{target:a,content:m})=>J(c,m,a),e)}catch(i){throw new Error(`Error populating inclusions in file ${s??"(unknown)"}: ${i}`)}},ge=e=>d.readFileSync(e,"utf-8"),fe=e=>{const t=h.resolve(e),n=h.dirname(t);return{content:ge(t),dir:n,path:t}},ve=(e,t=!0,n)=>{const{dir:s,path:r,content:i}=fe(e);n==null||n.unwatch(r),n==null||n.once("change",(c,a)=>{console.log(`Change detected in "${c}". Regenerating "${r}"...`),ve(e,t,n)});const l=he(i,0,c=>{const a=h.resolve(s,_e(c));return n==null||n.add(a),ge(a)},r);return t&&d.writeFileSync(r,l),n==null||n.add(r),l},pt=(e,t=!0,n)=>{const{path:s,content:r}=fe(e),i=de(r);return t&&d.writeFileSync(s,i),i};u.depopulateMarkdownInclusions=pt,u.populateMarkdownInclusions=ve,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|