@p-buddy/parkdown 0.0.25 → 0.0.26
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/dist/cli.js +1 -1
- package/dist/index.js +15 -15
- package/dist/index.umd.cjs +3 -3
- package/package.json +1 -1
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.26", 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
1
|
var be = Object.defineProperty;
|
|
2
2
|
var ye = (e, t, n) => t in e ? be(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
-
var
|
|
3
|
+
var _ = (e, t, n) => ye(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
4
|
import { writeFileSync as ie, readFileSync as Ce } from "node:fs";
|
|
5
5
|
import { basename as Ee, dirname as Q, join as O, resolve as le } from "node:path";
|
|
6
6
|
import { URLSearchParams as Se } from "node:url";
|
|
7
7
|
import { unified as xe } from "unified";
|
|
8
|
-
import
|
|
9
|
-
import { visit as
|
|
8
|
+
import _e from "remark-parse";
|
|
9
|
+
import { visit as ke } from "unist-util-visit";
|
|
10
10
|
import { dedent as Ne } 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, Me = xe().use(
|
|
13
|
+
const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, Me = xe().use(_e), z = {
|
|
14
14
|
md: (e) => Me.parse(e)
|
|
15
15
|
}, R = (e, t) => {
|
|
16
16
|
const n = [];
|
|
17
|
-
return
|
|
17
|
+
return ke(e, (s, r, o) => {
|
|
18
18
|
if (s.type !== "root") {
|
|
19
19
|
if (t && s.type !== t) return;
|
|
20
20
|
if (G(s)) {
|
|
@@ -103,11 +103,11 @@ const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
103
103
|
const t = e.length >= 2 && e[0] === "'" && e.at(-1) === "'", n = t && e.length >= 4 && e[1] === "'" && e.at(-2) === "'";
|
|
104
104
|
return !t || n ? e : e.slice(1, -1);
|
|
105
105
|
}, Fe = (e) => {
|
|
106
|
-
const t = /^(\w+)(?:\(([^)]*)\))?/, n = e.match(t);
|
|
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
113
|
const [, a, c, u] = l, p = u.trim();
|
|
@@ -203,8 +203,8 @@ const G = (e) => e.position !== void 0 && e.position.start.offset !== void 0 &&
|
|
|
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
|
}
|
|
@@ -534,12 +534,12 @@ const ce = (e, t) => e.range[0] - t.range[0], X = (e, t, n) => (n ?? P(e)).filte
|
|
|
534
534
|
], re = {
|
|
535
535
|
register: N(ot),
|
|
536
536
|
apply: N(it)
|
|
537
|
-
},
|
|
537
|
+
}, k = class k {
|
|
538
538
|
constructor() {
|
|
539
|
-
|
|
539
|
+
_(this, "recipes", /* @__PURE__ */ new Map());
|
|
540
540
|
}
|
|
541
541
|
tryStore(t) {
|
|
542
|
-
const n =
|
|
542
|
+
const n = k.Entries(t);
|
|
543
543
|
for (let s = 0; s < n.length; s++) {
|
|
544
544
|
const [r, o] = n[s];
|
|
545
545
|
if (r !== "register") continue;
|
|
@@ -555,7 +555,7 @@ const ce = (e, t) => e.range[0] - t.range[0], X = (e, t, n) => (n ?? P(e)).filte
|
|
|
555
555
|
}
|
|
556
556
|
}
|
|
557
557
|
apply(t) {
|
|
558
|
-
const n =
|
|
558
|
+
const n = k.Entries(t), s = [];
|
|
559
559
|
for (let r = 0; r < n.length; r++) {
|
|
560
560
|
const [o, i] = n[r];
|
|
561
561
|
if (o !== "apply") {
|
|
@@ -574,8 +574,8 @@ const ce = (e, t) => e.range[0] - t.range[0], X = (e, t, n) => (n ?? P(e)).filte
|
|
|
574
574
|
return s.join("&");
|
|
575
575
|
}
|
|
576
576
|
};
|
|
577
|
-
k
|
|
578
|
-
let H =
|
|
577
|
+
_(k, "Entries", (t) => Array.from(new URLSearchParams(t).entries()));
|
|
578
|
+
let H = k;
|
|
579
579
|
const lt = ["http", "./", "../", "?"], at = ({ url: e }) => lt.some((t) => e.startsWith(t)), ct = (e) => G(e) && Ae(e) && at(e), pe = ({ url: e }, t) => `[](${t ? O(t, e) : e})`, g = {
|
|
580
580
|
_open: "<!--",
|
|
581
581
|
_close: "-->",
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(function(d,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):(d=typeof globalThis<"u"?globalThis:d||self,m(d.index={},d.node_fs,d.node_path,d.node_url,d.unified,d.remarkParse,d.unistUtilVisit,d.tsDedent))})(this,function(d,m,g,ve,we,$e,ye,Ce){"use strict";var dt=Object.defineProperty;var mt=(d,m,g)=>m in d?dt(d,m,{enumerable:!0,configurable:!0,writable:!0,value:g}):d[m]=g;var j=(d,m,g)=>mt(d,typeof m!="symbol"?m+"":m,g);const $=(e,t)=>e.position.start.offset-t.position.start.offset;$.reverse=(e,t)=>$(t,e);const D=e=>e.position!==void 0&&e.position.start.offset!==void 0&&e.position.end.offset!==void 0,be=we.unified().use($e),L={md:e=>be.parse(e)},A=(e,t)=>{const n=[];return ye.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},Ee=e=>e.children.length===0,J=(e,t,...n)=>{if(n.length===0)throw new Error("No nodes to replace content from");n.sort($);const s=n.at(0),r=n.at(-1);return e.slice(0,s.position.start.offset)+t+e.slice(r.position.end.offset)},Se=(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)},O=(...e)=>e.join(" "),ke=(...e)=>e.join(`
|
|
2
2
|
`),xe=e=>{const t=e.split("?");return t.length>1?[t.slice(0,-1).join("?"),t.at(-1)]:[e,""]},Ne=e=>xe(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
|
-
`}},Me="-",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),I=(e,t=Me)=>{const n=Y.static.reduce(ee,e);return Y.url.map(([s,r])=>[t+s+t,r]).reduce(ee,n).replaceAll(t," ")},
|
|
3
|
+
`}},Me="-",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),I=(e,t=Me)=>{const n=Y.static.reduce(ee,e);return Y.url.map(([s,r])=>[t+s+t,r]).reduce(ee,n).replaceAll(t," ")},_e=["string","number","boolean"],Te=e=>_e.includes(e),je=/^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/,Ae=e=>{const t=e.match(je);if(!t)throw new Error(`Invalid invocation: ${e}`);const[,n,s=""]=t;if(!s.trim())return{name:n,parameters:[]};const r=Ie(s);return{name:n,parameters:r}},Oe=(e,t)=>{for(let n=t+1;n<e.length;n++)if(e[n]!==void 0)return!1;return!0},Ie=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?qe(r):void 0).filter((r,i,o)=>r!==void 0||!Oe(o,i))},qe=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)},Re=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[,a,c,u]=l,p=u.trim();if(!Te(p))throw new Error(`Unsupported type: ${p}`);o.push({name:a,optional:c==="?",type:p})}return{name:s,parameters:o}},N=e=>{const t=e.map(Re).reduce((n,{name:s,parameters:r})=>n.set(s,r),new Map);return n=>{const{name:s,parameters:r}=Ae(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:a})=>!a).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:a,type:c},u)=>{const p=r[u];if(p===void 0){if(a)return o;throw new Error(`Missing required parameter: ${l} for method '${s}'`)}switch(c){case"string":o[l]=p;break;case"number":case"boolean":o[l]=JSON.parse(p);break}if(typeof o[l]!==c)throw new Error(`Invalid type: ${l} must be ${c}, 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),Pe=N(["code(lang?: string, meta?: string)","quote()","dropdown(summary: string, open?: boolean, space?: string)"]),E=(e,t=1)=>`
|
|
4
4
|
`.repeat(t)+e+`
|
|
5
5
|
`.repeat(t),B=(e,t,n)=>`<${t}${n?` ${n}`:""}>${E(e)}</${t}>`,te=(e,t,n)=>{const s=Pe(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(`
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
`||e===void 0}),re=e=>De.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]),a=s===t.length;let c=n;for(;c>0&&t[c-1]!==`
|
|
11
11
|
`;)c--;let u=s;for(;u<t.length&&t[u]!==`
|
|
12
12
|
`;)u++;const p=t.slice(c,n).trim()===""&&t.slice(s,u).trim()==="";return o.isNewline&&l.isNewline?i(n-(a?1:0),s+1):o.isNewline||p?i(c,s+(l.isSpace||l.isNewline?1:0)):i(n-(o.isSpace?1:0),s)},e),Le=N(["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},Ue=(e,t,n)=>new v(...F(e,t,n).map(({range:s})=>s)),R=e=>Ce.dedent(e).trim(),Be=(e,...t)=>{if(t.length===0)return e;const n=q(e),s=new v,r=new v;for(const i of t)for(const[o,l]of C(e,i,n)){s.push(o.range[1],l.range[0]);const[a,...c]=e.slice(o.range[1],l.range[0]),u=c[c.length-1];r.push(o.range[0],o.range[1]+(a.trim()?0:1)),r.push(l.range[0],l.range[1]+(u.trim()?0:1))}return R(s.subtract(r).slice(e))},Fe=(e,...t)=>{if(t.length===0)return e;const n=q(e),s=([i,o])=>e.slice(i,o),r=new v;for(const i of t)for(const[o,l]of C(e,i,n)){const a=s([l.range[1],l.range[1]+1]).at(-1);r.push(o.range[0],a===`
|
|
13
|
-
`?l.range[1]+1:l.range[1])}return R(new v([0,e.length]).subtract(r).slice(e))},He=(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+=I(n??o.value,s),i=l.range[0];return r+=e.slice(i),R(new v([0,r.length]).subtract(Ue(r,t)).slice(r))},Qe=(e,t,n,s,r,i)=>{if(!t)return e;const o=!(s===void 0||s<0),l=r?I(r,i):"",a=s??0,c=q(e),u=new v(...c.map(({range:p})=>p));return C(e,t,c).map(p=>p[n==="start"?0:1]).sort(ne).reverse().reduce((p,{range:S})=>{const k=new v,W=o?1:-1;let
|
|
13
|
+
`?l.range[1]+1:l.range[1])}return R(new v([0,e.length]).subtract(r).slice(e))},He=(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+=I(n??o.value,s),i=l.range[0];return r+=e.slice(i),R(new v([0,r.length]).subtract(Ue(r,t)).slice(r))},Qe=(e,t,n,s,r,i)=>{if(!t)return e;const o=!(s===void 0||s<0),l=r?I(r,i):"",a=s??0,c=q(e),u=new v(...c.map(({range:p})=>p));return C(e,t,c).map(p=>p[n==="start"?0:1]).sort(ne).reverse().reduce((p,{range:S})=>{const k=new v,W=o?1:-1;let _=Math.abs(a),h=o?S[1]:S[0];for(;_>0&&h<p.length&&h>=0;)u.test(h)||(k.push(h),_--),h+=W;return h=Math.min(Math.max(0,h),p.length),p=p.slice(0,h)+l+p.slice(h),new v([0,p.length]).subtract(k.offset(o?0:l.length)).slice(p)},e)},Ge=(e,t,n,s,r)=>{let i="",o=0;[n,s]=[n,s??""].map(a=>I(a,r));const l=t?C(e,t):[[{range:[0,0]},{range:[e.length,e.length]}]];for(const[a,c]of l)i+=e.slice(o,a.range[1]),i+=e.slice(a.range[1],c.range[0]).replaceAll(n,s),o=c.range[0];return i+=e.slice(o),i},ze=(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},ie=(e,t,n)=>{var i,o,l,a;if(!t)return e;const s=c=>/\s/.test(e[c]),r=new v;for(const[c,u]of C(e,t)){if((i=n.start)!=null&&i.left){let p=c.range[0]-1;for(;s(p);)r.push(p--)}if((o=n.start)!=null&&o.right){let p=c.range[1];for(;s(p);)r.push(p++)}if((l=n.end)!=null&&l.left){let p=u.range[0]-1;for(;s(p);)r.push(p--)}if((a=n.end)!=null&&a.right){let p=u.range[1];for(;s(p);)r.push(p++)}}return new v([0,e.length]).subtract(r).slice(e)},Ve=(e,t,n)=>{if(!t)return re(e);const s=Le(t);switch(s.name){case"extract":e=Be(e,s.id,...U(s));break;case"remove":e=Fe(e,s.id,...U(s));break;case"replace":e=He(e,s.id,s.with,s.space);break;case"splice-start":case"splice-end":{const{deleteCount:r,insert:i,space:o,id:l}=s,a=s.name==="splice-start"?"start":"end";e=Qe(e,l,a,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=ie(e,o,{[l]:{left:r??!0,right:i??!0}});break}case"trim":{const{inside:r,outside:i,id:o}=s;e=ie(e,o,{start:{left:i??!0,right:r??!0},end:{left:r??!0,right:i??!0}});break}case"single-line":e=ze(e,s.id);break;case"remap":e=Ge(e,s.id,s.from,s.to,s.space);break}return e=n&&s.name!=="debug"?re(e):e,n?R(e):e},Xe=["recipe(id: string)"],Je=["recipe(id: string, 0?: string, 1?: string, 2?: string)"],oe={register:N(Xe),apply:N(Je)},M=class M{constructor(){j(this,"recipes",new Map)}tryStore(t){const n=M.Entries(t);for(let s=0;s<n.length;s++){const[r,i]=n[s];if(r!=="register")continue;const o=oe.register(i);switch(o.name){case"recipe":const l=n.slice(s+1).filter(([a])=>a!=="register").map(([a,c])=>`${a}=${c}`).join("&");this.recipes.set(o.id,l);break;default:throw new Error(`Unknown registration: ${o.name}`)}}}apply(t){const n=M.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=oe.apply(o);switch(l.name){case"recipe":s.push(this.recipes.get(l.id)),s.push(...U(l).map(a=>this.recipes.get(a)));break;default:throw new Error(`Unknown registration: ${l.name}`)}}return s.join("&")}};j(M,"Entries",t=>Array.from(new URLSearchParams(t).entries()));let H=M;const Ze=["http","./","../","?"],Ke=({url:e})=>Ze.some(t=>e.startsWith(t)),Ye=e=>D(e)&&Ee(e)&&Ke(e),le=({url:e},t)=>`[](${t?g.join(t,e):e})`,f={_open:"<!--",_close:"-->",_flag:"p↓",get begin(){return O(f._open,f._flag,"BEGIN",f._close)},get end(){return O(f._open,f._flag,"END",f._close)},lengthOf(e){const t=`lines: ${e.split(`
|
|
14
14
|
`).length}`,n=`chars: ${e.length}`;return O(f._open,f._flag,"length",t,n,f._close)}},ae=e=>t=>D(t)&&t.value===f[e],et=({position:e,url:t,siblingCount:n},s)=>({position:e,url:t,headingDepth:s,inline:n>=1}),tt=({position:{start:e},url:t,siblingCount:n},{position:{end:s}},r)=>({position:{start:e,end:s},url:t,headingDepth:r,inline:n>=1}),nt=(e,t,n)=>(e.inline?O:ke)(le(e,n),f.begin,f.lengthOf(t),t,f.end),st=e=>{const t=A(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}},P={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`)},rt=(e,t)=>{const n=[],s=[...e.map(i=>({node:i,type:"open"})),...t.map(i=>({node:i,type:"close"}))].sort((i,o)=>$(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 P.closingCommentNotMatchedToOpening(o);const l=r.pop().node;if(r.length>0)continue;n.push({open:l,close:o})}if(r.length>0)throw P.openingCommentNotClosed(r[0].node);return n},it=(e,t,n)=>{const s=[...t].sort($),r=[];return[...n].sort((i,o)=>$.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(Se(e,o,i.open).trim()!=="")throw P.openingCommentDoesNotFollowLink(i.open);return r.push([o,i])}r.push(o)}throw P.openingCommentDoesNotFollowLink(i.open)}),r.push(...s.reverse()),r.reverse()},ce=(e,t)=>{t??(t=L.md(e));const n=st(t),s=A(t,"link").filter(Ye),r=A(t,"html").sort($),i=r.filter(ae("begin")),o=r.filter(ae("end")),l=rt(i,o);return it(e,s,l).map(c=>Array.isArray(c)?tt(c[0],c[1].close,n(c[0])):et(c,n(c)))},ot=(e,{url:t})=>n=>e(g.join(g.dirname(t),n)),pe=(...e)=>{const t=e.reduce((n,s)=>n+s,0);return Math.min(Math.max(t,1),6)},lt=(e,t,n)=>{if(t===0)return e;n??(n=L.md(e));const s=A(n,"heading"),r=e.split(`
|
|
15
15
|
`);for(const i of s){const{depth:o,position:{start:l,end:a}}=i,c=pe(o,t),u=r[l.line-1].slice(o,a.column),p="#".repeat(c)+u;r[l.line-1]=p,i.depth=c}return r.join(`
|
|
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,
|
|
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,_;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 T=new ve.URLSearchParams(k),G=(W=(b=>{const y=Array.from(T.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=T.has("skip"),pt=T.get("heading")??0,ut=T.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:_.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"})});
|