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

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 CHANGED
@@ -1,6 +1,7 @@
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}
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"}]]),P=new Set(["theorem-like","definition-like"]);function v(e){return{type:"root",children:h(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 h(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(...h(r.children,t));else if(g.has(r.name))i.push(...w(r,Math.min(t,6)));else{const s=p(r);s!==null&&i.push(s)}}return i}function w(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(f).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(...h(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(f).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(f).filter(u)};m.push(o)}if(P.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 f(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(f).filter(u)};case"alert":return{type:"strong",children:t.children.map(f).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
+ ${r.join(`
4
+ `)}
4
5
  ---
5
6
 
6
- ${n}`}exports.ptxastToMarkdown=j;exports.ptxastToMdast=x;
7
+ ${i}`}exports.ptxastToMarkdown=q;exports.ptxastToMdast=v;
package/dist/index.js CHANGED
@@ -1,17 +1,17 @@
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";
1
+ import { DIVISION_HIERARCHY as b, EXTRA_DIVISION_TYPES as T, isTitlelessDivisionType as I, TITLELESS_DIVISION_TYPES as S, getPtxTextContent as p } from "@pretextbook/ptxast";
2
+ import { toMarkdown as E } from "mdast-util-to-markdown";
3
+ import { directiveToMarkdown as w } from "mdast-util-directive";
4
+ import { mathToMarkdown as _ } from "mdast-util-math";
5
5
  const g = /* @__PURE__ */ new Set([
6
- ...x,
7
- "appendix"
8
- ]), k = /* @__PURE__ */ new Set([
6
+ ...b,
7
+ ...T.filter((e) => !I(e))
8
+ ]), k = new Set(S), v = /* @__PURE__ */ new Set([
9
9
  "pretext",
10
10
  "book",
11
11
  "article",
12
12
  "frontmatter",
13
13
  "backmatter"
14
- ]), E = /* @__PURE__ */ new Map([
14
+ ]), P = /* @__PURE__ */ new Map([
15
15
  // theorem-like
16
16
  ["theorem", { name: "theorem", category: "theorem-like" }],
17
17
  ["lemma", { name: "lemma", category: "theorem-like" }],
@@ -50,85 +50,88 @@ const g = /* @__PURE__ */ new Set([
50
50
  ["solution", { name: "solution", category: "solution-like" }],
51
51
  ["hint", { name: "hint", category: "solution-like" }],
52
52
  ["answer", { name: "answer", category: "solution-like" }]
53
- ]), I = /* @__PURE__ */ new Set(["theorem-like", "definition-like"]);
54
- function M(e) {
53
+ ]), D = /* @__PURE__ */ new Set(["theorem-like", "definition-like"]);
54
+ function N(e) {
55
55
  return {
56
56
  type: "root",
57
57
  children: h(e.children, 1)
58
58
  };
59
59
  }
60
- function v(e) {
60
+ function x(e) {
61
61
  for (const t of e) {
62
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;
63
+ const i = t;
64
+ if (g.has(i.name) || k.has(i.name)) {
65
+ const n = i.attributes ?? {}, r = {};
66
+ 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 };
67
+ }
68
+ if (v.has(i.name)) {
69
+ const n = x(i.children);
70
+ if (n) return n;
68
71
  }
69
72
  }
70
73
  }
71
74
  function h(e, t) {
72
- const n = [];
73
- for (const r of e) {
74
- if (r.type !== "element") continue;
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)));
75
+ const i = [];
76
+ for (const n of e) {
77
+ if (n.type !== "element") continue;
78
+ const r = n;
79
+ if (v.has(r.name) || k.has(r.name))
80
+ i.push(...h(r.children, t));
81
+ else if (g.has(r.name))
82
+ i.push(...M(r, Math.min(t, 6)));
80
83
  else {
81
- const l = u(a);
82
- l !== null && n.push(l);
84
+ const c = u(r);
85
+ c !== null && i.push(c);
83
86
  }
84
87
  }
