@pretextbook/remark-pretext 0.0.12 → 0.1.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=C(g,i),k=[...p?[p]:[],...d?[d]:[],...y];return{tree:{type:"root",children:[h(i.documentRoot,k,a)]},messages:o}}if(v.isTitlelessDivisionType(i.topLevelDivision)){const a=S(i),p=A(C(r,{...i,depth:1},!0));return{tree:{type:"root",children:[h(i.topLevelDivision,p,a)]},messages:o}}if(i.topLevelTitle){const a=S(i),p=h("title",[q(i.topLevelTitle)]),d={...i,depth:i.depth+1,headingDepthOffset:(i.headingDepthOffset??0)+1},{introduction:g,rest:y}=T(r,d),k=A(C(y,d,!0)),f=g?[p,g,...k]:[p,...k];return{tree:{type:"root",children:[h(i.topLevelDivision,f,a)]},messages:o}}const{introduction:s,rest:l}=T(r,i),c=C(l,i);return{tree:{type:"root",children:s?[s,...c]:c},messages:o}}function C(e,t,n=!1){let o=7;for(const u of e)u.type==="heading"&&(o=Math.min(o,u.depth));if(o===7)return L(e,t,n);const i=[];let r=null,s=[],l=[];const c=()=>{r&&(i.push(ge(r,l,t)),r=null,l=[])};for(const u of e)u.type==="heading"&&u.depth===o?(!r&&s.length>0&&(i.push(...L(s,t,n)),s=[]),c(),r=u,l=[]):r?l.push(u):s.push(u);return!r&&s.length>0&&i.push(...L(s,t,n)),c(),i}function L(e,t,n=!1){const o=[];for(let i=0;i<e.length;i+=1){const r=e[i],s=_(r,t);if(s!==null){if(s.name==="p"&&s.children.length===1&&s.children[0].name==="md"){const l=s.children[0],c=o[o.length-1],u=i+1<e.length?_(e[i+1],t):null,a=u?.name==="p"?u.children:null;if(c?.name==="p")c.children.push(l),a&&(c.children.push(...a),i+=1);else{const p=[l];a&&(p.push(...a),i+=1),o.push(h("p",p))}continue}if((s.name==="ul"||s.name==="ol")&&o.length>0){const l=o[o.length-1];if(l?.name==="p"){l.children.push(s);continue}}o.push(s)}}return n?A(o):o}function ge(e,t,n){const o=e.depth+(n.headingDepthOffset??0),i=n.documentRoot?v.divisionTypeAtRootDepth(n.documentRoot,o):v.divisionTypeAtRelativeDepth(n.topLevelDivision,o),r=h("title",w(e.children,n)),s=ke(e,n),l={...n,depth:n.depth+1},{introduction:c,rest:u}=T(t,l),a=C(u,l,!0),p=A(a),d=c?[r,c,...p]:[r,...p];return h(i,d,s)}function ye(e){return e.type==="leafDirective"&&v.isTopLevelDivisionType(e.name)}function T(e,t){const n=e.findIndex(l=>l.type==="heading"||ye(l));if(n<=0)return{introduction:null,rest:e};const o=e.slice(0,n),i=e.slice(n),r=L(o,t,!0);return{introduction:r.length>0?h("introduction",r):null,rest:i}}function ve(e){const t=e.data;return t?.id?{"xml:id":t.id}:void 0}function ke(e,t){const n=ve(e),o=S(t);if(!(!n&&!o))return{...o,...n}}function S(e){if(e.depth!==0)return;const t=e.topLevelAttributesApplied;if(!(!e.topLevelAttributes||!t||t.done))return t.done=!0,e.topLevelAttributes}const be={paragraph:(e,t)=>Q(e,t),blockquote:(e,t)=>De(e,t),list:(e,t)=>Ce(e,t),code:(e,t)=>Le(e),containerDirective:(e,t)=>G(e,t),leafDirective:(e,t)=>Te(e,t)};function _(e,t){const n=be[e.type];return n?n(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),B("unknown-block-type",`unknown block type "${e.type}"`,$(e,t)))}function Q(e,t){return h("p",w(e.children,t))}function De(e,t){const n=e.children.filter(o=>o.type==="paragraph").map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return Q(o,i)});return h("blockquote",n)}function Ce(e,t){const n=e.children.map(o=>{const i={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return xe(o,i)});return h(e.ordered?"ol":"ul",n)}function xe(e,t){const n=L(e.children,t);return h("li",n)}function Le(e,t){return b("program",e.value,e.lang?{language:e.lang}:void 0)}function we(e,t){const n=e.value.split(/\\\\|[\r\n]+/).map(o=>o.trim()).filter(o=>o.length>0);return n.length>1?h("md",n.map(o=>b("mrow",o))):b("md",n[0]??"")}function Ie(e,t){return e.meta==="inline"?b("m",e.value):we(e)}function Te(e,t){const n=ue(e);return n||(t.messages&&t.messages.push({type:"warning",reason:"Unnamed leaf directive",category:"unknown-directive"}),B("unknown-directive","unnamed leaf directive",$(e,t)))}function G(e,t){const n=pe(e.name);if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),B("unknown-directive",`unknown directive "${e.name}"`,$(e,t));const o=Ee(e),i=e.children,{title:r,body:s}=Se(i,t),l={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return he(n,o,r,s,l,(c,u)=>_(c,u),(c,u)=>G(c,u))}function Se(e,t){const n=e[0];return n?.type==="paragraph"&&n.data?.directiveLabel===!0?{title:h("title",w(n.children,t)),body:e.slice(1)}:{title:null,body:e}}function Ee(e){const t=e.attributes??{},n={};for(const[o,i]of Object.entries(t))i!=null&&(n[o==="id"?"xml:id":o]=i);return Object.keys(n).length>0?n:void 0}function qe(e,t){return!t||e.position?.start?.offset===null||e.position?.start?.offset===void 0?"asterisk":t.charAt(e.position.start.offset)==="_"?"underscore":"asterisk"}const Ae={text:(e,t)=>q(e.value),emphasis:(e,t)=>{const o=qe(e,t.source)==="underscore"?"term":"em";return h(o,w(e.children,t))},strong:(e,t)=>h("alert",w(e.children,t)),inlineCode:(e,t)=>b("c",e.value),math:(e,t)=>Ie(e)};function w(e,t){return e.flatMap(n=>Me(n,t)).filter(n=>n!==null)}function Me(e,t){const n=Ae[e.type];if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),de("unknown-inline-type",`unknown inline type "${e.type}"`,$(e,t));const o={...t,ancestors:[...t.ancestors,e]};return n(e,o)}const Re=[{open:"$$",close:"$$",isDisplay:!0},{open:"\\[",close:"\\]",isDisplay:!0},{open:"$",close:"$",isDisplay:!1},{open:"\\(",close:"\\)",isDisplay:!1}],J="PTX_MATH_TOKEN_",F=new RegExp(`${J}(\\d+)`,"g");function ee(e,t){let n=null;for(const o of Re){const i=e.indexOf(o.open,t);if(i===-1)continue;const r=e.indexOf(o.close,i+o.open.length);if(r!==-1&&!(o.open==="$"&&(i>0&&e[i-1]==="$"||i+1<e.length&&e[i+1]==="$"))&&(!n||i<n.index)){const s=e.substring(i+o.open.length,r);n={index:i,pattern:o,content:s}}}return n}function $e(e,t){let n=t;for(;n<e.length;){const o=e.indexOf("`",n);if(o===-1)return null;let i=0,r=o;for(;r<e.length&&e[r]==="`";)i++,r++;const s="`".repeat(i);let l=r;for(;l<e.length;){const c=e.indexOf(s,l);if(c===-1)break;const u=c+i;if(u>=e.length||e[u]!=="`")return{start:o,end:u};l=c+1}n=o+i}return null}function Fe(e){const t=new Map;let n="",o=0,i=0;for(;o<e.length;){const r=$e(e,o),s=ee(e,o);if(r&&(!s||r.start<s.index)){n+=e.substring(o,r.end),o=r.end;continue}if(!s){n+=e.substring(o);break}n+=e.substring(o,s.index);const l=`${J}${i}`;n+=l,t.set(l,{type:"math",value:s.content,meta:s.pattern.isDisplay?"display":"inline"}),o=s.index+s.pattern.open.length+s.content.length+s.pattern.close.length,i+=1}return{markdown:n,tokens:t}}function Oe(e){const t=[];let n=0;for(;n<e.length;){const o=ee(e,n);if(!o){n<e.length&&t.push({type:"text",value:e.substring(n)});break}o.index>n&&t.push({type:"text",value:e.substring(n,o.index)}),t.push({type:"math",value:o.content,meta:o.pattern.isDisplay?"display":"inline"}),n=o.index+o.pattern.open.length+o.content.length+o.pattern.close.length}return t.length===0?[{type:"text",value:e}]:t}function _e(e,t){const n=[];let o=0;F.lastIndex=0;let i=F.exec(e);for(;i;){const r=i.index,s=i[0];r>o&&n.push({type:"text",value:e.substring(o,r)});const l=t.get(s);l?n.push(l):n.push({type:"text",value:s}),o=r+s.length,i=F.exec(e)}return o<e.length&&n.push({type:"text",value:e.substring(o)}),n.length===0?[{type:"text",value:e}]:n}function te(e){K.visit(e,"paragraph",t=>{const n=t.children||[],o=[];for(const i of n)if(i.type==="text"){const r=Oe(i.value);o.push(...r)}else o.push(i);t.children=o})}function Ne(e,t){K.visit(e,"paragraph",n=>{const o=n.children||[],i=[];for(const r of o)if(r.type==="text"){const s=_e(r.value,t);i.push(...s)}else i.push(r);n.children=i})}const Pe=()=>e=>{te(e)};function je(e){const t=e.trim();if(!t.startsWith(":"))return null;let n=0;for(let r=0;r<t.length&&t[r]===":";r++)n++;if(n<3)return null;const o=t.slice(n).trim(),i=o.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);return o===""?{colons:n,label:null,lineIndex:-1,isOpen:!1}:i?{colons:n,label:i[0],lineIndex:-1,isOpen:!0}:null}function Be(e){const t=[],n=[];for(const o of e)if(o.isOpen){const i={colons:o.colons,finalColons:o.colons,label:o.label,openLineIndex:o.lineIndex,closeLineIndex:null,children:[],parent:null};if(t.length>0){const r=t[t.length-1];i.parent=r,r.children.push(i)}else n.push(i);t.push(i)}else{const i=t[t.length-1];i&&i.colons===o.colons&&(i.closeLineIndex=o.lineIndex,t.pop())}return n}function ne(e){if(e.children.length===0)e.finalColons=e.colons;else{const t=Math.max(...e.children.map(ne));e.finalColons=Math.max(e.colons,t+1)}return e.finalColons}function ze(e,t,n){const o=e.slice(),i=[],r=t.slice();for(;r.length>0;){const s=r.shift();i.push(s),r.push(...s.children)}for(const s of i){if(s.openLineIndex>=0){const l=o[s.openLineIndex],c=l.match(/^:+/)?.[0].length||3,u=l.slice(c);o[s.openLineIndex]=":".repeat(s.finalColons)+u}s.closeLineIndex!==null&&s.closeLineIndex>=0&&(o[s.closeLineIndex]=":".repeat(s.finalColons))}return o}function Ue(e){const t=e.split(`
2
- `),n=[];let o=!1,i=null;for(let l=0;l<t.length;l++){const c=t[l],a=c.trim().match(/^(`{3,}|~{3,})/);if(a){const d=a[1];o?i&&d[0]===i[0]&&d.length>=i.length&&(o=!1,i=null):(o=!0,i=d);continue}if(o)continue;const p=je(c);p&&n.push({...p,lineIndex:l})}if(n.length===0)return e;const r=Be(n);for(const l of r)ne(l);return ze(t,r).join(`
3
- `)}function We(e){const t=e.trim();if(!t.endsWith(":"))return null;const n=t.slice(0,-1);if(!/^[a-zA-Z]/.test(n))return null;const o=n.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);if(!o)return null;const[,i,r]=o;return r&&!/^(\[[^\]]*\]|\{[^}]*\})*$/.test(r)||!R[i.toLowerCase()]?null:n}function N(e){let t=0;for(let n=0;n<e.length;n++)if(e[n]===" ")t+=1;else if(e[n]===" ")t+=4;else break;return t}function Ve(e,t){const n=N(e[t]);for(let o=t+1;o<e.length;o++)if(!oe(e[o]))return N(e[o])>n;return!1}function oe(e){return e.trim()===""}function He(e,t){let n=0,o=0;for(;o<e.length&&n<t;)if(e[o]===" ")n++,o++;else if(e[o]===" ")n+=4,o++;else break;return e.slice(o)}function Xe(e){const t=e.split(`
4
- `),n=[],o={level:0,openDirectives:[],inCodeFence:!1,codeFenceMarker:null};for(let i=0;i<t.length;i++){const r=t[i],s=r.trim(),l=N(r),c=s.match(/^(`{3,}|~{3,})/);if(c){const a=c[1];o.inCodeFence?o.codeFenceMarker&&s.startsWith(o.codeFenceMarker)&&(o.inCodeFence=!1,o.codeFenceMarker=null):(o.inCodeFence=!0,o.codeFenceMarker=a),n.push(r);continue}if(o.inCodeFence){n.push(r);continue}if(oe(r)){n.push("");continue}const u=We(s);if(u&&Ve(t,i)){for(;o.openDirectives.length>0&&!(o.openDirectives[o.openDirectives.length-1].indentLevel<l);){const y=o.openDirectives.pop();y&&n.push(":".repeat(y.colonCount))}const a=u.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/),p=a?a[1].toLowerCase()+(a[2]||""):u,d=o.openDirectives.length*1+3;n.push(":".repeat(d)+p),o.openDirectives.push({label:p,indentLevel:l,colonCount:d,bodyBaseIndent:-1}),o.level=l}else{for(;o.openDirectives.length>0&&l<=o.openDirectives[o.openDirectives.length-1].indentLevel;){const a=o.openDirectives.pop();a&&n.push(":".repeat(a.colonCount))}if(o.openDirectives.length>0){const a=o.openDirectives[o.openDirectives.length-1];a.bodyBaseIndent<0&&(a.bodyBaseIndent=l),n.push(He(r,a.bodyBaseIndent))}else n.push(r);o.level=l}}for(;o.openDirectives.length>0;){const i=o.openDirectives.pop();i&&n.push(":".repeat(i.colonCount))}return n.join(`
5
- `)}const Ze=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/,Ke=/^division:\s*(\S+)\s*$/m,Ye=/^id:\s*(\S+)\s*$/m,Qe=/^xmlid:\s*(\S+)\s*$/m,Ge=/^xml:id:\s*(\S+)\s*$/m,Je=/^label:\s*(\S+)\s*$/m,et=/^component:\s*(\S+)\s*$/m,tt=/^title:\s*(.+?)\s*$/m;function nt(e){if(e.length>=2){const t=e[0],n=e[e.length-1];if(t==='"'&&n==='"'||t==="'"&&n==="'")return e.slice(1,-1)}return e}function ot(e){const t=e.match(Ze);if(!t)return{body:e};const n=t[1],o=e.slice(t[0].length),i=n.match(Ke)?.[1];let r,s;i&&v.isRootDivisionType(i)?(s=i,r=v.rootChildDivision(i)):i&&v.isTopLevelDivisionType(i)&&(r=i);const l={},c=n.match(Ye)?.[1]??n.match(Qe)?.[1]??n.match(Ge)?.[1],u=n.match(Je)?.[1],a=n.match(et)?.[1];c&&(l["xml:id"]=c),u&&(l.label=u),a&&(l.component=a);const p=n.match(tt)?.[1],d=p?nt(p):void 0;return{division:r,documentRoot:s,attributes:Object.keys(l).length>0?l:void 0,title:d,body:o}}const ie=function(e){return function(n,o){if(typeof o?.value=="string"){const i=ot(o.value),r=e?.documentRoot??i.documentRoot,s=e?.topLevelDivision??i.division??(r?v.rootChildDivision(r):"chapter"),l=e?.topLevelAttributes??i.attributes,c=e?.topLevelTitle??i.title,u=Xe(i.body),a=Ue(u),p=Fe(a),g=H.unified().data("micromarkExtensions",[{disable:{null:["codeIndented"]}}]).use(X).use(Z).parse(p.markdown);return Ne(g,p.tokens),O(g,p.markdown,{topLevelDivision:s,documentRoot:r,topLevelAttributes:l,topLevelTitle:c})}return te(n),O(n,void 0,{topLevelDivision:e?.topLevelDivision??(e?.documentRoot?v.rootChildDivision(e.documentRoot):"chapter"),documentRoot:e?.documentRoot,topLevelAttributes:e?.topLevelAttributes,topLevelTitle:e?.topLevelTitle})}},it=/["&'<>`]/g,rt=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,st=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,lt=/[|\\{}()[\]^$+*?.]/g,U=new WeakMap;function ct(e,t){if(e=e.replace(t.subset?ut(t.subset):it,o),t.subset||t.escapeOnly)return e;return e.replace(rt,n).replace(st,o);function n(i,r,s){return t.format((i.charCodeAt(0)-55296)*1024+i.charCodeAt(1)-56320+65536,s.charCodeAt(r+2),t)}function o(i,r,s){return t.format(i.charCodeAt(0),s.charCodeAt(r+1),t)}}function ut(e){let t=U.get(e);return t||(t=at(e),U.set(e,t)),t}function at(e){const t=[];let n=-1;for(;++n<e.length;)t.push(e[n].replace(lt,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function pt(e){return"&#x"+e.toString(16).toUpperCase()+";"}function ft(e,t){return ct(e,Object.assign({format:pt},t))}const ht=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function D(e,t,n){const o=dt(e);return n?o.replace(n,i):i(o);function i(r){return ft(r,{subset:t})}}function dt(e){return String(e||"").replace(ht,"")}const mt=/]]>/g,gt=[">"];function yt(e){return"<![CDATA["+D(e.value,gt,mt)+"]]>"}function vt(e){return"<!--"+D(e.value,["-"])+"-->"}const kt=[" ",`
6
- `," ",'"',"&","'","/","<","=",">"];function M(e){return D(e,kt)}function W(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let o=0,i=n.indexOf(t);for(;i!==-1;)o++,i=n.indexOf(t,i+t.length);return o}function P(e,t){const n=String(e);let o=t.options.quote||'"';if(t.options.quoteSmart){const i=o==='"'?"'":'"';W(n,o)>W(n,i)&&(o=i)}return o+D(n,["<","&",o])+o}function bt(e,t){const n=M(e.name),o=e.public,i=e.system;let r="<!DOCTYPE";return n!==""&&(r+=" "+n),o?r+=" PUBLIC "+P(o,t):i&&(r+=" SYSTEM"),i&&(r+=" "+P(i,t)),r+">"}const Dt={}.hasOwnProperty;function Ct(e,t){const n=M(e.name),o=le(e,t),i=e.attributes||{},r=o?!1:t.options.closeEmptyElements,s=[];let l;for(l in i)if(Dt.call(i,l)){const c=i[l];c!=null&&s.push(M(l)+"="+P(c,t))}return"<"+n+(s.length===0?"":" "+s.join(" "))+(r?(t.options.tightClose?"":" ")+"/":"")+">"+o+(r?"":"</"+n+">")}const xt=/\?>/g,Lt=[">"];function wt(e){const t=M(e.name)||"x",n=D(e.value,Lt,xt);return"<?"+t+(n?" "+n:"")+"?>"}const It=["&","<"];function re(e){return D(e.value,It)}function Tt(e,t){return t.options.allowDangerousXml?e.value:re(e)}const St={}.hasOwnProperty,V={cdata:yt,comment:vt,doctype:bt,element:Ct,instruction:wt,raw:Tt,root:le,text:re};function se(e,t){const n=e&&e.type;if(!n)throw new Error("Expected node, not `"+e+"`");if(!St.call(V,n))throw new Error("Cannot compile unknown node `"+n+"`");const o=V[n];return o(e,t)}function le(e,t){const n=e&&e.children||[];let o=-1;const i=[];for(;++o<n.length;)i[o]=se(n[o],t);return i.join("")}function Et(e,t){const n={options:t||{}};if(typeof n.options.quote=="string"&&n.options.quote!=='"'&&n.options.quote!=="'")throw new Error("Invalid quote `"+n.options.quote+"`, expected `'` or `\"`");const o=Array.isArray(e)?{type:"root",children:e}:e;return se(o,n)}function qt(e,t){const n=H.unified().use(X).use(Z).use(ie,t),o=n.parse(e),i=n.runSync(o,{value:e});return Et(i.children,{closeEmptyElements:!0,tightClose:!0})}exports.DIRECTIVE_MAP=ae;exports.PROOF_SOLUTION_NAMES=j;exports.markdownToPretext=qt;exports.mdastToPtxast=O;exports.remarkMath=Pe;exports.remarkPretext=ie;
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;
package/dist/index.js CHANGED
@@ -158,7 +158,7 @@ const $ = {
158
158
  category: "solution-like",
159
159
  requiresStatement: !1
160
160
  }
161
- }, _t = $;
161
+ }, Pt = $;
162
162
  function de(e) {
163
163
  return $[e.toLowerCase()];
164
164
  }
