@pretextbook/remark-pretext 0.0.3 → 0.0.4

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"),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}},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,n){return{type:"element",name:e,attributes:n??{},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 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,r,o,s,i){const l=[];if(n&&l.push(n),e.hasNestedTasks){const c=r.findIndex(C);if(c!==-1){const a=[];for(let u=0;u<r.length;u++)C(r[u])&&a.push(u);const f=a[a.length-1],d=r.slice(0,c),m=r.slice(c).filter(C),k=[],g=[],N=[];for(let u=c;u<r.length;u++){const p=r[u];if(!C(p)){if(u<f){k.push(p);continue}if(se(p)){N.push(p);continue}g.push(p)}}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 u=S(d.map(p=>s(p,o)).filter(p=>p!==null));u.length>0&&l.push(v("introduction",u))}for(const u of m){const p=i(u,o);p&&l.push(p)}if(g.length>0){const u=S(g.map(p=>s(p,o)).filter(p=>p!==null));u.length>0&&l.push(v("conclusion",u))}for(const u of N){const p=i(u,o);p&&l.push(p)}}else $(l,e,r,o,s,i)}else $(l,e,r,o,s,i);return v(e.type,l,t)}function $(e,t,n,r,o,s){if(t.requiresStatement){const i=[],l=[];for(const c of n)if(c.type==="containerDirective"&&F.has(c.name)){const a=s(c,r);a&&l.push(a)}else i.push(c);if(i.length>0){const c=S(i.map(a=>o(a,r)).filter(a=>a!==null));c.length>0&&e.push(v("statement",c))}e.push(...l)}else{const i=S(n.map(l=>o(l,r)).filter(l=>l!==null));e.push(...i)}}function B(e){return{type:"text",value:e}}function h(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function x(e,t,n){return h(e,[B(t)],n)}function U(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 le(e,t).tree}function le(e,t){const n=[],r={ancestors:[],depth:0,messages:n,source:t},o=e.children;return{tree:{type:"root",children:H(o,r)},messages:n}}const O=["chapter","section","subsection","subsubsection","paragraphs"];function ce(e){return O[Math.min(e-1,O.length-1)]}function H(e,t,n=!1){let r=7;for(const a of e)a.type==="heading"&&(r=Math.min(r,a.depth));if(r===7)return w(e,t,n);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===r?(!s&&i.length>0&&(o.push(...w(i,t,n)),i=[]),c(),s=a,l=[]):s?l.push(a):i.push(a);return!s&&i.length>0&&o.push(...w(i,t,n)),c(),o}function w(e,t,n=!1){const r=[];for(let o=0;o<e.length;o+=1){const s=e[o],i=M(s,t);if(i!==null){if(i.name==="p"&&i.children.length===1&&i.children[0].name==="md"){const l=i.children[0],c=r[r.length-1],a=o+1<e.length?M(e[o+1],t):null,f=a?.name==="p"?a.children:null;if(c?.name==="p")c.children.push(l),f&&(c.children.push(...f),o+=1);else{const d=[l];f&&(d.push(...f),o+=1),r.push(h("p",d))}continue}if((i.name==="ul"||i.name==="ol")&&r.length>0){const l=r[r.length-1];if(l?.name==="p"){l.children.push(i);continue}}r.push(i)}}return n?U(r):r}function ae(e,t,n){const r=ce(e.depth),o=h("title",b(e.children,n)),s=ue(e),i=H(t,{...n,depth:n.depth+1},!0),l=U(i);return h(r,[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 M(e,t){const n=pe[e.type];return n?n(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 n=e.children.filter(r=>r.type==="paragraph").map(r=>{const o={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Z(r,o)});return h("blockquote",n)}function he(e,t){const n=e.children.map(r=>{const o={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return de(r,o)});return h(e.ordered?"ol":"ul",n)}function de(e,t){const n=w(e.children,t);return h("li",n)}function me(e,t){return x("program",e.value,e.lang?{language:e.lang}:void 0)}function ge(e,t){const n=e.value.split(/\\\\|[\r\n]+/).map(r=>r.trim()).filter(r=>r.length>0);return n.length>1?h("md",n.map(r=>x("mrow",r))):x("md",n[0]??"")}function ye(e,t){return e.meta==="inline"?x("m",e.value):ge(e)}function V(e,t){const n=oe(e.name);if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),null;const r=ve(e),o=e.children,{title:s,body:i}=ke(o,t),l={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return ie(n,r,s,i,l,(c,a)=>M(c,a),(c,a)=>V(c,a))}function ke(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 ve(e){const t=e.attributes??{},n={};for(const[r,o]of Object.entries(t))o!=null&&(n[r==="id"?"xml:id":r]=o);return Object.keys(n).length>0?n: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)=>B(e.value),emphasis:(e,t)=>{const r=xe(e,t.source)==="underscore"?"term":"em";return h(r,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(n=>Ce(n,t)).filter(n=>n!==null)}function Ce(e,t){const n=be[e.type];if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),null;const r={...t,ancestors:[...t.ancestors,e]};return n(e,r)}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 n=null;for(const r of we){const o=e.indexOf(r.open,t);if(o===-1)continue;const s=e.indexOf(r.close,o+r.open.length);if(s!==-1&&!(r.open==="$"&&(o>0&&e[o-1]==="$"||o+1<e.length&&e[o+1]==="$"))&&(!n||o<n.index)){const i=e.substring(o+r.open.length,s);n={index:o,pattern:r,content:i}}}return n}function Se(e,t){let n=t;for(;n<e.length;){const r=e.indexOf("`",n);if(r===-1)return null;let o=0,s=r;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:r,end:a};l=c+1}n=r+o}return null}function De(e){const t=new Map;let n="",r=0,o=0;for(;r<e.length;){const s=Se(e,r),i=K(e,r);if(s&&(!i||s.start<i.index)){n+=e.substring(r,s.end),r=s.end;continue}if(!i){n+=e.substring(r);break}n+=e.substring(r,i.index);const l=`${X}${o}`;n+=l,t.set(l,{type:"math",value:i.content,meta:i.pattern.isDisplay?"display":"inline"}),r=i.index+i.pattern.open.length+i.content.length+i.pattern.close.length,o+=1}return{markdown:n,tokens:t}}function qe(e){const t=[];let n=0;for(;n<e.length;){const r=K(e,n);if(!r){n<e.length&&t.push({type:"text",value:e.substring(n)});break}r.index>n&&t.push({type:"text",value:e.substring(n,r.index)}),t.push({type:"math",value:r.content,meta:r.pattern.isDisplay?"display":"inline"}),n=r.index+r.pattern.open.length+r.content.length+r.pattern.close.length}return t.length===0?[{type:"text",value:e}]:t}function Ie(e,t){const n=[];let r=0;I.lastIndex=0;let o=I.exec(e);for(;o;){const s=o.index,i=o[0];s>r&&n.push({type:"text",value:e.substring(r,s)});const l=t.get(i);l?n.push(l):n.push({type:"text",value:i}),r=s+i.length,o=I.exec(e)}return r<e.length&&n.push({type:"text",value:e.substring(r)}),n.length===0?[{type:"text",value:e}]:n}function Y(e){W.visit(e,"paragraph",t=>{const n=t.children||[],r=[];for(const o of n)if(o.type==="text"){const s=qe(o.value);r.push(...s)}else r.push(o);t.children=r})}function Te(e,t){W.visit(e,"paragraph",n=>{const r=n.children||[],o=[];for(const s of r)if(s.type==="text"){const i=Ie(s.value,t);o.push(...i)}else o.push(s);n.children=o})}const Me=()=>e=>{Y(e)};function Ee(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 r=t.slice(n).trim(),o=r.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);return r===""?{colons:n,label:null,lineIndex:-1,isOpen:!1}:o?{colons:n,label:o[0],lineIndex:-1,isOpen:!0}:null}function Le(e){const t=[],n=[];for(const r of e)if(r.isOpen){const o={colons:r.colons,finalColons:r.colons,label:r.label,openLineIndex:r.lineIndex,closeLineIndex:null,children:[],parent:null};if(t.length>0){const s=t[t.length-1];o.parent=s,s.children.push(o)}else n.push(o);t.push(o)}else{const o=t[t.length-1];o&&o.colons===r.colons&&(o.closeLineIndex=r.lineIndex,t.pop())}return n}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,n){const r=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=r[i.openLineIndex],c=l.match(/^:+/)?.[0].length||3,a=l.slice(c);r[i.openLineIndex]=":".repeat(i.finalColons)+a}i.closeLineIndex!==null&&i.closeLineIndex>=0&&(r[i.closeLineIndex]=":".repeat(i.finalColons))}return r}function Ne(e){const t=e.split(`
2
- `),n=[];let r=!1,o=null;for(let l=0;l<t.length;l++){const c=t[l],f=c.trim().match(/^(`{3,}|~{3,})/);if(f){const m=f[1];r?o&&m[0]===o[0]&&m.length>=o.length&&(r=!1,o=null):(r=!0,o=m);continue}if(r)continue;const d=Ee(c);d&&n.push({...d,lineIndex:l})}if(n.length===0)return e;const s=Le(n);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 n=t.slice(0,-1);if(!/^[a-zA-Z]/.test(n))return null;const r=n.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);if(!r)return null;const[,o,s]=r;return s&&!/^(\[[^\]]*\]|\{[^}]*\})*$/.test(s)||!q[o.toLowerCase()]?null:n}function E(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 Oe(e,t){const n=E(e[t]);for(let r=t+1;r<e.length;r++)if(!J(e[r]))return E(e[r])>n;return!1}function J(e){return e.trim()===""}function Pe(e){const t=e.split(`
4
- `),n=[],r={level:0,openDirectives:[],inCodeFence:!1,codeFenceMarker:null};for(let o=0;o<t.length;o++){const s=t[o],i=s.trim(),l=E(s),c=i.match(/^(`{3,}|~{3,})/);if(c){const f=c[1];r.inCodeFence?r.codeFenceMarker&&i.startsWith(r.codeFenceMarker)&&(r.inCodeFence=!1,r.codeFenceMarker=null):(r.inCodeFence=!0,r.codeFenceMarker=f),n.push(s);continue}if(r.inCodeFence){n.push(s);continue}if(J(s)){n.push("");continue}const a=$e(i);if(a&&Oe(t,o)){for(;r.openDirectives.length>0&&!(r.openDirectives[r.openDirectives.length-1].indentLevel<l);){const g=r.openDirectives.pop();g&&n.push(":".repeat(g.colonCount))}const f=a.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/),d=f?f[1].toLowerCase()+(f[2]||""):a,m=r.openDirectives.length*1+3;n.push(":".repeat(m)+d),r.openDirectives.push({label:d,indentLevel:l,colonCount:m}),r.level=l}else{for(;r.openDirectives.length>0&&l<=r.openDirectives[r.openDirectives.length-1].indentLevel;){const f=r.openDirectives.pop();f&&n.push(":".repeat(f.colonCount))}r.openDirectives.length>0,n.push(s),r.level=l}}for(;r.openDirectives.length>0;){const o=r.openDirectives.pop();o&&n.push(":".repeat(o.colonCount))}return n.join(`
5
- `)}const Q=function(){return function(t,n){if(typeof n?.value=="string"){const r=Pe(n.value),o=Ne(r),s=De(o),l=R.unified().use(j).use(z).parse(s.markdown);return Te(l,s.tokens),T(l,s.markdown)}return Y(t),T(t)}},Ae=/["&'<>`]/g,_e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,Re=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,je=/[|\\{}()[\]^$+*?.]/g,P=new WeakMap;function ze(e,t){if(e=e.replace(t.subset?We(t.subset):Ae,r),t.subset||t.escapeOnly)return e;return e.replace(_e,n).replace(Re,r);function n(o,s,i){return t.format((o.charCodeAt(0)-55296)*1024+o.charCodeAt(1)-56320+65536,i.charCodeAt(s+2),t)}function r(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=Be(e),P.set(e,t)),t}function Be(e){const t=[];let n=-1;for(;++n<e.length;)t.push(e[n].replace(je,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function Ue(e){return"&#x"+e.toString(16).toUpperCase()+";"}function He(e,t){return ze(e,Object.assign({format:Ue},t))}const Ze=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function y(e,t,n){const r=Ve(e);return n?r.replace(n,o):o(r);function o(s){return He(s,{subset:t})}}function Ve(e){return String(e||"").replace(Ze,"")}const Xe=/]]>/g,Ke=[">"];function Ye(e){return"<![CDATA["+y(e.value,Ke,Xe)+"]]>"}function Ge(e){return"<!--"+y(e.value,["-"])+"-->"}const Je=[" ",`
6
- `," ",'"',"&","'","/","<","=",">"];function D(e){return y(e,Je)}function A(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let r=0,o=n.indexOf(t);for(;o!==-1;)r++,o=n.indexOf(t,o+t.length);return r}function L(e,t){const n=String(e);let r=t.options.quote||'"';if(t.options.quoteSmart){const o=r==='"'?"'":'"';A(n,r)>A(n,o)&&(r=o)}return r+y(n,["<","&",r])+r}function Qe(e,t){const n=D(e.name),r=e.public,o=e.system;let s="<!DOCTYPE";return n!==""&&(s+=" "+n),r?s+=" PUBLIC "+L(r,t):o&&(s+=" SYSTEM"),o&&(s+=" "+L(o,t)),s+">"}const et={}.hasOwnProperty;function tt(e,t){const n=D(e.name),r=ne(e,t),o=e.attributes||{},s=r?!1:t.options.closeEmptyElements,i=[];let l;for(l in o)if(et.call(o,l)){const c=o[l];c!=null&&i.push(D(l)+"="+L(c,t))}return"<"+n+(i.length===0?"":" "+i.join(" "))+(s?(t.options.tightClose?"":" ")+"/":"")+">"+r+(s?"":"</"+n+">")}const nt=/\?>/g,rt=[">"];function ot(e){const t=D(e.name)||"x",n=y(e.value,rt,nt);return"<?"+t+(n?" "+n:"")+"?>"}const st=["&","<"];function ee(e){return y(e.value,st)}function it(e,t){return t.options.allowDangerousXml?e.value:ee(e)}const lt={}.hasOwnProperty,_={cdata:Ye,comment:Ge,doctype:Qe,element:tt,instruction:ot,raw:it,root:ne,text:ee};function te(e,t){const n=e&&e.type;if(!n)throw new Error("Expected node, not `"+e+"`");if(!lt.call(_,n))throw new Error("Cannot compile unknown node `"+n+"`");const r=_[n];return r(e,t)}function ne(e,t){const n=e&&e.children||[];let r=-1;const o=[];for(;++r<n.length;)o[r]=te(n[r],t);return o.join("")}function ct(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 r=Array.isArray(e)?{type:"root",children:e}:e;return te(r,n)}function at(e){const t=R.unified().use(j).use(z).use(Q),n=t.parse(e),r=t.runSync(n,{value:e});return ct(r.children)}exports.DIRECTIVE_MAP=re;exports.PROOF_SOLUTION_NAMES=F;exports.markdownToPretext=at;exports.mdastToPtxast=T;exports.remarkMath=Me;exports.remarkPretext=Q;
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;
package/dist/index.js CHANGED
@@ -43,189 +43,189 @@ const q = {
43
43
  solution: { type: "solution", category: "solution-like", requiresStatement: !1 },
44
44
  hint: { type: "hint", category: "solution-like", requiresStatement: !1 },
45
45
  answer: { type: "answer", category: "solution-like", requiresStatement: !1 }
46
- }, pt = q;
46
+ }, ft = q;
47
47
  function ne(e) {
48
48
  return q[e.toLowerCase()];
49
49
  }
50
- const W = new Set(
50
+ const B = new Set(
51
51
  Object.entries(q).filter(([e, t]) => t.category === "proof-like" || t.category === "solution-like").map(([e]) => e)
52
52
  );
53
- function v(e, t, n) {
53
+ function v(e, t, o) {
54
54
  return {
55
55
  type: "element",
56
56
  name: e,
57
- attributes: n ?? {},
57
+ attributes: o ?? {},
58
58
  children: t
59
59
  };
60
60
  }
61
61
  function C(e) {
62
62
  return e.type === "containerDirective" && e.name === "task";
63
63
  }
64
- function re(e) {
65
- return e.type === "containerDirective" && W.has(e.name);
64
+ function oe(e) {
65
+ return e.type === "containerDirective" && B.has(e.name);
66
66
  }
67
67
  function D(e) {
68
68
  const t = [];
69
- for (const n of e)
70
- 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);
69
+ for (const o of e)
70
+ o.name === "ul" || o.name === "ol" ? t.length > 0 && t[t.length - 1]?.name === "p" ? t[t.length - 1].children.push(o) : t.push(v("p", [o])) : t.push(o);
71
71
  return t;
72
72
  }
73
- function oe(e, t, n, r, o, s, i) {
73
+ function re(e, t, o, n, r, s, i) {
74
74
  const l = [];
75
- if (n && l.push(n), e.hasNestedTasks) {
76
- const c = r.findIndex(C);
75
+ if (o && l.push(o), e.hasNestedTasks) {
76
+ const c = n.findIndex(C);
77
77
  if (c !== -1) {
78
78
  const a = [];
79
- for (let u = 0; u < r.length; u++)
80
- C(r[u]) && a.push(u);
81
- const f = a[a.length - 1], d = r.slice(0, c), m = r.slice(c).filter(C), k = [], g = [], L = [];
82
- for (let u = c; u < r.length; u++) {
83
- const p = r[u];
84
- if (!C(p)) {
85
- if (u < f) {
86
- k.push(p);
79
+ for (let p = 0; p < n.length; p++)
80
+ C(n[p]) && a.push(p);
81
+ const u = a[a.length - 1], d = n.slice(0, c), m = n.slice(c).filter(C), k = [], g = [], L = [];
82
+ for (let p = c; p < n.length; p++) {
83
+ const f = n[p];
84
+ if (!C(f)) {
85
+ if (p < u) {
86
+ k.push(f);
87
87
  continue;
88
88
  }
89
- if (re(p)) {
90
- L.push(p);
89
+ if (oe(f)) {
90
+ L.push(f);
91
91
  continue;
92
92
  }
93
- g.push(p);
93
+ g.push(f);
94
94
  }
95
95
  }
96
- if (k.length > 0 && (o.messages ?? (o.messages = [])).push({
96
+ if (k.length > 0 && (r.messages ?? (r.messages = [])).push({
97
97
  type: "warning",
98
98
  reason: `Dropped ${k.length} non-task node(s) between task directives in ${e.type}.`,
99
99
  category: "dropped-content-between-tasks",
100
100
  position: k[0].position?.start
101
101
  }), d.length > 0) {
102
- const u = D(
103
- d.map((p) => s(p, o)).filter((p) => p !== null)
102
+ const p = D(
103
+ d.map((f) => s(f, r)).filter((f) => f !== null)
104
104
  );
105
- u.length > 0 && l.push(v("introduction", u));
105
+ p.length > 0 && l.push(v("introduction", p));
106
106
  }
107
- for (const u of m) {
108
- const p = i(u, o);
109
- p && l.push(p);
107
+ for (const p of m) {
108
+ const f = i(p, r);
109
+ f && l.push(f);
110
110
  }
111
111
  if (g.length > 0) {
112
- const u = D(
113
- g.map((p) => s(p, o)).filter((p) => p !== null)
112
+ const p = D(
113
+ g.map((f) => s(f, r)).filter((f) => f !== null)
114
114
  );
115
- u.length > 0 && l.push(v("conclusion", u));
115
+ p.length > 0 && l.push(v("conclusion", p));
116
116
  }
117
- for (const u of L) {
118
- const p = i(u, o);
119
- p && l.push(p);
117
+ for (const p of L) {
118
+ const f = i(p, r);
119
+ f && l.push(f);
120
120
  }
121
121
  } else
122
- F(l, e, r, o, s, i);
122
+ F(l, e, n, r, s, i);
123
123
  } else
124
- F(l, e, r, o, s, i);
124
+ F(l, e, n, r, s, i);
125
125
  return v(e.type, l, t);
126
126
  }
127
- function F(e, t, n, r, o, s) {
127
+ function F(e, t, o, n, r, s) {
128
128
  if (t.requiresStatement) {
129
129
  const i = [], l = [];
130
- for (const c of n)
131
- if (c.type === "containerDirective" && W.has(c.name)) {
132
- const a = s(c, r);
130
+ for (const c of o)
131
+ if (c.type === "containerDirective" && B.has(c.name)) {
132
+ const a = s(c, n);
133
133
  a && l.push(a);
134
134
  } else
135
135
  i.push(c);
136
136
  if (i.length > 0) {
137
137
  const c = D(
138
- i.map((a) => o(a, r)).filter((a) => a !== null)
138
+ i.map((a) => r(a, n)).filter((a) => a !== null)
139
139
  );
140
140
  c.length > 0 && e.push(v("statement", c));
141
141
  }
142
142
  e.push(...l);
143
143
  } else {
144
144
  const i = D(
145
- n.map((l) => o(l, r)).filter((l) => l !== null)
145
+ o.map((l) => r(l, n)).filter((l) => l !== null)
146
146
  );
147
147
  e.push(...i);
148
148
  }
149
149
  }
150
- function B(e) {
150
+ function W(e) {
151
151
  return { type: "text", value: e };
152
152
  }
153
- function h(e, t, n) {
153
+ function h(e, t, o) {
154
154
  return {
155
155
  type: "element",
156
156
  name: e,
157
- attributes: n ?? {},
157
+ attributes: o ?? {},
158
158
  children: t
159
159
  };
160
160
  }
161
- function x(e, t, n) {
162
- return h(e, [B(t)], n);
161
+ function x(e, t, o) {
162
+ return h(e, [W(t)], o);
163
163
  }
164
164
  function H(e) {
165
165
  const t = [];
166
- for (const n of e)
167
- 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);
166
+ for (const o of e)
167
+ o.name === "ul" || o.name === "ol" ? t.length > 0 && t[t.length - 1]?.name === "p" ? t[t.length - 1].children.push(o) : t.push(h("p", [o])) : t.push(o);
168
168
  return t;
169
169
  }
170
170
  function $(e, t) {
171
171
  return se(e, t).tree;
172
172
  }
173
173
  function se(e, t) {
174
- const n = [], r = { ancestors: [], depth: 0, messages: n, source: t }, o = e.children;
174
+ const o = [], n = { ancestors: [], depth: 0, messages: o, source: t }, r = e.children;
175
175
  return {
176
- tree: { type: "root", children: U(o, r) },
177
- messages: n
176
+ tree: { type: "root", children: U(r, n) },
177
+ messages: o
178
178
  };
179
179
  }
180
180
  const N = ["chapter", "section", "subsection", "subsubsection", "paragraphs"];
181
181
  function ie(e) {
182
182
  return N[Math.min(e - 1, N.length - 1)];
183
183
  }
184
- function U(e, t, n = !1) {
185
- let r = 7;
184
+ function U(e, t, o = !1) {
185
+ let n = 7;
186
186
  for (const a of e)
187
- a.type === "heading" && (r = Math.min(r, a.depth));
188
- if (r === 7)
189
- return w(e, t, n);
190
- const o = [];
187
+ a.type === "heading" && (n = Math.min(n, a.depth));
188
+ if (n === 7)
189
+ return w(e, t, o);
190
+ const r = [];
191
191
  let s = null, i = [], l = [];
192
192
  const c = () => {
193
- s && (o.push(le(s, l, t)), s = null, l = []);
193
+ s && (r.push(le(s, l, t)), s = null, l = []);
194
194
  };
195
195
  for (const a of e)
196
- a.type === "heading" && a.depth === r ? (!s && i.length > 0 && (o.push(...w(i, t, n)), i = []), c(), s = a, l = []) : s ? l.push(a) : i.push(a);
197
- return !s && i.length > 0 && o.push(...w(i, t, n)), c(), o;
196
+ a.type === "heading" && a.depth === n ? (!s && i.length > 0 && (r.push(...w(i, t, o)), i = []), c(), s = a, l = []) : s ? l.push(a) : i.push(a);
197
+ return !s && i.length > 0 && r.push(...w(i, t, o)), c(), r;
198
198
  }
199
- function w(e, t, n = !1) {
200
- const r = [];
201
- for (let o = 0; o < e.length; o += 1) {
202
- const s = e[o], i = T(s, t);
199
+ function w(e, t, o = !1) {
200
+ const n = [];
201
+ for (let r = 0; r < e.length; r += 1) {
202
+ const s = e[r], i = T(s, t);
203
203
  if (i !== null) {
204
204
  if (i.name === "p" && i.children.length === 1 && i.children[0].name === "md") {
205
- const l = i.children[0], c = r[r.length - 1], a = o + 1 < e.length ? T(e[o + 1], t) : null, f = a?.name === "p" ? a.children : null;
205
+ const l = i.children[0], c = n[n.length - 1], a = r + 1 < e.length ? T(e[r + 1], t) : null, u = a?.name === "p" ? a.children : null;
206
206
  if (c?.name === "p")
207
- c.children.push(l), f && (c.children.push(...f), o += 1);
207
+ c.children.push(l), u && (c.children.push(...u), r += 1);
208
208
  else {
209
209
  const d = [l];
210
- f && (d.push(...f), o += 1), r.push(h("p", d));
210
+ u && (d.push(...u), r += 1), n.push(h("p", d));
211
211
  }
212
212
  continue;
213
213
  }
214
- if ((i.name === "ul" || i.name === "ol") && r.length > 0) {
215
- const l = r[r.length - 1];
214
+ if ((i.name === "ul" || i.name === "ol") && n.length > 0) {
215
+ const l = n[n.length - 1];
216
216
  if (l?.name === "p") {
217
217
  l.children.push(i);
218
218
  continue;
219
219
  }
220
220
  }
221
- r.push(i);
221
+ n.push(i);
222
222
  }
223
223
  }
224
- return n ? H(r) : r;
224
+ return o ? H(n) : n;
225
225
  }
226
- function le(e, t, n) {
227
- const r = ie(e.depth), o = h("title", b(e.children, n)), s = ce(e), i = U(t, { ...n, depth: n.depth + 1 }, !0), l = H(i);
228
- return h(r, [o, ...l], s);
226
+ function le(e, t, o) {
227
+ const n = ie(e.depth), r = h("title", b(e.children, o)), s = ce(e), i = U(t, { ...o, depth: o.depth + 1 }, !0), l = H(i);
228
+ return h(n, [r, ...l], s);
229
229
  }
230
230
  function ce(e) {
231
231
  const t = e.data;
@@ -239,8 +239,8 @@ const ae = {
239
239
  containerDirective: (e, t) => X(e, t)
240
240
  };
241
241
  function T(e, t) {
242
- const n = ae[e.type];
243
- return n ? n(e, t) : (t.messages && t.messages.push({
242
+ const o = ae[e.type];
243
+ return o ? o(e, t) : (t.messages && t.messages.push({
244
244
  type: "warning",
245
245
  reason: `Unknown block type: ${e.type}`,
246
246
  category: "unknown-block-type"
@@ -250,45 +250,45 @@ function Z(e, t) {
250
250
  return h("p", b(e.children, t));
251
251
  }
252
252
  function ue(e, t) {
253
- const n = e.children.filter((r) => r.type === "paragraph").map((r) => {
254
- const o = { ...t, ancestors: [...t.ancestors, e], depth: t.depth + 1 };
255
- return Z(r, o);
253
+ const o = e.children.filter((n) => n.type === "paragraph").map((n) => {
254
+ const r = { ...t, ancestors: [...t.ancestors, e], depth: t.depth + 1 };
255
+ return Z(n, r);
256
256
  });
257
- return h("blockquote", n);
257
+ return h("blockquote", o);
258
258
  }
259
259
  function pe(e, t) {
260
- const n = e.children.map((r) => {
261
- const o = { ...t, ancestors: [...t.ancestors, e], depth: t.depth + 1 };
262
- return fe(r, o);
260
+ const o = e.children.map((n) => {
261
+ const r = { ...t, ancestors: [...t.ancestors, e], depth: t.depth + 1 };
262
+ return fe(n, r);
263
263
  });
264
- return h(e.ordered ? "ol" : "ul", n);
264
+ return h(e.ordered ? "ol" : "ul", o);
265
265
  }
266
266
  function fe(e, t) {
267
- const n = w(e.children, t);
268
- return h("li", n);
267
+ const o = w(e.children, t);
268
+ return h("li", o);
269
269
  }
270
270
  function he(e, t) {
271
271
  return x("program", e.value, e.lang ? { language: e.lang } : void 0);
272
272
  }
273
273
  function de(e, t) {
274
- const n = e.value.split(/\\\\|[\r\n]+/).map((r) => r.trim()).filter((r) => r.length > 0);
275
- return n.length > 1 ? h("md", n.map((r) => x("mrow", r))) : x("md", n[0] ?? "");
274
+ const o = e.value.split(/\\\\|[\r\n]+/).map((n) => n.trim()).filter((n) => n.length > 0);
275
+ return o.length > 1 ? h("md", o.map((n) => x("mrow", n))) : x("md", o[0] ?? "");
276
276
  }
277
277
  function me(e, t) {
278
278
  return e.meta === "inline" ? x("m", e.value) : de(e);
279
279
  }
280
280
  function X(e, t) {
281
- const n = ne(e.name);
282
- if (!n)
281
+ const o = ne(e.name);
282
+ if (!o)
283
283
  return t.messages && t.messages.push({
284
284
  type: "warning",
285
285
  reason: `Unknown directive: ${e.name}`,
286
286
  category: "unknown-directive"
287
287
  }), null;
288
- const r = ye(e), o = e.children, { title: s, body: i } = ge(o, t), l = { ...t, ancestors: [...t.ancestors, e], depth: t.depth + 1 };
289
- return oe(
288
+ const n = ye(e), r = e.children, { title: s, body: i } = ge(r, t), l = { ...t, ancestors: [...t.ancestors, e], depth: t.depth + 1 };
289
+ return re(
290
+ o,
290
291
  n,
291
- r,
292
292
  s,
293
293
  i,
294
294
  l,
@@ -297,44 +297,44 @@ function X(e, t) {
297
297
  );
298
298
  }
299
299
  function ge(e, t) {
300
- const n = e[0];
301
- return n?.type === "paragraph" && n.data?.directiveLabel === !0 ? {
302
- title: h("title", b(n.children, t)),
300
+ const o = e[0];
301
+ return o?.type === "paragraph" && o.data?.directiveLabel === !0 ? {
302
+ title: h("title", b(o.children, t)),
303
303
  body: e.slice(1)
304
304
  } : { title: null, body: e };
305
305
  }
306
306
  function ye(e) {
307
- const t = e.attributes ?? {}, n = {};
308
- for (const [r, o] of Object.entries(t))
309
- o != null && (n[r === "id" ? "xml:id" : r] = o);
310
- return Object.keys(n).length > 0 ? n : void 0;
307
+ const t = e.attributes ?? {}, o = {};
308
+ for (const [n, r] of Object.entries(t))
309
+ r != null && (o[n === "id" ? "xml:id" : n] = r);
310
+ return Object.keys(o).length > 0 ? o : void 0;
311
311
  }
312
312
  function ke(e, t) {
313
313
  return !t || e.position?.start?.offset === null || e.position?.start?.offset === void 0 ? "asterisk" : t.charAt(e.position.start.offset) === "_" ? "underscore" : "asterisk";
314
314
  }
315
315
  const ve = {
316
- text: (e, t) => B(e.value),
316
+ text: (e, t) => W(e.value),
317
317
  emphasis: (e, t) => {
318
- const r = ke(e, t.source) === "underscore" ? "term" : "em";
319
- return h(r, b(e.children, t));
318
+ const n = ke(e, t.source) === "underscore" ? "term" : "em";
319
+ return h(n, b(e.children, t));
320
320
  },
321
321
  strong: (e, t) => h("alert", b(e.children, t)),
322
322
  inlineCode: (e, t) => x("c", e.value),
323
323
  math: (e, t) => me(e)
324
324
  };
325
325
  function b(e, t) {
326
- return e.flatMap((n) => xe(n, t)).filter((n) => n !== null);
326
+ return e.flatMap((o) => xe(o, t)).filter((o) => o !== null);
327
327
  }
328
328
  function xe(e, t) {
329
- const n = ve[e.type];
330
- if (!n)
329
+ const o = ve[e.type];
330
+ if (!o)
331
331
  return t.messages && t.messages.push({
332
332
  type: "warning",
333
333
  reason: `Unknown inline type: ${e.type}`,
334
334
  category: "unknown-inline-type"
335
335
  }), null;
336
- const r = { ...t, ancestors: [...t.ancestors, e] };
337
- return n(e, r);
336
+ const n = { ...t, ancestors: [...t.ancestors, e] };
337
+ return o(e, n);
338
338
  }
339
339
  const be = [
340
340
  // Display math (check these first, before single $)
@@ -345,157 +345,157 @@ const be = [
345
345
  { open: "\\(", close: "\\)", isDisplay: !1 }
346
346
  ], K = "PTX_MATH_TOKEN_", I = new RegExp(`${K}(\\d+)`, "g");
347
347
  function Y(e, t) {
348
- let n = null;
349
- for (const r of be) {
350
- const o = e.indexOf(r.open, t);
351
- if (o === -1) continue;
352
- const s = e.indexOf(r.close, o + r.open.length);
353
- if (s !== -1 && !(r.open === "$" && (o > 0 && e[o - 1] === "$" || o + 1 < e.length && e[o + 1] === "$")) && (!n || o < n.index)) {
354
- const i = e.substring(o + r.open.length, s);
355
- n = { index: o, pattern: r, content: i };
348
+ let o = null;
349
+ for (const n of be) {
350
+ const r = e.indexOf(n.open, t);
351
+ if (r === -1) continue;
352
+ const s = e.indexOf(n.close, r + n.open.length);
353
+ if (s !== -1 && !(n.open === "$" && (r > 0 && e[r - 1] === "$" || r + 1 < e.length && e[r + 1] === "$")) && (!o || r < o.index)) {
354
+ const i = e.substring(r + n.open.length, s);
355
+ o = { index: r, pattern: n, content: i };
356
356
  }
357
357
  }
358
- return n;
358
+ return o;
359
359
  }
360
360
  function Ce(e, t) {
361
- let n = t;
362
- for (; n < e.length; ) {
363
- const r = e.indexOf("`", n);
364
- if (r === -1) return null;
365
- let o = 0, s = r;
361
+ let o = t;
362
+ for (; o < e.length; ) {
363
+ const n = e.indexOf("`", o);
364
+ if (n === -1) return null;
365
+ let r = 0, s = n;
366
366
  for (; s < e.length && e[s] === "`"; )
367
- o++, s++;
368
- const i = "`".repeat(o);
367
+ r++, s++;
368
+ const i = "`".repeat(r);
369
369
  let l = s;
370
370
  for (; l < e.length; ) {
371
371
  const c = e.indexOf(i, l);
372
372
  if (c === -1) break;
373
- const a = c + o;
373
+ const a = c + r;
374
374
  if (a >= e.length || e[a] !== "`")
375
- return { start: r, end: a };
375
+ return { start: n, end: a };
376
376
  l = c + 1;
377
377
  }
378
- n = r + o;
378
+ o = n + r;
379
379
  }
380
380
  return null;
381
381
  }
382
382
  function we(e) {
383
383
  const t = /* @__PURE__ */ new Map();
384
- let n = "", r = 0, o = 0;
385
- for (; r < e.length; ) {
386
- const s = Ce(e, r), i = Y(e, r);
384
+ let o = "", n = 0, r = 0;
385
+ for (; n < e.length; ) {
386
+ const s = Ce(e, n), i = Y(e, n);
387
387
  if (s && (!i || s.start < i.index)) {
388
- n += e.substring(r, s.end), r = s.end;
388
+ o += e.substring(n, s.end), n = s.end;
389
389
  continue;
390
390
  }
391
391
  if (!i) {
392
- n += e.substring(r);
392
+ o += e.substring(n);
393
393
  break;
394
394
  }
395
- n += e.substring(r, i.index);
396
- const l = `${K}${o}`;
397
- n += l, t.set(l, {
395
+ o += e.substring(n, i.index);
396
+ const l = `${K}${r}`;
397
+ o += l, t.set(l, {
398
398
  type: "math",
399
399
  value: i.content,
400
400
  meta: i.pattern.isDisplay ? "display" : "inline"
401
- }), r = i.index + i.pattern.open.length + i.content.length + i.pattern.close.length, o += 1;
401
+ }), n = i.index + i.pattern.open.length + i.content.length + i.pattern.close.length, r += 1;
402
402
  }
403
- return { markdown: n, tokens: t };
403
+ return { markdown: o, tokens: t };
404
404
  }
405
405
  function De(e) {
406
406
  const t = [];
407
- let n = 0;
408
- for (; n < e.length; ) {
409
- const r = Y(e, n);
410
- if (!r) {
411
- n < e.length && t.push({ type: "text", value: e.substring(n) });
407
+ let o = 0;
408
+ for (; o < e.length; ) {
409
+ const n = Y(e, o);
410
+ if (!n) {
411
+ o < e.length && t.push({ type: "text", value: e.substring(o) });
412
412
  break;
413
413
  }
414
- r.index > n && t.push({
414
+ n.index > o && t.push({
415
415
  type: "text",
416
- value: e.substring(n, r.index)
416
+ value: e.substring(o, n.index)
417
417
  }), t.push({
418
418
  type: "math",
419
- value: r.content,
420
- meta: r.pattern.isDisplay ? "display" : "inline"
421
- }), n = r.index + r.pattern.open.length + r.content.length + r.pattern.close.length;
419
+ value: n.content,
420
+ meta: n.pattern.isDisplay ? "display" : "inline"
421
+ }), o = n.index + n.pattern.open.length + n.content.length + n.pattern.close.length;
422
422
  }
423
423
  return t.length === 0 ? [{ type: "text", value: e }] : t;
424
424
  }
425
425
  function Se(e, t) {
426
- const n = [];
427
- let r = 0;
426
+ const o = [];
427
+ let n = 0;
428
428
  I.lastIndex = 0;
429
- let o = I.exec(e);
430
- for (; o; ) {
431
- const s = o.index, i = o[0];
432
- s > r && n.push({ type: "text", value: e.substring(r, s) });
429
+ let r = I.exec(e);
430
+ for (; r; ) {
431
+ const s = r.index, i = r[0];
432
+ s > n && o.push({ type: "text", value: e.substring(n, s) });
433
433
  const l = t.get(i);
434
- l ? n.push(l) : n.push({ type: "text", value: i }), r = s + i.length, o = I.exec(e);
434
+ l ? o.push(l) : o.push({ type: "text", value: i }), n = s + i.length, r = I.exec(e);
435
435
  }
436
- return r < e.length && n.push({ type: "text", value: e.substring(r) }), n.length === 0 ? [{ type: "text", value: e }] : n;
436
+ return n < e.length && o.push({ type: "text", value: e.substring(n) }), o.length === 0 ? [{ type: "text", value: e }] : o;
437
437
  }
438
438
  function V(e) {
439
439
  z(e, "paragraph", (t) => {
440
- const n = t.children || [], r = [];
441
- for (const o of n)
442
- if (o.type === "text") {
443
- const s = De(o.value);
444
- r.push(...s);
440
+ const o = t.children || [], n = [];
441
+ for (const r of o)
442
+ if (r.type === "text") {
443
+ const s = De(r.value);
444
+ n.push(...s);
445
445
  } else
446
- r.push(o);
447
- t.children = r;
446
+ n.push(r);
447
+ t.children = n;
448
448
  });
449
449
  }
450
450
  function qe(e, t) {
451
- z(e, "paragraph", (n) => {
452
- const r = n.children || [], o = [];
453
- for (const s of r)
451
+ z(e, "paragraph", (o) => {
452
+ const n = o.children || [], r = [];
453
+ for (const s of n)
454
454
  if (s.type === "text") {
455
455
  const i = Se(s.value, t);
456
- o.push(...i);
456
+ r.push(...i);
457
457
  } else
458
- o.push(s);
459
- n.children = o;
458
+ r.push(s);
459
+ o.children = r;
460
460
  });
461
461
  }
462
- const ft = () => (e) => {
462
+ const ht = () => (e) => {
463
463
  V(e);
464
464
  };
465
465
  function Ie(e) {
466
466
  const t = e.trim();
467
467
  if (!t.startsWith(":")) return null;
468
- let n = 0;
468
+ let o = 0;
469
469
  for (let s = 0; s < t.length && t[s] === ":"; s++)
470
- n++;
471
- if (n < 3) return null;
472
- const r = t.slice(n).trim(), o = r.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);
473
- return r === "" ? { colons: n, label: null, lineIndex: -1, isOpen: !1 } : o ? { colons: n, label: o[0], lineIndex: -1, isOpen: !0 } : null;
470
+ o++;
471
+ if (o < 3) return null;
472
+ const n = t.slice(o).trim(), r = n.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);
473
+ return n === "" ? { colons: o, label: null, lineIndex: -1, isOpen: !1 } : r ? { colons: o, label: r[0], lineIndex: -1, isOpen: !0 } : null;
474
474
  }
475
475
  function Te(e) {
476
- const t = [], n = [];
477
- for (const r of e)
478
- if (r.isOpen) {
479
- const o = {
480
- colons: r.colons,
481
- finalColons: r.colons,
482
- label: r.label,
483
- openLineIndex: r.lineIndex,
476
+ const t = [], o = [];
477
+ for (const n of e)
478
+ if (n.isOpen) {
479
+ const r = {
480
+ colons: n.colons,
481
+ finalColons: n.colons,
482
+ label: n.label,
483
+ openLineIndex: n.lineIndex,
484
484
  closeLineIndex: null,
485
485
  children: [],
486
486
  parent: null
487
487
  };
488
488
  if (t.length > 0) {
489
489
  const s = t[t.length - 1];
490
- o.parent = s, s.children.push(o);
490
+ r.parent = s, s.children.push(r);
491
491
  } else
492
- n.push(o);
493
- t.push(o);
492
+ o.push(r);
493
+ t.push(r);
494
494
  } else {
495
- const o = t[t.length - 1];
496
- o && o.colons === r.colons && (o.closeLineIndex = r.lineIndex, t.pop());
495
+ const r = t[t.length - 1];
496
+ r && r.colons === n.colons && (r.closeLineIndex = n.lineIndex, t.pop());
497
497
  }
498
- return n;
498
+ return o;
499
499
  }
500
500
  function G(e) {
501
501
  if (e.children.length === 0)
@@ -506,40 +506,40 @@ function G(e) {
506
506
  }
507
507
  return e.finalColons;
508
508
  }
509
- function Ee(e, t, n) {
510
- const r = e.slice(), o = [], s = t.slice();
509
+ function Ee(e, t, o) {
510
+ const n = e.slice(), r = [], s = t.slice();
511
511
  for (; s.length > 0; ) {
512
512
  const i = s.shift();
513
- o.push(i), s.push(...i.children);
513
+ r.push(i), s.push(...i.children);
514
514
  }
515
- for (const i of o) {
515
+ for (const i of r) {
516
516
  if (i.openLineIndex >= 0) {
517
- const l = r[i.openLineIndex], c = l.match(/^:+/)?.[0].length || 3, a = l.slice(c);
518
- r[i.openLineIndex] = ":".repeat(i.finalColons) + a;
517
+ const l = n[i.openLineIndex], c = l.match(/^:+/)?.[0].length || 3, a = l.slice(c);
518
+ n[i.openLineIndex] = ":".repeat(i.finalColons) + a;
519
519
  }
520
- i.closeLineIndex !== null && i.closeLineIndex >= 0 && (r[i.closeLineIndex] = ":".repeat(i.finalColons));
520
+ i.closeLineIndex !== null && i.closeLineIndex >= 0 && (n[i.closeLineIndex] = ":".repeat(i.finalColons));
521
521
  }
522
- return r;
522
+ return n;
523
523
  }
524
524
  function Me(e) {
525
525
  const t = e.split(`
526
- `), n = [];
527
- let r = !1, o = null;
526
+ `), o = [];
527
+ let n = !1, r = null;
528
528
  for (let l = 0; l < t.length; l++) {
529
- const c = t[l], f = c.trim().match(/^(`{3,}|~{3,})/);
530
- if (f) {
531
- const m = f[1];
532
- r ? o && m[0] === o[0] && m.length >= o.length && (r = !1, o = null) : (r = !0, o = m);
529
+ const c = t[l], u = c.trim().match(/^(`{3,}|~{3,})/);
530
+ if (u) {
531
+ const m = u[1];
532
+ n ? r && m[0] === r[0] && m.length >= r.length && (n = !1, r = null) : (n = !0, r = m);
533
533
  continue;
534
534
  }
535
- if (r)
535
+ if (n)
536
536
  continue;
537
537
  const d = Ie(c);
538
- d && n.push({ ...d, lineIndex: l });
538
+ d && o.push({ ...d, lineIndex: l });
539
539
  }
540
- if (n.length === 0)
540
+ if (o.length === 0)
541
541
  return e;
542
- const s = Te(n);
542
+ const s = Te(o);
543
543
  for (const l of s)
544
544
  G(l);
545
545
  return Ee(t, s).join(`
@@ -548,249 +548,266 @@ function Me(e) {
548
548
  function Le(e) {
549
549
  const t = e.trim();
550
550
  if (!t.endsWith(":")) return null;
551
- const n = t.slice(0, -1);
552
- if (!/^[a-zA-Z]/.test(n)) return null;
553
- const r = n.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);
554
- if (!r) return null;
555
- const [, o, s] = r;
556
- return s && !/^(\[[^\]]*\]|\{[^}]*\})*$/.test(s) || !q[o.toLowerCase()] ? null : n;
551
+ const o = t.slice(0, -1);
552
+ if (!/^[a-zA-Z]/.test(o)) return null;
553
+ const n = o.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);
554
+ if (!n) return null;
555
+ const [, r, s] = n;
556
+ return s && !/^(\[[^\]]*\]|\{[^}]*\})*$/.test(s) || !q[r.toLowerCase()] ? null : o;
557
557
  }
558
558
  function E(e) {
559
559
  let t = 0;
560
- for (let n = 0; n < e.length; n++)
561
- if (e[n] === " ")
560
+ for (let o = 0; o < e.length; o++)
561
+ if (e[o] === " ")
562
562
  t += 1;
563
- else if (e[n] === " ")
563
+ else if (e[o] === " ")
564
564
  t += 4;
565
565
  else
566
566
  break;
567
567
  return t;
568
568
  }
569
569
  function Fe(e, t) {
570
- const n = E(e[t]);
571
- for (let r = t + 1; r < e.length; r++)
572
- if (!J(e[r]))
573
- return E(e[r]) > n;
570
+ const o = E(e[t]);
571
+ for (let n = t + 1; n < e.length; n++)
572
+ if (!J(e[n]))
573
+ return E(e[n]) > o;
574
574
  return !1;
575
575
  }
576
576
  function J(e) {
577
577
  return e.trim() === "";
578
578
  }
579
- function $e(e) {
579
+ function $e(e, t) {
580
+ let o = 0, n = 0;
581
+ for (; n < e.length && o < t; )
582
+ if (e[n] === " ")
583
+ o++, n++;
584
+ else if (e[n] === " ")
585
+ o += 4, n++;
586
+ else
587
+ break;
588
+ return e.slice(n);
589
+ }
590
+ function Ne(e) {
580
591
  const t = e.split(`
581
- `), n = [], r = {
592
+ `), o = [], n = {
582
593
  level: 0,
583
594
  openDirectives: [],
584
595
  inCodeFence: !1,
585
596
  codeFenceMarker: null
586
597
  };
587
- for (let o = 0; o < t.length; o++) {
588
- const s = t[o], i = s.trim(), l = E(s), c = i.match(/^(`{3,}|~{3,})/);
598
+ for (let r = 0; r < t.length; r++) {
599
+ const s = t[r], i = s.trim(), l = E(s), c = i.match(/^(`{3,}|~{3,})/);
589
600
  if (c) {
590
- const f = c[1];
591
- r.inCodeFence ? r.codeFenceMarker && i.startsWith(r.codeFenceMarker) && (r.inCodeFence = !1, r.codeFenceMarker = null) : (r.inCodeFence = !0, r.codeFenceMarker = f), n.push(s);
601
+ const u = c[1];
602
+ n.inCodeFence ? n.codeFenceMarker && i.startsWith(n.codeFenceMarker) && (n.inCodeFence = !1, n.codeFenceMarker = null) : (n.inCodeFence = !0, n.codeFenceMarker = u), o.push(s);
592
603
  continue;
593
604
  }
594
- if (r.inCodeFence) {
595
- n.push(s);
605
+ if (n.inCodeFence) {
606
+ o.push(s);
596
607
  continue;
597
608
  }
598
609
  if (J(s)) {
599
- n.push("");
610
+ o.push("");
600
611
  continue;
601
612
  }
602
613
  const a = Le(i);
603
- if (a && Fe(t, o)) {
604
- for (; r.openDirectives.length > 0 && !(r.openDirectives[r.openDirectives.length - 1].indentLevel < l); ) {
605
- const g = r.openDirectives.pop();
606
- g && n.push(":".repeat(g.colonCount));
614
+ if (a && Fe(t, r)) {
615
+ for (; n.openDirectives.length > 0 && !(n.openDirectives[n.openDirectives.length - 1].indentLevel < l); ) {
616
+ const g = n.openDirectives.pop();
617
+ g && o.push(":".repeat(g.colonCount));
607
618
  }
608
- const f = a.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/), d = f ? f[1].toLowerCase() + (f[2] || "") : a, m = r.openDirectives.length * 1 + 3;
609
- n.push(":".repeat(m) + d), r.openDirectives.push({
619
+ 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;
620
+ o.push(":".repeat(m) + d), n.openDirectives.push({
610
621
  label: d,
611
622
  indentLevel: l,
612
- colonCount: m
613
- }), r.level = l;
623
+ colonCount: m,
624
+ bodyBaseIndent: -1
625
+ }), n.level = l;
614
626
  } else {
615
- for (; r.openDirectives.length > 0 && l <= r.openDirectives[r.openDirectives.length - 1].indentLevel; ) {
616
- const f = r.openDirectives.pop();
617
- f && n.push(":".repeat(f.colonCount));
627
+ for (; n.openDirectives.length > 0 && l <= n.openDirectives[n.openDirectives.length - 1].indentLevel; ) {
628
+ const u = n.openDirectives.pop();
629
+ u && o.push(":".repeat(u.colonCount));
618
630
  }
619
- r.openDirectives.length > 0, n.push(s), r.level = l;
631
+ if (n.openDirectives.length > 0) {
632
+ const u = n.openDirectives[n.openDirectives.length - 1];
633
+ u.bodyBaseIndent < 0 && (u.bodyBaseIndent = l), o.push($e(s, u.bodyBaseIndent));
634
+ } else
635
+ o.push(s);
636
+ n.level = l;
620
637
  }
621
638
  }
622
- for (; r.openDirectives.length > 0; ) {
623
- const o = r.openDirectives.pop();
624
- o && n.push(":".repeat(o.colonCount));
639
+ for (; n.openDirectives.length > 0; ) {
640
+ const r = n.openDirectives.pop();
641
+ r && o.push(":".repeat(r.colonCount));
625
642
  }
626
- return n.join(`
643
+ return o.join(`
627
644
  `);
628
645
  }
629
- const Ne = function() {
630
- return function(t, n) {
631
- if (typeof n?.value == "string") {
632
- const r = $e(n.value), o = Me(r), s = we(o), l = _().use(R).use(j).parse(s.markdown);
646
+ const Ae = function() {
647
+ return function(t, o) {
648
+ if (typeof o?.value == "string") {
649
+ const n = Ne(o.value), r = Me(n), s = we(r), l = _().data("micromarkExtensions", [{ disable: { null: ["codeIndented"] } }]).use(R).use(j).parse(s.markdown);
633
650
  return qe(l, s.tokens), $(l, s.markdown);
634
651
  }
635
652
  return V(t), $(t);
636
653
  };
637
- }, Ae = /["&'<>`]/g, Oe = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, Pe = (
654
+ }, Oe = /["&'<>`]/g, Pe = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, _e = (
638
655
  // eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
639
656
  /[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g
640
- ), _e = /[|\\{}()[\]^$+*?.]/g, A = /* @__PURE__ */ new WeakMap();
641
- function Re(e, t) {
657
+ ), Re = /[|\\{}()[\]^$+*?.]/g, A = /* @__PURE__ */ new WeakMap();
658
+ function je(e, t) {
642
659
  if (e = e.replace(
643
- t.subset ? je(t.subset) : Ae,
644
- r
660
+ t.subset ? ze(t.subset) : Oe,
661
+ n
645
662
  ), t.subset || t.escapeOnly)
646
663
  return e;
647
- return e.replace(Oe, n).replace(Pe, r);
648
- function n(o, s, i) {
664
+ return e.replace(Pe, o).replace(_e, n);
665
+ function o(r, s, i) {
649
666
  return t.format(
650
- (o.charCodeAt(0) - 55296) * 1024 + o.charCodeAt(1) - 56320 + 65536,
667
+ (r.charCodeAt(0) - 55296) * 1024 + r.charCodeAt(1) - 56320 + 65536,
651
668
  i.charCodeAt(s + 2),
652
669
  t
653
670
  );
654
671
  }
655
- function r(o, s, i) {
672
+ function n(r, s, i) {
656
673
  return t.format(
657
- o.charCodeAt(0),
674
+ r.charCodeAt(0),
658
675
  i.charCodeAt(s + 1),
659
676
  t
660
677
  );
661
678
  }
662
679
  }
663
- function je(e) {
680
+ function ze(e) {
664
681
  let t = A.get(e);
665
- return t || (t = ze(e), A.set(e, t)), t;
682
+ return t || (t = Be(e), A.set(e, t)), t;
666
683
  }
667
- function ze(e) {
684
+ function Be(e) {
668
685
  const t = [];
669
- let n = -1;
670
- for (; ++n < e.length; )
671
- t.push(e[n].replace(_e, "\\$&"));
686
+ let o = -1;
687
+ for (; ++o < e.length; )
688
+ t.push(e[o].replace(Re, "\\$&"));
672
689
  return new RegExp("(?:" + t.join("|") + ")", "g");
673
690
  }
674
691
  function We(e) {
675
692
  return "&#x" + e.toString(16).toUpperCase() + ";";
676
693
  }
677
- function Be(e, t) {
678
- return Re(e, Object.assign({ format: We }, t));
694
+ function He(e, t) {
695
+ return je(e, Object.assign({ format: We }, t));
679
696
  }
680
- const He = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
681
- function y(e, t, n) {
682
- const r = Ue(e);
683
- return n ? r.replace(n, o) : o(r);
684
- function o(s) {
685
- return Be(s, { subset: t });
697
+ const Ue = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
698
+ function y(e, t, o) {
699
+ const n = Ze(e);
700
+ return o ? n.replace(o, r) : r(n);
701
+ function r(s) {
702
+ return He(s, { subset: t });
686
703
  }
687
704
  }
688
- function Ue(e) {
689
- return String(e || "").replace(He, "");
690
- }
691
- const Ze = /]]>/g, Xe = [">"];
692
- function Ke(e) {
693
- return "<![CDATA[" + y(e.value, Xe, Ze) + "]]>";
705
+ function Ze(e) {
706
+ return String(e || "").replace(Ue, "");
694
707
  }
708
+ const Xe = /]]>/g, Ke = [">"];
695
709
  function Ye(e) {
710
+ return "<![CDATA[" + y(e.value, Ke, Xe) + "]]>";
711
+ }
712
+ function Ve(e) {
696
713
  return "<!--" + y(e.value, ["-"]) + "-->";
697
714
  }
698
- const Ve = [" ", `
715
+ const Ge = [" ", `
699
716
  `, " ", '"', "&", "'", "/", "<", "=", ">"];
700
717
  function S(e) {
701
- return y(e, Ve);
718
+ return y(e, Ge);
702
719
  }
703
720
  function O(e, t) {
704
- const n = String(e);
721
+ const o = String(e);
705
722
  if (typeof t != "string")
706
723
  throw new TypeError("Expected character");
707
- let r = 0, o = n.indexOf(t);
708
- for (; o !== -1; )
709
- r++, o = n.indexOf(t, o + t.length);
710
- return r;
724
+ let n = 0, r = o.indexOf(t);
725
+ for (; r !== -1; )
726
+ n++, r = o.indexOf(t, r + t.length);
727
+ return n;
711
728
  }
712
729
  function M(e, t) {
713
- const n = String(e);
714
- let r = t.options.quote || '"';
730
+ const o = String(e);
731
+ let n = t.options.quote || '"';
715
732
  if (t.options.quoteSmart) {
716
- const o = r === '"' ? "'" : '"';
717
- O(n, r) > O(n, o) && (r = o);
733
+ const r = n === '"' ? "'" : '"';
734
+ O(o, n) > O(o, r) && (n = r);
718
735
  }
719
- return r + y(n, ["<", "&", r]) + r;
736
+ return n + y(o, ["<", "&", n]) + n;
720
737
  }
721
- function Ge(e, t) {
722
- const n = S(e.name), r = e.public, o = e.system;
738
+ function Je(e, t) {
739
+ const o = S(e.name), n = e.public, r = e.system;
723
740
  let s = "<!DOCTYPE";
724
- return n !== "" && (s += " " + n), r ? s += " PUBLIC " + M(r, t) : o && (s += " SYSTEM"), o && (s += " " + M(o, t)), s + ">";
741
+ return o !== "" && (s += " " + o), n ? s += " PUBLIC " + M(n, t) : r && (s += " SYSTEM"), r && (s += " " + M(r, t)), s + ">";
725
742
  }
726
- const Je = {}.hasOwnProperty;
727
- function Qe(e, t) {
728
- const n = S(e.name), r = te(e, t), o = e.attributes || {}, s = r ? !1 : t.options.closeEmptyElements, i = [];
743
+ const Qe = {}.hasOwnProperty;
744
+ function et(e, t) {
745
+ const o = S(e.name), n = te(e, t), r = e.attributes || {}, s = n ? !1 : t.options.closeEmptyElements, i = [];
729
746
  let l;
730
- for (l in o)
731
- if (Je.call(o, l)) {
732
- const c = o[l];
747
+ for (l in r)
748
+ if (Qe.call(r, l)) {
749
+ const c = r[l];
733
750
  c != null && i.push(S(l) + "=" + M(c, t));
734
751
  }
735
- return "<" + n + (i.length === 0 ? "" : " " + i.join(" ")) + (s ? (t.options.tightClose ? "" : " ") + "/" : "") + ">" + r + (s ? "" : "</" + n + ">");
752
+ return "<" + o + (i.length === 0 ? "" : " " + i.join(" ")) + (s ? (t.options.tightClose ? "" : " ") + "/" : "") + ">" + n + (s ? "" : "</" + o + ">");
736
753
  }
737
- const et = /\?>/g, tt = [">"];
738
- function nt(e) {
739
- const t = S(e.name) || "x", n = y(e.value, tt, et);
740
- return "<?" + t + (n ? " " + n : "") + "?>";
754
+ const tt = /\?>/g, nt = [">"];
755
+ function ot(e) {
756
+ const t = S(e.name) || "x", o = y(e.value, nt, tt);
757
+ return "<?" + t + (o ? " " + o : "") + "?>";
741
758
  }
742
759
  const rt = ["&", "<"];
743
760
  function Q(e) {
744
761
  return y(e.value, rt);
745
762
  }
746
- function ot(e, t) {
763
+ function st(e, t) {
747
764
  return t.options.allowDangerousXml ? e.value : Q(e);
748
765
  }
749
- const st = {}.hasOwnProperty, P = {
750
- cdata: Ke,
751
- comment: Ye,
752
- doctype: Ge,
753
- element: Qe,
754
- instruction: nt,
755
- raw: ot,
766
+ const it = {}.hasOwnProperty, P = {
767
+ cdata: Ye,
768
+ comment: Ve,
769
+ doctype: Je,
770
+ element: et,
771
+ instruction: ot,
772
+ raw: st,
756
773
  root: te,
757
774
  text: Q
758
775
  };
759
776
  function ee(e, t) {
760
- const n = e && e.type;
761
- if (!n)
777
+ const o = e && e.type;
778
+ if (!o)
762
779
  throw new Error("Expected node, not `" + e + "`");
763
- if (!st.call(P, n))
764
- throw new Error("Cannot compile unknown node `" + n + "`");
765
- const r = P[n];
766
- return r(e, t);
780
+ if (!it.call(P, o))
781
+ throw new Error("Cannot compile unknown node `" + o + "`");
782
+ const n = P[o];
783
+ return n(e, t);
767
784
  }
768
785
  function te(e, t) {
769
- const n = e && e.children || [];
770
- let r = -1;
771
- const o = [];
772
- for (; ++r < n.length; )
773
- o[r] = ee(n[r], t);
774
- return o.join("");
786
+ const o = e && e.children || [];
787
+ let n = -1;
788
+ const r = [];
789
+ for (; ++n < o.length; )
790
+ r[n] = ee(o[n], t);
791
+ return r.join("");
775
792
  }
776
- function it(e, t) {
777
- const n = { options: {} };
778
- if (typeof n.options.quote == "string" && n.options.quote !== '"' && n.options.quote !== "'")
793
+ function lt(e, t) {
794
+ const o = { options: {} };
795
+ if (typeof o.options.quote == "string" && o.options.quote !== '"' && o.options.quote !== "'")
779
796
  throw new Error(
780
- "Invalid quote `" + n.options.quote + "`, expected `'` or `\"`"
797
+ "Invalid quote `" + o.options.quote + "`, expected `'` or `\"`"
781
798
  );
782
- const r = Array.isArray(e) ? { type: "root", children: e } : e;
783
- return ee(r, n);
799
+ const n = Array.isArray(e) ? { type: "root", children: e } : e;
800
+ return ee(n, o);
784
801
  }
785
- function ht(e) {
786
- const t = _().use(R).use(j).use(Ne), n = t.parse(e), r = t.runSync(n, { value: e });
787
- return it(r.children);
802
+ function dt(e) {
803
+ const t = _().use(R).use(j).use(Ae), o = t.parse(e), n = t.runSync(o, { value: e });
804
+ return lt(n.children);
788
805
  }
789
806
  export {
790
- pt as DIRECTIVE_MAP,
791
- W as PROOF_SOLUTION_NAMES,
792
- ht as markdownToPretext,
807
+ ft as DIRECTIVE_MAP,
808
+ B as PROOF_SOLUTION_NAMES,
809
+ dt as markdownToPretext,
793
810
  $ as mdastToPtxast,
794
- ft as remarkMath,
795
- Ne as remarkPretext
811
+ ht as remarkMath,
812
+ Ae as remarkPretext
796
813
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretextbook/remark-pretext",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "remark plugin to transform markdown-style PreTeXt directives into ptxast",
5
5
  "author": "Oscar Levin",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "test": "vitest run"
40
40
  },
41
41
  "dependencies": {
42
- "@pretextbook/ptxast": "^0.0.3",
42
+ "@pretextbook/ptxast": "^0.0.4",
43
43
  "@types/mdast": "^4.0.0",
44
44
  "mdast-util-directive": "^3.0.0",
45
45
  "remark-directive": "^4.0.0",