85
- return n;
88
+ return i;
86
89
  }
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")
92
- ), i = {
90
+ function M(e, t) {
91
+ const i = [], n = e.attributes ?? {}, r = e.children, c = r.find(
92
+ (a) => a.type === "element" && a.name === "title"
93
+ ), m = r.filter(
94
+ (a) => !(a.type === "element" && a.name === "title")
95
+ ), o = {
93
96
  type: "heading",
94
97
  depth: t,
95
- children: l ? l.children.map(f).filter(s) : [],
96
- ...r["xml:id"] ? { data: { id: r["xml:id"], hProperties: { id: r["xml:id"] } } } : {}
98
+ children: c ? c.children.map(f).filter(s) : [],
99
+ ...n["xml:id"] ? { data: { id: n["xml:id"], hProperties: { id: n["xml:id"] } } } : {}
97
100
  };
98
- n.push(i);
99
- const c = Math.min(t + 1, 6);
100
- return n.push(...h(m, c)), n;
101
+ i.push(o);
102
+ const l = Math.min(t + 1, 6);
103
+ return i.push(...h(m, l)), i;
101
104
  }
102
105
  function u(e) {
103
106
  switch (e.name) {
104
107
  case "p":
105
- return D(e);
108
+ return L(e);
106
109
  case "blockquote":
107
- return N(e);
110
+ return A(e);
108
111
  case "ol":
109
112
  return y(e, !0);
110
113
  case "ul":
111
114
  return y(e, !1);
112
115
  case "program":
113
- return A(e);
116
+ return j(e);
114
117
  case "me":
115
118
  case "men":
116
119
  case "md":
117
120
  case "mdn":
118
- return _(e);
121
+ return R(e);
119
122
  default: {
120
- const t = E.get(e.name);
121
- return t ? j(e, t) : null;
123
+ const t = P.get(e.name);
124
+ return t ? Y(e, t) : null;
122
125
  }
123
126
  }
124
127
  }
125
- function D(e) {
128
+ function L(e) {
126
129
  return {
127
130
  type: "paragraph",
128
131
  children: e.children.map(f).filter(s)
129
132
  };
130
133
  }
131
- function N(e) {
134
+ function A(e) {
132
135
  return {
133
136
  type: "blockquote",
134
137
  children: e.children.filter((t) => t.type === "element").map((t) => u(t)).filter(s)
@@ -139,72 +142,72 @@ function y(e, t) {
139
142
  type: "list",
140
143
  ordered: t,
141
144
  spread: !1,
142
- children: e.children.filter((n) => n.type === "element").map((n) => S(n))
145
+ children: e.children.filter((i) => i.type === "element").map((i) => O(i))
143
146
  };
144
147
  }
145
- function S(e) {
148
+ function O(e) {
146
149
  return {
147
150
  type: "listItem",
148
151
  spread: !1,
149
152
  children: e.children.filter((t) => t.type === "element").map((t) => u(t)).filter(s)
150
153
  };
151
154
  }
152
- function A(e) {
155
+ function j(e) {
153
156
  return {
154
157
  type: "code",
155
158
  lang: (e.attributes ?? {}).language ?? null,
156
159
  value: p(e)
157
160
  };
158
161
  }
159
- function _(e) {
162
+ function R(e) {
160
163
  const t = e.children;
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(` \\\\
164
+ return t.length > 0 && t[0].type === "text" ? { type: "math", value: p(e) } : { type: "math", value: t.filter((n) => n.type === "element" && n.name === "mrow").map((n) => p(n)).join(` \\\\
162
165
  `) };
163
166
  }
164
- function j(e, t) {
165
- const n = e.attributes ?? {}, r = e.children, a = {};
166
- n["xml:id"] && (a.id = n["xml:id"]);
167
- for (const [i, c] of Object.entries(n))
168
- i === "xml:id" || c == null || (a[i] = c);
169
- const l = r.find(
170
- (i) => i.type === "element" && i.name === "title"
167
+ function Y(e, t) {
168
+ const i = e.attributes ?? {}, n = e.children, r = {};
169
+ i["xml:id"] && (r.id = i["xml:id"]);
170
+ for (const [o, l] of Object.entries(i))
171
+ o === "xml:id" || l == null || (r[o] = l);
172
+ const c = n.find(
173
+ (o) => o.type === "element" && o.name === "title"
171
174
  ), m = [];
172
- if (l) {
173
- const i = {
175
+ if (c) {
176
+ const o = {
174
177
  type: "paragraph",
175
178
  data: { directiveLabel: !0 },
176
- children: l.children.map(f).filter(s)
179
+ children: c.children.map(f).filter(s)
177
180
  };
178
- m.push(i);
181
+ m.push(o);
179
182
  }
180
- if (I.has(t.category))
181
- for (const i of r) {
182
- if (i.type !== "element") continue;
183
- const c = i;
184
- if (c.name !== "title")
185
- if (c.name === "statement")
186
- for (const o of c.children) {
187
- if (o.type !== "element") continue;
188
- const d = u(o);
183
+ if (D.has(t.category))
184
+ for (const o of n) {
185
+ if (o.type !== "element") continue;
186
+ const l = o;
187
+ if (l.name !== "title")
188
+ if (l.name === "statement")
189
+ for (const a of l.children) {
190
+ if (a.type !== "element") continue;
191
+ const d = u(a);
189
192
  d && m.push(d);
190
193
  }
191
194
  else {
192
- const o = u(c);
193
- o && m.push(o);
195
+ const a = u(l);
196
+ a && m.push(a);
194
197
  }
195
198
  }
196
199
  else
197
- for (const i of r) {
198
- if (i.type !== "element") continue;
199
- const c = i;
200
- if (c.name === "title") continue;
201
- const o = u(c);
202
- o && m.push(o);
200
+ for (const o of n) {
201
+ if (o.type !== "element") continue;
202
+ const l = o;
203
+ if (l.name === "title") continue;
204
+ const a = u(l);
205
+ a && m.push(a);
203
206
  }
204
207
  return {
205
208
  type: "containerDirective",
206
209
  name: t.name,
207
- attributes: Object.keys(a).length > 0 ? a : void 0,
210
+ attributes: Object.keys(r).length > 0 ? r : void 0,
208
211
  children: m
209
212
  };
210
213
  }
@@ -235,17 +238,20 @@ function f(e) {
235
238
  function s(e) {
236
239
  return e !== null;
237
240
  }
238
- function O(e) {
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}
241
+ function H(e) {
242
+ const t = N(e), i = E(t, {
243
+ extensions: [w(), _()]
244
+ }), n = x(e.children);
245
+ if (!n) return i;
246
+ const r = [];
247
+ 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 : `---
248
+ ${r.join(`
249
+ `)}
244
250
  ---
245
251
 
246
- ${n}`;
252
+ ${i}`;
247
253
  }
248
254
  export {
249
- O as ptxastToMarkdown,
250
- M as ptxastToMdast
255
+ H as ptxastToMarkdown,
256
+ N as ptxastToMdast
251
257
  };
@@ -1,6 +1,7 @@
1
1
  import { Root as MdastRoot } from 'mdast';
2
2
  import { Root, ElementContent } from '@pretextbook/ptxast';
3
3
  export declare const DIVISION_TYPE_NAMES: Set<string>;
4
+ export declare const TITLELESS_DIVISION_TYPES: Set<string>;
4
5
  /**
5
6
  * Structural container types whose content should be recursed into
6
7
  * without emitting a heading, and without changing the current depth.
@@ -10,6 +11,23 @@ export declare const DIVISION_TYPE_NAMES: Set<string>;
10
11
  export declare const TRANSPARENT_TYPES: Set<string>;
11
12
  /** Convert an xast Root (PreTeXt document) to an mdast Root. */
12
13
  export declare function ptxastToMdast(root: Root): MdastRoot;
14
+ /** The outermost division's name plus the subset of its attributes that
15
+ * round-trip through markdown frontmatter (`xmlid`, `label`, `component`). */
16
+ export interface TopLevelDivisionInfo {
17
+ name: string;
18
+ attributes: {
19
+ xmlid?: string;
20
+ label?: string;
21
+ component?: string;
22
+ };
23
+ }
24
+ /**
25
+ * Find the outermost division in a ptxast tree (skipping transparent
26
+ * structural wrappers), i.e. the division a depth-1 heading would represent
27
+ * if this tree were flattened to markdown — along with its `xml:id`/
28
+ * `label`/`component` attributes, for round-tripping into frontmatter.
29
+ */
30
+ export declare function findTopLevelDivisionInfo(nodes: ElementContent[]): TopLevelDivisionInfo | undefined;
13
31
  /**
14
32
  * Find the name of the outermost division in a ptxast tree (skipping
15
33
  * transparent structural wrappers), i.e. the division a depth-1 heading
@@ -4,8 +4,10 @@ export { ptxastToMdast } from './ptxast-to-mdast.js';
4
4
  * Convert an xast Root (PreTeXt document) to a markdown string using the directive
5
5
  * syntax for PreTeXt block environments.
6
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.
7
+ * A leading frontmatter block is prepended when the outermost division
8
+ * carries information that markdown can't otherwise represent: a
9
+ * `division:` field when it isn't `chapter` (the default a depth-1 heading
10
+ * is assumed to mean), and `xmlid:`/`label:`/`component:` fields mirroring
11
+ * that division's `xml:id`/`label`/`component` attributes.
10
12
  */
11
13
  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.5",
3
+ "version": "0.0.6",
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.5",
42
+ "@pretextbook/ptxast": "^0.0.6",
43
43
  "@types/mdast": "^4.0.0",
44
44
  "mdast-util-directive": "^3.0.0",
45
45
  "mdast-util-math": "^3.0.0",