@p-buddy/parkdown 0.0.12 → 0.0.13
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 +12 -11
- package/dist/index.d.ts +6 -2
- package/dist/index.js +228 -221
- package/dist/index.umd.cjs +13 -13
- package/package.json +2 -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: 601 chars: 19975 -->
|
|
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`).
|
|
@@ -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: 388 chars: 15269 -->
|
|
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.
|
|
@@ -290,6 +290,8 @@ Specifiers will be searched for within the file's comments, and are expected to
|
|
|
290
290
|
/** some-specifier */
|
|
291
291
|
```
|
|
292
292
|
|
|
293
|
+
Identifiers will be searched for within the text of a comment split by spaces (i.e. `some-specifier` is a single identifier, but `some specifier` represents two separate identifiers).
|
|
294
|
+
|
|
293
295
|
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:
|
|
294
296
|
|
|
295
297
|
- `[](<url>?region=extract(some-specifier))`
|
|
@@ -314,7 +316,7 @@ Please see the [full explanation](#query-parameters-with-function-like-apis) to
|
|
|
314
316
|
|
|
315
317
|
[](src/region.ts?region=extract(definition))
|
|
316
318
|
<!-- p↓ BEGIN -->
|
|
317
|
-
<!-- p↓ length lines:
|
|
319
|
+
<!-- p↓ length lines: 64 chars: 3718 -->
|
|
318
320
|
|
|
319
321
|
```ts
|
|
320
322
|
const definitions = [
|
|
@@ -348,6 +350,34 @@ const definitions = [
|
|
|
348
350
|
* @example [](<url>?region=replace(specifier,new_content,_)
|
|
349
351
|
*/
|
|
350
352
|
"replace(id: string, with?: string, space?: string)",
|
|
353
|
+
/**
|
|
354
|
+
* Splice the retrieved content at the boundary of a comment region (which must INCLUDE the specified id).
|
|
355
|
+
*
|
|
356
|
+
* **NOTE:** Unlike `extract`, `remove`, and `replace`, `splice` does remove the comment from the content after processing.
|
|
357
|
+
* @param id The id of the comment regions to act on.
|
|
358
|
+
* @param deleteCount The number of characters to delete at either the beginning or end of the comment region.
|
|
359
|
+
* Specifying a number greater than or equal to 0 indicates the action should be taken at the end of the comment region.
|
|
360
|
+
* Specifying undefined or a number less than 0 indicates the action should be taken at the beginning of the comment region.
|
|
361
|
+
* @param insert The content to insert.
|
|
362
|
+
* @param space The space character to use between words in the content to insert (defaults to `-`).
|
|
363
|
+
* @example [](<url>?region=splice(specifier,-1)) // Delete one character at the beginning of the comment region.
|
|
364
|
+
* @example [](<url>?region=splice(specifier,undefined,new-content)) // Insert at the beginning of the comment region.
|
|
365
|
+
* @example [](<url>?region=splice(specifier,0,new-content)) // Insert at the end of the comment region.
|
|
366
|
+
* @example [](<url>?region=splice(specifier,1,new-content)) // Delete one character at the end of the comment region and insert.
|
|
367
|
+
*/
|
|
368
|
+
"splice(id: string, deleteCount?: number, insert?: string, space?: string)",
|
|
369
|
+
/**
|
|
370
|
+
* Remap the content within a comment region (which must INCLUDE the specified id).
|
|
371
|
+
*
|
|
372
|
+
* **NOTE:** Unlike `extract`, `remove`, and `replace`, `remap` does not remove the comment from the content after processing.
|
|
373
|
+
* @param id The id of the comment regions to act on.
|
|
374
|
+
* @param from The content to replace.
|
|
375
|
+
* @param to The content to replace with.
|
|
376
|
+
* @param space The space character to use between words in the content to replace (defaults to `-`).
|
|
377
|
+
* @example [](<url>?region=remap(specifier,hello-world,hello-universe))
|
|
378
|
+
* @example [](<url>?region=remap(specifier,hello_world,hello_universe,_)
|
|
379
|
+
*/
|
|
380
|
+
"remap(id: string, from: string, to?: string, space?: string)",
|
|
351
381
|
]
|
|
352
382
|
```
|
|
353
383
|
|
|
@@ -359,7 +389,7 @@ Skip the default processing behavior for the given type of file.
|
|
|
359
389
|
|
|
360
390
|
[](src/include.ts?wrap=dropdown(See-default-processing-behavior.)®ion=extract(Default-Behavior),replace(...))
|
|
361
391
|
<!-- p↓ BEGIN -->
|
|
362
|
-
<!-- p↓ length lines:
|
|
392
|
+
<!-- p↓ length lines: 17 chars: 273 -->
|
|
363
393
|
|
|
364
394
|
<details>
|
|
365
395
|
<summary>
|
|
@@ -368,15 +398,11 @@ See default processing behavior.
|
|
|
368
398
|
|
|
369
399
|
```ts
|
|
370
400
|
if (extension === "md") {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const relative = basePath ? join(basePath, dir) : dir;
|
|
374
|
-
const depth = clampHeadingSum(headingDepth, Number(headingModfiier));
|
|
375
|
-
|
|
376
|
-
content = recursivelyPopulateInclusions(content, depth, getContent, path, relative);
|
|
401
|
+
* ...
|
|
402
|
+
content = recursivelyPopulateInclusions(content, * ...);
|
|
377
403
|
}
|
|
378
404
|
else if (/^(js|ts)x?|svelte$/i.test(extension))
|
|
379
|
-
content = wrap(content, "code",
|
|
405
|
+
content = wrap(content, "code", * ...);
|
|
380
406
|
```
|
|
381
407
|
|
|
382
408
|
</details>
|
|
@@ -512,7 +538,7 @@ const definitions = [
|
|
|
512
538
|
|
|
513
539
|
[](.assets/api.md?heading=-1)
|
|
514
540
|
<!-- p↓ BEGIN -->
|
|
515
|
-
<!-- p↓ length lines:
|
|
541
|
+
<!-- p↓ length lines: 105 chars: 4993 -->
|
|
516
542
|
#### Query Parameters with Function-like APIs
|
|
517
543
|
|
|
518
544
|
Some query parameters have more complex APIs, which are defined by a collection of typescript function singatures (limited to only `string`, `boolean`, and `number` arguments), like:
|
|
@@ -543,7 +569,7 @@ Please note the following:
|
|
|
543
569
|
|
|
544
570
|
[](src/utils.ts?region=extract(url))
|
|
545
571
|
<!-- p↓ BEGIN -->
|
|
546
|
-
<!-- p↓ length lines:
|
|
572
|
+
<!-- p↓ length lines: 32 chars: 518 -->
|
|
547
573
|
|
|
548
574
|
```ts
|
|
549
575
|
const urlCharacters = {
|
|
@@ -571,6 +597,7 @@ const urlCharacters = {
|
|
|
571
597
|
["square"]: "[",
|
|
572
598
|
["unsquare"]: "]",
|
|
573
599
|
["tick"]: "`",
|
|
600
|
+
["line"]: "\n",
|
|
574
601
|
}
|
|
575
602
|
}
|
|
576
603
|
```
|
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Command as
|
|
3
|
-
import { populateMarkdownInclusions as l, depopulateMarkdownInclusions as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
[
|
|
2
|
+
import { Command as r } from "@commander-js/extra-typings";
|
|
3
|
+
import { populateMarkdownInclusions as l, depopulateMarkdownInclusions as a } from "@p-buddy/parkdown";
|
|
4
|
+
import f from "chokidar";
|
|
5
|
+
const c = "0.0.13", 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
|
+
t.length === 0 && t.push("README.md");
|
|
7
|
+
const m = [
|
|
8
|
+
[l, !u],
|
|
9
|
+
[a, d]
|
|
9
10
|
];
|
|
10
|
-
for (const [
|
|
11
|
-
for (const o of
|
|
12
|
-
const
|
|
13
|
-
|
|
11
|
+
for (const [e] of m.filter(([o, s]) => s))
|
|
12
|
+
for (const o of t) {
|
|
13
|
+
const s = h ? f.watch([], { persistent: !0, awaitWriteFinish: !0, atomic: !0 }) : void 0, i = e(o, !n, s);
|
|
14
|
+
n && console.log(i);
|
|
14
15
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { default as default_2 } from 'chokidar';
|
|
2
2
|
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const depopulateMarkdownInclusions: (file: string, writeFile?: boolean, watcher?: Watcher) => string;
|
|
4
|
+
|
|
5
|
+
export declare const populateMarkdownInclusions: (file: string, writeFile?: boolean, watcher?: Watcher) => string;
|
|
6
|
+
|
|
7
|
+
declare type Watcher = ReturnType<typeof default_2.watch>;
|
|
4
8
|
|
|
5
9
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
var
|
|
2
|
-
var de = (e,
|
|
3
|
-
var F = (e,
|
|
4
|
-
import { writeFileSync as K, readFileSync as
|
|
5
|
-
import { basename as
|
|
6
|
-
import { URLSearchParams as
|
|
7
|
-
import { unified as
|
|
1
|
+
var he = Object.defineProperty;
|
|
2
|
+
var de = (e, n, t) => n in e ? he(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
|
|
3
|
+
var F = (e, n, t) => de(e, typeof n != "symbol" ? n + "" : n, t);
|
|
4
|
+
import { writeFileSync as K, readFileSync as ve } from "node:fs";
|
|
5
|
+
import { basename as $e, dirname as A, join as y, resolve as Y } from "node:path";
|
|
6
|
+
import { URLSearchParams as Ce } from "node:url";
|
|
7
|
+
import { unified as we } from "unified";
|
|
8
8
|
import Ee from "remark-parse";
|
|
9
9
|
import { visit as ye } from "unist-util-visit";
|
|
10
10
|
import { dedent as j } from "ts-dedent";
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const D = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, Se =
|
|
11
|
+
const f = (e, n) => e.position.start.offset - n.position.start.offset;
|
|
12
|
+
f.reverse = (e, n) => f(n, e);
|
|
13
|
+
const D = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, Se = we().use(Ee), I = {
|
|
14
14
|
md: (e) => Se.parse(e)
|
|
15
|
-
}, S = (e,
|
|
16
|
-
const
|
|
15
|
+
}, S = (e, n) => {
|
|
16
|
+
const t = [];
|
|
17
17
|
return ye(e, (s, o, r) => {
|
|
18
18
|
if (s.type !== "root") {
|
|
19
|
-
if (
|
|
19
|
+
if (n && s.type !== n) return;
|
|
20
20
|
if (D(s)) {
|
|
21
21
|
const i = ((r == null ? void 0 : r.children.length) ?? 0) - 1;
|
|
22
|
-
|
|
22
|
+
t.push({ ...s, siblingIndex: o, siblingCount: i });
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
}),
|
|
26
|
-
}, xe = (e) => e.children.length === 0, ee = (e,
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
const s =
|
|
30
|
-
return e.slice(0, s.position.start.offset) +
|
|
31
|
-
}, Ne = (e,
|
|
32
|
-
const s = Math.min(
|
|
25
|
+
}), t;
|
|
26
|
+
}, xe = (e) => e.children.length === 0, ee = (e, n, ...t) => {
|
|
27
|
+
if (t.length === 0) throw new Error("No nodes to replace content from");
|
|
28
|
+
t.sort(f);
|
|
29
|
+
const s = t.at(0), o = t.at(-1);
|
|
30
|
+
return e.slice(0, s.position.start.offset) + n + e.slice(o.position.end.offset);
|
|
31
|
+
}, Ne = (e, n, t) => {
|
|
32
|
+
const s = Math.min(n.position.end.offset, t.position.end.offset), o = Math.max(n.position.start.offset, t.position.start.offset);
|
|
33
33
|
return e.slice(s, o);
|
|
34
34
|
}, E = (...e) => e.join(" "), be = (...e) => e.join(`
|
|
35
35
|
`), ke = (e) => {
|
|
36
|
-
const
|
|
37
|
-
return
|
|
36
|
+
const n = e.split("?");
|
|
37
|
+
return n.length > 1 ? [n.slice(0, -1).join("?"), n.at(-1)] : [e, ""];
|
|
38
38
|
}, Me = (e) => ke(e)[0];
|
|
39
39
|
class d {
|
|
40
|
-
constructor(...
|
|
40
|
+
constructor(...n) {
|
|
41
41
|
F(this, "intervals", []);
|
|
42
|
-
for (const [
|
|
43
|
-
this.push(
|
|
42
|
+
for (const [t, s] of n)
|
|
43
|
+
this.push(t, s);
|
|
44
44
|
}
|
|
45
|
-
push(
|
|
46
|
-
this.intervals.push([Math.min(
|
|
45
|
+
push(n, t) {
|
|
46
|
+
this.intervals.push([Math.min(n, t), Math.max(n, t)]);
|
|
47
47
|
}
|
|
48
|
-
combine(
|
|
49
|
-
this.intervals.push(...
|
|
48
|
+
combine(n) {
|
|
49
|
+
this.intervals.push(...n.intervals);
|
|
50
50
|
}
|
|
51
51
|
collapse() {
|
|
52
|
-
const { intervals:
|
|
53
|
-
if (!
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
let [s, o] =
|
|
57
|
-
for (let r = 1; r <
|
|
58
|
-
const [i,
|
|
59
|
-
i <= o ? o = Math.max(o,
|
|
52
|
+
const { intervals: n } = this;
|
|
53
|
+
if (!n.length) return this.intervals = [];
|
|
54
|
+
n.sort((r, i) => r[0] - i[0]);
|
|
55
|
+
const t = [];
|
|
56
|
+
let [s, o] = n[0];
|
|
57
|
+
for (let r = 1; r < n.length; r++) {
|
|
58
|
+
const [i, l] = n[r];
|
|
59
|
+
i <= o ? o = Math.max(o, l) : (t.push([s, o]), s = i, o = l);
|
|
60
60
|
}
|
|
61
|
-
return
|
|
61
|
+
return t.push([s, o]), this.intervals = t;
|
|
62
62
|
}
|
|
63
|
-
subtract(
|
|
64
|
-
const { intervals:
|
|
65
|
-
if (!
|
|
66
|
-
let o = [...
|
|
63
|
+
subtract(n) {
|
|
64
|
+
const { intervals: t } = this, { intervals: s } = n;
|
|
65
|
+
if (!t.length || !s.length) return t;
|
|
66
|
+
let o = [...t];
|
|
67
67
|
for (const [r, i] of s) {
|
|
68
|
-
const
|
|
69
|
-
for (const [
|
|
70
|
-
if (i <=
|
|
71
|
-
|
|
68
|
+
const l = [];
|
|
69
|
+
for (const [c, a] of o) {
|
|
70
|
+
if (i <= c || r >= a) {
|
|
71
|
+
l.push([c, a]);
|
|
72
72
|
continue;
|
|
73
73
|
}
|
|
74
|
-
r >
|
|
74
|
+
r > c && l.push([c, r]), i < a && l.push([i, a]);
|
|
75
75
|
}
|
|
76
|
-
o =
|
|
76
|
+
o = l;
|
|
77
77
|
}
|
|
78
78
|
return this.intervals = o;
|
|
79
79
|
}
|
|
@@ -117,84 +117,84 @@ const U = /,\s*(?![^()]*\))/, H = {
|
|
|
117
117
|
...Object.entries(H.unsafe),
|
|
118
118
|
...Object.entries(H.reserved)
|
|
119
119
|
]
|
|
120
|
-
}, Q = (e, [
|
|
121
|
-
const
|
|
122
|
-
return G.url.map(([s, o]) => [
|
|
123
|
-
},
|
|
124
|
-
const
|
|
125
|
-
if (!
|
|
126
|
-
const [,
|
|
127
|
-
if (!s.trim()) return { name:
|
|
120
|
+
}, Q = (e, [n, t]) => e.replaceAll(n, t), N = (e, n = _e) => {
|
|
121
|
+
const t = G.static.reduce(Q, e);
|
|
122
|
+
return G.url.map(([s, o]) => [n + s + n, o]).reduce(Q, t).replaceAll(n, " ");
|
|
123
|
+
}, Re = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), Oe = ["string", "number", "boolean"], Te = (e) => Oe.includes(e), Ae = /^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/, je = (e) => {
|
|
124
|
+
const n = e.match(Ae);
|
|
125
|
+
if (!n) throw new Error(`Invalid invocation: ${e}`);
|
|
126
|
+
const [, t, s = ""] = n;
|
|
127
|
+
if (!s.trim()) return { name: t, parameters: [] };
|
|
128
128
|
const o = Ie(s);
|
|
129
|
-
return { name:
|
|
130
|
-
}, De = (e,
|
|
131
|
-
for (let
|
|
132
|
-
if (e[
|
|
129
|
+
return { name: t, parameters: o };
|
|
130
|
+
}, De = (e, n) => {
|
|
131
|
+
for (let t = n + 1; t < e.length; t++)
|
|
132
|
+
if (e[t] !== void 0) return !1;
|
|
133
133
|
return !0;
|
|
134
134
|
}, Ie = (e) => {
|
|
135
|
-
const
|
|
136
|
-
let
|
|
135
|
+
const n = [];
|
|
136
|
+
let t = "", s = !1;
|
|
137
137
|
for (let o = 0; o < e.length; o++) {
|
|
138
138
|
const r = e[o], i = r === "'";
|
|
139
139
|
if (i && e.at(o + 1) === "'") {
|
|
140
|
-
const
|
|
141
|
-
s = !s,
|
|
142
|
-
} else i ? (s = !s,
|
|
140
|
+
const l = e.at(o + 2) === "'";
|
|
141
|
+
s = !s, t += l ? "'''" : "''", o += l ? 2 : 1;
|
|
142
|
+
} else i ? (s = !s, t += r) : r === "," && !s ? (n.push(t.trim()), t = "") : t += r;
|
|
143
143
|
}
|
|
144
|
-
return
|
|
144
|
+
return n.push(t.trim()), n.map((o) => o === "" ? void 0 : o ? Pe(o) : void 0).filter((o, r, i) => o !== void 0 || !De(i, r));
|
|
145
145
|
}, Pe = (e) => {
|
|
146
|
-
const
|
|
147
|
-
return !
|
|
146
|
+
const n = e.length >= 2 && e[0] === "'" && e.at(-1) === "'", t = n && e.length >= 4 && e[1] === "'" && e.at(-2) === "'";
|
|
147
|
+
return !n || t ? e : e.slice(1, -1);
|
|
148
148
|
}, We = (e) => {
|
|
149
|
-
const
|
|
150
|
-
if (!
|
|
151
|
-
const [, s, o] =
|
|
149
|
+
const n = /^(\w+)(?:\(([^)]*)\))?/, t = e.match(n);
|
|
150
|
+
if (!t) return { name: e };
|
|
151
|
+
const [, s, o] = t;
|
|
152
152
|
if (!o) return { name: s };
|
|
153
153
|
const r = /(\w+)(\?)?:\s*([^,]+)/g, i = [];
|
|
154
|
-
let
|
|
155
|
-
for (; (
|
|
156
|
-
const [,
|
|
154
|
+
let l;
|
|
155
|
+
for (; (l = r.exec(o)) !== null; ) {
|
|
156
|
+
const [, c, a, u] = l, p = u.trim();
|
|
157
157
|
if (!Te(p)) throw new Error(`Unsupported type: ${p}`);
|
|
158
|
-
i.push({ name:
|
|
158
|
+
i.push({ name: c, optional: a === "?", type: p });
|
|
159
159
|
}
|
|
160
160
|
return { name: s, parameters: i };
|
|
161
161
|
}, P = (e) => {
|
|
162
|
-
const
|
|
163
|
-
(
|
|
162
|
+
const n = e.map(We).reduce(
|
|
163
|
+
(t, { name: s, parameters: o }) => t.set(s, o),
|
|
164
164
|
/* @__PURE__ */ new Map()
|
|
165
165
|
);
|
|
166
|
-
return (
|
|
167
|
-
const { name: s, parameters: o } = je(
|
|
168
|
-
if (!
|
|
166
|
+
return (t) => {
|
|
167
|
+
const { name: s, parameters: o } = je(t);
|
|
168
|
+
if (!n.has(s))
|
|
169
169
|
throw new Error(`Unknown method: ${s}`);
|
|
170
|
-
const r =
|
|
170
|
+
const r = n.get(s);
|
|
171
171
|
if (r === void 0)
|
|
172
172
|
return { name: s };
|
|
173
173
|
if (o.length > r.length) {
|
|
174
|
-
const i = r.filter(({ optional:
|
|
175
|
-
throw new Error(`Too many parameters: ${o.length} for method '${s}' (expected: ${
|
|
174
|
+
const i = r.filter(({ optional: c }) => !c).length, l = i === r.length ? i.toString() : `${i} - ${r.length}`;
|
|
175
|
+
throw new Error(`Too many parameters: ${o.length} for method '${s}' (expected: ${l})`);
|
|
176
176
|
}
|
|
177
|
-
return r.reduce((i, { name:
|
|
177
|
+
return r.reduce((i, { name: l, optional: c, type: a }, u) => {
|
|
178
178
|
const p = o[u];
|
|
179
179
|
if (p === void 0) {
|
|
180
|
-
if (
|
|
181
|
-
throw new Error(`Missing required parameter: ${
|
|
180
|
+
if (c) return i;
|
|
181
|
+
throw new Error(`Missing required parameter: ${l} for method '${s}'`);
|
|
182
182
|
}
|
|
183
183
|
switch (a) {
|
|
184
184
|
case "string":
|
|
185
|
-
i[
|
|
185
|
+
i[l] = p;
|
|
186
186
|
break;
|
|
187
187
|
case "number":
|
|
188
188
|
case "boolean":
|
|
189
|
-
i[
|
|
189
|
+
i[l] = JSON.parse(p);
|
|
190
190
|
break;
|
|
191
191
|
}
|
|
192
|
-
if (typeof i[
|
|
193
|
-
throw new Error(`Invalid type: ${
|
|
192
|
+
if (typeof i[l] !== a)
|
|
193
|
+
throw new Error(`Invalid type: ${l} must be ${a}, got ${typeof i[l]} for method '${s}'`);
|
|
194
194
|
return i;
|
|
195
195
|
}, { name: s });
|
|
196
196
|
};
|
|
197
|
-
}, z = (e) => Object.entries(e).filter(([
|
|
197
|
+
}, z = (e) => Object.entries(e).filter(([n]) => n !== "name" && !isNaN(Number(n))).map(([n, t]) => t), Le = [
|
|
198
198
|
/**
|
|
199
199
|
* Wraps the content in a markdown-formatted code block.
|
|
200
200
|
* @param lang The language of the code block (defaults to the file extension).
|
|
@@ -224,34 +224,34 @@ const U = /,\s*(?![^()]*\))/, H = {
|
|
|
224
224
|
* @example [](<url>?wrap=dropdown(hello_world,,_))
|
|
225
225
|
*/
|
|
226
226
|
"dropdown(summary: string, open?: boolean, space?: string)"
|
|
227
|
-
], qe = P(Le),
|
|
228
|
-
`.repeat(
|
|
229
|
-
`.repeat(
|
|
230
|
-
const s = qe(
|
|
227
|
+
], qe = P(Le), h = (e, n = 1) => `
|
|
228
|
+
`.repeat(n) + e + `
|
|
229
|
+
`.repeat(n), T = (e, n, t) => `<${n}${t ? ` ${t}` : ""}>${h(e)}</${n}>`, X = (e, n, t) => {
|
|
230
|
+
const s = qe(n);
|
|
231
231
|
switch (s.name) {
|
|
232
232
|
case "code":
|
|
233
|
-
if (!s.lang && !s.meta && (
|
|
233
|
+
if (!s.lang && !s.meta && (t == null ? void 0 : t.inline) && !e.includes(`
|
|
234
234
|
`)) return `\`${e}\``;
|
|
235
|
-
const r = s.lang ?? (
|
|
236
|
-
return
|
|
235
|
+
const r = s.lang ?? (t == null ? void 0 : t.extension) ?? "", i = s.meta ? ` ${s.meta}` : "";
|
|
236
|
+
return h(`\`\`\`${r}${i}${h(e)}\`\`\``);
|
|
237
237
|
case "quote":
|
|
238
|
-
return
|
|
238
|
+
return t != null && t.inline && !e.includes(`
|
|
239
239
|
|
|
240
|
-
`) ? `> ${e}` :
|
|
240
|
+
`) ? `> ${e}` : h(T(h(e), "blockquote"));
|
|
241
241
|
case "dropdown":
|
|
242
|
-
const
|
|
243
|
-
return
|
|
242
|
+
const l = T(N(s.summary), "summary");
|
|
243
|
+
return h(T([l, e].join(`
|
|
244
244
|
`), "details", s.open ? "open" : void 0));
|
|
245
245
|
}
|
|
246
246
|
}, W = (e) => {
|
|
247
|
-
const
|
|
247
|
+
const n = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm, t = [];
|
|
248
248
|
let s;
|
|
249
|
-
for (; (s =
|
|
249
|
+
for (; (s = n.exec(e)) !== null; ) {
|
|
250
250
|
const o = [s.index, s.index + s[0].length], r = Be(s[0]).trim();
|
|
251
|
-
|
|
251
|
+
t.push({ range: o, value: r });
|
|
252
252
|
}
|
|
253
|
-
return
|
|
254
|
-
}, Be = (e) => e.startsWith("//") ? e.slice(2) : e.startsWith("/*") ? e.slice(2, -2) : e.startsWith("<!--") ? e.slice(4, -3) : e,
|
|
253
|
+
return t;
|
|
254
|
+
}, Be = (e) => e.startsWith("//") ? e.slice(2) : e.startsWith("/*") ? e.slice(2, -2) : e.startsWith("<!--") ? e.slice(4, -3) : e, ne = [
|
|
255
255
|
"p↓:",
|
|
256
256
|
"pd:",
|
|
257
257
|
"parkdown:"
|
|
@@ -259,19 +259,19 @@ const U = /,\s*(?![^()]*\))/, H = {
|
|
|
259
259
|
"splice(delete?: number, insert?: string)"
|
|
260
260
|
];
|
|
261
261
|
P(Fe);
|
|
262
|
-
const
|
|
262
|
+
const te = (e, n) => e.range[0] - n.range[0], se = (e, n, t) => (t ?? W(e)).filter(({ value: s }) => s.split(" ").includes(n)).sort(te), V = (e) => ({
|
|
263
263
|
isSpace: e === " ",
|
|
264
264
|
isNewline: e === `
|
|
265
265
|
` || e === void 0
|
|
266
|
-
}), J = (e) =>
|
|
267
|
-
const r = (p, b) =>
|
|
268
|
-
let a =
|
|
269
|
-
for (; a > 0 &&
|
|
266
|
+
}), J = (e) => ne.flatMap((n) => se(e, n)).sort((n, t) => n.range[0] - t.range[0]).reverse().reduce((n, { range: [t, s], value: o }) => {
|
|
267
|
+
const r = (p, b) => n.slice(0, p) + n.slice(b), i = V(n[t - 1]), l = V(n[s]), c = s === n.length;
|
|
268
|
+
let a = t;
|
|
269
|
+
for (; a > 0 && n[a - 1] !== `
|
|
270
270
|
`; ) a--;
|
|
271
|
-
const u =
|
|
272
|
-
return i.isNewline &&
|
|
271
|
+
const u = n.slice(a, t).trim() === "";
|
|
272
|
+
return i.isNewline && l.isNewline ? r(t - (c ? 1 : 0), s + 1) : i.isNewline || u ? r(a, s + (l.isSpace || l.isNewline ? 1 : 0)) : r(t - (i.isSpace ? 1 : 0), s);
|
|
273
273
|
}, e);
|
|
274
|
-
|
|
274
|
+
ne.map((e) => new RegExp(`^${Re(e)}(\\?[^\\s]+)`));
|
|
275
275
|
const Ue = [
|
|
276
276
|
/**
|
|
277
277
|
* Extract regions from the retrieved content between comments that INCLUDE the specified ids.
|
|
@@ -330,68 +330,68 @@ const Ue = [
|
|
|
330
330
|
* @example [](<url>?region=remap(specifier,hello-world,hello-universe))
|
|
331
331
|
* @example [](<url>?region=remap(specifier,hello_world,hello_universe,_)
|
|
332
332
|
*/
|
|
333
|
-
"remap(id: string, from: string, to
|
|
334
|
-
], He = P(Ue),
|
|
335
|
-
const s = se(e,
|
|
333
|
+
"remap(id: string, from: string, to?: string, space?: string)"
|
|
334
|
+
], He = P(Ue), v = (e, n, t) => {
|
|
335
|
+
const s = se(e, n, t), o = [];
|
|
336
336
|
for (let r = 0; r < s.length - 1; r += 2)
|
|
337
337
|
o.push([s[r], s[r + 1]]);
|
|
338
338
|
return o;
|
|
339
|
-
}, Ge = (e, ...
|
|
340
|
-
if (
|
|
341
|
-
const
|
|
342
|
-
for (const i of
|
|
343
|
-
for (const [
|
|
344
|
-
o.push(
|
|
345
|
-
const [a, ...u] = s([
|
|
346
|
-
r.push(
|
|
339
|
+
}, Ge = (e, ...n) => {
|
|
340
|
+
if (n.length === 0) return e;
|
|
341
|
+
const t = W(e), s = ([i, l]) => e.slice(i, l), o = new d(), r = new d();
|
|
342
|
+
for (const i of n)
|
|
343
|
+
for (const [l, c] of v(e, i, t)) {
|
|
344
|
+
o.push(l.range[1], c.range[0]);
|
|
345
|
+
const [a, ...u] = s([l.range[1], c.range[0]]), p = u[u.length - 1];
|
|
346
|
+
r.push(l.range[0], l.range[1] + (a.trim() ? 0 : 1)), r.push(c.range[0], c.range[1] + (p.trim() ? 0 : 1));
|
|
347
347
|
}
|
|
348
348
|
return o.collapse(), r.collapse(), j(
|
|
349
349
|
o.subtract(r).map(s).filter(Boolean).join("")
|
|
350
350
|
).trim();
|
|
351
|
-
}, Qe = (e, ...
|
|
352
|
-
if (
|
|
353
|
-
const
|
|
354
|
-
for (const i of
|
|
355
|
-
for (const [
|
|
356
|
-
const a = s([
|
|
357
|
-
o.push(
|
|
358
|
-
` ?
|
|
351
|
+
}, Qe = (e, ...n) => {
|
|
352
|
+
if (n.length === 0) return e;
|
|
353
|
+
const t = W(e), s = ([i, l]) => e.slice(i, l), o = new d();
|
|
354
|
+
for (const i of n)
|
|
355
|
+
for (const [l, c] of v(e, i, t)) {
|
|
356
|
+
const a = s([c.range[1], c.range[1] + 1]).at(-1);
|
|
357
|
+
o.push(l.range[0], a === `
|
|
358
|
+
` ? c.range[1] + 1 : c.range[1]);
|
|
359
359
|
}
|
|
360
360
|
o.collapse();
|
|
361
361
|
const r = new d([0, e.length]);
|
|
362
362
|
return r.subtract(o), j(
|
|
363
363
|
r.collapse().map(s).filter(Boolean).join("")
|
|
364
364
|
).trim();
|
|
365
|
-
}, ze = (e,
|
|
366
|
-
if (!
|
|
365
|
+
}, ze = (e, n, t, s) => {
|
|
366
|
+
if (!n) return e;
|
|
367
367
|
let o = "", r = 0;
|
|
368
|
-
for (const [
|
|
369
|
-
o += e.slice(r,
|
|
368
|
+
for (const [l, c] of v(e, n))
|
|
369
|
+
o += e.slice(r, l.range[1]), o += N(t ?? l.value, s), r = c.range[0];
|
|
370
370
|
o += e.slice(r);
|
|
371
371
|
const i = new d([0, o.length]);
|
|
372
372
|
return i.subtract(new d(
|
|
373
|
-
...
|
|
373
|
+
...v(o, n).flatMap(([l, c]) => [l.range, c.range])
|
|
374
374
|
)), j(
|
|
375
|
-
i.collapse().map(([
|
|
375
|
+
i.collapse().map(([l, c]) => o.slice(l, c)).filter(Boolean).join("")
|
|
376
376
|
).trim();
|
|
377
|
-
}, Xe = (e,
|
|
378
|
-
if (!
|
|
379
|
-
const r =
|
|
380
|
-
return
|
|
381
|
-
(
|
|
377
|
+
}, Xe = (e, n, t, s, o) => {
|
|
378
|
+
if (!n) return e;
|
|
379
|
+
const r = t === void 0 ? !1 : t >= 0, i = s ? N(s, o) : "", l = t ?? 0;
|
|
380
|
+
return v(e, n).map((c) => c[r ? 1 : 0]).sort(te).reverse().reduce(
|
|
381
|
+
(c, { range: a }) => r ? c.slice(0, a[1]) + i + c.slice(Math.min(a[1] + l, c.length)) : c.slice(0, Math.max(a[0] + l, 0)) + i + c.slice(a[0]),
|
|
382
382
|
e
|
|
383
383
|
);
|
|
384
|
-
}, Ve = (e,
|
|
385
|
-
if (!
|
|
384
|
+
}, Ve = (e, n, t, s, o) => {
|
|
385
|
+
if (!n) return e;
|
|
386
386
|
let r = "", i = 0;
|
|
387
|
-
const
|
|
388
|
-
console.log(
|
|
389
|
-
for (const [
|
|
390
|
-
r += e.slice(i,
|
|
387
|
+
const l = [t, s ?? ""].map((c) => N(c, o));
|
|
388
|
+
console.log(l);
|
|
389
|
+
for (const [c, a] of v(e, n))
|
|
390
|
+
r += e.slice(i, c.range[1]), r += e.slice(c.range[1], a.range[0]).replaceAll(l[0], l[1]), i = a.range[0];
|
|
391
391
|
return r += e.slice(i), r;
|
|
392
|
-
}, Je = (e,
|
|
393
|
-
if (!
|
|
394
|
-
const s = He(
|
|
392
|
+
}, Je = (e, n, t) => {
|
|
393
|
+
if (!n) return J(e);
|
|
394
|
+
const s = He(n);
|
|
395
395
|
switch (s.name) {
|
|
396
396
|
case "extract":
|
|
397
397
|
e = Ge(e, s.id, ...z(s));
|
|
@@ -409,8 +409,8 @@ const Ue = [
|
|
|
409
409
|
e = Ve(e, s.id, s.from, s.to, s.space);
|
|
410
410
|
break;
|
|
411
411
|
}
|
|
412
|
-
return
|
|
413
|
-
}, Ze = ["http", "./", "../"], Ke = ({ url: e }) => Ze.some((
|
|
412
|
+
return t ? J(e) : e;
|
|
413
|
+
}, Ze = ["http", "./", "../"], Ke = ({ url: e }) => Ze.some((n) => e.startsWith(n)), Ye = (e) => D(e) && xe(e) && Ke(e), oe = ({ url: e }, n) => `[](${n ? y(n, e) : e})`, m = {
|
|
414
414
|
_open: "<!--",
|
|
415
415
|
_close: "-->",
|
|
416
416
|
_flag: "p↓",
|
|
@@ -421,21 +421,21 @@ const Ue = [
|
|
|
421
421
|
return E(m._open, m._flag, "END", m._close);
|
|
422
422
|
},
|
|
423
423
|
lengthOf(e) {
|
|
424
|
-
const
|
|
425
|
-
`).length}`,
|
|
426
|
-
return E(m._open, m._flag, "length",
|
|
424
|
+
const n = `lines: ${e.split(`
|
|
425
|
+
`).length}`, t = `chars: ${e.length}`;
|
|
426
|
+
return E(m._open, m._flag, "length", n, t, m._close);
|
|
427
427
|
}
|
|
428
|
-
}, Z = (e) => (
|
|
429
|
-
oe(e,
|
|
428
|
+
}, Z = (e) => (n) => D(n) && n.value === m[e], en = ({ position: e, url: n, siblingCount: t }, s) => ({ position: e, url: n, headingDepth: s, inline: t >= 1 }), nn = ({ position: { start: e }, url: n, siblingCount: t }, { position: { end: s } }, o) => ({ position: { start: e, end: s }, url: n, headingDepth: o, inline: t >= 1 }), tn = (e, n, t) => (e.inline ? E : be)(
|
|
429
|
+
oe(e, t),
|
|
430
430
|
m.begin,
|
|
431
|
-
m.lengthOf(
|
|
432
|
-
|
|
431
|
+
m.lengthOf(n),
|
|
432
|
+
n,
|
|
433
433
|
m.end
|
|
434
|
-
),
|
|
435
|
-
const
|
|
436
|
-
return (
|
|
437
|
-
for (let s =
|
|
438
|
-
const o =
|
|
434
|
+
), sn = (e) => {
|
|
435
|
+
const n = S(e, "heading").reduce((t, { position: s, depth: o }) => t.set(s.start.line, o), /* @__PURE__ */ new Map());
|
|
436
|
+
return (t) => {
|
|
437
|
+
for (let s = t.position.start.line; s >= 1; s--) {
|
|
438
|
+
const o = n.get(s);
|
|
439
439
|
if (o) return o;
|
|
440
440
|
}
|
|
441
441
|
return 0;
|
|
@@ -444,27 +444,27 @@ const Ue = [
|
|
|
444
444
|
openingCommentDoesNotFollowLink: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),
|
|
445
445
|
closingCommentNotMatchedToOpening: ({ position: { start: e } }) => new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),
|
|
446
446
|
openingCommentNotClosed: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)
|
|
447
|
-
},
|
|
448
|
-
const
|
|
447
|
+
}, on = (e, n) => {
|
|
448
|
+
const t = [], s = [
|
|
449
449
|
...e.map((r) => ({ node: r, type: "open" })),
|
|
450
|
-
...
|
|
451
|
-
].sort((r, i) =>
|
|
450
|
+
...n.map((r) => ({ node: r, type: "close" }))
|
|
451
|
+
].sort((r, i) => f(r.node, i.node)), o = [];
|
|
452
452
|
for (const r of s)
|
|
453
453
|
if (r.type === "open") o.push(r);
|
|
454
454
|
else {
|
|
455
455
|
const i = r.node;
|
|
456
456
|
if (o.length === 0)
|
|
457
457
|
throw x.closingCommentNotMatchedToOpening(i);
|
|
458
|
-
const
|
|
458
|
+
const l = o.pop().node;
|
|
459
459
|
if (o.length > 0) continue;
|
|
460
|
-
|
|
460
|
+
t.push({ open: l, close: i });
|
|
461
461
|
}
|
|
462
462
|
if (o.length > 0)
|
|
463
463
|
throw x.openingCommentNotClosed(o[0].node);
|
|
464
|
-
return
|
|
465
|
-
},
|
|
466
|
-
const s = [...
|
|
467
|
-
return [...
|
|
464
|
+
return t;
|
|
465
|
+
}, rn = (e, n, t) => {
|
|
466
|
+
const s = [...n].sort(f), o = [];
|
|
467
|
+
return [...t].sort((r, i) => f.reverse(r.open, i.open)).forEach((r) => {
|
|
468
468
|
for (; s.length > 0; ) {
|
|
469
469
|
const i = s.pop();
|
|
470
470
|
if (i.position.start.offset < r.open.position.start.offset) {
|
|
@@ -476,50 +476,50 @@ const Ue = [
|
|
|
476
476
|
}
|
|
477
477
|
throw x.openingCommentDoesNotFollowLink(r.open);
|
|
478
478
|
}), o.push(...s.reverse()), o.reverse();
|
|
479
|
-
}, re = (e,
|
|
480
|
-
t ?? (t = I.md(e));
|
|
481
|
-
const n = st(t), s = S(t, "link").filter(Ye), o = S(t, "html").sort(h), r = o.filter(Z("begin")), i = o.filter(Z("end")), c = ot(r, i);
|
|
482
|
-
return rt(e, s, c).map((a) => Array.isArray(a) ? tt(a[0], a[1].close, n(a[0])) : et(a, n(a)));
|
|
483
|
-
}, it = (e, { url: t }) => (n) => e(y(A(t), n)), ie = (...e) => {
|
|
484
|
-
const t = e.reduce((n, s) => n + s, 0);
|
|
485
|
-
return Math.min(Math.max(t, 1), 6);
|
|
486
|
-
}, ct = (e, t, n) => {
|
|
487
|
-
if (t === 0) return e;
|
|
479
|
+
}, re = (e, n) => {
|
|
488
480
|
n ?? (n = I.md(e));
|
|
489
|
-
const s = S(n, "
|
|
481
|
+
const t = sn(n), s = S(n, "link").filter(Ye), o = S(n, "html").sort(f), r = o.filter(Z("begin")), i = o.filter(Z("end")), l = on(r, i);
|
|
482
|
+
return rn(e, s, l).map((a) => Array.isArray(a) ? nn(a[0], a[1].close, t(a[0])) : en(a, t(a)));
|
|
483
|
+
}, ln = (e, { url: n }) => (t) => e(y(A(n), t)), ie = (...e) => {
|
|
484
|
+
const n = e.reduce((t, s) => t + s, 0);
|
|
485
|
+
return Math.min(Math.max(n, 1), 6);
|
|
486
|
+
}, cn = (e, n, t) => {
|
|
487
|
+
if (n === 0) return e;
|
|
488
|
+
t ?? (t = I.md(e));
|
|
489
|
+
const s = S(t, "heading"), o = e.split(`
|
|
490
490
|
`);
|
|
491
491
|
for (const r of s) {
|
|
492
|
-
const { depth: i, position: { start:
|
|
493
|
-
o[
|
|
492
|
+
const { depth: i, position: { start: l, end: c } } = r, a = ie(i, n), u = o[l.line - 1].slice(i, c.column), p = "#".repeat(a) + u;
|
|
493
|
+
o[l.line - 1] = p, r.depth = a;
|
|
494
494
|
}
|
|
495
495
|
return o.join(`
|
|
496
496
|
`);
|
|
497
|
-
},
|
|
497
|
+
}, le = (e) => re(e).reverse().sort(f.reverse).reduce((n, t) => ee(n, oe(t), t), e), ce = (e, n, t, s, o) => {
|
|
498
498
|
try {
|
|
499
|
-
e =
|
|
499
|
+
e = le(e), e = cn(e, n);
|
|
500
500
|
const r = I.md(e);
|
|
501
|
-
return re(e, r).sort(
|
|
501
|
+
return re(e, r).sort(f).reverse().map((i) => {
|
|
502
502
|
var q, B;
|
|
503
|
-
const { url:
|
|
504
|
-
if (
|
|
505
|
-
let g =
|
|
506
|
-
const
|
|
503
|
+
const { url: l, headingDepth: c } = i, [a, ...u] = $e(l).split("?"), p = a.split(".").pop() ?? "", b = u.join("?"), k = A(l), L = y(k, a);
|
|
504
|
+
if (l.startsWith("./") || l.startsWith("../")) {
|
|
505
|
+
let g = t(L);
|
|
506
|
+
const $ = new Ce(b), M = (q = $.get("region")) == null ? void 0 : q.split(U);
|
|
507
507
|
g = (M == null ? void 0 : M.reduce(
|
|
508
|
-
(
|
|
508
|
+
(C, w, O, { length: fe }) => Je(C, w, O === fe - 1),
|
|
509
509
|
g
|
|
510
510
|
)) ?? g;
|
|
511
|
-
const me =
|
|
511
|
+
const me = $.has("skip"), ue = $.get("heading") ?? 0, ge = $.has("inline");
|
|
512
512
|
let { inline: _ } = i;
|
|
513
513
|
if (ge && (_ = !0), !me)
|
|
514
514
|
if (p === "md") {
|
|
515
|
-
const
|
|
516
|
-
g =
|
|
515
|
+
const C = ln(t, i), w = o ? y(o, k) : k, O = ie(c, Number(ue));
|
|
516
|
+
g = ce(
|
|
517
517
|
g,
|
|
518
518
|
/** p↓: ... */
|
|
519
|
-
|
|
520
|
-
|
|
519
|
+
O,
|
|
520
|
+
C,
|
|
521
521
|
L,
|
|
522
|
-
|
|
522
|
+
w
|
|
523
523
|
/** p↓: ... */
|
|
524
524
|
);
|
|
525
525
|
} else /^(js|ts)x?|svelte$/i.test(p) && (g = X(
|
|
@@ -529,24 +529,31 @@ const Ue = [
|
|
|
529
529
|
{ extension: p, inline: _ }
|
|
530
530
|
/** p↓: ... */
|
|
531
531
|
));
|
|
532
|
-
const
|
|
533
|
-
return g = (
|
|
534
|
-
} else throw
|
|
535
|
-
}).reduce((i, { target:
|
|
532
|
+
const R = (B = $.get("wrap")) == null ? void 0 : B.split(U);
|
|
533
|
+
return g = (R == null ? void 0 : R.reduce((C, w) => X(C, w, { extension: p, inline: _ }), g)) ?? g, { target: i, content: tn(i, g, o) };
|
|
534
|
+
} else throw l.startsWith("http") ? new Error("External web links are not implemented yet") : new Error(`Unsupported link type: ${l}`);
|
|
535
|
+
}).reduce((i, { target: l, content: c }) => ee(i, c, l), e);
|
|
536
536
|
} catch (r) {
|
|
537
537
|
throw new Error(`Error populating inclusions in file ${s ?? "(unknown)"}: ${r}`);
|
|
538
538
|
}
|
|
539
|
-
}, ae = (e) =>
|
|
540
|
-
const
|
|
541
|
-
return {
|
|
542
|
-
},
|
|
543
|
-
const { dir:
|
|
544
|
-
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
|
|
539
|
+
}, ae = (e) => ve(e, "utf-8"), pe = (e) => {
|
|
540
|
+
const n = Y(e), t = A(n);
|
|
541
|
+
return { content: ae(n), dir: t, path: n };
|
|
542
|
+
}, an = (e, n = !0, t) => {
|
|
543
|
+
const { dir: s, path: o, content: r } = pe(e);
|
|
544
|
+
t == null || t.unwatch(o), t == null || t.once("change", (c, a) => {
|
|
545
|
+
console.log(`Change detected in "${c}". Regenerating "${o}"...`), an(e, n, t);
|
|
546
|
+
});
|
|
547
|
+
const l = ce(r, 0, (c) => {
|
|
548
|
+
const a = Y(s, Me(c));
|
|
549
|
+
return t == null || t.add(a), ae(a);
|
|
550
|
+
}, o);
|
|
551
|
+
return n && K(o, l), t == null || t.add(o), l;
|
|
552
|
+
}, $n = (e, n = !0, t) => {
|
|
553
|
+
const { path: s, content: o } = pe(e), r = le(o);
|
|
554
|
+
return n && K(s, r), r;
|
|
548
555
|
};
|
|
549
556
|
export {
|
|
550
|
-
|
|
551
|
-
|
|
557
|
+
$n as depopulateMarkdownInclusions,
|
|
558
|
+
an as populateMarkdownInclusions
|
|
552
559
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
(function(p,m){typeof exports=="object"&&typeof module<"u"?m(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"],m):(p=typeof globalThis<"u"?globalThis:p||self,m(p.index={},p.node_fs,p.node_path,p.node_url,p.unified,p.remarkParse,p.unistUtilVisit,p.tsDedent))})(this,function(p,m,d,
|
|
2
|
-
`),
|
|
3
|
-
`}},
|
|
1
|
+
(function(p,m){typeof exports=="object"&&typeof module<"u"?m(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"],m):(p=typeof globalThis<"u"?globalThis:p||self,m(p.index={},p.node_fs,p.node_path,p.node_url,p.unified,p.remarkParse,p.unistUtilVisit,p.tsDedent))})(this,function(p,m,d,ue,me,de,ge,M){"use strict";var tn=Object.defineProperty;var sn=(p,m,d)=>m in p?tn(p,m,{enumerable:!0,configurable:!0,writable:!0,value:d}):p[m]=d;var pe=(p,m,d)=>sn(p,typeof m!="symbol"?m+"":m,d);const v=(e,n)=>e.position.start.offset-n.position.start.offset;v.reverse=(e,n)=>v(n,e);const T=e=>e.position!==void 0&&e.position.start.offset!==void 0&&e.position.end.offset!==void 0,fe=me.unified().use(de),j={md:e=>fe.parse(e)},x=(e,n)=>{const t=[];return ge.visit(e,(s,o,r)=>{if(s.type!=="root"){if(n&&s.type!==n)return;if(T(s)){const i=((r==null?void 0:r.children.length)??0)-1;t.push({...s,siblingIndex:o,siblingCount:i})}}}),t},he=e=>e.children.length===0,L=(e,n,...t)=>{if(t.length===0)throw new Error("No nodes to replace content from");t.sort(v);const s=t.at(0),o=t.at(-1);return e.slice(0,s.position.start.offset)+n+e.slice(o.position.end.offset)},ve=(e,n,t)=>{const s=Math.min(n.position.end.offset,t.position.end.offset),o=Math.max(n.position.start.offset,t.position.start.offset);return e.slice(s,o)},N=(...e)=>e.join(" "),$e=(...e)=>e.join(`
|
|
2
|
+
`),Ce=e=>{const n=e.split("?");return n.length>1?[n.slice(0,-1).join("?"),n.at(-1)]:[e,""]},we=e=>Ce(e)[0];class ${constructor(...n){pe(this,"intervals",[]);for(const[t,s]of n)this.push(t,s)}push(n,t){this.intervals.push([Math.min(n,t),Math.max(n,t)])}combine(n){this.intervals.push(...n.intervals)}collapse(){const{intervals:n}=this;if(!n.length)return this.intervals=[];n.sort((r,i)=>r[0]-i[0]);const t=[];let[s,o]=n[0];for(let r=1;r<n.length;r++){const[i,l]=n[r];i<=o?o=Math.max(o,l):(t.push([s,o]),s=i,o=l)}return t.push([s,o]),this.intervals=t}subtract(n){const{intervals:t}=this,{intervals:s}=n;if(!t.length||!s.length)return t;let o=[...t];for(const[r,i]of s){const l=[];for(const[c,a]of o){if(i<=c||r>=a){l.push([c,a]);continue}r>c&&l.push([c,r]),i<a&&l.push([i,a])}o=l}return this.intervals=o}}const B=/,\s*(?![^()]*\))/,F={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
|
+
`}},ye="-",U={static:[["'''",'"'],["''","'"],[/parkdown:\s+/g,""],[/p↓:\s+/g,""]],url:[...Object.entries(F.unsafe),...Object.entries(F.reserved)]},H=(e,[n,t])=>e.replaceAll(n,t),k=(e,n=ye)=>{const t=U.static.reduce(H,e);return U.url.map(([s,o])=>[n+s+n,o]).reduce(H,t).replaceAll(n," ")},Se=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Ee=["string","number","boolean"],xe=e=>Ee.includes(e),Ne=/^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/,ke=e=>{const n=e.match(Ne);if(!n)throw new Error(`Invalid invocation: ${e}`);const[,t,s=""]=n;if(!s.trim())return{name:t,parameters:[]};const o=Me(s);return{name:t,parameters:o}},be=(e,n)=>{for(let t=n+1;t<e.length;t++)if(e[t]!==void 0)return!1;return!0},Me=e=>{const n=[];let t="",s=!1;for(let o=0;o<e.length;o++){const r=e[o],i=r==="'";if(i&&e.at(o+1)==="'"){const l=e.at(o+2)==="'";s=!s,t+=l?"'''":"''",o+=l?2:1}else i?(s=!s,t+=r):r===","&&!s?(n.push(t.trim()),t=""):t+=r}return n.push(t.trim()),n.map(o=>o===""?void 0:o?Te(o):void 0).filter((o,r,i)=>o!==void 0||!be(i,r))},Te=e=>{const n=e.length>=2&&e[0]==="'"&&e.at(-1)==="'",t=n&&e.length>=4&&e[1]==="'"&&e.at(-2)==="'";return!n||t?e:e.slice(1,-1)},je=e=>{const n=/^(\w+)(?:\(([^)]*)\))?/,t=e.match(n);if(!t)return{name:e};const[,s,o]=t;if(!o)return{name:s};const r=/(\w+)(\?)?:\s*([^,]+)/g,i=[];let l;for(;(l=r.exec(o))!==null;){const[,c,a,f]=l,u=f.trim();if(!xe(u))throw new Error(`Unsupported type: ${u}`);i.push({name:c,optional:a==="?",type:u})}return{name:s,parameters:i}},O=e=>{const n=e.map(je).reduce((t,{name:s,parameters:o})=>t.set(s,o),new Map);return t=>{const{name:s,parameters:o}=ke(t);if(!n.has(s))throw new Error(`Unknown method: ${s}`);const r=n.get(s);if(r===void 0)return{name:s};if(o.length>r.length){const i=r.filter(({optional:c})=>!c).length,l=i===r.length?i.toString():`${i} - ${r.length}`;throw new Error(`Too many parameters: ${o.length} for method '${s}' (expected: ${l})`)}return r.reduce((i,{name:l,optional:c,type:a},f)=>{const u=o[f];if(u===void 0){if(c)return i;throw new Error(`Missing required parameter: ${l} for method '${s}'`)}switch(a){case"string":i[l]=u;break;case"number":case"boolean":i[l]=JSON.parse(u);break}if(typeof i[l]!==a)throw new Error(`Invalid type: ${l} must be ${a}, got ${typeof i[l]} for method '${s}'`);return i},{name:s})}},G=e=>Object.entries(e).filter(([n])=>n!=="name"&&!isNaN(Number(n))).map(([n,t])=>t),Oe=O(["code(lang?: string, meta?: string)","quote()","dropdown(summary: string, open?: boolean, space?: string)"]),C=(e,n=1)=>`
|
|
4
4
|
`.repeat(n)+e+`
|
|
5
|
-
`.repeat(n),R=(e,n,t)=>`<${n}${t?` ${t}`:""}>${
|
|
6
|
-
`))return`\`${e}\``;const r=s.lang??(t==null?void 0:t.extension)??"",i=s.meta?` ${s.meta}`:"";return
|
|
5
|
+
`.repeat(n),R=(e,n,t)=>`<${n}${t?` ${t}`:""}>${C(e)}</${n}>`,Q=(e,n,t)=>{const s=Oe(n);switch(s.name){case"code":if(!s.lang&&!s.meta&&(t==null?void 0:t.inline)&&!e.includes(`
|
|
6
|
+
`))return`\`${e}\``;const r=s.lang??(t==null?void 0:t.extension)??"",i=s.meta?` ${s.meta}`:"";return C(`\`\`\`${r}${i}${C(e)}\`\`\``);case"quote":return t!=null&&t.inline&&!e.includes(`
|
|
7
7
|
|
|
8
|
-
`)?`> ${e}
|
|
9
|
-
`),"details",s.open?"open":void 0))}},q=e=>{const n=/(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm,t=[];let s;for(;(s=n.exec(e))!==null;){const o=[s.index,s.index+s[0].length],r=
|
|
10
|
-
`||e===void 0}),Z=e=>z.flatMap(n=>X(e,n)).sort((n,t)=>n.range[0]-t.range[0]).reverse().reduce((n,{range:[t,s],value:o})=>{const r=(u,I)=>n.slice(0,u)+n.slice(I),i=J(n[t-1]),
|
|
11
|
-
`;)a--;const
|
|
12
|
-
`?
|
|
13
|
-
`).length}`,t=`chars: ${e.length}`;return
|
|
14
|
-
`);for(const r of s){const{depth:i,position:{start:
|
|
15
|
-
`)},te=e=>ee(e).reverse().sort(
|
|
8
|
+
`)?`> ${e}`:C(R(C(e),"blockquote"));case"dropdown":const l=R(k(s.summary),"summary");return C(R([l,e].join(`
|
|
9
|
+
`),"details",s.open?"open":void 0))}},q=e=>{const n=/(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm,t=[];let s;for(;(s=n.exec(e))!==null;){const o=[s.index,s.index+s[0].length],r=Re(s[0]).trim();t.push({range:o,value:r})}return t},Re=e=>e.startsWith("//")?e.slice(2):e.startsWith("/*")?e.slice(2,-2):e.startsWith("<!--")?e.slice(4,-3):e,z=["p↓:","pd:","parkdown:"];O(["splice(delete?: number, insert?: string)"]);const V=(e,n)=>e.range[0]-n.range[0],X=(e,n,t)=>(t??q(e)).filter(({value:s})=>s.split(" ").includes(n)).sort(V),J=e=>({isSpace:e===" ",isNewline:e===`
|
|
10
|
+
`||e===void 0}),Z=e=>z.flatMap(n=>X(e,n)).sort((n,t)=>n.range[0]-t.range[0]).reverse().reduce((n,{range:[t,s],value:o})=>{const r=(u,I)=>n.slice(0,u)+n.slice(I),i=J(n[t-1]),l=J(n[s]),c=s===n.length;let a=t;for(;a>0&&n[a-1]!==`
|
|
11
|
+
`;)a--;const f=n.slice(a,t).trim()==="";return i.isNewline&&l.isNewline?r(t-(c?1:0),s+1):i.isNewline||f?r(a,s+(l.isSpace||l.isNewline?1:0)):r(t-(i.isSpace?1:0),s)},e);z.map(e=>new RegExp(`^${Se(e)}(\\?[^\\s]+)`));const qe=O(["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)","splice(id: string, deleteCount?: number, insert?: string, space?: string)","remap(id: string, from: string, to?: string, space?: string)"]),w=(e,n,t)=>{const s=X(e,n,t),o=[];for(let r=0;r<s.length-1;r+=2)o.push([s[r],s[r+1]]);return o},Ie=(e,...n)=>{if(n.length===0)return e;const t=q(e),s=([i,l])=>e.slice(i,l),o=new $,r=new $;for(const i of n)for(const[l,c]of w(e,i,t)){o.push(l.range[1],c.range[0]);const[a,...f]=s([l.range[1],c.range[0]]),u=f[f.length-1];r.push(l.range[0],l.range[1]+(a.trim()?0:1)),r.push(c.range[0],c.range[1]+(u.trim()?0:1))}return o.collapse(),r.collapse(),M.dedent(o.subtract(r).map(s).filter(Boolean).join("")).trim()},Ae=(e,...n)=>{if(n.length===0)return e;const t=q(e),s=([i,l])=>e.slice(i,l),o=new $;for(const i of n)for(const[l,c]of w(e,i,t)){const a=s([c.range[1],c.range[1]+1]).at(-1);o.push(l.range[0],a===`
|
|
12
|
+
`?c.range[1]+1:c.range[1])}o.collapse();const r=new $([0,e.length]);return r.subtract(o),M.dedent(r.collapse().map(s).filter(Boolean).join("")).trim()},Pe=(e,n,t,s)=>{if(!n)return e;let o="",r=0;for(const[l,c]of w(e,n))o+=e.slice(r,l.range[1]),o+=k(t??l.value,s),r=c.range[0];o+=e.slice(r);const i=new $([0,o.length]);return i.subtract(new $(...w(o,n).flatMap(([l,c])=>[l.range,c.range]))),M.dedent(i.collapse().map(([l,c])=>o.slice(l,c)).filter(Boolean).join("")).trim()},De=(e,n,t,s,o)=>{if(!n)return e;const r=t===void 0?!1:t>=0,i=s?k(s,o):"",l=t??0;return w(e,n).map(c=>c[r?1:0]).sort(V).reverse().reduce((c,{range:a})=>r?c.slice(0,a[1])+i+c.slice(Math.min(a[1]+l,c.length)):c.slice(0,Math.max(a[0]+l,0))+i+c.slice(a[0]),e)},We=(e,n,t,s,o)=>{if(!n)return e;let r="",i=0;const l=[t,s??""].map(c=>k(c,o));console.log(l);for(const[c,a]of w(e,n))r+=e.slice(i,c.range[1]),r+=e.slice(c.range[1],a.range[0]).replaceAll(l[0],l[1]),i=a.range[0];return r+=e.slice(i),r},_e=(e,n,t)=>{if(!n)return Z(e);const s=qe(n);switch(s.name){case"extract":e=Ie(e,s.id,...G(s));break;case"remove":e=Ae(e,s.id,...G(s));break;case"replace":e=Pe(e,s.id,s.with,s.space);break;case"splice":e=De(e,s.id,s.deleteCount,s.insert,s.space);break;case"remap":e=We(e,s.id,s.from,s.to,s.space);break}return t?Z(e):e},Le=["http","./","../"],Be=({url:e})=>Le.some(n=>e.startsWith(n)),Fe=e=>T(e)&&he(e)&&Be(e),K=({url:e},n)=>`[](${n?d.join(n,e):e})`,g={_open:"<!--",_close:"-->",_flag:"p↓",get begin(){return N(g._open,g._flag,"BEGIN",g._close)},get end(){return N(g._open,g._flag,"END",g._close)},lengthOf(e){const n=`lines: ${e.split(`
|
|
13
|
+
`).length}`,t=`chars: ${e.length}`;return N(g._open,g._flag,"length",n,t,g._close)}},Y=e=>n=>T(n)&&n.value===g[e],Ue=({position:e,url:n,siblingCount:t},s)=>({position:e,url:n,headingDepth:s,inline:t>=1}),He=({position:{start:e},url:n,siblingCount:t},{position:{end:s}},o)=>({position:{start:e,end:s},url:n,headingDepth:o,inline:t>=1}),Ge=(e,n,t)=>(e.inline?N:$e)(K(e,t),g.begin,g.lengthOf(n),n,g.end),Qe=e=>{const n=x(e,"heading").reduce((t,{position:s,depth:o})=>t.set(s.start.line,o),new Map);return t=>{for(let s=t.position.start.line;s>=1;s--){const o=n.get(s);if(o)return o}return 0}},b={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`)},ze=(e,n)=>{const t=[],s=[...e.map(r=>({node:r,type:"open"})),...n.map(r=>({node:r,type:"close"}))].sort((r,i)=>v(r.node,i.node)),o=[];for(const r of s)if(r.type==="open")o.push(r);else{const i=r.node;if(o.length===0)throw b.closingCommentNotMatchedToOpening(i);const l=o.pop().node;if(o.length>0)continue;t.push({open:l,close:i})}if(o.length>0)throw b.openingCommentNotClosed(o[0].node);return t},Ve=(e,n,t)=>{const s=[...n].sort(v),o=[];return[...t].sort((r,i)=>v.reverse(r.open,i.open)).forEach(r=>{for(;s.length>0;){const i=s.pop();if(i.position.start.offset<r.open.position.start.offset){if(ve(e,i,r.open).trim()!=="")throw b.openingCommentDoesNotFollowLink(r.open);return o.push([i,r])}o.push(i)}throw b.openingCommentDoesNotFollowLink(r.open)}),o.push(...s.reverse()),o.reverse()},ee=(e,n)=>{n??(n=j.md(e));const t=Qe(n),s=x(n,"link").filter(Fe),o=x(n,"html").sort(v),r=o.filter(Y("begin")),i=o.filter(Y("end")),l=ze(r,i);return Ve(e,s,l).map(a=>Array.isArray(a)?He(a[0],a[1].close,t(a[0])):Ue(a,t(a)))},Xe=(e,{url:n})=>t=>e(d.join(d.dirname(n),t)),ne=(...e)=>{const n=e.reduce((t,s)=>t+s,0);return Math.min(Math.max(n,1),6)},Je=(e,n,t)=>{if(n===0)return e;t??(t=j.md(e));const s=x(t,"heading"),o=e.split(`
|
|
14
|
+
`);for(const r of s){const{depth:i,position:{start:l,end:c}}=r,a=ne(i,n),f=o[l.line-1].slice(i,c.column),u="#".repeat(a)+f;o[l.line-1]=u,r.depth=a}return o.join(`
|
|
15
|
+
`)},te=e=>ee(e).reverse().sort(v.reverse).reduce((n,t)=>L(n,K(t),t),e),se=(e,n,t,s,o)=>{try{e=te(e),e=Je(e,n);const r=j.md(e);return ee(e,r).sort(v).reverse().map(i=>{var ce,ae;const{url:l,headingDepth:c}=i,[a,...f]=d.basename(l).split("?"),u=a.split(".").pop()??"",I=f.join("?"),A=d.dirname(l),le=d.join(A,a);if(l.startsWith("./")||l.startsWith("../")){let h=t(le);const y=new ue.URLSearchParams(I),P=(ce=y.get("region"))==null?void 0:ce.split(B);h=(P==null?void 0:P.reduce((S,E,_,{length:nn})=>_e(S,E,_===nn-1),h))??h;const Ke=y.has("skip"),Ye=y.get("heading")??0,en=y.has("inline");let{inline:D}=i;if(en&&(D=!0),!Ke)if(u==="md"){const S=Xe(t,i),E=o?d.join(o,A):A,_=ne(c,Number(Ye));h=se(h,_,S,le,E)}else/^(js|ts)x?|svelte$/i.test(u)&&(h=Q(h,"code",{extension:u,inline:D}));const W=(ae=y.get("wrap"))==null?void 0:ae.split(B);return h=(W==null?void 0:W.reduce((S,E)=>Q(S,E,{extension:u,inline:D}),h))??h,{target:i,content:Ge(i,h,o)}}else throw l.startsWith("http")?new Error("External web links are not implemented yet"):new Error(`Unsupported link type: ${l}`)}).reduce((i,{target:l,content:c})=>L(i,c,l),e)}catch(r){throw new Error(`Error populating inclusions in file ${s??"(unknown)"}: ${r}`)}},oe=e=>m.readFileSync(e,"utf-8"),re=e=>{const n=d.resolve(e),t=d.dirname(n);return{content:oe(n),dir:t,path:n}},ie=(e,n=!0,t)=>{const{dir:s,path:o,content:r}=re(e);t==null||t.unwatch(o),t==null||t.once("change",(c,a)=>{console.log(`Change detected in "${c}". Regenerating "${o}"...`),ie(e,n,t)});const l=se(r,0,c=>{const a=d.resolve(s,we(c));return t==null||t.add(a),oe(a)},o);return n&&m.writeFileSync(o,l),t==null||t.add(o),l},Ze=(e,n=!0,t)=>{const{path:s,content:o}=re(e),r=te(o);return n&&m.writeFileSync(s,r),r};p.depopulateMarkdownInclusions=Ze,p.populateMarkdownInclusions=ie,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@p-buddy/parkdown",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.13",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"bin": "./dist/cli.js",
|
|
8
8
|
"files": [
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@commander-js/extra-typings": "^13.1.0",
|
|
27
|
+
"chokidar": "^4.0.3",
|
|
27
28
|
"remark-parse": "^11.0.0",
|
|
28
29
|
"ts-dedent": "^2.2.0",
|
|
29
30
|
"unified": "^11.0.5",
|