@pretextbook/ptxast-util-to-mdast 0.0.4 → 0.0.5

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/README.md CHANGED
@@ -28,7 +28,19 @@ Converts a `PtxRoot` tree to an mdast `Root` tree with directive nodes for PreTe
28
28
 
29
29
  ### `ptxastToMarkdown(root: PtxRoot): string`
30
30
 
31
- Converts a `PtxRoot` tree to a Markdown string. Theorem-like environments render as `:::theorem` directive fences; divisions render as ATX headings (`##`).
31
+ Converts a `PtxRoot` tree to a Markdown string. Theorem-like environments render as `:::theorem` directive fences; divisions render as ATX headings, relative to the document's actual outermost division (a depth-1 heading is whatever that division is — `chapter`, `section`, `part`, ...).
32
+
33
+ When the outermost division isn't `chapter` (the default a depth-1 heading is assumed to mean by [`@pretextbook/remark-pretext`](../remark-pretext)), a `division:` frontmatter block is prepended so the markdown can be converted back to PreTeXt unambiguously:
34
+
35
+ ```
36
+ ---
37
+ division: section
38
+ ---
39
+
40
+ # Top-level section
41
+
42
+ ## A subsection
43
+ ```
32
44
 
33
45
  ## License
34
46
 
package/dist/index.cjs CHANGED
@@ -1,2 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@pretextbook/ptxast"),k=require("mdast-util-to-markdown"),x=require("mdast-util-directive"),v=require("mdast-util-math"),b=new Set(["chapter","section","subsection","subsubsection","paragraphs","appendix"]),T={chapter:1,section:2,subsection:3,subsubsection:4,paragraphs:5,appendix:1},w=new Set(["pretext","book","article","frontmatter","backmatter","part"]),P=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"}]]),M=new Set(["theorem-like","definition-like"]);function g(e){return{type:"root",children:d(e.children,2)}}function d(e,t){const n=[];for(const r of e){if(r.type!=="element")continue;const o=r;if(w.has(o.name))n.push(...d(o.children,t));else if(b.has(o.name)){const l=T[o.name]??t;n.push(...E(o,l))}else{const l=u(o);l!==null&&n.push(l)}}return n}function E(e,t){const n=[],r=e.attributes??{},o=e.children,l=o.find(a=>a.type==="element"&&a.name==="title"),s=o.filter(a=>!(a.type==="element"&&a.name==="title")),i={type:"heading",depth:t,children:l?l.children.map(h).filter(m):[],...r["xml:id"]?{data:{id:r["xml:id"],hProperties:{id:r["xml:id"]}}}:{}};n.push(i);const c=Math.min(t+1,6);return n.push(...d(s,c)),n}function u(e){switch(e.name){case"p":return S(e);case"blockquote":return C(e);case"ol":return y(e,!0);case"ul":return y(e,!1);case"program":return D(e);case"me":case"men":case"md":case"mdn":return I(e);default:{const t=P.get(e.name);return t?j(e,t):null}}}function S(e){return{type:"paragraph",children:e.children.map(h).filter(m)}}function C(e){return{type:"blockquote",children:e.children.filter(t=>t.type==="element").map(t=>u(t)).filter(m)}}function y(e,t){return{type:"list",ordered:t,spread:!1,children:e.children.filter(n=>n.type==="element").map(n=>q(n))}}function q(e){return{type:"listItem",spread:!1,children:e.children.filter(t=>t.type==="element").map(t=>u(t)).filter(m)}}function D(e){return{type:"code",lang:(e.attributes??{}).language??null,value:p.getPtxTextContent(e)}}function I(e){const t=e.children;return t.length>0&&t[0].type==="text"?{type:"math",value:p.getPtxTextContent(e)}:{type:"math",value:t.filter(r=>r.type==="element"&&r.name==="mrow").map(r=>p.getPtxTextContent(r)).join(` \\\\
2
- `)}}function j(e,t){const n=e.attributes??{},r=e.children,o={};n["xml:id"]&&(o.id=n["xml:id"]);for(const[i,c]of Object.entries(n))i==="xml:id"||c==null||(o[i]=c);const l=r.find(i=>i.type==="element"&&i.name==="title"),s=[];if(l){const i={type:"paragraph",data:{directiveLabel:!0},children:l.children.map(h).filter(m)};s.push(i)}if(M.has(t.category))for(const i of r){if(i.type!=="element")continue;const c=i;if(c.name!=="title")if(c.name==="statement")for(const a of c.children){if(a.type!=="element")continue;const f=u(a);f&&s.push(f)}else{const a=u(c);a&&s.push(a)}}else for(const i of r){if(i.type!=="element")continue;const c=i;if(c.name==="title")continue;const a=u(c);a&&s.push(a)}return{type:"containerDirective",name:t.name,attributes:Object.keys(o).length>0?o:void 0,children:s}}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(m)};case"alert":return{type:"strong",children:t.children.map(h).filter(m)};case"c":return{type:"inlineCode",value:p.getPtxTextContent(t)};case"m":return{type:"inlineMath",value:p.getPtxTextContent(t)};default:return null}}function m(e){return e!==null}function N(e){const t=g(e);return k.toMarkdown(t,{extensions:[x.directiveToMarkdown(),v.mathToMarkdown()]})}exports.ptxastToMarkdown=N;exports.ptxastToMdast=g;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@pretextbook/ptxast"),T=require("mdast-util-to-markdown"),b=require("mdast-util-directive"),w=require("mdast-util-math"),g=new Set([...p.DIVISION_HIERARCHY,"appendix"]),k=new Set(["pretext","book","article","frontmatter","backmatter"]),M=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"}]]),P=new Set(["theorem-like","definition-like"]);function x(e){return{type:"root",children:d(e.children,1)}}function v(e){for(const t of e){if(t.type!=="element")continue;const n=t;if(g.has(n.name))return n.name;if(k.has(n.name)){const i=v(n.children);if(i)return i}}}function d(e,t){const n=[];for(const i of e){if(i.type!=="element")continue;const a=i;if(k.has(a.name))n.push(...d(a.children,t));else if(g.has(a.name))n.push(...E(a,Math.min(t,6)));else{const l=u(a);l!==null&&n.push(l)}}return n}function E(e,t){const n=[],i=e.attributes??{},a=e.children,l=a.find(o=>o.type==="element"&&o.name==="title"),s=a.filter(o=>!(o.type==="element"&&o.name==="title")),r={type:"heading",depth:t,children:l?l.children.map(h).filter(m):[],...i["xml:id"]?{data:{id:i["xml:id"],hProperties:{id:i["xml:id"]}}}:{}};n.push(r);const c=Math.min(t+1,6);return n.push(...d(s,c)),n}function u(e){switch(e.name){case"p":return I(e);case"blockquote":return S(e);case"ol":return y(e,!0);case"ul":return y(e,!1);case"program":return D(e);case"me":case"men":case"md":case"mdn":return N(e);default:{const t=M.get(e.name);return t?q(e,t):null}}}function I(e){return{type:"paragraph",children:e.children.map(h).filter(m)}}function S(e){return{type:"blockquote",children:e.children.filter(t=>t.type==="element").map(t=>u(t)).filter(m)}}function y(e,t){return{type:"list",ordered:t,spread:!1,children:e.children.filter(n=>n.type==="element").map(n=>C(n))}}function C(e){return{type:"listItem",spread:!1,children:e.children.filter(t=>t.type==="element").map(t=>u(t)).filter(m)}}function D(e){return{type:"code",lang:(e.attributes??{}).language??null,value:p.getPtxTextContent(e)}}function N(e){const t=e.children;return t.length>0&&t[0].type==="text"?{type:"math",value:p.getPtxTextContent(e)}:{type:"math",value:t.filter(i=>i.type==="element"&&i.name==="mrow").map(i=>p.getPtxTextContent(i)).join(` \\\\
2
+ `)}}function q(e,t){const n=e.attributes??{},i=e.children,a={};n["xml:id"]&&(a.id=n["xml:id"]);for(const[r,c]of Object.entries(n))r==="xml:id"||c==null||(a[r]=c);const l=i.find(r=>r.type==="element"&&r.name==="title"),s=[];if(l){const r={type:"paragraph",data:{directiveLabel:!0},children:l.children.map(h).filter(m)};s.push(r)}if(P.has(t.category))for(const r of i){if(r.type!=="element")continue;const c=r;if(c.name!=="title")if(c.name==="statement")for(const o of c.children){if(o.type!=="element")continue;const f=u(o);f&&s.push(f)}else{const o=u(c);o&&s.push(o)}}else for(const r of i){if(r.type!=="element")continue;const c=r;if(c.name==="title")continue;const o=u(c);o&&s.push(o)}return{type:"containerDirective",name:t.name,attributes:Object.keys(a).length>0?a:void 0,children:s}}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(m)};case"alert":return{type:"strong",children:t.children.map(h).filter(m)};case"c":return{type:"inlineCode",value:p.getPtxTextContent(t)};case"m":return{type:"inlineMath",value:p.getPtxTextContent(t)};default:return null}}function m(e){return e!==null}function j(e){const t=x(e),n=T.toMarkdown(t,{extensions:[b.directiveToMarkdown(),w.mathToMarkdown()]}),i=v(e.children);return!i||i==="chapter"?n:`---
3
+ division: ${i}
4
+ ---
5
+
6
+ ${n}`}exports.ptxastToMarkdown=j;exports.ptxastToMdast=x;
package/dist/index.js CHANGED
@@ -1,30 +1,17 @@
1
- import { getPtxTextContent as u } from "@pretextbook/ptxast";
2
- import { toMarkdown as g } from "mdast-util-to-markdown";
3
- import { directiveToMarkdown as k } from "mdast-util-directive";
4
- import { mathToMarkdown as v } from "mdast-util-math";
5
- const x = /* @__PURE__ */ new Set([
6
- "chapter",
7
- "section",
8
- "subsection",
9
- "subsubsection",
10
- "paragraphs",
11
- // appendix is division-like at the same level as chapter
1
+ import { DIVISION_HIERARCHY as x, getPtxTextContent as p } from "@pretextbook/ptxast";
2
+ import { toMarkdown as b } from "mdast-util-to-markdown";
3
+ import { directiveToMarkdown as T } from "mdast-util-directive";
4
+ import { mathToMarkdown as w } from "mdast-util-math";
5
+ const g = /* @__PURE__ */ new Set([
6
+ ...x,
12
7
  "appendix"
13
- ]), b = {
14
- chapter: 1,
15
- section: 2,
16
- subsection: 3,
17
- subsubsection: 4,
18
- paragraphs: 5,
19
- appendix: 1
20
- }, T = /* @__PURE__ */ new Set([
8
+ ]), k = /* @__PURE__ */ new Set([
21
9
  "pretext",
22
10
  "book",
23
11
  "article",
24
12
  "frontmatter",
25
- "backmatter",
26
- "part"
27
- ]), w = /* @__PURE__ */ new Map([
13
+ "backmatter"
14
+ ]), E = /* @__PURE__ */ new Map([
28
15
  // theorem-like
29
16
  ["theorem", { name: "theorem", category: "theorem-like" }],
30
17
  ["lemma", { name: "lemma", category: "theorem-like" }],
@@ -63,78 +50,88 @@ const x = /* @__PURE__ */ new Set([
63
50
  ["solution", { name: "solution", category: "solution-like" }],
64
51
  ["hint", { name: "hint", category: "solution-like" }],
65
52
  ["answer", { name: "answer", category: "solution-like" }]
66
- ]), E = /* @__PURE__ */ new Set(["theorem-like", "definition-like"]);
67
- function P(e) {
53
+ ]), I = /* @__PURE__ */ new Set(["theorem-like", "definition-like"]);
54
+ function M(e) {
68
55
  return {
69
56
  type: "root",
70
- children: f(e.children, 2)
57
+ children: h(e.children, 1)
71
58
  };
72
59
  }
73
- function f(e, t) {
60
+ function v(e) {
61
+ for (const t of e) {
62
+ if (t.type !== "element") continue;
63
+ const n = t;
64
+ if (g.has(n.name)) return n.name;
65
+ if (k.has(n.name)) {
66
+ const r = v(n.children);
67
+ if (r) return r;
68
+ }
69
+ }
70
+ }
71
+ function h(e, t) {
74
72
  const n = [];
75
73
  for (const r of e) {
76
74
  if (r.type !== "element") continue;
77
- const o = r;
78
- if (T.has(o.name))
79
- n.push(...f(o.children, t));
80
- else if (x.has(o.name)) {
81
- const l = b[o.name] ?? t;
82
- n.push(...M(o, l));
83
- } else {
84
- const l = p(o);
75
+ const a = r;
76
+ if (k.has(a.name))
77
+ n.push(...h(a.children, t));
78
+ else if (g.has(a.name))
79
+ n.push(...P(a, Math.min(t, 6)));
80
+ else {
81
+ const l = u(a);
85
82
  l !== null && n.push(l);
86
83
  }
87
84
  }
88
85
  return n;
89
86
  }
90
- function M(e, t) {
91
- const n = [], r = e.attributes ?? {}, o = e.children, l = o.find(
92
- (a) => a.type === "element" && a.name === "title"
93
- ), s = o.filter(
94
- (a) => !(a.type === "element" && a.name === "title")
87
+ function P(e, t) {
88
+ const n = [], r = e.attributes ?? {}, a = e.children, l = a.find(
89
+ (o) => o.type === "element" && o.name === "title"
90
+ ), m = a.filter(
91
+ (o) => !(o.type === "element" && o.name === "title")
95
92
  ), i = {
96
93
  type: "heading",
97
94
  depth: t,
98
- children: l ? l.children.map(h).filter(m) : [],
95
+ children: l ? l.children.map(f).filter(s) : [],
99
96
  ...r["xml:id"] ? { data: { id: r["xml:id"], hProperties: { id: r["xml:id"] } } } : {}
100
97
  };
101
98
  n.push(i);
102
99
  const c = Math.min(t + 1, 6);
103
- return n.push(...f(s, c)), n;
100
+ return n.push(...h(m, c)), n;
104
101
  }
105
- function p(e) {
102
+ function u(e) {
106
103
  switch (e.name) {
107
104
  case "p":
108
- return I(e);
105
+ return D(e);
109
106
  case "blockquote":
110
- return S(e);
107
+ return N(e);
111
108
  case "ol":
112
109
  return y(e, !0);
113
110
  case "ul":
114
111
  return y(e, !1);
115
112
  case "program":
116
- return N(e);
113
+ return A(e);
117
114
  case "me":
118
115
  case "men":
119
116
  case "md":
120
117
  case "mdn":
121
- return j(e);
118
+ return _(e);
122
119
  default: {
123
- const t = w.get(e.name);
124
- return t ? _(e, t) : null;
120
+ const t = E.get(e.name);
121
+ return t ? j(e, t) : null;
125
122
  }
126
123
  }
127
124
  }
128
- function I(e) {
125
+ function D(e) {
129
126
  return {
130
127
  type: "paragraph",
131
- children: e.children.map(h).filter(m)
128
+ children: e.children.map(f).filter(s)
132
129
  };
133
130
  }
134
- function S(e) {
131
+ function N(e) {
135
132
  return {
136
133
  type: "blockquote",
137
- children: e.children.filter((t) => t.type === "element").map((t) => p(t)).filter(m)
134
+ children: e.children.filter((t) => t.type === "element").map((t) => u(t)).filter(s)
138
135
  };
139
136
  }
140
137
  function y(e, t) {
@@ -142,58 +139,58 @@ function y(e, t) {
142
139
  type: "list",
143
140
  ordered: t,
144
141
  spread: !1,
145
- children: e.children.filter((n) => n.type === "element").map((n) => D(n))
142
+ children: e.children.filter((n) => n.type === "element").map((n) => S(n))
146
143
  };
147
144
  }
148
- function D(e) {
145
+ function S(e) {
149
146
  return {
150
147
  type: "listItem",
151
148
  spread: !1,
152
- children: e.children.filter((t) => t.type === "element").map((t) => p(t)).filter(m)
149
+ children: e.children.filter((t) => t.type === "element").map((t) => u(t)).filter(s)
153
150
  };
154
151
  }
155
- function N(e) {
152
+ function A(e) {
156
153
  return {
157
154
  type: "code",
158
155
  lang: (e.attributes ?? {}).language ?? null,
159
- value: u(e)
156
+ value: p(e)
160
157
  };
161
158
  }
162
- function j(e) {
159
+ function _(e) {
163
160
  const t = e.children;
164
- return t.length > 0 && t[0].type === "text" ? { type: "math", value: u(e) } : { type: "math", value: t.filter((r) => r.type === "element" && r.name === "mrow").map((r) => u(r)).join(` \\\\
161
+ return t.length > 0 && t[0].type === "text" ? { type: "math", value: p(e) } : { type: "math", value: t.filter((r) => r.type === "element" && r.name === "mrow").map((r) => p(r)).join(` \\\\
165
162
  `) };
166
163
  }
167
- function _(e, t) {
168
- const n = e.attributes ?? {}, r = e.children, o = {};
169
- n["xml:id"] && (o.id = n["xml:id"]);
164
+ function j(e, t) {
165
+ const n = e.attributes ?? {}, r = e.children, a = {};
166
+ n["xml:id"] && (a.id = n["xml:id"]);
170
167
  for (const [i, c] of Object.entries(n))
171
- i === "xml:id" || c == null || (o[i] = c);
168
+ i === "xml:id" || c == null || (a[i] = c);
172
169
  const l = r.find(
173
170
  (i) => i.type === "element" && i.name === "title"
174
- ), s = [];
171
+ ), m = [];
175
172
  if (l) {
176
173
  const i = {
177
174
  type: "paragraph",
178
175
  data: { directiveLabel: !0 },
179
- children: l.children.map(h).filter(m)
176
+ children: l.children.map(f).filter(s)
180
177
  };
181
- s.push(i);
178
+ m.push(i);
182
179
  }
183
- if (E.has(t.category))
180
+ if (I.has(t.category))
184
181
  for (const i of r) {
185
182
  if (i.type !== "element") continue;
186
183
  const c = i;
187
184
  if (c.name !== "title")
188
185
  if (c.name === "statement")
189
- for (const a of c.children) {
190
- if (a.type !== "element") continue;
191
- const d = p(a);
192
- d && s.push(d);
186
+ for (const o of c.children) {
187
+ if (o.type !== "element") continue;
188
+ const d = u(o);
189
+ d && m.push(d);
193
190
  }
194
191
  else {
195
- const a = p(c);
196
- a && s.push(a);
192
+ const o = u(c);
193
+ o && m.push(o);
197
194
  }
198
195
  }
199
196
  else
@@ -201,17 +198,17 @@ function _(e, t) {
201
198
  if (i.type !== "element") continue;
202
199
  const c = i;
203
200
  if (c.name === "title") continue;
204
- const a = p(c);
205
- a && s.push(a);
201
+ const o = u(c);
202
+ o && m.push(o);
206
203
  }
207
204
  return {
208
205
  type: "containerDirective",
209
206
  name: t.name,
210
- attributes: Object.keys(o).length > 0 ? o : void 0,
211
- children: s
207
+ attributes: Object.keys(a).length > 0 ? a : void 0,
208
+ children: m
212
209
  };
213
210
  }
214
- function h(e) {
211
+ function f(e) {
215
212
  if (e.type === "text")
216
213
  return { type: "text", value: e.value ?? "" };
217
214
  if (e.type !== "element") return null;
@@ -220,31 +217,35 @@ function h(e) {
220
217
  case "em":
221
218
  return {
222
219
  type: "emphasis",
223
- children: t.children.map(h).filter(m)
220
+ children: t.children.map(f).filter(s)
224
221
  };
225
222
  case "alert":
226
223
  return {
227
224
  type: "strong",
228
- children: t.children.map(h).filter(m)
225
+ children: t.children.map(f).filter(s)
229
226
  };
230
227
  case "c":
231
- return { type: "inlineCode", value: u(t) };
228
+ return { type: "inlineCode", value: p(t) };
232
229
  case "m":
233
- return { type: "inlineMath", value: u(t) };
230
+ return { type: "inlineMath", value: p(t) };
234
231
  default:
235
232
  return null;
236
233
  }
237
234
  }
238
- function m(e) {
235
+ function s(e) {
239
236
  return e !== null;
240
237
  }
241
238
  function O(e) {
242
- const t = P(e);
243
- return g(t, {
244
- extensions: [k(), v()]
245
- });
239
+ const t = M(e), n = b(t, {
240
+ extensions: [T(), w()]
241
+ }), r = v(e.children);
242
+ return !r || r === "chapter" ? n : `---
243
+ division: ${r}
244
+ ---
245
+
246
+ ${n}`;
246
247
  }
247
248
  export {
248
249
  O as ptxastToMarkdown,
249
- P as ptxastToMdast
250
+ M as ptxastToMdast
250
251
  };
@@ -1,4 +1,18 @@
1
1
  import { Root as MdastRoot } from 'mdast';
2
- import { Root } from '@pretextbook/ptxast';
2
+ import { Root, ElementContent } from '@pretextbook/ptxast';
3
+ export declare const DIVISION_TYPE_NAMES: Set<string>;
4
+ /**
5
+ * Structural container types whose content should be recursed into
6
+ * without emitting a heading, and without changing the current depth.
7
+ * This handles full ptxast trees that include a `pretext > book > chapter`
8
+ * hierarchy.
9
+ */
10
+ export declare const TRANSPARENT_TYPES: Set<string>;
3
11
  /** Convert an xast Root (PreTeXt document) to an mdast Root. */
4
12
  export declare function ptxastToMdast(root: Root): MdastRoot;
13
+ /**
14
+ * Find the name of the outermost division in a ptxast tree (skipping
15
+ * transparent structural wrappers), i.e. the division a depth-1 heading
16
+ * would represent if this tree were flattened to markdown.
17
+ */
18
+ export declare function findTopLevelDivision(nodes: ElementContent[]): string | undefined;
@@ -3,5 +3,9 @@ export { ptxastToMdast } from './ptxast-to-mdast.js';
3
3
  /**
4
4
  * Convert an xast Root (PreTeXt document) to a markdown string using the directive
5
5
  * syntax for PreTeXt block environments.
6
+ *
7
+ * When the document's outermost division isn't `chapter` (the default a
8
+ * depth-1 heading is assumed to mean), a `division:` frontmatter block is
9
+ * prepended so the markdown can be converted back to PreTeXt unambiguously.
6
10
  */
7
11
  export declare function ptxastToMarkdown(root: Root): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretextbook/ptxast-util-to-mdast",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
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.4",
42
+ "@pretextbook/ptxast": "^0.0.5",
43
43
  "@types/mdast": "^4.0.0",
44
44
  "mdast-util-directive": "^3.0.0",
45
45
  "mdast-util-math": "^3.0.0",