@pretextbook/remark-pretext 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("unified"),X=require("remark-parse"),Z=require("remark-directive"),v=require("@pretextbook/ptxast"),K=require("unist-util-visit");function ce(e,t={}){const n={};for(const[o,i]of Object.entries(t))i!=null&&(n[o]=i);return{type:"element",name:`plus:${e}`,attributes:n,children:[]}}function ue(e){const t=e.name?.trim();return t?ce(t,e.attributes??{}):null}const R={theorem:{type:"theorem",category:"theorem-like",requiresStatement:!0},lemma:{type:"lemma",category:"theorem-like",requiresStatement:!0},corollary:{type:"corollary",category:"theorem-like",requiresStatement:!0},proposition:{type:"proposition",category:"theorem-like",requiresStatement:!0},claim:{type:"claim",category:"theorem-like",requiresStatement:!0},fact:{type:"fact",category:"theorem-like",requiresStatement:!0},conjecture:{type:"conjecture",category:"theorem-like",requiresStatement:!0},axiom:{type:"axiom",category:"theorem-like",requiresStatement:!0},principle:{type:"principle",category:"theorem-like",requiresStatement:!0},hypothesis:{type:"hypothesis",category:"theorem-like",requiresStatement:!0},algorithm:{type:"algorithm",category:"theorem-like",requiresStatement:!0},definition:{type:"definition",category:"definition-like",requiresStatement:!0},notation:{type:"notation",category:"definition-like",requiresStatement:!0},remark:{type:"remark",category:"remark-like",requiresStatement:!1},note:{type:"note",category:"remark-like",requiresStatement:!1},observation:{type:"observation",category:"remark-like",requiresStatement:!1},warning:{type:"warning",category:"remark-like",requiresStatement:!1},insight:{type:"insight",category:"remark-like",requiresStatement:!1},assemblage:{type:"assemblage",category:"remark-like",requiresStatement:!1},example:{type:"example",category:"example-like",requiresStatement:!1},question:{type:"question",category:"example-like",requiresStatement:!1},problem:{type:"problem",category:"example-like",requiresStatement:!1},exercise:{type:"exercise",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},activity:{type:"activity",category:"example-like",requiresStatement:!1},exploration:{type:"exploration",category:"example-like",requiresStatement:!1},investigation:{type:"investigation",category:"example-like",requiresStatement:!1},project:{type:"project",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},task:{type:"task",category:"example-like",requiresStatement:!0,hasNestedTasks:!0},proof:{type:"proof",category:"proof-like",requiresStatement:!1},case:{type:"case",category:"proof-like",requiresStatement:!1},solution:{type:"solution",category:"solution-like",requiresStatement:!1},hint:{type:"hint",category:"solution-like",requiresStatement:!1},answer:{type:"answer",category:"solution-like",requiresStatement:!1}},ae=R;function pe(e){return R[e.toLowerCase()]}const j=new Set(Object.entries(R).filter(([e,t])=>t.category==="proof-like"||t.category==="solution-like").map(([e])=>e));function x(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function I(e){return e.type==="containerDirective"&&e.name==="task"}function fe(e){return e.type==="containerDirective"&&j.has(e.name)}function E(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(x("p",[n])):t.push(n);return t}function he(e,t,n,o,i,r,s){const l=[];if(n&&l.push(n),e.hasNestedTasks){const c=o.findIndex(I);if(c!==-1){const u=[];for(let f=0;f<o.length;f++)I(o[f])&&u.push(f);const a=u[u.length-1],p=o.slice(0,c),d=o.slice(c).filter(I),g=[],y=[],k=[];for(let f=c;f<o.length;f++){const m=o[f];if(!I(m)){if(f<a){g.push(m);continue}if(fe(m)){k.push(m);continue}y.push(m)}}if(g.length>0&&(i.messages??(i.messages=[])).push({type:"warning",reason:`Dropped ${g.length} non-task node(s) between task directives in ${e.type}.`,category:"dropped-content-between-tasks",position:g[0].position?.start}),p.length>0){const f=E(p.map(m=>r(m,i)).filter(m=>m!==null));f.length>0&&l.push(x("introduction",f))}for(const f of d){const m=s(f,i);m&&l.push(m)}if(y.length>0){const f=E(y.map(m=>r(m,i)).filter(m=>m!==null));f.length>0&&l.push(x("conclusion",f))}for(const f of k){const m=s(f,i);m&&l.push(m)}}else z(l,e,o,i,r,s)}else z(l,e,o,i,r,s);return x(e.type,l,t)}function z(e,t,n,o,i,r){if(t.requiresStatement){const s=[],l=[];for(const c of n)if(c.type==="containerDirective"&&j.has(c.name)){const u=r(c,o);u&&l.push(u)}else s.push(c);if(s.length>0){const c=E(s.map(u=>i(u,o)).filter(u=>u!==null));c.length>0&&e.push(x("statement",c))}e.push(...l)}else{const s=E(n.map(l=>i(l,o)).filter(l=>l!==null));e.push(...s)}}function q(e){return{type:"text",value:e}}function h(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function b(e,t,n){return h(e,[q(t)],n)}function Y(e){return{type:"comment",value:e.replace(/--/g,"- -")}}function $(e,t){const n=e?.position,o=n?.start?.offset,i=n?.end?.offset;return t.source&&o!=null&&i!=null?t.source.slice(o,i):""}function B(e,t,n){return h("TODO",[Y(`todo: ${t}`),b("pre",n)],{type:e})}function de(e,t,n){return h("TODO",[Y(`todo: ${t}`),b("c",n)],{type:e})}function A(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(h("p",[n])):t.push(n);return t}function O(e,t,n){return me(e,t,n).tree}function me(e,t,n){const o=[],i={ancestors:[],depth:0,messages:o,source:t,topLevelDivision:n?.topLevelDivision??"chapter",documentRoot:n?.documentRoot,topLevelAttributes:n?.topLevelAttributes,topLevelAttributesApplied:n?.topLevelAttributes?{done:!1}:void 0,topLevelTitle:n?.topLevelTitle},r=e.children;if(i.documentRoot){const a=S(i),p=i.topLevelTitle?h("title",[q(i.topLevelTitle)]):null,{introduction:d,rest:g}=T(r,i),y=L(g,i),k=[...p?[p]:[],...d?[d]:[],...y];return{tree:{type:"root",children:[h(i.documentRoot,k,a)]},messages:o}}if(v.isTitlelessDivisionType(i.topLevelDivision)){const a=S(i),p=A(L(r,{...i,depth:1},!0));return{tree:{type:"root",children:[h(i.topLevelDivision,p,a)]},messages:o}}if(i.topLevelTitle){const a=S(i),p=h("title",[q(i.topLevelTitle)]),d={...i,depth:i.depth+1,headingDepthOffset:(i.headingDepthOffset??0)+1},{introduction:g,rest:y}=T(r,d),k=A(L(y,d,!0)),f=g?[p,g,...k]:[p,...k];return{tree:{type:"root",children:[h(i.topLevelDivision,f,a)]},messages:o}}const{introduction:s,rest:l}=T(r,i),c=L(l,i);return{tree:{type:"root",children:s?[s,...c]:c},messages:o}}function L(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 w(e,t,n);const i=[];let r=null,s=[],l=[];const c=()=>{r&&(i.push(ge(r,l,t)),r=null,l=[])};for(const u of e)u.type==="heading"&&u.depth===o?(!r&&s.length>0&&(i.push(...w(s,t,n)),s=[]),c(),r=u,l=[]):r?l.push(u):s.push(u);return!r&&s.length>0&&i.push(...w(s,t,n)),c(),i}function w(e,t,n=!1){const o=[];for(let i=0;i<e.length;i+=1){const r=e[i],s=_(r,t);if(s!==null){if(s.name==="p"&&s.children.length===1&&s.children[0].name==="md"){const l=s.children[0],c=o[o.length-1],u=i+1<e.length?_(e[i+1],t):null,a=u?.name==="p"?u.children:null;if(c?.name==="p")c.children.push(l),a&&(c.children.push(...a),i+=1);else{const p=[l];a&&(p.push(...a),i+=1),o.push(h("p",p))}continue}if((s.name==="ul"||s.name==="ol")&&o.length>0){const l=o[o.length-1];if(l?.name==="p"){l.children.push(s);continue}}o.push(s)}}return n?A(o):o}function ge(e,t,n){const o=e.depth+(n.headingDepthOffset??0),i=n.documentRoot?v.divisionTypeAtRootDepth(n.documentRoot,o):v.divisionTypeAtRelativeDepth(n.topLevelDivision,o),r=h("title",D(e.children,n)),s=ke(e,n),l={...n,depth:n.depth+1},{introduction:c,rest:u}=T(t,l),a=L(u,l,!0),p=A(a),d=c?[r,c,...p]:[r,...p];return h(i,d,s)}function ye(e){return e.type==="leafDirective"&&v.isTopLevelDivisionType(e.name)}function T(e,t){const n=e.findIndex(l=>l.type==="heading"||ye(l));if(n<=0)return{introduction:null,rest:e};const o=e.slice(0,n),i=e.slice(n),r=w(o,t,!0);return{introduction:r.length>0?h("introduction",r):null,rest:i}}function ve(e){const t=e.data;return t?.id?{"xml:id":t.id}:void 0}function ke(e,t){const n=ve(e),o=S(t);if(!(!n&&!o))return{...o,...n}}function S(e){if(e.depth!==0)return;const t=e.topLevelAttributesApplied;if(!(!e.topLevelAttributes||!t||t.done))return t.done=!0,e.topLevelAttributes}const be={paragraph:(e,t)=>Q(e,t),blockquote:(e,t)=>De(e,t),list:(e,t)=>Ce(e,t),code:(e,t)=>xe(e),containerDirective:(e,t)=>G(e,t),leafDirective:(e,t)=>Se(e,t)};function _(e,t){const n=be[e.type];return n?n(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),B("unknown-block-type",`unknown block type "${e.type}"`,$(e,t)))}function Q(e,t){return h("p",D(e.children,t))}function De(e,t){const n=e.children.filter(o=>o.type==="paragraph").map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Q(o,i)});return h("blockquote",n)}function Ce(e,t){const n=e.children.map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Le(o,i)});return h(e.ordered?"ol":"ul",n)}function Le(e,t){const n=w(e.children,t);return h("li",n)}function xe(e,t){return b("program",e.value,e.lang?{language:e.lang}:void 0)}function we(e,t){const n=e.value.split(/\\\\|[\r\n]+/).map(o=>o.trim()).filter(o=>o.length>0);return n.length>1?h("md",n.map(o=>b("mrow",o))):b("md",n[0]??"")}function Ie(e,t){return e.meta==="inline"?b("m",e.value):we(e)}function Te(e,t){return h("url",D(e.children,t),{href:e.url})}function Se(e,t){const n=ue(e);return n||(t.messages&&t.messages.push({type:"warning",reason:"Unnamed leaf directive",category:"unknown-directive"}),B("unknown-directive","unnamed leaf directive",$(e,t)))}function G(e,t){const n=pe(e.name);if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),B("unknown-directive",`unknown directive "${e.name}"`,$(e,t));const o=qe(e),i=e.children,{title:r,body:s}=Ee(i,t),l={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return he(n,o,r,s,l,(c,u)=>_(c,u),(c,u)=>G(c,u))}function Ee(e,t){const n=e[0];return n?.type==="paragraph"&&n.data?.directiveLabel===!0?{title:h("title",D(n.children,t)),body:e.slice(1)}:{title:null,body:e}}function qe(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 Ae(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 Me={text:(e,t)=>q(e.value),emphasis:(e,t)=>{const o=Ae(e,t.source)==="underscore"?"term":"em";return h(o,D(e.children,t))},strong:(e,t)=>h("alert",D(e.children,t)),inlineCode:(e,t)=>b("c",e.value),math:(e,t)=>Ie(e),link:(e,t)=>Te(e,t)};function D(e,t){return e.flatMap(n=>Re(n,t)).filter(n=>n!==null)}function Re(e,t){const n=Me[e.type];if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),de("unknown-inline-type",`unknown inline type "${e.type}"`,$(e,t));const o={...t,ancestors:[...t.ancestors,e]};return n(e,o)}const $e=[{open:"$$",close:"$$",isDisplay:!0},{open:"\\[",close:"\\]",isDisplay:!0},{open:"$",close:"$",isDisplay:!1},{open:"\\(",close:"\\)",isDisplay:!1}],J="PTX_MATH_TOKEN_",F=new RegExp(`${J}(\\d+)`,"g");function ee(e,t){let n=null;for(const o of $e){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 Fe(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 Oe(e){const t=new Map;let n="",o=0,i=0;for(;o<e.length;){const r=Fe(e,o),s=ee(e,o);if(r&&(!s||r.start<s.index)){n+=e.substring(o,r.end),o=r.end;continue}if(!s){n+=e.substring(o);break}n+=e.substring(o,s.index);const l=`${J}${i}`;n+=l,t.set(l,{type:"math",value:s.content,meta:s.pattern.isDisplay?"display":"inline"}),o=s.index+s.pattern.open.length+s.content.length+s.pattern.close.length,i+=1}return{markdown:n,tokens:t}}function _e(e){const t=[];let n=0;for(;n<e.length;){const o=ee(e,n);if(!o){n<e.length&&t.push({type:"text",value:e.substring(n)});break}o.index>n&&t.push({type:"text",value:e.substring(n,o.index)}),t.push({type:"math",value:o.content,meta:o.pattern.isDisplay?"display":"inline"}),n=o.index+o.pattern.open.length+o.content.length+o.pattern.close.length}return t.length===0?[{type:"text",value:e}]:t}function Ne(e,t){const n=[];let o=0;F.lastIndex=0;let i=F.exec(e);for(;i;){const r=i.index,s=i[0];r>o&&n.push({type:"text",value:e.substring(o,r)});const l=t.get(s);l?n.push(l):n.push({type:"text",value:s}),o=r+s.length,i=F.exec(e)}return o<e.length&&n.push({type:"text",value:e.substring(o)}),n.length===0?[{type:"text",value:e}]:n}function te(e){K.visit(e,"paragraph",t=>{const n=t.children||[],o=[];for(const i of n)if(i.type==="text"){const r=_e(i.value);o.push(...r)}else o.push(i);t.children=o})}function Pe(e,t){K.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 je=()=>e=>{te(e)};function Be(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 ze(e){const t=[],n=[];for(const o of e)if(o.isOpen){const i={colons:o.colons,finalColons:o.colons,label:o.label,openLineIndex:o.lineIndex,closeLineIndex:null,children:[],parent:null};if(t.length>0){const r=t[t.length-1];i.parent=r,r.children.push(i)}else n.push(i);t.push(i)}else{const i=t[t.length-1];i&&i.colons===o.colons&&(i.closeLineIndex=o.lineIndex,t.pop())}return n}function ne(e){if(e.children.length===0)e.finalColons=e.colons;else{const t=Math.max(...e.children.map(ne));e.finalColons=Math.max(e.colons,t+1)}return e.finalColons}function Ue(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 We(e){const t=e.split(`
2
- `),n=[];let o=!1,i=null;for(let l=0;l<t.length;l++){const c=t[l],a=c.trim().match(/^(`{3,}|~{3,})/);if(a){const d=a[1];o?i&&d[0]===i[0]&&d.length>=i.length&&(o=!1,i=null):(o=!0,i=d);continue}if(o)continue;const p=Be(c);p&&n.push({...p,lineIndex:l})}if(n.length===0)return e;const r=ze(n);for(const l of r)ne(l);return Ue(t,r).join(`
3
- `)}function Ve(e){const t=e.trim();if(!t.endsWith(":"))return null;const n=t.slice(0,-1);if(!/^[a-zA-Z]/.test(n))return null;const o=n.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);if(!o)return null;const[,i,r]=o;return r&&!/^(\[[^\]]*\]|\{[^}]*\})*$/.test(r)||!R[i.toLowerCase()]?null:n}function N(e){let t=0;for(let n=0;n<e.length;n++)if(e[n]===" ")t+=1;else if(e[n]===" ")t+=4;else break;return t}function He(e,t){const n=N(e[t]);for(let o=t+1;o<e.length;o++)if(!oe(e[o]))return N(e[o])>n;return!1}function oe(e){return e.trim()===""}function Xe(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 Ze(e){const t=e.split(`
4
- `),n=[],o={level:0,openDirectives:[],inCodeFence:!1,codeFenceMarker:null};for(let i=0;i<t.length;i++){const r=t[i],s=r.trim(),l=N(r),c=s.match(/^(`{3,}|~{3,})/);if(c){const a=c[1];o.inCodeFence?o.codeFenceMarker&&s.startsWith(o.codeFenceMarker)&&(o.inCodeFence=!1,o.codeFenceMarker=null):(o.inCodeFence=!0,o.codeFenceMarker=a),n.push(r);continue}if(o.inCodeFence){n.push(r);continue}if(oe(r)){n.push("");continue}const u=Ve(s);if(u&&He(t,i)){for(;o.openDirectives.length>0&&!(o.openDirectives[o.openDirectives.length-1].indentLevel<l);){const y=o.openDirectives.pop();y&&n.push(":".repeat(y.colonCount))}const a=u.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/),p=a?a[1].toLowerCase()+(a[2]||""):u,d=o.openDirectives.length*1+3;n.push(":".repeat(d)+p),o.openDirectives.push({label:p,indentLevel:l,colonCount:d,bodyBaseIndent:-1}),o.level=l}else{for(;o.openDirectives.length>0&&l<=o.openDirectives[o.openDirectives.length-1].indentLevel;){const a=o.openDirectives.pop();a&&n.push(":".repeat(a.colonCount))}if(o.openDirectives.length>0){const a=o.openDirectives[o.openDirectives.length-1];a.bodyBaseIndent<0&&(a.bodyBaseIndent=l),n.push(Xe(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 Ke=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/,Ye=/^division:\s*(\S+)\s*$/m,Qe=/^id:\s*(\S+)\s*$/m,Ge=/^xmlid:\s*(\S+)\s*$/m,Je=/^xml:id:\s*(\S+)\s*$/m,et=/^label:\s*(\S+)\s*$/m,tt=/^component:\s*(\S+)\s*$/m,nt=/^title:\s*(.+?)\s*$/m;function ot(e){if(e.length>=2){const t=e[0],n=e[e.length-1];if(t==='"'&&n==='"'||t==="'"&&n==="'")return e.slice(1,-1)}return e}function it(e){const t=e.match(Ke);if(!t)return{body:e};const n=t[1],o=e.slice(t[0].length),i=n.match(Ye)?.[1];let r,s;i&&v.isRootDivisionType(i)?(s=i,r=v.rootChildDivision(i)):i&&v.isTopLevelDivisionType(i)&&(r=i);const l={},c=n.match(Qe)?.[1]??n.match(Ge)?.[1]??n.match(Je)?.[1],u=n.match(et)?.[1],a=n.match(tt)?.[1];c&&(l["xml:id"]=c),u&&(l.label=u),a&&(l.component=a);const p=n.match(nt)?.[1],d=p?ot(p):void 0;return{division:r,documentRoot:s,attributes:Object.keys(l).length>0?l:void 0,title:d,body:o}}const ie=function(e){return function(n,o){if(typeof o?.value=="string"){const i=it(o.value),r=e?.documentRoot??i.documentRoot,s=e?.topLevelDivision??i.division??(r?v.rootChildDivision(r):"chapter"),l=e?.topLevelAttributes??i.attributes,c=e?.topLevelTitle??i.title,u=Ze(i.body),a=We(u),p=Oe(a),g=H.unified().data("micromarkExtensions",[{disable:{null:["codeIndented"]}}]).use(X).use(Z).parse(p.markdown);return Pe(g,p.tokens),O(g,p.markdown,{topLevelDivision:s,documentRoot:r,topLevelAttributes:l,topLevelTitle:c})}return te(n),O(n,void 0,{topLevelDivision:e?.topLevelDivision??(e?.documentRoot?v.rootChildDivision(e.documentRoot):"chapter"),documentRoot:e?.documentRoot,topLevelAttributes:e?.topLevelAttributes,topLevelTitle:e?.topLevelTitle})}},rt=/["&'<>`]/g,st=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,lt=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,ct=/[|\\{}()[\]^$+*?.]/g,U=new WeakMap;function ut(e,t){if(e=e.replace(t.subset?at(t.subset):rt,o),t.subset||t.escapeOnly)return e;return e.replace(st,n).replace(lt,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 at(e){let t=U.get(e);return t||(t=pt(e),U.set(e,t)),t}function pt(e){const t=[];let n=-1;for(;++n<e.length;)t.push(e[n].replace(ct,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function ft(e){return"&#x"+e.toString(16).toUpperCase()+";"}function ht(e,t){return ut(e,Object.assign({format:ft},t))}const dt=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function C(e,t,n){const o=mt(e);return n?o.replace(n,i):i(o);function i(r){return ht(r,{subset:t})}}function mt(e){return String(e||"").replace(dt,"")}const gt=/]]>/g,yt=[">"];function vt(e){return"<![CDATA["+C(e.value,yt,gt)+"]]>"}function kt(e){return"<!--"+C(e.value,["-"])+"-->"}const bt=[" ",`
6
- `," ",'"',"&","'","/","<","=",">"];function M(e){return C(e,bt)}function W(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let o=0,i=n.indexOf(t);for(;i!==-1;)o++,i=n.indexOf(t,i+t.length);return o}function P(e,t){const n=String(e);let o=t.options.quote||'"';if(t.options.quoteSmart){const i=o==='"'?"'":'"';W(n,o)>W(n,i)&&(o=i)}return o+C(n,["<","&",o])+o}function Dt(e,t){const n=M(e.name),o=e.public,i=e.system;let r="<!DOCTYPE";return n!==""&&(r+=" "+n),o?r+=" PUBLIC "+P(o,t):i&&(r+=" SYSTEM"),i&&(r+=" "+P(i,t)),r+">"}const Ct={}.hasOwnProperty;function Lt(e,t){const n=M(e.name),o=le(e,t),i=e.attributes||{},r=o?!1:t.options.closeEmptyElements,s=[];let l;for(l in i)if(Ct.call(i,l)){const c=i[l];c!=null&&s.push(M(l)+"="+P(c,t))}return"<"+n+(s.length===0?"":" "+s.join(" "))+(r?(t.options.tightClose?"":" ")+"/":"")+">"+o+(r?"":"</"+n+">")}const xt=/\?>/g,wt=[">"];function It(e){const t=M(e.name)||"x",n=C(e.value,wt,xt);return"<?"+t+(n?" "+n:"")+"?>"}const Tt=["&","<"];function re(e){return C(e.value,Tt)}function St(e,t){return t.options.allowDangerousXml?e.value:re(e)}const Et={}.hasOwnProperty,V={cdata:vt,comment:kt,doctype:Dt,element:Lt,instruction:It,raw:St,root:le,text:re};function se(e,t){const n=e&&e.type;if(!n)throw new Error("Expected node, not `"+e+"`");if(!Et.call(V,n))throw new Error("Cannot compile unknown node `"+n+"`");const o=V[n];return o(e,t)}function le(e,t){const n=e&&e.children||[];let o=-1;const i=[];for(;++o<n.length;)i[o]=se(n[o],t);return i.join("")}function qt(e,t){const n={options:t||{}};if(typeof n.options.quote=="string"&&n.options.quote!=='"'&&n.options.quote!=="'")throw new Error("Invalid quote `"+n.options.quote+"`, expected `'` or `\"`");const o=Array.isArray(e)?{type:"root",children:e}:e;return se(o,n)}function At(e,t){const n=H.unified().use(X).use(Z).use(ie,t),o=n.parse(e),i=n.runSync(o,{value:e});return qt(i.children,{closeEmptyElements:!0,tightClose:!0})}exports.DIRECTIVE_MAP=ae;exports.PROOF_SOLUTION_NAMES=j;exports.markdownToPretext=At;exports.mdastToPtxast=O;exports.remarkMath=je;exports.remarkPretext=ie;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("unified"),X=require("remark-parse"),Z=require("remark-directive"),v=require("@pretextbook/ptxast"),K=require("unist-util-visit");function ce(e,t={}){const n={};for(const[o,i]of Object.entries(t))i!=null&&(n[o]=i);return{type:"element",name:`plus:${e}`,attributes:n,children:[]}}function ue(e){const t=e.name?.trim();return t?ce(t,e.attributes??{}):null}const M={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=M;function pe(e){return M[e.toLowerCase()]}const B=new Set(Object.entries(M).filter(([e,t])=>t.category==="proof-like"||t.category==="solution-like").map(([e])=>e));function x(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function I(e){return e.type==="containerDirective"&&e.name==="task"}function fe(e){return e.type==="containerDirective"&&B.has(e.name)}function E(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(x("p",[n])):t.push(n);return t}function he(e,t,n,o,i,r,s){const l=[];if(n&&l.push(n),e.hasNestedTasks){const c=o.findIndex(I);if(c!==-1){const u=[];for(let f=0;f<o.length;f++)I(o[f])&&u.push(f);const a=u[u.length-1],p=o.slice(0,c),d=o.slice(c).filter(I),g=[],y=[],k=[];for(let f=c;f<o.length;f++){const m=o[f];if(!I(m)){if(f<a){g.push(m);continue}if(fe(m)){k.push(m);continue}y.push(m)}}if(g.length>0&&(i.messages??(i.messages=[])).push({type:"warning",reason:`Dropped ${g.length} non-task node(s) between task directives in ${e.type}.`,category:"dropped-content-between-tasks",position:g[0].position?.start}),p.length>0){const f=E(p.map(m=>r(m,i)).filter(m=>m!==null));f.length>0&&l.push(x("introduction",f))}for(const f of d){const m=s(f,i);m&&l.push(m)}if(y.length>0){const f=E(y.map(m=>r(m,i)).filter(m=>m!==null));f.length>0&&l.push(x("conclusion",f))}for(const f of k){const m=s(f,i);m&&l.push(m)}}else z(l,e,o,i,r,s)}else z(l,e,o,i,r,s);return x(e.type,l,t)}function z(e,t,n,o,i,r){if(t.requiresStatement){const s=[],l=[];for(const c of n)if(c.type==="containerDirective"&&B.has(c.name)){const u=r(c,o);u&&l.push(u)}else s.push(c);if(s.length>0){const c=E(s.map(u=>i(u,o)).filter(u=>u!==null));c.length>0&&e.push(x("statement",c))}e.push(...l)}else{const s=E(n.map(l=>i(l,o)).filter(l=>l!==null));e.push(...s)}}function q(e){return{type:"text",value:e}}function h(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function b(e,t,n){return h(e,[q(t)],n)}function Y(e){return{type:"comment",value:e.replace(/--/g,"- -")}}function $(e,t){const n=e?.position,o=n?.start?.offset,i=n?.end?.offset;return t.source&&o!=null&&i!=null?t.source.slice(o,i):""}function j(e,t,n){return h("TODO",[Y(`todo: ${t}`),b("pre",n)],{type:e})}function de(e,t,n){return h("TODO",[Y(`todo: ${t}`),b("c",n)],{type:e})}function A(e){const t=[];for(const n of e)n.name==="ul"||n.name==="ol"?t.length>0&&t[t.length-1]?.name==="p"?t[t.length-1].children.push(n):t.push(h("p",[n])):t.push(n);return t}function O(e,t,n){return me(e,t,n).tree}function me(e,t,n){const o=[],i={ancestors:[],depth:0,messages:o,source:t,topLevelDivision:n?.topLevelDivision??"chapter",documentRoot:n?.documentRoot,topLevelAttributes:n?.topLevelAttributes,topLevelAttributesApplied:n?.topLevelAttributes?{done:!1}:void 0,topLevelTitle:n?.topLevelTitle},r=e.children;if(i.documentRoot){const a=S(i),p=i.topLevelTitle?h("title",[q(i.topLevelTitle)]):null,{introduction:d,rest:g}=T(r,i),y=i.documentRoot==="slideshow"&&ge(g)?ye(g,i):D(g,i),k=[...p?[p]:[],...d?[d]:[],...y];return{tree:{type:"root",children:[h(i.documentRoot,k,a)]},messages:o}}if(v.isTitlelessDivisionType(i.topLevelDivision)){const a=S(i),p=A(D(r,{...i,depth:1},!0));return{tree:{type:"root",children:[h(i.topLevelDivision,p,a)]},messages:o}}if(i.topLevelTitle){const a=S(i),p=h("title",[q(i.topLevelTitle)]),d={...i,depth:i.depth+1,headingDepthOffset:(i.headingDepthOffset??0)+1},{introduction:g,rest:y}=T(r,d),k=A(D(y,d,!0)),f=g?[p,g,...k]:[p,...k];return{tree:{type:"root",children:[h(i.topLevelDivision,f,a)]},messages:o}}const{introduction:s,rest:l}=T(r,i),c=D(l,i);return{tree:{type:"root",children:s?[s,...c]:c},messages:o}}function ge(e){return e.some(t=>t.type==="thematicBreak")}function ye(e,t){return D(e,t)}function D(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 w(e,t,n);const i=[];let r=null,s=[],l=[];const c=()=>{r&&(i.push(ve(r,l,t)),r=null,l=[])};for(const u of e)u.type==="heading"&&u.depth===o?(!r&&s.length>0&&(i.push(...w(s,t,n)),s=[]),c(),r=u,l=[]):r?l.push(u):s.push(u);return!r&&s.length>0&&i.push(...w(s,t,n)),c(),i}function w(e,t,n=!1){const o=[];for(let i=0;i<e.length;i+=1){const r=e[i],s=_(r,t);if(s!==null){if(s.name==="p"&&s.children.length===1&&s.children[0].name==="md"){const l=s.children[0],c=o[o.length-1],u=i+1<e.length?_(e[i+1],t):null,a=u?.name==="p"?u.children:null;if(c?.name==="p")c.children.push(l),a&&(c.children.push(...a),i+=1);else{const p=[l];a&&(p.push(...a),i+=1),o.push(h("p",p))}continue}if((s.name==="ul"||s.name==="ol")&&o.length>0){const l=o[o.length-1];if(l?.name==="p"){l.children.push(s);continue}}o.push(s)}}return n?A(o):o}function ve(e,t,n){const o=e.depth+(n.headingDepthOffset??0),i=n.documentRoot?v.divisionTypeAtRootDepth(n.documentRoot,o):v.divisionTypeAtRelativeDepth(n.topLevelDivision,o),r=h("title",C(e.children,n)),s=De(e,n),l={...n,depth:n.depth+1},{introduction:c,rest:u}=T(t,l),a=D(u,l,!0),p=A(a),d=c?[r,c,...p]:[r,...p];return h(i,d,s)}function ke(e){return e.type==="leafDirective"&&v.isTopLevelDivisionType(e.name)}function T(e,t){const n=e.findIndex(l=>l.type==="heading"||ke(l));if(n<=0)return{introduction:null,rest:e};const o=e.slice(0,n),i=e.slice(n),r=w(o,t,!0);return{introduction:r.length>0?h("introduction",r):null,rest:i}}function be(e){const t=e.data;return t?.id?{"xml:id":t.id}:void 0}function De(e,t){const n=be(e),o=S(t);if(!(!n&&!o))return{...o,...n}}function S(e){if(e.depth!==0)return;const t=e.topLevelAttributesApplied;if(!(!e.topLevelAttributes||!t||t.done))return t.done=!0,e.topLevelAttributes}const Ce={paragraph:(e,t)=>Q(e,t),blockquote:(e,t)=>Le(e,t),list:(e,t)=>xe(e,t),code:(e,t)=>Ie(e),containerDirective:(e,t)=>G(e,t),leafDirective:(e,t)=>qe(e,t)};function _(e,t){const n=Ce[e.type];return n?n(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),j("unknown-block-type",`unknown block type "${e.type}"`,$(e,t)))}function Q(e,t){return h("p",C(e.children,t))}function Le(e,t){const n=e.children.filter(o=>o.type==="paragraph").map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Q(o,i)});return h("blockquote",n)}function xe(e,t){const n=e.children.map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return we(o,i)});return h(e.ordered?"ol":"ul",n)}function we(e,t){const n=w(e.children,t);return h("li",n)}function Ie(e,t){return b("program",e.value,e.lang?{language:e.lang}:void 0)}function Te(e,t){const n=e.value.split(/\\\\|[\r\n]+/).map(o=>o.trim()).filter(o=>o.length>0);return n.length>1?h("md",n.map(o=>b("mrow",o))):b("md",n[0]??"")}function Se(e,t){return e.meta==="inline"?b("m",e.value):Te(e)}function Ee(e,t){return h("url",C(e.children,t),{href:e.url})}function qe(e,t){const n=ue(e);return n||(t.messages&&t.messages.push({type:"warning",reason:"Unnamed leaf directive",category:"unknown-directive"}),j("unknown-directive","unnamed leaf directive",$(e,t)))}function G(e,t){const n=pe(e.name);if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),j("unknown-directive",`unknown directive "${e.name}"`,$(e,t));const o=Re(e),i=e.children,{title:r,body:s}=Ae(i,t),l={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return he(n,o,r,s,l,(c,u)=>_(c,u),(c,u)=>G(c,u))}function Ae(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 Re(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 Me(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 $e={text:(e,t)=>q(e.value),emphasis:(e,t)=>{const o=Me(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)=>b("c",e.value),math:(e,t)=>Se(e),link:(e,t)=>Ee(e,t)};function C(e,t){return e.flatMap(n=>Fe(n,t)).filter(n=>n!==null)}function Fe(e,t){const n=$e[e.type];if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),de("unknown-inline-type",`unknown inline type "${e.type}"`,$(e,t));const o={...t,ancestors:[...t.ancestors,e]};return n(e,o)}const Oe=[{open:"$$",close:"$$",isDisplay:!0},{open:"\\[",close:"\\]",isDisplay:!0},{open:"$",close:"$",isDisplay:!1},{open:"\\(",close:"\\)",isDisplay:!1}],J="PTX_MATH_TOKEN_",F=new RegExp(`${J}(\\d+)`,"g");function ee(e,t){let n=null;for(const o of Oe){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 Ne(e){const t=new Map;let n="",o=0,i=0;for(;o<e.length;){const r=_e(e,o),s=ee(e,o);if(r&&(!s||r.start<s.index)){n+=e.substring(o,r.end),o=r.end;continue}if(!s){n+=e.substring(o);break}n+=e.substring(o,s.index);const l=`${J}${i}`;n+=l,t.set(l,{type:"math",value:s.content,meta:s.pattern.isDisplay?"display":"inline"}),o=s.index+s.pattern.open.length+s.content.length+s.pattern.close.length,i+=1}return{markdown:n,tokens:t}}function Pe(e){const t=[];let n=0;for(;n<e.length;){const o=ee(e,n);if(!o){n<e.length&&t.push({type:"text",value:e.substring(n)});break}o.index>n&&t.push({type:"text",value:e.substring(n,o.index)}),t.push({type:"math",value:o.content,meta:o.pattern.isDisplay?"display":"inline"}),n=o.index+o.pattern.open.length+o.content.length+o.pattern.close.length}return t.length===0?[{type:"text",value:e}]:t}function Be(e,t){const n=[];let o=0;F.lastIndex=0;let i=F.exec(e);for(;i;){const r=i.index,s=i[0];r>o&&n.push({type:"text",value:e.substring(o,r)});const l=t.get(s);l?n.push(l):n.push({type:"text",value:s}),o=r+s.length,i=F.exec(e)}return o<e.length&&n.push({type:"text",value:e.substring(o)}),n.length===0?[{type:"text",value:e}]:n}function te(e){K.visit(e,"paragraph",t=>{const n=t.children||[],o=[];for(const i of n)if(i.type==="text"){const r=Pe(i.value);o.push(...r)}else o.push(i);t.children=o})}function je(e,t){K.visit(e,"paragraph",n=>{const o=n.children||[],i=[];for(const r of o)if(r.type==="text"){const s=Be(r.value,t);i.push(...s)}else i.push(r);n.children=i})}const ze=()=>e=>{te(e)};function Ue(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 We(e){const t=[],n=[];for(const o of e)if(o.isOpen){const i={colons:o.colons,finalColons:o.colons,label:o.label,openLineIndex:o.lineIndex,closeLineIndex:null,children:[],parent:null};if(t.length>0){const r=t[t.length-1];i.parent=r,r.children.push(i)}else n.push(i);t.push(i)}else{const i=t[t.length-1];i&&i.colons===o.colons&&(i.closeLineIndex=o.lineIndex,t.pop())}return n}function ne(e){if(e.children.length===0)e.finalColons=e.colons;else{const t=Math.max(...e.children.map(ne));e.finalColons=Math.max(e.colons,t+1)}return e.finalColons}function Ve(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 He(e){const t=e.split(`
2
+ `),n=[];let o=!1,i=null;for(let l=0;l<t.length;l++){const c=t[l],a=c.trim().match(/^(`{3,}|~{3,})/);if(a){const d=a[1];o?i&&d[0]===i[0]&&d.length>=i.length&&(o=!1,i=null):(o=!0,i=d);continue}if(o)continue;const p=Ue(c);p&&n.push({...p,lineIndex:l})}if(n.length===0)return e;const r=We(n);for(const l of r)ne(l);return Ve(t,r).join(`
3
+ `)}function Xe(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)||!M[i.toLowerCase()]?null:n}function N(e){let t=0;for(let n=0;n<e.length;n++)if(e[n]===" ")t+=1;else if(e[n]===" ")t+=4;else break;return t}function Ze(e,t){const n=N(e[t]);for(let o=t+1;o<e.length;o++)if(!oe(e[o]))return N(e[o])>n;return!1}function oe(e){return e.trim()===""}function Ke(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 Ye(e){const t=e.split(`
4
+ `),n=[],o={level:0,openDirectives:[],inCodeFence:!1,codeFenceMarker:null};for(let i=0;i<t.length;i++){const r=t[i],s=r.trim(),l=N(r),c=s.match(/^(`{3,}|~{3,})/);if(c){const a=c[1];o.inCodeFence?o.codeFenceMarker&&s.startsWith(o.codeFenceMarker)&&(o.inCodeFence=!1,o.codeFenceMarker=null):(o.inCodeFence=!0,o.codeFenceMarker=a),n.push(r);continue}if(o.inCodeFence){n.push(r);continue}if(oe(r)){n.push("");continue}const u=Xe(s);if(u&&Ze(t,i)){for(;o.openDirectives.length>0&&!(o.openDirectives[o.openDirectives.length-1].indentLevel<l);){const y=o.openDirectives.pop();y&&n.push(":".repeat(y.colonCount))}const a=u.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/),p=a?a[1].toLowerCase()+(a[2]||""):u,d=o.openDirectives.length*1+3;n.push(":".repeat(d)+p),o.openDirectives.push({label:p,indentLevel:l,colonCount:d,bodyBaseIndent:-1}),o.level=l}else{for(;o.openDirectives.length>0&&l<=o.openDirectives[o.openDirectives.length-1].indentLevel;){const a=o.openDirectives.pop();a&&n.push(":".repeat(a.colonCount))}if(o.openDirectives.length>0){const a=o.openDirectives[o.openDirectives.length-1];a.bodyBaseIndent<0&&(a.bodyBaseIndent=l),n.push(Ke(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 Qe=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/,Ge=/^division:\s*(\S+)\s*$/m,Je=/^id:\s*(\S+)\s*$/m,et=/^xmlid:\s*(\S+)\s*$/m,tt=/^xml:id:\s*(\S+)\s*$/m,nt=/^label:\s*(\S+)\s*$/m,ot=/^component:\s*(\S+)\s*$/m,it=/^title:\s*(.+?)\s*$/m;function rt(e){if(e.length>=2){const t=e[0],n=e[e.length-1];if(t==='"'&&n==='"'||t==="'"&&n==="'")return e.slice(1,-1)}return e}function st(e){const t=e.match(Qe);if(!t)return{body:e};const n=t[1],o=e.slice(t[0].length),i=n.match(Ge)?.[1];let r,s;i&&v.isRootDivisionType(i)?(s=i,r=v.rootChildDivision(i)):i&&v.isTopLevelDivisionType(i)&&(r=i);const l={},c=n.match(Je)?.[1]??n.match(et)?.[1]??n.match(tt)?.[1],u=n.match(nt)?.[1],a=n.match(ot)?.[1];c&&(l["xml:id"]=c),u&&(l.label=u),a&&(l.component=a);const p=n.match(it)?.[1],d=p?rt(p):void 0;return{division:r,documentRoot:s,attributes:Object.keys(l).length>0?l:void 0,title:d,body:o}}const ie=function(e){return function(n,o){if(typeof o?.value=="string"){const i=st(o.value),r=e?.documentRoot??i.documentRoot,s=e?.topLevelDivision??i.division??(r?v.rootChildDivision(r):"chapter"),l=e?.topLevelAttributes??i.attributes,c=e?.topLevelTitle??i.title,u=Ye(i.body),a=He(u),p=Ne(a),g=H.unified().data("micromarkExtensions",[{disable:{null:["codeIndented"]}}]).use(X).use(Z).parse(p.markdown);return je(g,p.tokens),O(g,p.markdown,{topLevelDivision:s,documentRoot:r,topLevelAttributes:l,topLevelTitle:c})}return te(n),O(n,void 0,{topLevelDivision:e?.topLevelDivision??(e?.documentRoot?v.rootChildDivision(e.documentRoot):"chapter"),documentRoot:e?.documentRoot,topLevelAttributes:e?.topLevelAttributes,topLevelTitle:e?.topLevelTitle})}},lt=/["&'<>`]/g,ct=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,ut=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,at=/[|\\{}()[\]^$+*?.]/g,U=new WeakMap;function pt(e,t){if(e=e.replace(t.subset?ft(t.subset):lt,o),t.subset||t.escapeOnly)return e;return e.replace(ct,n).replace(ut,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 ft(e){let t=U.get(e);return t||(t=ht(e),U.set(e,t)),t}function ht(e){const t=[];let n=-1;for(;++n<e.length;)t.push(e[n].replace(at,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function dt(e){return"&#x"+e.toString(16).toUpperCase()+";"}function mt(e,t){return pt(e,Object.assign({format:dt},t))}const gt=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function L(e,t,n){const o=yt(e);return n?o.replace(n,i):i(o);function i(r){return mt(r,{subset:t})}}function yt(e){return String(e||"").replace(gt,"")}const vt=/]]>/g,kt=[">"];function bt(e){return"<![CDATA["+L(e.value,kt,vt)+"]]>"}function Dt(e){return"<!--"+L(e.value,["-"])+"-->"}const Ct=[" ",`
6
+ `," ",'"',"&","'","/","<","=",">"];function R(e){return L(e,Ct)}function W(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let o=0,i=n.indexOf(t);for(;i!==-1;)o++,i=n.indexOf(t,i+t.length);return o}function P(e,t){const n=String(e);let o=t.options.quote||'"';if(t.options.quoteSmart){const i=o==='"'?"'":'"';W(n,o)>W(n,i)&&(o=i)}return o+L(n,["<","&",o])+o}function Lt(e,t){const n=R(e.name),o=e.public,i=e.system;let r="<!DOCTYPE";return n!==""&&(r+=" "+n),o?r+=" PUBLIC "+P(o,t):i&&(r+=" SYSTEM"),i&&(r+=" "+P(i,t)),r+">"}const xt={}.hasOwnProperty;function wt(e,t){const n=R(e.name),o=le(e,t),i=e.attributes||{},r=o?!1:t.options.closeEmptyElements,s=[];let l;for(l in i)if(xt.call(i,l)){const c=i[l];c!=null&&s.push(R(l)+"="+P(c,t))}return"<"+n+(s.length===0?"":" "+s.join(" "))+(r?(t.options.tightClose?"":" ")+"/":"")+">"+o+(r?"":"</"+n+">")}const It=/\?>/g,Tt=[">"];function St(e){const t=R(e.name)||"x",n=L(e.value,Tt,It);return"<?"+t+(n?" "+n:"")+"?>"}const Et=["&","<"];function re(e){return L(e.value,Et)}function qt(e,t){return t.options.allowDangerousXml?e.value:re(e)}const At={}.hasOwnProperty,V={cdata:bt,comment:Dt,doctype:Lt,element:wt,instruction:St,raw:qt,root:le,text:re};function se(e,t){const n=e&&e.type;if(!n)throw new Error("Expected node, not `"+e+"`");if(!At.call(V,n))throw new Error("Cannot compile unknown node `"+n+"`");const o=V[n];return o(e,t)}function le(e,t){const n=e&&e.children||[];let o=-1;const i=[];for(;++o<n.length;)i[o]=se(n[o],t);return i.join("")}function Rt(e,t){const n={options:t||{}};if(typeof n.options.quote=="string"&&n.options.quote!=='"'&&n.options.quote!=="'")throw new Error("Invalid quote `"+n.options.quote+"`, expected `'` or `\"`");const o=Array.isArray(e)?{type:"root",children:e}:e;return se(o,n)}function Mt(e,t){const n=H.unified().use(X).use(Z).use(ie,t),o=n.parse(e),i=n.runSync(o,{value:e});return Rt(i.children,{closeEmptyElements:!0,tightClose:!0})}exports.DIRECTIVE_MAP=ae;exports.PROOF_SOLUTION_NAMES=B;exports.markdownToPretext=Mt;exports.mdastToPtxast=O;exports.remarkMath=ze;exports.remarkPretext=ie;
package/dist/index.js CHANGED
@@ -158,7 +158,7 @@ const $ = {
158
158
  category: "solution-like",
159
159
  requiresStatement: !1
160
160
  }
161
- }, Pt = $;
161
+ }, jt = $;
162
162
  function de(e) {
163
163
  return $[e.toLowerCase()];
164
164
  }
@@ -236,7 +236,7 @@ function ge(e, t, n, o, i, r, s) {
236
236
  m && l.push(m);
237
237
  }
238
238
  } else
239
- j(
239
+ B(
240
240
  l,
241
241
  e,
242
242
  o,
@@ -245,7 +245,7 @@ function ge(e, t, n, o, i, r, s) {
245
245
  s
246
246
  );
247
247
  } else
248
- j(
248
+ B(
249
249
  l,
250
250
  e,
251
251
  o,
@@ -255,7 +255,7 @@ function ge(e, t, n, o, i, r, s) {
255
255
  );
256
256
  return L(e.type, l, t);
257
257
  }
258
- function j(e, t, n, o, i, r) {
258
+ function B(e, t, n, o, i, r) {
259
259
  if (t.requiresStatement) {
260
260
  const s = [], l = [];
261
261
  for (const c of n)
@@ -315,7 +315,7 @@ function q(e) {
315
315
  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);
316
316
  return t;
317
317
  }
318
- function B(e, t, n) {
318
+ function j(e, t, n) {
319
319
  return ve(e, t, n).tree;
320
320
  }
321
321
  function ve(e, t, n) {
@@ -331,7 +331,7 @@ function ve(e, t, n) {
331
331
  topLevelTitle: n?.topLevelTitle
332
332
  }, r = e.children;
333
333
  if (i.documentRoot) {
334
- const a = S(i), p = i.topLevelTitle ? h("title", [E(i.topLevelTitle)]) : null, { introduction: d, rest: g } = I(r, i), y = C(g, i), v = [
334
+ const a = S(i), p = i.topLevelTitle ? h("title", [E(i.topLevelTitle)]) : null, { introduction: d, rest: g } = I(r, i), y = i.documentRoot === "slideshow" && ke(g) ? be(g, i) : b(g, i), v = [
335
335
  ...p ? [p] : [],
336
336
  ...d ? [d] : [],
337
337
  ...y
@@ -343,7 +343,7 @@ function ve(e, t, n) {
343
343
  }
344
344
  if (ce(i.topLevelDivision)) {
345
345
  const a = S(i), p = q(
346
- C(r, { ...i, depth: 1 }, !0)
346
+ b(r, { ...i, depth: 1 }, !0)
347
347
  );
348
348
  return {
349
349
  tree: { type: "root", children: [h(i.topLevelDivision, p, a)] },
@@ -356,20 +356,26 @@ function ve(e, t, n) {
356
356
  depth: i.depth + 1,
357
357
  headingDepthOffset: (i.headingDepthOffset ?? 0) + 1
358
358
  }, { introduction: g, rest: y } = I(r, d), v = q(
359
- C(y, d, !0)
359
+ b(y, d, !0)
360
360
  ), f = g ? [p, g, ...v] : [p, ...v];
361
361
  return {
362
362
  tree: { type: "root", children: [h(i.topLevelDivision, f, a)] },
363
363
  messages: o
364
364
  };
365
365
  }
366
- const { introduction: s, rest: l } = I(r, i), c = C(l, i);
366
+ const { introduction: s, rest: l } = I(r, i), c = b(l, i);
367
367
  return {
368
368
  tree: { type: "root", children: s ? [s, ...c] : c },
369
369
  messages: o
370
370
  };
371
371
  }
372
- function C(e, t, n = !1) {
372
+ function ke(e) {
373
+ return e.some((t) => t.type === "thematicBreak");
374
+ }
375
+ function be(e, t) {
376
+ return b(e, t);
377
+ }
378
+ function b(e, t, n = !1) {
373
379
  let o = 7;
374
380
  for (const u of e)
375
381
  u.type === "heading" && (o = Math.min(o, u.depth));
@@ -378,7 +384,7 @@ function C(e, t, n = !1) {
378
384
  const i = [];
379
385
  let r = null, s = [], l = [];
380
386
  const c = () => {
381
- r && (i.push(ke(r, l, t)), r = null, l = []);
387
+ r && (i.push(De(r, l, t)), r = null, l = []);
382
388
  };
383
389
  for (const u of e)
384
390
  u.type === "heading" && u.depth === o ? (!r && s.length > 0 && (i.push(
@@ -417,28 +423,28 @@ function x(e, t, n = !1) {
417
423
  }
418
424
  return n ? q(o) : o;
419
425
  }
420
- function ke(e, t, n) {
421
- const o = e.depth + (n.headingDepthOffset ?? 0), i = n.documentRoot ? ue(n.documentRoot, o) : ae(n.topLevelDivision, o), r = h("title", b(e.children, n)), s = Ce(e, n), l = { ...n, depth: n.depth + 1 }, { introduction: c, rest: u } = I(t, l), a = C(u, l, !0), p = q(a), d = c ? [r, c, ...p] : [r, ...p];
426
+ function De(e, t, n) {
427
+ const o = e.depth + (n.headingDepthOffset ?? 0), i = n.documentRoot ? ue(n.documentRoot, o) : ae(n.topLevelDivision, o), r = h("title", D(e.children, n)), s = xe(e, n), l = { ...n, depth: n.depth + 1 }, { introduction: c, rest: u } = I(t, l), a = b(u, l, !0), p = q(a), d = c ? [r, c, ...p] : [r, ...p];
422
428
  return h(i, d, s);
423
429
  }
424
- function be(e) {
430
+ function Ce(e) {
425
431
  return e.type === "leafDirective" && V(e.name);
426
432
  }
427
433
  function I(e, t) {
428
434
  const n = e.findIndex(
429
- (l) => l.type === "heading" || be(l)
435
+ (l) => l.type === "heading" || Ce(l)
430
436
  );
431
437
  if (n <= 0)
432
438
  return { introduction: null, rest: e };
433
439
  const o = e.slice(0, n), i = e.slice(n), r = x(o, t, !0);
434
440
  return { introduction: r.length > 0 ? h("introduction", r) : null, rest: i };
435
441
  }
436
- function De(e) {
442
+ function Le(e) {
437
443
  const t = e.data;
438
444
  return t?.id ? { "xml:id": t.id } : void 0;
439
445
  }
440
- function Ce(e, t) {
441
- const n = De(e), o = S(t);
446
+ function xe(e, t) {
447
+ const n = Le(e), o = S(t);
442
448
  if (!(!n && !o))
443
449
  return { ...o, ...n };
444
450
  }
@@ -448,16 +454,16 @@ function S(e) {
448
454
  if (!(!e.topLevelAttributes || !t || t.done))
449
455
  return t.done = !0, e.topLevelAttributes;
450
456
  }
451
- const Le = {
457
+ const we = {
452
458
  paragraph: (e, t) => G(e, t),
453
- blockquote: (e, t) => xe(e, t),
454
- list: (e, t) => we(e, t),
455
- code: (e, t) => Se(e),
459
+ blockquote: (e, t) => Ie(e, t),
460
+ list: (e, t) => Se(e, t),
461
+ code: (e, t) => Ee(e),
456
462
  containerDirective: (e, t) => J(e, t),
457
- leafDirective: (e, t) => Ae(e, t)
463
+ leafDirective: (e, t) => Re(e, t)
458
464
  };
459
465
  function O(e, t) {
460
- const n = Le[e.type];
466
+ const n = we[e.type];
461
467
  return n ? n(e, t) : (t.messages && t.messages.push({
462
468
  type: "warning",
463
469
  reason: `Unknown block type: ${e.type}`,
@@ -469,9 +475,9 @@ function O(e, t) {
469
475
  ));
470
476
  }
471
477
  function G(e, t) {
472
- return h("p", b(e.children, t));
478
+ return h("p", D(e.children, t));
473
479
  }
474
- function xe(e, t) {
480
+ function Ie(e, t) {
475
481
  const n = e.children.filter((o) => o.type === "paragraph").map((o) => {
476
482
  const i = {
477
483
  ...t,
@@ -482,45 +488,45 @@ function xe(e, t) {
482
488
  });
483
489
  return h("blockquote", n);
484
490
  }
485
- function we(e, t) {
491
+ function Se(e, t) {
486
492
  const n = e.children.map((o) => {
487
493
  const i = {
488
494
  ...t,
489
495
  ancestors: [...t.ancestors, e],
490
496
  depth: t.depth + 1
491
497
  };
492
- return Ie(o, i);
498
+ return Te(o, i);
493
499
  });
494
500
  return h(e.ordered ? "ol" : "ul", n);
495
501
  }
496
- function Ie(e, t) {
502
+ function Te(e, t) {
497
503
  const n = x(
498
504
  e.children,
499
505
  t
500
506
  );
501
507
  return h("li", n);
502
508
  }
503
- function Se(e, t) {
509
+ function Ee(e, t) {
504
510
  return k(
505
511
  "program",
506
512
  e.value,
507
513
  e.lang ? { language: e.lang } : void 0
508
514
  );
509
515
  }
510
- function Te(e, t) {
516
+ function qe(e, t) {
511
517
  const n = e.value.split(/\\\\|[\r\n]+/).map((o) => o.trim()).filter((o) => o.length > 0);
512
518
  return n.length > 1 ? h(
513
519
  "md",
514
520
  n.map((o) => k("mrow", o))
515
521
  ) : k("md", n[0] ?? "");
516
522
  }
517
- function Ee(e, t) {
518
- return e.meta === "inline" ? k("m", e.value) : Te(e);
523
+ function Ae(e, t) {
524
+ return e.meta === "inline" ? k("m", e.value) : qe(e);
519
525
  }
520
- function qe(e, t) {
521
- return h("url", b(e.children, t), { href: e.url });
526
+ function $e(e, t) {
527
+ return h("url", D(e.children, t), { href: e.url });
522
528
  }
523
- function Ae(e, t) {
529
+ function Re(e, t) {
524
530
  const n = he(e);
525
531
  return n || (t.messages && t.messages.push({
526
532
  type: "warning",
@@ -544,7 +550,7 @@ function J(e, t) {
544
550
  `unknown directive "${e.name}"`,
545
551
  R(e, t)
546
552
  );
547
- const o = Re(e), i = e.children, { title: r, body: s } = $e(
553
+ const o = Me(e), i = e.children, { title: r, body: s } = Fe(
548
554
  i,
549
555
  t
550
556
  ), l = {
@@ -562,41 +568,41 @@ function J(e, t) {
562
568
  (c, u) => J(c, u)
563
569
  );
564
570
  }
565
- function $e(e, t) {
571
+ function Fe(e, t) {
566
572
  const n = e[0];
567
573
  return n?.type === "paragraph" && n.data?.directiveLabel === !0 ? {
568
574
  title: h(
569
575
  "title",
570
- b(n.children, t)
576
+ D(n.children, t)
571
577
  ),
572
578
  body: e.slice(1)
573
579
  } : { title: null, body: e };
574
580
  }
575
- function Re(e) {
581
+ function Me(e) {
576
582
  const t = e.attributes ?? {}, n = {};
577
583
  for (const [o, i] of Object.entries(t))
578
584
  i != null && (n[o === "id" ? "xml:id" : o] = i);
579
585
  return Object.keys(n).length > 0 ? n : void 0;
580
586
  }
581
- function Fe(e, t) {
587
+ function Oe(e, t) {
582
588
  return !t || e.position?.start?.offset === null || e.position?.start?.offset === void 0 ? "asterisk" : t.charAt(e.position.start.offset) === "_" ? "underscore" : "asterisk";
583
589
  }
584
- const Me = {
590
+ const Ne = {
585
591
  text: (e, t) => E(e.value),
586
592
  emphasis: (e, t) => {
587
- const o = Fe(e, t.source) === "underscore" ? "term" : "em";
588
- return h(o, b(e.children, t));
593
+ const o = Oe(e, t.source) === "underscore" ? "term" : "em";
594
+ return h(o, D(e.children, t));
589
595
  },
590
- strong: (e, t) => h("alert", b(e.children, t)),
596
+ strong: (e, t) => h("alert", D(e.children, t)),
591
597
  inlineCode: (e, t) => k("c", e.value),
592
- math: (e, t) => Ee(e),
593
- link: (e, t) => qe(e, t)
598
+ math: (e, t) => Ae(e),
599
+ link: (e, t) => $e(e, t)
594
600
  };
595
- function b(e, t) {
596
- return e.flatMap((n) => Oe(n, t)).filter((n) => n !== null);
601
+ function D(e, t) {
602
+ return e.flatMap((n) => _e(n, t)).filter((n) => n !== null);
597
603
  }
598
- function Oe(e, t) {
599
- const n = Me[e.type];
604
+ function _e(e, t) {
605
+ const n = Ne[e.type];
600
606
  if (!n)
601
607
  return t.messages && t.messages.push({
602
608
  type: "warning",
@@ -610,7 +616,7 @@ function Oe(e, t) {
610
616
  const o = { ...t, ancestors: [...t.ancestors, e] };
611
617
  return n(e, o);
612
618
  }
613
- const Ne = [
619
+ const Pe = [
614
620
  // Display math (check these first, before single $)
615
621
  { open: "$$", close: "$$", isDisplay: !0 },
616
622
  { open: "\\[", close: "\\]", isDisplay: !0 },
@@ -620,7 +626,7 @@ const Ne = [
620
626
  ], ee = "PTX_MATH_TOKEN_", F = new RegExp(`${ee}(\\d+)`, "g");
621
627
  function te(e, t) {
622
628
  let n = null;
623
- for (const o of Ne) {
629
+ for (const o of Pe) {
624
630
  const i = e.indexOf(o.open, t);
625
631
  if (i === -1) continue;
626
632
  const r = e.indexOf(o.close, i + o.open.length);
@@ -631,7 +637,7 @@ function te(e, t) {
631
637
  }
632
638
  return n;
633
639
  }
634
- function _e(e, t) {
640
+ function Be(e, t) {
635
641
  let n = t;
636
642
  for (; n < e.length; ) {
637
643
  const o = e.indexOf("`", n);
@@ -653,11 +659,11 @@ function _e(e, t) {
653
659
  }
654
660
  return null;
655
661
  }
656
- function Pe(e) {
662
+ function je(e) {
657
663
  const t = /* @__PURE__ */ new Map();
658
664
  let n = "", o = 0, i = 0;
659
665
  for (; o < e.length; ) {
660
- const r = _e(e, o), s = te(e, o);
666
+ const r = Be(e, o), s = te(e, o);
661
667
  if (r && (!s || r.start < s.index)) {
662
668
  n += e.substring(o, r.end), o = r.end;
663
669
  continue;
@@ -676,7 +682,7 @@ function Pe(e) {
676
682
  }
677
683
  return { markdown: n, tokens: t };
678
684
  }
679
- function je(e) {
685
+ function ze(e) {
680
686
  const t = [];
681
687
  let n = 0;
682
688
  for (; n < e.length; ) {
@@ -696,7 +702,7 @@ function je(e) {
696
702
  }
697
703
  return t.length === 0 ? [{ type: "text", value: e }] : t;
698
704
  }
699
- function Be(e, t) {
705
+ function We(e, t) {
700
706
  const n = [];
701
707
  let o = 0;
702
708
  F.lastIndex = 0;
@@ -714,29 +720,29 @@ function ne(e) {
714
720
  const n = t.children || [], o = [];
715
721
  for (const i of n)
716
722
  if (i.type === "text") {
717
- const r = je(i.value);
723
+ const r = ze(i.value);
718
724
  o.push(...r);
719
725
  } else
720
726
  o.push(i);
721
727
  t.children = o;
722
728
  });
723
729
  }
724
- function ze(e, t) {
730
+ function Ue(e, t) {
725
731
  K(e, "paragraph", (n) => {
726
732
  const o = n.children || [], i = [];
727
733
  for (const r of o)
728
734
  if (r.type === "text") {
729
- const s = Be(r.value, t);
735
+ const s = We(r.value, t);
730
736
  i.push(...s);
731
737
  } else
732
738
  i.push(r);
733
739
  n.children = i;
734
740
  });
735
741
  }
736
- const jt = () => (e) => {
742
+ const zt = () => (e) => {
737
743
  ne(e);
738
744
  };
739
- function We(e) {
745
+ function He(e) {
740
746
  const t = e.trim();
741
747
  if (!t.startsWith(":")) return null;
742
748
  let n = 0;
@@ -753,7 +759,7 @@ function We(e) {
753
759
  isOpen: !0
754
760
  } : null;
755
761
  }
756
- function Ue(e) {
762
+ function Xe(e) {
757
763
  const t = [], n = [];
758
764
  for (const o of e)
759
765
  if (o.isOpen) {
@@ -787,7 +793,7 @@ function oe(e) {
787
793
  }
788
794
  return e.finalColons;
789
795
  }
790
- function He(e, t, n) {
796
+ function Ze(e, t, n) {
791
797
  const o = e.slice(), i = [], r = t.slice();
792
798
  for (; r.length > 0; ) {
793
799
  const s = r.shift();
@@ -802,7 +808,7 @@ function He(e, t, n) {
802
808
  }
803
809
  return o;
804
810
  }
805
- function Xe(e) {
811
+ function Ve(e) {
806
812
  const t = e.split(`
807
813
  `), n = [];
808
814
  let o = !1, i = null;
@@ -815,18 +821,18 @@ function Xe(e) {
815
821
  }
816
822
  if (o)
817
823
  continue;
818
- const p = We(c);
824
+ const p = He(c);
819
825
  p && n.push({ ...p, lineIndex: l });
820
826
  }
821
827
  if (n.length === 0)
822
828
  return e;
823
- const r = Ue(n);
829
+ const r = Xe(n);
824
830
  for (const l of r)
825
831
  oe(l);
826
- return He(t, r).join(`
832
+ return Ze(t, r).join(`
827
833
  `);
828
834
  }
829
- function Ze(e) {
835
+ function Ke(e) {
830
836
  const t = e.trim();
831
837
  if (!t.endsWith(":")) return null;
832
838
  const n = t.slice(0, -1);
@@ -847,7 +853,7 @@ function N(e) {
847
853
  break;
848
854
  return t;
849
855
  }
850
- function Ve(e, t) {
856
+ function Ye(e, t) {
851
857
  const n = N(e[t]);
852
858
  for (let o = t + 1; o < e.length; o++)
853
859
  if (!ie(e[o]))
@@ -857,7 +863,7 @@ function Ve(e, t) {
857
863
  function ie(e) {
858
864
  return e.trim() === "";
859
865
  }
860
- function Ke(e, t) {
866
+ function Qe(e, t) {
861
867
  let n = 0, o = 0;
862
868
  for (; o < e.length && n < t; )
863
869
  if (e[o] === " ")
@@ -868,7 +874,7 @@ function Ke(e, t) {
868
874
  break;
869
875
  return e.slice(o);
870
876
  }
871
- function Ye(e) {
877
+ function Ge(e) {
872
878
  const t = e.split(`
873
879
  `), n = [], o = {
874
880
  level: 0,
@@ -891,8 +897,8 @@ function Ye(e) {
891
897
  n.push("");
892
898
  continue;
893
899
  }
894
- const u = Ze(s);
895
- if (u && Ve(t, i)) {
900
+ const u = Ke(s);
901
+ if (u && Ye(t, i)) {
896
902
  for (; o.openDirectives.length > 0 && !(o.openDirectives[o.openDirectives.length - 1].indentLevel < l); ) {
897
903
  const y = o.openDirectives.pop();
898
904
  y && n.push(":".repeat(y.colonCount));
@@ -911,7 +917,7 @@ function Ye(e) {
911
917
  }
912
918
  if (o.openDirectives.length > 0) {
913
919
  const a = o.openDirectives[o.openDirectives.length - 1];
914
- a.bodyBaseIndent < 0 && (a.bodyBaseIndent = l), n.push(Ke(r, a.bodyBaseIndent));
920
+ a.bodyBaseIndent < 0 && (a.bodyBaseIndent = l), n.push(Qe(r, a.bodyBaseIndent));
915
921
  } else
916
922
  n.push(r);
917
923
  o.level = l;
@@ -924,8 +930,8 @@ function Ye(e) {
924
930
  return n.join(`
925
931
  `);
926
932
  }
927
- const Qe = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/, Ge = /^division:\s*(\S+)\s*$/m, Je = /^id:\s*(\S+)\s*$/m, et = /^xmlid:\s*(\S+)\s*$/m, tt = /^xml:id:\s*(\S+)\s*$/m, nt = /^label:\s*(\S+)\s*$/m, ot = /^component:\s*(\S+)\s*$/m, it = /^title:\s*(.+?)\s*$/m;
928
- function rt(e) {
933
+ const Je = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/, et = /^division:\s*(\S+)\s*$/m, tt = /^id:\s*(\S+)\s*$/m, nt = /^xmlid:\s*(\S+)\s*$/m, ot = /^xml:id:\s*(\S+)\s*$/m, it = /^label:\s*(\S+)\s*$/m, rt = /^component:\s*(\S+)\s*$/m, st = /^title:\s*(.+?)\s*$/m;
934
+ function lt(e) {
929
935
  if (e.length >= 2) {
930
936
  const t = e[0], n = e[e.length - 1];
931
937
  if (t === '"' && n === '"' || t === "'" && n === "'")
@@ -933,16 +939,16 @@ function rt(e) {
933
939
  }
934
940
  return e;
935
941
  }
936
- function st(e) {
937
- const t = e.match(Qe);
942
+ function ct(e) {
943
+ const t = e.match(Je);
938
944
  if (!t)
939
945
  return { body: e };
940
- const n = t[1], o = e.slice(t[0].length), i = n.match(Ge)?.[1];
946
+ const n = t[1], o = e.slice(t[0].length), i = n.match(et)?.[1];
941
947
  let r, s;
942
948
  i && pe(i) ? (s = i, r = M(i)) : i && V(i) && (r = i);
943
- const l = {}, c = n.match(Je)?.[1] ?? n.match(et)?.[1] ?? n.match(tt)?.[1], u = n.match(nt)?.[1], a = n.match(ot)?.[1];
949
+ const l = {}, c = n.match(tt)?.[1] ?? n.match(nt)?.[1] ?? n.match(ot)?.[1], u = n.match(it)?.[1], a = n.match(rt)?.[1];
944
950
  c && (l["xml:id"] = c), u && (l.label = u), a && (l.component = a);
945
- const p = n.match(it)?.[1], d = p ? rt(p) : void 0;
951
+ const p = n.match(st)?.[1], d = p ? lt(p) : void 0;
946
952
  return {
947
953
  division: r,
948
954
  documentRoot: s,
@@ -951,39 +957,39 @@ function st(e) {
951
957
  body: o
952
958
  };
953
959
  }
954
- const lt = function(e) {
960
+ const ut = function(e) {
955
961
  return function(n, o) {
956
962
  if (typeof o?.value == "string") {
957
- const i = st(o.value), r = e?.documentRoot ?? i.documentRoot, s = e?.topLevelDivision ?? i.division ?? (r ? M(r) : "chapter"), l = e?.topLevelAttributes ?? i.attributes, c = e?.topLevelTitle ?? i.title, u = Ye(
963
+ const i = ct(o.value), r = e?.documentRoot ?? i.documentRoot, s = e?.topLevelDivision ?? i.division ?? (r ? M(r) : "chapter"), l = e?.topLevelAttributes ?? i.attributes, c = e?.topLevelTitle ?? i.title, u = Ge(
958
964
  i.body
959
- ), a = Xe(u), p = Pe(a), g = H().data("micromarkExtensions", [
965
+ ), a = Ve(u), p = je(a), g = H().data("micromarkExtensions", [
960
966
  { disable: { null: ["codeIndented"] } }
961
967
  ]).use(X).use(Z).parse(p.markdown);
962
- return ze(g, p.tokens), B(g, p.markdown, {
968
+ return Ue(g, p.tokens), j(g, p.markdown, {
963
969
  topLevelDivision: s,
964
970
  documentRoot: r,
965
971
  topLevelAttributes: l,
966
972
  topLevelTitle: c
967
973
  });
968
974
  }
969
- return ne(n), B(n, void 0, {
975
+ return ne(n), j(n, void 0, {
970
976
  topLevelDivision: e?.topLevelDivision ?? (e?.documentRoot ? M(e.documentRoot) : "chapter"),
971
977
  documentRoot: e?.documentRoot,
972
978
  topLevelAttributes: e?.topLevelAttributes,
973
979
  topLevelTitle: e?.topLevelTitle
974
980
  });
975
981
  };
976
- }, ct = /["&'<>`]/g, ut = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, at = (
982
+ }, at = /["&'<>`]/g, pt = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, ft = (
977
983
  // eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
978
984
  /[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g
979
- ), pt = /[|\\{}()[\]^$+*?.]/g, z = /* @__PURE__ */ new WeakMap();
980
- function ft(e, t) {
985
+ ), ht = /[|\\{}()[\]^$+*?.]/g, z = /* @__PURE__ */ new WeakMap();
986
+ function dt(e, t) {
981
987
  if (e = e.replace(
982
- t.subset ? ht(t.subset) : ct,
988
+ t.subset ? mt(t.subset) : at,
983
989
  o
984
990
  ), t.subset || t.escapeOnly)
985
991
  return e;
986
- return e.replace(ut, n).replace(at, o);
992
+ return e.replace(pt, n).replace(ft, o);
987
993
  function n(i, r, s) {
988
994
  return t.format(
989
995
  (i.charCodeAt(0) - 55296) * 1024 + i.charCodeAt(1) - 56320 + 65536,
@@ -999,45 +1005,45 @@ function ft(e, t) {
999
1005
  );
1000
1006
  }
1001
1007
  }
1002
- function ht(e) {
1008
+ function mt(e) {
1003
1009
  let t = z.get(e);
1004
- return t || (t = dt(e), z.set(e, t)), t;
1010
+ return t || (t = gt(e), z.set(e, t)), t;
1005
1011
  }
1006
- function dt(e) {
1012
+ function gt(e) {
1007
1013
  const t = [];
1008
1014
  let n = -1;
1009
1015
  for (; ++n < e.length; )
1010
- t.push(e[n].replace(pt, "\\$&"));
1016
+ t.push(e[n].replace(ht, "\\$&"));
1011
1017
  return new RegExp("(?:" + t.join("|") + ")", "g");
1012
1018
  }
1013
- function mt(e) {
1019
+ function yt(e) {
1014
1020
  return "&#x" + e.toString(16).toUpperCase() + ";";
1015
1021
  }
1016
- function gt(e, t) {
1017
- return ft(e, Object.assign({ format: mt }, t));
1022
+ function vt(e, t) {
1023
+ return dt(e, Object.assign({ format: yt }, t));
1018
1024
  }
1019
- const yt = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
1020
- function D(e, t, n) {
1021
- const o = vt(e);
1025
+ const kt = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
1026
+ function C(e, t, n) {
1027
+ const o = bt(e);
1022
1028
  return n ? o.replace(n, i) : i(o);
1023
1029
  function i(r) {
1024
- return gt(r, { subset: t });
1030
+ return vt(r, { subset: t });
1025
1031
  }
1026
1032
  }
1027
- function vt(e) {
1028
- return String(e || "").replace(yt, "");
1033
+ function bt(e) {
1034
+ return String(e || "").replace(kt, "");
1029
1035
  }
1030
- const kt = /]]>/g, bt = [">"];
1031
- function Dt(e) {
1032
- return "<![CDATA[" + D(e.value, bt, kt) + "]]>";
1036
+ const Dt = /]]>/g, Ct = [">"];
1037
+ function Lt(e) {
1038
+ return "<![CDATA[" + C(e.value, Ct, Dt) + "]]>";
1033
1039
  }
1034
- function Ct(e) {
1035
- return "<!--" + D(e.value, ["-"]) + "-->";
1040
+ function xt(e) {
1041
+ return "<!--" + C(e.value, ["-"]) + "-->";
1036
1042
  }
1037
- const Lt = [" ", `
1043
+ const wt = [" ", `
1038
1044
  `, " ", '"', "&", "'", "/", "<", "=", ">"];
1039
1045
  function A(e) {
1040
- return D(e, Lt);
1046
+ return C(e, wt);
1041
1047
  }
1042
1048
  function W(e, t) {
1043
1049
  const n = String(e);
@@ -1055,43 +1061,43 @@ function _(e, t) {
1055
1061
  const i = o === '"' ? "'" : '"';
1056
1062
  W(n, o) > W(n, i) && (o = i);
1057
1063
  }
1058
- return o + D(n, ["<", "&", o]) + o;
1064
+ return o + C(n, ["<", "&", o]) + o;
1059
1065
  }
1060
- function xt(e, t) {
1066
+ function It(e, t) {
1061
1067
  const n = A(e.name), o = e.public, i = e.system;
1062
1068
  let r = "<!DOCTYPE";
1063
1069
  return n !== "" && (r += " " + n), o ? r += " PUBLIC " + _(o, t) : i && (r += " SYSTEM"), i && (r += " " + _(i, t)), r + ">";
1064
1070
  }
1065
- const wt = {}.hasOwnProperty;
1066
- function It(e, t) {
1071
+ const St = {}.hasOwnProperty;
1072
+ function Tt(e, t) {
1067
1073
  const n = A(e.name), o = le(e, t), i = e.attributes || {}, r = o ? !1 : t.options.closeEmptyElements, s = [];
1068
1074
  let l;
1069
1075
  for (l in i)
1070
- if (wt.call(i, l)) {
1076
+ if (St.call(i, l)) {
1071
1077
  const c = i[l];
1072
1078
  c != null && s.push(A(l) + "=" + _(c, t));
1073
1079
  }
1074
1080
  return "<" + n + (s.length === 0 ? "" : " " + s.join(" ")) + (r ? (t.options.tightClose ? "" : " ") + "/" : "") + ">" + o + (r ? "" : "</" + n + ">");
1075
1081
  }
1076
- const St = /\?>/g, Tt = [">"];
1077
- function Et(e) {
1078
- const t = A(e.name) || "x", n = D(e.value, Tt, St);
1082
+ const Et = /\?>/g, qt = [">"];
1083
+ function At(e) {
1084
+ const t = A(e.name) || "x", n = C(e.value, qt, Et);
1079
1085
  return "<?" + t + (n ? " " + n : "") + "?>";
1080
1086
  }
1081
- const qt = ["&", "<"];
1087
+ const $t = ["&", "<"];
1082
1088
  function re(e) {
1083
- return D(e.value, qt);
1089
+ return C(e.value, $t);
1084
1090
  }
1085
- function At(e, t) {
1091
+ function Rt(e, t) {
1086
1092
  return t.options.allowDangerousXml ? e.value : re(e);
1087
1093
  }
1088
- const $t = {}.hasOwnProperty, U = {
1089
- cdata: Dt,
1090
- comment: Ct,
1091
- doctype: xt,
1092
- element: It,
1093
- instruction: Et,
1094
- raw: At,
1094
+ const Ft = {}.hasOwnProperty, U = {
1095
+ cdata: Lt,
1096
+ comment: xt,
1097
+ doctype: It,
1098
+ element: Tt,
1099
+ instruction: At,
1100
+ raw: Rt,
1095
1101
  root: le,
1096
1102
  text: re
1097
1103
  };
@@ -1099,7 +1105,7 @@ function se(e, t) {
1099
1105
  const n = e && e.type;
1100
1106
  if (!n)
1101
1107
  throw new Error("Expected node, not `" + e + "`");
1102
- if (!$t.call(U, n))
1108
+ if (!Ft.call(U, n))
1103
1109
  throw new Error("Cannot compile unknown node `" + n + "`");
1104
1110
  const o = U[n];
1105
1111
  return o(e, t);
@@ -1112,7 +1118,7 @@ function le(e, t) {
1112
1118
  i[o] = se(n[o], t);
1113
1119
  return i.join("");
1114
1120
  }
1115
- function Rt(e, t) {
1121
+ function Mt(e, t) {
1116
1122
  const n = { options: t || {} };
1117
1123
  if (typeof n.options.quote == "string" && n.options.quote !== '"' && n.options.quote !== "'")
1118
1124
  throw new Error(
@@ -1121,18 +1127,18 @@ function Rt(e, t) {
1121
1127
  const o = Array.isArray(e) ? { type: "root", children: e } : e;
1122
1128
  return se(o, n);
1123
1129
  }
1124
- function Bt(e, t) {
1125
- const n = H().use(X).use(Z).use(lt, t), o = n.parse(e), i = n.runSync(o, { value: e });
1126
- return Rt(i.children, {
1130
+ function Wt(e, t) {
1131
+ const n = H().use(X).use(Z).use(ut, t), o = n.parse(e), i = n.runSync(o, { value: e });
1132
+ return Mt(i.children, {
1127
1133
  closeEmptyElements: !0,
1128
1134
  tightClose: !0
1129
1135
  });
1130
1136
  }
1131
1137
  export {
1132
- Pt as DIRECTIVE_MAP,
1138
+ jt as DIRECTIVE_MAP,
1133
1139
  Y as PROOF_SOLUTION_NAMES,
1134
- Bt as markdownToPretext,
1135
- B as mdastToPtxast,
1136
- jt as remarkMath,
1137
- lt as remarkPretext
1140
+ Wt as markdownToPretext,
1141
+ j as mdastToPtxast,
1142
+ zt as remarkMath,
1143
+ ut as remarkPretext
1138
1144
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretextbook/remark-pretext",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "remark plugin to transform markdown-style PreTeXt directives into ptxast",
5
5
  "author": "Oscar Levin",
6
6
  "license": "MIT",