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