@pretextbook/remark-pretext 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("unified"),j=require("remark-parse"),z=require("remark-directive"),B=require("unist-util-visit"),q={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}},re=q;function oe(e){return q[e.toLowerCase()]}const F=new Set(Object.entries(q).filter(([e,t])=>t.category==="proof-like"||t.category==="solution-like").map(([e])=>e));function v(e,t,r){return{type:"element",name:e,attributes:r??{},children:t}}function C(e){return e.type==="containerDirective"&&e.name==="task"}function se(e){return e.type==="containerDirective"&&F.has(e.name)}function S(e){const t=[];for(const r of e)r.name==="ul"||r.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(r):t.push(v("p",[r])):t.push(r);return t}function ie(e,t,r,n,o,s,i){const l=[];if(r&&l.push(r),e.hasNestedTasks){const c=n.findIndex(C);if(c!==-1){const a=[];for(let p=0;p<n.length;p++)C(n[p])&&a.push(p);const u=a[a.length-1],d=n.slice(0,c),m=n.slice(c).filter(C),k=[],g=[],N=[];for(let p=c;p<n.length;p++){const f=n[p];if(!C(f)){if(p<u){k.push(f);continue}if(se(f)){N.push(f);continue}g.push(f)}}if(k.length>0&&(o.messages??(o.messages=[])).push({type:"warning",reason:`Dropped ${k.length} non-task node(s) between task directives in ${e.type}.`,category:"dropped-content-between-tasks",position:k[0].position?.start}),d.length>0){const p=S(d.map(f=>s(f,o)).filter(f=>f!==null));p.length>0&&l.push(v("introduction",p))}for(const p of m){const f=i(p,o);f&&l.push(f)}if(g.length>0){const p=S(g.map(f=>s(f,o)).filter(f=>f!==null));p.length>0&&l.push(v("conclusion",p))}for(const p of N){const f=i(p,o);f&&l.push(f)}}else $(l,e,n,o,s,i)}else $(l,e,n,o,s,i);return v(e.type,l,t)}function $(e,t,r,n,o,s){if(t.requiresStatement){const i=[],l=[];for(const c of r)if(c.type==="containerDirective"&&F.has(c.name)){const a=s(c,n);a&&l.push(a)}else i.push(c);if(i.length>0){const c=S(i.map(a=>o(a,n)).filter(a=>a!==null));c.length>0&&e.push(v("statement",c))}e.push(...l)}else{const i=S(r.map(l=>o(l,n)).filter(l=>l!==null));e.push(...i)}}function W(e){return{type:"text",value:e}}function h(e,t,r){return{type:"element",name:e,attributes:r??{},children:t}}function x(e,t,r){return h(e,[W(t)],r)}function U(e){const t=[];for(const r of e)r.name==="ul"||r.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(r):t.push(h("p",[r])):t.push(r);return t}function T(e,t){return le(e,t).tree}function le(e,t){const r=[],n={ancestors:[],depth:0,messages:r,source:t},o=e.children;return{tree:{type:"root",children:H(o,n)},messages:r}}const O=["chapter","section","subsection","subsubsection","paragraphs"];function ce(e){return O[Math.min(e-1,O.length-1)]}function H(e,t,r=!1){let n=7;for(const a of e)a.type==="heading"&&(n=Math.min(n,a.depth));if(n===7)return w(e,t,r);const o=[];let s=null,i=[],l=[];const c=()=>{s&&(o.push(ae(s,l,t)),s=null,l=[])};for(const a of e)a.type==="heading"&&a.depth===n?(!s&&i.length>0&&(o.push(...w(i,t,r)),i=[]),c(),s=a,l=[]):s?l.push(a):i.push(a);return!s&&i.length>0&&o.push(...w(i,t,r)),c(),o}function w(e,t,r=!1){const n=[];for(let o=0;o<e.length;o+=1){const s=e[o],i=E(s,t);if(i!==null){if(i.name==="p"&&i.children.length===1&&i.children[0].name==="md"){const l=i.children[0],c=n[n.length-1],a=o+1<e.length?E(e[o+1],t):null,u=a?.name==="p"?a.children:null;if(c?.name==="p")c.children.push(l),u&&(c.children.push(...u),o+=1);else{const d=[l];u&&(d.push(...u),o+=1),n.push(h("p",d))}continue}if((i.name==="ul"||i.name==="ol")&&n.length>0){const l=n[n.length-1];if(l?.name==="p"){l.children.push(i);continue}}n.push(i)}}return r?U(n):n}function ae(e,t,r){const n=ce(e.depth),o=h("title",b(e.children,r)),s=ue(e),i=H(t,{...r,depth:r.depth+1},!0),l=U(i);return h(n,[o,...l],s)}function ue(e){const t=e.data;return t?.id?{"xml:id":t.id}:void 0}const pe={paragraph:(e,t)=>Z(e,t),blockquote:(e,t)=>fe(e,t),list:(e,t)=>he(e,t),code:(e,t)=>me(e),containerDirective:(e,t)=>V(e,t)};function E(e,t){const r=pe[e.type];return r?r(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),null)}function Z(e,t){return h("p",b(e.children,t))}function fe(e,t){const r=e.children.filter(n=>n.type==="paragraph").map(n=>{const o={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Z(n,o)});return h("blockquote",r)}function he(e,t){const r=e.children.map(n=>{const o={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return de(n,o)});return h(e.ordered?"ol":"ul",r)}function de(e,t){const r=w(e.children,t);return h("li",r)}function me(e,t){return x("program",e.value,e.lang?{language:e.lang}:void 0)}function ge(e,t){const r=e.value.split(/\\\\|[\r\n]+/).map(n=>n.trim()).filter(n=>n.length>0);return r.length>1?h("md",r.map(n=>x("mrow",n))):x("md",r[0]??"")}function ye(e,t){return e.meta==="inline"?x("m",e.value):ge(e)}function V(e,t){const r=oe(e.name);if(!r)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),null;const n=ve(e),o=e.children,{title:s,body:i}=ke(o,t),l={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return ie(r,n,s,i,l,(c,a)=>E(c,a),(c,a)=>V(c,a))}function ke(e,t){const r=e[0];return r?.type==="paragraph"&&r.data?.directiveLabel===!0?{title:h("title",b(r.children,t)),body:e.slice(1)}:{title:null,body:e}}function ve(e){const t=e.attributes??{},r={};for(const[n,o]of Object.entries(t))o!=null&&(r[n==="id"?"xml:id":n]=o);return Object.keys(r).length>0?r:void 0}function xe(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 be={text:(e,t)=>W(e.value),emphasis:(e,t)=>{const n=xe(e,t.source)==="underscore"?"term":"em";return h(n,b(e.children,t))},strong:(e,t)=>h("alert",b(e.children,t)),inlineCode:(e,t)=>x("c",e.value),math:(e,t)=>ye(e)};function b(e,t){return e.flatMap(r=>Ce(r,t)).filter(r=>r!==null)}function Ce(e,t){const r=be[e.type];if(!r)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),null;const n={...t,ancestors:[...t.ancestors,e]};return r(e,n)}const we=[{open:"$$",close:"$$",isDisplay:!0},{open:"\\[",close:"\\]",isDisplay:!0},{open:"$",close:"$",isDisplay:!1},{open:"\\(",close:"\\)",isDisplay:!1}],X="PTX_MATH_TOKEN_",I=new RegExp(`${X}(\\d+)`,"g");function K(e,t){let r=null;for(const n of we){const o=e.indexOf(n.open,t);if(o===-1)continue;const s=e.indexOf(n.close,o+n.open.length);if(s!==-1&&!(n.open==="$"&&(o>0&&e[o-1]==="$"||o+1<e.length&&e[o+1]==="$"))&&(!r||o<r.index)){const i=e.substring(o+n.open.length,s);r={index:o,pattern:n,content:i}}}return r}function Se(e,t){let r=t;for(;r<e.length;){const n=e.indexOf("`",r);if(n===-1)return null;let o=0,s=n;for(;s<e.length&&e[s]==="`";)o++,s++;const i="`".repeat(o);let l=s;for(;l<e.length;){const c=e.indexOf(i,l);if(c===-1)break;const a=c+o;if(a>=e.length||e[a]!=="`")return{start:n,end:a};l=c+1}r=n+o}return null}function De(e){const t=new Map;let r="",n=0,o=0;for(;n<e.length;){const s=Se(e,n),i=K(e,n);if(s&&(!i||s.start<i.index)){r+=e.substring(n,s.end),n=s.end;continue}if(!i){r+=e.substring(n);break}r+=e.substring(n,i.index);const l=`${X}${o}`;r+=l,t.set(l,{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,o+=1}return{markdown:r,tokens:t}}function qe(e){const t=[];let r=0;for(;r<e.length;){const n=K(e,r);if(!n){r<e.length&&t.push({type:"text",value:e.substring(r)});break}n.index>r&&t.push({type:"text",value:e.substring(r,n.index)}),t.push({type:"math",value:n.content,meta:n.pattern.isDisplay?"display":"inline"}),r=n.index+n.pattern.open.length+n.content.length+n.pattern.close.length}return t.length===0?[{type:"text",value:e}]:t}function Ie(e,t){const r=[];let n=0;I.lastIndex=0;let o=I.exec(e);for(;o;){const s=o.index,i=o[0];s>n&&r.push({type:"text",value:e.substring(n,s)});const l=t.get(i);l?r.push(l):r.push({type:"text",value:i}),n=s+i.length,o=I.exec(e)}return n<e.length&&r.push({type:"text",value:e.substring(n)}),r.length===0?[{type:"text",value:e}]:r}function Y(e){B.visit(e,"paragraph",t=>{const r=t.children||[],n=[];for(const o of r)if(o.type==="text"){const s=qe(o.value);n.push(...s)}else n.push(o);t.children=n})}function Te(e,t){B.visit(e,"paragraph",r=>{const n=r.children||[],o=[];for(const s of n)if(s.type==="text"){const i=Ie(s.value,t);o.push(...i)}else o.push(s);r.children=o})}const Ee=()=>e=>{Y(e)};function Me(e){const t=e.trim();if(!t.startsWith(":"))return null;let r=0;for(let s=0;s<t.length&&t[s]===":";s++)r++;if(r<3)return null;const n=t.slice(r).trim(),o=n.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);return n===""?{colons:r,label:null,lineIndex:-1,isOpen:!1}:o?{colons:r,label:o[0],lineIndex:-1,isOpen:!0}:null}function Le(e){const t=[],r=[];for(const n of e)if(n.isOpen){const o={colons:n.colons,finalColons:n.colons,label:n.label,openLineIndex:n.lineIndex,closeLineIndex:null,children:[],parent:null};if(t.length>0){const s=t[t.length-1];o.parent=s,s.children.push(o)}else r.push(o);t.push(o)}else{const o=t[t.length-1];o&&o.colons===n.colons&&(o.closeLineIndex=n.lineIndex,t.pop())}return r}function G(e){if(e.children.length===0)e.finalColons=e.colons;else{const t=Math.max(...e.children.map(G));e.finalColons=Math.max(e.colons,t+1)}return e.finalColons}function Fe(e,t,r){const n=e.slice(),o=[],s=t.slice();for(;s.length>0;){const i=s.shift();o.push(i),s.push(...i.children)}for(const i of o){if(i.openLineIndex>=0){const l=n[i.openLineIndex],c=l.match(/^:+/)?.[0].length||3,a=l.slice(c);n[i.openLineIndex]=":".repeat(i.finalColons)+a}i.closeLineIndex!==null&&i.closeLineIndex>=0&&(n[i.closeLineIndex]=":".repeat(i.finalColons))}return n}function Ne(e){const t=e.split(`
2
- `),r=[];let n=!1,o=null;for(let l=0;l<t.length;l++){const c=t[l],u=c.trim().match(/^(`{3,}|~{3,})/);if(u){const m=u[1];n?o&&m[0]===o[0]&&m.length>=o.length&&(n=!1,o=null):(n=!0,o=m);continue}if(n)continue;const d=Me(c);d&&r.push({...d,lineIndex:l})}if(r.length===0)return e;const s=Le(r);for(const l of s)G(l);return Fe(t,s).join(`
3
- `)}function $e(e){const t=e.trim();if(!t.endsWith(":"))return null;const r=t.slice(0,-1);if(!/^[a-zA-Z]/.test(r))return null;const n=r.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);if(!n)return null;const[,o,s]=n;return s&&!/^(\[[^\]]*\]|\{[^}]*\})*$/.test(s)||!q[o.toLowerCase()]?null:r}function M(e){let t=0;for(let r=0;r<e.length;r++)if(e[r]===" ")t+=1;else if(e[r]===" ")t+=4;else break;return t}function Oe(e,t){const r=M(e[t]);for(let n=t+1;n<e.length;n++)if(!J(e[n]))return M(e[n])>r;return!1}function J(e){return e.trim()===""}function Pe(e,t){let r=0,n=0;for(;n<e.length&&r<t;)if(e[n]===" ")r++,n++;else if(e[n]===" ")r+=4,n++;else break;return e.slice(n)}function Ae(e){const t=e.split(`
4
- `),r=[],n={level:0,openDirectives:[],inCodeFence:!1,codeFenceMarker:null};for(let o=0;o<t.length;o++){const s=t[o],i=s.trim(),l=M(s),c=i.match(/^(`{3,}|~{3,})/);if(c){const u=c[1];n.inCodeFence?n.codeFenceMarker&&i.startsWith(n.codeFenceMarker)&&(n.inCodeFence=!1,n.codeFenceMarker=null):(n.inCodeFence=!0,n.codeFenceMarker=u),r.push(s);continue}if(n.inCodeFence){r.push(s);continue}if(J(s)){r.push("");continue}const a=$e(i);if(a&&Oe(t,o)){for(;n.openDirectives.length>0&&!(n.openDirectives[n.openDirectives.length-1].indentLevel<l);){const g=n.openDirectives.pop();g&&r.push(":".repeat(g.colonCount))}const u=a.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/),d=u?u[1].toLowerCase()+(u[2]||""):a,m=n.openDirectives.length*1+3;r.push(":".repeat(m)+d),n.openDirectives.push({label:d,indentLevel:l,colonCount:m,bodyBaseIndent:-1}),n.level=l}else{for(;n.openDirectives.length>0&&l<=n.openDirectives[n.openDirectives.length-1].indentLevel;){const u=n.openDirectives.pop();u&&r.push(":".repeat(u.colonCount))}if(n.openDirectives.length>0){const u=n.openDirectives[n.openDirectives.length-1];u.bodyBaseIndent<0&&(u.bodyBaseIndent=l),r.push(Pe(s,u.bodyBaseIndent))}else r.push(s);n.level=l}}for(;n.openDirectives.length>0;){const o=n.openDirectives.pop();o&&r.push(":".repeat(o.colonCount))}return r.join(`
5
- `)}const Q=function(){return function(t,r){if(typeof r?.value=="string"){const n=Ae(r.value),o=Ne(n),s=De(o),l=R.unified().data("micromarkExtensions",[{disable:{null:["codeIndented"]}}]).use(j).use(z).parse(s.markdown);return Te(l,s.tokens),T(l,s.markdown)}return Y(t),T(t)}},_e=/["&'<>`]/g,Re=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,je=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,ze=/[|\\{}()[\]^$+*?.]/g,P=new WeakMap;function Be(e,t){if(e=e.replace(t.subset?We(t.subset):_e,n),t.subset||t.escapeOnly)return e;return e.replace(Re,r).replace(je,n);function r(o,s,i){return t.format((o.charCodeAt(0)-55296)*1024+o.charCodeAt(1)-56320+65536,i.charCodeAt(s+2),t)}function n(o,s,i){return t.format(o.charCodeAt(0),i.charCodeAt(s+1),t)}}function We(e){let t=P.get(e);return t||(t=Ue(e),P.set(e,t)),t}function Ue(e){const t=[];let r=-1;for(;++r<e.length;)t.push(e[r].replace(ze,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function He(e){return"&#x"+e.toString(16).toUpperCase()+";"}function Ze(e,t){return Be(e,Object.assign({format:He},t))}const Ve=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function y(e,t,r){const n=Xe(e);return r?n.replace(r,o):o(n);function o(s){return Ze(s,{subset:t})}}function Xe(e){return String(e||"").replace(Ve,"")}const Ke=/]]>/g,Ye=[">"];function Ge(e){return"<![CDATA["+y(e.value,Ye,Ke)+"]]>"}function Je(e){return"<!--"+y(e.value,["-"])+"-->"}const Qe=[" ",`
6
- `," ",'"',"&","'","/","<","=",">"];function D(e){return y(e,Qe)}function A(e,t){const r=String(e);if(typeof t!="string")throw new TypeError("Expected character");let n=0,o=r.indexOf(t);for(;o!==-1;)n++,o=r.indexOf(t,o+t.length);return n}function L(e,t){const r=String(e);let n=t.options.quote||'"';if(t.options.quoteSmart){const o=n==='"'?"'":'"';A(r,n)>A(r,o)&&(n=o)}return n+y(r,["<","&",n])+n}function et(e,t){const r=D(e.name),n=e.public,o=e.system;let s="<!DOCTYPE";return r!==""&&(s+=" "+r),n?s+=" PUBLIC "+L(n,t):o&&(s+=" SYSTEM"),o&&(s+=" "+L(o,t)),s+">"}const tt={}.hasOwnProperty;function nt(e,t){const r=D(e.name),n=ne(e,t),o=e.attributes||{},s=n?!1:t.options.closeEmptyElements,i=[];let l;for(l in o)if(tt.call(o,l)){const c=o[l];c!=null&&i.push(D(l)+"="+L(c,t))}return"<"+r+(i.length===0?"":" "+i.join(" "))+(s?(t.options.tightClose?"":" ")+"/":"")+">"+n+(s?"":"</"+r+">")}const rt=/\?>/g,ot=[">"];function st(e){const t=D(e.name)||"x",r=y(e.value,ot,rt);return"<?"+t+(r?" "+r:"")+"?>"}const it=["&","<"];function ee(e){return y(e.value,it)}function lt(e,t){return t.options.allowDangerousXml?e.value:ee(e)}const ct={}.hasOwnProperty,_={cdata:Ge,comment:Je,doctype:et,element:nt,instruction:st,raw:lt,root:ne,text:ee};function te(e,t){const r=e&&e.type;if(!r)throw new Error("Expected node, not `"+e+"`");if(!ct.call(_,r))throw new Error("Cannot compile unknown node `"+r+"`");const n=_[r];return n(e,t)}function ne(e,t){const r=e&&e.children||[];let n=-1;const o=[];for(;++n<r.length;)o[n]=te(r[n],t);return o.join("")}function at(e,t){const r={options:{}};if(typeof r.options.quote=="string"&&r.options.quote!=='"'&&r.options.quote!=="'")throw new Error("Invalid quote `"+r.options.quote+"`, expected `'` or `\"`");const n=Array.isArray(e)?{type:"root",children:e}:e;return te(n,r)}function ut(e){const t=R.unified().use(j).use(z).use(Q),r=t.parse(e),n=t.runSync(r,{value:e});return at(n.children)}exports.DIRECTIVE_MAP=re;exports.PROOF_SOLUTION_NAMES=F;exports.markdownToPretext=ut;exports.mdastToPtxast=T;exports.remarkMath=Ee;exports.remarkPretext=Q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("unified"),B=require("remark-parse"),z=require("remark-directive"),W=require("unist-util-visit"),q={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}},se=q;function le(e){return q[e.toLowerCase()]}const L=new Set(Object.entries(q).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 C(e){return e.type==="containerDirective"&&e.name==="task"}function ce(e){return e.type==="containerDirective"&&L.has(e.name)}function D(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 ae(e,t,n,o,r,i,s){const l=[];if(n&&l.push(n),e.hasNestedTasks){const c=o.findIndex(C);if(c!==-1){const a=[];for(let p=0;p<o.length;p++)C(o[p])&&a.push(p);const u=a[a.length-1],d=o.slice(0,c),m=o.slice(c).filter(C),v=[],y=[],O=[];for(let p=c;p<o.length;p++){const f=o[p];if(!C(f)){if(p<u){v.push(f);continue}if(ce(f)){O.push(f);continue}y.push(f)}}if(v.length>0&&(r.messages??(r.messages=[])).push({type:"warning",reason:`Dropped ${v.length} non-task node(s) between task directives in ${e.type}.`,category:"dropped-content-between-tasks",position:v[0].position?.start}),d.length>0){const p=D(d.map(f=>i(f,r)).filter(f=>f!==null));p.length>0&&l.push(x("introduction",p))}for(const p of m){const f=s(p,r);f&&l.push(f)}if(y.length>0){const p=D(y.map(f=>i(f,r)).filter(f=>f!==null));p.length>0&&l.push(x("conclusion",p))}for(const p of O){const f=s(p,r);f&&l.push(f)}}else N(l,e,o,r,i,s)}else N(l,e,o,r,i,s);return x(e.type,l,t)}function N(e,t,n,o,r,i){if(t.requiresStatement){const s=[],l=[];for(const c of n)if(c.type==="containerDirective"&&L.has(c.name)){const a=i(c,o);a&&l.push(a)}else s.push(c);if(s.length>0){const c=D(s.map(a=>r(a,o)).filter(a=>a!==null));c.length>0&&e.push(x("statement",c))}e.push(...l)}else{const s=D(n.map(l=>r(l,o)).filter(l=>l!==null));e.push(...s)}}function U(e){return{type:"text",value:e}}function h(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function g(e,t,n){return h(e,[U(t)],n)}function H(e){return{type:"comment",value:e.replace(/--/g,"- -")}}function F(e,t){const n=e?.position,o=n?.start?.offset,r=n?.end?.offset;return t.source&&o!=null&&r!=null?t.source.slice(o,r):""}function Z(e,t,n){return h("TODO",[H(`todo: ${t}`),g("pre",n)],{type:e})}function ue(e,t,n){return h("TODO",[H(`todo: ${t}`),g("c",n)],{type:e})}function V(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 T(e,t){return pe(e,t).tree}function pe(e,t){const n=[],o={ancestors:[],depth:0,messages:n,source:t},r=e.children;return{tree:{type:"root",children:X(r,o)},messages:n}}const P=["chapter","section","subsection","subsubsection","paragraphs"];function fe(e){return P[Math.min(e-1,P.length-1)]}function X(e,t,n=!1){let o=7;for(const a of e)a.type==="heading"&&(o=Math.min(o,a.depth));if(o===7)return w(e,t,n);const r=[];let i=null,s=[],l=[];const c=()=>{i&&(r.push(he(i,l,t)),i=null,l=[])};for(const a of e)a.type==="heading"&&a.depth===o?(!i&&s.length>0&&(r.push(...w(s,t,n)),s=[]),c(),i=a,l=[]):i?l.push(a):s.push(a);return!i&&s.length>0&&r.push(...w(s,t,n)),c(),r}function w(e,t,n=!1){const o=[];for(let r=0;r<e.length;r+=1){const i=e[r],s=E(i,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],a=r+1<e.length?E(e[r+1],t):null,u=a?.name==="p"?a.children:null;if(c?.name==="p")c.children.push(l),u&&(c.children.push(...u),r+=1);else{const d=[l];u&&(d.push(...u),r+=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?V(o):o}function he(e,t,n){const o=fe(e.depth),r=h("title",b(e.children,n)),i=de(e),s=X(t,{...n,depth:n.depth+1},!0),l=V(s);return h(o,[r,...l],i)}function de(e){const t=e.data;return t?.id?{"xml:id":t.id}:void 0}const me={paragraph:(e,t)=>K(e,t),blockquote:(e,t)=>ge(e,t),list:(e,t)=>ye(e,t),code:(e,t)=>ve(e),containerDirective:(e,t)=>Y(e,t)};function E(e,t){const n=me[e.type];return n?n(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),Z("unknown-block-type",`unknown block type "${e.type}"`,F(e,t)))}function K(e,t){return h("p",b(e.children,t))}function ge(e,t){const n=e.children.filter(o=>o.type==="paragraph").map(o=>{const r={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return K(o,r)});return h("blockquote",n)}function ye(e,t){const n=e.children.map(o=>{const r={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return ke(o,r)});return h(e.ordered?"ol":"ul",n)}function ke(e,t){const n=w(e.children,t);return h("li",n)}function ve(e,t){return g("program",e.value,e.lang?{language:e.lang}:void 0)}function xe(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=>g("mrow",o))):g("md",n[0]??"")}function be(e,t){return e.meta==="inline"?g("m",e.value):xe(e)}function Y(e,t){const n=le(e.name);if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),Z("unknown-directive",`unknown directive "${e.name}"`,F(e,t));const o=we(e),r=e.children,{title:i,body:s}=Ce(r,t),l={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return ae(n,o,i,s,l,(c,a)=>E(c,a),(c,a)=>Y(c,a))}function Ce(e,t){const n=e[0];return n?.type==="paragraph"&&n.data?.directiveLabel===!0?{title:h("title",b(n.children,t)),body:e.slice(1)}:{title:null,body:e}}function we(e){const t=e.attributes??{},n={};for(const[o,r]of Object.entries(t))r!=null&&(n[o==="id"?"xml:id":o]=r);return Object.keys(n).length>0?n:void 0}function De(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 Se={text:(e,t)=>U(e.value),emphasis:(e,t)=>{const o=De(e,t.source)==="underscore"?"term":"em";return h(o,b(e.children,t))},strong:(e,t)=>h("alert",b(e.children,t)),inlineCode:(e,t)=>g("c",e.value),math:(e,t)=>be(e)};function b(e,t){return e.flatMap(n=>qe(n,t)).filter(n=>n!==null)}function qe(e,t){const n=Se[e.type];if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),ue("unknown-inline-type",`unknown inline type "${e.type}"`,F(e,t));const o={...t,ancestors:[...t.ancestors,e]};return n(e,o)}const Ie=[{open:"$$",close:"$$",isDisplay:!0},{open:"\\[",close:"\\]",isDisplay:!0},{open:"$",close:"$",isDisplay:!1},{open:"\\(",close:"\\)",isDisplay:!1}],G="PTX_MATH_TOKEN_",I=new RegExp(`${G}(\\d+)`,"g");function J(e,t){let n=null;for(const o of Ie){const r=e.indexOf(o.open,t);if(r===-1)continue;const i=e.indexOf(o.close,r+o.open.length);if(i!==-1&&!(o.open==="$"&&(r>0&&e[r-1]==="$"||r+1<e.length&&e[r+1]==="$"))&&(!n||r<n.index)){const s=e.substring(r+o.open.length,i);n={index:r,pattern:o,content:s}}}return n}function Te(e,t){let n=t;for(;n<e.length;){const o=e.indexOf("`",n);if(o===-1)return null;let r=0,i=o;for(;i<e.length&&e[i]==="`";)r++,i++;const s="`".repeat(r);let l=i;for(;l<e.length;){const c=e.indexOf(s,l);if(c===-1)break;const a=c+r;if(a>=e.length||e[a]!=="`")return{start:o,end:a};l=c+1}n=o+r}return null}function Ee(e){const t=new Map;let n="",o=0,r=0;for(;o<e.length;){const i=Te(e,o),s=J(e,o);if(i&&(!s||i.start<s.index)){n+=e.substring(o,i.end),o=i.end;continue}if(!s){n+=e.substring(o);break}n+=e.substring(o,s.index);const l=`${G}${r}`;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,r+=1}return{markdown:n,tokens:t}}function Me(e){const t=[];let n=0;for(;n<e.length;){const o=J(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;I.lastIndex=0;let r=I.exec(e);for(;r;){const i=r.index,s=r[0];i>o&&n.push({type:"text",value:e.substring(o,i)});const l=t.get(s);l?n.push(l):n.push({type:"text",value:s}),o=i+s.length,r=I.exec(e)}return o<e.length&&n.push({type:"text",value:e.substring(o)}),n.length===0?[{type:"text",value:e}]:n}function Q(e){W.visit(e,"paragraph",t=>{const n=t.children||[],o=[];for(const r of n)if(r.type==="text"){const i=Me(r.value);o.push(...i)}else o.push(r);t.children=o})}function Le(e,t){W.visit(e,"paragraph",n=>{const o=n.children||[],r=[];for(const i of o)if(i.type==="text"){const s=$e(i.value,t);r.push(...s)}else r.push(i);n.children=r})}const Fe=()=>e=>{Q(e)};function Oe(e){const t=e.trim();if(!t.startsWith(":"))return null;let n=0;for(let i=0;i<t.length&&t[i]===":";i++)n++;if(n<3)return null;const o=t.slice(n).trim(),r=o.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);return o===""?{colons:n,label:null,lineIndex:-1,isOpen:!1}:r?{colons:n,label:r[0],lineIndex:-1,isOpen:!0}:null}function Ne(e){const t=[],n=[];for(const o of e)if(o.isOpen){const r={colons:o.colons,finalColons:o.colons,label:o.label,openLineIndex:o.lineIndex,closeLineIndex:null,children:[],parent:null};if(t.length>0){const i=t[t.length-1];r.parent=i,i.children.push(r)}else n.push(r);t.push(r)}else{const r=t[t.length-1];r&&r.colons===o.colons&&(r.closeLineIndex=o.lineIndex,t.pop())}return n}function ee(e){if(e.children.length===0)e.finalColons=e.colons;else{const t=Math.max(...e.children.map(ee));e.finalColons=Math.max(e.colons,t+1)}return e.finalColons}function Pe(e,t,n){const o=e.slice(),r=[],i=t.slice();for(;i.length>0;){const s=i.shift();r.push(s),i.push(...s.children)}for(const s of r){if(s.openLineIndex>=0){const l=o[s.openLineIndex],c=l.match(/^:+/)?.[0].length||3,a=l.slice(c);o[s.openLineIndex]=":".repeat(s.finalColons)+a}s.closeLineIndex!==null&&s.closeLineIndex>=0&&(o[s.closeLineIndex]=":".repeat(s.finalColons))}return o}function Ae(e){const t=e.split(`
2
+ `),n=[];let o=!1,r=null;for(let l=0;l<t.length;l++){const c=t[l],u=c.trim().match(/^(`{3,}|~{3,})/);if(u){const m=u[1];o?r&&m[0]===r[0]&&m.length>=r.length&&(o=!1,r=null):(o=!0,r=m);continue}if(o)continue;const d=Oe(c);d&&n.push({...d,lineIndex:l})}if(n.length===0)return e;const i=Ne(n);for(const l of i)ee(l);return Pe(t,i).join(`
3
+ `)}function _e(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[,r,i]=o;return i&&!/^(\[[^\]]*\]|\{[^}]*\})*$/.test(i)||!q[r.toLowerCase()]?null:n}function M(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 Re(e,t){const n=M(e[t]);for(let o=t+1;o<e.length;o++)if(!te(e[o]))return M(e[o])>n;return!1}function te(e){return e.trim()===""}function je(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 Be(e){const t=e.split(`
4
+ `),n=[],o={level:0,openDirectives:[],inCodeFence:!1,codeFenceMarker:null};for(let r=0;r<t.length;r++){const i=t[r],s=i.trim(),l=M(i),c=s.match(/^(`{3,}|~{3,})/);if(c){const u=c[1];o.inCodeFence?o.codeFenceMarker&&s.startsWith(o.codeFenceMarker)&&(o.inCodeFence=!1,o.codeFenceMarker=null):(o.inCodeFence=!0,o.codeFenceMarker=u),n.push(i);continue}if(o.inCodeFence){n.push(i);continue}if(te(i)){n.push("");continue}const a=_e(s);if(a&&Re(t,r)){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 u=a.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/),d=u?u[1].toLowerCase()+(u[2]||""):a,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 u=o.openDirectives.pop();u&&n.push(":".repeat(u.colonCount))}if(o.openDirectives.length>0){const u=o.openDirectives[o.openDirectives.length-1];u.bodyBaseIndent<0&&(u.bodyBaseIndent=l),n.push(je(i,u.bodyBaseIndent))}else n.push(i);o.level=l}}for(;o.openDirectives.length>0;){const r=o.openDirectives.pop();r&&n.push(":".repeat(r.colonCount))}return n.join(`
5
+ `)}const ne=function(){return function(t,n){if(typeof n?.value=="string"){const o=Be(n.value),r=Ae(o),i=Ee(r),l=j.unified().data("micromarkExtensions",[{disable:{null:["codeIndented"]}}]).use(B).use(z).parse(i.markdown);return Le(l,i.tokens),T(l,i.markdown)}return Q(t),T(t)}},ze=/["&'<>`]/g,We=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,Ue=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,He=/[|\\{}()[\]^$+*?.]/g,A=new WeakMap;function Ze(e,t){if(e=e.replace(t.subset?Ve(t.subset):ze,o),t.subset||t.escapeOnly)return e;return e.replace(We,n).replace(Ue,o);function n(r,i,s){return t.format((r.charCodeAt(0)-55296)*1024+r.charCodeAt(1)-56320+65536,s.charCodeAt(i+2),t)}function o(r,i,s){return t.format(r.charCodeAt(0),s.charCodeAt(i+1),t)}}function Ve(e){let t=A.get(e);return t||(t=Xe(e),A.set(e,t)),t}function Xe(e){const t=[];let n=-1;for(;++n<e.length;)t.push(e[n].replace(He,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function Ke(e){return"&#x"+e.toString(16).toUpperCase()+";"}function Ye(e,t){return Ze(e,Object.assign({format:Ke},t))}const Ge=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function k(e,t,n){const o=Je(e);return n?o.replace(n,r):r(o);function r(i){return Ye(i,{subset:t})}}function Je(e){return String(e||"").replace(Ge,"")}const Qe=/]]>/g,et=[">"];function tt(e){return"<![CDATA["+k(e.value,et,Qe)+"]]>"}function nt(e){return"<!--"+k(e.value,["-"])+"-->"}const ot=[" ",`
6
+ `," ",'"',"&","'","/","<","=",">"];function S(e){return k(e,ot)}function _(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let o=0,r=n.indexOf(t);for(;r!==-1;)o++,r=n.indexOf(t,r+t.length);return o}function $(e,t){const n=String(e);let o=t.options.quote||'"';if(t.options.quoteSmart){const r=o==='"'?"'":'"';_(n,o)>_(n,r)&&(o=r)}return o+k(n,["<","&",o])+o}function rt(e,t){const n=S(e.name),o=e.public,r=e.system;let i="<!DOCTYPE";return n!==""&&(i+=" "+n),o?i+=" PUBLIC "+$(o,t):r&&(i+=" SYSTEM"),r&&(i+=" "+$(r,t)),i+">"}const it={}.hasOwnProperty;function st(e,t){const n=S(e.name),o=ie(e,t),r=e.attributes||{},i=o?!1:t.options.closeEmptyElements,s=[];let l;for(l in r)if(it.call(r,l)){const c=r[l];c!=null&&s.push(S(l)+"="+$(c,t))}return"<"+n+(s.length===0?"":" "+s.join(" "))+(i?(t.options.tightClose?"":" ")+"/":"")+">"+o+(i?"":"</"+n+">")}const lt=/\?>/g,ct=[">"];function at(e){const t=S(e.name)||"x",n=k(e.value,ct,lt);return"<?"+t+(n?" "+n:"")+"?>"}const ut=["&","<"];function oe(e){return k(e.value,ut)}function pt(e,t){return t.options.allowDangerousXml?e.value:oe(e)}const ft={}.hasOwnProperty,R={cdata:tt,comment:nt,doctype:rt,element:st,instruction:at,raw:pt,root:ie,text:oe};function re(e,t){const n=e&&e.type;if(!n)throw new Error("Expected node, not `"+e+"`");if(!ft.call(R,n))throw new Error("Cannot compile unknown node `"+n+"`");const o=R[n];return o(e,t)}function ie(e,t){const n=e&&e.children||[];let o=-1;const r=[];for(;++o<n.length;)r[o]=re(n[o],t);return r.join("")}function ht(e,t){const n={options:{}};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 dt(e){const t=j.unified().use(B).use(z).use(ne),n=t.parse(e),o=t.runSync(n,{value:e});return ht(o.children)}exports.DIRECTIVE_MAP=se;exports.PROOF_SOLUTION_NAMES=L;exports.markdownToPretext=dt;exports.mdastToPtxast=T;exports.remarkMath=Fe;exports.remarkPretext=ne;