@pretextbook/remark-pretext 0.0.8 → 0.0.9

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 W=require("unified"),H=require("remark-parse"),V=require("remark-directive"),g=require("@pretextbook/ptxast"),X=require("unist-util-visit");function le(e,t={}){const n={};for(const[o,r]of Object.entries(t))r!=null&&(n[o]=r);return{type:"element",name:`plus:${e}`,attributes:n,children:[]}}function ce(e){const t=e.name?.trim();return t?le(t,e.attributes??{}):null}const E={theorem:{type:"theorem",category:"theorem-like",requiresStatement:!0},lemma:{type:"lemma",category:"theorem-like",requiresStatement:!0},corollary:{type:"corollary",category:"theorem-like",requiresStatement:!0},proposition:{type:"proposition",category:"theorem-like",requiresStatement:!0},claim:{type:"claim",category:"theorem-like",requiresStatement:!0},fact:{type:"fact",category:"theorem-like",requiresStatement:!0},conjecture:{type:"conjecture",category:"theorem-like",requiresStatement:!0},axiom:{type:"axiom",category:"theorem-like",requiresStatement:!0},principle:{type:"principle",category:"theorem-like",requiresStatement:!0},hypothesis:{type:"hypothesis",category:"theorem-like",requiresStatement:!0},algorithm:{type:"algorithm",category:"theorem-like",requiresStatement:!0},definition:{type:"definition",category:"definition-like",requiresStatement:!0},notation:{type:"notation",category:"definition-like",requiresStatement:!0},remark:{type:"remark",category:"remark-like",requiresStatement:!1},note:{type:"note",category:"remark-like",requiresStatement:!1},observation:{type:"observation",category:"remark-like",requiresStatement:!1},warning:{type:"warning",category:"remark-like",requiresStatement:!1},insight:{type:"insight",category:"remark-like",requiresStatement:!1},assemblage:{type:"assemblage",category:"remark-like",requiresStatement:!1},example:{type:"example",category:"example-like",requiresStatement:!1},question:{type:"question",category:"example-like",requiresStatement:!1},problem:{type:"problem",category:"example-like",requiresStatement:!1},exercise:{type:"exercise",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},activity:{type:"activity",category:"example-like",requiresStatement:!1},exploration:{type:"exploration",category:"example-like",requiresStatement:!1},investigation:{type:"investigation",category:"example-like",requiresStatement:!1},project:{type:"project",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},task:{type:"task",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},proof:{type:"proof",category:"proof-like",requiresStatement:!1},case:{type:"case",category:"proof-like",requiresStatement:!1},solution:{type:"solution",category:"solution-like",requiresStatement:!1},hint:{type:"hint",category:"solution-like",requiresStatement:!1},answer:{type:"answer",category:"solution-like",requiresStatement:!1}},ae=E;function ue(e){return E[e.toLowerCase()]}const O=new Set(Object.entries(E).filter(([e,t])=>t.category==="proof-like"||t.category==="solution-like").map(([e])=>e));function D(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function C(e){return e.type==="containerDirective"&&e.name==="task"}function pe(e){return e.type==="containerDirective"&&O.has(e.name)}function I(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(D("p",[n])):t.push(n);return t}function fe(e,t,n,o,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),b=[],v=[],P=[];for(let p=c;p<o.length;p++){const f=o[p];if(!C(f)){if(p<u){b.push(f);continue}if(pe(f)){P.push(f);continue}v.push(f)}}if(b.length>0&&(r.messages??(r.messages=[])).push({type:"warning",reason:`Dropped ${b.length} non-task node(s) between task directives in ${e.type}.`,category:"dropped-content-between-tasks",position:b[0].position?.start}),d.length>0){const p=I(d.map(f=>i(f,r)).filter(f=>f!==null));p.length>0&&l.push(D("introduction",p))}for(const p of m){const f=s(p,r);f&&l.push(f)}if(v.length>0){const p=I(v.map(f=>i(f,r)).filter(f=>f!==null));p.length>0&&l.push(D("conclusion",p))}for(const p of P){const f=s(p,r);f&&l.push(f)}}else j(l,e,o,r,i,s)}else j(l,e,o,r,i,s);return D(e.type,l,t)}function j(e,t,n,o,r,i){if(t.requiresStatement){const s=[],l=[];for(const c of n)if(c.type==="containerDirective"&&O.has(c.name)){const a=i(c,o);a&&l.push(a)}else s.push(c);if(s.length>0){const c=I(s.map(a=>r(a,o)).filter(a=>a!==null));c.length>0&&e.push(D("statement",c))}e.push(...l)}else{const s=I(n.map(l=>r(l,o)).filter(l=>l!==null));e.push(...s)}}function Z(e){return{type:"text",value:e}}function h(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function y(e,t,n){return h(e,[Z(t)],n)}function K(e){return{type:"comment",value:e.replace(/--/g,"- -")}}function T(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 N(e,t,n){return h("TODO",[K(`todo: ${t}`),y("pre",n)],{type:e})}function he(e,t,n){return h("TODO",[K(`todo: ${t}`),y("c",n)],{type:e})}function _(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(h("p",[n])):t.push(n);return t}function A(e,t,n){return de(e,t,n).tree}function de(e,t,n){const o=[],r={ancestors:[],depth:0,messages:o,source:t,topLevelDivision:n?.topLevelDivision??"chapter",documentRoot:n?.documentRoot,topLevelAttributes:n?.topLevelAttributes,topLevelAttributesApplied:n?.topLevelAttributes?{done:!1}:void 0},i=e.children;if(r.documentRoot){const l=M(r),c=w(i,r);return{tree:{type:"root",children:[h(r.documentRoot,c,l)]},messages:o}}if(g.isTitlelessDivisionType(r.topLevelDivision)){const l=M(r),c=_(w(i,{...r,depth:1},!0));return{tree:{type:"root",children:[h(r.topLevelDivision,c,l)]},messages:o}}return{tree:{type:"root",children:w(i,r)},messages:o}}function w(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 S(e,t,n);const r=[];let i=null,s=[],l=[];const c=()=>{i&&(r.push(me(i,l,t)),i=null,l=[])};for(const a of e)a.type==="heading"&&a.depth===o?(!i&&s.length>0&&(r.push(...S(s,t,n)),s=[]),c(),i=a,l=[]):i?l.push(a):s.push(a);return!i&&s.length>0&&r.push(...S(s,t,n)),c(),r}function S(e,t,n=!1){const o=[];for(let r=0;r<e.length;r+=1){const i=e[r],s=R(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?R(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?_(o):o}function me(e,t,n){const o=n.documentRoot?g.divisionTypeAtRootDepth(n.documentRoot,e.depth):g.divisionTypeAtRelativeDepth(n.topLevelDivision,e.depth),r=h("title",x(e.children,n)),i=ye(e,n),s=w(t,{...n,depth:n.depth+1},!0),l=_(s);return h(o,[r,...l],i)}function ge(e){const t=e.data;return t?.id?{"xml:id":t.id}:void 0}function ye(e,t){const n=ge(e),o=M(t);if(!(!n&&!o))return{...o,...n}}function M(e){if(e.depth!==0)return;const t=e.topLevelAttributesApplied;if(!(!e.topLevelAttributes||!t||t.done))return t.done=!0,e.topLevelAttributes}const ve={paragraph:(e,t)=>Y(e,t),blockquote:(e,t)=>ke(e,t),list:(e,t)=>be(e,t),code:(e,t)=>xe(e),containerDirective:(e,t)=>G(e,t),leafDirective:(e,t)=>Se(e,t)};function R(e,t){const n=ve[e.type];return n?n(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),N("unknown-block-type",`unknown block type "${e.type}"`,T(e,t)))}function Y(e,t){return h("p",x(e.children,t))}function ke(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 Y(o,r)});return h("blockquote",n)}function be(e,t){const n=e.children.map(o=>{const r={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return De(o,r)});return h(e.ordered?"ol":"ul",n)}function De(e,t){const n=S(e.children,t);return h("li",n)}function xe(e,t){return y("program",e.value,e.lang?{language:e.lang}:void 0)}function Ce(e,t){const n=e.value.split(/\\\\|[\r\n]+/).map(o=>o.trim()).filter(o=>o.length>0);return n.length>1?h("md",n.map(o=>y("mrow",o))):y("md",n[0]??"")}function we(e,t){return e.meta==="inline"?y("m",e.value):Ce(e)}function Se(e,t){const n=ce(e);return n||(t.messages&&t.messages.push({type:"warning",reason:"Unnamed leaf directive",category:"unknown-directive"}),N("unknown-directive","unnamed leaf directive",T(e,t)))}function G(e,t){const n=ue(e.name);if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),N("unknown-directive",`unknown directive "${e.name}"`,T(e,t));const o=Le(e),r=e.children,{title:i,body:s}=Ie(r,t),l={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return fe(n,o,i,s,l,(c,a)=>R(c,a),(c,a)=>G(c,a))}function Ie(e,t){const n=e[0];return n?.type==="paragraph"&&n.data?.directiveLabel===!0?{title:h("title",x(n.children,t)),body:e.slice(1)}:{title:null,body:e}}function Le(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 Ee(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 Te={text:(e,t)=>Z(e.value),emphasis:(e,t)=>{const o=Ee(e,t.source)==="underscore"?"term":"em";return h(o,x(e.children,t))},strong:(e,t)=>h("alert",x(e.children,t)),inlineCode:(e,t)=>y("c",e.value),math:(e,t)=>we(e)};function x(e,t){return e.flatMap(n=>qe(n,t)).filter(n=>n!==null)}function qe(e,t){const n=Te[e.type];if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),he("unknown-inline-type",`unknown inline type "${e.type}"`,T(e,t));const o={...t,ancestors:[...t.ancestors,e]};return n(e,o)}const Ae=[{open:"$$",close:"$$",isDisplay:!0},{open:"\\[",close:"\\]",isDisplay:!0},{open:"$",close:"$",isDisplay:!1},{open:"\\(",close:"\\)",isDisplay:!1}],J="PTX_MATH_TOKEN_",q=new RegExp(`${J}(\\d+)`,"g");function Q(e,t){let n=null;for(const o of Ae){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 Me(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 Re(e){const t=new Map;let n="",o=0,r=0;for(;o<e.length;){const i=Me(e,o),s=Q(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=`${J}${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 $e(e){const t=[];let n=0;for(;n<e.length;){const o=Q(e,n);if(!o){n<e.length&&t.push({type:"text",value:e.substring(n)});break}o.index>n&&t.push({type:"text",value:e.substring(n,o.index)}),t.push({type:"math",value:o.content,meta:o.pattern.isDisplay?"display":"inline"}),n=o.index+o.pattern.open.length+o.content.length+o.pattern.close.length}return t.length===0?[{type:"text",value:e}]:t}function Fe(e,t){const n=[];let o=0;q.lastIndex=0;let r=q.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=q.exec(e)}return o<e.length&&n.push({type:"text",value:e.substring(o)}),n.length===0?[{type:"text",value:e}]:n}function ee(e){X.visit(e,"paragraph",t=>{const n=t.children||[],o=[];for(const r of n)if(r.type==="text"){const i=$e(r.value);o.push(...i)}else o.push(r);t.children=o})}function Oe(e,t){X.visit(e,"paragraph",n=>{const o=n.children||[],r=[];for(const i of o)if(i.type==="text"){const s=Fe(i.value,t);r.push(...s)}else r.push(i);n.children=r})}const Ne=()=>e=>{ee(e)};function _e(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 Pe(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 te(e){if(e.children.length===0)e.finalColons=e.colons;else{const t=Math.max(...e.children.map(te));e.finalColons=Math.max(e.colons,t+1)}return e.finalColons}function je(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 Be(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=_e(c);d&&n.push({...d,lineIndex:l})}if(n.length===0)return e;const i=Pe(n);for(const l of i)te(l);return je(t,i).join(`
3
- `)}function ze(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)||!E[r.toLowerCase()]?null:n}function $(e){let t=0;for(let n=0;n<e.length;n++)if(e[n]===" ")t+=1;else if(e[n]===" ")t+=4;else break;return t}function Ue(e,t){const n=$(e[t]);for(let o=t+1;o<e.length;o++)if(!ne(e[o]))return $(e[o])>n;return!1}function ne(e){return e.trim()===""}function We(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 He(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=$(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(ne(i)){n.push("");continue}const a=ze(s);if(a&&Ue(t,r)){for(;o.openDirectives.length>0&&!(o.openDirectives[o.openDirectives.length-1].indentLevel<l);){const v=o.openDirectives.pop();v&&n.push(":".repeat(v.colonCount))}const 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(We(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 Ve=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/,Xe=/^division:\s*(\S+)\s*$/m,Ze=/^xmlid:\s*(\S+)\s*$/m,Ke=/^xml:id:\s*(\S+)\s*$/m,Ye=/^label:\s*(\S+)\s*$/m,Ge=/^component:\s*(\S+)\s*$/m;function Je(e){const t=e.match(Ve);if(!t)return{body:e};const n=t[1],o=e.slice(t[0].length),r=n.match(Xe)?.[1];let i,s;r&&g.isRootDivisionType(r)?(s=r,i=g.rootChildDivision(r)):r&&g.isTopLevelDivisionType(r)&&(i=r);const l={},c=n.match(Ze)?.[1]??n.match(Ke)?.[1],a=n.match(Ye)?.[1],u=n.match(Ge)?.[1];return c&&(l["xml:id"]=c),a&&(l.label=a),u&&(l.component=u),{division:i,documentRoot:s,attributes:Object.keys(l).length>0?l:void 0,body:o}}const oe=function(e){return function(n,o){if(typeof o?.value=="string"){const r=Je(o.value),i=e?.documentRoot??r.documentRoot,s=e?.topLevelDivision??r.division??(i?g.rootChildDivision(i):"chapter"),l=e?.topLevelAttributes??r.attributes,c=He(r.body),a=Be(c),u=Re(a),m=W.unified().data("micromarkExtensions",[{disable:{null:["codeIndented"]}}]).use(H).use(V).parse(u.markdown);return Oe(m,u.tokens),A(m,u.markdown,{topLevelDivision:s,documentRoot:i,topLevelAttributes:l})}return ee(n),A(n,void 0,{topLevelDivision:e?.topLevelDivision??(e?.documentRoot?g.rootChildDivision(e.documentRoot):"chapter"),documentRoot:e?.documentRoot,topLevelAttributes:e?.topLevelAttributes})}},Qe=/["&'<>`]/g,et=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,tt=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,nt=/[|\\{}()[\]^$+*?.]/g,B=new WeakMap;function ot(e,t){if(e=e.replace(t.subset?rt(t.subset):Qe,o),t.subset||t.escapeOnly)return e;return e.replace(et,n).replace(tt,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 rt(e){let t=B.get(e);return t||(t=it(e),B.set(e,t)),t}function it(e){const t=[];let n=-1;for(;++n<e.length;)t.push(e[n].replace(nt,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function st(e){return"&#x"+e.toString(16).toUpperCase()+";"}function lt(e,t){return ot(e,Object.assign({format:st},t))}const ct=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function k(e,t,n){const o=at(e);return n?o.replace(n,r):r(o);function r(i){return lt(i,{subset:t})}}function at(e){return String(e||"").replace(ct,"")}const ut=/]]>/g,pt=[">"];function ft(e){return"<![CDATA["+k(e.value,pt,ut)+"]]>"}function ht(e){return"<!--"+k(e.value,["-"])+"-->"}const dt=[" ",`
6
- `," ",'"',"&","'","/","<","=",">"];function L(e){return k(e,dt)}function z(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 F(e,t){const n=String(e);let o=t.options.quote||'"';if(t.options.quoteSmart){const r=o==='"'?"'":'"';z(n,o)>z(n,r)&&(o=r)}return o+k(n,["<","&",o])+o}function mt(e,t){const n=L(e.name),o=e.public,r=e.system;let i="<!DOCTYPE";return n!==""&&(i+=" "+n),o?i+=" PUBLIC "+F(o,t):r&&(i+=" SYSTEM"),r&&(i+=" "+F(r,t)),i+">"}const gt={}.hasOwnProperty;function yt(e,t){const n=L(e.name),o=se(e,t),r=e.attributes||{},i=o?!1:t.options.closeEmptyElements,s=[];let l;for(l in r)if(gt.call(r,l)){const c=r[l];c!=null&&s.push(L(l)+"="+F(c,t))}return"<"+n+(s.length===0?"":" "+s.join(" "))+(i?(t.options.tightClose?"":" ")+"/":"")+">"+o+(i?"":"</"+n+">")}const vt=/\?>/g,kt=[">"];function bt(e){const t=L(e.name)||"x",n=k(e.value,kt,vt);return"<?"+t+(n?" "+n:"")+"?>"}const Dt=["&","<"];function re(e){return k(e.value,Dt)}function xt(e,t){return t.options.allowDangerousXml?e.value:re(e)}const Ct={}.hasOwnProperty,U={cdata:ft,comment:ht,doctype:mt,element:yt,instruction:bt,raw:xt,root:se,text:re};function ie(e,t){const n=e&&e.type;if(!n)throw new Error("Expected node, not `"+e+"`");if(!Ct.call(U,n))throw new Error("Cannot compile unknown node `"+n+"`");const o=U[n];return o(e,t)}function se(e,t){const n=e&&e.children||[];let o=-1;const r=[];for(;++o<n.length;)r[o]=ie(n[o],t);return r.join("")}function wt(e,t){const n={options:t||{}};if(typeof n.options.quote=="string"&&n.options.quote!=='"'&&n.options.quote!=="'")throw new Error("Invalid quote `"+n.options.quote+"`, expected `'` or `\"`");const o=Array.isArray(e)?{type:"root",children:e}:e;return ie(o,n)}function St(e,t){const n=W.unified().use(H).use(V).use(oe,t),o=n.parse(e),r=n.runSync(o,{value:e});return wt(r.children,{closeEmptyElements:!0,tightClose:!0})}exports.DIRECTIVE_MAP=ae;exports.PROOF_SOLUTION_NAMES=O;exports.markdownToPretext=St;exports.mdastToPtxast=A;exports.remarkMath=Ne;exports.remarkPretext=oe;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("unified"),H=require("remark-parse"),V=require("remark-directive"),g=require("@pretextbook/ptxast"),X=require("unist-util-visit");function le(e,t={}){const n={};for(const[o,i]of Object.entries(t))i!=null&&(n[o]=i);return{type:"element",name:`plus:${e}`,attributes:n,children:[]}}function ce(e){const t=e.name?.trim();return t?le(t,e.attributes??{}):null}const T={theorem:{type:"theorem",category:"theorem-like",requiresStatement:!0},lemma:{type:"lemma",category:"theorem-like",requiresStatement:!0},corollary:{type:"corollary",category:"theorem-like",requiresStatement:!0},proposition:{type:"proposition",category:"theorem-like",requiresStatement:!0},claim:{type:"claim",category:"theorem-like",requiresStatement:!0},fact:{type:"fact",category:"theorem-like",requiresStatement:!0},conjecture:{type:"conjecture",category:"theorem-like",requiresStatement:!0},axiom:{type:"axiom",category:"theorem-like",requiresStatement:!0},principle:{type:"principle",category:"theorem-like",requiresStatement:!0},hypothesis:{type:"hypothesis",category:"theorem-like",requiresStatement:!0},algorithm:{type:"algorithm",category:"theorem-like",requiresStatement:!0},definition:{type:"definition",category:"definition-like",requiresStatement:!0},notation:{type:"notation",category:"definition-like",requiresStatement:!0},remark:{type:"remark",category:"remark-like",requiresStatement:!1},note:{type:"note",category:"remark-like",requiresStatement:!1},observation:{type:"observation",category:"remark-like",requiresStatement:!1},warning:{type:"warning",category:"remark-like",requiresStatement:!1},insight:{type:"insight",category:"remark-like",requiresStatement:!1},assemblage:{type:"assemblage",category:"remark-like",requiresStatement:!1},example:{type:"example",category:"example-like",requiresStatement:!1},question:{type:"question",category:"example-like",requiresStatement:!1},problem:{type:"problem",category:"example-like",requiresStatement:!1},exercise:{type:"exercise",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},activity:{type:"activity",category:"example-like",requiresStatement:!1},exploration:{type:"exploration",category:"example-like",requiresStatement:!1},investigation:{type:"investigation",category:"example-like",requiresStatement:!1},project:{type:"project",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},task:{type:"task",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},proof:{type:"proof",category:"proof-like",requiresStatement:!1},case:{type:"case",category:"proof-like",requiresStatement:!1},solution:{type:"solution",category:"solution-like",requiresStatement:!1},hint:{type:"hint",category:"solution-like",requiresStatement:!1},answer:{type:"answer",category:"solution-like",requiresStatement:!1}},ue=T;function ae(e){return T[e.toLowerCase()]}const O=new Set(Object.entries(T).filter(([e,t])=>t.category==="proof-like"||t.category==="solution-like").map(([e])=>e));function D(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function w(e){return e.type==="containerDirective"&&e.name==="task"}function pe(e){return e.type==="containerDirective"&&O.has(e.name)}function L(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(D("p",[n])):t.push(n);return t}function fe(e,t,n,o,i,r,s){const l=[];if(n&&l.push(n),e.hasNestedTasks){const c=o.findIndex(w);if(c!==-1){const u=[];for(let p=0;p<o.length;p++)w(o[p])&&u.push(p);const a=u[u.length-1],d=o.slice(0,c),m=o.slice(c).filter(w),b=[],v=[],P=[];for(let p=c;p<o.length;p++){const f=o[p];if(!w(f)){if(p<a){b.push(f);continue}if(pe(f)){P.push(f);continue}v.push(f)}}if(b.length>0&&(i.messages??(i.messages=[])).push({type:"warning",reason:`Dropped ${b.length} non-task node(s) between task directives in ${e.type}.`,category:"dropped-content-between-tasks",position:b[0].position?.start}),d.length>0){const p=L(d.map(f=>r(f,i)).filter(f=>f!==null));p.length>0&&l.push(D("introduction",p))}for(const p of m){const f=s(p,i);f&&l.push(f)}if(v.length>0){const p=L(v.map(f=>r(f,i)).filter(f=>f!==null));p.length>0&&l.push(D("conclusion",p))}for(const p of P){const f=s(p,i);f&&l.push(f)}}else j(l,e,o,i,r,s)}else j(l,e,o,i,r,s);return D(e.type,l,t)}function j(e,t,n,o,i,r){if(t.requiresStatement){const s=[],l=[];for(const c of n)if(c.type==="containerDirective"&&O.has(c.name)){const u=r(c,o);u&&l.push(u)}else s.push(c);if(s.length>0){const c=L(s.map(u=>i(u,o)).filter(u=>u!==null));c.length>0&&e.push(D("statement",c))}e.push(...l)}else{const s=L(n.map(l=>i(l,o)).filter(l=>l!==null));e.push(...s)}}function Z(e){return{type:"text",value:e}}function h(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function y(e,t,n){return h(e,[Z(t)],n)}function K(e){return{type:"comment",value:e.replace(/--/g,"- -")}}function E(e,t){const n=e?.position,o=n?.start?.offset,i=n?.end?.offset;return t.source&&o!=null&&i!=null?t.source.slice(o,i):""}function N(e,t,n){return h("TODO",[K(`todo: ${t}`),y("pre",n)],{type:e})}function he(e,t,n){return h("TODO",[K(`todo: ${t}`),y("c",n)],{type:e})}function _(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(h("p",[n])):t.push(n);return t}function A(e,t,n){return de(e,t,n).tree}function de(e,t,n){const o=[],i={ancestors:[],depth:0,messages:o,source:t,topLevelDivision:n?.topLevelDivision??"chapter",documentRoot:n?.documentRoot,topLevelAttributes:n?.topLevelAttributes,topLevelAttributesApplied:n?.topLevelAttributes?{done:!1}:void 0},r=e.children;if(i.documentRoot){const l=M(i),c=I(r,i);return{tree:{type:"root",children:[h(i.documentRoot,c,l)]},messages:o}}if(g.isTitlelessDivisionType(i.topLevelDivision)){const l=M(i),c=_(I(r,{...i,depth:1},!0));return{tree:{type:"root",children:[h(i.topLevelDivision,c,l)]},messages:o}}return{tree:{type:"root",children:I(r,i)},messages:o}}function I(e,t,n=!1){let o=7;for(const u of e)u.type==="heading"&&(o=Math.min(o,u.depth));if(o===7)return x(e,t,n);const i=[];let r=null,s=[],l=[];const c=()=>{r&&(i.push(me(r,l,t)),r=null,l=[])};for(const u of e)u.type==="heading"&&u.depth===o?(!r&&s.length>0&&(i.push(...x(s,t,n)),s=[]),c(),r=u,l=[]):r?l.push(u):s.push(u);return!r&&s.length>0&&i.push(...x(s,t,n)),c(),i}function x(e,t,n=!1){const o=[];for(let i=0;i<e.length;i+=1){const r=e[i],s=R(r,t);if(s!==null){if(s.name==="p"&&s.children.length===1&&s.children[0].name==="md"){const l=s.children[0],c=o[o.length-1],u=i+1<e.length?R(e[i+1],t):null,a=u?.name==="p"?u.children:null;if(c?.name==="p")c.children.push(l),a&&(c.children.push(...a),i+=1);else{const d=[l];a&&(d.push(...a),i+=1),o.push(h("p",d))}continue}if((s.name==="ul"||s.name==="ol")&&o.length>0){const l=o[o.length-1];if(l?.name==="p"){l.children.push(s);continue}}o.push(s)}}return n?_(o):o}function me(e,t,n){const o=n.documentRoot?g.divisionTypeAtRootDepth(n.documentRoot,e.depth):g.divisionTypeAtRelativeDepth(n.topLevelDivision,e.depth),i=h("title",C(e.children,n)),r=ke(e,n),s={...n,depth:n.depth+1},{introduction:l,rest:c}=ye(t,s),u=I(c,s,!0),a=_(u),d=l?[i,l,...a]:[i,...a];return h(o,d,r)}function ge(e){return e.type==="leafDirective"&&g.isTopLevelDivisionType(e.name)}function ye(e,t){const n=e.findIndex(l=>l.type==="heading"||ge(l));if(n<=0)return{introduction:null,rest:e};const o=e.slice(0,n),i=e.slice(n),r=x(o,t,!0);return{introduction:r.length>0?h("introduction",r):null,rest:i}}function ve(e){const t=e.data;return t?.id?{"xml:id":t.id}:void 0}function ke(e,t){const n=ve(e),o=M(t);if(!(!n&&!o))return{...o,...n}}function M(e){if(e.depth!==0)return;const t=e.topLevelAttributesApplied;if(!(!e.topLevelAttributes||!t||t.done))return t.done=!0,e.topLevelAttributes}const be={paragraph:(e,t)=>Y(e,t),blockquote:(e,t)=>De(e,t),list:(e,t)=>xe(e,t),code:(e,t)=>we(e),containerDirective:(e,t)=>G(e,t),leafDirective:(e,t)=>Se(e,t)};function R(e,t){const n=be[e.type];return n?n(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),N("unknown-block-type",`unknown block type "${e.type}"`,E(e,t)))}function Y(e,t){return h("p",C(e.children,t))}function De(e,t){const n=e.children.filter(o=>o.type==="paragraph").map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Y(o,i)});return h("blockquote",n)}function xe(e,t){const n=e.children.map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Ce(o,i)});return h(e.ordered?"ol":"ul",n)}function Ce(e,t){const n=x(e.children,t);return h("li",n)}function we(e,t){return y("program",e.value,e.lang?{language:e.lang}:void 0)}function Ie(e,t){const n=e.value.split(/\\\\|[\r\n]+/).map(o=>o.trim()).filter(o=>o.length>0);return n.length>1?h("md",n.map(o=>y("mrow",o))):y("md",n[0]??"")}function Le(e,t){return e.meta==="inline"?y("m",e.value):Ie(e)}function Se(e,t){const n=ce(e);return n||(t.messages&&t.messages.push({type:"warning",reason:"Unnamed leaf directive",category:"unknown-directive"}),N("unknown-directive","unnamed leaf directive",E(e,t)))}function G(e,t){const n=ae(e.name);if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),N("unknown-directive",`unknown directive "${e.name}"`,E(e,t));const o=Ee(e),i=e.children,{title:r,body:s}=Te(i,t),l={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return fe(n,o,r,s,l,(c,u)=>R(c,u),(c,u)=>G(c,u))}function Te(e,t){const n=e[0];return n?.type==="paragraph"&&n.data?.directiveLabel===!0?{title:h("title",C(n.children,t)),body:e.slice(1)}:{title:null,body:e}}function Ee(e){const t=e.attributes??{},n={};for(const[o,i]of Object.entries(t))i!=null&&(n[o==="id"?"xml:id":o]=i);return Object.keys(n).length>0?n:void 0}function qe(e,t){return!t||e.position?.start?.offset===null||e.position?.start?.offset===void 0?"asterisk":t.charAt(e.position.start.offset)==="_"?"underscore":"asterisk"}const Ae={text:(e,t)=>Z(e.value),emphasis:(e,t)=>{const o=qe(e,t.source)==="underscore"?"term":"em";return h(o,C(e.children,t))},strong:(e,t)=>h("alert",C(e.children,t)),inlineCode:(e,t)=>y("c",e.value),math:(e,t)=>Le(e)};function C(e,t){return e.flatMap(n=>Me(n,t)).filter(n=>n!==null)}function Me(e,t){const n=Ae[e.type];if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),he("unknown-inline-type",`unknown inline type "${e.type}"`,E(e,t));const o={...t,ancestors:[...t.ancestors,e]};return n(e,o)}const Re=[{open:"$$",close:"$$",isDisplay:!0},{open:"\\[",close:"\\]",isDisplay:!0},{open:"$",close:"$",isDisplay:!1},{open:"\\(",close:"\\)",isDisplay:!1}],J="PTX_MATH_TOKEN_",q=new RegExp(`${J}(\\d+)`,"g");function Q(e,t){let n=null;for(const o of Re){const i=e.indexOf(o.open,t);if(i===-1)continue;const r=e.indexOf(o.close,i+o.open.length);if(r!==-1&&!(o.open==="$"&&(i>0&&e[i-1]==="$"||i+1<e.length&&e[i+1]==="$"))&&(!n||i<n.index)){const s=e.substring(i+o.open.length,r);n={index:i,pattern:o,content:s}}}return n}function $e(e,t){let n=t;for(;n<e.length;){const o=e.indexOf("`",n);if(o===-1)return null;let i=0,r=o;for(;r<e.length&&e[r]==="`";)i++,r++;const s="`".repeat(i);let l=r;for(;l<e.length;){const c=e.indexOf(s,l);if(c===-1)break;const u=c+i;if(u>=e.length||e[u]!=="`")return{start:o,end:u};l=c+1}n=o+i}return null}function Fe(e){const t=new Map;let n="",o=0,i=0;for(;o<e.length;){const r=$e(e,o),s=Q(e,o);if(r&&(!s||r.start<s.index)){n+=e.substring(o,r.end),o=r.end;continue}if(!s){n+=e.substring(o);break}n+=e.substring(o,s.index);const l=`${J}${i}`;n+=l,t.set(l,{type:"math",value:s.content,meta:s.pattern.isDisplay?"display":"inline"}),o=s.index+s.pattern.open.length+s.content.length+s.pattern.close.length,i+=1}return{markdown:n,tokens:t}}function Oe(e){const t=[];let n=0;for(;n<e.length;){const o=Q(e,n);if(!o){n<e.length&&t.push({type:"text",value:e.substring(n)});break}o.index>n&&t.push({type:"text",value:e.substring(n,o.index)}),t.push({type:"math",value:o.content,meta:o.pattern.isDisplay?"display":"inline"}),n=o.index+o.pattern.open.length+o.content.length+o.pattern.close.length}return t.length===0?[{type:"text",value:e}]:t}function Ne(e,t){const n=[];let o=0;q.lastIndex=0;let i=q.exec(e);for(;i;){const r=i.index,s=i[0];r>o&&n.push({type:"text",value:e.substring(o,r)});const l=t.get(s);l?n.push(l):n.push({type:"text",value:s}),o=r+s.length,i=q.exec(e)}return o<e.length&&n.push({type:"text",value:e.substring(o)}),n.length===0?[{type:"text",value:e}]:n}function ee(e){X.visit(e,"paragraph",t=>{const n=t.children||[],o=[];for(const i of n)if(i.type==="text"){const r=Oe(i.value);o.push(...r)}else o.push(i);t.children=o})}function _e(e,t){X.visit(e,"paragraph",n=>{const o=n.children||[],i=[];for(const r of o)if(r.type==="text"){const s=Ne(r.value,t);i.push(...s)}else i.push(r);n.children=i})}const Pe=()=>e=>{ee(e)};function je(e){const t=e.trim();if(!t.startsWith(":"))return null;let n=0;for(let r=0;r<t.length&&t[r]===":";r++)n++;if(n<3)return null;const o=t.slice(n).trim(),i=o.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);return o===""?{colons:n,label:null,lineIndex:-1,isOpen:!1}:i?{colons:n,label:i[0],lineIndex:-1,isOpen:!0}:null}function Be(e){const t=[],n=[];for(const o of e)if(o.isOpen){const i={colons:o.colons,finalColons:o.colons,label:o.label,openLineIndex:o.lineIndex,closeLineIndex:null,children:[],parent:null};if(t.length>0){const r=t[t.length-1];i.parent=r,r.children.push(i)}else n.push(i);t.push(i)}else{const i=t[t.length-1];i&&i.colons===o.colons&&(i.closeLineIndex=o.lineIndex,t.pop())}return n}function te(e){if(e.children.length===0)e.finalColons=e.colons;else{const t=Math.max(...e.children.map(te));e.finalColons=Math.max(e.colons,t+1)}return e.finalColons}function ze(e,t,n){const o=e.slice(),i=[],r=t.slice();for(;r.length>0;){const s=r.shift();i.push(s),r.push(...s.children)}for(const s of i){if(s.openLineIndex>=0){const l=o[s.openLineIndex],c=l.match(/^:+/)?.[0].length||3,u=l.slice(c);o[s.openLineIndex]=":".repeat(s.finalColons)+u}s.closeLineIndex!==null&&s.closeLineIndex>=0&&(o[s.closeLineIndex]=":".repeat(s.finalColons))}return o}function Ue(e){const t=e.split(`
2
+ `),n=[];let o=!1,i=null;for(let l=0;l<t.length;l++){const c=t[l],a=c.trim().match(/^(`{3,}|~{3,})/);if(a){const m=a[1];o?i&&m[0]===i[0]&&m.length>=i.length&&(o=!1,i=null):(o=!0,i=m);continue}if(o)continue;const d=je(c);d&&n.push({...d,lineIndex:l})}if(n.length===0)return e;const r=Be(n);for(const l of r)te(l);return ze(t,r).join(`
3
+ `)}function We(e){const t=e.trim();if(!t.endsWith(":"))return null;const n=t.slice(0,-1);if(!/^[a-zA-Z]/.test(n))return null;const o=n.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);if(!o)return null;const[,i,r]=o;return r&&!/^(\[[^\]]*\]|\{[^}]*\})*$/.test(r)||!T[i.toLowerCase()]?null:n}function $(e){let t=0;for(let n=0;n<e.length;n++)if(e[n]===" ")t+=1;else if(e[n]===" ")t+=4;else break;return t}function He(e,t){const n=$(e[t]);for(let o=t+1;o<e.length;o++)if(!ne(e[o]))return $(e[o])>n;return!1}function ne(e){return e.trim()===""}function Ve(e,t){let n=0,o=0;for(;o<e.length&&n<t;)if(e[o]===" ")n++,o++;else if(e[o]===" ")n+=4,o++;else break;return e.slice(o)}function Xe(e){const t=e.split(`
4
+ `),n=[],o={level:0,openDirectives:[],inCodeFence:!1,codeFenceMarker:null};for(let i=0;i<t.length;i++){const r=t[i],s=r.trim(),l=$(r),c=s.match(/^(`{3,}|~{3,})/);if(c){const a=c[1];o.inCodeFence?o.codeFenceMarker&&s.startsWith(o.codeFenceMarker)&&(o.inCodeFence=!1,o.codeFenceMarker=null):(o.inCodeFence=!0,o.codeFenceMarker=a),n.push(r);continue}if(o.inCodeFence){n.push(r);continue}if(ne(r)){n.push("");continue}const u=We(s);if(u&&He(t,i)){for(;o.openDirectives.length>0&&!(o.openDirectives[o.openDirectives.length-1].indentLevel<l);){const v=o.openDirectives.pop();v&&n.push(":".repeat(v.colonCount))}const a=u.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/),d=a?a[1].toLowerCase()+(a[2]||""):u,m=o.openDirectives.length*1+3;n.push(":".repeat(m)+d),o.openDirectives.push({label:d,indentLevel:l,colonCount:m,bodyBaseIndent:-1}),o.level=l}else{for(;o.openDirectives.length>0&&l<=o.openDirectives[o.openDirectives.length-1].indentLevel;){const a=o.openDirectives.pop();a&&n.push(":".repeat(a.colonCount))}if(o.openDirectives.length>0){const a=o.openDirectives[o.openDirectives.length-1];a.bodyBaseIndent<0&&(a.bodyBaseIndent=l),n.push(Ve(r,a.bodyBaseIndent))}else n.push(r);o.level=l}}for(;o.openDirectives.length>0;){const i=o.openDirectives.pop();i&&n.push(":".repeat(i.colonCount))}return n.join(`
5
+ `)}const Ze=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/,Ke=/^division:\s*(\S+)\s*$/m,Ye=/^xmlid:\s*(\S+)\s*$/m,Ge=/^xml:id:\s*(\S+)\s*$/m,Je=/^label:\s*(\S+)\s*$/m,Qe=/^component:\s*(\S+)\s*$/m;function et(e){const t=e.match(Ze);if(!t)return{body:e};const n=t[1],o=e.slice(t[0].length),i=n.match(Ke)?.[1];let r,s;i&&g.isRootDivisionType(i)?(s=i,r=g.rootChildDivision(i)):i&&g.isTopLevelDivisionType(i)&&(r=i);const l={},c=n.match(Ye)?.[1]??n.match(Ge)?.[1],u=n.match(Je)?.[1],a=n.match(Qe)?.[1];return c&&(l["xml:id"]=c),u&&(l.label=u),a&&(l.component=a),{division:r,documentRoot:s,attributes:Object.keys(l).length>0?l:void 0,body:o}}const oe=function(e){return function(n,o){if(typeof o?.value=="string"){const i=et(o.value),r=e?.documentRoot??i.documentRoot,s=e?.topLevelDivision??i.division??(r?g.rootChildDivision(r):"chapter"),l=e?.topLevelAttributes??i.attributes,c=Xe(i.body),u=Ue(c),a=Fe(u),m=W.unified().data("micromarkExtensions",[{disable:{null:["codeIndented"]}}]).use(H).use(V).parse(a.markdown);return _e(m,a.tokens),A(m,a.markdown,{topLevelDivision:s,documentRoot:r,topLevelAttributes:l})}return ee(n),A(n,void 0,{topLevelDivision:e?.topLevelDivision??(e?.documentRoot?g.rootChildDivision(e.documentRoot):"chapter"),documentRoot:e?.documentRoot,topLevelAttributes:e?.topLevelAttributes})}},tt=/["&'<>`]/g,nt=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,ot=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,it=/[|\\{}()[\]^$+*?.]/g,B=new WeakMap;function rt(e,t){if(e=e.replace(t.subset?st(t.subset):tt,o),t.subset||t.escapeOnly)return e;return e.replace(nt,n).replace(ot,o);function n(i,r,s){return t.format((i.charCodeAt(0)-55296)*1024+i.charCodeAt(1)-56320+65536,s.charCodeAt(r+2),t)}function o(i,r,s){return t.format(i.charCodeAt(0),s.charCodeAt(r+1),t)}}function st(e){let t=B.get(e);return t||(t=lt(e),B.set(e,t)),t}function lt(e){const t=[];let n=-1;for(;++n<e.length;)t.push(e[n].replace(it,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function ct(e){return"&#x"+e.toString(16).toUpperCase()+";"}function ut(e,t){return rt(e,Object.assign({format:ct},t))}const at=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function k(e,t,n){const o=pt(e);return n?o.replace(n,i):i(o);function i(r){return ut(r,{subset:t})}}function pt(e){return String(e||"").replace(at,"")}const ft=/]]>/g,ht=[">"];function dt(e){return"<![CDATA["+k(e.value,ht,ft)+"]]>"}function mt(e){return"<!--"+k(e.value,["-"])+"-->"}const gt=[" ",`
6
+ `," ",'"',"&","'","/","<","=",">"];function S(e){return k(e,gt)}function z(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let o=0,i=n.indexOf(t);for(;i!==-1;)o++,i=n.indexOf(t,i+t.length);return o}function F(e,t){const n=String(e);let o=t.options.quote||'"';if(t.options.quoteSmart){const i=o==='"'?"'":'"';z(n,o)>z(n,i)&&(o=i)}return o+k(n,["<","&",o])+o}function yt(e,t){const n=S(e.name),o=e.public,i=e.system;let r="<!DOCTYPE";return n!==""&&(r+=" "+n),o?r+=" PUBLIC "+F(o,t):i&&(r+=" SYSTEM"),i&&(r+=" "+F(i,t)),r+">"}const vt={}.hasOwnProperty;function kt(e,t){const n=S(e.name),o=se(e,t),i=e.attributes||{},r=o?!1:t.options.closeEmptyElements,s=[];let l;for(l in i)if(vt.call(i,l)){const c=i[l];c!=null&&s.push(S(l)+"="+F(c,t))}return"<"+n+(s.length===0?"":" "+s.join(" "))+(r?(t.options.tightClose?"":" ")+"/":"")+">"+o+(r?"":"</"+n+">")}const bt=/\?>/g,Dt=[">"];function xt(e){const t=S(e.name)||"x",n=k(e.value,Dt,bt);return"<?"+t+(n?" "+n:"")+"?>"}const Ct=["&","<"];function ie(e){return k(e.value,Ct)}function wt(e,t){return t.options.allowDangerousXml?e.value:ie(e)}const It={}.hasOwnProperty,U={cdata:dt,comment:mt,doctype:yt,element:kt,instruction:xt,raw:wt,root:se,text:ie};function re(e,t){const n=e&&e.type;if(!n)throw new Error("Expected node, not `"+e+"`");if(!It.call(U,n))throw new Error("Cannot compile unknown node `"+n+"`");const o=U[n];return o(e,t)}function se(e,t){const n=e&&e.children||[];let o=-1;const i=[];for(;++o<n.length;)i[o]=re(n[o],t);return i.join("")}function Lt(e,t){const n={options:t||{}};if(typeof n.options.quote=="string"&&n.options.quote!=='"'&&n.options.quote!=="'")throw new Error("Invalid quote `"+n.options.quote+"`, expected `'` or `\"`");const o=Array.isArray(e)?{type:"root",children:e}:e;return re(o,n)}function St(e,t){const n=W.unified().use(H).use(V).use(oe,t),o=n.parse(e),i=n.runSync(o,{value:e});return Lt(i.children,{closeEmptyElements:!0,tightClose:!0})}exports.DIRECTIVE_MAP=ue;exports.PROOF_SOLUTION_NAMES=O;exports.markdownToPretext=St;exports.mdastToPtxast=A;exports.remarkMath=Pe;exports.remarkPretext=oe;
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { unified as W } from "unified";
2
2
  import U from "remark-parse";
3
3
  import H from "remark-directive";
4
- import { isTitlelessDivisionType as se, divisionTypeAtRootDepth as le, divisionTypeAtRelativeDepth as ce, isRootDivisionType as ae, rootChildDivision as q, isTopLevelDivisionType as ue } from "@pretextbook/ptxast";
5
- import { visit as X } from "unist-util-visit";
4
+ import { isTitlelessDivisionType as le, divisionTypeAtRootDepth as ce, divisionTypeAtRelativeDepth as ue, isTopLevelDivisionType as X, isRootDivisionType as ae, rootChildDivision as q } from "@pretextbook/ptxast";
5
+ import { visit as Z } from "unist-util-visit";
6
6
  function pe(e, t = {}) {
7
7
  const n = {};
8
8
  for (const [o, r] of Object.entries(t))
@@ -59,11 +59,11 @@ const S = {
59
59
  solution: { type: "solution", category: "solution-like", requiresStatement: !1 },
60
60
  hint: { type: "hint", category: "solution-like", requiresStatement: !1 },
61
61
  answer: { type: "answer", category: "solution-like", requiresStatement: !1 }
62
- }, Mt = S;
62
+ }, Ft = S;
63
63
  function he(e) {
64
64
  return S[e.toLowerCase()];
65
65
  }
66
- const Z = new Set(
66
+ const V = new Set(
67
67
  Object.entries(S).filter(([e, t]) => t.category === "proof-like" || t.category === "solution-like").map(([e]) => e)
68
68
  );
69
69
  function b(e, t, n) {
@@ -74,11 +74,11 @@ function b(e, t, n) {
74
74
  children: t
75
75
  };
76
76
  }
77
- function x(e) {
77
+ function C(e) {
78
78
  return e.type === "containerDirective" && e.name === "task";
79
79
  }
80
80
  function de(e) {
81
- return e.type === "containerDirective" && Z.has(e.name);
81
+ return e.type === "containerDirective" && V.has(e.name);
82
82
  }
83
83
  function L(e) {
84
84
  const t = [];
@@ -89,16 +89,16 @@ function L(e) {
89
89
  function me(e, t, n, o, r, i, s) {
90
90
  const l = [];
91
91
  if (n && l.push(n), e.hasNestedTasks) {
92
- const c = o.findIndex(x);
92
+ const c = o.findIndex(C);
93
93
  if (c !== -1) {
94
- const a = [];
94
+ const u = [];
95
95
  for (let p = 0; p < o.length; p++)
96
- x(o[p]) && a.push(p);
97
- const u = a[a.length - 1], d = o.slice(0, c), m = o.slice(c).filter(x), k = [], y = [], O = [];
96
+ C(o[p]) && u.push(p);
97
+ const a = u[u.length - 1], d = o.slice(0, c), m = o.slice(c).filter(C), k = [], y = [], O = [];
98
98
  for (let p = c; p < o.length; p++) {
99
99
  const f = o[p];
100
- if (!x(f)) {
101
- if (p < u) {
100
+ if (!C(f)) {
101
+ if (p < a) {
102
102
  k.push(f);
103
103
  continue;
104
104
  }
@@ -144,14 +144,14 @@ function _(e, t, n, o, r, i) {
144
144
  if (t.requiresStatement) {
145
145
  const s = [], l = [];
146
146
  for (const c of n)
147
- if (c.type === "containerDirective" && Z.has(c.name)) {
148
- const a = i(c, o);
149
- a && l.push(a);
147
+ if (c.type === "containerDirective" && V.has(c.name)) {
148
+ const u = i(c, o);
149
+ u && l.push(u);
150
150
  } else
151
151
  s.push(c);
152
152
  if (s.length > 0) {
153
153
  const c = L(
154
- s.map((a) => r(a, o)).filter((a) => a !== null)
154
+ s.map((u) => r(u, o)).filter((u) => u !== null)
155
155
  );
156
156
  c.length > 0 && e.push(b("statement", c));
157
157
  }
@@ -163,7 +163,7 @@ function _(e, t, n, o, r, i) {
163
163
  e.push(...s);
164
164
  }
165
165
  }
166
- function V(e) {
166
+ function K(e) {
167
167
  return { type: "text", value: e };
168
168
  }
169
169
  function h(e, t, n) {
@@ -175,9 +175,9 @@ function h(e, t, n) {
175
175
  };
176
176
  }
177
177
  function g(e, t, n) {
178
- return h(e, [V(t)], n);
178
+ return h(e, [K(t)], n);
179
179
  }
180
- function K(e) {
180
+ function Y(e) {
181
181
  return { type: "comment", value: e.replace(/--/g, "- -") };
182
182
  }
183
183
  function E(e, t) {
@@ -185,12 +185,12 @@ function E(e, t) {
185
185
  return t.source && o != null && r != null ? t.source.slice(o, r) : "";
186
186
  }
187
187
  function F(e, t, n) {
188
- return h("TODO", [K(`todo: ${t}`), g("pre", n)], {
188
+ return h("TODO", [Y(`todo: ${t}`), g("pre", n)], {
189
189
  type: e
190
190
  });
191
191
  }
192
192
  function ge(e, t, n) {
193
- return h("TODO", [K(`todo: ${t}`), g("c", n)], {
193
+ return h("TODO", [Y(`todo: ${t}`), g("c", n)], {
194
194
  type: e
195
195
  });
196
196
  }
@@ -215,56 +215,56 @@ function ye(e, t, n) {
215
215
  topLevelAttributesApplied: n?.topLevelAttributes ? { done: !1 } : void 0
216
216
  }, i = e.children;
217
217
  if (r.documentRoot) {
218
- const l = A(r), c = C(i, r);
218
+ const l = A(r), c = w(i, r);
219
219
  return {
220
220
  tree: { type: "root", children: [h(r.documentRoot, c, l)] },
221
221
  messages: o
222
222
  };
223
223
  }
224
- if (se(r.topLevelDivision)) {
224
+ if (le(r.topLevelDivision)) {
225
225
  const l = A(r), c = N(
226
- C(i, { ...r, depth: 1 }, !0)
226
+ w(i, { ...r, depth: 1 }, !0)
227
227
  );
228
228
  return { tree: { type: "root", children: [h(r.topLevelDivision, c, l)] }, messages: o };
229
229
  }
230
230
  return {
231
- tree: { type: "root", children: C(i, r) },
231
+ tree: { type: "root", children: w(i, r) },
232
232
  messages: o
233
233
  };
234
234
  }
235
- function C(e, t, n = !1) {
235
+ function w(e, t, n = !1) {
236
236
  let o = 7;
237
- for (const a of e)
238
- a.type === "heading" && (o = Math.min(o, a.depth));
237
+ for (const u of e)
238
+ u.type === "heading" && (o = Math.min(o, u.depth));
239
239
  if (o === 7)
240
- return w(e, t, n);
240
+ return D(e, t, n);
241
241
  const r = [];
242
242
  let i = null, s = [], l = [];
243
243
  const c = () => {
244
244
  i && (r.push(ve(i, l, t)), i = null, l = []);
245
245
  };
246
- for (const a of e)
247
- a.type === "heading" && a.depth === o ? (!i && s.length > 0 && (r.push(
248
- ...w(s, t, n)
249
- ), s = []), c(), i = a, l = []) : i ? l.push(a) : s.push(a);
246
+ for (const u of e)
247
+ u.type === "heading" && u.depth === o ? (!i && s.length > 0 && (r.push(
248
+ ...D(s, t, n)
249
+ ), s = []), c(), i = u, l = []) : i ? l.push(u) : s.push(u);
250
250
  return !i && s.length > 0 && r.push(
251
- ...w(s, t, n)
251
+ ...D(s, t, n)
252
252
  ), c(), r;
253
253
  }
254
- function w(e, t, n = !1) {
254
+ function D(e, t, n = !1) {
255
255
  const o = [];
256
256
  for (let r = 0; r < e.length; r += 1) {
257
257
  const i = e[r], s = $(i, t);
258
258
  if (s !== null) {
259
259
  if (s.name === "p" && s.children.length === 1 && s.children[0].name === "md") {
260
- const l = s.children[0], c = o[o.length - 1], a = r + 1 < e.length ? $(e[r + 1], t) : null, u = a?.name === "p" ? a.children : null;
260
+ const l = s.children[0], c = o[o.length - 1], u = r + 1 < e.length ? $(e[r + 1], t) : null, a = u?.name === "p" ? u.children : null;
261
261
  if (c?.name === "p")
262
- c.children.push(l), u && (c.children.push(
263
- ...u
262
+ c.children.push(l), a && (c.children.push(
263
+ ...a
264
264
  ), r += 1);
265
265
  else {
266
266
  const d = [l];
267
- u && (d.push(...u), r += 1), o.push(h("p", d));
267
+ a && (d.push(...a), r += 1), o.push(h("p", d));
268
268
  }
269
269
  continue;
270
270
  }
@@ -281,19 +281,27 @@ function w(e, t, n = !1) {
281
281
  return n ? N(o) : o;
282
282
  }
283
283
  function ve(e, t, n) {
284
- const o = n.documentRoot ? le(n.documentRoot, e.depth) : ce(n.topLevelDivision, e.depth), r = h("title", D(e.children, n)), i = be(e, n), s = C(
285
- t,
286
- { ...n, depth: n.depth + 1 },
287
- !0
288
- ), l = N(s);
289
- return h(o, [r, ...l], i);
284
+ const o = n.documentRoot ? ce(n.documentRoot, e.depth) : ue(n.topLevelDivision, e.depth), r = h("title", x(e.children, n)), i = xe(e, n), s = { ...n, depth: n.depth + 1 }, { introduction: l, rest: c } = be(t, s), u = w(c, s, !0), a = N(u), d = l ? [r, l, ...a] : [r, ...a];
285
+ return h(o, d, i);
290
286
  }
291
287
  function ke(e) {
288
+ return e.type === "leafDirective" && X(e.name);
289
+ }
290
+ function be(e, t) {
291
+ const n = e.findIndex(
292
+ (l) => l.type === "heading" || ke(l)
293
+ );
294
+ if (n <= 0)
295
+ return { introduction: null, rest: e };
296
+ const o = e.slice(0, n), r = e.slice(n), i = D(o, t, !0);
297
+ return { introduction: i.length > 0 ? h("introduction", i) : null, rest: r };
298
+ }
299
+ function De(e) {
292
300
  const t = e.data;
293
301
  return t?.id ? { "xml:id": t.id } : void 0;
294
302
  }
295
- function be(e, t) {
296
- const n = ke(e), o = A(t);
303
+ function xe(e, t) {
304
+ const n = De(e), o = A(t);
297
305
  if (!(!n && !o))
298
306
  return { ...o, ...n };
299
307
  }
@@ -303,16 +311,16 @@ function A(e) {
303
311
  if (!(!e.topLevelAttributes || !t || t.done))
304
312
  return t.done = !0, e.topLevelAttributes;
305
313
  }
306
- const De = {
307
- paragraph: (e, t) => Y(e, t),
308
- blockquote: (e, t) => xe(e, t),
309
- list: (e, t) => Ce(e, t),
310
- code: (e, t) => Le(e),
311
- containerDirective: (e, t) => G(e, t),
312
- leafDirective: (e, t) => Ee(e, t)
314
+ const Ce = {
315
+ paragraph: (e, t) => G(e, t),
316
+ blockquote: (e, t) => we(e, t),
317
+ list: (e, t) => Le(e, t),
318
+ code: (e, t) => Se(e),
319
+ containerDirective: (e, t) => J(e, t),
320
+ leafDirective: (e, t) => qe(e, t)
313
321
  };
314
322
  function $(e, t) {
315
- const n = De[e.type];
323
+ const n = Ce[e.type];
316
324
  return n ? n(e, t) : (t.messages && t.messages.push({
317
325
  type: "warning",
318
326
  reason: `Unknown block type: ${e.type}`,
@@ -323,56 +331,56 @@ function $(e, t) {
323
331
  E(e, t)
324
332
  ));
325
333
  }
326
- function Y(e, t) {
327
- return h("p", D(e.children, t));
334
+ function G(e, t) {
335
+ return h("p", x(e.children, t));
328
336
  }
329
- function xe(e, t) {
337
+ function we(e, t) {
330
338
  const n = e.children.filter((o) => o.type === "paragraph").map((o) => {
331
339
  const r = {
332
340
  ...t,
333
341
  ancestors: [...t.ancestors, e],
334
342
  depth: t.depth + 1
335
343
  };
336
- return Y(o, r);
344
+ return G(o, r);
337
345
  });
338
346
  return h("blockquote", n);
339
347
  }
340
- function Ce(e, t) {
348
+ function Le(e, t) {
341
349
  const n = e.children.map((o) => {
342
350
  const r = {
343
351
  ...t,
344
352
  ancestors: [...t.ancestors, e],
345
353
  depth: t.depth + 1
346
354
  };
347
- return we(o, r);
355
+ return Ie(o, r);
348
356
  });
349
357
  return h(e.ordered ? "ol" : "ul", n);
350
358
  }
351
- function we(e, t) {
352
- const n = w(
359
+ function Ie(e, t) {
360
+ const n = D(
353
361
  e.children,
354
362
  t
355
363
  );
356
364
  return h("li", n);
357
365
  }
358
- function Le(e, t) {
366
+ function Se(e, t) {
359
367
  return g(
360
368
  "program",
361
369
  e.value,
362
370
  e.lang ? { language: e.lang } : void 0
363
371
  );
364
372
  }
365
- function Ie(e, t) {
373
+ function Ee(e, t) {
366
374
  const n = e.value.split(/\\\\|[\r\n]+/).map((o) => o.trim()).filter((o) => o.length > 0);
367
375
  return n.length > 1 ? h(
368
376
  "md",
369
377
  n.map((o) => g("mrow", o))
370
378
  ) : g("md", n[0] ?? "");
371
379
  }
372
- function Se(e, t) {
373
- return e.meta === "inline" ? g("m", e.value) : Ie(e);
380
+ function Te(e, t) {
381
+ return e.meta === "inline" ? g("m", e.value) : Ee(e);
374
382
  }
375
- function Ee(e, t) {
383
+ function qe(e, t) {
376
384
  const n = fe(e);
377
385
  return n || (t.messages && t.messages.push({
378
386
  type: "warning",
@@ -384,7 +392,7 @@ function Ee(e, t) {
384
392
  E(e, t)
385
393
  ));
386
394
  }
387
- function G(e, t) {
395
+ function J(e, t) {
388
396
  const n = he(e.name);
389
397
  if (!n)
390
398
  return t.messages && t.messages.push({
@@ -396,7 +404,7 @@ function G(e, t) {
396
404
  `unknown directive "${e.name}"`,
397
405
  E(e, t)
398
406
  );
399
- const o = qe(e), r = e.children, { title: i, body: s } = Te(
407
+ const o = $e(e), r = e.children, { title: i, body: s } = Ae(
400
408
  r,
401
409
  t
402
410
  ), l = {
@@ -410,44 +418,44 @@ function G(e, t) {
410
418
  i,
411
419
  s,
412
420
  l,
413
- (c, a) => $(c, a),
414
- (c, a) => G(c, a)
421
+ (c, u) => $(c, u),
422
+ (c, u) => J(c, u)
415
423
  );
416
424
  }
417
- function Te(e, t) {
425
+ function Ae(e, t) {
418
426
  const n = e[0];
419
427
  return n?.type === "paragraph" && n.data?.directiveLabel === !0 ? {
420
428
  title: h(
421
429
  "title",
422
- D(n.children, t)
430
+ x(n.children, t)
423
431
  ),
424
432
  body: e.slice(1)
425
433
  } : { title: null, body: e };
426
434
  }
427
- function qe(e) {
435
+ function $e(e) {
428
436
  const t = e.attributes ?? {}, n = {};
429
437
  for (const [o, r] of Object.entries(t))
430
438
  r != null && (n[o === "id" ? "xml:id" : o] = r);
431
439
  return Object.keys(n).length > 0 ? n : void 0;
432
440
  }
433
- function Ae(e, t) {
441
+ function Me(e, t) {
434
442
  return !t || e.position?.start?.offset === null || e.position?.start?.offset === void 0 ? "asterisk" : t.charAt(e.position.start.offset) === "_" ? "underscore" : "asterisk";
435
443
  }
436
- const $e = {
437
- text: (e, t) => V(e.value),
444
+ const Re = {
445
+ text: (e, t) => K(e.value),
438
446
  emphasis: (e, t) => {
439
- const o = Ae(e, t.source) === "underscore" ? "term" : "em";
440
- return h(o, D(e.children, t));
447
+ const o = Me(e, t.source) === "underscore" ? "term" : "em";
448
+ return h(o, x(e.children, t));
441
449
  },
442
- strong: (e, t) => h("alert", D(e.children, t)),
450
+ strong: (e, t) => h("alert", x(e.children, t)),
443
451
  inlineCode: (e, t) => g("c", e.value),
444
- math: (e, t) => Se(e)
452
+ math: (e, t) => Te(e)
445
453
  };
446
- function D(e, t) {
447
- return e.flatMap((n) => Me(n, t)).filter((n) => n !== null);
454
+ function x(e, t) {
455
+ return e.flatMap((n) => Fe(n, t)).filter((n) => n !== null);
448
456
  }
449
- function Me(e, t) {
450
- const n = $e[e.type];
457
+ function Fe(e, t) {
458
+ const n = Re[e.type];
451
459
  if (!n)
452
460
  return t.messages && t.messages.push({
453
461
  type: "warning",
@@ -461,17 +469,17 @@ function Me(e, t) {
461
469
  const o = { ...t, ancestors: [...t.ancestors, e] };
462
470
  return n(e, o);
463
471
  }
464
- const Re = [
472
+ const Ne = [
465
473
  // Display math (check these first, before single $)
466
474
  { open: "$$", close: "$$", isDisplay: !0 },
467
475
  { open: "\\[", close: "\\]", isDisplay: !0 },
468
476
  // Inline math
469
477
  { open: "$", close: "$", isDisplay: !1 },
470
478
  { open: "\\(", close: "\\)", isDisplay: !1 }
471
- ], J = "PTX_MATH_TOKEN_", T = new RegExp(`${J}(\\d+)`, "g");
472
- function Q(e, t) {
479
+ ], Q = "PTX_MATH_TOKEN_", T = new RegExp(`${Q}(\\d+)`, "g");
480
+ function ee(e, t) {
473
481
  let n = null;
474
- for (const o of Re) {
482
+ for (const o of Ne) {
475
483
  const r = e.indexOf(o.open, t);
476
484
  if (r === -1) continue;
477
485
  const i = e.indexOf(o.close, r + o.open.length);
@@ -482,7 +490,7 @@ function Q(e, t) {
482
490
  }
483
491
  return n;
484
492
  }
485
- function Fe(e, t) {
493
+ function Oe(e, t) {
486
494
  let n = t;
487
495
  for (; n < e.length; ) {
488
496
  const o = e.indexOf("`", n);
@@ -495,20 +503,20 @@ function Fe(e, t) {
495
503
  for (; l < e.length; ) {
496
504
  const c = e.indexOf(s, l);
497
505
  if (c === -1) break;
498
- const a = c + r;
499
- if (a >= e.length || e[a] !== "`")
500
- return { start: o, end: a };
506
+ const u = c + r;
507
+ if (u >= e.length || e[u] !== "`")
508
+ return { start: o, end: u };
501
509
  l = c + 1;
502
510
  }
503
511
  n = o + r;
504
512
  }
505
513
  return null;
506
514
  }
507
- function Ne(e) {
515
+ function _e(e) {
508
516
  const t = /* @__PURE__ */ new Map();
509
517
  let n = "", o = 0, r = 0;
510
518
  for (; o < e.length; ) {
511
- const i = Fe(e, o), s = Q(e, o);
519
+ const i = Oe(e, o), s = ee(e, o);
512
520
  if (i && (!s || i.start < s.index)) {
513
521
  n += e.substring(o, i.end), o = i.end;
514
522
  continue;
@@ -518,7 +526,7 @@ function Ne(e) {
518
526
  break;
519
527
  }
520
528
  n += e.substring(o, s.index);
521
- const l = `${J}${r}`;
529
+ const l = `${Q}${r}`;
522
530
  n += l, t.set(l, {
523
531
  type: "math",
524
532
  value: s.content,
@@ -527,11 +535,11 @@ function Ne(e) {
527
535
  }
528
536
  return { markdown: n, tokens: t };
529
537
  }
530
- function Oe(e) {
538
+ function Pe(e) {
531
539
  const t = [];
532
540
  let n = 0;
533
541
  for (; n < e.length; ) {
534
- const o = Q(e, n);
542
+ const o = ee(e, n);
535
543
  if (!o) {
536
544
  n < e.length && t.push({ type: "text", value: e.substring(n) });
537
545
  break;
@@ -547,7 +555,7 @@ function Oe(e) {
547
555
  }
548
556
  return t.length === 0 ? [{ type: "text", value: e }] : t;
549
557
  }
550
- function _e(e, t) {
558
+ function je(e, t) {
551
559
  const n = [];
552
560
  let o = 0;
553
561
  T.lastIndex = 0;
@@ -560,34 +568,34 @@ function _e(e, t) {
560
568
  }
561
569
  return o < e.length && n.push({ type: "text", value: e.substring(o) }), n.length === 0 ? [{ type: "text", value: e }] : n;
562
570
  }
563
- function ee(e) {
564
- X(e, "paragraph", (t) => {
571
+ function te(e) {
572
+ Z(e, "paragraph", (t) => {
565
573
  const n = t.children || [], o = [];
566
574
  for (const r of n)
567
575
  if (r.type === "text") {
568
- const i = Oe(r.value);
576
+ const i = Pe(r.value);
569
577
  o.push(...i);
570
578
  } else
571
579
  o.push(r);
572
580
  t.children = o;
573
581
  });
574
582
  }
575
- function Pe(e, t) {
576
- X(e, "paragraph", (n) => {
583
+ function Be(e, t) {
584
+ Z(e, "paragraph", (n) => {
577
585
  const o = n.children || [], r = [];
578
586
  for (const i of o)
579
587
  if (i.type === "text") {
580
- const s = _e(i.value, t);
588
+ const s = je(i.value, t);
581
589
  r.push(...s);
582
590
  } else
583
591
  r.push(i);
584
592
  n.children = r;
585
593
  });
586
594
  }
587
- const Rt = () => (e) => {
588
- ee(e);
595
+ const Nt = () => (e) => {
596
+ te(e);
589
597
  };
590
- function je(e) {
598
+ function ze(e) {
591
599
  const t = e.trim();
592
600
  if (!t.startsWith(":")) return null;
593
601
  let n = 0;
@@ -597,7 +605,7 @@ function je(e) {
597
605
  const o = t.slice(n).trim(), r = o.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);
598
606
  return o === "" ? { colons: n, label: null, lineIndex: -1, isOpen: !1 } : r ? { colons: n, label: r[0], lineIndex: -1, isOpen: !0 } : null;
599
607
  }
600
- function Be(e) {
608
+ function We(e) {
601
609
  const t = [], n = [];
602
610
  for (const o of e)
603
611
  if (o.isOpen) {
@@ -622,16 +630,16 @@ function Be(e) {
622
630
  }
623
631
  return n;
624
632
  }
625
- function te(e) {
633
+ function ne(e) {
626
634
  if (e.children.length === 0)
627
635
  e.finalColons = e.colons;
628
636
  else {
629
- const t = Math.max(...e.children.map(te));
637
+ const t = Math.max(...e.children.map(ne));
630
638
  e.finalColons = Math.max(e.colons, t + 1);
631
639
  }
632
640
  return e.finalColons;
633
641
  }
634
- function ze(e, t, n) {
642
+ function Ue(e, t, n) {
635
643
  const o = e.slice(), r = [], i = t.slice();
636
644
  for (; i.length > 0; ) {
637
645
  const s = i.shift();
@@ -639,38 +647,38 @@ function ze(e, t, n) {
639
647
  }
640
648
  for (const s of r) {
641
649
  if (s.openLineIndex >= 0) {
642
- const l = o[s.openLineIndex], c = l.match(/^:+/)?.[0].length || 3, a = l.slice(c);
643
- o[s.openLineIndex] = ":".repeat(s.finalColons) + a;
650
+ const l = o[s.openLineIndex], c = l.match(/^:+/)?.[0].length || 3, u = l.slice(c);
651
+ o[s.openLineIndex] = ":".repeat(s.finalColons) + u;
644
652
  }
645
653
  s.closeLineIndex !== null && s.closeLineIndex >= 0 && (o[s.closeLineIndex] = ":".repeat(s.finalColons));
646
654
  }
647
655
  return o;
648
656
  }
649
- function We(e) {
657
+ function He(e) {
650
658
  const t = e.split(`
651
659
  `), n = [];
652
660
  let o = !1, r = null;
653
661
  for (let l = 0; l < t.length; l++) {
654
- const c = t[l], u = c.trim().match(/^(`{3,}|~{3,})/);
655
- if (u) {
656
- const m = u[1];
662
+ const c = t[l], a = c.trim().match(/^(`{3,}|~{3,})/);
663
+ if (a) {
664
+ const m = a[1];
657
665
  o ? r && m[0] === r[0] && m.length >= r.length && (o = !1, r = null) : (o = !0, r = m);
658
666
  continue;
659
667
  }
660
668
  if (o)
661
669
  continue;
662
- const d = je(c);
670
+ const d = ze(c);
663
671
  d && n.push({ ...d, lineIndex: l });
664
672
  }
665
673
  if (n.length === 0)
666
674
  return e;
667
- const i = Be(n);
675
+ const i = We(n);
668
676
  for (const l of i)
669
- te(l);
670
- return ze(t, i).join(`
677
+ ne(l);
678
+ return Ue(t, i).join(`
671
679
  `);
672
680
  }
673
- function Ue(e) {
681
+ function Xe(e) {
674
682
  const t = e.trim();
675
683
  if (!t.endsWith(":")) return null;
676
684
  const n = t.slice(0, -1);
@@ -691,17 +699,17 @@ function M(e) {
691
699
  break;
692
700
  return t;
693
701
  }
694
- function He(e, t) {
702
+ function Ze(e, t) {
695
703
  const n = M(e[t]);
696
704
  for (let o = t + 1; o < e.length; o++)
697
- if (!ne(e[o]))
705
+ if (!oe(e[o]))
698
706
  return M(e[o]) > n;
699
707
  return !1;
700
708
  }
701
- function ne(e) {
709
+ function oe(e) {
702
710
  return e.trim() === "";
703
711
  }
704
- function Xe(e, t) {
712
+ function Ve(e, t) {
705
713
  let n = 0, o = 0;
706
714
  for (; o < e.length && n < t; )
707
715
  if (e[o] === " ")
@@ -712,7 +720,7 @@ function Xe(e, t) {
712
720
  break;
713
721
  return e.slice(o);
714
722
  }
715
- function Ze(e) {
723
+ function Ke(e) {
716
724
  const t = e.split(`
717
725
  `), n = [], o = {
718
726
  level: 0,
@@ -723,25 +731,25 @@ function Ze(e) {
723
731
  for (let r = 0; r < t.length; r++) {
724
732
  const i = t[r], s = i.trim(), l = M(i), c = s.match(/^(`{3,}|~{3,})/);
725
733
  if (c) {
726
- const u = c[1];
727
- o.inCodeFence ? o.codeFenceMarker && s.startsWith(o.codeFenceMarker) && (o.inCodeFence = !1, o.codeFenceMarker = null) : (o.inCodeFence = !0, o.codeFenceMarker = u), n.push(i);
734
+ const a = c[1];
735
+ o.inCodeFence ? o.codeFenceMarker && s.startsWith(o.codeFenceMarker) && (o.inCodeFence = !1, o.codeFenceMarker = null) : (o.inCodeFence = !0, o.codeFenceMarker = a), n.push(i);
728
736
  continue;
729
737
  }
730
738
  if (o.inCodeFence) {
731
739
  n.push(i);
732
740
  continue;
733
741
  }
734
- if (ne(i)) {
742
+ if (oe(i)) {
735
743
  n.push("");
736
744
  continue;
737
745
  }
738
- const a = Ue(s);
739
- if (a && He(t, r)) {
746
+ const u = Xe(s);
747
+ if (u && Ze(t, r)) {
740
748
  for (; o.openDirectives.length > 0 && !(o.openDirectives[o.openDirectives.length - 1].indentLevel < l); ) {
741
749
  const y = o.openDirectives.pop();
742
750
  y && n.push(":".repeat(y.colonCount));
743
751
  }
744
- 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;
752
+ const a = u.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/), d = a ? a[1].toLowerCase() + (a[2] || "") : u, m = o.openDirectives.length * 1 + 3;
745
753
  n.push(":".repeat(m) + d), o.openDirectives.push({
746
754
  label: d,
747
755
  indentLevel: l,
@@ -750,12 +758,12 @@ function Ze(e) {
750
758
  }), o.level = l;
751
759
  } else {
752
760
  for (; o.openDirectives.length > 0 && l <= o.openDirectives[o.openDirectives.length - 1].indentLevel; ) {
753
- const u = o.openDirectives.pop();
754
- u && n.push(":".repeat(u.colonCount));
761
+ const a = o.openDirectives.pop();
762
+ a && n.push(":".repeat(a.colonCount));
755
763
  }
756
764
  if (o.openDirectives.length > 0) {
757
- const u = o.openDirectives[o.openDirectives.length - 1];
758
- u.bodyBaseIndent < 0 && (u.bodyBaseIndent = l), n.push(Xe(i, u.bodyBaseIndent));
765
+ const a = o.openDirectives[o.openDirectives.length - 1];
766
+ a.bodyBaseIndent < 0 && (a.bodyBaseIndent = l), n.push(Ve(i, a.bodyBaseIndent));
759
767
  } else
760
768
  n.push(i);
761
769
  o.level = l;
@@ -768,49 +776,49 @@ function Ze(e) {
768
776
  return n.join(`
769
777
  `);
770
778
  }
771
- const Ve = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/, Ke = /^division:\s*(\S+)\s*$/m, Ye = /^xmlid:\s*(\S+)\s*$/m, Ge = /^xml:id:\s*(\S+)\s*$/m, Je = /^label:\s*(\S+)\s*$/m, Qe = /^component:\s*(\S+)\s*$/m;
772
- function et(e) {
773
- const t = e.match(Ve);
779
+ const Ye = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/, Ge = /^division:\s*(\S+)\s*$/m, Je = /^xmlid:\s*(\S+)\s*$/m, Qe = /^xml:id:\s*(\S+)\s*$/m, et = /^label:\s*(\S+)\s*$/m, tt = /^component:\s*(\S+)\s*$/m;
780
+ function nt(e) {
781
+ const t = e.match(Ye);
774
782
  if (!t)
775
783
  return { body: e };
776
- const n = t[1], o = e.slice(t[0].length), r = n.match(Ke)?.[1];
784
+ const n = t[1], o = e.slice(t[0].length), r = n.match(Ge)?.[1];
777
785
  let i, s;
778
- r && ae(r) ? (s = r, i = q(r)) : r && ue(r) && (i = r);
779
- const l = {}, c = n.match(Ye)?.[1] ?? n.match(Ge)?.[1], a = n.match(Je)?.[1], u = n.match(Qe)?.[1];
780
- return c && (l["xml:id"] = c), a && (l.label = a), u && (l.component = u), {
786
+ r && ae(r) ? (s = r, i = q(r)) : r && X(r) && (i = r);
787
+ const l = {}, c = n.match(Je)?.[1] ?? n.match(Qe)?.[1], u = n.match(et)?.[1], a = n.match(tt)?.[1];
788
+ return c && (l["xml:id"] = c), u && (l.label = u), a && (l.component = a), {
781
789
  division: i,
782
790
  documentRoot: s,
783
791
  attributes: Object.keys(l).length > 0 ? l : void 0,
784
792
  body: o
785
793
  };
786
794
  }
787
- const tt = function(e) {
795
+ const ot = function(e) {
788
796
  return function(n, o) {
789
797
  if (typeof o?.value == "string") {
790
- const r = et(o.value), i = e?.documentRoot ?? r.documentRoot, s = e?.topLevelDivision ?? r.division ?? (i ? q(i) : "chapter"), l = e?.topLevelAttributes ?? r.attributes, c = Ze(r.body), a = We(c), u = Ne(a), m = W().data("micromarkExtensions", [{ disable: { null: ["codeIndented"] } }]).use(U).use(H).parse(u.markdown);
791
- return Pe(m, u.tokens), P(m, u.markdown, {
798
+ const r = nt(o.value), i = e?.documentRoot ?? r.documentRoot, s = e?.topLevelDivision ?? r.division ?? (i ? q(i) : "chapter"), l = e?.topLevelAttributes ?? r.attributes, c = Ke(r.body), u = He(c), a = _e(u), m = W().data("micromarkExtensions", [{ disable: { null: ["codeIndented"] } }]).use(U).use(H).parse(a.markdown);
799
+ return Be(m, a.tokens), P(m, a.markdown, {
792
800
  topLevelDivision: s,
793
801
  documentRoot: i,
794
802
  topLevelAttributes: l
795
803
  });
796
804
  }
797
- return ee(n), P(n, void 0, {
805
+ return te(n), P(n, void 0, {
798
806
  topLevelDivision: e?.topLevelDivision ?? (e?.documentRoot ? q(e.documentRoot) : "chapter"),
799
807
  documentRoot: e?.documentRoot,
800
808
  topLevelAttributes: e?.topLevelAttributes
801
809
  });
802
810
  };
803
- }, nt = /["&'<>`]/g, ot = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, rt = (
811
+ }, rt = /["&'<>`]/g, it = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, st = (
804
812
  // eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
805
813
  /[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g
806
- ), it = /[|\\{}()[\]^$+*?.]/g, j = /* @__PURE__ */ new WeakMap();
807
- function st(e, t) {
814
+ ), lt = /[|\\{}()[\]^$+*?.]/g, j = /* @__PURE__ */ new WeakMap();
815
+ function ct(e, t) {
808
816
  if (e = e.replace(
809
- t.subset ? lt(t.subset) : nt,
817
+ t.subset ? ut(t.subset) : rt,
810
818
  o
811
819
  ), t.subset || t.escapeOnly)
812
820
  return e;
813
- return e.replace(ot, n).replace(rt, o);
821
+ return e.replace(it, n).replace(st, o);
814
822
  function n(r, i, s) {
815
823
  return t.format(
816
824
  (r.charCodeAt(0) - 55296) * 1024 + r.charCodeAt(1) - 56320 + 65536,
@@ -826,45 +834,45 @@ function st(e, t) {
826
834
  );
827
835
  }
828
836
  }
829
- function lt(e) {
837
+ function ut(e) {
830
838
  let t = j.get(e);
831
- return t || (t = ct(e), j.set(e, t)), t;
839
+ return t || (t = at(e), j.set(e, t)), t;
832
840
  }
833
- function ct(e) {
841
+ function at(e) {
834
842
  const t = [];
835
843
  let n = -1;
836
844
  for (; ++n < e.length; )
837
- t.push(e[n].replace(it, "\\$&"));
845
+ t.push(e[n].replace(lt, "\\$&"));
838
846
  return new RegExp("(?:" + t.join("|") + ")", "g");
839
847
  }
840
- function at(e) {
848
+ function pt(e) {
841
849
  return "&#x" + e.toString(16).toUpperCase() + ";";
842
850
  }
843
- function ut(e, t) {
844
- return st(e, Object.assign({ format: at }, t));
851
+ function ft(e, t) {
852
+ return ct(e, Object.assign({ format: pt }, t));
845
853
  }
846
- const pt = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
854
+ const ht = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
847
855
  function v(e, t, n) {
848
- const o = ft(e);
856
+ const o = dt(e);
849
857
  return n ? o.replace(n, r) : r(o);
850
858
  function r(i) {
851
- return ut(i, { subset: t });
859
+ return ft(i, { subset: t });
852
860
  }
853
861
  }
854
- function ft(e) {
855
- return String(e || "").replace(pt, "");
862
+ function dt(e) {
863
+ return String(e || "").replace(ht, "");
856
864
  }
857
- const ht = /]]>/g, dt = [">"];
858
- function mt(e) {
859
- return "<![CDATA[" + v(e.value, dt, ht) + "]]>";
865
+ const mt = /]]>/g, gt = [">"];
866
+ function yt(e) {
867
+ return "<![CDATA[" + v(e.value, gt, mt) + "]]>";
860
868
  }
861
- function gt(e) {
869
+ function vt(e) {
862
870
  return "<!--" + v(e.value, ["-"]) + "-->";
863
871
  }
864
- const yt = [" ", `
872
+ const kt = [" ", `
865
873
  `, " ", '"', "&", "'", "/", "<", "=", ">"];
866
874
  function I(e) {
867
- return v(e, yt);
875
+ return v(e, kt);
868
876
  }
869
877
  function B(e, t) {
870
878
  const n = String(e);
@@ -884,82 +892,82 @@ function R(e, t) {
884
892
  }
885
893
  return o + v(n, ["<", "&", o]) + o;
886
894
  }
887
- function vt(e, t) {
895
+ function bt(e, t) {
888
896
  const n = I(e.name), o = e.public, r = e.system;
889
897
  let i = "<!DOCTYPE";
890
898
  return n !== "" && (i += " " + n), o ? i += " PUBLIC " + R(o, t) : r && (i += " SYSTEM"), r && (i += " " + R(r, t)), i + ">";
891
899
  }
892
- const kt = {}.hasOwnProperty;
893
- function bt(e, t) {
894
- const n = I(e.name), o = ie(e, t), r = e.attributes || {}, i = o ? !1 : t.options.closeEmptyElements, s = [];
900
+ const Dt = {}.hasOwnProperty;
901
+ function xt(e, t) {
902
+ const n = I(e.name), o = se(e, t), r = e.attributes || {}, i = o ? !1 : t.options.closeEmptyElements, s = [];
895
903
  let l;
896
904
  for (l in r)
897
- if (kt.call(r, l)) {
905
+ if (Dt.call(r, l)) {
898
906
  const c = r[l];
899
907
  c != null && s.push(I(l) + "=" + R(c, t));
900
908
  }
901
909
  return "<" + n + (s.length === 0 ? "" : " " + s.join(" ")) + (i ? (t.options.tightClose ? "" : " ") + "/" : "") + ">" + o + (i ? "" : "</" + n + ">");
902
910
  }
903
- const Dt = /\?>/g, xt = [">"];
904
- function Ct(e) {
905
- const t = I(e.name) || "x", n = v(e.value, xt, Dt);
911
+ const Ct = /\?>/g, wt = [">"];
912
+ function Lt(e) {
913
+ const t = I(e.name) || "x", n = v(e.value, wt, Ct);
906
914
  return "<?" + t + (n ? " " + n : "") + "?>";
907
915
  }
908
- const wt = ["&", "<"];
909
- function oe(e) {
910
- return v(e.value, wt);
911
- }
912
- function Lt(e, t) {
913
- return t.options.allowDangerousXml ? e.value : oe(e);
914
- }
915
- const It = {}.hasOwnProperty, z = {
916
- cdata: mt,
917
- comment: gt,
918
- doctype: vt,
919
- element: bt,
920
- instruction: Ct,
921
- raw: Lt,
922
- root: ie,
923
- text: oe
916
+ const It = ["&", "<"];
917
+ function re(e) {
918
+ return v(e.value, It);
919
+ }
920
+ function St(e, t) {
921
+ return t.options.allowDangerousXml ? e.value : re(e);
922
+ }
923
+ const Et = {}.hasOwnProperty, z = {
924
+ cdata: yt,
925
+ comment: vt,
926
+ doctype: bt,
927
+ element: xt,
928
+ instruction: Lt,
929
+ raw: St,
930
+ root: se,
931
+ text: re
924
932
  };
925
- function re(e, t) {
933
+ function ie(e, t) {
926
934
  const n = e && e.type;
927
935
  if (!n)
928
936
  throw new Error("Expected node, not `" + e + "`");
929
- if (!It.call(z, n))
937
+ if (!Et.call(z, n))
930
938
  throw new Error("Cannot compile unknown node `" + n + "`");
931
939
  const o = z[n];
932
940
  return o(e, t);
933
941
  }
934
- function ie(e, t) {
942
+ function se(e, t) {
935
943
  const n = e && e.children || [];
936
944
  let o = -1;
937
945
  const r = [];
938
946
  for (; ++o < n.length; )
939
- r[o] = re(n[o], t);
947
+ r[o] = ie(n[o], t);
940
948
  return r.join("");
941
949
  }
942
- function St(e, t) {
950
+ function Tt(e, t) {
943
951
  const n = { options: t || {} };
944
952
  if (typeof n.options.quote == "string" && n.options.quote !== '"' && n.options.quote !== "'")
945
953
  throw new Error(
946
954
  "Invalid quote `" + n.options.quote + "`, expected `'` or `\"`"
947
955
  );
948
956
  const o = Array.isArray(e) ? { type: "root", children: e } : e;
949
- return re(o, n);
957
+ return ie(o, n);
950
958
  }
951
- function Ft(e, t) {
952
- const n = W().use(U).use(H).use(tt, t), o = n.parse(e), r = n.runSync(o, { value: e });
953
- return St(r.children, {
959
+ function Ot(e, t) {
960
+ const n = W().use(U).use(H).use(ot, t), o = n.parse(e), r = n.runSync(o, { value: e });
961
+ return Tt(r.children, {
954
962
  closeEmptyElements: !0,
955
963
  tightClose: !0
956
964
  });
957
965
  }
958
966
  export {
959
- Mt as DIRECTIVE_MAP,
960
- Z as PROOF_SOLUTION_NAMES,
961
- Ft as markdownToPretext,
967
+ Ft as DIRECTIVE_MAP,
968
+ V as PROOF_SOLUTION_NAMES,
969
+ Ot as markdownToPretext,
962
970
  P as mdastToPtxast,
963
- Rt as remarkMath,
964
- tt as remarkPretext
971
+ Nt as remarkMath,
972
+ ot as remarkPretext
965
973
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretextbook/remark-pretext",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "remark plugin to transform markdown-style PreTeXt directives into ptxast",
5
5
  "author": "Oscar Levin",
6
6
  "license": "MIT",