@@ -167,7 +167,7 @@ const Y = new Set(
167
167
  ([e, t]) => t.category === "proof-like" || t.category === "solution-like"
168
168
  ).map(([e]) => e)
169
169
  );
170
- function C(e, t, n) {
170
+ function L(e, t, n) {
171
171
  return {
172
172
  type: "element",
173
173
  name: e,
@@ -184,7 +184,7 @@ function me(e) {
184
184
  function T(e) {
185
185
  const t = [];
186
186
  for (const n of e)
187
- n.name === "ul" || n.name === "ol" ? t.length > 0 && t[t.length - 1]?.name === "p" ? t[t.length - 1].children.push(n) : t.push(C("p", [n])) : t.push(n);
187
+ n.name === "ul" || n.name === "ol" ? t.length > 0 && t[t.length - 1]?.name === "p" ? t[t.length - 1].children.push(n) : t.push(L("p", [n])) : t.push(n);
188
188
  return t;
189
189
  }
190
190
  function ge(e, t, n, o, i, r, s) {
@@ -219,7 +219,7 @@ function ge(e, t, n, o, i, r, s) {
219
219
  const f = T(
220
220
  p.map((m) => r(m, i)).filter((m) => m !== null)
221
221
  );
222
- f.length > 0 && l.push(C("introduction", f));
222
+ f.length > 0 && l.push(L("introduction", f));
223
223
  }
224
224
  for (const f of d) {
225
225
  const m = s(f, i);
@@ -229,7 +229,7 @@ function ge(e, t, n, o, i, r, s) {
229
229
  const f = T(
230
230
  y.map((m) => r(m, i)).filter((m) => m !== null)
231
231
  );
232
- f.length > 0 && l.push(C("conclusion", f));
232
+ f.length > 0 && l.push(L("conclusion", f));
233
233
  }
234
234
  for (const f of v) {
235
235
  const m = s(f, i);
@@ -253,7 +253,7 @@ function ge(e, t, n, o, i, r, s) {
253
253
  r,
254
254
  s
255
255
  );
256
- return C(e.type, l, t);
256
+ return L(e.type, l, t);
257
257
  }
258
258
  function j(e, t, n, o, i, r) {
259
259
  if (t.requiresStatement) {
@@ -268,7 +268,7 @@ function j(e, t, n, o, i, r) {
268
268
  const c = T(
269
269
  s.map((u) => i(u, o)).filter((u) => u !== null)
270
270
  );
271
- c.length > 0 && e.push(C("statement", c));
271
+ c.length > 0 && e.push(L("statement", c));
272
272
  }
273
273
  e.push(...l);
274
274
  } else {
@@ -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 = D(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 = C(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
- D(r, { ...i, depth: 1 }, !0)
346
+ C(r, { ...i, depth: 1 }, !0)
347
347
  );
348
348
  return {
349
349
  tree: { type: "root", children: [h(i.topLevelDivision, p, a)] },
@@ -356,25 +356,25 @@ 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
- D(y, d, !0)
359
+ C(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 = D(l, i);
366
+ const { introduction: s, rest: l } = I(r, i), c = C(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 D(e, t, n = !1) {
372
+ function C(e, t, n = !1) {
373
373
  let o = 7;
374
374
  for (const u of e)
375
375
  u.type === "heading" && (o = Math.min(o, u.depth));
376
376
  if (o === 7)
377
- return L(e, t, n);
377
+ return x(e, t, n);
378
378
  const i = [];
379
379
  let r = null, s = [], l = [];
380
380
  const c = () => {
@@ -382,13 +382,13 @@ function D(e, t, n = !1) {
382
382
  };
383
383
  for (const u of e)
384
384
  u.type === "heading" && u.depth === o ? (!r && s.length > 0 && (i.push(
385
- ...L(s, t, n)
385
+ ...x(s, t, n)
386
386
  ), s = []), c(), r = u, l = []) : r ? l.push(u) : s.push(u);
387
387
  return !r && s.length > 0 && i.push(
388
- ...L(s, t, n)
388
+ ...x(s, t, n)
389
389
  ), c(), i;
390
390
  }
391
- function L(e, t, n = !1) {
391
+ function x(e, t, n = !1) {
392
392
  const o = [];
393
393
  for (let i = 0; i < e.length; i += 1) {
394
394
  const r = e[i], s = O(r, t);
@@ -418,7 +418,7 @@ function L(e, t, n = !1) {
418
418
  return n ? q(o) : o;
419
419
  }
420
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", x(e.children, n)), s = Ce(e, n), l = { ...n, depth: n.depth + 1 }, { introduction: c, rest: u } = I(t, l), a = D(u, l, !0), p = q(a), d = c ? [r, c, ...p] : [r, ...p];
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];
422
422
  return h(i, d, s);
423
423
  }
424
424
  function be(e) {
@@ -430,7 +430,7 @@ function I(e, t) {
430
430
  );
431
431
  if (n <= 0)
432
432
  return { introduction: null, rest: e };
433
- const o = e.slice(0, n), i = e.slice(n), r = L(o, t, !0);
433
+ const o = e.slice(0, n), i = e.slice(n), r = x(o, t, !0);
434
434
  return { introduction: r.length > 0 ? h("introduction", r) : null, rest: i };
435
435
  }
436
436
  function De(e) {
@@ -454,7 +454,7 @@ const Le = {
454
454
  list: (e, t) => we(e, t),
455
455
  code: (e, t) => Se(e),
456
456
  containerDirective: (e, t) => J(e, t),
457
- leafDirective: (e, t) => qe(e, t)
457
+ leafDirective: (e, t) => Ae(e, t)
458
458
  };
459
459
  function O(e, t) {
460
460
  const n = Le[e.type];
@@ -469,7 +469,7 @@ function O(e, t) {
469
469
  ));
470
470
  }
471
471
  function G(e, t) {
472
- return h("p", x(e.children, t));
472
+ return h("p", b(e.children, t));
473
473
  }
474
474
  function xe(e, t) {
475
475
  const n = e.children.filter((o) => o.type === "paragraph").map((o) => {
@@ -494,7 +494,7 @@ function we(e, t) {
494
494
  return h(e.ordered ? "ol" : "ul", n);
495
495
  }
496
496
  function Ie(e, t) {
497
- const n = L(
497
+ const n = x(
498
498
  e.children,
499
499
  t
500
500
  );
@@ -518,6 +518,9 @@ function Ee(e, t) {
518
518
  return e.meta === "inline" ? k("m", e.value) : Te(e);
519
519
  }
520
520
  function qe(e, t) {
521
+ return h("url", b(e.children, t), { href: e.url });
522
+ }
523
+ function Ae(e, t) {
521
524
  const n = he(e);
522
525
  return n || (t.messages && t.messages.push({
523
526
  type: "warning",
@@ -541,7 +544,7 @@ function J(e, t) {
541
544
  `unknown directive "${e.name}"`,
542
545
  R(e, t)
543
546
  );
544
- const o = $e(e), i = e.children, { title: r, body: s } = Ae(
547
+ const o = Re(e), i = e.children, { title: r, body: s } = $e(
545
548
  i,
546
549
  t
547
550
  ), l = {
@@ -559,40 +562,41 @@ function J(e, t) {
559
562
  (c, u) => J(c, u)
560
563
  );
561
564
  }
562
- function Ae(e, t) {
565
+ function $e(e, t) {
563
566
  const n = e[0];
564
567
  return n?.type === "paragraph" && n.data?.directiveLabel === !0 ? {
565
568
  title: h(
566
569
  "title",
567
- x(n.children, t)
570
+ b(n.children, t)
568
571
  ),
569
572
  body: e.slice(1)
570
573
  } : { title: null, body: e };
571
574
  }
572
- function $e(e) {
575
+ function Re(e) {
573
576
  const t = e.attributes ?? {}, n = {};
574
577
  for (const [o, i] of Object.entries(t))
575
578
  i != null && (n[o === "id" ? "xml:id" : o] = i);
576
579
  return Object.keys(n).length > 0 ? n : void 0;
577
580
  }
578
- function Re(e, t) {
581
+ function Fe(e, t) {
579
582
  return !t || e.position?.start?.offset === null || e.position?.start?.offset === void 0 ? "asterisk" : t.charAt(e.position.start.offset) === "_" ? "underscore" : "asterisk";
580
583
  }
581
- const Fe = {
584
+ const Me = {
582
585
  text: (e, t) => E(e.value),
583
586
  emphasis: (e, t) => {
584
- const o = Re(e, t.source) === "underscore" ? "term" : "em";
585
- return h(o, x(e.children, t));
587
+ const o = Fe(e, t.source) === "underscore" ? "term" : "em";
588
+ return h(o, b(e.children, t));
586
589
  },
587
- strong: (e, t) => h("alert", x(e.children, t)),
590
+ strong: (e, t) => h("alert", b(e.children, t)),
588
591
  inlineCode: (e, t) => k("c", e.value),
589
- math: (e, t) => Ee(e)
592
+ math: (e, t) => Ee(e),
593
+ link: (e, t) => qe(e, t)
590
594
  };
591
- function x(e, t) {
592
- return e.flatMap((n) => Me(n, t)).filter((n) => n !== null);
595
+ function b(e, t) {
596
+ return e.flatMap((n) => Oe(n, t)).filter((n) => n !== null);
593
597
  }
594
- function Me(e, t) {
595
- const n = Fe[e.type];
598
+ function Oe(e, t) {
599
+ const n = Me[e.type];
596
600
  if (!n)
597
601
  return t.messages && t.messages.push({
598
602
  type: "warning",
@@ -606,7 +610,7 @@ function Me(e, t) {
606
610
  const o = { ...t, ancestors: [...t.ancestors, e] };
607
611
  return n(e, o);
608
612
  }
609
- const Oe = [
613
+ const Ne = [
610
614
  // Display math (check these first, before single $)
611
615
  { open: "$$", close: "$$", isDisplay: !0 },
612
616
  { open: "\\[", close: "\\]", isDisplay: !0 },
@@ -616,7 +620,7 @@ const Oe = [
616
620
  ], ee = "PTX_MATH_TOKEN_", F = new RegExp(`${ee}(\\d+)`, "g");
617
621
  function te(e, t) {
618
622
  let n = null;
619
- for (const o of Oe) {
623
+ for (const o of Ne) {
620
624
  const i = e.indexOf(o.open, t);
621
625
  if (i === -1) continue;
622
626
  const r = e.indexOf(o.close, i + o.open.length);
@@ -627,7 +631,7 @@ function te(e, t) {
627
631
  }
628
632
  return n;
629
633
  }
630
- function Ne(e, t) {
634
+ function _e(e, t) {
631
635
  let n = t;
632
636
  for (; n < e.length; ) {
633
637
  const o = e.indexOf("`", n);
@@ -649,11 +653,11 @@ function Ne(e, t) {
649
653
  }
650
654
  return null;
651
655
  }
652
- function _e(e) {
656
+ function Pe(e) {
653
657
  const t = /* @__PURE__ */ new Map();
654
658
  let n = "", o = 0, i = 0;
655
659
  for (; o < e.length; ) {
656
- const r = Ne(e, o), s = te(e, o);
660
+ const r = _e(e, o), s = te(e, o);
657
661
  if (r && (!s || r.start < s.index)) {
658
662
  n += e.substring(o, r.end), o = r.end;
659
663
  continue;
@@ -672,7 +676,7 @@ function _e(e) {
672
676
  }
673
677
  return { markdown: n, tokens: t };
674
678
  }
675
- function Pe(e) {
679
+ function je(e) {
676
680
  const t = [];
677
681
  let n = 0;
678
682
  for (; n < e.length; ) {
@@ -692,7 +696,7 @@ function Pe(e) {
692
696
  }
693
697
  return t.length === 0 ? [{ type: "text", value: e }] : t;
694
698
  }
695
- function je(e, t) {
699
+ function Be(e, t) {
696
700
  const n = [];
697
701
  let o = 0;
698
702
  F.lastIndex = 0;
@@ -710,29 +714,29 @@ function ne(e) {
710
714
  const n = t.children || [], o = [];
711
715
  for (const i of n)
712
716
  if (i.type === "text") {
713
- const r = Pe(i.value);
717
+ const r = je(i.value);
714
718
  o.push(...r);
715
719
  } else
716
720
  o.push(i);
717
721
  t.children = o;
718
722
  });
719
723
  }
720
- function Be(e, t) {
724
+ function ze(e, t) {
721
725
  K(e, "paragraph", (n) => {
722
726
  const o = n.children || [], i = [];
723
727
  for (const r of o)
724
728
  if (r.type === "text") {
725
- const s = je(r.value, t);
729
+ const s = Be(r.value, t);
726
730
  i.push(...s);
727
731
  } else
728
732
  i.push(r);
729
733
  n.children = i;
730
734
  });
731
735
  }
732
- const Pt = () => (e) => {
736
+ const jt = () => (e) => {
733
737
  ne(e);
734
738
  };
735
- function ze(e) {
739
+ function We(e) {
736
740
  const t = e.trim();
737
741
  if (!t.startsWith(":")) return null;
738
742
  let n = 0;
@@ -749,7 +753,7 @@ function ze(e) {
749
753
  isOpen: !0
750
754
  } : null;
751
755
  }
752
- function We(e) {
756
+ function Ue(e) {
753
757
  const t = [], n = [];
754
758
  for (const o of e)
755
759
  if (o.isOpen) {
@@ -783,7 +787,7 @@ function oe(e) {
783
787
  }
784
788
  return e.finalColons;
785
789
  }
786
- function Ue(e, t, n) {
790
+ function He(e, t, n) {
787
791
  const o = e.slice(), i = [], r = t.slice();
788
792
  for (; r.length > 0; ) {
789
793
  const s = r.shift();
@@ -798,7 +802,7 @@ function Ue(e, t, n) {
798
802
  }
799
803
  return o;
800
804
  }
801
- function He(e) {
805
+ function Xe(e) {
802
806
  const t = e.split(`
803
807
  `), n = [];
804
808
  let o = !1, i = null;
@@ -811,18 +815,18 @@ function He(e) {
811
815
  }
812
816
  if (o)
813
817
  continue;
814
- const p = ze(c);
818
+ const p = We(c);
815
819
  p && n.push({ ...p, lineIndex: l });
816
820
  }
817
821
  if (n.length === 0)
818
822
  return e;
819
- const r = We(n);
823
+ const r = Ue(n);
820
824
  for (const l of r)
821
825
  oe(l);
822
- return Ue(t, r).join(`
826
+ return He(t, r).join(`
823
827
  `);
824
828
  }
825
- function Xe(e) {
829
+ function Ze(e) {
826
830
  const t = e.trim();
827
831
  if (!t.endsWith(":")) return null;
828
832
  const n = t.slice(0, -1);
@@ -843,7 +847,7 @@ function N(e) {
843
847
  break;
844
848
  return t;
845
849
  }
846
- function Ze(e, t) {
850
+ function Ve(e, t) {
847
851
  const n = N(e[t]);
848
852
  for (let o = t + 1; o < e.length; o++)
849
853
  if (!ie(e[o]))
@@ -853,7 +857,7 @@ function Ze(e, t) {
853
857
  function ie(e) {
854
858
  return e.trim() === "";
855
859
  }
856
- function Ve(e, t) {
860
+ function Ke(e, t) {
857
861
  let n = 0, o = 0;
858
862
  for (; o < e.length && n < t; )
859
863
  if (e[o] === " ")
@@ -864,7 +868,7 @@ function Ve(e, t) {
864
868
  break;
865
869
  return e.slice(o);
866
870
  }
867
- function Ke(e) {
871
+ function Ye(e) {
868
872
  const t = e.split(`
869
873
  `), n = [], o = {
870
874
  level: 0,
@@ -887,8 +891,8 @@ function Ke(e) {
887
891
  n.push("");
888
892
  continue;
889
893
  }
890
- const u = Xe(s);
891
- if (u && Ze(t, i)) {
894
+ const u = Ze(s);
895
+ if (u && Ve(t, i)) {
892
896
  for (; o.openDirectives.length > 0 && !(o.openDirectives[o.openDirectives.length - 1].indentLevel < l); ) {
893
897
  const y = o.openDirectives.pop();
894
898
  y && n.push(":".repeat(y.colonCount));
@@ -907,7 +911,7 @@ function Ke(e) {
907
911
  }
908
912
  if (o.openDirectives.length > 0) {
909
913
  const a = o.openDirectives[o.openDirectives.length - 1];
910
- a.bodyBaseIndent < 0 && (a.bodyBaseIndent = l), n.push(Ve(r, a.bodyBaseIndent));
914
+ a.bodyBaseIndent < 0 && (a.bodyBaseIndent = l), n.push(Ke(r, a.bodyBaseIndent));
911
915
  } else
912
916
  n.push(r);
913
917
  o.level = l;
@@ -920,8 +924,8 @@ function Ke(e) {
920
924
  return n.join(`
921
925
  `);
922
926
  }
923
- const Ye = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/, Qe = /^division:\s*(\S+)\s*$/m, Ge = /^id:\s*(\S+)\s*$/m, Je = /^xmlid:\s*(\S+)\s*$/m, et = /^xml:id:\s*(\S+)\s*$/m, tt = /^label:\s*(\S+)\s*$/m, nt = /^component:\s*(\S+)\s*$/m, ot = /^title:\s*(.+?)\s*$/m;
924
- function it(e) {
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) {
925
929
  if (e.length >= 2) {
926
930
  const t = e[0], n = e[e.length - 1];
927
931
  if (t === '"' && n === '"' || t === "'" && n === "'")
@@ -929,16 +933,16 @@ function it(e) {
929
933
  }
930
934
  return e;
931
935
  }
932
- function rt(e) {
933
- const t = e.match(Ye);
936
+ function st(e) {
937
+ const t = e.match(Qe);
934
938
  if (!t)
935
939
  return { body: e };
936
- const n = t[1], o = e.slice(t[0].length), i = n.match(Qe)?.[1];
940
+ const n = t[1], o = e.slice(t[0].length), i = n.match(Ge)?.[1];
937
941
  let r, s;
938
942
  i && pe(i) ? (s = i, r = M(i)) : i && V(i) && (r = i);
939
- const l = {}, c = n.match(Ge)?.[1] ?? n.match(Je)?.[1] ?? n.match(et)?.[1], u = n.match(tt)?.[1], a = n.match(nt)?.[1];
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];
940
944
  c && (l["xml:id"] = c), u && (l.label = u), a && (l.component = a);
941
- const p = n.match(ot)?.[1], d = p ? it(p) : void 0;
945
+ const p = n.match(it)?.[1], d = p ? rt(p) : void 0;
942
946
  return {
943
947
  division: r,
944
948
  documentRoot: s,
@@ -947,15 +951,15 @@ function rt(e) {
947
951
  body: o
948
952
  };
949
953
  }
950
- const st = function(e) {
954
+ const lt = function(e) {
951
955
  return function(n, o) {
952
956
  if (typeof o?.value == "string") {
953
- const i = rt(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 = Ke(
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(
954
958
  i.body
955
- ), a = He(u), p = _e(a), g = H().data("micromarkExtensions", [
959
+ ), a = Xe(u), p = Pe(a), g = H().data("micromarkExtensions", [
956
960
  { disable: { null: ["codeIndented"] } }
957
961
  ]).use(X).use(Z).parse(p.markdown);
958
- return Be(g, p.tokens), B(g, p.markdown, {
962
+ return ze(g, p.tokens), B(g, p.markdown, {
959
963
  topLevelDivision: s,
960
964
  documentRoot: r,
961
965
  topLevelAttributes: l,
@@ -969,17 +973,17 @@ const st = function(e) {
969
973
  topLevelTitle: e?.topLevelTitle
970
974
  });
971
975
  };
972
- }, lt = /["&'<>`]/g, ct = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, ut = (
976
+ }, ct = /["&'<>`]/g, ut = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, at = (
973
977
  // eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
974
978
  /[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g
975
- ), at = /[|\\{}()[\]^$+*?.]/g, z = /* @__PURE__ */ new WeakMap();
976
- function pt(e, t) {
979
+ ), pt = /[|\\{}()[\]^$+*?.]/g, z = /* @__PURE__ */ new WeakMap();
980
+ function ft(e, t) {
977
981
  if (e = e.replace(
978
- t.subset ? ft(t.subset) : lt,
982
+ t.subset ? ht(t.subset) : ct,
979
983
  o
980
984
  ), t.subset || t.escapeOnly)
981
985
  return e;
982
- return e.replace(ct, n).replace(ut, o);
986
+ return e.replace(ut, n).replace(at, o);
983
987
  function n(i, r, s) {
984
988
  return t.format(
985
989
  (i.charCodeAt(0) - 55296) * 1024 + i.charCodeAt(1) - 56320 + 65536,
@@ -995,45 +999,45 @@ function pt(e, t) {
995
999
  );
996
1000
  }
997
1001
  }
998
- function ft(e) {
1002
+ function ht(e) {
999
1003
  let t = z.get(e);
1000
- return t || (t = ht(e), z.set(e, t)), t;
1004
+ return t || (t = dt(e), z.set(e, t)), t;
1001
1005
  }
1002
- function ht(e) {
1006
+ function dt(e) {
1003
1007
  const t = [];
1004
1008
  let n = -1;
1005
1009
  for (; ++n < e.length; )
1006
- t.push(e[n].replace(at, "\\$&"));
1010
+ t.push(e[n].replace(pt, "\\$&"));
1007
1011
  return new RegExp("(?:" + t.join("|") + ")", "g");
1008
1012
  }
1009
- function dt(e) {
1013
+ function mt(e) {
1010
1014
  return "&#x" + e.toString(16).toUpperCase() + ";";
1011
1015
  }
1012
- function mt(e, t) {
1013
- return pt(e, Object.assign({ format: dt }, t));
1016
+ function gt(e, t) {
1017
+ return ft(e, Object.assign({ format: mt }, t));
1014
1018
  }
1015
- const gt = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
1016
- function b(e, t, n) {
1017
- const o = yt(e);
1019
+ const yt = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
1020
+ function D(e, t, n) {
1021
+ const o = vt(e);
1018
1022
  return n ? o.replace(n, i) : i(o);
1019
1023
  function i(r) {
1020
- return mt(r, { subset: t });
1024
+ return gt(r, { subset: t });
1021
1025
  }
1022
1026
  }
1023
- function yt(e) {
1024
- return String(e || "").replace(gt, "");
1025
- }
1026
- const vt = /]]>/g, kt = [">"];
1027
- function bt(e) {
1028
- return "<![CDATA[" + b(e.value, kt, vt) + "]]>";
1027
+ function vt(e) {
1028
+ return String(e || "").replace(yt, "");
1029
1029
  }
1030
+ const kt = /]]>/g, bt = [">"];
1030
1031
  function Dt(e) {
1031
- return "<!--" + b(e.value, ["-"]) + "-->";
1032
+ return "<![CDATA[" + D(e.value, bt, kt) + "]]>";
1033
+ }
1034
+ function Ct(e) {
1035
+ return "<!--" + D(e.value, ["-"]) + "-->";
1032
1036
  }
1033
- const Ct = [" ", `
1037
+ const Lt = [" ", `
1034
1038
  `, " ", '"', "&", "'", "/", "<", "=", ">"];
1035
1039
  function A(e) {
1036
- return b(e, Ct);
1040
+ return D(e, Lt);
1037
1041
  }
1038
1042
  function W(e, t) {
1039
1043
  const n = String(e);
@@ -1051,43 +1055,43 @@ function _(e, t) {
1051
1055
  const i = o === '"' ? "'" : '"';
1052
1056
  W(n, o) > W(n, i) && (o = i);
1053
1057
  }
1054
- return o + b(n, ["<", "&", o]) + o;
1058
+ return o + D(n, ["<", "&", o]) + o;
1055
1059
  }
1056
- function Lt(e, t) {
1060
+ function xt(e, t) {
1057
1061
  const n = A(e.name), o = e.public, i = e.system;
1058
1062
  let r = "<!DOCTYPE";
1059
1063
  return n !== "" && (r += " " + n), o ? r += " PUBLIC " + _(o, t) : i && (r += " SYSTEM"), i && (r += " " + _(i, t)), r + ">";
1060
1064
  }
1061
- const xt = {}.hasOwnProperty;
1062
- function wt(e, t) {
1065
+ const wt = {}.hasOwnProperty;
1066
+ function It(e, t) {
1063
1067
  const n = A(e.name), o = le(e, t), i = e.attributes || {}, r = o ? !1 : t.options.closeEmptyElements, s = [];
1064
1068
  let l;
1065
1069
  for (l in i)
1066
- if (xt.call(i, l)) {
1070
+ if (wt.call(i, l)) {
1067
1071
  const c = i[l];
1068
1072
  c != null && s.push(A(l) + "=" + _(c, t));
1069
1073
  }
1070
1074
  return "<" + n + (s.length === 0 ? "" : " " + s.join(" ")) + (r ? (t.options.tightClose ? "" : " ") + "/" : "") + ">" + o + (r ? "" : "</" + n + ">");
1071
1075
  }
1072
- const It = /\?>/g, St = [">"];
1073
- function Tt(e) {
1074
- const t = A(e.name) || "x", n = b(e.value, St, It);
1076
+ const St = /\?>/g, Tt = [">"];
1077
+ function Et(e) {
1078
+ const t = A(e.name) || "x", n = D(e.value, Tt, St);
1075
1079
  return "<?" + t + (n ? " " + n : "") + "?>";
1076
1080
  }
1077
- const Et = ["&", "<"];
1081
+ const qt = ["&", "<"];
1078
1082
  function re(e) {
1079
- return b(e.value, Et);
1083
+ return D(e.value, qt);
1080
1084
  }
1081
- function qt(e, t) {
1085
+ function At(e, t) {
1082
1086
  return t.options.allowDangerousXml ? e.value : re(e);
1083
1087
  }
1084
- const At = {}.hasOwnProperty, U = {
1085
- cdata: bt,
1086
- comment: Dt,
1087
- doctype: Lt,
1088
- element: wt,
1089
- instruction: Tt,
1090
- raw: qt,
1088
+ const $t = {}.hasOwnProperty, U = {
1089
+ cdata: Dt,
1090
+ comment: Ct,
1091
+ doctype: xt,
1092
+ element: It,
1093
+ instruction: Et,
1094
+ raw: At,
1091
1095
  root: le,
1092
1096
  text: re
1093
1097
  };
@@ -1095,7 +1099,7 @@ function se(e, t) {
1095
1099
  const n = e && e.type;
1096
1100
  if (!n)
1097
1101
  throw new Error("Expected node, not `" + e + "`");
1098
- if (!At.call(U, n))
1102
+ if (!$t.call(U, n))
1099
1103
  throw new Error("Cannot compile unknown node `" + n + "`");
1100
1104
  const o = U[n];
1101
1105
  return o(e, t);
@@ -1108,7 +1112,7 @@ function le(e, t) {
1108
1112
  i[o] = se(n[o], t);
1109
1113
  return i.join("");
1110
1114
  }
1111
- function $t(e, t) {
1115
+ function Rt(e, t) {
1112
1116
  const n = { options: t || {} };
1113
1117
  if (typeof n.options.quote == "string" && n.options.quote !== '"' && n.options.quote !== "'")
1114
1118
  throw new Error(
@@ -1117,18 +1121,18 @@ function $t(e, t) {
1117
1121
  const o = Array.isArray(e) ? { type: "root", children: e } : e;
1118
1122
  return se(o, n);
1119
1123
  }
1120
- function jt(e, t) {
1121
- const n = H().use(X).use(Z).use(st, t), o = n.parse(e), i = n.runSync(o, { value: e });
1122
- return $t(i.children, {
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, {
1123
1127
  closeEmptyElements: !0,
1124
1128
  tightClose: !0
1125
1129
  });
1126
1130
  }
1127
1131
  export {
1128
- _t as DIRECTIVE_MAP,
1132
+ Pt as DIRECTIVE_MAP,
1129
1133
  Y as PROOF_SOLUTION_NAMES,
1130
- jt as markdownToPretext,
1134
+ Bt as markdownToPretext,
1131
1135
  B as mdastToPtxast,
1132
- Pt as remarkMath,
1133
- st as remarkPretext
1136
+ jt as remarkMath,
1137
+ lt as remarkPretext
1134
1138
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretextbook/remark-pretext",
3
- "version": "0.0.12",
3
+ "version": "0.1.0",
4
4
  "description": "remark plugin to transform markdown-style PreTeXt directives into ptxast",
5
5
  "author": "Oscar Levin",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "test": "vitest run"
40
40
  },
41
41
  "dependencies": {
42
- "@pretextbook/ptxast": "^0.1.0",
42
+ "@pretextbook/ptxast": "^0.2.0",
43
43
  "@types/mdast": "^4.0.0",
44
44
  "mdast-util-directive": "^3.0.0",
45
45
  "remark-directive": "^4.0.0",