@pretextbook/pretext-html 0.11.0 → 0.12.0

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.
@@ -249,6 +249,9 @@ const N = `<?xml version="1.0" encoding="UTF-8"?>
249
249
  <source>
250
250
  <directories external="../assets" generated="../generated-assets" />
251
251
  </source>
252
+ <common>
253
+ <tableofcontents level="0"/>
254
+ </common>
252
255
  <html>
253
256
  <platform portable="yes"/>
254
257
  </html>
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "node:fs/promises";
2
2
  import "node:process";
3
3
  import "./printout.js";
4
- import { m as i, l as s } from "./cli-CMAunrD_.js";
4
+ import { m as i, l as s } from "./cli-BkTQ4BJP.js";
5
5
  export {
6
6
  i as main,
7
7
  s as parseArgs
@@ -183,7 +183,7 @@ ${Ve()}
183
183
  ${Je}`;
184
184
  return r.replace(/<body([^>]*)>/i, `<body$1>${i}`);
185
185
  }
186
- const Ge = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.11.0/assets";
186
+ const Ge = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.12.0/assets";
187
187
  let he;
188
188
  function Dn(e) {
189
189
  he = e.replace(/\/+$/, "");
@@ -280,11 +280,11 @@ function st(e) {
280
280
  );
281
281
  }
282
282
  const J = /* @__PURE__ */ new Map(), ge = /* @__PURE__ */ new Map();
283
- let U, at = 0, be = we;
283
+ let U, ct = 0, be = we;
284
284
  function Ln(e) {
285
285
  be = e;
286
286
  }
