@pretextbook/remark-pretext 0.1.0 → 0.3.0
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 +44 -1
- package/dist/index.cjs +15 -6
- package/dist/index.js +1948 -613
- package/dist/lib/context.d.ts +2 -0
- package/dist/lib/heading-attributes.d.ts +8 -0
- package/dist/lib/math-parser.d.ts +8 -2
- package/dist/lib/mdast-to-ptxast.d.ts +6 -3
- package/dist/lib/parse-markdown.d.ts +16 -0
- package/dist/lib/raw-pretext.d.ts +28 -0
- package/dist/lib/remark-pretext.d.ts +4 -4
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -192,7 +192,50 @@ when both are present.
|
|
|
192
192
|
- `**text**` → `<alert>` (semantic emphasis in PreTeXt)
|
|
193
193
|
- `` `code` `` → `<c>`
|
|
194
194
|
- `$...$` and `\(...\)` → `<m>`
|
|
195
|
-
- `$$...$$` and `\[...\]` → display math (`<md>`)
|
|
195
|
+
- `$$...$$` and `\[...\]` → display math (`<md>`), or `<m>` where display
|
|
196
|
+
math can't go (titles, emphasis, link text)
|
|
197
|
+
- Titles take the same inline elements, whether they come from a heading, a
|
|
198
|
+
directive label, or frontmatter `title:`.
|
|
199
|
+
|
|
200
|
+
### Ids and cross-references
|
|
201
|
+
|
|
202
|
+
A heading takes an id the way a directive does, in braces at the end of the
|
|
203
|
+
line. It becomes the division's `xml:id`, and any other attributes follow it:
|
|
204
|
+
|
|
205
|
+
```markdown
|
|
206
|
+
## My Title {#sec-a}
|
|
207
|
+
|
|
208
|
+
## Another Title {#sec-b label="sec-another"}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The braces must come last and start with the `#id`. Write `\{` for a title that
|
|
212
|
+
really does end in `{#id}`.
|
|
213
|
+
|
|
214
|
+
A link to an id is a cross-reference:
|
|
215
|
+
|
|
216
|
+
- `[](#sec-a)` → `<xref ref="sec-a"/>`, which PreTeXt fills in with the target's
|
|
217
|
+
own name
|
|
218
|
+
- `[this section](#sec-a)` → `<xref ref="sec-a">this section</xref>`
|
|
219
|
+
|
|
220
|
+
Inline directives (`:name[...]`) aren't read, so a colon in prose like `f:X`
|
|
221
|
+
stays text.
|
|
222
|
+
|
|
223
|
+
### Raw PreTeXt
|
|
224
|
+
|
|
225
|
+
PreTeXt can be written directly in the Markdown, for anything without Markdown
|
|
226
|
+
syntax of its own. It follows CommonMark's rules for HTML:
|
|
227
|
+
|
|
228
|
+
- **Tags within a paragraph, heading or title** become elements, and what's
|
|
229
|
+
between them is still Markdown: `<fn>about *this* and $x$</fn>`. The exceptions
|
|
230
|
+
are `<m>`, `<c>` and the other elements holding LaTeX or code, which are left
|
|
231
|
+
as written.
|
|
232
|
+
- **A block**, meaning a tag that starts a line and stands alone there, or a
|
|
233
|
+
block-level element like `<figure>`, stays PreTeXt through to its closing tag,
|
|
234
|
+
even past blank lines. Markdown and `$` aren't read inside it. Anything that
|
|
235
|
+
can only be in a paragraph, like a lone `<xref>` line, gets a `<p>`.
|
|
236
|
+
|
|
237
|
+
Comments (`<!-- ... -->`) are dropped. Tags that don't balance, don't parse, or
|
|
238
|
+
aren't PreTeXt (`<br>`, `<div>`) come out as a `<TODO>` holding the source.
|
|
196
239
|
|
|
197
240
|
## Supported Directives
|
|
198
241
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("unified"),X=require("remark-parse"),Z=require("remark-directive"),v=require("@pretextbook/ptxast"),K=require("unist-util-visit");function ce(e,t={}){const n={};for(const[o,i]of Object.entries(t))i!=null&&(n[o]=i);return{type:"element",name:`plus:${e}`,attributes:n,children:[]}}function ue(e){const t=e.name?.trim();return t?ce(t,e.attributes??{}):null}const R={theorem:{type:"theorem",category:"theorem-like",requiresStatement:!0},lemma:{type:"lemma",category:"theorem-like",requiresStatement:!0},corollary:{type:"corollary",category:"theorem-like",requiresStatement:!0},proposition:{type:"proposition",category:"theorem-like",requiresStatement:!0},claim:{type:"claim",category:"theorem-like",requiresStatement:!0},fact:{type:"fact",category:"theorem-like",requiresStatement:!0},conjecture:{type:"conjecture",category:"theorem-like",requiresStatement:!0},axiom:{type:"axiom",category:"theorem-like",requiresStatement:!0},principle:{type:"principle",category:"theorem-like",requiresStatement:!0},hypothesis:{type:"hypothesis",category:"theorem-like",requiresStatement:!0},algorithm:{type:"algorithm",category:"theorem-like",requiresStatement:!0},definition:{type:"definition",category:"definition-like",requiresStatement:!0},notation:{type:"notation",category:"definition-like",requiresStatement:!0},remark:{type:"remark",category:"remark-like",requiresStatement:!1},note:{type:"note",category:"remark-like",requiresStatement:!1},observation:{type:"observation",category:"remark-like",requiresStatement:!1},warning:{type:"warning",category:"remark-like",requiresStatement:!1},insight:{type:"insight",category:"remark-like",requiresStatement:!1},assemblage:{type:"assemblage",category:"remark-like",requiresStatement:!1},example:{type:"example",category:"example-like",requiresStatement:!1},question:{type:"question",category:"example-like",requiresStatement:!1},problem:{type:"problem",category:"example-like",requiresStatement:!1},exercise:{type:"exercise",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},activity:{type:"activity",category:"example-like",requiresStatement:!1},exploration:{type:"exploration",category:"example-like",requiresStatement:!1},investigation:{type:"investigation",category:"example-like",requiresStatement:!1},project:{type:"project",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},task:{type:"task",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},proof:{type:"proof",category:"proof-like",requiresStatement:!1},case:{type:"case",category:"proof-like",requiresStatement:!1},solution:{type:"solution",category:"solution-like",requiresStatement:!1},hint:{type:"hint",category:"solution-like",requiresStatement:!1},answer:{type:"answer",category:"solution-like",requiresStatement:!1}},ae=R;function pe(e){return R[e.toLowerCase()]}const j=new Set(Object.entries(R).filter(([e,t])=>t.category==="proof-like"||t.category==="solution-like").map(([e])=>e));function x(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function I(e){return e.type==="containerDirective"&&e.name==="task"}function fe(e){return e.type==="containerDirective"&&j.has(e.name)}function E(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(x("p",[n])):t.push(n);return t}function he(e,t,n,o,i,r,s){const l=[];if(n&&l.push(n),e.hasNestedTasks){const c=o.findIndex(I);if(c!==-1){const u=[];for(let f=0;f<o.length;f++)I(o[f])&&u.push(f);const a=u[u.length-1],p=o.slice(0,c),d=o.slice(c).filter(I),g=[],y=[],k=[];for(let f=c;f<o.length;f++){const m=o[f];if(!I(m)){if(f<a){g.push(m);continue}if(fe(m)){k.push(m);continue}y.push(m)}}if(g.length>0&&(i.messages??(i.messages=[])).push({type:"warning",reason:`Dropped ${g.length} non-task node(s) between task directives in ${e.type}.`,category:"dropped-content-between-tasks",position:g[0].position?.start}),p.length>0){const f=E(p.map(m=>r(m,i)).filter(m=>m!==null));f.length>0&&l.push(x("introduction",f))}for(const f of d){const m=s(f,i);m&&l.push(m)}if(y.length>0){const f=E(y.map(m=>r(m,i)).filter(m=>m!==null));f.length>0&&l.push(x("conclusion",f))}for(const f of k){const m=s(f,i);m&&l.push(m)}}else z(l,e,o,i,r,s)}else z(l,e,o,i,r,s);return x(e.type,l,t)}function z(e,t,n,o,i,r){if(t.requiresStatement){const s=[],l=[];for(const c of n)if(c.type==="containerDirective"&&j.has(c.name)){const u=r(c,o);u&&l.push(u)}else s.push(c);if(s.length>0){const c=E(s.map(u=>i(u,o)).filter(u=>u!==null));c.length>0&&e.push(x("statement",c))}e.push(...l)}else{const s=E(n.map(l=>i(l,o)).filter(l=>l!==null));e.push(...s)}}function q(e){return{type:"text",value:e}}function h(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function b(e,t,n){return h(e,[q(t)],n)}function Y(e){return{type:"comment",value:e.replace(/--/g,"- -")}}function $(e,t){const n=e?.position,o=n?.start?.offset,i=n?.end?.offset;return t.source&&o!=null&&i!=null?t.source.slice(o,i):""}function B(e,t,n){return h("TODO",[Y(`todo: ${t}`),b("pre",n)],{type:e})}function de(e,t,n){return h("TODO",[Y(`todo: ${t}`),b("c",n)],{type:e})}function A(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(h("p",[n])):t.push(n);return t}function O(e,t,n){return me(e,t,n).tree}function me(e,t,n){const o=[],i={ancestors:[],depth:0,messages:o,source:t,topLevelDivision:n?.topLevelDivision??"chapter",documentRoot:n?.documentRoot,topLevelAttributes:n?.topLevelAttributes,topLevelAttributesApplied:n?.topLevelAttributes?{done:!1}:void 0,topLevelTitle:n?.topLevelTitle},r=e.children;if(i.documentRoot){const a=S(i),p=i.topLevelTitle?h("title",[q(i.topLevelTitle)]):null,{introduction:d,rest:g}=T(r,i),y=L(g,i),k=[...p?[p]:[],...d?[d]:[],...y];return{tree:{type:"root",children:[h(i.documentRoot,k,a)]},messages:o}}if(v.isTitlelessDivisionType(i.topLevelDivision)){const a=S(i),p=A(L(r,{...i,depth:1},!0));return{tree:{type:"root",children:[h(i.topLevelDivision,p,a)]},messages:o}}if(i.topLevelTitle){const a=S(i),p=h("title",[q(i.topLevelTitle)]),d={...i,depth:i.depth+1,headingDepthOffset:(i.headingDepthOffset??0)+1},{introduction:g,rest:y}=T(r,d),k=A(L(y,d,!0)),f=g?[p,g,...k]:[p,...k];return{tree:{type:"root",children:[h(i.topLevelDivision,f,a)]},messages:o}}const{introduction:s,rest:l}=T(r,i),c=L(l,i);return{tree:{type:"root",children:s?[s,...c]:c},messages:o}}function L(e,t,n=!1){let o=7;for(const u of e)u.type==="heading"&&(o=Math.min(o,u.depth));if(o===7)return w(e,t,n);const i=[];let r=null,s=[],l=[];const c=()=>{r&&(i.push(ge(r,l,t)),r=null,l=[])};for(const u of e)u.type==="heading"&&u.depth===o?(!r&&s.length>0&&(i.push(...w(s,t,n)),s=[]),c(),r=u,l=[]):r?l.push(u):s.push(u);return!r&&s.length>0&&i.push(...w(s,t,n)),c(),i}function w(e,t,n=!1){const o=[];for(let i=0;i<e.length;i+=1){const r=e[i],s=_(r,t);if(s!==null){if(s.name==="p"&&s.children.length===1&&s.children[0].name==="md"){const l=s.children[0],c=o[o.length-1],u=i+1<e.length?_(e[i+1],t):null,a=u?.name==="p"?u.children:null;if(c?.name==="p")c.children.push(l),a&&(c.children.push(...a),i+=1);else{const p=[l];a&&(p.push(...a),i+=1),o.push(h("p",p))}continue}if((s.name==="ul"||s.name==="ol")&&o.length>0){const l=o[o.length-1];if(l?.name==="p"){l.children.push(s);continue}}o.push(s)}}return n?A(o):o}function ge(e,t,n){const o=e.depth+(n.headingDepthOffset??0),i=n.documentRoot?v.divisionTypeAtRootDepth(n.documentRoot,o):v.divisionTypeAtRelativeDepth(n.topLevelDivision,o),r=h("title",D(e.children,n)),s=ke(e,n),l={...n,depth:n.depth+1},{introduction:c,rest:u}=T(t,l),a=L(u,l,!0),p=A(a),d=c?[r,c,...p]:[r,...p];return h(i,d,s)}function ye(e){return e.type==="leafDirective"&&v.isTopLevelDivisionType(e.name)}function T(e,t){const n=e.findIndex(l=>l.type==="heading"||ye(l));if(n<=0)return{introduction:null,rest:e};const o=e.slice(0,n),i=e.slice(n),r=w(o,t,!0);return{introduction:r.length>0?h("introduction",r):null,rest:i}}function ve(e){const t=e.data;return t?.id?{"xml:id":t.id}:void 0}function ke(e,t){const n=ve(e),o=S(t);if(!(!n&&!o))return{...o,...n}}function S(e){if(e.depth!==0)return;const t=e.topLevelAttributesApplied;if(!(!e.topLevelAttributes||!t||t.done))return t.done=!0,e.topLevelAttributes}const be={paragraph:(e,t)=>Q(e,t),blockquote:(e,t)=>De(e,t),list:(e,t)=>Ce(e,t),code:(e,t)=>xe(e),containerDirective:(e,t)=>G(e,t),leafDirective:(e,t)=>Se(e,t)};function _(e,t){const n=be[e.type];return n?n(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),B("unknown-block-type",`unknown block type "${e.type}"`,$(e,t)))}function Q(e,t){return h("p",D(e.children,t))}function De(e,t){const n=e.children.filter(o=>o.type==="paragraph").map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Q(o,i)});return h("blockquote",n)}function Ce(e,t){const n=e.children.map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Le(o,i)});return h(e.ordered?"ol":"ul",n)}function Le(e,t){const n=w(e.children,t);return h("li",n)}function xe(e,t){return b("program",e.value,e.lang?{language:e.lang}:void 0)}function we(e,t){const n=e.value.split(/\\\\|[\r\n]+/).map(o=>o.trim()).filter(o=>o.length>0);return n.length>1?h("md",n.map(o=>b("mrow",o))):b("md",n[0]??"")}function Ie(e,t){return e.meta==="inline"?b("m",e.value):we(e)}function Te(e,t){return h("url",D(e.children,t),{href:e.url})}function Se(e,t){const n=ue(e);return n||(t.messages&&t.messages.push({type:"warning",reason:"Unnamed leaf directive",category:"unknown-directive"}),B("unknown-directive","unnamed leaf directive",$(e,t)))}function G(e,t){const n=pe(e.name);if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),B("unknown-directive",`unknown directive "${e.name}"`,$(e,t));const o=qe(e),i=e.children,{title:r,body:s}=Ee(i,t),l={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return he(n,o,r,s,l,(c,u)=>_(c,u),(c,u)=>G(c,u))}function Ee(e,t){const n=e[0];return n?.type==="paragraph"&&n.data?.directiveLabel===!0?{title:h("title",D(n.children,t)),body:e.slice(1)}:{title:null,body:e}}function qe(e){const t=e.attributes??{},n={};for(const[o,i]of Object.entries(t))i!=null&&(n[o==="id"?"xml:id":o]=i);return Object.keys(n).length>0?n:void 0}function Ae(e,t){return!t||e.position?.start?.offset===null||e.position?.start?.offset===void 0?"asterisk":t.charAt(e.position.start.offset)==="_"?"underscore":"asterisk"}const Me={text:(e,t)=>q(e.value),emphasis:(e,t)=>{const o=Ae(e,t.source)==="underscore"?"term":"em";return h(o,D(e.children,t))},strong:(e,t)=>h("alert",D(e.children,t)),inlineCode:(e,t)=>b("c",e.value),math:(e,t)=>Ie(e),link:(e,t)=>Te(e,t)};function D(e,t){return e.flatMap(n=>Re(n,t)).filter(n=>n!==null)}function Re(e,t){const n=Me[e.type];if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),de("unknown-inline-type",`unknown inline type "${e.type}"`,$(e,t));const o={...t,ancestors:[...t.ancestors,e]};return n(e,o)}const $e=[{open:"$$",close:"$$",isDisplay:!0},{open:"\\[",close:"\\]",isDisplay:!0},{open:"$",close:"$",isDisplay:!1},{open:"\\(",close:"\\)",isDisplay:!1}],J="PTX_MATH_TOKEN_",F=new RegExp(`${J}(\\d+)`,"g");function ee(e,t){let n=null;for(const o of $e){const i=e.indexOf(o.open,t);if(i===-1)continue;const r=e.indexOf(o.close,i+o.open.length);if(r!==-1&&!(o.open==="$"&&(i>0&&e[i-1]==="$"||i+1<e.length&&e[i+1]==="$"))&&(!n||i<n.index)){const s=e.substring(i+o.open.length,r);n={index:i,pattern:o,content:s}}}return n}function Fe(e,t){let n=t;for(;n<e.length;){const o=e.indexOf("`",n);if(o===-1)return null;let i=0,r=o;for(;r<e.length&&e[r]==="`";)i++,r++;const s="`".repeat(i);let l=r;for(;l<e.length;){const c=e.indexOf(s,l);if(c===-1)break;const u=c+i;if(u>=e.length||e[u]!=="`")return{start:o,end:u};l=c+1}n=o+i}return null}function Oe(e){const t=new Map;let n="",o=0,i=0;for(;o<e.length;){const r=Fe(e,o),s=ee(e,o);if(r&&(!s||r.start<s.index)){n+=e.substring(o,r.end),o=r.end;continue}if(!s){n+=e.substring(o);break}n+=e.substring(o,s.index);const l=`${J}${i}`;n+=l,t.set(l,{type:"math",value:s.content,meta:s.pattern.isDisplay?"display":"inline"}),o=s.index+s.pattern.open.length+s.content.length+s.pattern.close.length,i+=1}return{markdown:n,tokens:t}}function _e(e){const t=[];let n=0;for(;n<e.length;){const o=ee(e,n);if(!o){n<e.length&&t.push({type:"text",value:e.substring(n)});break}o.index>n&&t.push({type:"text",value:e.substring(n,o.index)}),t.push({type:"math",value:o.content,meta:o.pattern.isDisplay?"display":"inline"}),n=o.index+o.pattern.open.length+o.content.length+o.pattern.close.length}return t.length===0?[{type:"text",value:e}]:t}function Ne(e,t){const n=[];let o=0;F.lastIndex=0;let i=F.exec(e);for(;i;){const r=i.index,s=i[0];r>o&&n.push({type:"text",value:e.substring(o,r)});const l=t.get(s);l?n.push(l):n.push({type:"text",value:s}),o=r+s.length,i=F.exec(e)}return o<e.length&&n.push({type:"text",value:e.substring(o)}),n.length===0?[{type:"text",value:e}]:n}function te(e){K.visit(e,"paragraph",t=>{const n=t.children||[],o=[];for(const i of n)if(i.type==="text"){const r=_e(i.value);o.push(...r)}else o.push(i);t.children=o})}function Pe(e,t){K.visit(e,"paragraph",n=>{const o=n.children||[],i=[];for(const r of o)if(r.type==="text"){const s=Ne(r.value,t);i.push(...s)}else i.push(r);n.children=i})}const je=()=>e=>{te(e)};function Be(e){const t=e.trim();if(!t.startsWith(":"))return null;let n=0;for(let r=0;r<t.length&&t[r]===":";r++)n++;if(n<3)return null;const o=t.slice(n).trim(),i=o.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);return o===""?{colons:n,label:null,lineIndex:-1,isOpen:!1}:i?{colons:n,label:i[0],lineIndex:-1,isOpen:!0}:null}function ze(e){const t=[],n=[];for(const o of e)if(o.isOpen){const i={colons:o.colons,finalColons:o.colons,label:o.label,openLineIndex:o.lineIndex,closeLineIndex:null,children:[],parent:null};if(t.length>0){const r=t[t.length-1];i.parent=r,r.children.push(i)}else n.push(i);t.push(i)}else{const i=t[t.length-1];i&&i.colons===o.colons&&(i.closeLineIndex=o.lineIndex,t.pop())}return n}function ne(e){if(e.children.length===0)e.finalColons=e.colons;else{const t=Math.max(...e.children.map(ne));e.finalColons=Math.max(e.colons,t+1)}return e.finalColons}function Ue(e,t,n){const o=e.slice(),i=[],r=t.slice();for(;r.length>0;){const s=r.shift();i.push(s),r.push(...s.children)}for(const s of i){if(s.openLineIndex>=0){const l=o[s.openLineIndex],c=l.match(/^:+/)?.[0].length||3,u=l.slice(c);o[s.openLineIndex]=":".repeat(s.finalColons)+u}s.closeLineIndex!==null&&s.closeLineIndex>=0&&(o[s.closeLineIndex]=":".repeat(s.finalColons))}return o}function We(e){const t=e.split(`
|
|
2
|
-
`),n=[];let
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("unist-util-visit"),oe=require("unified"),le=require("remark-parse"),Ae=require("remark-directive"),S=require("@pretextbook/ptxast"),Oe=/([\w:.-]+)=(?:"([^"]*)"|'([^']*)'|([^\s"'{}]+))/g,rt=new RegExp(String.raw`\s*\{#([\w:.-]+)((?:\s+${Oe.source})*)\s*\}$`);function st(e,t){const{start:n,end:i}=e.position??{},r=t?.slice(n?.offset,i?.offset)??"";return r[r.lastIndexOf("{")-1]==="\\"}function ot(e,t){H.visit(e,"heading",n=>{const i=n.children[n.children.length-1];if(i?.type!=="text")return;const r=rt.exec(i.value);if(!r||st(n,t))return;const s={};for(const[,c,...a]of r[2].matchAll(Oe))s[c]=a.find(h=>h!==void 0)??"";n.data={...n.data,id:r[1],attributes:s},i.value=i.value.slice(0,r.index),i.value||n.children.pop()})}const lt=[{open:"$$",close:"$$",isDisplay:!0},{open:"\\[",close:"\\]",isDisplay:!0},{open:"$",close:"$",isDisplay:!1},{open:"\\(",close:"\\)",isDisplay:!1}],Me="",Re="",X=new RegExp(`${Me}\\d+${Re}`,"g"),xe=/[\p{L}\p{N}]/u;function ke(e,t){let n=0;for(let i=t-1;i>=0&&e[i]==="\\";i--)n++;return n%2===1}function ct(e,t){const n=e[t-1]??"",i=e[t+1]??"";if(ke(e,t)||n==="$"||i==="$"||xe.test(n)||i===""||/\s/.test(i))return-1;let r=e.indexOf("$",t+1);for(;r!==-1&&ke(e,r);)r=e.indexOf("$",r+1);if(r===-1)return-1;const s=e.slice(t+1,r);return s.includes(`
|
|
2
|
+
`)||s.includes("`")||/\s$/.test(s)||xe.test(e[r+1]??"")?-1:r}function $e(e,t){let n=null;for(const i of lt){let r=e.indexOf(i.open,t),s=-1;for(;r!==-1&&(s=i.open==="$"?ct(e,r):e.indexOf(i.close,r+i.open.length),!(s!==-1||i.open!=="$"));)r=e.indexOf(i.open,r+1);if(!(r===-1||s===-1)&&(!n||r<n.index)){const c=e.substring(r+i.open.length,s);n={index:r,pattern:i,content:c}}}return n}function at(e,t){let n=t;for(;n<e.length;){const i=e.indexOf("`",n);if(i===-1)return null;let r=0,s=i;for(;s<e.length&&e[s]==="`";)r++,s++;const c="`".repeat(r);let a=s;for(;a<e.length;){const h=e.indexOf(c,a);if(h===-1)break;const p=h+r;if(p>=e.length||e[p]!=="`")return{start:i,end:p};a=h+1}n=i+r}return null}function qe(e){const t=new Map;let n="",i=0,r=0;for(;i<e.length;){const s=at(e,i),c=$e(e,i);if(s&&(!c||s.start<c.index)){n+=e.substring(i,s.end),i=s.end;continue}if(!c){n+=e.substring(i);break}n+=e.substring(i,c.index);const a=`${Me}${r}${Re}`;n+=a;const h=c.index+c.pattern.open.length+c.content.length+c.pattern.close.length;t.set(a,{type:"math",value:c.content,meta:c.pattern.isDisplay?"display":"inline",source:e.substring(c.index,h)}),i=h,r+=1}return{markdown:n,tokens:t}}function ut(e){const t=[];let n=0;for(;n<e.length;){const i=$e(e,n);if(!i){n<e.length&&t.push({type:"text",value:e.substring(n)});break}i.index>n&&t.push({type:"text",value:e.substring(n,i.index)}),t.push({type:"math",value:i.content,meta:i.pattern.isDisplay?"display":"inline"}),n=i.index+i.pattern.open.length+i.content.length+i.pattern.close.length}return t.length===0?[{type:"text",value:e}]:t}function ht(e,t){const n=[];let i=0;X.lastIndex=0;let r=X.exec(e);for(;r;){const s=r.index,c=r[0];s>i&&n.push({type:"text",value:e.substring(i,s)});const a=t.get(c);a?n.push(a):n.push({type:"text",value:c}),i=s+c.length,r=X.exec(e)}return i<e.length&&n.push({type:"text",value:e.substring(i)}),n.length===0?[{type:"text",value:e}]:n}function Pe(e,t){H.visit(e,"text",(n,i,r)=>{if(!r||i===void 0)return;const s=r.type==="paragraph"&&!r.data?.directiveLabel,c=t(n.value).map(a=>a.type==="math"&&!s?{...a,meta:"inline"}:a);return r.children.splice(i,1,...c),i+c.length})}function Fe(e){Pe(e,ut)}const ft=["value","url","title","alt"];function Y(e,t){return e.replace(X,n=>t.get(n)?.source??n)}function je(e,t){Pe(e,n=>ht(n,t)),H.visit(e,n=>{for(const i of ft)typeof n[i]=="string"&&(n[i]=Y(n[i],t));for(const[i,r]of Object.entries(n.attributes??{}))typeof r=="string"&&(n.attributes[i]=Y(r,t))})}const pt=()=>e=>{Fe(e)},dt=["blockQuote","codeFenced","codeIndented","definition","headingAtx","htmlFlow","list","setextUnderline","thematicBreak"];function mt(){const e=this.data();e.micromarkExtensions=e.micromarkExtensions?.map(({text:t,...n})=>n)}function gt(e){const{markdown:t,tokens:n}=qe(e),r=oe.unified().data("micromarkExtensions",[{disable:{null:["codeIndented"]}}]).use(le).use(Ae).use(mt).parse(t);return je(r,n),{tree:r,source:t,restoreSource:s=>Y(s,n)}}function yt(e){const{markdown:t,tokens:n}=qe(e);for(const s of n.values())s.meta="inline";const r=oe.unified().data("micromarkExtensions",[{disable:{null:dt}}]).use(le).parse(t);return je(r,n),{tree:r.children.flatMap(s=>s.children),source:t,restoreSource:s=>Y(s,n)}}function vt(e,t={}){const n={};for(const[i,r]of Object.entries(t))r!=null&&(n[i]=r);return{type:"element",name:`plus:${e}`,attributes:n,children:[]}}function bt(e){const t=e.name?.trim();return t?vt(t,e.attributes??{}):null}var te,Ee;function wt(){if(Ee)return te;Ee=1;var e=Object.defineProperty,t=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,r=(l,o)=>{for(var u in o)e(l,u,{get:o[u],enumerable:!0})},s=(l,o,u,f)=>{if(o&&typeof o=="object"||typeof o=="function")for(let d of n(o))!i.call(l,d)&&d!==u&&e(l,d,{get:()=>o[d],enumerable:!(f=t(o,d))||f.enumerable});return l},c=l=>s(e({},"__esModule",{value:!0}),l),a={};r(a,{XmlCdata:()=>pe,XmlComment:()=>de,XmlDeclaration:()=>me,XmlDocument:()=>ge,XmlDocumentType:()=>ye,XmlElement:()=>K,XmlError:()=>ve,XmlNode:()=>w,XmlProcessingInstruction:()=>Q,XmlText:()=>G,parseXml:()=>it}),te=c(a);var h="",p=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,m=class{constructor(l){if(this.k=this.u(l,!0),this.d=0,this.length=l.length,this.l=this.k!==this.length,this.h=l,this.l){let o=[];for(let u=0,f=0;f<this.k;++f)o[f]=u,u+=l.codePointAt(u)>65535?2:1;this.A=o}}get B(){return this.d>=this.k}u(l,o=this.l){return o?l.replace(p,"_").length:l.length}p(l=1){this.d=Math.min(this.k,this.d+l)}f(l=this.d){var o;return this.l?(o=this.A[l])!=null?o:1/0:l}G(l=1){let o=this.m(l);return this.p(l),o}v(l){let o=this.f(),u=this.h.slice(o,o+l);return this.p(this.u(u)),u}w(l){let{length:o,l:u,h:f}=this,d=this.f(),y=d;if(u)for(;y<o;){let E=f[y],C=E>="\uD800"&&E<="\uDBFF";if(C&&(E+=f[y+1]),!l(E))break;y+=C?2:1}else for(;y<o&&l(f[y]);)++y;return this.v(y-d)}b(l){let{length:o}=l,u=this.f();return l===this.h.slice(u,u+o)?(this.p(o===1?1:this.u(l)),l):h}x(l){let o=this.h.slice(this.f()).search(l);return o>0?this.v(o):h}s(l){let o=this.f(),u=this.h.indexOf(l,o);return u>0?this.v(u-o):h}m(l=1){let{d:o,h:u}=this;return this.l?u.slice(this.f(o),this.f(o+l)):u.slice(o,o+l)}n(l=0){this.d=l>=0?Math.min(this.k,l):Math.max(0,this.d+l)}},g=/["&<]/,x=/['&<]/,T=/\r\n|[\n\r\t]/g,D=/<|&|]]>/,N=Object.freeze(Object.assign(Object.create(null),{amp:"&",apos:"'",gt:">",lt:"<",quot:'"'}));function v(l){let o=l.codePointAt(0);return o>=97&&o<=122||o>=65&&o<=90||o>=48&&o<=57||o===45||o===46||o===183||o>=768&&o<=879||o===8255||o===8256||b(l,o)}function b(l,o=l.codePointAt(0)){return o>=97&&o<=122||o>=65&&o<=90||o===58||o===95||o>=192&&o<=214||o>=216&&o<=246||o>=248&&o<=767||o>=880&&o<=893||o>=895&&o<=8191||o===8204||o===8205||o>=8304&&o<=8591||o>=11264&&o<=12271||o>=12289&&o<=55295||o>=63744&&o<=64975||o>=65008&&o<=65533||o>=65536&&o<=983039}function he(l){return l==="#"||v(l)}function tt(l){let o=l.codePointAt(0);return o===32||o===9||o===10||o===13}function fe(l){return l>=32&&l<=55295||l===10||l===9||l===13||l>=57344&&l<=65533||l>=65536&&l<=1114111}var L=class Xe{constructor(){this.parent=null,this.start=-1,this.end=-1}get document(){var o,u;return(u=(o=this.parent)==null?void 0:o.document)!=null?u:null}get isRootNode(){return this.parent!==null&&this.parent===this.document&&this.type===Xe.TYPE_ELEMENT}get preserveWhitespace(){var o;return!!((o=this.parent)!=null&&o.preserveWhitespace)}get type(){return""}toJSON(){let o={type:this.type};return this.isRootNode&&(o.isRootNode=!0),this.preserveWhitespace&&(o.preserveWhitespace=!0),this.start!==-1&&(o.start=this.start,o.end=this.end),o}};L.TYPE_CDATA="cdata",L.TYPE_COMMENT="comment",L.TYPE_DOCUMENT="document",L.TYPE_DOCUMENT_TYPE="doctype",L.TYPE_ELEMENT="element",L.TYPE_PROCESSING_INSTRUCTION="pi",L.TYPE_TEXT="text",L.TYPE_XML_DECLARATION="xmldecl";var w=L,G=class extends w{constructor(l=""){super(),this.text=l}get type(){return w.TYPE_TEXT}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{text:this.text})}},pe=class extends G{get type(){return w.TYPE_CDATA}},de=class extends w{constructor(l=""){super(),this.content=l}get type(){return w.TYPE_COMMENT}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{content:this.content})}},me=class extends w{constructor(l,o,u){super(),this.version=l,this.encoding=o??null,this.standalone=u??null}get type(){return w.TYPE_XML_DECLARATION}toJSON(){let l=w.prototype.toJSON.call(this);l.version=this.version;for(let o of["encoding","standalone"])this[o]!==null&&(l[o]=this[o]);return l}},K=class Be extends w{constructor(o,u=Object.create(null),f=[]){super(),this.name=o,this.attributes=u,this.children=f}get isEmpty(){return this.children.length===0}get preserveWhitespace(){let o=this;for(;o instanceof Be;){if("xml:space"in o.attributes)return o.attributes["xml:space"]==="preserve";o=o.parent}return!1}get text(){return this.children.map(o=>"text"in o?o.text:"").join("")}get type(){return w.TYPE_ELEMENT}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{name:this.name,attributes:this.attributes,children:this.children.map(o=>o.toJSON())})}},ge=class extends w{constructor(l=[]){super(),this.children=l}get document(){return this}get root(){for(let l of this.children)if(l instanceof K)return l;return null}get text(){return this.children.map(l=>"text"in l?l.text:"").join("")}get type(){return w.TYPE_DOCUMENT}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{children:this.children.map(l=>l.toJSON())})}},ye=class extends w{constructor(l,o,u,f){super(),this.name=l,this.publicId=o??null,this.systemId=u??null,this.internalSubset=f??null}get type(){return w.TYPE_DOCUMENT_TYPE}toJSON(){let l=w.prototype.toJSON.call(this);l.name=this.name;for(let o of["publicId","systemId","internalSubset"])this[o]!==null&&(l[o]=this[o]);return l}},ve=class extends Error{constructor(l,o,u){let f=1,d="",y=1;for(let ee=0;ee<o;++ee){let we=u[ee];we===`
|
|
3
|
+
`?(f=1,d="",y+=1):(f+=1,d+=we)}let E=u.indexOf(`
|
|
4
|
+
`,o);d+=E===-1?u.slice(o):u.slice(o,E);let C=0;d.length>50&&(f<40?d=d.slice(0,50):(C=f-20,d=d.slice(C,f+30))),super(`${l} (line ${y}, column ${f})
|
|
5
|
+
${d}
|
|
6
|
+
`+" ".repeat(f-C+1)+`^
|
|
7
|
+
`),this.column=f,this.excerpt=d,this.line=y,this.name="XmlError",this.pos=o}},Q=class extends w{constructor(l,o=""){super(),this.name=l,this.content=o}get type(){return w.TYPE_PROCESSING_INSTRUCTION}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{name:this.name,content:this.content})}},be="",nt=class{constructor(l,o={}){let u=this.document=new ge;this.j=u,this.g=o,this.c=new m(l),this.g.includeOffsets&&(u.start=0,u.end=l.length),this.parse()}i(l,o){return l.parent=this.j,this.g.includeOffsets&&(l.start=this.c.f(o),l.end=this.c.f()),this.j.children.push(l),!0}y(l,o,u=!0){let{children:f}=this.j,{length:d}=f;if(u&&(l=F(l)),d>0){let y=f[d-1];if(y?.type===w.TYPE_TEXT){let E=y;return E.text+=l,this.g.includeOffsets&&(E.end=this.c.f()),!0}}return this.i(new G(l),o)}H(){let l=Object.create(null);for(;this.e();){let o=this.q();if(!o)break;let u=this.t()&&this.I();if(u===!1)throw this.a("Attribute value expected");if(o in l)throw this.a(`Duplicate attribute: ${o}`);if(o==="xml:space"&&u!=="default"&&u!=="preserve")throw this.a('Value of the `xml:space` attribute must be "default" or "preserve"');l[o]=u}if(this.g.sortAttributes){let o=Object.keys(l).sort(),u=Object.create(null);for(let f=0;f<o.length;++f){let d=o[f];u[d]=l[d]}l=u}return l}I(){let{c:l}=this,o=l.m();if(o!=='"'&&o!=="'")return!1;l.p();let u,f=!1,d=be,y=o==='"'?g:x;e:for(;!l.B;)switch(u=l.x(y),u&&(this.o(u),d+=u.replace(T," ")),l.m()){case o:f=!0;break e;case"&":d+=this.C();continue;case"<":throw this.a("Unescaped `<` is not allowed in an attribute value");default:break e}if(!f)throw this.a("Unclosed attribute");return l.p(),d}J(){let{c:l}=this,o=l.d;if(!l.b("<![CDATA["))return!1;let u=l.s("]]>");if(this.o(u),!l.b("]]>"))throw this.a("Unclosed CDATA section");return this.g.preserveCdata?this.i(new pe(F(u)),o):this.y(u,o)}K(){let{c:l}=this,o=l.d,u=l.x(D);if(!u)return!1;if(this.o(u),l.m(3)==="]]>")throw this.a("Element content may not contain the CDATA section close delimiter `]]>`");return this.y(u,o)}D(){let{c:l}=this,o=l.d;if(!l.b("<!--"))return!1;let u=l.s("--");if(this.o(u),!l.b("-->"))throw l.m(2)==="--"?this.a("The string `--` isn't allowed inside a comment"):this.a("Unclosed comment");return this.g.preserveComments?this.i(new de(F(u)),o):!0}L(){let l=this.c.d,o=this.C();return o?this.y(o,l,!1):!1}M(){let{c:l}=this,o=l.d;if(!l.b("<!DOCTYPE"))return!1;let u=this.e()&&this.q();if(!u)throw this.a("Expected a name");let f,d;if(this.e()){if(l.b("PUBLIC")){if(f=this.e()&&this.N(),f===!1)throw this.a("Expected a public identifier");this.e()}if(f!==void 0||l.b("SYSTEM")){if(this.e(),d=this.r(),d===!1)throw this.a("Expected a system identifier");this.e()}}let y;if(l.b("[")){if(y=l.x(/\][\x20\t\r\n]*>/),!l.b("]"))throw this.a("Unclosed internal subset");this.e()}if(!l.b(">"))throw this.a("Unclosed doctype declaration");return this.g.preserveDocumentType?this.i(new ye(u,f,d,y),o):!0}E(){let{c:l}=this,o=l.d;if(!l.b("<"))return!1;let u=this.q();if(!u)return l.n(o),!1;let f=this.H(),d=!!l.b("/>"),y=new K(u,f);if(y.parent=this.j,!d){if(!l.b(">"))throw this.a(`Unclosed start tag for element \`${u}\``);this.j=y;do this.K();while(this.E()||this.L()||this.J()||this.F()||this.D());let E=l.d,C;if(!l.b("</")||!(C=this.q())||C!==u)throw l.n(E),this.a(`Missing end tag for element ${u}`);if(this.e(),!l.b(">"))throw this.a(`Unclosed end tag for element ${u}`);this.j=y.parent}return this.i(y,o)}t(){return this.e(),this.c.b("=")?(this.e(),!0):!1}z(){return this.D()||this.F()||this.e()}q(){return b(this.c.m())?this.c.w(v):be}F(){let{c:l}=this,o=l.d;if(!l.b("<?"))return!1;let u=this.q();if(u){if(u.toLowerCase()==="xml")throw l.n(o),this.a("XML declaration isn't allowed here")}else throw this.a("Invalid processing instruction");if(!this.e()){if(l.b("?>"))return this.i(new Q(u),o);throw this.a("Whitespace is required after a processing instruction name")}let f=l.s("?>");if(this.o(f),!l.b("?>"))throw this.a("Unterminated processing instruction");return this.i(new Q(u,F(f)),o)}O(){let{c:l}=this,o=l.d;for(this.P();this.z(););if(this.M())for(;this.z(););return o<l.d}N(){let l=this.c.d,o=this.r();if(o!==!1&&!/^[-\x20\r\na-zA-Z0-9'()+,./:=?;!*#@$_%]*$/.test(o))throw this.c.n(l),this.a("Invalid character in public identifier");return o}C(){let{c:l}=this;if(!l.b("&"))return!1;let o=l.w(he);if(l.G()!==";")throw this.a("Unterminated reference (a reference must end with `;`)");let u;if(o[0]==="#"){let f=o[1]==="x"?parseInt(o.slice(2),16):parseInt(o.slice(1),10);if(isNaN(f)||!/^#(?:x[0-9A-Fa-f]+|[0-9]+)$/.test(o))throw this.a("Invalid character reference");if(!fe(f))throw this.a("Character reference resolves to an invalid character");u=String.fromCodePoint(f)}else if(u=N[o],u===void 0){let{ignoreUndefinedEntities:f,resolveUndefinedEntity:d}=this.g,y=`&${o};`;if(d){let E=d(y);if(E!=null){let C=typeof E;if(C!=="string")throw new TypeError(`\`resolveUndefinedEntity()\` must return a string, \`null\`, or \`undefined\`, but returned a value of type ${C}`);return E}}if(f)return y;throw l.n(-y.length),this.a(`Named entity isn't defined: ${y}`)}return u}r(){let{c:l}=this,o=l.b('"')||l.b("'");if(!o)return!1;let u=l.s(o);if(this.o(u),!l.b(o))throw this.a("Missing end quote");return u}e(){return!!this.c.w(tt)}P(){let{c:l}=this,o=l.d;if(!l.b("<?xml"))return!1;if(!this.e())throw this.a("Invalid XML declaration");let u=!!l.b("version")&&this.t()&&this.r();if(u===!1)throw this.a("XML version is missing or invalid");if(!/^1\.[0-9]+$/.test(u))throw this.a("Invalid character in version number");let f,d;if(this.e()){if(f=!!l.b("encoding")&&this.t()&&this.r(),f){if(!/^[A-Za-z][\w.-]*$/.test(f))throw this.a("Invalid character in encoding name");this.e()}if(d=!!l.b("standalone")&&this.t()&&this.r(),d){if(d!=="yes"&&d!=="no")throw this.a('Only "yes" and "no" are permitted as values of `standalone`');this.e()}}if(!l.b("?>"))throw this.a("Invalid or unclosed XML declaration");return this.g.preserveXmlDeclaration?this.i(new me(u,f||void 0,d||void 0),o):!0}a(l){let{c:o}=this;return new ve(l,o.d,o.h)}parse(){if(this.c.b("\uFEFF"),this.O(),!this.E())throw this.a("Root element is missing or invalid");for(;this.z(););if(!this.c.B)throw this.a("Extra content at the end of the document")}o(l){let{length:o}=l;for(let u=0;u<o;++u){let f=l.codePointAt(u);if(!fe(f))throw this.c.n(-([...l].length-u)),this.a("Invalid character");f>65535&&(u+=1)}}};function F(l){let o=0;for(;(o=l.indexOf("\r",o))!==-1;)l=l[o+1]===`
|
|
8
|
+
`?l.slice(0,o)+l.slice(o+1):l.slice(0,o)+`
|
|
9
|
+
`+l.slice(o+1);return l}function it(l,o){return new nt(l,o).document}return te}var xt=wt();function kt(e){const t=String(e),n=[];return{toOffset:r,toPoint:i};function i(s){if(typeof s=="number"&&s>-1&&s<=t.length){let c=0;for(;;){let a=n[c];if(a===void 0){const h=De(t,n[c-1]);a=h===-1?t.length+1:h+1,n[c]=a}if(a>s)return{line:c+1,column:s-(c>0?n[c-1]:0)+1,offset:s};c++}}}function r(s){if(s&&typeof s.line=="number"&&typeof s.column=="number"&&!Number.isNaN(s.line)&&!Number.isNaN(s.column)){for(;n.length<s.line;){const a=n[n.length-1],h=De(t,a),p=h===-1?t.length+1:h+1;if(a===p)break;n.push(p)}const c=(s.line>1?n[s.line-2]:0)+s.column-1;if(c<n[s.line-1])return c}}}function De(e,t){const n=e.indexOf("\r",t),i=e.indexOf(`
|
|
10
|
+
`,t);return i===-1?n:n===-1||n+1===i?i:n<i?n:i}function Et(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?Te(e.position):"start"in e||"end"in e?Te(e):"line"in e||"column"in e?ne(e):""}function ne(e){return Ie(e&&e.line)+":"+Ie(e&&e.column)}function Te(e){return ne(e&&e.start)+"-"+ne(e&&e.end)}function Ie(e){return e&&typeof e=="number"?e:1}class I extends Error{constructor(t,n,i){super(),typeof n=="string"&&(i=n,n=void 0);let r="",s={},c=!1;if(n&&("line"in n&&"column"in n?s={place:n}:"start"in n&&"end"in n?s={place:n}:"type"in n?s={ancestors:[n],place:n.position}:s={...n}),typeof t=="string"?r=t:!s.cause&&t&&(c=!0,r=t.message,s.cause=t),!s.ruleId&&!s.source&&typeof i=="string"){const h=i.indexOf(":");h===-1?s.ruleId=i:(s.source=i.slice(0,h),s.ruleId=i.slice(h+1))}if(!s.place&&s.ancestors&&s.ancestors){const h=s.ancestors[s.ancestors.length-1];h&&(s.place=h.position)}const a=s.place&&"start"in s.place?s.place.start:s.place;this.ancestors=s.ancestors||void 0,this.cause=s.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=r,this.line=a?a.line:void 0,this.name=Et(s.place)||"1:1",this.place=s.place||void 0,this.reason=this.message,this.ruleId=s.ruleId||void 0,this.source=s.source||void 0,this.stack=c&&s.cause&&typeof s.cause.stack=="string"?s.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}I.prototype.file="";I.prototype.name="";I.prototype.reason="";I.prototype.message="";I.prototype.stack="";I.prototype.column=void 0;I.prototype.line=void 0;I.prototype.ancestors=void 0;I.prototype.cause=void 0;I.prototype.fatal=void 0;I.prototype.place=void 0;I.prototype.ruleId=void 0;I.prototype.source=void 0;function Dt(e){const t=kt(e);let n;try{n=xt.parseXml(String(e),{includeOffsets:!0,preserveCdata:!0,preserveComments:!0,preserveDocumentType:!0,preserveXmlDeclaration:!0})}catch(s){const c=s,a=t.toPoint(c.pos),h=new I("Could not parse XML with `@rgrove/parse-xml`",{cause:c,place:a,ruleId:"error",source:"xast-util-from-xml"});throw h.fatal=!0,h.url="https://github.com/syntax-tree/xast-util-from-xml#throws",h}const i={location:t},r=Ct(n,i);return Ye(n,r,i),r}function Tt(e){return{type:"cdata",value:e.text}}function It(e){return{type:"comment",value:e.content}}function Ct(e,t){return{type:"root",children:Ue(e.children,t)}}function St(e){return{type:"doctype",name:e.name,public:e.publicId||void 0,system:e.systemId||void 0}}function Lt(e,t){const n=Ue(e.children,t);return{type:"element",name:e.name,attributes:{...e.attributes},children:n}}function Nt(e){return{type:"instruction",name:e.name,value:e.content}}function _t(e){return{type:"text",value:e.text}}function At(e){const t=[];return e.version&&t.push('version="'+e.version+'"'),e.encoding&&t.push('encoding="'+e.encoding+'"'),e.standalone&&t.push('standalone="'+e.standalone+'"'),{type:"instruction",name:"xml",value:t.join(" ")}}function Ue(e,t){const n=[];let i=-1;for(;++i<e.length;){const r=e[i];let s;r.type==="cdata"?s=Tt(r):r.type==="comment"?s=It(r):r.type==="doctype"?s=St(r):r.type==="element"?s=Lt(r,t):r.type==="pi"?s=Nt(r):r.type==="text"?s=_t(r):r.type==="xmldecl"&&(s=At(r)),s&&(Ye(r,s,t),n.push(s))}return n}function Ye(e,t,n){const i=e.start===-1?void 0:n.location.toPoint(e.start),r=e.end===-1?void 0:n.location.toPoint(e.end);i&&r&&(t.position={start:i,end:r})}const Ot=/<!--[\s\S]*?-->/g,ce=new Set(["me","men","mdn"]),Mt=new Set([...ce,"c","cd","cline","m","md","mrow","pre"]),Rt=new Set(["blockquote","containerDirective","listItem","root"]),ze=new Set([...ce,...S.getPtxSchemaChildElementNames("p")]);for(const e of S.getPtxSchemaChildElementNames("section"))ze.delete(e);function $t(e){return S.isPtxSchemaElementName(e)||ce.has(e)}function q(e){let t;try{t=Dt(`<raw>${e.replace(Ot,"")}</raw>`)}catch{return null}const i=t.children.find(s=>s.type==="element").children;return i.every(s=>s.type==="element"?$t(s.name):s.type!=="instruction")?i:null}function qt(e){const t=q(e);if(t)return{children:t};const[n]=q(e.replace(/>$/,"/>"))??[];return n?.type==="element"?{children:[],opens:n}:null}function Pt(e,t,n){const i=new RegExp(`^<${n}(\\s[^]*)?(?<!/)>$`),r=new RegExp(`^</${n}\\s*>$`);let s=1;for(let c=t+1;c<e.length;c+=1){if(e[c].type!=="html")continue;const{value:a}=e[c];if(i.test(a)&&(s+=1),r.test(a)&&(s-=1),s===0)return c}return-1}function Ft(e){const t=[];let n=null;for(const i of e){if(i.type==="element"&&!ze.has(i.name)){t.push(i),n=null;continue}!n&&i.type==="text"&&!i.value.trim()||(n||(n={type:"element",name:"p",attributes:{},children:[]},t.push(n)),n.children.push(i))}return t}function jt(e,t,n,i){const r=q(e[t].value);if(r)return{nodes:r,end:t};const s=e[t].position?.start.offset;if(n===void 0||s===void 0)return null;let c=e[t].position?.end.offset;for(let a=t+1;a<e.length;a+=1){const h=e[a].position?.end.offset;if(!n.slice(c,h).includes("</"))continue;c=h;const p=q(i(n.slice(s,h)));if(p)return{nodes:p,end:a}}return null}function Xt(e,t,n){H.visit(e,i=>{if(!Rt.has(i.type))return;const r=i.children;for(let s=0;s<r.length;s+=1){if(r[s].type!=="html")continue;const c=jt(r,s,t,n);if(!c)continue;const a=Ft(c.nodes).map(h=>({type:"ptxRaw",element:h}));r.splice(s,c.end-s+1,...a),s+=a.length-1}})}const Z={theorem:{type:"theorem",category:"theorem-like",requiresStatement:!0},lemma:{type:"lemma",category:"theorem-like",requiresStatement:!0},corollary:{type:"corollary",category:"theorem-like",requiresStatement:!0},proposition:{type:"proposition",category:"theorem-like",requiresStatement:!0},claim:{type:"claim",category:"theorem-like",requiresStatement:!0},fact:{type:"fact",category:"theorem-like",requiresStatement:!0},conjecture:{type:"conjecture",category:"theorem-like",requiresStatement:!0},axiom:{type:"axiom",category:"theorem-like",requiresStatement:!0},principle:{type:"principle",category:"theorem-like",requiresStatement:!0},hypothesis:{type:"hypothesis",category:"theorem-like",requiresStatement:!0},algorithm:{type:"algorithm",category:"theorem-like",requiresStatement:!0},definition:{type:"definition",category:"definition-like",requiresStatement:!0},notation:{type:"notation",category:"definition-like",requiresStatement:!0},remark:{type:"remark",category:"remark-like",requiresStatement:!1},note:{type:"note",category:"remark-like",requiresStatement:!1},observation:{type:"observation",category:"remark-like",requiresStatement:!1},warning:{type:"warning",category:"remark-like",requiresStatement:!1},insight:{type:"insight",category:"remark-like",requiresStatement:!1},assemblage:{type:"assemblage",category:"remark-like",requiresStatement:!1},example:{type:"example",category:"example-like",requiresStatement:!1},question:{type:"question",category:"example-like",requiresStatement:!1},problem:{type:"problem",category:"example-like",requiresStatement:!1},exercise:{type:"exercise",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},activity:{type:"activity",category:"example-like",requiresStatement:!1},exploration:{type:"exploration",category:"example-like",requiresStatement:!1},investigation:{type:"investigation",category:"example-like",requiresStatement:!1},project:{type:"project",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},task:{type:"task",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},proof:{type:"proof",category:"proof-like",requiresStatement:!1},case:{type:"case",category:"proof-like",requiresStatement:!1},solution:{type:"solution",category:"solution-like",requiresStatement:!1},hint:{type:"hint",category:"solution-like",requiresStatement:!1},answer:{type:"answer",category:"solution-like",requiresStatement:!1}},Bt=Z;function Ut(e){return Z[e.toLowerCase()]}const ae=new Set(Object.entries(Z).filter(([e,t])=>t.category==="proof-like"||t.category==="solution-like").map(([e])=>e));function R(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function j(e){return e.type==="containerDirective"&&e.name==="task"}function Yt(e){return e.type==="containerDirective"&&ae.has(e.name)}function z(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(R("p",[n])):t.push(n);return t}function zt(e,t,n,i,r,s,c){const a=[];if(n&&a.push(n),e.hasNestedTasks){const h=i.findIndex(j);if(h!==-1){const p=[];for(let v=0;v<i.length;v++)j(i[v])&&p.push(v);const m=p[p.length-1],g=i.slice(0,h),x=i.slice(h).filter(j),T=[],D=[],N=[];for(let v=h;v<i.length;v++){const b=i[v];if(!j(b)){if(v<m){T.push(b);continue}if(Yt(b)){N.push(b);continue}D.push(b)}}if(T.length>0&&(r.messages??(r.messages=[])).push({type:"warning",reason:`Dropped ${T.length} non-task node(s) between task directives in ${e.type}.`,category:"dropped-content-between-tasks",position:T[0].position?.start}),g.length>0){const v=z(g.map(b=>s(b,r)).filter(b=>b!==null));v.length>0&&a.push(R("introduction",v))}for(const v of x){const b=c(v,r);b&&a.push(b)}if(D.length>0){const v=z(D.map(b=>s(b,r)).filter(b=>b!==null));v.length>0&&a.push(R("conclusion",v))}for(const v of N){const b=c(v,r);b&&a.push(b)}}else Ce(a,e,i,r,s,c)}else Ce(a,e,i,r,s,c);return R(e.type,a,t)}function Ce(e,t,n,i,r,s){if(t.requiresStatement){const c=[],a=[];for(const h of n)if(h.type==="containerDirective"&&ae.has(h.name)){const p=s(h,i);p&&a.push(p)}else c.push(h);if(c.length>0){const h=z(c.map(p=>r(p,i)).filter(p=>p!==null));h.length>0&&e.push(R("statement",h))}e.push(...a)}else{const c=z(n.map(a=>r(a,i)).filter(a=>a!==null));e.push(...c)}}function Je(e){return{type:"text",value:e}}function k(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function A(e,t,n){return k(e,[Je(t)],n)}function We(e){return{type:"comment",value:e.replace(/--/g,"- -")}}function P(e,t){const n=e?.position,i=n?.start?.offset,r=n?.end?.offset;return t.source&&i!=null&&r!=null?t.restoreSource(t.source.slice(i,r)):""}function ue(e,t,n){return k("TODO",[We(`todo: ${t}`),A("pre",n)],{type:e})}function Jt(e,t,n){return k("TODO",[We(`todo: ${t}`),A("c",n)],{type:e})}function J(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(k("p",[n])):t.push(n);return t}function ie(e,t,n){return Wt(e,t,n).tree}function Wt(e,t,n){const i=[],r=n?.restoreSource??(g=>g);Xt(e,t,r),ot(e,t);const s={ancestors:[],depth:0,messages:i,source:t,restoreSource:r,topLevelDivision:n?.topLevelDivision??"chapter",documentRoot:n?.documentRoot,topLevelAttributes:n?.topLevelAttributes,topLevelAttributesApplied:n?.topLevelAttributes?{done:!1}:void 0,topLevelTitle:n?.topLevelTitle},c=e.children;if(s.documentRoot){const g=U(s),x=s.topLevelTitle?Se(s.topLevelTitle,s):null,{introduction:T,rest:D}=B(c,s),N=s.documentRoot==="slideshow"&&Vt(D)?Ht(D,s):O(D,s),v=[...x?[x]:[],...T?[T]:[],...N];return{tree:{type:"root",children:[k(s.documentRoot,v,g)]},messages:i}}if(S.isTitlelessDivisionType(s.topLevelDivision)){const g=U(s),x=J(O(c,{...s,depth:1},!0));return{tree:{type:"root",children:[k(s.topLevelDivision,x,g)]},messages:i}}if(s.topLevelTitle){const g=U(s),x=Se(s.topLevelTitle,s),T={...s,depth:s.depth+1,headingDepthOffset:(s.headingDepthOffset??0)+1},{introduction:D,rest:N}=B(c,T),v=J(O(N,T,!0)),b=D?[x,D,...v]:[x,...v];return{tree:{type:"root",children:[k(s.topLevelDivision,b,g)]},messages:i}}const{introduction:a,rest:h}=B(c,s),p=O(h,s);return{tree:{type:"root",children:a?[a,...p]:p},messages:i}}function Se(e,t){const{tree:n,source:i,restoreSource:r}=yt(e);return k("title",_(n,{...t,source:i,restoreSource:r}))}function Vt(e){return e.some(t=>t.type==="thematicBreak")}function Ht(e,t){return O(e,t)}function O(e,t,n=!1){let i=7;for(const p of e)p.type==="heading"&&(i=Math.min(i,p.depth));if(i===7)return $(e,t,n);const r=[];let s=null,c=[],a=[];const h=()=>{s&&(r.push(Zt(s,a,t)),s=null,a=[])};for(const p of e)p.type==="heading"&&p.depth===i?(!s&&c.length>0&&(r.push(...$(c,t,n)),c=[]),h(),s=p,a=[]):s?a.push(p):c.push(p);return!s&&c.length>0&&r.push(...$(c,t,n)),h(),r}function $(e,t,n=!1){const i=[];for(let r=0;r<e.length;r+=1){const s=e[r],c=W(s,t);if(c!==null){if(c.name==="p"&&c.children.length===1&&c.children[0].name==="md"){const a=c.children[0],h=i[i.length-1],p=r+1<e.length?W(e[r+1],t):null,m=p?.name==="p"?p.children:null;if(h?.name==="p")h.children.push(a),m&&(h.children.push(...m),r+=1);else{const g=[a];m&&(g.push(...m),r+=1),i.push(k("p",g))}continue}if((c.name==="ul"||c.name==="ol")&&i.length>0){const a=i[i.length-1];if(a?.name==="p"){a.children.push(c);continue}}i.push(c)}}return n?J(i):i}function Zt(e,t,n){const i=e.depth+(n.headingDepthOffset??0),r=n.documentRoot?S.divisionTypeAtRootDepth(n.documentRoot,i):S.divisionTypeAtRelativeDepth(n.topLevelDivision,i),s=k("title",_(e.children,n)),c=Qt(e,n),a={...n,depth:n.depth+1},{introduction:h,rest:p}=B(t,a),m=O(p,a,!0),g=J(m),x=h?[s,h,...g]:[s,...g];return k(r,x,c)}function Gt(e){return e.type==="leafDirective"&&S.isTopLevelDivisionType(e.name)}function B(e,t){const n=e.findIndex(a=>a.type==="heading"||Gt(a));if(n<=0)return{introduction:null,rest:e};const i=e.slice(0,n),r=e.slice(n),s=$(i,t,!0);return{introduction:s.length>0?k("introduction",s):null,rest:r}}function Kt(e){const t=e.data;return t?.id?{...t.attributes,"xml:id":t.id}:void 0}function Qt(e,t){const n=Kt(e),i=U(t);if(!(!n&&!i))return{...i,...n}}function U(e){if(e.depth!==0)return;const t=e.topLevelAttributesApplied;if(!(!e.topLevelAttributes||!t||t.done))return t.done=!0,e.topLevelAttributes}const en={paragraph:(e,t)=>tn(e,t),blockquote:(e,t)=>nn(e,t),list:(e,t)=>rn(e,t),code:(e,t)=>on(e),containerDirective:(e,t)=>Ve(e,t),leafDirective:(e,t)=>un(e,t),ptxRaw:e=>e.element};function W(e,t){const n=en[e.type];return n?n(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),ue("unknown-block-type",`unknown block type "${e.type}"`,P(e,t)))}function tn(e,t){return k("p",_(e.children,t))}function nn(e,t){const n=e.children.filter(i=>i.type==="paragraph"||i.type==="ptxRaw").map(i=>{const r={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return W(i,r)});return k("blockquote",n)}function rn(e,t){const n=e.children.map(i=>{const r={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return sn(i,r)});return k(e.ordered?"ol":"ul",n)}function sn(e,t){const n=$(e.children,t);return k("li",n)}function on(e,t){return A("program",e.value,e.lang?{language:e.lang}:void 0)}function ln(e,t){const n=e.value.split(/\\\\|[\r\n]+/).map(i=>i.trim()).filter(i=>i.length>0);return n.length>1?k("md",n.map(i=>A("mrow",i))):A("md",n[0]??"")}function cn(e,t){return e.meta==="inline"?A("m",e.value):ln(e)}function an(e,t){const n=_(e.children,t);return/^#./.test(e.url)?k("xref",n,{ref:e.url.slice(1)}):k("url",n,{href:e.url})}function un(e,t){const n=bt(e);return n||(t.messages&&t.messages.push({type:"warning",reason:"Unnamed leaf directive",category:"unknown-directive"}),ue("unknown-directive","unnamed leaf directive",P(e,t)))}function Ve(e,t){const n=Ut(e.name);if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),ue("unknown-directive",`unknown directive "${e.name}"`,P(e,t));const i=fn(e),r=e.children,{title:s,body:c}=hn(r,t),a={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return zt(n,i,s,c,a,(h,p)=>W(h,p),(h,p)=>Ve(h,p))}function hn(e,t){const n=e[0];return n?.type==="paragraph"&&n.data?.directiveLabel===!0?{title:k("title",_(n.children,t)),body:e.slice(1)}:{title:null,body:e}}function fn(e){const t=e.attributes??{},n={};for(const[i,r]of Object.entries(t))r!=null&&(n[i==="id"?"xml:id":i]=r);return Object.keys(n).length>0?n:void 0}function pn(e,t){return!t||e.position?.start?.offset===null||e.position?.start?.offset===void 0?"asterisk":t.charAt(e.position.start.offset)==="_"?"underscore":"asterisk"}const dn={text:(e,t)=>Je(e.value),emphasis:(e,t)=>{const i=pn(e,t.source)==="underscore"?"term":"em";return k(i,_(e.children,t))},strong:(e,t)=>k("alert",_(e.children,t)),inlineCode:(e,t)=>A("c",e.value),math:(e,t)=>cn(e),link:(e,t)=>an(e,t)};function _(e,t){const n=[];for(let i=0;i<e.length;i+=1){const r=mn(e,i,t);if(r){n.push(...r.children),i=r.end;continue}const s=gn(e[i],t);s!==null&&n.push(s)}return n}function mn(e,t,n){const i=e[t];if(i.type!=="html")return null;const r=qt(i.value);if(!r)return null;const{opens:s}=r;if(!s)return{children:r.children,end:t};const c=Pt(e,t,s.name);if(c===-1)return null;if(Mt.has(s.name)){const p={start:i.position?.start,end:e[c].position?.end},m=q(P({position:p},n));return m&&{children:m,end:c}}const a=_(e.slice(t+1,c),n);return{children:[{...s,children:a}],end:c}}function gn(e,t){const n=dn[e.type];if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),Jt("unknown-inline-type",`unknown inline type "${e.type}"`,P(e,t));const i={...t,ancestors:[...t.ancestors,e]};return n(e,i)}function yn(e){const t=e.trim();if(!t.startsWith(":"))return null;let n=0;for(let s=0;s<t.length&&t[s]===":";s++)n++;if(n<3)return null;const i=t.slice(n).trim(),r=i.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);return i===""?{colons:n,label:null,lineIndex:-1,isOpen:!1}:r?{colons:n,label:r[0],lineIndex:-1,isOpen:!0}:null}function vn(e){const t=[],n=[];for(const i of e)if(i.isOpen){const r={colons:i.colons,finalColons:i.colons,label:i.label,openLineIndex:i.lineIndex,closeLineIndex:null,children:[],parent:null};if(t.length>0){const s=t[t.length-1];r.parent=s,s.children.push(r)}else n.push(r);t.push(r)}else{const r=t[t.length-1];r&&r.colons===i.colons&&(r.closeLineIndex=i.lineIndex,t.pop())}return n}function He(e){if(e.children.length===0)e.finalColons=e.colons;else{const t=Math.max(...e.children.map(He));e.finalColons=Math.max(e.colons,t+1)}return e.finalColons}function bn(e,t,n){const i=e.slice(),r=[],s=t.slice();for(;s.length>0;){const c=s.shift();r.push(c),s.push(...c.children)}for(const c of r){if(c.openLineIndex>=0){const a=i[c.openLineIndex],h=a.match(/^:+/)?.[0].length||3,p=a.slice(h);i[c.openLineIndex]=":".repeat(c.finalColons)+p}c.closeLineIndex!==null&&c.closeLineIndex>=0&&(i[c.closeLineIndex]=":".repeat(c.finalColons))}return i}function wn(e){const t=e.split(`
|
|
11
|
+
`),n=[];let i=!1,r=null;for(let a=0;a<t.length;a++){const h=t[a],m=h.trim().match(/^(`{3,}|~{3,})/);if(m){const x=m[1];i?r&&x[0]===r[0]&&x.length>=r.length&&(i=!1,r=null):(i=!0,r=x);continue}if(i)continue;const g=yn(h);g&&n.push({...g,lineIndex:a})}if(n.length===0)return e;const s=vn(n);for(const a of s)He(a);return bn(t,s).join(`
|
|
12
|
+
`)}function xn(e){const t=e.trim();if(!t.endsWith(":"))return null;const n=t.slice(0,-1);if(!/^[a-zA-Z]/.test(n))return null;const i=n.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);if(!i)return null;const[,r,s]=i;return s&&!/^(\[[^\]]*\]|\{[^}]*\})*$/.test(s)||!Z[r.toLowerCase()]?null:n}function re(e){let t=0;for(let n=0;n<e.length;n++)if(e[n]===" ")t+=1;else if(e[n]===" ")t+=4;else break;return t}function kn(e,t){const n=re(e[t]);for(let i=t+1;i<e.length;i++)if(!Ze(e[i]))return re(e[i])>n;return!1}function Ze(e){return e.trim()===""}function En(e,t){let n=0,i=0;for(;i<e.length&&n<t;)if(e[i]===" ")n++,i++;else if(e[i]===" ")n+=4,i++;else break;return e.slice(i)}function Dn(e){const t=e.split(`
|
|
13
|
+
`),n=[],i={level:0,openDirectives:[],inCodeFence:!1,codeFenceMarker:null};for(let r=0;r<t.length;r++){const s=t[r],c=s.trim(),a=re(s),h=c.match(/^(`{3,}|~{3,})/);if(h){const m=h[1];i.inCodeFence?i.codeFenceMarker&&c.startsWith(i.codeFenceMarker)&&(i.inCodeFence=!1,i.codeFenceMarker=null):(i.inCodeFence=!0,i.codeFenceMarker=m),n.push(s);continue}if(i.inCodeFence){n.push(s);continue}if(Ze(s)){n.push("");continue}const p=xn(c);if(p&&kn(t,r)){for(;i.openDirectives.length>0&&!(i.openDirectives[i.openDirectives.length-1].indentLevel<a);){const D=i.openDirectives.pop();D&&n.push(":".repeat(D.colonCount))}const m=p.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/),g=m?m[1].toLowerCase()+(m[2]||""):p,x=i.openDirectives.length*1+3;n.push(":".repeat(x)+g),i.openDirectives.push({label:g,indentLevel:a,colonCount:x,bodyBaseIndent:-1}),i.level=a}else{for(;i.openDirectives.length>0&&a<=i.openDirectives[i.openDirectives.length-1].indentLevel;){const m=i.openDirectives.pop();m&&n.push(":".repeat(m.colonCount))}if(i.openDirectives.length>0){const m=i.openDirectives[i.openDirectives.length-1];m.bodyBaseIndent<0&&(m.bodyBaseIndent=a),n.push(En(s,m.bodyBaseIndent))}else n.push(s);i.level=a}}for(;i.openDirectives.length>0;){const r=i.openDirectives.pop();r&&n.push(":".repeat(r.colonCount))}return n.join(`
|
|
14
|
+
`)}const Tn=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/,In=/^division:\s*(\S+)\s*$/m,Cn=/^id:\s*(\S+)\s*$/m,Sn=/^xmlid:\s*(\S+)\s*$/m,Ln=/^xml:id:\s*(\S+)\s*$/m,Nn=/^label:\s*(\S+)\s*$/m,_n=/^component:\s*(\S+)\s*$/m,An=/^title:\s*(.+?)\s*$/m;function On(e){if(e.length>=2){const t=e[0],n=e[e.length-1];if(t==='"'&&n==='"'||t==="'"&&n==="'")return e.slice(1,-1)}return e}function Mn(e){const t=e.match(Tn);if(!t)return{body:e};const n=t[1],i=e.slice(t[0].length),r=n.match(In)?.[1];let s,c;r&&S.isRootDivisionType(r)?(c=r,s=S.rootChildDivision(r)):r&&S.isTopLevelDivisionType(r)&&(s=r);const a={},h=n.match(Cn)?.[1]??n.match(Sn)?.[1]??n.match(Ln)?.[1],p=n.match(Nn)?.[1],m=n.match(_n)?.[1];h&&(a["xml:id"]=h),p&&(a.label=p),m&&(a.component=m);const g=n.match(An)?.[1],x=g?On(g):void 0;return{division:s,documentRoot:c,attributes:Object.keys(a).length>0?a:void 0,title:x,body:i}}const Ge=function(e){return function(n,i){if(typeof i?.value=="string"){const r=Mn(i.value),s=e?.documentRoot??r.documentRoot,c=e?.topLevelDivision??r.division??(s?S.rootChildDivision(s):"chapter"),a=e?.topLevelAttributes??r.attributes,h=e?.topLevelTitle??r.title,p=Dn(r.body),m=wn(p),g=gt(m);return ie(g.tree,g.source,{topLevelDivision:c,documentRoot:s,topLevelAttributes:a,topLevelTitle:h,restoreSource:g.restoreSource})}return Fe(n),ie(n,void 0,{topLevelDivision:e?.topLevelDivision??(e?.documentRoot?S.rootChildDivision(e.documentRoot):"chapter"),documentRoot:e?.documentRoot,topLevelAttributes:e?.topLevelAttributes,topLevelTitle:e?.topLevelTitle})}},Rn=/["&'<>`]/g,$n=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,qn=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,Pn=/[|\\{}()[\]^$+*?.]/g,Le=new WeakMap;function Fn(e,t){if(e=e.replace(t.subset?jn(t.subset):Rn,i),t.subset||t.escapeOnly)return e;return e.replace($n,n).replace(qn,i);function n(r,s,c){return t.format((r.charCodeAt(0)-55296)*1024+r.charCodeAt(1)-56320+65536,c.charCodeAt(s+2),t)}function i(r,s,c){return t.format(r.charCodeAt(0),c.charCodeAt(s+1),t)}}function jn(e){let t=Le.get(e);return t||(t=Xn(e),Le.set(e,t)),t}function Xn(e){const t=[];let n=-1;for(;++n<e.length;)t.push(e[n].replace(Pn,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function Bn(e){return"&#x"+e.toString(16).toUpperCase()+";"}function Un(e,t){return Fn(e,Object.assign({format:Bn},t))}const Yn=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function M(e,t,n){const i=zn(e);return n?i.replace(n,r):r(i);function r(s){return Un(s,{subset:t})}}function zn(e){return String(e||"").replace(Yn,"")}const Jn=/]]>/g,Wn=[">"];function Vn(e){return"<![CDATA["+M(e.value,Wn,Jn)+"]]>"}function Hn(e){return"<!--"+M(e.value,["-"])+"-->"}const Zn=[" ",`
|
|
15
|
+
`," ",'"',"&","'","/","<","=",">"];function V(e){return M(e,Zn)}function Ne(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let i=0,r=n.indexOf(t);for(;r!==-1;)i++,r=n.indexOf(t,r+t.length);return i}function se(e,t){const n=String(e);let i=t.options.quote||'"';if(t.options.quoteSmart){const r=i==='"'?"'":'"';Ne(n,i)>Ne(n,r)&&(i=r)}return i+M(n,["<","&",i])+i}function Gn(e,t){const n=V(e.name),i=e.public,r=e.system;let s="<!DOCTYPE";return n!==""&&(s+=" "+n),i?s+=" PUBLIC "+se(i,t):r&&(s+=" SYSTEM"),r&&(s+=" "+se(r,t)),s+">"}const Kn={}.hasOwnProperty;function Qn(e,t){const n=V(e.name),i=et(e,t),r=e.attributes||{},s=i?!1:t.options.closeEmptyElements,c=[];let a;for(a in r)if(Kn.call(r,a)){const h=r[a];h!=null&&c.push(V(a)+"="+se(h,t))}return"<"+n+(c.length===0?"":" "+c.join(" "))+(s?(t.options.tightClose?"":" ")+"/":"")+">"+i+(s?"":"</"+n+">")}const ei=/\?>/g,ti=[">"];function ni(e){const t=V(e.name)||"x",n=M(e.value,ti,ei);return"<?"+t+(n?" "+n:"")+"?>"}const ii=["&","<"];function Ke(e){return M(e.value,ii)}function ri(e,t){return t.options.allowDangerousXml?e.value:Ke(e)}const si={}.hasOwnProperty,_e={cdata:Vn,comment:Hn,doctype:Gn,element:Qn,instruction:ni,raw:ri,root:et,text:Ke};function Qe(e,t){const n=e&&e.type;if(!n)throw new Error("Expected node, not `"+e+"`");if(!si.call(_e,n))throw new Error("Cannot compile unknown node `"+n+"`");const i=_e[n];return i(e,t)}function et(e,t){const n=e&&e.children||[];let i=-1;const r=[];for(;++i<n.length;)r[i]=Qe(n[i],t);return r.join("")}function oi(e,t){const n={options:t||{}};if(typeof n.options.quote=="string"&&n.options.quote!=='"'&&n.options.quote!=="'")throw new Error("Invalid quote `"+n.options.quote+"`, expected `'` or `\"`");const i=Array.isArray(e)?{type:"root",children:e}:e;return Qe(i,n)}function li(e,t){const n=oe.unified().use(le).use(Ae).use(Ge,t),i=n.parse(e),r=n.runSync(i,{value:e});return oi(r.children,{closeEmptyElements:!0,tightClose:!0})}exports.DIRECTIVE_MAP=Bt;exports.PROOF_SOLUTION_NAMES=ae;exports.markdownToPretext=li;exports.mdastToPtxast=ie;exports.remarkMath=pt;exports.remarkPretext=Ge;
|