@pretextbook/remark-pretext 0.0.9 → 0.0.10

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
@@ -86,6 +86,48 @@ There are two ways to change it:
86
86
  // → '<section><title>Title</title><subsection>...'
87
87
  ```
88
88
 
89
+ ### Title from frontmatter
90
+
91
+ By default (no `title:` field), `#` supplies the top-level division's own
92
+ title, as shown above. Adding a `title:` field to the frontmatter moves the
93
+ title there instead — `#` then starts the top-level division's **first
94
+ subdivision**, and every heading resolves one level deeper than usual:
95
+
96
+ ```markdown
97
+ ---
98
+ division: section
99
+ title: Limits
100
+ ---
101
+
102
+ Some introductory text.
103
+
104
+ # Part A
105
+
106
+ A `<subsection>` titled "Part A".
107
+ ```
108
+
109
+ ```xml
110
+ <section>
111
+ <title>Limits</title>
112
+ <introduction>
113
+ <p>Some introductory text.</p>
114
+ </introduction>
115
+ <subsection>
116
+ <title>Part A</title>
117
+ ...
118
+ </subsection>
119
+ </section>
120
+ ```
121
+
122
+ When `division:` names a document root (`book`/`article`/`slideshow`),
123
+ `title:` sets the root element's own `<title>` instead, and `#` keeps its
124
+ existing meaning (the root's outermost child division — unaffected by this
125
+ field, since it was already one level below the root).
126
+
127
+ Pass `topLevelTitle` to `remarkPretext` or `markdownToPretext` to set this
128
+ explicitly instead; like `topLevelDivision`, it overrides frontmatter when
129
+ both are present.
130
+
89
131
  ### Section-like divisions
90
132
 