287
- function ct(e, n) {
287
+ function at(e, n) {
288
288
  const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = ge.get(t);
289
289
  if (r !== void 0)
290
290
  return Promise.resolve(new Response(r, { status: 200 }));
@@ -306,11 +306,11 @@ async function dt(e, n) {
306
306
  return new Response(i, { status: 200 });
307
307
  }
308
308
  function xe() {
309
- U || (U = globalThis.fetch, globalThis.fetch = ct);
309
+ U || (U = globalThis.fetch, globalThis.fetch = at);
310
310
  }
311
311
  function Ee(e) {
312
312
  xe();
313
- const n = `mnt${++at}.ptx.invalid`;
313
+ const n = `mnt${++ct}.ptx.invalid`;
314
314
  return J.set(n, e), `http://${n}`;
315
315
  }
316
316
  function ut(e) {
@@ -338,13 +338,13 @@ function ye(e) {
338
338
  if (!i || t.has(i))
339
339
  continue;
340
340
  t.add(i);
341
- const o = D(r, "data-printout-type") ?? "", s = D(r, "data-printout-number") ?? "", a = D(r, "data-printout-title") ?? "";
341
+ const o = D(r, "data-printout-type") ?? "", s = D(r, "data-printout-number") ?? "", c = D(r, "data-printout-title") ?? "";
342
342
  n.push({
343
343
  id: i,
344
344
  type: o,
345
345
  number: s,
346
- title: a,
347
- label: mt(o, s, a)
346
+ title: c,
347
+ label: mt(o, s, c)
348
348
  });
349
349
  }
350
350
  return n;
@@ -427,18 +427,21 @@ function St(e, n) {
427
427
  const t = Tt.exec(e), r = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e, i = /<head[^>]*>/i.exec(r);
428
428
  if (!i)
429
429
  return r;
430
- const o = n && ye(r).some((c) => c.id === n) ? n : void 0, s = `
430
+ const o = n && ye(r).some((a) => a.id === n) ? n : void 0, s = `
431
431
  ${Et}
432
432
  ${bt(o)}
433
433
  ${o ? `${xt()}
434
- ` : ""}${yt}`, a = i.index + i[0].length;
435
- return r.slice(0, a) + s + r.slice(a);
434
+ ` : ""}${yt}`, c = i.index + i[0].length;
435
+ return r.slice(0, c) + s + r.slice(c);
436
436
  }
437
437
  const H = `<?xml version="1.0" encoding="UTF-8"?>
438
438
  <publication>
439
439
  <source>
440
440
  <directories external="../assets" generated="../generated-assets" />
441
441
  </source>
442
+ <common>
443
+ <tableofcontents level="0"/>
444
+ </common>
442
445
  <html>
443
446
  <platform portable="yes"/>
444
447
  </html>
@@ -484,8 +487,8 @@ function Rt(e, n = {}) {
484
487
  throw new Error(
485
488
  "Invalid publication file: no root <publication> element found"
486
489
  );
487
- const a = y(s, "html"), c = y(a, "platform");
488
- if (c.attributes = { ...c.attributes, portable: "yes" }, t && _t(a, t), i) {
490
+ const c = y(s, "html"), a = y(c, "platform");
491
+ if (a.attributes = { ...a.attributes, portable: "yes" }, t && _t(c, t), i) {
489
492
  const d = y(s, "revealjs");
490
493
  It(d), r && kt(d, r);
491
494
  }
@@ -604,12 +607,12 @@ function Ht(e, n, t = {}) {
604
607
  const r = Ut.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, o = Nt.exec(i);
605
608
  if (!o)
606
609
  return i;
607
- const s = o.index + o[0].length, a = `
610
+ const s = o.index + o[0].length, c = `
608
611
  ${Ft}
609
612
  ${Ot}
610
613
  ${Ct(n, t)}
611
614
  ${Wt}`;
612
- return i.slice(0, s) + a + i.slice(s);
615
+ return i.slice(0, s) + c + i.slice(s);
613
616
  }
614
617
  const $e = "http://www.w3.org/2001/XInclude", oe = 64;
615
618
  async function Vt(e, n, t) {
@@ -650,16 +653,16 @@ async function R(e, n, t, r) {
650
653
  const s = e.children[o];
651
654
  if (s.type !== "element")
652
655
  continue;
653
- const a = A(t, s);
654
- if (_e(s, a)) {
655
- const c = await ke(
656
+ const c = A(t, s);
657
+ if (_e(s, c)) {
658
+ const a = await ke(
656
659
  s,
657
660
  n,
658
- a,
661
+ c,
659
662
  r
660
663
  );
661
- e.children.splice(o, 1, ...c), o += c.length - 1, i = !0;
662
- } else await R(s, n, a, r) && (i = !0);
664
+ e.children.splice(o, 1, ...a), o += a.length - 1, i = !0;
665
+ } else await R(s, n, c, r) && (i = !0);
663
666
  }
664
667
  return i;
665
668
  }
@@ -677,37 +680,37 @@ async function ke(e, n, t, r) {
677
680
  s = decodeURIComponent(o);
678
681
  } catch {
679
682
  }
680
- const a = h(n, s);
681
- if (a !== r.projectDir && !a.startsWith(r.projectDir + W))
683
+ const c = h(n, s);
684
+ if (c !== r.projectDir && !c.startsWith(r.projectDir + W))
682
685
  throw new Error(
683
686
  `xi:include escapes the project directory: ${o} (in ${i})`
684
687
  );
685
- if (r.stack.includes(a))
688
+ if (r.stack.includes(c))
686
689
  throw new Error(
687
- `Circular xi:include: ${[...r.stack, a].join(" -> ")}`
690
+ `Circular xi:include: ${[...r.stack, c].join(" -> ")}`
688
691
  );
689
692
  if (r.stack.length >= oe)
690
693
  throw new Error(`xi:include nesting exceeds ${oe} levels`);
691
- const c = await B(a);
692
- if (c === void 0) {
694
+ const a = await B(c);
695
+ if (a === void 0) {
693
696
  const p = Kt(e, t);
694
697
  if (p)
695
698
  return await R(p, n, t, r), p.children;
696
699
  throw new Error(`xi:include target not found: ${o} (in ${i})`);
697
700
  }
698
701
  if (e.attributes.parse === "text")
699
- return [{ type: "text", value: c }];
702
+ return [{ type: "text", value: a }];
700
703
  let d;
701
704
  try {
702
- d = T(c);
705
+ d = T(a);
703
706
  } catch (p) {
704
707
  throw new Error(
705
- `Could not parse xi:include target ${a} as XML: ${p instanceof Error ? p.message : p}. (Included files must be well-formed, with a single root element.)`
708
+ `Could not parse xi:include target ${c} as XML: ${p instanceof Error ? p.message : p}. (Included files must be well-formed, with a single root element.)`
706
709
  );
707
710
  }
708
- r.stack.push(a);
711
+ r.stack.push(c);
709
712
  try {
710
- await R(d, E(a), { "": "" }, r);
713
+ await R(d, E(c), { "": "" }, r);
711
714
  } finally {
712
715
  r.stack.pop();
713
716
  }
@@ -715,7 +718,7 @@ async function ke(e, n, t, r) {
715
718
  (p) => p.type === "element"
716
719
  );
717
720
  for (const p of u)
718
- Jt(p, a);
721
+ Jt(p, c);
719
722
  return u;
720
723
  }
721
724
  function se(e) {
@@ -728,22 +731,22 @@ async function zt(e, n, t) {
728
731
  );
729
732
  if (!i)
730
733
  return;
731
- const o = h(n), s = E(o), a = {
734
+ const o = h(n), s = E(o), c = {
732
735
  projectDir: h(t),
733
736
  stack: [o]
734
- }, c = A({ "": "" }, i);
737
+ }, a = A({ "": "" }, i);
735
738
  for (const d of i.children) {
736
739
  if (d.type !== "element")
737
740
  continue;
738
- const u = A(c, d);
741
+ const u = A(a, d);
739
742
  if (se(d))
740
- return await R(d, s, u, a), I(d);
743
+ return await R(d, s, u, c), I(d);
741
744
  if (_e(d, u)) {
742
745
  const f = (await ke(
743
746
  d,
744
747
  s,
745
748
  u,
746
- a
749
+ c
747
750
  )).find(
748
751
  (w) => w.type === "element" && se(w)
749
752
  );
@@ -783,28 +786,28 @@ function Yt(e, n, t) {
783
786
  }
784
787
  function Re(e, n, t, r, i, o) {
785
788
  const s = Xt(e) ?? r;
786
- let a, c;
789
+ let c, a;
787
790
  if (Gt(e))
788
- c = "root";
791
+ a = "root";
789
792
  else {
790
793
  const u = e.attributes.label ?? e.attributes["xml:id"];
791
- a = u ?? `${n}-${t}`, o.push({
792
- id: a,
794
+ c = u ?? `${n}-${t}`, o.push({
795
+ id: c,
793
796
  file: s,
794
797
  line: e.position?.start.line ?? 1,
795
798
  column: e.position?.start.column ?? 1,
796
799
  endLine: e.position?.end.line ?? e.position?.start.line ?? 1,
797
800
  parent: i
798
- }), c = a;
801
+ }), a = c;
799
802
  }
800
803
  let d = 0;
801
804
  for (const u of e.children)
802
805
  Ie(u) && (d += 1, Re(
803
806
  u,
804
- c,
807
+ a,
805
808
  d,
806
809
  s,
807
- a ?? i,
810
+ c ?? i,
808
811
  o
809
812
  ));
810
813
  }
@@ -1024,7 +1027,7 @@ function on(e, n) {
1024
1027
  (f) => f.name !== "pretext" && f.name !== "mathbook"
1025
1028
  ), o = i[0], s = o?.name === "book" && o.children.some(
1026
1029
  (f) => g(f) && f.name === "part"
1027
- ), a = tn(i, s), c = new Set(r), d = nn(t), u = /* @__PURE__ */ new Set();
1030
+ ), c = tn(i, s), a = new Set(r), d = nn(t), u = /* @__PURE__ */ new Set();
1028
1031
  if (d.size > 0)
1029
1032
  for (const f of d) {
1030
1033
  const w = V(e, f);
@@ -1035,29 +1038,29 @@ function on(e, n) {
1035
1038
  if (b && b !== t) {
1036
1039
  u.add(b);
1037
1040
  for (const v of L(e, b) ?? [])
1038
- c.add(v);
1041
+ a.add(v);
1039
1042
  }
1040
1043
  }
1041
1044
  for (const f of r) {
1042
1045
  if (f === t) break;
1043
- X(f, c);
1046
+ X(f, a);
1044
1047
  }
1045
1048
  for (const f of u)
1046
1049
  Oe(f);
1047
1050
  const p = e.children.find(g);
1048
- return p && !r.includes(p) && X(p, c), { content: I(e), divisionId: n, level: a };
1051
+ return p && !r.includes(p) && X(p, a), { content: I(e), divisionId: n, level: c };
1049
1052
  }
1050
- const sn = "This live preview shows a single division, so links into the rest of the document do not work here.", an = /<a\b([^>]*)>/g, cn = /\sid="([^"]*)"/g, C = /\shref="([^"]*)"/, ln = /\\href\{([^{}]*)\}/g, ae = /\stitle="([^"]*)"/;
1053
+ const sn = "This live preview shows a single division, so links into the rest of the document do not work here.", cn = /<a\b([^>]*)>/g, an = /\sid="([^"]*)"/g, C = /\shref="([^"]*)"/, ln = /\\href\{([^{}]*)\}/g, ce = /\stitle="([^"]*)"/;
1051
1054
  function dn(e) {
1052
1055
  const n = /* @__PURE__ */ new Set();
1053
- for (const t of e.matchAll(cn))
1056
+ for (const t of e.matchAll(an))
1054
1057
  n.add(t[1]);
1055
1058
  return n;
1056
1059
  }
1057
1060
  function un(e) {
1058
1061
  return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1059
1062
  }
1060
- function ce(e, n) {
1063
+ function ae(e, n) {
1061
1064
  if (e.startsWith("#") || e === "") return { kind: "keep" };
1062
1065
  if (/^[a-z][a-z0-9+.-]*:/i.test(e) || e.startsWith("//"))
1063
1066
  return { kind: "keep" };
@@ -1068,18 +1071,18 @@ function ce(e, n) {
1068
1071
  }
1069
1072
  function fn(e, n = {}) {
1070
1073
  const t = n.offPageMessage ?? sn, r = dn(e);
1071
- return e.replace(an, (o, s) => {
1072
- const a = C.exec(s);
1073
- if (!a) return o;
1074
- const c = ce(a[1], r);
1075
- if (c.kind === "keep") return o;
1076
- if (c.kind === "same-page")
1077
- return `<a${s.replace(C, ` href="#${c.id}"`)}>`;
1078
- const d = ae.exec(s), u = un(t), p = d ? `${d[1]} — ${u}` : u;
1079
- return `<a${s.replace(C, "").replace(ae, "")} title="${p}" aria-disabled="true" style="cursor:default">`;
1074
+ return e.replace(cn, (o, s) => {
1075
+ const c = C.exec(s);
1076
+ if (!c) return o;
1077
+ const a = ae(c[1], r);
1078
+ if (a.kind === "keep") return o;
1079
+ if (a.kind === "same-page")
1080
+ return `<a${s.replace(C, ` href="#${a.id}"`)}>`;
1081
+ const d = ce.exec(s), u = un(t), p = d ? `${d[1]} — ${u}` : u;
1082
+ return `<a${s.replace(C, "").replace(ce, "")} title="${p}" aria-disabled="true" style="cursor:default">`;
1080
1083
  }).replace(ln, (o, s) => {
1081
- const a = ce(s, r);
1082
- return a.kind === "same-page" ? `\\href{#${a.id}}` : o;
1084
+ const c = ae(s, r);
1085
+ return c.kind === "same-page" ? `\\href{#${c.id}}` : o;
1083
1086
  });
1084
1087
  }
1085
1088
  function pn() {
@@ -1148,18 +1151,18 @@ async function Tn(e, n, t, r) {
1148
1151
  (u) => u.type === "element"
1149
1152
  ), o = i?.attributes["xml:id"];
1150
1153
  if (!i || !o) return;
1151
- const s = h(n), a = r ?? await B(s);
1152
- if (a === void 0) return;
1153
- let c;
1154
+ const s = h(n), c = r ?? await B(s);
1155
+ if (c === void 0) return;
1156
+ let a;
1154
1157
  try {
1155
- c = (await z(a, s, t)).tree;
1158
+ a = (await z(c, s, t)).tree;
1156
1159
  } catch {
1157
1160
  return;
1158
1161
  }
1159
- if (!rn(c, o, i)) return;
1160
- const d = on(c, o);
1162
+ if (!rn(a, o, i)) return;
1163
+ const d = on(a, o);
1161
1164
  if (d)
1162
- return { ...d, tree: c };
1165
+ return { ...d, tree: a };
1163
1166
  }
1164
1167
  let je = !1;
1165
1168
  function Sn(e) {
@@ -1204,13 +1207,13 @@ async function In(e, n) {
1204
1207
  const t = kn[n], r = `${n}\0${e}`;
1205
1208
  let i = F.get(r);
1206
1209
  return i || (i = (async () => {
1207
- const { XmlDocument: o, XsltStylesheet: s } = await Ce(), a = Ee(e), c = await we(M(), `/${t}`);
1208
- if (c === void 0)
1210
+ const { XmlDocument: o, XsltStylesheet: s } = await Ce(), c = Ee(e), a = await we(M(), `/${t}`);
1211
+ if (a === void 0)
1209
1212
  throw new Error(
1210
1213
  `Could not read ${t} from ${M()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1211
1214
  );
1212
- const d = new TextDecoder().decode(c), u = await o.fromString(d, {
1213
- url: `${a}/${t}`,
1215
+ const d = new TextDecoder().decode(a), u = await o.fromString(d, {
1216
+ url: `${c}/${t}`,
1214
1217
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1215
1218
  });
1216
1219
  return s.fromXmlDocument(u);
@@ -1237,14 +1240,14 @@ async function fe(e) {
1237
1240
  const s = j(
1238
1241
  r,
1239
1242
  h(e.mainSourcePath ?? t)
1240
- ), a = s.startsWith("..") ? o : s, c = Ee(r);
1243
+ ), c = s.startsWith("..") ? o : s, a = Ee(r);
1241
1244
  try {
1242
- let d, u = `${c}/__pretext-preview-publication.xml`;
1245
+ let d, u = `${a}/__pretext-preview-publication.xml`;
1243
1246
  if (e.publicationPath) {
1244
1247
  const l = h(e.publicationPath);
1245
1248
  d = await le(l);
1246
1249
  const m = j(r, l);
1247
- m.startsWith("..") || (u = `${c}/${m.split(W).join("/")}`);
1250
+ m.startsWith("..") || (u = `${a}/${m.split(W).join("/")}`);
1248
1251
  }
1249
1252
  let p, f;
1250
1253
  if (e.sourceMap) {
@@ -1266,7 +1269,7 @@ async function fe(e) {
1266
1269
  target: w
1267
1270
  });
1268
1271
  ft(u, b);
1269
- const v = Pt(b), K = E(h(r, a)), G = v.external !== void 0 && v.generated !== void 0 ? {
1272
+ const v = Pt(b), K = E(h(r, c)), G = v.external !== void 0 && v.generated !== void 0 ? {
1270
1273
  external: h(K, v.external),
1271
1274
  generated: h(K, v.generated)
1272
1275
  } : void 0, S = xn(f);
@@ -1296,7 +1299,7 @@ async function fe(e) {
1296
1299
  }
1297
1300
  }
1298
1301
  const Z = p ? Yt(p, q, Y) : void 0, Q = await n.fromString(f, {
1299
- url: `${c}/${a.split(W).join("/")}`,
1302
+ url: `${a}/${c.split(W).join("/")}`,
1300
1303
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1301
1304
  }), _ = {
1302
1305
  publisher: k(u)
@@ -1339,7 +1342,7 @@ async function fe(e) {
1339
1342
  O.delete();
1340
1343
  }
1341
1344
  } finally {
1342
- ut(c);
1345
+ ut(a);
1343
1346
  }
1344
1347
  }
1345
1348
  export {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { O as i, P as s, b as t, d as a, a as n, c as o, f as l, e as d, i as p, g as E, o as c, p as P, r as v, h as m, j as S, m as g, s as A, k as B, x as f } from "./cli-CMAunrD_.js";
1
+ import { O as i, P as s, b as t, d as a, a as n, c as o, f as l, e as d, i as p, g as E, o as c, p as P, r as v, h as m, j as S, m as g, s as A, k as B, x as f } from "./cli-BkTQ4BJP.js";
2
2
  import { injectRevealBridge as R, isRevealView as _, revealBridgeScript as u } from "./reveal.js";
3
3
  import { describeAsset as x, missingAssetPlaceholder as T, missingAssetSvg as b, rewriteAssetUrls as M } from "./assets.js";
4
4
  import { PREVIEW_THEME_MESSAGE as G, injectThemeBridge as I, isPreviewTheme as L, previewThemeMessage as O, themeBridgeScript as V } from "./theme.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretextbook/pretext-html",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Convert PreTeXt documents to HTML in pure JavaScript using the official PreTeXt XSLT stylesheets via libxslt-wasm. No Python or PreTeXt installation required.",
5
5
  "author": "Oscar Levin",
6
6
  "license": "MIT",