@pretextbook/remark-pretext 0.0.7 → 0.0.8
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 +282 -240
- package/dist/lib/context.d.ts +5 -1
- package/dist/lib/frontmatter.d.ts +6 -2
- package/dist/lib/mdast-to-ptxast.d.ts +5 -1
- package/dist/lib/plus-include.d.ts +27 -0
- package/dist/lib/remark-pretext.d.ts +8 -1
- 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 z=require("unified"),W=require("remark-parse"),U=require("remark-directive"),$=require("@pretextbook/ptxast"),H=require("unist-util-visit"),L={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}},le=L;function ce(e){return L[e.toLowerCase()]}const F=new Set(Object.entries(L).filter(([e,t])=>t.category==="proof-like"||t.category==="solution-like").map(([e])=>e));function b(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function D(e){return e.type==="containerDirective"&&e.name==="task"}function ae(e){return e.type==="containerDirective"&&F.has(e.name)}function w(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(b("p",[n])):t.push(n);return t}function ue(e,t,n,o,r,i,s){const l=[];if(n&&l.push(n),e.hasNestedTasks){const c=o.findIndex(D);if(c!==-1){const a=[];for(let p=0;p<o.length;p++)D(o[p])&&a.push(p);const u=a[a.length-1],d=o.slice(0,c),m=o.slice(c).filter(D),k=[],y=[],_=[];for(let p=c;p<o.length;p++){const f=o[p];if(!D(f)){if(p<u){k.push(f);continue}if(ae(f)){_.push(f);continue}y.push(f)}}if(k.length>0&&(r.messages??(r.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=w(d.map(f=>i(f,r)).filter(f=>f!==null));p.length>0&&l.push(b("introduction",p))}for(const p of m){const f=s(p,r);f&&l.push(f)}if(y.length>0){const p=w(y.map(f=>i(f,r)).filter(f=>f!==null));p.length>0&&l.push(b("conclusion",p))}for(const p of _){const f=s(p,r);f&&l.push(f)}}else P(l,e,o,r,i,s)}else P(l,e,o,r,i,s);return b(e.type,l,t)}function P(e,t,n,o,r,i){if(t.requiresStatement){const s=[],l=[];for(const c of n)if(c.type==="containerDirective"&&F.has(c.name)){const a=i(c,o);a&&l.push(a)}else s.push(c);if(s.length>0){const c=w(s.map(a=>r(a,o)).filter(a=>a!==null));c.length>0&&e.push(b("statement",c))}e.push(...l)}else{const s=w(n.map(l=>r(l,o)).filter(l=>l!==null));e.push(...s)}}function V(e){return{type:"text",value:e}}function h(e,t,n){return{type:"element",name:e,attributes:n??{},children:t}}function g(e,t,n){return h(e,[V(t)],n)}function Z(e){return{type:"comment",value:e.replace(/--/g,"- -")}}function O(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 X(e,t,n){return h("TODO",[Z(`todo: ${t}`),g("pre",n)],{type:e})}function pe(e,t,n){return h("TODO",[Z(`todo: ${t}`),g("c",n)],{type:e})}function N(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 q(e,t,n){return fe(e,t,n).tree}function fe(e,t,n){const o=[],r={ancestors:[],depth:0,messages:o,source:t,topLevelDivision:n?.topLevelDivision??"chapter",topLevelAttributes:n?.topLevelAttributes,topLevelAttributesApplied:n?.topLevelAttributes?{done:!1}:void 0},i=e.children;if($.isTitlelessDivisionType(r.topLevelDivision)){const l=K(r),c=N(T(i,{...r,depth:1},!0));return{tree:{type:"root",children:[h(r.topLevelDivision,c,l)]},messages:o}}return{tree:{type:"root",children:T(i,r)},messages:o}}function T(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 C(e,t,n);const r=[];let i=null,s=[],l=[];const c=()=>{i&&(r.push(he(i,l,t)),i=null,l=[])};for(const a of e)a.type==="heading"&&a.depth===o?(!i&&s.length>0&&(r.push(...C(s,t,n)),s=[]),c(),i=a,l=[]):i?l.push(a):s.push(a);return!i&&s.length>0&&r.push(...C(s,t,n)),c(),r}function C(e,t,n=!1){const o=[];for(let r=0;r<e.length;r+=1){const i=e[r],s=E(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?E(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?N(o):o}function he(e,t,n){const o=$.divisionTypeAtRelativeDepth(n.topLevelDivision,e.depth),r=h("title",x(e.children,n)),i=me(e,n),s=T(t,{...n,depth:n.depth+1},!0),l=N(s);return h(o,[r,...l],i)}function de(e){const t=e.data;return t?.id?{"xml:id":t.id}:void 0}function me(e,t){const n=de(e),o=K(t);if(!(!n&&!o))return{...o,...n}}function K(e){if(e.depth!==0)return;const t=e.topLevelAttributesApplied;if(!(!e.topLevelAttributes||!t||t.done))return t.done=!0,e.topLevelAttributes}const ge={paragraph:(e,t)=>Y(e,t),blockquote:(e,t)=>ye(e,t),list:(e,t)=>ve(e,t),code:(e,t)=>be(e),containerDirective:(e,t)=>G(e,t)};function E(e,t){const n=ge[e.type];return n?n(e,t):(t.messages&&t.messages.push({type:"warning",reason:`Unknown block type: ${e.type}`,category:"unknown-block-type"}),X("unknown-block-type",`unknown block type "${e.type}"`,O(e,t)))}function Y(e,t){return h("p",x(e.children,t))}function ye(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 ve(e,t){const n=e.children.map(o=>{const r={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return ke(o,r)});return h(e.ordered?"ol":"ul",n)}function ke(e,t){const n=C(e.children,t);return h("li",n)}function be(e,t){return g("program",e.value,e.lang?{language:e.lang}:void 0)}function xe(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=>g("mrow",o))):g("md",n[0]??"")}function De(e,t){return e.meta==="inline"?g("m",e.value):xe(e)}function G(e,t){const n=ce(e.name);if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown directive: ${e.name}`,category:"unknown-directive"}),X("unknown-directive",`unknown directive "${e.name}"`,O(e,t));const o=we(e),r=e.children,{title:i,body:s}=Ce(r,t),l={...t,ancestors:[...t.ancestors,e],depth:t.depth+1};return ue(n,o,i,s,l,(c,a)=>E(c,a),(c,a)=>G(c,a))}function Ce(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 we(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 Se(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 Le={text:(e,t)=>V(e.value),emphasis:(e,t)=>{const o=Se(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)=>g("c",e.value),math:(e,t)=>De(e)};function x(e,t){return e.flatMap(n=>Ie(n,t)).filter(n=>n!==null)}function Ie(e,t){const n=Le[e.type];if(!n)return t.messages&&t.messages.push({type:"warning",reason:`Unknown inline type: ${e.type}`,category:"unknown-inline-type"}),pe("unknown-inline-type",`unknown inline type "${e.type}"`,O(e,t));const o={...t,ancestors:[...t.ancestors,e]};return n(e,o)}const qe=[{open:"$$",close:"$$",isDisplay:!0},{open:"\\[",close:"\\]",isDisplay:!0},{open:"$",close:"$",isDisplay:!1},{open:"\\(",close:"\\)",isDisplay:!1}],J="PTX_MATH_TOKEN_",I=new RegExp(`${J}(\\d+)`,"g");function Q(e,t){let n=null;for(const o of qe){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 Te(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 Ee(e){const t=new Map;let n="",o=0,r=0;for(;o<e.length;){const i=Te(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 Ae(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 Me(e,t){const n=[];let o=0;I.lastIndex=0;let r=I.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=I.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){H.visit(e,"paragraph",t=>{const n=t.children||[],o=[];for(const r of n)if(r.type==="text"){const i=Ae(r.value);o.push(...i)}else o.push(r);t.children=o})}function $e(e,t){H.visit(e,"paragraph",n=>{const o=n.children||[],r=[];for(const i of o)if(i.type==="text"){const s=Me(i.value,t);r.push(...s)}else r.push(i);n.children=r})}const Fe=()=>e=>{ee(e)};function Oe(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 Ne(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 _e(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 Pe(e){const t=e.split(`
|
|
2
|
-
`),n=[];let o=!1,r=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];o?r&&m[0]===r[0]&&m.length>=r.length&&(o=!1,r=null):(o=!0,r=m);continue}if(o)continue;const d=
|
|
3
|
-
`)}function
|
|
4
|
-
`),n=[],o={level:0,openDirectives:[],inCodeFence:!1,codeFenceMarker:null};for(let r=0;r<t.length;r++){const i=t[r],s=i.trim(),l
|
|
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,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,r=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];o?r&&m[0]===r[0]&&m.length>=r.length&&(o=!1,r=null):(o=!0,r=m);continue}if(o)continue;const d=_e(c);d&&n.push({...d,lineIndex:l})}if(n.length===0)return e;const i=Pe(n);for(const l of i)te(l);return je(t,i).join(`
|
|
3
|
+
`)}function ze(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[,r,i]=o;return i&&!/^(\[[^\]]*\]|\{[^}]*\})*$/.test(i)||!E[r.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 Ue(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 We(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 He(e){const t=e.split(`
|
|
4
|
+
`),n=[],o={level:0,openDirectives:[],inCodeFence:!1,codeFenceMarker:null};for(let r=0;r<t.length;r++){const i=t[r],s=i.trim(),l=$(i),c=s.match(/^(`{3,}|~{3,})/);if(c){const u=c[1];o.inCodeFence?o.codeFenceMarker&&s.startsWith(o.codeFenceMarker)&&(o.inCodeFence=!1,o.codeFenceMarker=null):(o.inCodeFence=!0,o.codeFenceMarker=u),n.push(i);continue}if(o.inCodeFence){n.push(i);continue}if(ne(i)){n.push("");continue}const a=ze(s);if(a&&Ue(t,r)){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 u=a.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/),d=u?u[1].toLowerCase()+(u[2]||""):a,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 u=o.openDirectives.pop();u&&n.push(":".repeat(u.colonCount))}if(o.openDirectives.length>0){const u=o.openDirectives[o.openDirectives.length-1];u.bodyBaseIndent<0&&(u.bodyBaseIndent=l),n.push(We(i,u.bodyBaseIndent))}else n.push(i);o.level=l}}for(;o.openDirectives.length>0;){const r=o.openDirectives.pop();r&&n.push(":".repeat(r.colonCount))}return n.join(`
|
|
5
|
+
`)}const Ve=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/,Xe=/^division:\s*(\S+)\s*$/m,Ze=/^xmlid:\s*(\S+)\s*$/m,Ke=/^xml:id:\s*(\S+)\s*$/m,Ye=/^label:\s*(\S+)\s*$/m,Ge=/^component:\s*(\S+)\s*$/m;function Je(e){const t=e.match(Ve);if(!t)return{body:e};const n=t[1],o=e.slice(t[0].length),r=n.match(Xe)?.[1];let i,s;r&&g.isRootDivisionType(r)?(s=r,i=g.rootChildDivision(r)):r&&g.isTopLevelDivisionType(r)&&(i=r);const l={},c=n.match(Ze)?.[1]??n.match(Ke)?.[1],a=n.match(Ye)?.[1],u=n.match(Ge)?.[1];return c&&(l["xml:id"]=c),a&&(l.label=a),u&&(l.component=u),{division:i,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 r=Je(o.value),i=e?.documentRoot??r.documentRoot,s=e?.topLevelDivision??r.division??(i?g.rootChildDivision(i):"chapter"),l=e?.topLevelAttributes??r.attributes,c=He(r.body),a=Be(c),u=Re(a),m=W.unified().data("micromarkExtensions",[{disable:{null:["codeIndented"]}}]).use(H).use(V).parse(u.markdown);return Oe(m,u.tokens),A(m,u.markdown,{topLevelDivision:s,documentRoot:i,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})}},Qe=/["&'<>`]/g,et=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,tt=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,nt=/[|\\{}()[\]^$+*?.]/g,B=new WeakMap;function ot(e,t){if(e=e.replace(t.subset?rt(t.subset):Qe,o),t.subset||t.escapeOnly)return e;return e.replace(et,n).replace(tt,o);function n(r,i,s){return t.format((r.charCodeAt(0)-55296)*1024+r.charCodeAt(1)-56320+65536,s.charCodeAt(i+2),t)}function o(r,i,s){return t.format(r.charCodeAt(0),s.charCodeAt(i+1),t)}}function rt(e){let t=B.get(e);return t||(t=it(e),B.set(e,t)),t}function it(e){const t=[];let n=-1;for(;++n<e.length;)t.push(e[n].replace(nt,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}function st(e){return"&#x"+e.toString(16).toUpperCase()+";"}function lt(e,t){return ot(e,Object.assign({format:st},t))}const ct=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function k(e,t,n){const o=at(e);return n?o.replace(n,r):r(o);function r(i){return lt(i,{subset:t})}}function at(e){return String(e||"").replace(ct,"")}const ut=/]]>/g,pt=[">"];function ft(e){return"<![CDATA["+k(e.value,pt,ut)+"]]>"}function ht(e){return"<!--"+k(e.value,["-"])+"-->"}const dt=[" ",`
|
|
6
|
+
`," ",'"',"&","'","/","<","=",">"];function L(e){return k(e,dt)}function z(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let o=0,r=n.indexOf(t);for(;r!==-1;)o++,r=n.indexOf(t,r+t.length);return o}function F(e,t){const n=String(e);let o=t.options.quote||'"';if(t.options.quoteSmart){const r=o==='"'?"'":'"';z(n,o)>z(n,r)&&(o=r)}return o+k(n,["<","&",o])+o}function mt(e,t){const n=L(e.name),o=e.public,r=e.system;let i="<!DOCTYPE";return n!==""&&(i+=" "+n),o?i+=" PUBLIC "+F(o,t):r&&(i+=" SYSTEM"),r&&(i+=" "+F(r,t)),i+">"}const gt={}.hasOwnProperty;function yt(e,t){const n=L(e.name),o=se(e,t),r=e.attributes||{},i=o?!1:t.options.closeEmptyElements,s=[];let l;for(l in r)if(gt.call(r,l)){const c=r[l];c!=null&&s.push(L(l)+"="+F(c,t))}return"<"+n+(s.length===0?"":" "+s.join(" "))+(i?(t.options.tightClose?"":" ")+"/":"")+">"+o+(i?"":"</"+n+">")}const vt=/\?>/g,kt=[">"];function bt(e){const t=L(e.name)||"x",n=k(e.value,kt,vt);return"<?"+t+(n?" "+n:"")+"?>"}const Dt=["&","<"];function re(e){return k(e.value,Dt)}function xt(e,t){return t.options.allowDangerousXml?e.value:re(e)}const Ct={}.hasOwnProperty,U={cdata:ft,comment:ht,doctype:mt,element:yt,instruction:bt,raw:xt,root:se,text:re};function ie(e,t){const n=e&&e.type;if(!n)throw new Error("Expected node, not `"+e+"`");if(!Ct.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 r=[];for(;++o<n.length;)r[o]=ie(n[o],t);return r.join("")}function wt(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 ie(o,n)}function St(e,t){const n=W.unified().use(H).use(V).use(oe,t),o=n.parse(e),r=n.runSync(o,{value:e});return wt(r.children,{closeEmptyElements:!0,tightClose:!0})}exports.DIRECTIVE_MAP=ae;exports.PROOF_SOLUTION_NAMES=O;exports.markdownToPretext=St;exports.mdastToPtxast=A;exports.remarkMath=Ne;exports.remarkPretext=oe;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
import { unified as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { isTitlelessDivisionType as
|
|
5
|
-
import { visit as
|
|
1
|
+
import { unified as W } from "unified";
|
|
2
|
+
import U from "remark-parse";
|
|
3
|
+
import H from "remark-directive";
|
|
4
|
+
import { isTitlelessDivisionType as se, divisionTypeAtRootDepth as le, divisionTypeAtRelativeDepth as ce, isRootDivisionType as ae, rootChildDivision as q, isTopLevelDivisionType as ue } from "@pretextbook/ptxast";
|
|
5
|
+
import { visit as X } from "unist-util-visit";
|
|
6
|
+
function pe(e, t = {}) {
|
|
7
|
+
const n = {};
|
|
8
|
+
for (const [o, r] of Object.entries(t))
|
|
9
|
+
r != null && (n[o] = r);
|
|
10
|
+
return {
|
|
11
|
+
type: "element",
|
|
12
|
+
name: `plus:${e}`,
|
|
13
|
+
attributes: n,
|
|
14
|
+
children: []
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function fe(e) {
|
|
18
|
+
const t = e.name?.trim();
|
|
19
|
+
return t ? pe(t, e.attributes ?? {}) : null;
|
|
20
|
+
}
|
|
6
21
|
const S = {
|
|
7
22
|
// theorem-like (requires statement wrapping)
|
|
8
23
|
theorem: { type: "theorem", category: "theorem-like", requiresStatement: !0 },
|
|
@@ -44,11 +59,11 @@ const S = {
|
|
|
44
59
|
solution: { type: "solution", category: "solution-like", requiresStatement: !1 },
|
|
45
60
|
hint: { type: "hint", category: "solution-like", requiresStatement: !1 },
|
|
46
61
|
answer: { type: "answer", category: "solution-like", requiresStatement: !1 }
|
|
47
|
-
},
|
|
48
|
-
function
|
|
62
|
+
}, Mt = S;
|
|
63
|
+
function he(e) {
|
|
49
64
|
return S[e.toLowerCase()];
|
|
50
65
|
}
|
|
51
|
-
const
|
|
66
|
+
const Z = new Set(
|
|
52
67
|
Object.entries(S).filter(([e, t]) => t.category === "proof-like" || t.category === "solution-like").map(([e]) => e)
|
|
53
68
|
);
|
|
54
69
|
function b(e, t, n) {
|
|
@@ -59,36 +74,36 @@ function b(e, t, n) {
|
|
|
59
74
|
children: t
|
|
60
75
|
};
|
|
61
76
|
}
|
|
62
|
-
function
|
|
77
|
+
function x(e) {
|
|
63
78
|
return e.type === "containerDirective" && e.name === "task";
|
|
64
79
|
}
|
|
65
|
-
function
|
|
66
|
-
return e.type === "containerDirective" &&
|
|
80
|
+
function de(e) {
|
|
81
|
+
return e.type === "containerDirective" && Z.has(e.name);
|
|
67
82
|
}
|
|
68
|
-
function
|
|
83
|
+
function L(e) {
|
|
69
84
|
const t = [];
|
|
70
85
|
for (const n of e)
|
|
71
86
|
n.name === "ul" || n.name === "ol" ? t.length > 0 && t[t.length - 1]?.name === "p" ? t[t.length - 1].children.push(n) : t.push(b("p", [n])) : t.push(n);
|
|
72
87
|
return t;
|
|
73
88
|
}
|
|
74
|
-
function
|
|
89
|
+
function me(e, t, n, o, r, i, s) {
|
|
75
90
|
const l = [];
|
|
76
91
|
if (n && l.push(n), e.hasNestedTasks) {
|
|
77
|
-
const c = o.findIndex(
|
|
92
|
+
const c = o.findIndex(x);
|
|
78
93
|
if (c !== -1) {
|
|
79
94
|
const a = [];
|
|
80
95
|
for (let p = 0; p < o.length; p++)
|
|
81
|
-
|
|
82
|
-
const u = a[a.length - 1], d = o.slice(0, c), m = o.slice(c).filter(
|
|
96
|
+
x(o[p]) && a.push(p);
|
|
97
|
+
const u = a[a.length - 1], d = o.slice(0, c), m = o.slice(c).filter(x), k = [], y = [], O = [];
|
|
83
98
|
for (let p = c; p < o.length; p++) {
|
|
84
99
|
const f = o[p];
|
|
85
|
-
if (!
|
|
100
|
+
if (!x(f)) {
|
|
86
101
|
if (p < u) {
|
|
87
102
|
k.push(f);
|
|
88
103
|
continue;
|
|
89
104
|
}
|
|
90
|
-
if (
|
|
91
|
-
|
|
105
|
+
if (de(f)) {
|
|
106
|
+
O.push(f);
|
|
92
107
|
continue;
|
|
93
108
|
}
|
|
94
109
|
y.push(f);
|
|
@@ -100,7 +115,7 @@ function ue(e, t, n, o, r, i, s) {
|
|
|
100
115
|
category: "dropped-content-between-tasks",
|
|
101
116
|
position: k[0].position?.start
|
|
102
117
|
}), d.length > 0) {
|
|
103
|
-
const p =
|
|
118
|
+
const p = L(
|
|
104
119
|
d.map((f) => i(f, r)).filter((f) => f !== null)
|
|
105
120
|
);
|
|
106
121
|
p.length > 0 && l.push(b("introduction", p));
|
|
@@ -110,45 +125,45 @@ function ue(e, t, n, o, r, i, s) {
|
|
|
110
125
|
f && l.push(f);
|
|
111
126
|
}
|
|
112
127
|
if (y.length > 0) {
|
|
113
|
-
const p =
|
|
128
|
+
const p = L(
|
|
114
129
|
y.map((f) => i(f, r)).filter((f) => f !== null)
|
|
115
130
|
);
|
|
116
131
|
p.length > 0 && l.push(b("conclusion", p));
|
|
117
132
|
}
|
|
118
|
-
for (const p of
|
|
133
|
+
for (const p of O) {
|
|
119
134
|
const f = s(p, r);
|
|
120
135
|
f && l.push(f);
|
|
121
136
|
}
|
|
122
137
|
} else
|
|
123
|
-
|
|
138
|
+
_(l, e, o, r, i, s);
|
|
124
139
|
} else
|
|
125
|
-
|
|
140
|
+
_(l, e, o, r, i, s);
|
|
126
141
|
return b(e.type, l, t);
|
|
127
142
|
}
|
|
128
|
-
function
|
|
143
|
+
function _(e, t, n, o, r, i) {
|
|
129
144
|
if (t.requiresStatement) {
|
|
130
145
|
const s = [], l = [];
|
|
131
146
|
for (const c of n)
|
|
132
|
-
if (c.type === "containerDirective" &&
|
|
147
|
+
if (c.type === "containerDirective" && Z.has(c.name)) {
|
|
133
148
|
const a = i(c, o);
|
|
134
149
|
a && l.push(a);
|
|
135
150
|
} else
|
|
136
151
|
s.push(c);
|
|
137
152
|
if (s.length > 0) {
|
|
138
|
-
const c =
|
|
153
|
+
const c = L(
|
|
139
154
|
s.map((a) => r(a, o)).filter((a) => a !== null)
|
|
140
155
|
);
|
|
141
156
|
c.length > 0 && e.push(b("statement", c));
|
|
142
157
|
}
|
|
143
158
|
e.push(...l);
|
|
144
159
|
} else {
|
|
145
|
-
const s =
|
|
160
|
+
const s = L(
|
|
146
161
|
n.map((l) => r(l, o)).filter((l) => l !== null)
|
|
147
162
|
);
|
|
148
163
|
e.push(...s);
|
|
149
164
|
}
|
|
150
165
|
}
|
|
151
|
-
function
|
|
166
|
+
function V(e) {
|
|
152
167
|
return { type: "text", value: e };
|
|
153
168
|
}
|
|
154
169
|
function h(e, t, n) {
|
|
@@ -160,81 +175,89 @@ function h(e, t, n) {
|
|
|
160
175
|
};
|
|
161
176
|
}
|
|
162
177
|
function g(e, t, n) {
|
|
163
|
-
return h(e, [
|
|
178
|
+
return h(e, [V(t)], n);
|
|
164
179
|
}
|
|
165
|
-
function
|
|
180
|
+
function K(e) {
|
|
166
181
|
return { type: "comment", value: e.replace(/--/g, "- -") };
|
|
167
182
|
}
|
|
168
|
-
function
|
|
183
|
+
function E(e, t) {
|
|
169
184
|
const n = e?.position, o = n?.start?.offset, r = n?.end?.offset;
|
|
170
185
|
return t.source && o != null && r != null ? t.source.slice(o, r) : "";
|
|
171
186
|
}
|
|
172
|
-
function
|
|
173
|
-
return h("TODO", [
|
|
187
|
+
function F(e, t, n) {
|
|
188
|
+
return h("TODO", [K(`todo: ${t}`), g("pre", n)], {
|
|
174
189
|
type: e
|
|
175
190
|
});
|
|
176
191
|
}
|
|
177
|
-
function
|
|
178
|
-
return h("TODO", [
|
|
192
|
+
function ge(e, t, n) {
|
|
193
|
+
return h("TODO", [K(`todo: ${t}`), g("c", n)], {
|
|
179
194
|
type: e
|
|
180
195
|
});
|
|
181
196
|
}
|
|
182
|
-
function
|
|
197
|
+
function N(e) {
|
|
183
198
|
const t = [];
|
|
184
199
|
for (const n of e)
|
|
185
200
|
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);
|
|
186
201
|
return t;
|
|
187
202
|
}
|
|
188
|
-
function
|
|
189
|
-
return
|
|
203
|
+
function P(e, t, n) {
|
|
204
|
+
return ye(e, t, n).tree;
|
|
190
205
|
}
|
|
191
|
-
function
|
|
206
|
+
function ye(e, t, n) {
|
|
192
207
|
const o = [], r = {
|
|
193
208
|
ancestors: [],
|
|
194
209
|
depth: 0,
|
|
195
210
|
messages: o,
|
|
196
211
|
source: t,
|
|
197
212
|
topLevelDivision: n?.topLevelDivision ?? "chapter",
|
|
213
|
+
documentRoot: n?.documentRoot,
|
|
198
214
|
topLevelAttributes: n?.topLevelAttributes,
|
|
199
215
|
topLevelAttributesApplied: n?.topLevelAttributes ? { done: !1 } : void 0
|
|
200
216
|
}, i = e.children;
|
|
201
|
-
if (
|
|
202
|
-
const l =
|
|
203
|
-
|
|
217
|
+
if (r.documentRoot) {
|
|
218
|
+
const l = A(r), c = C(i, r);
|
|
219
|
+
return {
|
|
220
|
+
tree: { type: "root", children: [h(r.documentRoot, c, l)] },
|
|
221
|
+
messages: o
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
if (se(r.topLevelDivision)) {
|
|
225
|
+
const l = A(r), c = N(
|
|
226
|
+
C(i, { ...r, depth: 1 }, !0)
|
|
204
227
|
);
|
|
205
228
|
return { tree: { type: "root", children: [h(r.topLevelDivision, c, l)] }, messages: o };
|
|
206
229
|
}
|
|
207
230
|
return {
|
|
208
|
-
tree: { type: "root", children:
|
|
231
|
+
tree: { type: "root", children: C(i, r) },
|
|
209
232
|
messages: o
|
|
210
233
|
};
|
|
211
234
|
}
|
|
212
|
-
function
|
|
235
|
+
function C(e, t, n = !1) {
|
|
213
236
|
let o = 7;
|
|
214
237
|
for (const a of e)
|
|
215
238
|
a.type === "heading" && (o = Math.min(o, a.depth));
|
|
216
239
|
if (o === 7)
|
|
217
|
-
return
|
|
240
|
+
return w(e, t, n);
|
|
218
241
|
const r = [];
|
|
219
242
|
let i = null, s = [], l = [];
|
|
220
243
|
const c = () => {
|
|
221
|
-
i && (r.push(
|
|
244
|
+
i && (r.push(ve(i, l, t)), i = null, l = []);
|
|
222
245
|
};
|
|
223
246
|
for (const a of e)
|
|
224
247
|
a.type === "heading" && a.depth === o ? (!i && s.length > 0 && (r.push(
|
|
225
|
-
...
|
|
248
|
+
...w(s, t, n)
|
|
226
249
|
), s = []), c(), i = a, l = []) : i ? l.push(a) : s.push(a);
|
|
227
250
|
return !i && s.length > 0 && r.push(
|
|
228
|
-
...
|
|
251
|
+
...w(s, t, n)
|
|
229
252
|
), c(), r;
|
|
230
253
|
}
|
|
231
|
-
function
|
|
254
|
+
function w(e, t, n = !1) {
|
|
232
255
|
const o = [];
|
|
233
256
|
for (let r = 0; r < e.length; r += 1) {
|
|
234
|
-
const i = e[r], s =
|
|
257
|
+
const i = e[r], s = $(i, t);
|
|
235
258
|
if (s !== null) {
|
|
236
259
|
if (s.name === "p" && s.children.length === 1 && s.children[0].name === "md") {
|
|
237
|
-
const l = s.children[0], c = o[o.length - 1], a = r + 1 < e.length ?
|
|
260
|
+
const l = s.children[0], c = o[o.length - 1], a = r + 1 < e.length ? $(e[r + 1], t) : null, u = a?.name === "p" ? a.children : null;
|
|
238
261
|
if (c?.name === "p")
|
|
239
262
|
c.children.push(l), u && (c.children.push(
|
|
240
263
|
...u
|
|
@@ -255,115 +278,125 @@ function C(e, t, n = !1) {
|
|
|
255
278
|
o.push(s);
|
|
256
279
|
}
|
|
257
280
|
}
|
|
258
|
-
return n ?
|
|
281
|
+
return n ? N(o) : o;
|
|
259
282
|
}
|
|
260
|
-
function
|
|
261
|
-
const o =
|
|
262
|
-
n.topLevelDivision,
|
|
263
|
-
e.depth
|
|
264
|
-
), r = h("title", x(e.children, n)), i = me(e, n), s = q(
|
|
283
|
+
function ve(e, t, n) {
|
|
284
|
+
const o = n.documentRoot ? le(n.documentRoot, e.depth) : ce(n.topLevelDivision, e.depth), r = h("title", D(e.children, n)), i = be(e, n), s = C(
|
|
265
285
|
t,
|
|
266
286
|
{ ...n, depth: n.depth + 1 },
|
|
267
287
|
!0
|
|
268
|
-
), l =
|
|
288
|
+
), l = N(s);
|
|
269
289
|
return h(o, [r, ...l], i);
|
|
270
290
|
}
|
|
271
|
-
function
|
|
291
|
+
function ke(e) {
|
|
272
292
|
const t = e.data;
|
|
273
293
|
return t?.id ? { "xml:id": t.id } : void 0;
|
|
274
294
|
}
|
|
275
|
-
function
|
|
276
|
-
const n =
|
|
295
|
+
function be(e, t) {
|
|
296
|
+
const n = ke(e), o = A(t);
|
|
277
297
|
if (!(!n && !o))
|
|
278
298
|
return { ...o, ...n };
|
|
279
299
|
}
|
|
280
|
-
function
|
|
300
|
+
function A(e) {
|
|
281
301
|
if (e.depth !== 0) return;
|
|
282
302
|
const t = e.topLevelAttributesApplied;
|
|
283
303
|
if (!(!e.topLevelAttributes || !t || t.done))
|
|
284
304
|
return t.done = !0, e.topLevelAttributes;
|
|
285
305
|
}
|
|
286
|
-
const
|
|
287
|
-
paragraph: (e, t) =>
|
|
288
|
-
blockquote: (e, t) =>
|
|
289
|
-
list: (e, t) =>
|
|
290
|
-
code: (e, t) =>
|
|
291
|
-
containerDirective: (e, t) =>
|
|
306
|
+
const De = {
|
|
307
|
+
paragraph: (e, t) => Y(e, t),
|
|
308
|
+
blockquote: (e, t) => xe(e, t),
|
|
309
|
+
list: (e, t) => Ce(e, t),
|
|
310
|
+
code: (e, t) => Le(e),
|
|
311
|
+
containerDirective: (e, t) => G(e, t),
|
|
312
|
+
leafDirective: (e, t) => Ee(e, t)
|
|
292
313
|
};
|
|
293
|
-
function
|
|
294
|
-
const n =
|
|
314
|
+
function $(e, t) {
|
|
315
|
+
const n = De[e.type];
|
|
295
316
|
return n ? n(e, t) : (t.messages && t.messages.push({
|
|
296
317
|
type: "warning",
|
|
297
318
|
reason: `Unknown block type: ${e.type}`,
|
|
298
319
|
category: "unknown-block-type"
|
|
299
|
-
}),
|
|
320
|
+
}), F(
|
|
300
321
|
"unknown-block-type",
|
|
301
322
|
`unknown block type "${e.type}"`,
|
|
302
|
-
|
|
323
|
+
E(e, t)
|
|
303
324
|
));
|
|
304
325
|
}
|
|
305
|
-
function
|
|
306
|
-
return h("p",
|
|
326
|
+
function Y(e, t) {
|
|
327
|
+
return h("p", D(e.children, t));
|
|
307
328
|
}
|
|
308
|
-
function
|
|
329
|
+
function xe(e, t) {
|
|
309
330
|
const n = e.children.filter((o) => o.type === "paragraph").map((o) => {
|
|
310
331
|
const r = {
|
|
311
332
|
...t,
|
|
312
333
|
ancestors: [...t.ancestors, e],
|
|
313
334
|
depth: t.depth + 1
|
|
314
335
|
};
|
|
315
|
-
return
|
|
336
|
+
return Y(o, r);
|
|
316
337
|
});
|
|
317
338
|
return h("blockquote", n);
|
|
318
339
|
}
|
|
319
|
-
function
|
|
340
|
+
function Ce(e, t) {
|
|
320
341
|
const n = e.children.map((o) => {
|
|
321
342
|
const r = {
|
|
322
343
|
...t,
|
|
323
344
|
ancestors: [...t.ancestors, e],
|
|
324
345
|
depth: t.depth + 1
|
|
325
346
|
};
|
|
326
|
-
return
|
|
347
|
+
return we(o, r);
|
|
327
348
|
});
|
|
328
349
|
return h(e.ordered ? "ol" : "ul", n);
|
|
329
350
|
}
|
|
330
|
-
function
|
|
331
|
-
const n =
|
|
351
|
+
function we(e, t) {
|
|
352
|
+
const n = w(
|
|
332
353
|
e.children,
|
|
333
354
|
t
|
|
334
355
|
);
|
|
335
356
|
return h("li", n);
|
|
336
357
|
}
|
|
337
|
-
function
|
|
358
|
+
function Le(e, t) {
|
|
338
359
|
return g(
|
|
339
360
|
"program",
|
|
340
361
|
e.value,
|
|
341
362
|
e.lang ? { language: e.lang } : void 0
|
|
342
363
|
);
|
|
343
364
|
}
|
|
344
|
-
function
|
|
365
|
+
function Ie(e, t) {
|
|
345
366
|
const n = e.value.split(/\\\\|[\r\n]+/).map((o) => o.trim()).filter((o) => o.length > 0);
|
|
346
367
|
return n.length > 1 ? h(
|
|
347
368
|
"md",
|
|
348
369
|
n.map((o) => g("mrow", o))
|
|
349
370
|
) : g("md", n[0] ?? "");
|
|
350
371
|
}
|
|
351
|
-
function
|
|
352
|
-
return e.meta === "inline" ? g("m", e.value) :
|
|
372
|
+
function Se(e, t) {
|
|
373
|
+
return e.meta === "inline" ? g("m", e.value) : Ie(e);
|
|
353
374
|
}
|
|
354
|
-
function
|
|
355
|
-
const n =
|
|
375
|
+
function Ee(e, t) {
|
|
376
|
+
const n = fe(e);
|
|
377
|
+
return n || (t.messages && t.messages.push({
|
|
378
|
+
type: "warning",
|
|
379
|
+
reason: "Unnamed leaf directive",
|
|
380
|
+
category: "unknown-directive"
|
|
381
|
+
}), F(
|
|
382
|
+
"unknown-directive",
|
|
383
|
+
"unnamed leaf directive",
|
|
384
|
+
E(e, t)
|
|
385
|
+
));
|
|
386
|
+
}
|
|
387
|
+
function G(e, t) {
|
|
388
|
+
const n = he(e.name);
|
|
356
389
|
if (!n)
|
|
357
390
|
return t.messages && t.messages.push({
|
|
358
391
|
type: "warning",
|
|
359
392
|
reason: `Unknown directive: ${e.name}`,
|
|
360
393
|
category: "unknown-directive"
|
|
361
|
-
}),
|
|
394
|
+
}), F(
|
|
362
395
|
"unknown-directive",
|
|
363
396
|
`unknown directive "${e.name}"`,
|
|
364
|
-
|
|
397
|
+
E(e, t)
|
|
365
398
|
);
|
|
366
|
-
const o =
|
|
399
|
+
const o = qe(e), r = e.children, { title: i, body: s } = Te(
|
|
367
400
|
r,
|
|
368
401
|
t
|
|
369
402
|
), l = {
|
|
@@ -371,74 +404,74 @@ function Y(e, t) {
|
|
|
371
404
|
ancestors: [...t.ancestors, e],
|
|
372
405
|
depth: t.depth + 1
|
|
373
406
|
};
|
|
374
|
-
return
|
|
407
|
+
return me(
|
|
375
408
|
n,
|
|
376
409
|
o,
|
|
377
410
|
i,
|
|
378
411
|
s,
|
|
379
412
|
l,
|
|
380
|
-
(c, a) =>
|
|
381
|
-
(c, a) =>
|
|
413
|
+
(c, a) => $(c, a),
|
|
414
|
+
(c, a) => G(c, a)
|
|
382
415
|
);
|
|
383
416
|
}
|
|
384
|
-
function
|
|
417
|
+
function Te(e, t) {
|
|
385
418
|
const n = e[0];
|
|
386
419
|
return n?.type === "paragraph" && n.data?.directiveLabel === !0 ? {
|
|
387
420
|
title: h(
|
|
388
421
|
"title",
|
|
389
|
-
|
|
422
|
+
D(n.children, t)
|
|
390
423
|
),
|
|
391
424
|
body: e.slice(1)
|
|
392
425
|
} : { title: null, body: e };
|
|
393
426
|
}
|
|
394
|
-
function
|
|
427
|
+
function qe(e) {
|
|
395
428
|
const t = e.attributes ?? {}, n = {};
|
|
396
429
|
for (const [o, r] of Object.entries(t))
|
|
397
430
|
r != null && (n[o === "id" ? "xml:id" : o] = r);
|
|
398
431
|
return Object.keys(n).length > 0 ? n : void 0;
|
|
399
432
|
}
|
|
400
|
-
function
|
|
433
|
+
function Ae(e, t) {
|
|
401
434
|
return !t || e.position?.start?.offset === null || e.position?.start?.offset === void 0 ? "asterisk" : t.charAt(e.position.start.offset) === "_" ? "underscore" : "asterisk";
|
|
402
435
|
}
|
|
403
|
-
const
|
|
404
|
-
text: (e, t) =>
|
|
436
|
+
const $e = {
|
|
437
|
+
text: (e, t) => V(e.value),
|
|
405
438
|
emphasis: (e, t) => {
|
|
406
|
-
const o =
|
|
407
|
-
return h(o,
|
|
439
|
+
const o = Ae(e, t.source) === "underscore" ? "term" : "em";
|
|
440
|
+
return h(o, D(e.children, t));
|
|
408
441
|
},
|
|
409
|
-
strong: (e, t) => h("alert",
|
|
442
|
+
strong: (e, t) => h("alert", D(e.children, t)),
|
|
410
443
|
inlineCode: (e, t) => g("c", e.value),
|
|
411
|
-
math: (e, t) =>
|
|
444
|
+
math: (e, t) => Se(e)
|
|
412
445
|
};
|
|
413
|
-
function
|
|
414
|
-
return e.flatMap((n) =>
|
|
446
|
+
function D(e, t) {
|
|
447
|
+
return e.flatMap((n) => Me(n, t)).filter((n) => n !== null);
|
|
415
448
|
}
|
|
416
|
-
function
|
|
417
|
-
const n =
|
|
449
|
+
function Me(e, t) {
|
|
450
|
+
const n = $e[e.type];
|
|
418
451
|
if (!n)
|
|
419
452
|
return t.messages && t.messages.push({
|
|
420
453
|
type: "warning",
|
|
421
454
|
reason: `Unknown inline type: ${e.type}`,
|
|
422
455
|
category: "unknown-inline-type"
|
|
423
|
-
}),
|
|
456
|
+
}), ge(
|
|
424
457
|
"unknown-inline-type",
|
|
425
458
|
`unknown inline type "${e.type}"`,
|
|
426
|
-
|
|
459
|
+
E(e, t)
|
|
427
460
|
);
|
|
428
461
|
const o = { ...t, ancestors: [...t.ancestors, e] };
|
|
429
462
|
return n(e, o);
|
|
430
463
|
}
|
|
431
|
-
const
|
|
464
|
+
const Re = [
|
|
432
465
|
// Display math (check these first, before single $)
|
|
433
466
|
{ open: "$$", close: "$$", isDisplay: !0 },
|
|
434
467
|
{ open: "\\[", close: "\\]", isDisplay: !0 },
|
|
435
468
|
// Inline math
|
|
436
469
|
{ open: "$", close: "$", isDisplay: !1 },
|
|
437
470
|
{ open: "\\(", close: "\\)", isDisplay: !1 }
|
|
438
|
-
],
|
|
439
|
-
function
|
|
471
|
+
], J = "PTX_MATH_TOKEN_", T = new RegExp(`${J}(\\d+)`, "g");
|
|
472
|
+
function Q(e, t) {
|
|
440
473
|
let n = null;
|
|
441
|
-
for (const o of
|
|
474
|
+
for (const o of Re) {
|
|
442
475
|
const r = e.indexOf(o.open, t);
|
|
443
476
|
if (r === -1) continue;
|
|
444
477
|
const i = e.indexOf(o.close, r + o.open.length);
|
|
@@ -449,7 +482,7 @@ function J(e, t) {
|
|
|
449
482
|
}
|
|
450
483
|
return n;
|
|
451
484
|
}
|
|
452
|
-
function
|
|
485
|
+
function Fe(e, t) {
|
|
453
486
|
let n = t;
|
|
454
487
|
for (; n < e.length; ) {
|
|
455
488
|
const o = e.indexOf("`", n);
|
|
@@ -471,11 +504,11 @@ function Ee(e, t) {
|
|
|
471
504
|
}
|
|
472
505
|
return null;
|
|
473
506
|
}
|
|
474
|
-
function
|
|
507
|
+
function Ne(e) {
|
|
475
508
|
const t = /* @__PURE__ */ new Map();
|
|
476
509
|
let n = "", o = 0, r = 0;
|
|
477
510
|
for (; o < e.length; ) {
|
|
478
|
-
const i =
|
|
511
|
+
const i = Fe(e, o), s = Q(e, o);
|
|
479
512
|
if (i && (!s || i.start < s.index)) {
|
|
480
513
|
n += e.substring(o, i.end), o = i.end;
|
|
481
514
|
continue;
|
|
@@ -485,7 +518,7 @@ function Te(e) {
|
|
|
485
518
|
break;
|
|
486
519
|
}
|
|
487
520
|
n += e.substring(o, s.index);
|
|
488
|
-
const l = `${
|
|
521
|
+
const l = `${J}${r}`;
|
|
489
522
|
n += l, t.set(l, {
|
|
490
523
|
type: "math",
|
|
491
524
|
value: s.content,
|
|
@@ -494,11 +527,11 @@ function Te(e) {
|
|
|
494
527
|
}
|
|
495
528
|
return { markdown: n, tokens: t };
|
|
496
529
|
}
|
|
497
|
-
function
|
|
530
|
+
function Oe(e) {
|
|
498
531
|
const t = [];
|
|
499
532
|
let n = 0;
|
|
500
533
|
for (; n < e.length; ) {
|
|
501
|
-
const o =
|
|
534
|
+
const o = Q(e, n);
|
|
502
535
|
if (!o) {
|
|
503
536
|
n < e.length && t.push({ type: "text", value: e.substring(n) });
|
|
504
537
|
break;
|
|
@@ -514,47 +547,47 @@ function Ae(e) {
|
|
|
514
547
|
}
|
|
515
548
|
return t.length === 0 ? [{ type: "text", value: e }] : t;
|
|
516
549
|
}
|
|
517
|
-
function
|
|
550
|
+
function _e(e, t) {
|
|
518
551
|
const n = [];
|
|
519
552
|
let o = 0;
|
|
520
|
-
|
|
521
|
-
let r =
|
|
553
|
+
T.lastIndex = 0;
|
|
554
|
+
let r = T.exec(e);
|
|
522
555
|
for (; r; ) {
|
|
523
556
|
const i = r.index, s = r[0];
|
|
524
557
|
i > o && n.push({ type: "text", value: e.substring(o, i) });
|
|
525
558
|
const l = t.get(s);
|
|
526
|
-
l ? n.push(l) : n.push({ type: "text", value: s }), o = i + s.length, r =
|
|
559
|
+
l ? n.push(l) : n.push({ type: "text", value: s }), o = i + s.length, r = T.exec(e);
|
|
527
560
|
}
|
|
528
561
|
return o < e.length && n.push({ type: "text", value: e.substring(o) }), n.length === 0 ? [{ type: "text", value: e }] : n;
|
|
529
562
|
}
|
|
530
|
-
function
|
|
531
|
-
|
|
563
|
+
function ee(e) {
|
|
564
|
+
X(e, "paragraph", (t) => {
|
|
532
565
|
const n = t.children || [], o = [];
|
|
533
566
|
for (const r of n)
|
|
534
567
|
if (r.type === "text") {
|
|
535
|
-
const i =
|
|
568
|
+
const i = Oe(r.value);
|
|
536
569
|
o.push(...i);
|
|
537
570
|
} else
|
|
538
571
|
o.push(r);
|
|
539
572
|
t.children = o;
|
|
540
573
|
});
|
|
541
574
|
}
|
|
542
|
-
function
|
|
543
|
-
|
|
575
|
+
function Pe(e, t) {
|
|
576
|
+
X(e, "paragraph", (n) => {
|
|
544
577
|
const o = n.children || [], r = [];
|
|
545
578
|
for (const i of o)
|
|
546
579
|
if (i.type === "text") {
|
|
547
|
-
const s =
|
|
580
|
+
const s = _e(i.value, t);
|
|
548
581
|
r.push(...s);
|
|
549
582
|
} else
|
|
550
583
|
r.push(i);
|
|
551
584
|
n.children = r;
|
|
552
585
|
});
|
|
553
586
|
}
|
|
554
|
-
const
|
|
555
|
-
|
|
587
|
+
const Rt = () => (e) => {
|
|
588
|
+
ee(e);
|
|
556
589
|
};
|
|
557
|
-
function
|
|
590
|
+
function je(e) {
|
|
558
591
|
const t = e.trim();
|
|
559
592
|
if (!t.startsWith(":")) return null;
|
|
560
593
|
let n = 0;
|
|
@@ -564,7 +597,7 @@ function Fe(e) {
|
|
|
564
597
|
const o = t.slice(n).trim(), r = o.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);
|
|
565
598
|
return o === "" ? { colons: n, label: null, lineIndex: -1, isOpen: !1 } : r ? { colons: n, label: r[0], lineIndex: -1, isOpen: !0 } : null;
|
|
566
599
|
}
|
|
567
|
-
function
|
|
600
|
+
function Be(e) {
|
|
568
601
|
const t = [], n = [];
|
|
569
602
|
for (const o of e)
|
|
570
603
|
if (o.isOpen) {
|
|
@@ -589,16 +622,16 @@ function Ne(e) {
|
|
|
589
622
|
}
|
|
590
623
|
return n;
|
|
591
624
|
}
|
|
592
|
-
function
|
|
625
|
+
function te(e) {
|
|
593
626
|
if (e.children.length === 0)
|
|
594
627
|
e.finalColons = e.colons;
|
|
595
628
|
else {
|
|
596
|
-
const t = Math.max(...e.children.map(
|
|
629
|
+
const t = Math.max(...e.children.map(te));
|
|
597
630
|
e.finalColons = Math.max(e.colons, t + 1);
|
|
598
631
|
}
|
|
599
632
|
return e.finalColons;
|
|
600
633
|
}
|
|
601
|
-
function
|
|
634
|
+
function ze(e, t, n) {
|
|
602
635
|
const o = e.slice(), r = [], i = t.slice();
|
|
603
636
|
for (; i.length > 0; ) {
|
|
604
637
|
const s = i.shift();
|
|
@@ -613,7 +646,7 @@ function Oe(e, t, n) {
|
|
|
613
646
|
}
|
|
614
647
|
return o;
|
|
615
648
|
}
|
|
616
|
-
function
|
|
649
|
+
function We(e) {
|
|
617
650
|
const t = e.split(`
|
|
618
651
|
`), n = [];
|
|
619
652
|
let o = !1, r = null;
|
|
@@ -626,18 +659,18 @@ function _e(e) {
|
|
|
626
659
|
}
|
|
627
660
|
if (o)
|
|
628
661
|
continue;
|
|
629
|
-
const d =
|
|
662
|
+
const d = je(c);
|
|
630
663
|
d && n.push({ ...d, lineIndex: l });
|
|
631
664
|
}
|
|
632
665
|
if (n.length === 0)
|
|
633
666
|
return e;
|
|
634
|
-
const i =
|
|
667
|
+
const i = Be(n);
|
|
635
668
|
for (const l of i)
|
|
636
|
-
|
|
637
|
-
return
|
|
669
|
+
te(l);
|
|
670
|
+
return ze(t, i).join(`
|
|
638
671
|
`);
|
|
639
672
|
}
|
|
640
|
-
function
|
|
673
|
+
function Ue(e) {
|
|
641
674
|
const t = e.trim();
|
|
642
675
|
if (!t.endsWith(":")) return null;
|
|
643
676
|
const n = t.slice(0, -1);
|
|
@@ -647,7 +680,7 @@ function Re(e) {
|
|
|
647
680
|
const [, r, i] = o;
|
|
648
681
|
return i && !/^(\[[^\]]*\]|\{[^}]*\})*$/.test(i) || !S[r.toLowerCase()] ? null : n;
|
|
649
682
|
}
|
|
650
|
-
function
|
|
683
|
+
function M(e) {
|
|
651
684
|
let t = 0;
|
|
652
685
|
for (let n = 0; n < e.length; n++)
|
|
653
686
|
if (e[n] === " ")
|
|
@@ -658,17 +691,17 @@ function T(e) {
|
|
|
658
691
|
break;
|
|
659
692
|
return t;
|
|
660
693
|
}
|
|
661
|
-
function
|
|
662
|
-
const n =
|
|
694
|
+
function He(e, t) {
|
|
695
|
+
const n = M(e[t]);
|
|
663
696
|
for (let o = t + 1; o < e.length; o++)
|
|
664
|
-
if (!
|
|
665
|
-
return
|
|
697
|
+
if (!ne(e[o]))
|
|
698
|
+
return M(e[o]) > n;
|
|
666
699
|
return !1;
|
|
667
700
|
}
|
|
668
|
-
function
|
|
701
|
+
function ne(e) {
|
|
669
702
|
return e.trim() === "";
|
|
670
703
|
}
|
|
671
|
-
function
|
|
704
|
+
function Xe(e, t) {
|
|
672
705
|
let n = 0, o = 0;
|
|
673
706
|
for (; o < e.length && n < t; )
|
|
674
707
|
if (e[o] === " ")
|
|
@@ -679,7 +712,7 @@ function je(e, t) {
|
|
|
679
712
|
break;
|
|
680
713
|
return e.slice(o);
|
|
681
714
|
}
|
|
682
|
-
function
|
|
715
|
+
function Ze(e) {
|
|
683
716
|
const t = e.split(`
|
|
684
717
|
`), n = [], o = {
|
|
685
718
|
level: 0,
|
|
@@ -688,7 +721,7 @@ function Be(e) {
|
|
|
688
721
|
codeFenceMarker: null
|
|
689
722
|
};
|
|
690
723
|
for (let r = 0; r < t.length; r++) {
|
|
691
|
-
const i = t[r], s = i.trim(), l =
|
|
724
|
+
const i = t[r], s = i.trim(), l = M(i), c = s.match(/^(`{3,}|~{3,})/);
|
|
692
725
|
if (c) {
|
|
693
726
|
const u = c[1];
|
|
694
727
|
o.inCodeFence ? o.codeFenceMarker && s.startsWith(o.codeFenceMarker) && (o.inCodeFence = !1, o.codeFenceMarker = null) : (o.inCodeFence = !0, o.codeFenceMarker = u), n.push(i);
|
|
@@ -698,12 +731,12 @@ function Be(e) {
|
|
|
698
731
|
n.push(i);
|
|
699
732
|
continue;
|
|
700
733
|
}
|
|
701
|
-
if (
|
|
734
|
+
if (ne(i)) {
|
|
702
735
|
n.push("");
|
|
703
736
|
continue;
|
|
704
737
|
}
|
|
705
|
-
const a =
|
|
706
|
-
if (a &&
|
|
738
|
+
const a = Ue(s);
|
|
739
|
+
if (a && He(t, r)) {
|
|
707
740
|
for (; o.openDirectives.length > 0 && !(o.openDirectives[o.openDirectives.length - 1].indentLevel < l); ) {
|
|
708
741
|
const y = o.openDirectives.pop();
|
|
709
742
|
y && n.push(":".repeat(y.colonCount));
|
|
@@ -722,7 +755,7 @@ function Be(e) {
|
|
|
722
755
|
}
|
|
723
756
|
if (o.openDirectives.length > 0) {
|
|
724
757
|
const u = o.openDirectives[o.openDirectives.length - 1];
|
|
725
|
-
u.bodyBaseIndent < 0 && (u.bodyBaseIndent = l), n.push(
|
|
758
|
+
u.bodyBaseIndent < 0 && (u.bodyBaseIndent = l), n.push(Xe(i, u.bodyBaseIndent));
|
|
726
759
|
} else
|
|
727
760
|
n.push(i);
|
|
728
761
|
o.level = l;
|
|
@@ -735,43 +768,49 @@ function Be(e) {
|
|
|
735
768
|
return n.join(`
|
|
736
769
|
`);
|
|
737
770
|
}
|
|
738
|
-
const
|
|
739
|
-
function
|
|
740
|
-
const t = e.match(
|
|
771
|
+
const Ve = /^---\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;
|
|
772
|
+
function et(e) {
|
|
773
|
+
const t = e.match(Ve);
|
|
741
774
|
if (!t)
|
|
742
775
|
return { body: e };
|
|
743
|
-
const n = t[1], o = e.slice(t[0].length), r = n.match(
|
|
744
|
-
|
|
776
|
+
const n = t[1], o = e.slice(t[0].length), r = n.match(Ke)?.[1];
|
|
777
|
+
let i, s;
|
|
778
|
+
r && ae(r) ? (s = r, i = q(r)) : r && ue(r) && (i = r);
|
|
779
|
+
const l = {}, c = n.match(Ye)?.[1] ?? n.match(Ge)?.[1], a = n.match(Je)?.[1], u = n.match(Qe)?.[1];
|
|
780
|
+
return c && (l["xml:id"] = c), a && (l.label = a), u && (l.component = u), {
|
|
745
781
|
division: i,
|
|
746
|
-
|
|
782
|
+
documentRoot: s,
|
|
783
|
+
attributes: Object.keys(l).length > 0 ? l : void 0,
|
|
747
784
|
body: o
|
|
748
785
|
};
|
|
749
786
|
}
|
|
750
|
-
const
|
|
787
|
+
const tt = function(e) {
|
|
751
788
|
return function(n, o) {
|
|
752
789
|
if (typeof o?.value == "string") {
|
|
753
|
-
const r =
|
|
754
|
-
return
|
|
755
|
-
topLevelDivision:
|
|
756
|
-
|
|
790
|
+
const r = et(o.value), i = e?.documentRoot ?? r.documentRoot, s = e?.topLevelDivision ?? r.division ?? (i ? q(i) : "chapter"), l = e?.topLevelAttributes ?? r.attributes, c = Ze(r.body), a = We(c), u = Ne(a), m = W().data("micromarkExtensions", [{ disable: { null: ["codeIndented"] } }]).use(U).use(H).parse(u.markdown);
|
|
791
|
+
return Pe(m, u.tokens), P(m, u.markdown, {
|
|
792
|
+
topLevelDivision: s,
|
|
793
|
+
documentRoot: i,
|
|
794
|
+
topLevelAttributes: l
|
|
757
795
|
});
|
|
758
796
|
}
|
|
759
|
-
return
|
|
760
|
-
topLevelDivision: e?.topLevelDivision ?? "chapter",
|
|
797
|
+
return ee(n), P(n, void 0, {
|
|
798
|
+
topLevelDivision: e?.topLevelDivision ?? (e?.documentRoot ? q(e.documentRoot) : "chapter"),
|
|
799
|
+
documentRoot: e?.documentRoot,
|
|
761
800
|
topLevelAttributes: e?.topLevelAttributes
|
|
762
801
|
});
|
|
763
802
|
};
|
|
764
|
-
},
|
|
803
|
+
}, nt = /["&'<>`]/g, ot = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, rt = (
|
|
765
804
|
// eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
|
|
766
805
|
/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g
|
|
767
|
-
),
|
|
768
|
-
function
|
|
806
|
+
), it = /[|\\{}()[\]^$+*?.]/g, j = /* @__PURE__ */ new WeakMap();
|
|
807
|
+
function st(e, t) {
|
|
769
808
|
if (e = e.replace(
|
|
770
|
-
t.subset ?
|
|
809
|
+
t.subset ? lt(t.subset) : nt,
|
|
771
810
|
o
|
|
772
811
|
), t.subset || t.escapeOnly)
|
|
773
812
|
return e;
|
|
774
|
-
return e.replace(
|
|
813
|
+
return e.replace(ot, n).replace(rt, o);
|
|
775
814
|
function n(r, i, s) {
|
|
776
815
|
return t.format(
|
|
777
816
|
(r.charCodeAt(0) - 55296) * 1024 + r.charCodeAt(1) - 56320 + 65536,
|
|
@@ -787,47 +826,47 @@ function Qe(e, t) {
|
|
|
787
826
|
);
|
|
788
827
|
}
|
|
789
828
|
}
|
|
790
|
-
function
|
|
791
|
-
let t =
|
|
792
|
-
return t || (t =
|
|
829
|
+
function lt(e) {
|
|
830
|
+
let t = j.get(e);
|
|
831
|
+
return t || (t = ct(e), j.set(e, t)), t;
|
|
793
832
|
}
|
|
794
|
-
function
|
|
833
|
+
function ct(e) {
|
|
795
834
|
const t = [];
|
|
796
835
|
let n = -1;
|
|
797
836
|
for (; ++n < e.length; )
|
|
798
|
-
t.push(e[n].replace(
|
|
837
|
+
t.push(e[n].replace(it, "\\$&"));
|
|
799
838
|
return new RegExp("(?:" + t.join("|") + ")", "g");
|
|
800
839
|
}
|
|
801
|
-
function
|
|
840
|
+
function at(e) {
|
|
802
841
|
return "&#x" + e.toString(16).toUpperCase() + ";";
|
|
803
842
|
}
|
|
804
|
-
function
|
|
805
|
-
return
|
|
843
|
+
function ut(e, t) {
|
|
844
|
+
return st(e, Object.assign({ format: at }, t));
|
|
806
845
|
}
|
|
807
|
-
const
|
|
846
|
+
const pt = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
|
|
808
847
|
function v(e, t, n) {
|
|
809
|
-
const o =
|
|
848
|
+
const o = ft(e);
|
|
810
849
|
return n ? o.replace(n, r) : r(o);
|
|
811
850
|
function r(i) {
|
|
812
|
-
return
|
|
851
|
+
return ut(i, { subset: t });
|
|
813
852
|
}
|
|
814
853
|
}
|
|
815
|
-
function
|
|
816
|
-
return String(e || "").replace(
|
|
854
|
+
function ft(e) {
|
|
855
|
+
return String(e || "").replace(pt, "");
|
|
817
856
|
}
|
|
818
|
-
const
|
|
819
|
-
function
|
|
820
|
-
return "<![CDATA[" + v(e.value,
|
|
857
|
+
const ht = /]]>/g, dt = [">"];
|
|
858
|
+
function mt(e) {
|
|
859
|
+
return "<![CDATA[" + v(e.value, dt, ht) + "]]>";
|
|
821
860
|
}
|
|
822
|
-
function
|
|
861
|
+
function gt(e) {
|
|
823
862
|
return "<!--" + v(e.value, ["-"]) + "-->";
|
|
824
863
|
}
|
|
825
|
-
const
|
|
864
|
+
const yt = [" ", `
|
|
826
865
|
`, " ", '"', "&", "'", "/", "<", "=", ">"];
|
|
827
|
-
function
|
|
828
|
-
return v(e,
|
|
866
|
+
function I(e) {
|
|
867
|
+
return v(e, yt);
|
|
829
868
|
}
|
|
830
|
-
function
|
|
869
|
+
function B(e, t) {
|
|
831
870
|
const n = String(e);
|
|
832
871
|
if (typeof t != "string")
|
|
833
872
|
throw new TypeError("Expected character");
|
|
@@ -836,88 +875,91 @@ function R(e, t) {
|
|
|
836
875
|
o++, r = n.indexOf(t, r + t.length);
|
|
837
876
|
return o;
|
|
838
877
|
}
|
|
839
|
-
function
|
|
878
|
+
function R(e, t) {
|
|
840
879
|
const n = String(e);
|
|
841
880
|
let o = t.options.quote || '"';
|
|
842
881
|
if (t.options.quoteSmart) {
|
|
843
882
|
const r = o === '"' ? "'" : '"';
|
|
844
|
-
|
|
883
|
+
B(n, o) > B(n, r) && (o = r);
|
|
845
884
|
}
|
|
846
885
|
return o + v(n, ["<", "&", o]) + o;
|
|
847
886
|
}
|
|
848
|
-
function
|
|
849
|
-
const n =
|
|
887
|
+
function vt(e, t) {
|
|
888
|
+
const n = I(e.name), o = e.public, r = e.system;
|
|
850
889
|
let i = "<!DOCTYPE";
|
|
851
|
-
return n !== "" && (i += " " + n), o ? i += " PUBLIC " +
|
|
890
|
+
return n !== "" && (i += " " + n), o ? i += " PUBLIC " + R(o, t) : r && (i += " SYSTEM"), r && (i += " " + R(r, t)), i + ">";
|
|
852
891
|
}
|
|
853
|
-
const
|
|
854
|
-
function
|
|
855
|
-
const n =
|
|
892
|
+
const kt = {}.hasOwnProperty;
|
|
893
|
+
function bt(e, t) {
|
|
894
|
+
const n = I(e.name), o = ie(e, t), r = e.attributes || {}, i = o ? !1 : t.options.closeEmptyElements, s = [];
|
|
856
895
|
let l;
|
|
857
896
|
for (l in r)
|
|
858
|
-
if (
|
|
897
|
+
if (kt.call(r, l)) {
|
|
859
898
|
const c = r[l];
|
|
860
|
-
c != null && s.push(
|
|
899
|
+
c != null && s.push(I(l) + "=" + R(c, t));
|
|
861
900
|
}
|
|
862
901
|
return "<" + n + (s.length === 0 ? "" : " " + s.join(" ")) + (i ? (t.options.tightClose ? "" : " ") + "/" : "") + ">" + o + (i ? "" : "</" + n + ">");
|
|
863
902
|
}
|
|
864
|
-
const
|
|
865
|
-
function
|
|
866
|
-
const t =
|
|
903
|
+
const Dt = /\?>/g, xt = [">"];
|
|
904
|
+
function Ct(e) {
|
|
905
|
+
const t = I(e.name) || "x", n = v(e.value, xt, Dt);
|
|
867
906
|
return "<?" + t + (n ? " " + n : "") + "?>";
|
|
868
907
|
}
|
|
869
|
-
const
|
|
870
|
-
function
|
|
871
|
-
return v(e.value,
|
|
872
|
-
}
|
|
873
|
-
function
|
|
874
|
-
return t.options.allowDangerousXml ? e.value :
|
|
875
|
-
}
|
|
876
|
-
const
|
|
877
|
-
cdata:
|
|
878
|
-
comment:
|
|
879
|
-
doctype:
|
|
880
|
-
element:
|
|
881
|
-
instruction:
|
|
882
|
-
raw:
|
|
883
|
-
root:
|
|
884
|
-
text:
|
|
908
|
+
const wt = ["&", "<"];
|
|
909
|
+
function oe(e) {
|
|
910
|
+
return v(e.value, wt);
|
|
911
|
+
}
|
|
912
|
+
function Lt(e, t) {
|
|
913
|
+
return t.options.allowDangerousXml ? e.value : oe(e);
|
|
914
|
+
}
|
|
915
|
+
const It = {}.hasOwnProperty, z = {
|
|
916
|
+
cdata: mt,
|
|
917
|
+
comment: gt,
|
|
918
|
+
doctype: vt,
|
|
919
|
+
element: bt,
|
|
920
|
+
instruction: Ct,
|
|
921
|
+
raw: Lt,
|
|
922
|
+
root: ie,
|
|
923
|
+
text: oe
|
|
885
924
|
};
|
|
886
|
-
function
|
|
925
|
+
function re(e, t) {
|
|
887
926
|
const n = e && e.type;
|
|
888
927
|
if (!n)
|
|
889
928
|
throw new Error("Expected node, not `" + e + "`");
|
|
890
|
-
if (!
|
|
929
|
+
if (!It.call(z, n))
|
|
891
930
|
throw new Error("Cannot compile unknown node `" + n + "`");
|
|
892
|
-
const o =
|
|
931
|
+
const o = z[n];
|
|
893
932
|
return o(e, t);
|
|
894
933
|
}
|
|
895
|
-
function
|
|
934
|
+
function ie(e, t) {
|
|
896
935
|
const n = e && e.children || [];
|
|
897
936
|
let o = -1;
|
|
898
937
|
const r = [];
|
|
899
938
|
for (; ++o < n.length; )
|
|
900
|
-
r[o] =
|
|
939
|
+
r[o] = re(n[o], t);
|
|
901
940
|
return r.join("");
|
|
902
941
|
}
|
|
903
|
-
function
|
|
904
|
-
const n = { options: {} };
|
|
942
|
+
function St(e, t) {
|
|
943
|
+
const n = { options: t || {} };
|
|
905
944
|
if (typeof n.options.quote == "string" && n.options.quote !== '"' && n.options.quote !== "'")
|
|
906
945
|
throw new Error(
|
|
907
946
|
"Invalid quote `" + n.options.quote + "`, expected `'` or `\"`"
|
|
908
947
|
);
|
|
909
948
|
const o = Array.isArray(e) ? { type: "root", children: e } : e;
|
|
910
|
-
return
|
|
949
|
+
return re(o, n);
|
|
911
950
|
}
|
|
912
|
-
function
|
|
913
|
-
const n =
|
|
914
|
-
return
|
|
951
|
+
function Ft(e, t) {
|
|
952
|
+
const n = W().use(U).use(H).use(tt, t), o = n.parse(e), r = n.runSync(o, { value: e });
|
|
953
|
+
return St(r.children, {
|
|
954
|
+
closeEmptyElements: !0,
|
|
955
|
+
tightClose: !0
|
|
956
|
+
});
|
|
915
957
|
}
|
|
916
958
|
export {
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
959
|
+
Mt as DIRECTIVE_MAP,
|
|
960
|
+
Z as PROOF_SOLUTION_NAMES,
|
|
961
|
+
Ft as markdownToPretext,
|
|
962
|
+
P as mdastToPtxast,
|
|
963
|
+
Rt as remarkMath,
|
|
964
|
+
tt as remarkPretext
|
|
923
965
|
};
|
package/dist/lib/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BlockContent, DefinitionContent, PhrasingContent } from 'mdast';
|
|
2
|
-
import { TopLevelDivisionType } from '@pretextbook/ptxast';
|
|
2
|
+
import { RootDivisionType, TopLevelDivisionType } from '@pretextbook/ptxast';
|
|
3
3
|
export interface VisitContext {
|
|
4
4
|
/** Parent node, if any. */
|
|
5
5
|
parent?: BlockContent | DefinitionContent | PhrasingContent;
|
|
@@ -13,6 +13,10 @@ export interface VisitContext {
|
|
|
13
13
|
source?: string;
|
|
14
14
|
/** The division type that a depth-1 heading (`#`) maps to. */
|
|
15
15
|
topLevelDivision: TopLevelDivisionType;
|
|
16
|
+
/** When set, the whole document is wrapped in this root element
|
|
17
|
+
* (`book`/`article`/`slideshow`) and `topLevelDivision` is the root's
|
|
18
|
+
* outermost child division. */
|
|
19
|
+
documentRoot?: RootDivisionType;
|
|
16
20
|
/** Attributes (e.g. from frontmatter `xmlid`/`label`/`component`) to apply
|
|
17
21
|
* to the first root-level division built from the document. */
|
|
18
22
|
topLevelAttributes?: Record<string, string>;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { TopLevelDivisionType } from '@pretextbook/ptxast';
|
|
1
|
+
import { RootDivisionType, TopLevelDivisionType } from '@pretextbook/ptxast';
|
|
2
2
|
export interface FrontmatterResult {
|
|
3
|
-
/** The
|
|
3
|
+
/** The division a depth-1 heading (`#`) maps to, if present and valid. When
|
|
4
|
+
* `documentRoot` is set this is the root's outermost child division. */
|
|
4
5
|
division?: TopLevelDivisionType;
|
|
6
|
+
/** The document root (`book`/`article`/`slideshow`) to wrap the whole
|
|
7
|
+
* document in, when `division:` names one. */
|
|
8
|
+
documentRoot?: RootDivisionType;
|
|
5
9
|
/** Attributes (`xml:id`, `label`, `component`) for the top-level division. */
|
|
6
10
|
attributes?: Record<string, string>;
|
|
7
11
|
/** The markdown source with the frontmatter block removed. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Root as MdastRoot } from 'mdast';
|
|
2
2
|
import { Root } from 'xast';
|
|
3
3
|
import { ConversionMessage } from './context.js';
|
|
4
|
-
import { TopLevelDivisionType } from '@pretextbook/ptxast';
|
|
4
|
+
import { RootDivisionType, TopLevelDivisionType } from '@pretextbook/ptxast';
|
|
5
5
|
/** Result type for conversion: tree + diagnostic messages. */
|
|
6
6
|
export interface ConversionResult {
|
|
7
7
|
tree: Root;
|
|
@@ -11,6 +11,10 @@ export interface ConversionResult {
|
|
|
11
11
|
export interface MdastToPtxastOptions {
|
|
12
12
|
/** The division type that a depth-1 heading (`#`) maps to. Defaults to `'chapter'`. */
|
|
13
13
|
topLevelDivision?: TopLevelDivisionType;
|
|
14
|
+
/** When set, wrap the whole document in this root element
|
|
15
|
+
* (`book`/`article`/`slideshow`); `topLevelDivision` is then the division a
|
|
16
|
+
* depth-1 heading maps to inside the root. */
|
|
17
|
+
documentRoot?: RootDivisionType;
|
|
14
18
|
/** Attributes (`xml:id`, `label`, `component`) applied to the first
|
|
15
19
|
* root-level division built from the document, e.g. from frontmatter. */
|
|
16
20
|
topLevelAttributes?: Record<string, string>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Element } from 'xast';
|
|
2
|
+
import { ContainerDirective, LeafDirective, TextDirective } from 'mdast-util-directive';
|
|
3
|
+
/** Any of the three remark-directive node shapes (`:x`, `::x`, `:::x`). */
|
|
4
|
+
type DirectiveNode = TextDirective | LeafDirective | ContainerDirective;
|
|
5
|
+
/**
|
|
6
|
+
* Build a `<plus:KIND .../>` include element from a kind name and attributes.
|
|
7
|
+
*
|
|
8
|
+
* This is the one choke point every include syntax funnels through: the tag is
|
|
9
|
+
* always `plus:<kind>`, the element is always empty (a reference, never
|
|
10
|
+
* transcluded), and `null`/`undefined` attribute values are dropped so a
|
|
11
|
+
* value-less directive attribute doesn't emit `key="null"`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function plusIncludeElement(kind: string, attributes?: Record<string, string | null | undefined>): Element;
|
|
14
|
+
/**
|
|
15
|
+
* Interpret a remark-directive node as a PreTeXt Plus include: the directive
|
|
16
|
+
* name becomes the `plus:` kind and its attributes pass through verbatim
|
|
17
|
+
* (`::section{ref="x"}` → `<plus:section ref="x"/>`).
|
|
18
|
+
*
|
|
19
|
+
* Attributes are intentionally *not* remapped the way block directives remap
|
|
20
|
+
* `id`→`xml:id`: an include points at another element by `ref`, so its
|
|
21
|
+
* attributes are kept exactly as written.
|
|
22
|
+
*
|
|
23
|
+
* Returns `null` when the node carries no usable name, so callers can fall back
|
|
24
|
+
* to their normal handling rather than emitting `<plus:/>`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function directiveToPlusInclude(node: DirectiveNode): Element | null;
|
|
27
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Plugin } from 'unified';
|
|
2
2
|
import { Root as MdastRoot } from 'mdast';
|
|
3
3
|
import { Root } from 'xast';
|
|
4
|
-
import { TopLevelDivisionType } from '@pretextbook/ptxast';
|
|
4
|
+
import { RootDivisionType, TopLevelDivisionType } from '@pretextbook/ptxast';
|
|
5
5
|
/** Options for the remark-pretext plugin. */
|
|
6
6
|
export interface RemarkPretextOptions {
|
|
7
7
|
/**
|
|
@@ -10,6 +10,13 @@ export interface RemarkPretextOptions {
|
|
|
10
10
|
* `'chapter'` (matching historical behavior) when neither is set.
|
|
11
11
|
*/
|
|
12
12
|
topLevelDivision?: TopLevelDivisionType;
|
|
13
|
+
/**
|
|
14
|
+
* Wraps the whole document in this root element (`book`/`article`/
|
|
15
|
+
* `slideshow`). Overrides any document root declared via the frontmatter
|
|
16
|
+
* `division:` field. When set, `topLevelDivision` is the division a depth-1
|
|
17
|
+
* heading maps to *inside* the root.
|
|
18
|
+
*/
|
|
19
|
+
documentRoot?: RootDivisionType;
|
|
13
20
|
/**
|
|
14
21
|
* Attributes (`xml:id`, `label`, `component`) applied to the first
|
|
15
22
|
* root-level division. Overrides any `xmlid:`/`label:`/`component:`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pretextbook/remark-pretext",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
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.7",
|
|
43
43
|
"@types/mdast": "^4.0.0",
|
|
44
44
|
"mdast-util-directive": "^3.0.0",
|
|
45
45
|
"remark-directive": "^4.0.0",
|