@pretextbook/ptxast-util-to-mdast 0.0.6 → 0.0.7
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 +2 -2
- package/dist/index.js +17 -16
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@pretextbook/ptxast"),T=require("mdast-util-to-markdown"),I=require("mdast-util-directive"),S=require("mdast-util-math"),g=new Set([...c.DIVISION_HIERARCHY,...c.EXTRA_DIVISION_TYPES.filter(e=>!c.isTitlelessDivisionType(e))]),k=new Set(c.TITLELESS_DIVISION_TYPES),x=new Set(["pretext","book","article","frontmatter","backmatter"]),E=new Map([["theorem",{name:"theorem",category:"theorem-like"}],["lemma",{name:"lemma",category:"theorem-like"}],["corollary",{name:"corollary",category:"theorem-like"}],["proposition",{name:"proposition",category:"theorem-like"}],["claim",{name:"claim",category:"theorem-like"}],["fact",{name:"fact",category:"theorem-like"}],["conjecture",{name:"conjecture",category:"theorem-like"}],["axiom",{name:"axiom",category:"theorem-like"}],["principle",{name:"principle",category:"theorem-like"}],["hypothesis",{name:"hypothesis",category:"theorem-like"}],["algorithm",{name:"algorithm",category:"theorem-like"}],["definition",{name:"definition",category:"definition-like"}],["notation",{name:"notation",category:"definition-like"}],["remark",{name:"remark",category:"remark-like"}],["note",{name:"note",category:"remark-like"}],["observation",{name:"observation",category:"remark-like"}],["warning",{name:"warning",category:"remark-like"}],["insight",{name:"insight",category:"remark-like"}],["assemblage",{name:"assemblage",category:"remark-like"}],["example",{name:"example",category:"example-like"}],["question",{name:"question",category:"example-like"}],["problem",{name:"problem",category:"example-like"}],["exercise",{name:"exercise",category:"example-like"}],["activity",{name:"activity",category:"example-like"}],["exploration",{name:"exploration",category:"example-like"}],["investigation",{name:"investigation",category:"example-like"}],["project",{name:"project",category:"example-like"}],["proof",{name:"proof",category:"proof-like"}],["case",{name:"case",category:"proof-like"}],["solution",{name:"solution",category:"solution-like"}],["hint",{name:"hint",category:"solution-like"}],["answer",{name:"answer",category:"solution-like"}]]),
|
|
2
|
-
`)}}function j(e,t){const i=e.attributes??{},n=e.children,r={};i["xml:id"]&&(r.id=i["xml:id"]);for(const[o,l]of Object.entries(i))o==="xml:id"||l==null||(r[o]=l);const s=n.find(o=>o.type==="element"&&o.name==="title"),m=[];if(s){const o={type:"paragraph",data:{directiveLabel:!0},children:s.children.map(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@pretextbook/ptxast"),T=require("mdast-util-to-markdown"),I=require("mdast-util-directive"),S=require("mdast-util-math"),g=new Set([...c.DIVISION_HIERARCHY,...c.EXTRA_DIVISION_TYPES.filter(e=>!c.isTitlelessDivisionType(e))]),k=new Set(c.TITLELESS_DIVISION_TYPES),x=new Set(["pretext","book","article","slideshow","frontmatter","backmatter"]),E=new Map([["theorem",{name:"theorem",category:"theorem-like"}],["lemma",{name:"lemma",category:"theorem-like"}],["corollary",{name:"corollary",category:"theorem-like"}],["proposition",{name:"proposition",category:"theorem-like"}],["claim",{name:"claim",category:"theorem-like"}],["fact",{name:"fact",category:"theorem-like"}],["conjecture",{name:"conjecture",category:"theorem-like"}],["axiom",{name:"axiom",category:"theorem-like"}],["principle",{name:"principle",category:"theorem-like"}],["hypothesis",{name:"hypothesis",category:"theorem-like"}],["algorithm",{name:"algorithm",category:"theorem-like"}],["definition",{name:"definition",category:"definition-like"}],["notation",{name:"notation",category:"definition-like"}],["remark",{name:"remark",category:"remark-like"}],["note",{name:"note",category:"remark-like"}],["observation",{name:"observation",category:"remark-like"}],["warning",{name:"warning",category:"remark-like"}],["insight",{name:"insight",category:"remark-like"}],["assemblage",{name:"assemblage",category:"remark-like"}],["example",{name:"example",category:"example-like"}],["question",{name:"question",category:"example-like"}],["problem",{name:"problem",category:"example-like"}],["exercise",{name:"exercise",category:"example-like"}],["activity",{name:"activity",category:"example-like"}],["exploration",{name:"exploration",category:"example-like"}],["investigation",{name:"investigation",category:"example-like"}],["project",{name:"project",category:"example-like"}],["proof",{name:"proof",category:"proof-like"}],["case",{name:"case",category:"proof-like"}],["solution",{name:"solution",category:"solution-like"}],["hint",{name:"hint",category:"solution-like"}],["answer",{name:"answer",category:"solution-like"}]]),w=new Set(["theorem-like","definition-like"]);function v(e){return{type:"root",children:f(e.children,1)}}function b(e){for(const t of e){if(t.type!=="element")continue;const i=t;if(g.has(i.name)||k.has(i.name)){const n=i.attributes??{},r={};return n["xml:id"]&&(r.xmlid=n["xml:id"]),n.label&&(r.label=n.label),n.component&&(r.component=n.component),{name:i.name,attributes:r}}if(x.has(i.name)){const n=b(i.children);if(n)return n}}}function f(e,t){const i=[];for(const n of e){if(n.type!=="element")continue;const r=n;if(x.has(r.name)||k.has(r.name))i.push(...f(r.children,t));else if(g.has(r.name))i.push(...P(r,Math.min(t,6)));else{const s=p(r);s!==null&&i.push(s)}}return i}function P(e,t){const i=[],n=e.attributes??{},r=e.children,s=r.find(a=>a.type==="element"&&a.name==="title"),m=r.filter(a=>!(a.type==="element"&&a.name==="title")),o={type:"heading",depth:t,children:s?s.children.map(h).filter(u):[],...n["xml:id"]?{data:{id:n["xml:id"],hProperties:{id:n["xml:id"]}}}:{}};i.push(o);const l=Math.min(t+1,6);return i.push(...f(m,l)),i}function p(e){switch(e.name){case"p":return M(e);case"blockquote":return D(e);case"ol":return y(e,!0);case"ul":return y(e,!1);case"program":return N(e);case"me":case"men":case"md":case"mdn":return C(e);default:{const t=E.get(e.name);return t?j(e,t):null}}}function M(e){return{type:"paragraph",children:e.children.map(h).filter(u)}}function D(e){return{type:"blockquote",children:e.children.filter(t=>t.type==="element").map(t=>p(t)).filter(u)}}function y(e,t){return{type:"list",ordered:t,spread:!1,children:e.children.filter(i=>i.type==="element").map(i=>_(i))}}function _(e){return{type:"listItem",spread:!1,children:e.children.filter(t=>t.type==="element").map(t=>p(t)).filter(u)}}function N(e){return{type:"code",lang:(e.attributes??{}).language??null,value:c.getPtxTextContent(e)}}function C(e){const t=e.children;return t.length>0&&t[0].type==="text"?{type:"math",value:c.getPtxTextContent(e)}:{type:"math",value:t.filter(n=>n.type==="element"&&n.name==="mrow").map(n=>c.getPtxTextContent(n)).join(` \\\\
|
|
2
|
+
`)}}function j(e,t){const i=e.attributes??{},n=e.children,r={};i["xml:id"]&&(r.id=i["xml:id"]);for(const[o,l]of Object.entries(i))o==="xml:id"||l==null||(r[o]=l);const s=n.find(o=>o.type==="element"&&o.name==="title"),m=[];if(s){const o={type:"paragraph",data:{directiveLabel:!0},children:s.children.map(h).filter(u)};m.push(o)}if(w.has(t.category))for(const o of n){if(o.type!=="element")continue;const l=o;if(l.name!=="title")if(l.name==="statement")for(const a of l.children){if(a.type!=="element")continue;const d=p(a);d&&m.push(d)}else{const a=p(l);a&&m.push(a)}}else for(const o of n){if(o.type!=="element")continue;const l=o;if(l.name==="title")continue;const a=p(l);a&&m.push(a)}return{type:"containerDirective",name:t.name,attributes:Object.keys(r).length>0?r:void 0,children:m}}function h(e){if(e.type==="text")return{type:"text",value:e.value??""};if(e.type!=="element")return null;const t=e;switch(t.name){case"em":return{type:"emphasis",children:t.children.map(h).filter(u)};case"alert":return{type:"strong",children:t.children.map(h).filter(u)};case"c":return{type:"inlineCode",value:c.getPtxTextContent(t)};case"m":return{type:"inlineMath",value:c.getPtxTextContent(t)};default:return null}}function u(e){return e!==null}function q(e){const t=v(e),i=T.toMarkdown(t,{extensions:[I.directiveToMarkdown(),S.mathToMarkdown()]}),n=b(e.children);if(!n)return i;const r=[];return n.name!=="chapter"&&r.push(`division: ${n.name}`),n.attributes.xmlid&&r.push(`xmlid: ${n.attributes.xmlid}`),n.attributes.label&&r.push(`label: ${n.attributes.label}`),n.attributes.component&&r.push(`component: ${n.attributes.component}`),r.length===0?i:`---
|
|
3
3
|
${r.join(`
|
|
4
4
|
`)}
|
|
5
5
|
---
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const g = /* @__PURE__ */ new Set([
|
|
|
9
9
|
"pretext",
|
|
10
10
|
"book",
|
|
11
11
|
"article",
|
|
12
|
+
"slideshow",
|
|
12
13
|
"frontmatter",
|
|
13
14
|
"backmatter"
|
|
14
15
|
]), P = /* @__PURE__ */ new Map([
|
|
@@ -90,17 +91,17 @@ function h(e, t) {
|
|
|
90
91
|
function M(e, t) {
|
|
91
92
|
const i = [], n = e.attributes ?? {}, r = e.children, c = r.find(
|
|
92
93
|
(a) => a.type === "element" && a.name === "title"
|
|
93
|
-
),
|
|
94
|
+
), s = r.filter(
|
|
94
95
|
(a) => !(a.type === "element" && a.name === "title")
|
|
95
96
|
), o = {
|
|
96
97
|
type: "heading",
|
|
97
98
|
depth: t,
|
|
98
|
-
children: c ? c.children.map(f).filter(
|
|
99
|
+
children: c ? c.children.map(f).filter(m) : [],
|
|
99
100
|
...n["xml:id"] ? { data: { id: n["xml:id"], hProperties: { id: n["xml:id"] } } } : {}
|
|
100
101
|
};
|
|
101
102
|
i.push(o);
|
|
102
103
|
const l = Math.min(t + 1, 6);
|
|
103
|
-
return i.push(...h(
|
|
104
|
+
return i.push(...h(s, l)), i;
|
|
104
105
|
}
|
|
105
106
|
function u(e) {
|
|
106
107
|
switch (e.name) {
|
|
@@ -128,13 +129,13 @@ function u(e) {
|
|
|
128
129
|
function L(e) {
|
|
129
130
|
return {
|
|
130
131
|
type: "paragraph",
|
|
131
|
-
children: e.children.map(f).filter(
|
|
132
|
+
children: e.children.map(f).filter(m)
|
|
132
133
|
};
|
|
133
134
|
}
|
|
134
135
|
function A(e) {
|
|
135
136
|
return {
|
|
136
137
|
type: "blockquote",
|
|
137
|
-
children: e.children.filter((t) => t.type === "element").map((t) => u(t)).filter(
|
|
138
|
+
children: e.children.filter((t) => t.type === "element").map((t) => u(t)).filter(m)
|
|
138
139
|
};
|
|
139
140
|
}
|
|
140
141
|
function y(e, t) {
|
|
@@ -149,7 +150,7 @@ function O(e) {
|
|
|
149
150
|
return {
|
|
150
151
|
type: "listItem",
|
|
151
152
|
spread: !1,
|
|
152
|
-
children: e.children.filter((t) => t.type === "element").map((t) => u(t)).filter(
|
|
153
|
+
children: e.children.filter((t) => t.type === "element").map((t) => u(t)).filter(m)
|
|
153
154
|
};
|
|
154
155
|
}
|
|
155
156
|
function j(e) {
|
|
@@ -171,14 +172,14 @@ function Y(e, t) {
|
|
|
171
172
|
o === "xml:id" || l == null || (r[o] = l);
|
|
172
173
|
const c = n.find(
|
|
173
174
|
(o) => o.type === "element" && o.name === "title"
|
|
174
|
-
),
|
|
175
|
+
), s = [];
|
|
175
176
|
if (c) {
|
|
176
177
|
const o = {
|
|
177
178
|
type: "paragraph",
|
|
178
179
|
data: { directiveLabel: !0 },
|
|
179
|
-
children: c.children.map(f).filter(
|
|
180
|
+
children: c.children.map(f).filter(m)
|
|
180
181
|
};
|
|
181
|
-
|
|
182
|
+
s.push(o);
|
|
182
183
|
}
|
|
183
184
|
if (D.has(t.category))
|
|
184
185
|
for (const o of n) {
|
|
@@ -189,11 +190,11 @@ function Y(e, t) {
|
|
|
189
190
|
for (const a of l.children) {
|
|
190
191
|
if (a.type !== "element") continue;
|
|
191
192
|
const d = u(a);
|
|
192
|
-
d &&
|
|
193
|
+
d && s.push(d);
|
|
193
194
|
}
|
|
194
195
|
else {
|
|
195
196
|
const a = u(l);
|
|
196
|
-
a &&
|
|
197
|
+
a && s.push(a);
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
200
|
else
|
|
@@ -202,13 +203,13 @@ function Y(e, t) {
|
|
|
202
203
|
const l = o;
|
|
203
204
|
if (l.name === "title") continue;
|
|
204
205
|
const a = u(l);
|
|
205
|
-
a &&
|
|
206
|
+
a && s.push(a);
|
|
206
207
|
}
|
|
207
208
|
return {
|
|
208
209
|
type: "containerDirective",
|
|
209
210
|
name: t.name,
|
|
210
211
|
attributes: Object.keys(r).length > 0 ? r : void 0,
|
|
211
|
-
children:
|
|
212
|
+
children: s
|
|
212
213
|
};
|
|
213
214
|
}
|
|
214
215
|
function f(e) {
|
|
@@ -220,12 +221,12 @@ function f(e) {
|
|
|
220
221
|
case "em":
|
|
221
222
|
return {
|
|
222
223
|
type: "emphasis",
|
|
223
|
-
children: t.children.map(f).filter(
|
|
224
|
+
children: t.children.map(f).filter(m)
|
|
224
225
|
};
|
|
225
226
|
case "alert":
|
|
226
227
|
return {
|
|
227
228
|
type: "strong",
|
|
228
|
-
children: t.children.map(f).filter(
|
|
229
|
+
children: t.children.map(f).filter(m)
|
|
229
230
|
};
|
|
230
231
|
case "c":
|
|
231
232
|
return { type: "inlineCode", value: p(t) };
|
|
@@ -235,7 +236,7 @@ function f(e) {
|
|
|
235
236
|
return null;
|
|
236
237
|
}
|
|
237
238
|
}
|
|
238
|
-
function
|
|
239
|
+
function m(e) {
|
|
239
240
|
return e !== null;
|
|
240
241
|
}
|
|
241
242
|
function H(e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pretextbook/ptxast-util-to-mdast",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Convert ptxast to mdast (markdown AST) and markdown strings",
|
|
5
5
|
"author": "Oscar Levin",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -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
|
"mdast-util-math": "^3.0.0",
|