@pretextbook/remark-pretext 0.0.13 → 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=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 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
- }, _t = $;
161
+ }, jt = $;
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,14 +229,14 @@ 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);
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,
@@ -253,9 +253,9 @@ 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
- 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)
@@ -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 {
@@ -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 = 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 = 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
- D(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,39 +356,45 @@ 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
+ 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 = D(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 D(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));
376
382
  if (o === 7)
377
- return L(e, t, n);
383
+ return x(e, t, n);
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(
385
- ...L(s, t, n)
391
+ ...x(s, t, n)
386
392
  ), s = []), c(), r = u, l = []) : r ? l.push(u) : s.push(u);
387
393
  return !r && s.length > 0 && i.push(
388
- ...L(s, t, n)
394
+ ...x(s, t, n)
389
395
  ), c(), i;
390
396
  }
391
- function L(e, t, n = !1) {
397
+ function x(e, t, n = !1) {
392
398
  const o = [];
393
399
  for (let i = 0; i < e.length; i += 1) {
394
400
  const r = e[i], s = O(r, t);
@@ -417,28 +423,28 @@ function L(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", 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];
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
- const o = e.slice(0, n), i = e.slice(n), r = L(o, t, !0);
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) => qe(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", x(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,42 +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) {
497
- const n = L(
502
+ function Te(e, t) {
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) {
526
+ function $e(e, t) {
527
+ return h("url", D(e.children, t), { href: e.url });
528
+ }
529
+ function Re(e, t) {
521
530
  const n = he(e);
522
531
  return n || (t.messages && t.messages.push({
523
532
  type: "warning",
@@ -541,7 +550,7 @@ function J(e, t) {
541
550
  `unknown directive "${e.name}"`,
542
551
  R(e, t)
543
552
  );
544
- const o = $e(e), i = e.children, { title: r, body: s } = Ae(
553
+ const o = Me(e), i = e.children, { title: r, body: s } = Fe(
545
554
  i,
546
555
  t
547
556
  ), l = {
@@ -559,40 +568,41 @@ function J(e, t) {
559
568
  (c, u) => J(c, u)
560
569
  );
561
570
  }
562
- function Ae(e, t) {
571
+ function Fe(e, t) {
563
572
  const n = e[0];
564
573
  return n?.type === "paragraph" && n.data?.directiveLabel === !0 ? {
565
574
  title: h(
566
575
  "title",
567
- x(n.children, t)
576
+ D(n.children, t)
568
577
  ),
569
578
  body: e.slice(1)
570
579
  } : { title: null, body: e };
571
580
  }
572
- function $e(e) {
581
+ function Me(e) {
573
582
  const t = e.attributes ?? {}, n = {};
574
583
  for (const [o, i] of Object.entries(t))
575
584
  i != null && (n[o === "id" ? "xml:id" : o] = i);
576
585
  return Object.keys(n).length > 0 ? n : void 0;
577
586
  }
578
- function Re(e, t) {
587
+ function Oe(e, t) {
579
588
  return !t || e.position?.start?.offset === null || e.position?.start?.offset === void 0 ? "asterisk" : t.charAt(e.position.start.offset) === "_" ? "underscore" : "asterisk";
580
589
  }
581
- const Fe = {
590
+ const Ne = {
582
591
  text: (e, t) => E(e.value),
583
592
  emphasis: (e, t) => {
584
- const o = Re(e, t.source) === "underscore" ? "term" : "em";
585
- return h(o, x(e.children, t));
593
+ const o = Oe(e, t.source) === "underscore" ? "term" : "em";
594
+ return h(o, D(e.children, t));
586
595
  },
587
- strong: (e, t) => h("alert", x(e.children, t)),
596
+ strong: (e, t) => h("alert", D(e.children, t)),
588
597
  inlineCode: (e, t) => k("c", e.value),
589
- math: (e, t) => Ee(e)
598
+ math: (e, t) => Ae(e),
599
+ link: (e, t) => $e(e, t)
590
600
  };
591
- function x(e, t) {
592
- return e.flatMap((n) => Me(n, t)).filter((n) => n !== null);
601
+ function D(e, t) {
602
+ return e.flatMap((n) => _e(n, t)).filter((n) => n !== null);
593
603
  }
594
- function Me(e, t) {
595
- const n = Fe[e.type];
604
+ function _e(e, t) {
605
+ const n = Ne[e.type];
596
606
  if (!n)
597
607
  return t.messages && t.messages.push({
598
608
  type: "warning",
@@ -606,7 +616,7 @@ function Me(e, t) {
606
616
  const o = { ...t, ancestors: [...t.ancestors, e] };
607
617
  return n(e, o);
608
618
  }
609
- const Oe = [
619
+ const Pe = [
610
620
  // Display math (check these first, before single $)
611
621
  { open: "$$", close: "$$", isDisplay: !0 },
612
622
  { open: "\\[", close: "\\]", isDisplay: !0 },
@@ -616,7 +626,7 @@ const Oe = [
616
626
  ], ee = "PTX_MATH_TOKEN_", F = new RegExp(`${ee}(\\d+)`, "g");
617
627
  function te(e, t) {
618
628
  let n = null;
619
- for (const o of Oe) {
629
+ for (const o of Pe) {
620
630
  const i = e.indexOf(o.open, t);
621
631
  if (i === -1) continue;
622
632
  const r = e.indexOf(o.close, i + o.open.length);
@@ -627,7 +637,7 @@ function te(e, t) {
627
637
  }
628
638
  return n;
629
639
  }
630
- function Ne(e, t) {
640
+ function Be(e, t) {
631
641
  let n = t;
632
642
  for (; n < e.length; ) {
633
643
  const o = e.indexOf("`", n);
@@ -649,11 +659,11 @@ function Ne(e, t) {
649
659
  }
650
660
  return null;
651
661
  }
652
- function _e(e) {
662
+ function je(e) {
653
663
  const t = /* @__PURE__ */ new Map();
654
664
  let n = "", o = 0, i = 0;
655
665
  for (; o < e.length; ) {
656
- const r = Ne(e, o), s = te(e, o);
666
+ const r = Be(e, o), s = te(e, o);
657
667
  if (r && (!s || r.start < s.index)) {
658
668
  n += e.substring(o, r.end), o = r.end;
659
669
  continue;
@@ -672,7 +682,7 @@ function _e(e) {
672
682
  }
673
683
  return { markdown: n, tokens: t };
674
684
  }
675
- function Pe(e) {
685
+ function ze(e) {
676
686
  const t = [];
677
687
  let n = 0;
678
688
  for (; n < e.length; ) {
@@ -692,7 +702,7 @@ function Pe(e) {
692
702
  }
693
703
  return t.length === 0 ? [{ type: "text", value: e }] : t;
694
704
  }
695
- function je(e, t) {
705
+ function We(e, t) {
696
706
  const n = [];
697
707
  let o = 0;
698
708
  F.lastIndex = 0;
@@ -710,29 +720,29 @@ function ne(e) {
710
720
  const n = t.children || [], o = [];
711
721
  for (const i of n)
712
722
  if (i.type === "text") {
713
- const r = Pe(i.value);
723
+ const r = ze(i.value);
714
724
  o.push(...r);
715
725
  } else
716
726
  o.push(i);
717
727
  t.children = o;
718
728
  });
719
729
  }
720
- function Be(e, t) {
730
+ function Ue(e, t) {
721
731
  K(e, "paragraph", (n) => {
722
732
  const o = n.children || [], i = [];
723
733
  for (const r of o)
724
734
  if (r.type === "text") {
725
- const s = je(r.value, t);
735
+ const s = We(r.value, t);
726
736
  i.push(...s);
727
737
  } else
728
738
  i.push(r);
729
739
  n.children = i;
730
740
  });
731
741
  }
732
- const Pt = () => (e) => {
742
+ const zt = () => (e) => {
733
743
  ne(e);
734
744
  };
735
- function ze(e) {
745
+ function He(e) {
736
746
  const t = e.trim();
737
747
  if (!t.startsWith(":")) return null;
738
748
  let n = 0;
@@ -749,7 +759,7 @@ function ze(e) {
749
759
  isOpen: !0
750
760
  } : null;
751
761
  }
752
- function We(e) {
762
+ function Xe(e) {
753
763
  const t = [], n = [];
754
764
  for (const o of e)
755
765
  if (o.isOpen) {
@@ -783,7 +793,7 @@ function oe(e) {
783
793
  }
784
794
  return e.finalColons;
785
795
  }
786
- function Ue(e, t, n) {
796
+ function Ze(e, t, n) {
787
797
  const o = e.slice(), i = [], r = t.slice();
788
798
  for (; r.length > 0; ) {
789
799
  const s = r.shift();
@@ -798,7 +808,7 @@ function Ue(e, t, n) {
798
808
  }
799
809
  return o;
800
810
  }
801
- function He(e) {
811
+ function Ve(e) {
802
812
  const t = e.split(`
803
813
  `), n = [];
804
814
  let o = !1, i = null;
@@ -811,18 +821,18 @@ function He(e) {
811
821
  }
812
822
  if (o)
813
823
  continue;
814
- const p = ze(c);
824
+ const p = He(c);
815
825
  p && n.push({ ...p, lineIndex: l });
816
826
  }
817
827
  if (n.length === 0)
818
828
  return e;
819
- const r = We(n);
829
+ const r = Xe(n);
820
830
  for (const l of r)
821
831
  oe(l);
822
- return Ue(t, r).join(`
832
+ return Ze(t, r).join(`
823
833
  `);
824
834
  }
825
- function Xe(e) {
835
+ function Ke(e) {
826
836
  const t = e.trim();
827
837
  if (!t.endsWith(":")) return null;
828
838
  const n = t.slice(0, -1);
@@ -843,7 +853,7 @@ function N(e) {
843
853
  break;
844
854
  return t;
845
855
  }
846
- function Ze(e, t) {
856
+ function Ye(e, t) {
847
857
  const n = N(e[t]);
848
858
  for (let o = t + 1; o < e.length; o++)
849
859
  if (!ie(e[o]))
@@ -853,7 +863,7 @@ function Ze(e, t) {
853
863
  function ie(e) {
854
864
  return e.trim() === "";
855
865
  }
856
- function Ve(e, t) {
866
+ function Qe(e, t) {
857
867
  let n = 0, o = 0;
858
868
  for (; o < e.length && n < t; )
859
869
  if (e[o] === " ")
@@ -864,7 +874,7 @@ function Ve(e, t) {
864
874
  break;
865
875
  return e.slice(o);
866
876
  }
867
- function Ke(e) {
877
+ function Ge(e) {
868
878
  const t = e.split(`
869
879
  `), n = [], o = {
870
880
  level: 0,
@@ -887,8 +897,8 @@ function Ke(e) {
887
897
  n.push("");
888
898
  continue;
889
899
  }
890
- const u = Xe(s);
891
- if (u && Ze(t, i)) {
900
+ const u = Ke(s);
901
+ if (u && Ye(t, i)) {
892
902
  for (; o.openDirectives.length > 0 && !(o.openDirectives[o.openDirectives.length - 1].indentLevel < l); ) {
893
903
  const y = o.openDirectives.pop();
894
904
  y && n.push(":".repeat(y.colonCount));
@@ -907,7 +917,7 @@ function Ke(e) {
907
917
  }
908
918
  if (o.openDirectives.length > 0) {
909
919
  const a = o.openDirectives[o.openDirectives.length - 1];
910
- a.bodyBaseIndent < 0 && (a.bodyBaseIndent = l), n.push(Ve(r, a.bodyBaseIndent));
920
+ a.bodyBaseIndent < 0 && (a.bodyBaseIndent = l), n.push(Qe(r, a.bodyBaseIndent));
911
921
  } else
912
922
  n.push(r);
913
923
  o.level = l;
@@ -920,8 +930,8 @@ function Ke(e) {
920
930
  return n.join(`
921
931
  `);
922
932
  }
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) {
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) {
925
935
  if (e.length >= 2) {
926
936
  const t = e[0], n = e[e.length - 1];
927
937
  if (t === '"' && n === '"' || t === "'" && n === "'")
@@ -929,16 +939,16 @@ function it(e) {
929
939
  }
930
940
  return e;
931
941
  }
932
- function rt(e) {
933
- const t = e.match(Ye);
942
+ function ct(e) {
943
+ const t = e.match(Je);
934
944
  if (!t)
935
945
  return { body: e };
936
- const n = t[1], o = e.slice(t[0].length), i = n.match(Qe)?.[1];
946
+ const n = t[1], o = e.slice(t[0].length), i = n.match(et)?.[1];
937
947
  let r, s;
938
948
  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];
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];
940
950
  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;
951
+ const p = n.match(st)?.[1], d = p ? lt(p) : void 0;
942
952
  return {
943
953
  division: r,
944
954
  documentRoot: s,
@@ -947,39 +957,39 @@ function rt(e) {
947
957
  body: o
948
958
  };
949
959
  }
950
- const st = function(e) {
960
+ const ut = function(e) {
951
961
  return function(n, o) {
952
962
  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(
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(
954
964
  i.body
955
- ), a = He(u), p = _e(a), g = H().data("micromarkExtensions", [
965
+ ), a = Ve(u), p = je(a), g = H().data("micromarkExtensions", [
956
966
  { disable: { null: ["codeIndented"] } }
957
967
  ]).use(X).use(Z).parse(p.markdown);
958
- return Be(g, p.tokens), B(g, p.markdown, {
968
+ return Ue(g, p.tokens), j(g, p.markdown, {
959
969
  topLevelDivision: s,
960
970
  documentRoot: r,
961
971
  topLevelAttributes: l,
962
972
  topLevelTitle: c
963
973
  });
964
974
  }
965
- return ne(n), B(n, void 0, {
975
+ return ne(n), j(n, void 0, {
966
976
  topLevelDivision: e?.topLevelDivision ?? (e?.documentRoot ? M(e.documentRoot) : "chapter"),
967
977
  documentRoot: e?.documentRoot,
968
978
  topLevelAttributes: e?.topLevelAttributes,
969
979
  topLevelTitle: e?.topLevelTitle
970
980
  });
971
981
  };
972
- }, lt = /["&'<>`]/g, ct = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, ut = (
982
+ }, at = /["&'<>`]/g, pt = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, ft = (
973
983
  // eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
974
984
  /[\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) {
985
+ ), ht = /[|\\{}()[\]^$+*?.]/g, z = /* @__PURE__ */ new WeakMap();
986
+ function dt(e, t) {
977
987
  if (e = e.replace(
978
- t.subset ? ft(t.subset) : lt,
988
+ t.subset ? mt(t.subset) : at,
979
989
  o
980
990
  ), t.subset || t.escapeOnly)
981
991
  return e;
982
- return e.replace(ct, n).replace(ut, o);
992
+ return e.replace(pt, n).replace(ft, o);
983
993
  function n(i, r, s) {
984
994
  return t.format(
985
995
  (i.charCodeAt(0) - 55296) * 1024 + i.charCodeAt(1) - 56320 + 65536,
@@ -995,45 +1005,45 @@ function pt(e, t) {
995
1005
  );
996
1006
  }
997
1007
  }
998
- function ft(e) {
1008
+ function mt(e) {
999
1009
  let t = z.get(e);
1000
- return t || (t = ht(e), z.set(e, t)), t;
1010
+ return t || (t = gt(e), z.set(e, t)), t;
1001
1011
  }
1002
- function ht(e) {
1012
+ function gt(e) {
1003
1013
  const t = [];
1004
1014
  let n = -1;
1005
1015
  for (; ++n < e.length; )
1006
- t.push(e[n].replace(at, "\\$&"));
1016
+ t.push(e[n].replace(ht, "\\$&"));
1007
1017
  return new RegExp("(?:" + t.join("|") + ")", "g");
1008
1018
  }
1009
- function dt(e) {
1019
+ function yt(e) {
1010
1020
  return "&#x" + e.toString(16).toUpperCase() + ";";
1011
1021
  }
1012
- function mt(e, t) {
1013
- return pt(e, Object.assign({ format: dt }, t));
1022
+ function vt(e, t) {
1023
+ return dt(e, Object.assign({ format: yt }, t));
1014
1024
  }
1015
- const gt = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
1016
- function b(e, t, n) {
1017
- const o = yt(e);
1025
+ const kt = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
1026
+ function C(e, t, n) {
1027
+ const o = bt(e);
1018
1028
  return n ? o.replace(n, i) : i(o);
1019
1029
  function i(r) {
1020
- return mt(r, { subset: t });
1030
+ return vt(r, { subset: t });
1021
1031
  }
1022
1032
  }
1023
- function yt(e) {
1024
- return String(e || "").replace(gt, "");
1025
- }
1026
- const vt = /]]>/g, kt = [">"];
1027
1033
  function bt(e) {
1028
- return "<![CDATA[" + b(e.value, kt, vt) + "]]>";
1034
+ return String(e || "").replace(kt, "");
1035
+ }
1036
+ const Dt = /]]>/g, Ct = [">"];
1037
+ function Lt(e) {
1038
+ return "<![CDATA[" + C(e.value, Ct, Dt) + "]]>";
1029
1039
  }
1030
- function Dt(e) {
1031
- return "<!--" + b(e.value, ["-"]) + "-->";
1040
+ function xt(e) {
1041
+ return "<!--" + C(e.value, ["-"]) + "-->";
1032
1042
  }
1033
- const Ct = [" ", `
1043
+ const wt = [" ", `
1034
1044
  `, " ", '"', "&", "'", "/", "<", "=", ">"];
1035
1045
  function A(e) {
1036
- return b(e, Ct);
1046
+ return C(e, wt);
1037
1047
  }
1038
1048
  function W(e, t) {
1039
1049
  const n = String(e);
@@ -1051,43 +1061,43 @@ function _(e, t) {
1051
1061
  const i = o === '"' ? "'" : '"';
1052
1062
  W(n, o) > W(n, i) && (o = i);
1053
1063
  }
1054
- return o + b(n, ["<", "&", o]) + o;
1064
+ return o + C(n, ["<", "&", o]) + o;
1055
1065
  }
1056
- function Lt(e, t) {
1066
+ function It(e, t) {
1057
1067
  const n = A(e.name), o = e.public, i = e.system;
1058
1068
  let r = "<!DOCTYPE";
1059
1069
  return n !== "" && (r += " " + n), o ? r += " PUBLIC " + _(o, t) : i && (r += " SYSTEM"), i && (r += " " + _(i, t)), r + ">";
1060
1070
  }
1061
- const xt = {}.hasOwnProperty;
1062
- function wt(e, t) {
1071
+ const St = {}.hasOwnProperty;
1072
+ function Tt(e, t) {
1063
1073
  const n = A(e.name), o = le(e, t), i = e.attributes || {}, r = o ? !1 : t.options.closeEmptyElements, s = [];
1064
1074
  let l;
1065
1075
  for (l in i)
1066
- if (xt.call(i, l)) {
1076
+ if (St.call(i, l)) {
1067
1077
  const c = i[l];
1068
1078
  c != null && s.push(A(l) + "=" + _(c, t));
1069
1079
  }
1070
1080
  return "<" + n + (s.length === 0 ? "" : " " + s.join(" ")) + (r ? (t.options.tightClose ? "" : " ") + "/" : "") + ">" + o + (r ? "" : "</" + n + ">");
1071
1081
  }
1072
- const It = /\?>/g, St = [">"];
1073
- function Tt(e) {
1074
- const t = A(e.name) || "x", n = b(e.value, St, It);
1082
+ const Et = /\?>/g, qt = [">"];
1083
+ function At(e) {
1084
+ const t = A(e.name) || "x", n = C(e.value, qt, Et);
1075
1085
  return "<?" + t + (n ? " " + n : "") + "?>";
1076
1086
  }
1077
- const Et = ["&", "<"];
1087
+ const $t = ["&", "<"];
1078
1088
  function re(e) {
1079
- return b(e.value, Et);
1089
+ return C(e.value, $t);
1080
1090
  }
1081
- function qt(e, t) {
1091
+ function Rt(e, t) {
1082
1092
  return t.options.allowDangerousXml ? e.value : re(e);
1083
1093
  }
1084
- const At = {}.hasOwnProperty, U = {
1085
- cdata: bt,
1086
- comment: Dt,
1087
- doctype: Lt,
1088
- element: wt,
1089
- instruction: Tt,
1090
- raw: qt,
1094
+ const Ft = {}.hasOwnProperty, U = {
1095
+ cdata: Lt,
1096
+ comment: xt,
1097
+ doctype: It,
1098
+ element: Tt,
1099
+ instruction: At,
1100
+ raw: Rt,
1091
1101
  root: le,
1092
1102
  text: re
1093
1103
  };
@@ -1095,7 +1105,7 @@ function se(e, t) {
1095
1105
  const n = e && e.type;
1096
1106
  if (!n)
1097
1107
  throw new Error("Expected node, not `" + e + "`");
1098
- if (!At.call(U, n))
1108
+ if (!Ft.call(U, n))
1099
1109
  throw new Error("Cannot compile unknown node `" + n + "`");
1100
1110
  const o = U[n];
1101
1111
  return o(e, t);
@@ -1108,7 +1118,7 @@ function le(e, t) {
1108
1118
  i[o] = se(n[o], t);
1109
1119
  return i.join("");
1110
1120
  }
1111
- function $t(e, t) {
1121
+ function Mt(e, t) {
1112
1122
  const n = { options: t || {} };
1113
1123
  if (typeof n.options.quote == "string" && n.options.quote !== '"' && n.options.quote !== "'")
1114
1124
  throw new Error(
@@ -1117,18 +1127,18 @@ function $t(e, t) {
1117
1127
  const o = Array.isArray(e) ? { type: "root", children: e } : e;
1118
1128
  return se(o, n);
1119
1129
  }
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, {
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, {
1123
1133
  closeEmptyElements: !0,
1124
1134
  tightClose: !0
1125
1135
  });
1126
1136
  }
1127
1137
  export {
1128
- _t as DIRECTIVE_MAP,
1138
+ jt as DIRECTIVE_MAP,
1129
1139
  Y as PROOF_SOLUTION_NAMES,
1130
- jt as markdownToPretext,
1131
- B as mdastToPtxast,
1132
- Pt as remarkMath,
1133
- st as remarkPretext
1140
+ Wt as markdownToPretext,
1141
+ j as mdastToPtxast,
1142
+ zt as remarkMath,
1143
+ ut as remarkPretext
1134
1144
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretextbook/remark-pretext",
3
- "version": "0.0.13",
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",