@pretextbook/remark-pretext 0.2.0 → 0.4.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 +73 -1
- package/dist/index.cjs +15 -6
- package/dist/index.js +1987 -618
- package/dist/lib/context.d.ts +2 -0
- package/dist/lib/directive-map.d.ts +1 -1
- 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 +4 -1
package/README.md
CHANGED
|
@@ -192,7 +192,78 @@ 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
|
+
### Tables
|
|
224
|
+
|
|
225
|
+
A GFM pipe table becomes a `<tabular>`. Wrap it in a `table` directive to get
|
|
226
|
+
a numbered, titled `<table>`:
|
|
227
|
+
|
|
228
|
+
```markdown
|
|
229
|
+
:::table[Values of $f$]{#tbl-values}
|
|
230
|
+
| $x$ | $f(x)$ |
|
|
231
|
+
| :-: | -----: |
|
|
232
|
+
| 0 | 1 |
|
|
233
|
+
| -1 | $|e|$ |
|
|
234
|
+
:::
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
- The header row becomes `<row header="yes">`. A header row whose cells are
|
|
238
|
+
all empty means the table has no header.
|
|
239
|
+
- Column alignment (`:--`, `:-:`, `--:`) becomes `halign` on the `<tabular>`
|
|
240
|
+
when every column agrees, and a `<col halign>` per column otherwise.
|
|
241
|
+
- Cells take the same inline elements as a paragraph. Math is read before the
|
|
242
|
+
table, so `$|x|$` stays in one cell; a literal `|` elsewhere is `\|`.
|
|
243
|
+
- For anything a pipe table can't say (borders, widths, `colspan`, paragraphs
|
|
244
|
+
in cells), write a raw `<tabular>` (see below). Converting back to Markdown
|
|
245
|
+
(`@pretextbook/ptxast-util-to-mdast`) does the same: a `<tabular>` becomes a
|
|
246
|
+
pipe table only when nothing would be lost, and stays raw PreTeXt otherwise.
|
|
247
|
+
|
|
248
|
+
Of GFM's other extensions, none are on: `~~text~~`, bare-URL autolinks and
|
|
249
|
+
footnotes stay plain text.
|
|
250
|
+
|
|
251
|
+
### Raw PreTeXt
|
|
252
|
+
|
|
253
|
+
PreTeXt can be written directly in the Markdown, for anything without Markdown
|
|
254
|
+
syntax of its own. It follows CommonMark's rules for HTML:
|
|
255
|
+
|
|
256
|
+
- **Tags within a paragraph, heading or title** become elements, and what's
|
|
257
|
+
between them is still Markdown: `<fn>about *this* and $x$</fn>`. The exceptions
|
|
258
|
+
are `<m>`, `<c>` and the other elements holding LaTeX or code, which are left
|
|
259
|
+
as written.
|
|
260
|
+
- **A block**, meaning a tag that starts a line and stands alone there, or a
|
|
261
|
+
block-level element like `<figure>`, stays PreTeXt through to its closing tag,
|
|
262
|
+
even past blank lines. Markdown and `$` aren't read inside it. Anything that
|
|
263
|
+
can only be in a paragraph, like a lone `<xref>` line, gets a `<p>`.
|
|
264
|
+
|
|
265
|
+
Comments (`<!-- ... -->`) are dropped. Tags that don't balance, don't parse, or
|
|
266
|
+
aren't PreTeXt (`<br>`, `<div>`) come out as a `<TODO>` holding the source.
|
|
196
267
|
|
|
197
268
|
## Supported Directives
|
|
198
269
|
|
|
@@ -204,3 +275,4 @@ when both are present.
|
|
|
204
275
|
| example-like | `example`, `question`, `problem`, `exercise`, `activity`, `exploration`, `investigation`, `project` |
|
|
205
276
|
| proof-like | `proof`, `case` |
|
|
206
277
|
| solution-like | `solution`, `hint`, `answer` |
|
|
278
|
+
| figure-like | `table` (around a pipe table; see [Tables](#tables)) |
|
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 M={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=M;function pe(e){return M[e.toLowerCase()]}const B=new Set(Object.entries(M).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"&&B.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"&&B.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 j(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=i.documentRoot==="slideshow"&&ge(g)?ye(g,i):D(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(D(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(D(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=D(l,i);return{tree:{type:"root",children:s?[s,...c]:c},messages:o}}function ge(e){return e.some(t=>t.type==="thematicBreak")}function ye(e,t){return D(e,t)}function D(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(ve(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 ve(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",C(e.children,n)),s=De(e,n),l={...n,depth:n.depth+1},{introduction:c,rest:u}=T(t,l),a=D(u,l,!0),p=A(a),d=c?[r,c,...p]:[r,...p];return h(i,d,s)}function ke(e){return e.type==="leafDirective"&&v.isTopLevelDivisionType(e.name)}function T(e,t){const n=e.findIndex(l=>l.type==="heading"||ke(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 be(e){const t=e.data;return t?.id?{"xml:id":t.id}:void 0}function De(e,t){const n=be(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 Ce={paragraph:(e,t)=>Q(e,t),blockquote:(e,t)=>Le(e,t),list:(e,t)=>xe(e,t),code:(e,t)=>Ie(e),containerDirective:(e,t)=>G(e,t),leafDirective:(e,t)=>qe(e,t)};function _(e,t){const n=Ce[e.type];return n?n(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),j("unknown-block-type",`unknown block type "${e.type}"`,$(e,t)))}function Q(e,t){return h("p",C(e.children,t))}function Le(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 xe(e,t){const n=e.children.map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return we(o,i)});return h(e.ordered?"ol":"ul",n)}function we(e,t){const n=w(e.children,t);return h("li",n)}function Ie(e,t){return b("program",e.value,e.lang?{language:e.lang}:void 0)}function Te(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 Se(e,t){return e.meta==="inline"?b("m",e.value):Te(e)}function Ee(e,t){return h("url",C(e.children,t),{href:e.url})}function qe(e,t){const n=ue(e);return n||(t.messages&&t.messages.push({type:"warning",reason:"Unnamed leaf directive",category:"unknown-directive"}),j("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"}),j("unknown-directive",`unknown directive "${e.name}"`,$(e,t));const o=Re(e),i=e.children,{title:r,body:s}=Ae(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 Ae(e,t){const n=e[0];return n?.type==="paragraph"&&n.data?.directiveLabel===!0?{title:h("title",C(n.children,t)),body:e.slice(1)}:{title:null,body:e}}function Re(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 Me(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 $e={text:(e,t)=>q(e.value),emphasis:(e,t)=>{const o=Me(e,t.source)==="underscore"?"term":"em";return h(o,C(e.children,t))},strong:(e,t)=>h("alert",C(e.children,t)),inlineCode:(e,t)=>b("c",e.value),math:(e,t)=>Se(e),link:(e,t)=>Ee(e,t)};function C(e,t){return e.flatMap(n=>Fe(n,t)).filter(n=>n!==null)}function Fe(e,t){const n=$e[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 Oe=[{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 Oe){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 _e(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 Ne(e){const t=new Map;let n="",o=0,i=0;for(;o<e.length;){const r=_e(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 Pe(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 Be(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=Pe(i.value);o.push(...r)}else o.push(i);t.children=o})}function je(e,t){K.visit(e,"paragraph",n=>{const o=n.children||[],i=[];for(const r of o)if(r.type==="text"){const s=Be(r.value,t);i.push(...s)}else i.push(r);n.children=i})}const ze=()=>e=>{te(e)};function Ue(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 We(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 Ve(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 He(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"),Oe=require("remark-directive"),st=require("micromark-extension-gfm-table"),ot=require("mdast-util-gfm-table"),S=require("@pretextbook/ptxast"),Me=/([\w:.-]+)=(?:"([^"]*)"|'([^']*)'|([^\s"'{}]+))/g,lt=new RegExp(String.raw`\s*\{#([\w:.-]+)((?:\s+${Me.source})*)\s*\}$`);function ct(e,t){const{start:n,end:i}=e.position??{},r=t?.slice(n?.offset,i?.offset)??"";return r[r.lastIndexOf("{")-1]==="\\"}function at(e,t){H.visit(e,"heading",n=>{const i=n.children[n.children.length-1];if(i?.type!=="text")return;const r=lt.exec(i.value);if(!r||ct(n,t))return;const s={};for(const[,c,...a]of r[2].matchAll(Me))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 ut=[{open:"$$",close:"$$",isDisplay:!0},{open:"\\[",close:"\\]",isDisplay:!0},{open:"$",close:"$",isDisplay:!1},{open:"\\(",close:"\\)",isDisplay:!1}],Re="",$e="",X=new RegExp(`${Re}\\d+${$e}`,"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 ht(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 qe(e,t){let n=null;for(const i of ut){let r=e.indexOf(i.open,t),s=-1;for(;r!==-1&&(s=i.open==="$"?ht(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 ft(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 f=h+r;if(f>=e.length||e[f]!=="`")return{start:i,end:f};a=h+1}n=i+r}return null}function Pe(e){const t=new Map;let n="",i=0,r=0;for(;i<e.length;){const s=ft(e,i),c=qe(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=`${Re}${r}${$e}`;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 dt(e){const t=[];let n=0;for(;n<e.length;){const i=qe(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 pt(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 Fe(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 je(e){Fe(e,dt)}const mt=["value","url","title","alt"];function Y(e,t){return e.replace(X,n=>t.get(n)?.source??n)}function Xe(e,t){Fe(e,n=>pt(n,t)),H.visit(e,n=>{for(const i of mt)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 gt=()=>e=>{je(e)},yt=["blockQuote","codeFenced","codeIndented","definition","headingAtx","htmlFlow","list","setextUnderline","thematicBreak"];function vt(){const e=this.data();e.micromarkExtensions=e.micromarkExtensions?.map(({text:t,...n})=>n)}function bt(e){const{markdown:t,tokens:n}=Pe(e),r=oe.unified().data("micromarkExtensions",[{disable:{null:["codeIndented"]}},st.gfmTable()]).data("fromMarkdownExtensions",[ot.gfmTableFromMarkdown()]).use(le).use(Oe).use(vt).parse(t);return Xe(r,n),{tree:r,source:t,restoreSource:s=>Y(s,n)}}function wt(e){const{markdown:t,tokens:n}=Pe(e);for(const s of n.values())s.meta="inline";const r=oe.unified().data("micromarkExtensions",[{disable:{null:yt}}]).use(le).parse(t);return Xe(r,n),{tree:r.children.flatMap(s=>s.children),source:t,restoreSource:s=>Y(s,n)}}function xt(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 kt(e){const t=e.name?.trim();return t?xt(t,e.attributes??{}):null}var te,Ee;function Et(){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,d)=>{if(o&&typeof o=="object"||typeof o=="function")for(let p of n(o))!i.call(l,p)&&p!==u&&e(l,p,{get:()=>o[p],enumerable:!(d=t(o,p))||d.enumerable});return l},c=l=>s(e({},"__esModule",{value:!0}),l),a={};r(a,{XmlCdata:()=>de,XmlComment:()=>pe,XmlDeclaration:()=>me,XmlDocument:()=>ge,XmlDocumentType:()=>ye,XmlElement:()=>K,XmlError:()=>ve,XmlNode:()=>x,XmlProcessingInstruction:()=>Q,XmlText:()=>Z,parseXml:()=>rt}),te=c(a);var h="",f=/[\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,d=0;d<this.k;++d)o[d]=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(f,"_").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:d}=this,p=this.f(),y=p;if(u)for(;y<o;){let E=d[y],C=E>="\uD800"&&E<="\uDBFF";if(C&&(E+=d[y+1]),!l(E))break;y+=C?2:1}else for(;y<o&&l(d[y]);)++y;return this.v(y-p)}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=/["&<]/,k=/['&<]/,D=/\r\n|[\n\r\t]/g,T=/<|&|]]>/,_=Object.freeze(Object.assign(Object.create(null),{amp:"&",apos:"'",gt:">",lt:"<",quot:'"'}));function b(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||w(l,o)}function w(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==="#"||b(l)}function nt(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 Be{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===Be.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 x=L,Z=class extends x{constructor(l=""){super(),this.text=l}get type(){return x.TYPE_TEXT}toJSON(){return Object.assign(x.prototype.toJSON.call(this),{text:this.text})}},de=class extends Z{get type(){return x.TYPE_CDATA}},pe=class extends x{constructor(l=""){super(),this.content=l}get type(){return x.TYPE_COMMENT}toJSON(){return Object.assign(x.prototype.toJSON.call(this),{content:this.content})}},me=class extends x{constructor(l,o,u){super(),this.version=l,this.encoding=o??null,this.standalone=u??null}get type(){return x.TYPE_XML_DECLARATION}toJSON(){let l=x.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 Ue extends x{constructor(o,u=Object.create(null),d=[]){super(),this.name=o,this.attributes=u,this.children=d}get isEmpty(){return this.children.length===0}get preserveWhitespace(){let o=this;for(;o instanceof Ue;){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 x.TYPE_ELEMENT}toJSON(){return Object.assign(x.prototype.toJSON.call(this),{name:this.name,attributes:this.attributes,children:this.children.map(o=>o.toJSON())})}},ge=class extends x{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 x.TYPE_DOCUMENT}toJSON(){return Object.assign(x.prototype.toJSON.call(this),{children:this.children.map(l=>l.toJSON())})}},ye=class extends x{constructor(l,o,u,d){super(),this.name=l,this.publicId=o??null,this.systemId=u??null,this.internalSubset=d??null}get type(){return x.TYPE_DOCUMENT_TYPE}toJSON(){let l=x.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 d=1,p="",y=1;for(let ee=0;ee<o;++ee){let we=u[ee];we===`
|
|
3
|
+
`?(d=1,p="",y+=1):(d+=1,p+=we)}let E=u.indexOf(`
|
|
4
|
+
`,o);p+=E===-1?u.slice(o):u.slice(o,E);let C=0;p.length>50&&(d<40?p=p.slice(0,50):(C=d-20,p=p.slice(C,d+30))),super(`${l} (line ${y}, column ${d})
|
|
5
|
+
${p}
|
|
6
|
+
`+" ".repeat(d-C+1)+`^
|
|
7
|
+
`),this.column=d,this.excerpt=p,this.line=y,this.name="XmlError",this.pos=o}},Q=class extends x{constructor(l,o=""){super(),this.name=l,this.content=o}get type(){return x.TYPE_PROCESSING_INSTRUCTION}toJSON(){return Object.assign(x.prototype.toJSON.call(this),{name:this.name,content:this.content})}},be="",it=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:d}=this.j,{length:p}=d;if(u&&(l=F(l)),p>0){let y=d[p-1];if(y?.type===x.TYPE_TEXT){let E=y;return E.text+=l,this.g.includeOffsets&&(E.end=this.c.f()),!0}}return this.i(new Z(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 d=0;d<o.length;++d){let p=o[d];u[p]=l[p]}l=u}return l}I(){let{c:l}=this,o=l.m();if(o!=='"'&&o!=="'")return!1;l.p();let u,d=!1,p=be,y=o==='"'?g:k;e:for(;!l.B;)switch(u=l.x(y),u&&(this.o(u),p+=u.replace(D," ")),l.m()){case o:d=!0;break e;case"&":p+=this.C();continue;case"<":throw this.a("Unescaped `<` is not allowed in an attribute value");default:break e}if(!d)throw this.a("Unclosed attribute");return l.p(),p}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 de(F(u)),o):this.y(u,o)}K(){let{c:l}=this,o=l.d,u=l.x(T);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 pe(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 d,p;if(this.e()){if(l.b("PUBLIC")){if(d=this.e()&&this.N(),d===!1)throw this.a("Expected a public identifier");this.e()}if(d!==void 0||l.b("SYSTEM")){if(this.e(),p=this.r(),p===!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,d,p,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 d=this.H(),p=!!l.b("/>"),y=new K(u,d);if(y.parent=this.j,!p){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 w(this.c.m())?this.c.w(b):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 d=l.s("?>");if(this.o(d),!l.b("?>"))throw this.a("Unterminated processing instruction");return this.i(new Q(u,F(d)),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 d=o[1]==="x"?parseInt(o.slice(2),16):parseInt(o.slice(1),10);if(isNaN(d)||!/^#(?:x[0-9A-Fa-f]+|[0-9]+)$/.test(o))throw this.a("Invalid character reference");if(!fe(d))throw this.a("Character reference resolves to an invalid character");u=String.fromCodePoint(d)}else if(u=_[o],u===void 0){let{ignoreUndefinedEntities:d,resolveUndefinedEntity:p}=this.g,y=`&${o};`;if(p){let E=p(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(d)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(nt)}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 d,p;if(this.e()){if(d=!!l.b("encoding")&&this.t()&&this.r(),d){if(!/^[A-Za-z][\w.-]*$/.test(d))throw this.a("Invalid character in encoding name");this.e()}if(p=!!l.b("standalone")&&this.t()&&this.r(),p){if(p!=="yes"&&p!=="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,d||void 0,p||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 d=l.codePointAt(u);if(!fe(d))throw this.c.n(-([...l].length-u)),this.a("Invalid character");d>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 rt(l,o){return new it(l,o).document}return te}var Tt=Et();function Dt(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=Te(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=Te(t,a),f=h===-1?t.length+1:h+1;if(a===f)break;n.push(f)}const c=(s.line>1?n[s.line-2]:0)+s.column-1;if(c<n[s.line-1])return c}}}function Te(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 It(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?De(e.position):"start"in e||"end"in e?De(e):"line"in e||"column"in e?ne(e):""}function ne(e){return Ie(e&&e.line)+":"+Ie(e&&e.column)}function De(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=It(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 Ct(e){const t=Dt(e);let n;try{n=Tt.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=Nt(n,i);return ze(n,r,i),r}function St(e){return{type:"cdata",value:e.text}}function Lt(e){return{type:"comment",value:e.content}}function Nt(e,t){return{type:"root",children:Ye(e.children,t)}}function _t(e){return{type:"doctype",name:e.name,public:e.publicId||void 0,system:e.systemId||void 0}}function At(e,t){const n=Ye(e.children,t);return{type:"element",name:e.name,attributes:{...e.attributes},children:n}}function Ot(e){return{type:"instruction",name:e.name,value:e.content}}function Mt(e){return{type:"text",value:e.text}}function Rt(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 Ye(e,t){const n=[];let i=-1;for(;++i<e.length;){const r=e[i];let s;r.type==="cdata"?s=St(r):r.type==="comment"?s=Lt(r):r.type==="doctype"?s=_t(r):r.type==="element"?s=At(r,t):r.type==="pi"?s=Ot(r):r.type==="text"?s=Mt(r):r.type==="xmldecl"&&(s=Rt(r)),s&&(ze(r,s,t),n.push(s))}return n}function ze(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 $t=/<!--[\s\S]*?-->/g,ce=new Set(["me","men","mdn"]),qt=new Set([...ce,"c","cd","cline","m","md","mrow","pre"]),Pt=new Set(["blockquote","containerDirective","listItem","root"]),Je=new Set([...ce,...S.getPtxSchemaChildElementNames("p")]);for(const e of S.getPtxSchemaChildElementNames("section"))Je.delete(e);function Ft(e){return S.isPtxSchemaElementName(e)||ce.has(e)}function q(e){let t;try{t=Ct(`<raw>${e.replace($t,"")}</raw>`)}catch{return null}const i=t.children.find(s=>s.type==="element").children;return i.every(s=>s.type==="element"?Ft(s.name):s.type!=="instruction")?i:null}function jt(e){const t=q(e);if(t)return{children:t};const[n]=q(e.replace(/>$/,"/>"))??[];return n?.type==="element"?{children:[],opens:n}:null}function Xt(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 Bt(e){const t=[];let n=null;for(const i of e){if(i.type==="element"&&!Je.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 Ut(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 f=q(i(n.slice(s,h)));if(f)return{nodes:f,end:a}}return null}function Yt(e,t,n){H.visit(e,i=>{if(!Pt.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=Ut(r,s,t,n);if(!c)continue;const a=Bt(c.nodes).map(h=>({type:"ptxRaw",element:h}));r.splice(s,c.end-s+1,...a),s+=a.length-1}})}const G={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},table:{type:"table",category:"figure-like",requiresStatement:!1}},zt=G;function Jt(e){return G[e.toLowerCase()]}const ae=new Set(Object.entries(G).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 Wt(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 Vt(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 f=[];for(let b=0;b<i.length;b++)j(i[b])&&f.push(b);const m=f[f.length-1],g=i.slice(0,h),k=i.slice(h).filter(j),D=[],T=[],_=[];for(let b=h;b<i.length;b++){const w=i[b];if(!j(w)){if(b<m){D.push(w);continue}if(Wt(w)){_.push(w);continue}T.push(w)}}if(D.length>0&&(r.messages??(r.messages=[])).push({type:"warning",reason:`Dropped ${D.length} non-task node(s) between task directives in ${e.type}.`,category:"dropped-content-between-tasks",position:D[0].position?.start}),g.length>0){const b=z(g.map(w=>s(w,r)).filter(w=>w!==null));b.length>0&&a.push(R("introduction",b))}for(const b of k){const w=c(b,r);w&&a.push(w)}if(T.length>0){const b=z(T.map(w=>s(w,r)).filter(w=>w!==null));b.length>0&&a.push(R("conclusion",b))}for(const b of _){const w=c(b,r);w&&a.push(w)}}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 f=s(h,i);f&&a.push(f)}else c.push(h);if(c.length>0){const h=z(c.map(f=>r(f,i)).filter(f=>f!==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 We(e){return{type:"text",value:e}}function v(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function A(e,t,n){return v(e,[We(t)],n)}function Ve(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 v("TODO",[Ve(`todo: ${t}`),A("pre",n)],{type:e})}function Ht(e,t,n){return v("TODO",[Ve(`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(v("p",[n])):t.push(n);return t}function ie(e,t,n){return Gt(e,t,n).tree}function Gt(e,t,n){const i=[],r=n?.restoreSource??(g=>g);Yt(e,t,r),at(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),k=s.topLevelTitle?Se(s.topLevelTitle,s):null,{introduction:D,rest:T}=B(c,s),_=s.documentRoot==="slideshow"&&Zt(T)?Kt(T,s):O(T,s),b=[...k?[k]:[],...D?[D]:[],..._];return{tree:{type:"root",children:[v(s.documentRoot,b,g)]},messages:i}}if(S.isTitlelessDivisionType(s.topLevelDivision)){const g=U(s),k=J(O(c,{...s,depth:1},!0));return{tree:{type:"root",children:[v(s.topLevelDivision,k,g)]},messages:i}}if(s.topLevelTitle){const g=U(s),k=Se(s.topLevelTitle,s),D={...s,depth:s.depth+1,headingDepthOffset:(s.headingDepthOffset??0)+1},{introduction:T,rest:_}=B(c,D),b=J(O(_,D,!0)),w=T?[k,T,...b]:[k,...b];return{tree:{type:"root",children:[v(s.topLevelDivision,w,g)]},messages:i}}const{introduction:a,rest:h}=B(c,s),f=O(h,s);return{tree:{type:"root",children:a?[a,...f]:f},messages:i}}function Se(e,t){const{tree:n,source:i,restoreSource:r}=wt(e);return v("title",N(n,{...t,source:i,restoreSource:r}))}function Zt(e){return e.some(t=>t.type==="thematicBreak")}function Kt(e,t){return O(e,t)}function O(e,t,n=!1){let i=7;for(const f of e)f.type==="heading"&&(i=Math.min(i,f.depth));if(i===7)return $(e,t,n);const r=[];let s=null,c=[],a=[];const h=()=>{s&&(r.push(Qt(s,a,t)),s=null,a=[])};for(const f of e)f.type==="heading"&&f.depth===i?(!s&&c.length>0&&(r.push(...$(c,t,n)),c=[]),h(),s=f,a=[]):s?a.push(f):c.push(f);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],f=r+1<e.length?W(e[r+1],t):null,m=f?.name==="p"?f.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(v("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 Qt(e,t,n){const i=e.depth+(n.headingDepthOffset??0),r=n.documentRoot?S.divisionTypeAtRootDepth(n.documentRoot,i):S.divisionTypeAtRelativeDepth(n.topLevelDivision,i),s=v("title",N(e.children,n)),c=nn(e,n),a={...n,depth:n.depth+1},{introduction:h,rest:f}=B(t,a),m=O(f,a,!0),g=J(m),k=h?[s,h,...g]:[s,...g];return v(r,k,c)}function en(e){return e.type==="leafDirective"&&S.isTopLevelDivisionType(e.name)}function B(e,t){const n=e.findIndex(a=>a.type==="heading"||en(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?v("introduction",s):null,rest:r}}function tn(e){const t=e.data;return t?.id?{...t.attributes,"xml:id":t.id}:void 0}function nn(e,t){const n=tn(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 rn={paragraph:(e,t)=>sn(e,t),blockquote:(e,t)=>on(e,t),list:(e,t)=>ln(e,t),code:(e,t)=>an(e),table:(e,t)=>un(e,t),containerDirective:(e,t)=>He(e,t),leafDirective:(e,t)=>mn(e,t),ptxRaw:e=>e.element};function W(e,t){const n=rn[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 sn(e,t){return v("p",N(e.children,t))}function on(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 v("blockquote",n)}function ln(e,t){const n=e.children.map(i=>{const r={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return cn(i,r)});return v(e.ordered?"ol":"ul",n)}function cn(e,t){const n=$(e.children,t);return v("li",n)}function an(e,t){return A("program",e.value,e.lang?{language:e.lang}:void 0)}function un(e,t){const[n,...i]=e.children,r=n?.children.length??0,s=Array.from({length:r},(m,g)=>e.align?.[g]??null),c={...t,ancestors:[...t.ancestors,e],depth:t.depth+1},a=[];n&&!hn(n)&&a.push(Le(n,r,c,{header:"yes"}));for(const m of i)a.push(Le(m,r,c));const h=s.every(m=>m===s[0])?s[0]:void 0;if(h)return v("tabular",a,{halign:h});if(h===null)return v("tabular",a);const f=s.map(m=>v("col",[],m?{halign:m}:void 0));return v("tabular",[...f,...a])}function hn(e){return e.children.every(t=>t.children.every(n=>n.type==="text"&&n.value.trim()===""))}function Le(e,t,n,i){const r=e.children.map(s=>v("cell",N(s.children,n)));for(;r.length<t;)r.push(v("cell",[]));return v("row",r,i)}function fn(e,t){const n=e.value.split(/\\\\|[\r\n]+/).map(i=>i.trim()).filter(i=>i.length>0);return n.length>1?v("md",n.map(i=>A("mrow",i))):A("md",n[0]??"")}function dn(e,t){return e.meta==="inline"?A("m",e.value):fn(e)}function pn(e,t){const n=N(e.children,t);return/^#./.test(e.url)?v("xref",n,{ref:e.url.slice(1)}):v("url",n,{href:e.url})}function mn(e,t){const n=kt(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 He(e,t){const n=Jt(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=yn(e),r=e.children,{title:s,body:c}=gn(r,t),a={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Vt(n,i,s,c,a,(h,f)=>W(h,f),(h,f)=>He(h,f))}function gn(e,t){const n=e[0];return n?.type==="paragraph"&&n.data?.directiveLabel===!0?{title:v("title",N(n.children,t)),body:e.slice(1)}:{title:null,body:e}}function yn(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 vn(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 bn={text:(e,t)=>We(e.value),emphasis:(e,t)=>{const i=vn(e,t.source)==="underscore"?"term":"em";return v(i,N(e.children,t))},strong:(e,t)=>v("alert",N(e.children,t)),inlineCode:(e,t)=>A("c",e.value),math:(e,t)=>dn(e),link:(e,t)=>pn(e,t)};function N(e,t){const n=[];for(let i=0;i<e.length;i+=1){const r=wn(e,i,t);if(r){n.push(...r.children),i=r.end;continue}const s=xn(e[i],t);s!==null&&n.push(s)}return n}function wn(e,t,n){const i=e[t];if(i.type!=="html")return null;const r=jt(i.value);if(!r)return null;const{opens:s}=r;if(!s)return{children:r.children,end:t};const c=Xt(e,t,s.name);if(c===-1)return null;if(qt.has(s.name)){const f={start:i.position?.start,end:e[c].position?.end},m=q(P({position:f},n));return m&&{children:m,end:c}}const a=N(e.slice(t+1,c),n);return{children:[{...s,children:a}],end:c}}function xn(e,t){const n=bn[e.type];if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),Ht("unknown-inline-type",`unknown inline type "${e.type}"`,P(e,t));const i={...t,ancestors:[...t.ancestors,e]};return n(e,i)}function kn(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 En(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 Ge(e){if(e.children.length===0)e.finalColons=e.colons;else{const t=Math.max(...e.children.map(Ge));e.finalColons=Math.max(e.colons,t+1)}return e.finalColons}function Tn(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,f=a.slice(h);i[c.openLineIndex]=":".repeat(c.finalColons)+f}c.closeLineIndex!==null&&c.closeLineIndex>=0&&(i[c.closeLineIndex]=":".repeat(c.finalColons))}return i}function Dn(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 k=m[1];i?r&&k[0]===r[0]&&k.length>=r.length&&(i=!1,r=null):(i=!0,r=k);continue}if(i)continue;const g=kn(h);g&&n.push({...g,lineIndex:a})}if(n.length===0)return e;const s=En(n);for(const a of s)Ge(a);return Tn(t,s).join(`
|
|
12
|
+
`)}function In(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)||!G[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 Cn(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 Sn(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 Ln(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 f=In(c);if(f&&Cn(t,r)){for(;i.openDirectives.length>0&&!(i.openDirectives[i.openDirectives.length-1].indentLevel<a);){const T=i.openDirectives.pop();T&&n.push(":".repeat(T.colonCount))}const m=f.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/),g=m?m[1].toLowerCase()+(m[2]||""):f,k=i.openDirectives.length*1+3;n.push(":".repeat(k)+g),i.openDirectives.push({label:g,indentLevel:a,colonCount:k,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(Sn(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 Nn=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/,_n=/^division:\s*(\S+)\s*$/m,An=/^id:\s*(\S+)\s*$/m,On=/^xmlid:\s*(\S+)\s*$/m,Mn=/^xml:id:\s*(\S+)\s*$/m,Rn=/^label:\s*(\S+)\s*$/m,$n=/^component:\s*(\S+)\s*$/m,qn=/^title:\s*(.+?)\s*$/m;function Pn(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 Fn(e){const t=e.match(Nn);if(!t)return{body:e};const n=t[1],i=e.slice(t[0].length),r=n.match(_n)?.[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(An)?.[1]??n.match(On)?.[1]??n.match(Mn)?.[1],f=n.match(Rn)?.[1],m=n.match($n)?.[1];h&&(a["xml:id"]=h),f&&(a.label=f),m&&(a.component=m);const g=n.match(qn)?.[1],k=g?Pn(g):void 0;return{division:s,documentRoot:c,attributes:Object.keys(a).length>0?a:void 0,title:k,body:i}}const Ke=function(e){return function(n,i){if(typeof i?.value=="string"){const r=Fn(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,f=Ln(r.body),m=Dn(f),g=bt(m);return ie(g.tree,g.source,{topLevelDivision:c,documentRoot:s,topLevelAttributes:a,topLevelTitle:h,restoreSource:g.restoreSource})}return je(n),ie(n,void 0,{topLevelDivision:e?.topLevelDivision??(e?.documentRoot?S.rootChildDivision(e.documentRoot):"chapter"),documentRoot:e?.documentRoot,topLevelAttributes:e?.topLevelAttributes,topLevelTitle:e?.topLevelTitle})}},jn=/["&'<>`]/g,Xn=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,Bn=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,Un=/[|\\{}()[\]^$+*?.]/g,Ne=new WeakMap;function Yn(e,t){if(e=e.replace(t.subset?zn(t.subset):jn,i),t.subset||t.escapeOnly)return e;return e.replace(Xn,n).replace(Bn,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 zn(e){let t=Ne.get(e);return t||(t=Jn(e),Ne.set(e,t)),t}function Jn(e){const t=[];let n=-1;for(;++n<e.length;)t.push(e[n].replace(Un,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function Wn(e){return"&#x"+e.toString(16).toUpperCase()+";"}function Vn(e,t){return Yn(e,Object.assign({format:Wn},t))}const Hn=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function M(e,t,n){const i=Gn(e);return n?i.replace(n,r):r(i);function r(s){return Vn(s,{subset:t})}}function Gn(e){return String(e||"").replace(Hn,"")}const Zn=/]]>/g,Kn=[">"];function Qn(e){return"<![CDATA["+M(e.value,Kn,Zn)+"]]>"}function ei(e){return"<!--"+M(e.value,["-"])+"-->"}const ti=[" ",`
|
|
15
|
+
`," ",'"',"&","'","/","<","=",">"];function V(e){return M(e,ti)}function _e(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==='"'?"'":'"';_e(n,i)>_e(n,r)&&(i=r)}return i+M(n,["<","&",i])+i}function ni(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 ii={}.hasOwnProperty;function ri(e,t){const n=V(e.name),i=tt(e,t),r=e.attributes||{},s=i?!1:t.options.closeEmptyElements,c=[];let a;for(a in r)if(ii.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 si=/\?>/g,oi=[">"];function li(e){const t=V(e.name)||"x",n=M(e.value,oi,si);return"<?"+t+(n?" "+n:"")+"?>"}const ci=["&","<"];function Qe(e){return M(e.value,ci)}function ai(e,t){return t.options.allowDangerousXml?e.value:Qe(e)}const ui={}.hasOwnProperty,Ae={cdata:Qn,comment:ei,doctype:ni,element:ri,instruction:li,raw:ai,root:tt,text:Qe};function et(e,t){const n=e&&e.type;if(!n)throw new Error("Expected node, not `"+e+"`");if(!ui.call(Ae,n))throw new Error("Cannot compile unknown node `"+n+"`");const i=Ae[n];return i(e,t)}function tt(e,t){const n=e&&e.children||[];let i=-1;const r=[];for(;++i<n.length;)r[i]=et(n[i],t);return r.join("")}function hi(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 et(i,n)}function fi(e,t){const n=oe.unified().use(le).use(Oe).use(Ke,t),i=n.parse(e),r=n.runSync(i,{value:e});return hi(r.children,{closeEmptyElements:!0,tightClose:!0})}exports.DIRECTIVE_MAP=zt;exports.PROOF_SOLUTION_NAMES=ae;exports.markdownToPretext=fi;exports.mdastToPtxast=ie;exports.remarkMath=gt;exports.remarkPretext=Ke;
|