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