@pretextbook/remark-pretext 0.3.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 CHANGED
@@ -220,6 +220,34 @@ A link to an id is a cross-reference:
220
220
  Inline directives (`:name[...]`) aren't read, so a colon in prose like `f:X`
221
221
  stays text.
222
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
+
223
251
  ### Raw PreTeXt
224
252
 
225
253
  PreTeXt can be written directly in the Markdown, for anything without Markdown
@@ -247,3 +275,4 @@ aren't PreTeXt (`<br>`, `<div>`) come out as a `<TODO>` holding the source.
247
275
  | example-like | `example`, `question`, `problem`, `exercise`, `activity`, `exploration`, `investigation`, `project` |
248
276
  | proof-like | `proof`, `case` |
249
277
  | solution-like | `solution`, `hint`, `answer` |
278
+ | figure-like | `table` (around a pipe table; see [Tables](#tables)) |
package/dist/index.cjs CHANGED
@@ -1,15 +1,15 @@
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]===`
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
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;
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;