91
133
  `division:` also accepts a set of section-like types that don't belong to
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("unified"),H=require("remark-parse"),V=require("remark-directive"),g=require("@pretextbook/ptxast"),X=require("unist-util-visit");function le(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 ce(e){const t=e.name?.trim();return t?le(t,e.attributes??{}):null}const T={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}},ue=T;function ae(e){return T[e.toLowerCase()]}const O=new Set(Object.entries(T).filter(([e,t])=>t.category==="proof-like"||t.category==="solution-like").map(([e])=>e));function D(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function w(e){return e.type==="containerDirective"&&e.name==="task"}function pe(e){return e.type==="containerDirective"&&O.has(e.name)}function L(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(D("p",[n])):t.push(n);return t}function fe(e,t,n,o,i,r,s){const l=[];if(n&&l.push(n),e.hasNestedTasks){const c=o.findIndex(w);if(c!==-1){const u=[];for(let p=0;p<o.length;p++)w(o[p])&&u.push(p);const a=u[u.length-1],d=o.slice(0,c),m=o.slice(c).filter(w),b=[],v=[],P=[];for(let p=c;p<o.length;p++){const f=o[p];if(!w(f)){if(p<a){b.push(f);continue}if(pe(f)){P.push(f);continue}v.push(f)}}if(b.length>0&&(i.messages??(i.messages=[])).push({type:"warning",reason:`Dropped ${b.length} non-task node(s) between task directives in ${e.type}.`,category:"dropped-content-between-tasks",position:b[0].position?.start}),d.length>0){const p=L(d.map(f=>r(f,i)).filter(f=>f!==null));p.length>0&&l.push(D("introduction",p))}for(const p of m){const f=s(p,i);f&&l.push(f)}if(v.length>0){const p=L(v.map(f=>r(f,i)).filter(f=>f!==null));p.length>0&&l.push(D("conclusion",p))}for(const p of P){const f=s(p,i);f&&l.push(f)}}else j(l,e,o,i,r,s)}else j(l,e,o,i,r,s);return D(e.type,l,t)}function j(e,t,n,o,i,r){if(t.requiresStatement){const s=[],l=[];for(const c of n)if(c.type==="containerDirective"&&O.has(c.name)){const u=r(c,o);u&&l.push(u)}else s.push(c);if(s.length>0){const c=L(s.map(u=>i(u,o)).filter(u=>u!==null));c.length>0&&e.push(D("statement",c))}e.push(...l)}else{const s=L(n.map(l=>i(l,o)).filter(l=>l!==null));e.push(...s)}}function Z(e){return{type:"text",value:e}}function h(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function y(e,t,n){return h(e,[Z(t)],n)}function K(e){return{type:"comment",value:e.replace(/--/g,"- -")}}function E(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 N(e,t,n){return h("TODO",[K(`todo: ${t}`),y("pre",n)],{type:e})}function he(e,t,n){return h("TODO",[K(`todo: ${t}`),y("c",n)],{type:e})}function _(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 A(e,t,n){return de(e,t,n).tree}function de(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},r=e.children;if(i.documentRoot){const l=M(i),c=I(r,i);return{tree:{type:"root",children:[h(i.documentRoot,c,l)]},messages:o}}if(g.isTitlelessDivisionType(i.topLevelDivision)){const l=M(i),c=_(I(r,{...i,depth:1},!0));return{tree:{type:"root",children:[h(i.topLevelDivision,c,l)]},messages:o}}return{tree:{type:"root",children:I(r,i)},messages:o}}function I(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 x(e,t,n);const i=[];let r=null,s=[],l=[];const c=()=>{r&&(i.push(me(r,l,t)),r=null,l=[])};for(const u of e)u.type==="heading"&&u.depth===o?(!r&&s.length>0&&(i.push(...x(s,t,n)),s=[]),c(),r=u,l=[]):r?l.push(u):s.push(u);return!r&&s.length>0&&i.push(...x(s,t,n)),c(),i}function x(e,t,n=!1){const o=[];for(let i=0;i<e.length;i+=1){const r=e[i],s=R(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?R(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 d=[l];a&&(d.push(...a),i+=1),o.push(h("p",d))}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?_(o):o}function me(e,t,n){const o=n.documentRoot?g.divisionTypeAtRootDepth(n.documentRoot,e.depth):g.divisionTypeAtRelativeDepth(n.topLevelDivision,e.depth),i=h("title",C(e.children,n)),r=ke(e,n),s={...n,depth:n.depth+1},{introduction:l,rest:c}=ye(t,s),u=I(c,s,!0),a=_(u),d=l?[i,l,...a]:[i,...a];return h(o,d,r)}function ge(e){return e.type==="leafDirective"&&g.isTopLevelDivisionType(e.name)}function ye(e,t){const n=e.findIndex(l=>l.type==="heading"||ge(l));if(n<=0)return{introduction:null,rest:e};const o=e.slice(0,n),i=e.slice(n),r=x(o,t,!0);return{introduction:r.length>0?h("introduction",r):null,rest:i}}function ve(e){const t=e.data;return t?.id?{"xml:id":t.id}:void 0}function ke(e,t){const n=ve(e),o=M(t);if(!(!n&&!o))return{...o,...n}}function M(e){if(e.depth!==0)return;const t=e.topLevelAttributesApplied;if(!(!e.topLevelAttributes||!t||t.done))return t.done=!0,e.topLevelAttributes}const be={paragraph:(e,t)=>Y(e,t),blockquote:(e,t)=>De(e,t),list:(e,t)=>xe(e,t),code:(e,t)=>we(e),containerDirective:(e,t)=>G(e,t),leafDirective:(e,t)=>Se(e,t)};function R(e,t){const n=be[e.type];return n?n(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),N("unknown-block-type",`unknown block type "${e.type}"`,E(e,t)))}function Y(e,t){return h("p",C(e.children,t))}function De(e,t){const n=e.children.filter(o=>o.type==="paragraph").map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Y(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 Ce(o,i)});return h(e.ordered?"ol":"ul",n)}function Ce(e,t){const n=x(e.children,t);return h("li",n)}function we(e,t){return y("program",e.value,e.lang?{language:e.lang}:void 0)}function Ie(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=>y("mrow",o))):y("md",n[0]??"")}function Le(e,t){return e.meta==="inline"?y("m",e.value):Ie(e)}function Se(e,t){const n=ce(e);return n||(t.messages&&t.messages.push({type:"warning",reason:"Unnamed leaf directive",category:"unknown-directive"}),N("unknown-directive","unnamed leaf directive",E(e,t)))}function G(e,t){const n=ae(e.name);if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),N("unknown-directive",`unknown directive "${e.name}"`,E(e,t));const o=Ee(e),i=e.children,{title:r,body:s}=Te(i,t),l={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return fe(n,o,r,s,l,(c,u)=>R(c,u),(c,u)=>G(c,u))}function Te(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 Ee(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 qe(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 Ae={text:(e,t)=>Z(e.value),emphasis:(e,t)=>{const o=qe(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)=>y("c",e.value),math:(e,t)=>Le(e)};function C(e,t){return e.flatMap(n=>Me(n,t)).filter(n=>n!==null)}function Me(e,t){const n=Ae[e.type];if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),he("unknown-inline-type",`unknown inline type "${e.type}"`,E(e,t));const o={...t,ancestors:[...t.ancestors,e]};return n(e,o)}const Re=[{open:"$$",close:"$$",isDisplay:!0},{open:"\\[",close:"\\]",isDisplay:!0},{open:"$",close:"$",isDisplay:!1},{open:"\\(",close:"\\)",isDisplay:!1}],J="PTX_MATH_TOKEN_",q=new RegExp(`${J}(\\d+)`,"g");function Q(e,t){let n=null;for(const o of Re){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 Fe(e){const t=new Map;let n="",o=0,i=0;for(;o<e.length;){const r=$e(e,o),s=Q(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 Oe(e){const t=[];let n=0;for(;n<e.length;){const o=Q(e,n);if(!o){n<e.length&&t.push({type:"text",value:e.substring(n)});break}o.index>n&&t.push({type:"text",value:e.substring(n,o.index)}),t.push({type:"math",value:o.content,meta:o.pattern.isDisplay?"display":"inline"}),n=o.index+o.pattern.open.length+o.content.length+o.pattern.close.length}return t.length===0?[{type:"text",value:e}]:t}function Ne(e,t){const n=[];let o=0;q.lastIndex=0;let i=q.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=q.exec(e)}return o<e.length&&n.push({type:"text",value:e.substring(o)}),n.length===0?[{type:"text",value:e}]:n}function ee(e){X.visit(e,"paragraph",t=>{const n=t.children||[],o=[];for(const i of n)if(i.type==="text"){const r=Oe(i.value);o.push(...r)}else o.push(i);t.children=o})}function _e(e,t){X.visit(e,"paragraph",n=>{const o=n.children||[],i=[];for(const r of o)if(r.type==="text"){const s=Ne(r.value,t);i.push(...s)}else i.push(r);n.children=i})}const Pe=()=>e=>{ee(e)};function je(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 Be(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 te(e){if(e.children.length===0)e.finalColons=e.colons;else{const t=Math.max(...e.children.map(te));e.finalColons=Math.max(e.colons,t+1)}return e.finalColons}function ze(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 Ue(e){const t=e.split(`
2
- `),n=[];let o=!1,i=null;for(let l=0;l<t.length;l++){const c=t[l],a=c.trim().match(/^(`{3,}|~{3,})/);if(a){const m=a[1];o?i&&m[0]===i[0]&&m.length>=i.length&&(o=!1,i=null):(o=!0,i=m);continue}if(o)continue;const d=je(c);d&&n.push({...d,lineIndex:l})}if(n.length===0)return e;const r=Be(n);for(const l of r)te(l);return ze(t,r).join(`
3
- `)}function We(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 o=n.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);if(!o)return null;const[,i,r]=o;return r&&!/^(\[[^\]]*\]|\{[^}]*\})*$/.test(r)||!T[i.toLowerCase()]?null:n}function $(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 He(e,t){const n=$(e[t]);for(let o=t+1;o<e.length;o++)if(!ne(e[o]))return $(e[o])>n;return!1}function ne(e){return e.trim()===""}function Ve(e,t){let n=0,o=0;for(;o<e.length&&n<t;)if(e[o]===" ")n++,o++;else if(e[o]===" ")n+=4,o++;else break;return e.slice(o)}function Xe(e){const t=e.split(`
4
- `),n=[],o={level:0,openDirectives:[],inCodeFence:!1,codeFenceMarker:null};for(let i=0;i<t.length;i++){const r=t[i],s=r.trim(),l=$(r),c=s.match(/^(`{3,}|~{3,})/);if(c){const a=c[1];o.inCodeFence?o.codeFenceMarker&&s.startsWith(o.codeFenceMarker)&&(o.inCodeFence=!1,o.codeFenceMarker=null):(o.inCodeFence=!0,o.codeFenceMarker=a),n.push(r);continue}if(o.inCodeFence){n.push(r);continue}if(ne(r)){n.push("");continue}const u=We(s);if(u&&He(t,i)){for(;o.openDirectives.length>0&&!(o.openDirectives[o.openDirectives.length-1].indentLevel<l);){const v=o.openDirectives.pop();v&&n.push(":".repeat(v.colonCount))}const a=u.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/),d=a?a[1].toLowerCase()+(a[2]||""):u,m=o.openDirectives.length*1+3;n.push(":".repeat(m)+d),o.openDirectives.push({label:d,indentLevel:l,colonCount:m,bodyBaseIndent:-1}),o.level=l}else{for(;o.openDirectives.length>0&&l<=o.openDirectives[o.openDirectives.length-1].indentLevel;){const a=o.openDirectives.pop();a&&n.push(":".repeat(a.colonCount))}if(o.openDirectives.length>0){const a=o.openDirectives[o.openDirectives.length-1];a.bodyBaseIndent<0&&(a.bodyBaseIndent=l),n.push(Ve(r,a.bodyBaseIndent))}else n.push(r);o.level=l}}for(;o.openDirectives.length>0;){const i=o.openDirectives.pop();i&&n.push(":".repeat(i.colonCount))}return n.join(`
5
- `)}const Ze=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/,Ke=/^division:\s*(\S+)\s*$/m,Ye=/^xmlid:\s*(\S+)\s*$/m,Ge=/^xml:id:\s*(\S+)\s*$/m,Je=/^label:\s*(\S+)\s*$/m,Qe=/^component:\s*(\S+)\s*$/m;function et(e){const t=e.match(Ze);if(!t)return{body:e};const n=t[1],o=e.slice(t[0].length),i=n.match(Ke)?.[1];let r,s;i&&g.isRootDivisionType(i)?(s=i,r=g.rootChildDivision(i)):i&&g.isTopLevelDivisionType(i)&&(r=i);const l={},c=n.match(Ye)?.[1]??n.match(Ge)?.[1],u=n.match(Je)?.[1],a=n.match(Qe)?.[1];return c&&(l["xml:id"]=c),u&&(l.label=u),a&&(l.component=a),{division:r,documentRoot:s,attributes:Object.keys(l).length>0?l:void 0,body:o}}const oe=function(e){return function(n,o){if(typeof o?.value=="string"){const i=et(o.value),r=e?.documentRoot??i.documentRoot,s=e?.topLevelDivision??i.division??(r?g.rootChildDivision(r):"chapter"),l=e?.topLevelAttributes??i.attributes,c=Xe(i.body),u=Ue(c),a=Fe(u),m=W.unified().data("micromarkExtensions",[{disable:{null:["codeIndented"]}}]).use(H).use(V).parse(a.markdown);return _e(m,a.tokens),A(m,a.markdown,{topLevelDivision:s,documentRoot:r,topLevelAttributes:l})}return ee(n),A(n,void 0,{topLevelDivision:e?.topLevelDivision??(e?.documentRoot?g.rootChildDivision(e.documentRoot):"chapter"),documentRoot:e?.documentRoot,topLevelAttributes:e?.topLevelAttributes})}},tt=/["&'<>`]/g,nt=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,ot=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,it=/[|\\{}()[\]^$+*?.]/g,B=new WeakMap;function rt(e,t){if(e=e.replace(t.subset?st(t.subset):tt,o),t.subset||t.escapeOnly)return e;return e.replace(nt,n).replace(ot,o);function n(i,r,s){return t.format((i.charCodeAt(0)-55296)*1024+i.charCodeAt(1)-56320+65536,s.charCodeAt(r+2),t)}function o(i,r,s){return t.format(i.charCodeAt(0),s.charCodeAt(r+1),t)}}function st(e){let t=B.get(e);return t||(t=lt(e),B.set(e,t)),t}function lt(e){const t=[];let n=-1;for(;++n<e.length;)t.push(e[n].replace(it,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function ct(e){return"&#x"+e.toString(16).toUpperCase()+";"}function ut(e,t){return rt(e,Object.assign({format:ct},t))}const at=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function k(e,t,n){const o=pt(e);return n?o.replace(n,i):i(o);function i(r){return ut(r,{subset:t})}}function pt(e){return String(e||"").replace(at,"")}const ft=/]]>/g,ht=[">"];function dt(e){return"<![CDATA["+k(e.value,ht,ft)+"]]>"}function mt(e){return"<!--"+k(e.value,["-"])+"-->"}const gt=[" ",`
6
- `," ",'"',"&","'","/","<","=",">"];function S(e){return k(e,gt)}function z(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let o=0,i=n.indexOf(t);for(;i!==-1;)o++,i=n.indexOf(t,i+t.length);return o}function F(e,t){const n=String(e);let o=t.options.quote||'"';if(t.options.quoteSmart){const i=o==='"'?"'":'"';z(n,o)>z(n,i)&&(o=i)}return o+k(n,["<","&",o])+o}function yt(e,t){const n=S(e.name),o=e.public,i=e.system;let r="<!DOCTYPE";return n!==""&&(r+=" "+n),o?r+=" PUBLIC "+F(o,t):i&&(r+=" SYSTEM"),i&&(r+=" "+F(i,t)),r+">"}const vt={}.hasOwnProperty;function kt(e,t){const n=S(e.name),o=se(e,t),i=e.attributes||{},r=o?!1:t.options.closeEmptyElements,s=[];let l;for(l in i)if(vt.call(i,l)){const c=i[l];c!=null&&s.push(S(l)+"="+F(c,t))}return"<"+n+(s.length===0?"":" "+s.join(" "))+(r?(t.options.tightClose?"":" ")+"/":"")+">"+o+(r?"":"</"+n+">")}const bt=/\?>/g,Dt=[">"];function xt(e){const t=S(e.name)||"x",n=k(e.value,Dt,bt);return"<?"+t+(n?" "+n:"")+"?>"}const Ct=["&","<"];function ie(e){return k(e.value,Ct)}function wt(e,t){return t.options.allowDangerousXml?e.value:ie(e)}const It={}.hasOwnProperty,U={cdata:dt,comment:mt,doctype:yt,element:kt,instruction:xt,raw:wt,root:se,text:ie};function re(e,t){const n=e&&e.type;if(!n)throw new Error("Expected node, not `"+e+"`");if(!It.call(U,n))throw new Error("Cannot compile unknown node `"+n+"`");const o=U[n];return o(e,t)}function se(e,t){const n=e&&e.children||[];let o=-1;const i=[];for(;++o<n.length;)i[o]=re(n[o],t);return i.join("")}function Lt(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 o=Array.isArray(e)?{type:"root",children:e}:e;return re(o,n)}function St(e,t){const n=W.unified().use(H).use(V).use(oe,t),o=n.parse(e),i=n.runSync(o,{value:e});return Lt(i.children,{closeEmptyElements:!0,tightClose:!0})}exports.DIRECTIVE_MAP=ue;exports.PROOF_SOLUTION_NAMES=O;exports.markdownToPretext=St;exports.mdastToPtxast=A;exports.remarkMath=Pe;exports.remarkPretext=oe;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("unified"),X=require("remark-parse"),Z=require("remark-directive"),v=require("@pretextbook/ptxast"),K=require("unist-util-visit");function ce(e,t={}){const n={};for(const[o,i]of Object.entries(t))i!=null&&(n[o]=i);return{type:"element",name:`plus:${e}`,attributes:n,children:[]}}function ue(e){const t=e.name?.trim();return t?ce(t,e.attributes??{}):null}const R={theorem:{type:"theorem",category:"theorem-like",requiresStatement:!0},lemma:{type:"lemma",category:"theorem-like",requiresStatement:!0},corollary:{type:"corollary",category:"theorem-like",requiresStatement:!0},proposition:{type:"proposition",category:"theorem-like",requiresStatement:!0},claim:{type:"claim",category:"theorem-like",requiresStatement:!0},fact:{type:"fact",category:"theorem-like",requiresStatement:!0},conjecture:{type:"conjecture",category:"theorem-like",requiresStatement:!0},axiom:{type:"axiom",category:"theorem-like",requiresStatement:!0},principle:{type:"principle",category:"theorem-like",requiresStatement:!0},hypothesis:{type:"hypothesis",category:"theorem-like",requiresStatement:!0},algorithm:{type:"algorithm",category:"theorem-like",requiresStatement:!0},definition:{type:"definition",category:"definition-like",requiresStatement:!0},notation:{type:"notation",category:"definition-like",requiresStatement:!0},remark:{type:"remark",category:"remark-like",requiresStatement:!1},note:{type:"note",category:"remark-like",requiresStatement:!1},observation:{type:"observation",category:"remark-like",requiresStatement:!1},warning:{type:"warning",category:"remark-like",requiresStatement:!1},insight:{type:"insight",category:"remark-like",requiresStatement:!1},assemblage:{type:"assemblage",category:"remark-like",requiresStatement:!1},example:{type:"example",category:"example-like",requiresStatement:!1},question:{type:"question",category:"example-like",requiresStatement:!1},problem:{type:"problem",category:"example-like",requiresStatement:!1},exercise:{type:"exercise",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},activity:{type:"activity",category:"example-like",requiresStatement:!1},exploration:{type:"exploration",category:"example-like",requiresStatement:!1},investigation:{type:"investigation",category:"example-like",requiresStatement:!1},project:{type:"project",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},task:{type:"task",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},proof:{type:"proof",category:"proof-like",requiresStatement:!1},case:{type:"case",category:"proof-like",requiresStatement:!1},solution:{type:"solution",category:"solution-like",requiresStatement:!1},hint:{type:"hint",category:"solution-like",requiresStatement:!1},answer:{type:"answer",category:"solution-like",requiresStatement:!1}},ae=R;function pe(e){return R[e.toLowerCase()]}const j=new Set(Object.entries(R).filter(([e,t])=>t.category==="proof-like"||t.category==="solution-like").map(([e])=>e));function x(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function I(e){return e.type==="containerDirective"&&e.name==="task"}function fe(e){return e.type==="containerDirective"&&j.has(e.name)}function E(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(x("p",[n])):t.push(n);return t}function he(e,t,n,o,i,r,s){const l=[];if(n&&l.push(n),e.hasNestedTasks){const c=o.findIndex(I);if(c!==-1){const u=[];for(let f=0;f<o.length;f++)I(o[f])&&u.push(f);const a=u[u.length-1],p=o.slice(0,c),d=o.slice(c).filter(I),g=[],y=[],k=[];for(let f=c;f<o.length;f++){const m=o[f];if(!I(m)){if(f<a){g.push(m);continue}if(fe(m)){k.push(m);continue}y.push(m)}}if(g.length>0&&(i.messages??(i.messages=[])).push({type:"warning",reason:`Dropped ${g.length} non-task node(s) between task directives in ${e.type}.`,category:"dropped-content-between-tasks",position:g[0].position?.start}),p.length>0){const f=E(p.map(m=>r(m,i)).filter(m=>m!==null));f.length>0&&l.push(x("introduction",f))}for(const f of d){const m=s(f,i);m&&l.push(m)}if(y.length>0){const f=E(y.map(m=>r(m,i)).filter(m=>m!==null));f.length>0&&l.push(x("conclusion",f))}for(const f of k){const m=s(f,i);m&&l.push(m)}}else z(l,e,o,i,r,s)}else z(l,e,o,i,r,s);return x(e.type,l,t)}function z(e,t,n,o,i,r){if(t.requiresStatement){const s=[],l=[];for(const c of n)if(c.type==="containerDirective"&&j.has(c.name)){const u=r(c,o);u&&l.push(u)}else s.push(c);if(s.length>0){const c=E(s.map(u=>i(u,o)).filter(u=>u!==null));c.length>0&&e.push(x("statement",c))}e.push(...l)}else{const s=E(n.map(l=>i(l,o)).filter(l=>l!==null));e.push(...s)}}function q(e){return{type:"text",value:e}}function h(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function b(e,t,n){return h(e,[q(t)],n)}function Y(e){return{type:"comment",value:e.replace(/--/g,"- -")}}function $(e,t){const n=e?.position,o=n?.start?.offset,i=n?.end?.offset;return t.source&&o!=null&&i!=null?t.source.slice(o,i):""}function B(e,t,n){return h("TODO",[Y(`todo: ${t}`),b("pre",n)],{type:e})}function de(e,t,n){return h("TODO",[Y(`todo: ${t}`),b("c",n)],{type:e})}function A(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(h("p",[n])):t.push(n);return t}function O(e,t,n){return me(e,t,n).tree}function me(e,t,n){const o=[],i={ancestors:[],depth:0,messages:o,source:t,topLevelDivision:n?.topLevelDivision??"chapter",documentRoot:n?.documentRoot,topLevelAttributes:n?.topLevelAttributes,topLevelAttributesApplied:n?.topLevelAttributes?{done:!1}:void 0,topLevelTitle:n?.topLevelTitle},r=e.children;if(i.documentRoot){const a=S(i),p=i.topLevelTitle?h("title",[q(i.topLevelTitle)]):null,{introduction:d,rest:g}=T(r,i),y=C(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(C(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(C(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=C(l,i);return{tree:{type:"root",children:s?[s,...c]:c},messages:o}}function C(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 L(e,t,n);const i=[];let r=null,s=[],l=[];const c=()=>{r&&(i.push(ge(r,l,t)),r=null,l=[])};for(const u of e)u.type==="heading"&&u.depth===o?(!r&&s.length>0&&(i.push(...L(s,t,n)),s=[]),c(),r=u,l=[]):r?l.push(u):s.push(u);return!r&&s.length>0&&i.push(...L(s,t,n)),c(),i}function L(e,t,n=!1){const o=[];for(let i=0;i<e.length;i+=1){const r=e[i],s=_(r,t);if(s!==null){if(s.name==="p"&&s.children.length===1&&s.children[0].name==="md"){const l=s.children[0],c=o[o.length-1],u=i+1<e.length?_(e[i+1],t):null,a=u?.name==="p"?u.children:null;if(c?.name==="p")c.children.push(l),a&&(c.children.push(...a),i+=1);else{const p=[l];a&&(p.push(...a),i+=1),o.push(h("p",p))}continue}if((s.name==="ul"||s.name==="ol")&&o.length>0){const l=o[o.length-1];if(l?.name==="p"){l.children.push(s);continue}}o.push(s)}}return n?A(o):o}function ge(e,t,n){const o=e.depth+(n.headingDepthOffset??0),i=n.documentRoot?v.divisionTypeAtRootDepth(n.documentRoot,o):v.divisionTypeAtRelativeDepth(n.topLevelDivision,o),r=h("title",w(e.children,n)),s=ke(e,n),l={...n,depth:n.depth+1},{introduction:c,rest:u}=T(t,l),a=C(u,l,!0),p=A(a),d=c?[r,c,...p]:[r,...p];return h(i,d,s)}function ye(e){return e.type==="leafDirective"&&v.isTopLevelDivisionType(e.name)}function T(e,t){const n=e.findIndex(l=>l.type==="heading"||ye(l));if(n<=0)return{introduction:null,rest:e};const o=e.slice(0,n),i=e.slice(n),r=L(o,t,!0);return{introduction:r.length>0?h("introduction",r):null,rest:i}}function ve(e){const t=e.data;return t?.id?{"xml:id":t.id}:void 0}function ke(e,t){const n=ve(e),o=S(t);if(!(!n&&!o))return{...o,...n}}function S(e){if(e.depth!==0)return;const t=e.topLevelAttributesApplied;if(!(!e.topLevelAttributes||!t||t.done))return t.done=!0,e.topLevelAttributes}const be={paragraph:(e,t)=>Q(e,t),blockquote:(e,t)=>De(e,t),list:(e,t)=>Ce(e,t),code:(e,t)=>Le(e),containerDirective:(e,t)=>G(e,t),leafDirective:(e,t)=>Te(e,t)};function _(e,t){const n=be[e.type];return n?n(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),B("unknown-block-type",`unknown block type "${e.type}"`,$(e,t)))}function Q(e,t){return h("p",w(e.children,t))}function De(e,t){const n=e.children.filter(o=>o.type==="paragraph").map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Q(o,i)});return h("blockquote",n)}function Ce(e,t){const n=e.children.map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return xe(o,i)});return h(e.ordered?"ol":"ul",n)}function xe(e,t){const n=L(e.children,t);return h("li",n)}function Le(e,t){return b("program",e.value,e.lang?{language:e.lang}:void 0)}function we(e,t){const n=e.value.split(/\\\\|[\r\n]+/).map(o=>o.trim()).filter(o=>o.length>0);return n.length>1?h("md",n.map(o=>b("mrow",o))):b("md",n[0]??"")}function Ie(e,t){return e.meta==="inline"?b("m",e.value):we(e)}function Te(e,t){const n=ue(e);return n||(t.messages&&t.messages.push({type:"warning",reason:"Unnamed leaf directive",category:"unknown-directive"}),B("unknown-directive","unnamed leaf directive",$(e,t)))}function G(e,t){const n=pe(e.name);if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),B("unknown-directive",`unknown directive "${e.name}"`,$(e,t));const o=Ee(e),i=e.children,{title:r,body:s}=Se(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 Se(e,t){const n=e[0];return n?.type==="paragraph"&&n.data?.directiveLabel===!0?{title:h("title",w(n.children,t)),body:e.slice(1)}:{title:null,body:e}}function Ee(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 qe(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 Ae={text:(e,t)=>q(e.value),emphasis:(e,t)=>{const o=qe(e,t.source)==="underscore"?"term":"em";return h(o,w(e.children,t))},strong:(e,t)=>h("alert",w(e.children,t)),inlineCode:(e,t)=>b("c",e.value),math:(e,t)=>Ie(e)};function w(e,t){return e.flatMap(n=>Me(n,t)).filter(n=>n!==null)}function Me(e,t){const n=Ae[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 Re=[{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 Re){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 Fe(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 Oe(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 _e(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=Oe(i.value);o.push(...r)}else o.push(i);t.children=o})}function Ne(e,t){K.visit(e,"paragraph",n=>{const o=n.children||[],i=[];for(const r of o)if(r.type==="text"){const s=_e(r.value,t);i.push(...s)}else i.push(r);n.children=i})}const Pe=()=>e=>{te(e)};function je(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 Be(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 ze(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 Ue(e){const t=e.split(`
2
+ `),n=[];let o=!1,i=null;for(let l=0;l<t.length;l++){const c=t[l],a=c.trim().match(/^(`{3,}|~{3,})/);if(a){const d=a[1];o?i&&d[0]===i[0]&&d.length>=i.length&&(o=!1,i=null):(o=!0,i=d);continue}if(o)continue;const p=je(c);p&&n.push({...p,lineIndex:l})}if(n.length===0)return e;const r=Be(n);for(const l of r)ne(l);return ze(t,r).join(`
3
+ `)}function We(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 o=n.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);if(!o)return null;const[,i,r]=o;return r&&!/^(\[[^\]]*\]|\{[^}]*\})*$/.test(r)||!R[i.toLowerCase()]?null:n}function N(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 Ve(e,t){const n=N(e[t]);for(let o=t+1;o<e.length;o++)if(!oe(e[o]))return N(e[o])>n;return!1}function oe(e){return e.trim()===""}function He(e,t){let n=0,o=0;for(;o<e.length&&n<t;)if(e[o]===" ")n++,o++;else if(e[o]===" ")n+=4,o++;else break;return e.slice(o)}function Xe(e){const t=e.split(`
4
+ `),n=[],o={level:0,openDirectives:[],inCodeFence:!1,codeFenceMarker:null};for(let i=0;i<t.length;i++){const r=t[i],s=r.trim(),l=N(r),c=s.match(/^(`{3,}|~{3,})/);if(c){const a=c[1];o.inCodeFence?o.codeFenceMarker&&s.startsWith(o.codeFenceMarker)&&(o.inCodeFence=!1,o.codeFenceMarker=null):(o.inCodeFence=!0,o.codeFenceMarker=a),n.push(r);continue}if(o.inCodeFence){n.push(r);continue}if(oe(r)){n.push("");continue}const u=We(s);if(u&&Ve(t,i)){for(;o.openDirectives.length>0&&!(o.openDirectives[o.openDirectives.length-1].indentLevel<l);){const y=o.openDirectives.pop();y&&n.push(":".repeat(y.colonCount))}const a=u.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/),p=a?a[1].toLowerCase()+(a[2]||""):u,d=o.openDirectives.length*1+3;n.push(":".repeat(d)+p),o.openDirectives.push({label:p,indentLevel:l,colonCount:d,bodyBaseIndent:-1}),o.level=l}else{for(;o.openDirectives.length>0&&l<=o.openDirectives[o.openDirectives.length-1].indentLevel;){const a=o.openDirectives.pop();a&&n.push(":".repeat(a.colonCount))}if(o.openDirectives.length>0){const a=o.openDirectives[o.openDirectives.length-1];a.bodyBaseIndent<0&&(a.bodyBaseIndent=l),n.push(He(r,a.bodyBaseIndent))}else n.push(r);o.level=l}}for(;o.openDirectives.length>0;){const i=o.openDirectives.pop();i&&n.push(":".repeat(i.colonCount))}return n.join(`
5
+ `)}const Ze=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/,Ke=/^division:\s*(\S+)\s*$/m,Ye=/^id:\s*(\S+)\s*$/m,Qe=/^xmlid:\s*(\S+)\s*$/m,Ge=/^xml:id:\s*(\S+)\s*$/m,Je=/^label:\s*(\S+)\s*$/m,et=/^component:\s*(\S+)\s*$/m,tt=/^title:\s*(.+?)\s*$/m;function nt(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 ot(e){const t=e.match(Ze);if(!t)return{body:e};const n=t[1],o=e.slice(t[0].length),i=n.match(Ke)?.[1];let r,s;i&&v.isRootDivisionType(i)?(s=i,r=v.rootChildDivision(i)):i&&v.isTopLevelDivisionType(i)&&(r=i);const l={},c=n.match(Ye)?.[1]??n.match(Qe)?.[1]??n.match(Ge)?.[1],u=n.match(Je)?.[1],a=n.match(et)?.[1];c&&(l["xml:id"]=c),u&&(l.label=u),a&&(l.component=a);const p=n.match(tt)?.[1],d=p?nt(p):void 0;return{division:r,documentRoot:s,attributes:Object.keys(l).length>0?l:void 0,title:d,body:o}}const ie=function(e){return function(n,o){if(typeof o?.value=="string"){const i=ot(o.value),r=e?.documentRoot??i.documentRoot,s=e?.topLevelDivision??i.division??(r?v.rootChildDivision(r):"chapter"),l=e?.topLevelAttributes??i.attributes,c=e?.topLevelTitle??i.title,u=Xe(i.body),a=Ue(u),p=Fe(a),g=H.unified().data("micromarkExtensions",[{disable:{null:["codeIndented"]}}]).use(X).use(Z).parse(p.markdown);return Ne(g,p.tokens),O(g,p.markdown,{topLevelDivision:s,documentRoot:r,topLevelAttributes:l,topLevelTitle:c})}return te(n),O(n,void 0,{topLevelDivision:e?.topLevelDivision??(e?.documentRoot?v.rootChildDivision(e.documentRoot):"chapter"),documentRoot:e?.documentRoot,topLevelAttributes:e?.topLevelAttributes,topLevelTitle:e?.topLevelTitle})}},it=/["&'<>`]/g,rt=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,st=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,lt=/[|\\{}()[\]^$+*?.]/g,U=new WeakMap;function ct(e,t){if(e=e.replace(t.subset?ut(t.subset):it,o),t.subset||t.escapeOnly)return e;return e.replace(rt,n).replace(st,o);function n(i,r,s){return t.format((i.charCodeAt(0)-55296)*1024+i.charCodeAt(1)-56320+65536,s.charCodeAt(r+2),t)}function o(i,r,s){return t.format(i.charCodeAt(0),s.charCodeAt(r+1),t)}}function ut(e){let t=U.get(e);return t||(t=at(e),U.set(e,t)),t}function at(e){const t=[];let n=-1;for(;++n<e.length;)t.push(e[n].replace(lt,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function pt(e){return"&#x"+e.toString(16).toUpperCase()+";"}function ft(e,t){return ct(e,Object.assign({format:pt},t))}const ht=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function D(e,t,n){const o=dt(e);return n?o.replace(n,i):i(o);function i(r){return ft(r,{subset:t})}}function dt(e){return String(e||"").replace(ht,"")}const mt=/]]>/g,gt=[">"];function yt(e){return"<![CDATA["+D(e.value,gt,mt)+"]]>"}function vt(e){return"<!--"+D(e.value,["-"])+"-->"}const kt=[" ",`
6
+ `," ",'"',"&","'","/","<","=",">"];function M(e){return D(e,kt)}function W(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let o=0,i=n.indexOf(t);for(;i!==-1;)o++,i=n.indexOf(t,i+t.length);return o}function P(e,t){const n=String(e);let o=t.options.quote||'"';if(t.options.quoteSmart){const i=o==='"'?"'":'"';W(n,o)>W(n,i)&&(o=i)}return o+D(n,["<","&",o])+o}function bt(e,t){const n=M(e.name),o=e.public,i=e.system;let r="<!DOCTYPE";return n!==""&&(r+=" "+n),o?r+=" PUBLIC "+P(o,t):i&&(r+=" SYSTEM"),i&&(r+=" "+P(i,t)),r+">"}const Dt={}.hasOwnProperty;function Ct(e,t){const n=M(e.name),o=le(e,t),i=e.attributes||{},r=o?!1:t.options.closeEmptyElements,s=[];let l;for(l in i)if(Dt.call(i,l)){const c=i[l];c!=null&&s.push(M(l)+"="+P(c,t))}return"<"+n+(s.length===0?"":" "+s.join(" "))+(r?(t.options.tightClose?"":" ")+"/":"")+">"+o+(r?"":"</"+n+">")}const xt=/\?>/g,Lt=[">"];function wt(e){const t=M(e.name)||"x",n=D(e.value,Lt,xt);return"<?"+t+(n?" "+n:"")+"?>"}const It=["&","<"];function re(e){return D(e.value,It)}function Tt(e,t){return t.options.allowDangerousXml?e.value:re(e)}const St={}.hasOwnProperty,V={cdata:yt,comment:vt,doctype:bt,element:Ct,instruction:wt,raw:Tt,root:le,text:re};function se(e,t){const n=e&&e.type;if(!n)throw new Error("Expected node, not `"+e+"`");if(!St.call(V,n))throw new Error("Cannot compile unknown node `"+n+"`");const o=V[n];return o(e,t)}function le(e,t){const n=e&&e.children||[];let o=-1;const i=[];for(;++o<n.length;)i[o]=se(n[o],t);return i.join("")}function Et(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 o=Array.isArray(e)?{type:"root",children:e}:e;return se(o,n)}function qt(e,t){const n=H.unified().use(X).use(Z).use(ie,t),o=n.parse(e),i=n.runSync(o,{value:e});return Et(i.children,{closeEmptyElements:!0,tightClose:!0})}exports.DIRECTIVE_MAP=ae;exports.PROOF_SOLUTION_NAMES=j;exports.markdownToPretext=qt;exports.mdastToPtxast=O;exports.remarkMath=Pe;exports.remarkPretext=ie;