@pretextbook/pretext-html 0.5.0 → 0.6.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.
@@ -1,11 +1,11 @@
1
- import { readFile as A, writeFile as O } from "node:fs/promises";
1
+ import { readFile as R, writeFile as O } from "node:fs/promises";
2
2
  import * as b from "node:process";
3
3
  import * as l from "node:path";
4
- import { fileURLToPath as he } from "node:url";
4
+ import { fileURLToPath as me } from "node:url";
5
5
  import { fromXml as x } from "xast-util-from-xml";
6
- import { toXml as $ } from "xast-util-to-xml";
7
- import { injectRevealBridge as me } from "./reveal.js";
8
- import { injectThemeBridge as pe } from "./theme.js";
6
+ import { toXml as E } from "xast-util-to-xml";
7
+ import { injectRevealBridge as pe } from "./reveal.js";
8
+ import { injectThemeBridge as we } from "./theme.js";
9
9
  async function Q(e, r) {
10
10
  const t = l.resolve(e), n = l.resolve(t, `.${l.posix.normalize(r)}`);
11
11
  if (n !== t && !n.startsWith(t + l.sep)) {
@@ -15,35 +15,57 @@ async function Q(e, r) {
15
15
  return;
16
16
  }
17
17
  try {
18
- return new Uint8Array(await A(n));
18
+ return new Uint8Array(await R(n));
19
19
  } catch {
20
20
  return;
21
21
  }
22
22
  }
23
- async function j(e) {
23
+ async function A(e) {
24
24
  try {
25
- return await A(e, "utf8");
25
+ return await R(e, "utf8");
26
26
  } catch {
27
27
  return;
28
28
  }
29
29
  }
30
- let K;
31
- function st(e) {
32
- K = e;
30
+ let ee;
31
+ function dt(e) {
32
+ ee = e;
33
33
  }
34
34
  function I() {
35
- return K ?? process.env.PRETEXT_HTML_ASSETS ?? l.resolve(l.dirname(he(import.meta.url)), "..", "assets");
35
+ return ee ?? process.env.PRETEXT_HTML_ASSETS ?? l.resolve(l.dirname(me(import.meta.url)), "..", "assets");
36
36
  }
37
- function we(e, r) {
37
+ function be(e, r) {
38
38
  return l.join(e, r);
39
39
  }
40
- const X = /* @__PURE__ */ new Map(), ee = /* @__PURE__ */ new Map();
41
- let M, be = 0, te = Q;
42
- function it(e) {
43
- te = e;
40
+ const ge = "born-hidden-knowl", ve = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
41
+ function ye(e) {
42
+ const r = /\bclass="([^"]*)"/.exec(e);
43
+ return r ? r[1].trim().split(/\s+/) : [];
44
44
  }
45
- function ge(e, r) {
46
- const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n = ee.get(t);
45
+ function xe(e) {
46
+ return /(^|\s)open(\s|=|$)/.test(e);
47
+ }
48
+ function H(e) {
49
+ return xe(e) ? e : ` open${e}`;
50
+ }
51
+ function Te(e) {
52
+ return e.replace(
53
+ ve,
54
+ (r, t, n, o) => {
55
+ if (!ye(t).includes(ge))
56
+ return r;
57
+ const s = `<details${H(t)}>`;
58
+ return o === void 0 ? `${s}${n}` : `${s}${n}<summary${H(o)}>`;
59
+ }
60
+ );
61
+ }
62
+ const j = /* @__PURE__ */ new Map(), te = /* @__PURE__ */ new Map();
63
+ let L, $e = 0, re = Q;
64
+ function ft(e) {
65
+ re = e;
66
+ }
67
+ function Ee(e, r) {
68
+ const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n = te.get(t);
47
69
  if (n !== void 0)
48
70
  return Promise.resolve(new Response(n, { status: 200 }));
49
71
  let o;
@@ -52,32 +74,32 @@ function ge(e, r) {
52
74
  } catch {
53
75
  o = "";
54
76
  }
55
- const s = X.get(o);
56
- return s !== void 0 ? ye(s, t) : M(e, r);
77
+ const s = j.get(o);
78
+ return s !== void 0 ? ke(s, t) : L(e, r);
57
79
  }
58
- const ve = '<?xml version="1.0"?><pretext-preview-missing-file/>';
59
- async function ye(e, r) {
60
- const t = decodeURIComponent(new URL(r).pathname), n = await te(e, t);
80
+ const Se = '<?xml version="1.0"?><pretext-preview-missing-file/>';
81
+ async function ke(e, r) {
82
+ const t = decodeURIComponent(new URL(r).pathname), n = await re(e, t);
61
83
  if (n === void 0)
62
- return new Response(ve, { status: 200 });
84
+ return new Response(Se, { status: 200 });
63
85
  const o = typeof n == "string" ? n : new Uint8Array(n);
64
86
  return new Response(o, { status: 200 });
65
87
  }
66
- function re() {
67
- M || (M = globalThis.fetch, globalThis.fetch = ge);
88
+ function ne() {
89
+ L || (L = globalThis.fetch, globalThis.fetch = Ee);
68
90
  }
69
- function ne(e) {
70
- re();
71
- const r = `mnt${++be}.ptx.invalid`;
72
- return X.set(r, e), `http://${r}`;
91
+ function oe(e) {
92
+ ne();
93
+ const r = `mnt${++$e}.ptx.invalid`;
94
+ return j.set(r, e), `http://${r}`;
73
95
  }
74
- function xe(e) {
75
- X.delete(new URL(e).host);
96
+ function Pe(e) {
97
+ j.delete(new URL(e).host);
76
98
  }
77
- function Te(e, r) {
78
- re(), ee.set(e, r);
99
+ function De(e, r) {
100
+ ne(), te.set(e, r);
79
101
  }
80
- const R = `<?xml version="1.0" encoding="UTF-8"?>
102
+ const M = `<?xml version="1.0" encoding="UTF-8"?>
81
103
  <publication>
82
104
  <source>
83
105
  <directories external="../assets" generated="../generated-assets" />
@@ -86,7 +108,7 @@ const R = `<?xml version="1.0" encoding="UTF-8"?>
86
108
  <platform portable="yes"/>
87
109
  </html>
88
110
  </publication>
89
- `, Ee = ["theme", "style", "shell"];
111
+ `, Ie = ["theme", "style", "shell"];
90
112
  function w(e, r) {
91
113
  for (const t of e.children)
92
114
  if (t.type === "element" && t.name === r)
@@ -96,21 +118,21 @@ function g(e, r) {
96
118
  let t = w(e, r);
97
119
  return t || (t = { type: "element", name: r, attributes: {}, children: [] }, e.children.push(t)), t;
98
120
  }
99
- function $e(e, r) {
121
+ function Le(e, r) {
100
122
  const t = w(e, "css");
101
- if (t && Ee.some((o) => t.attributes?.[o]))
123
+ if (t && Ie.some((o) => t.attributes?.[o]))
102
124
  return;
103
125
  const n = t ?? g(e, "css");
104
126
  n.attributes = { ...n.attributes, theme: r };
105
127
  }
106
- function Se(e, r) {
128
+ function Me(e, r) {
107
129
  const t = w(e, "appearance");
108
130
  if (t?.attributes?.theme)
109
131
  return;
110
132
  const n = t ?? g(e, "appearance");
111
133
  n.attributes = { ...n.attributes, theme: r };
112
134
  }
113
- function Pe(e) {
135
+ function Re(e) {
114
136
  const r = g(e, "resources");
115
137
  r.attributes = {
116
138
  ...r.attributes,
@@ -118,30 +140,30 @@ function Pe(e) {
118
140
  math: "online"
119
141
  };
120
142
  }
121
- function ke(e, r = {}) {
143
+ function Ae(e, r = {}) {
122
144
  const t = r.cssTheme?.trim(), n = r.revealTheme?.trim(), o = r.target === "slides";
123
145
  if (!e && !t && !o)
124
- return R;
125
- const s = x(e ?? R), a = w(s, "publication");
146
+ return M;
147
+ const s = x(e ?? M), a = w(s, "publication");
126
148
  if (!a)
127
149
  throw new Error(
128
150
  "Invalid publication file: no root <publication> element found"
129
151
  );
130
152
  const i = g(a, "html"), u = g(i, "platform");
131
- if (u.attributes = { ...u.attributes, portable: "yes" }, t && $e(i, t), o) {
153
+ if (u.attributes = { ...u.attributes, portable: "yes" }, t && Le(i, t), o) {
132
154
  const c = g(a, "revealjs");
133
- Pe(c), n && Se(c, n);
155
+ Re(c), n && Me(c, n);
134
156
  }
135
- return $(s);
157
+ return E(s);
136
158
  }
137
- function H(e) {
159
+ function N(e) {
138
160
  if (!(e === void 0 || e === "" || e.startsWith("/")))
139
161
  return e.endsWith("/") ? e : `${e}/`;
140
162
  }
141
- function De(e) {
142
- const r = x(e ?? R), t = w(r, "publication"), n = t && w(t, "source"), o = n && w(n, "directories"), s = H(
163
+ function je(e) {
164
+ const r = x(e ?? M), t = w(r, "publication"), n = t && w(t, "source"), o = n && w(n, "directories"), s = N(
143
165
  o?.attributes?.external ?? void 0
144
- ), a = H(
166
+ ), a = N(
145
167
  o?.attributes?.generated ?? void 0
146
168
  );
147
169
  return {
@@ -150,11 +172,11 @@ function De(e) {
150
172
  managed: s !== void 0 && a !== void 0
151
173
  };
152
174
  }
153
- const oe = "http://www.w3.org/2001/XInclude", N = 64;
154
- async function Ie(e, r, t) {
155
- return e.includes("include") ? (await se(e, r, t)).content : e;
175
+ const se = "http://www.w3.org/2001/XInclude", J = 64;
176
+ async function Xe(e, r, t) {
177
+ return e.includes("include") ? (await ie(e, r, t)).content : e;
156
178
  }
157
- async function se(e, r, t) {
179
+ async function ie(e, r, t) {
158
180
  const n = x(e), o = {
159
181
  projectDir: l.resolve(t),
160
182
  stack: [l.resolve(r)]
@@ -164,12 +186,12 @@ async function se(e, r, t) {
164
186
  { "": "" },
165
187
  o
166
188
  );
167
- return { tree: n, content: s ? $(n) : e };
189
+ return { tree: n, content: s ? E(n) : e };
168
190
  }
169
- function Me(e) {
191
+ function Fe(e) {
170
192
  return e.data?.ptxIncludedFile;
171
193
  }
172
- function Re(e, r) {
194
+ function Ce(e, r) {
173
195
  const t = e.data ?? (e.data = {});
174
196
  t.ptxIncludedFile = r;
175
197
  }
@@ -179,9 +201,9 @@ function S(e, r) {
179
201
  (n === "xmlns" || n.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[n === "xmlns" ? "" : n.slice(6)] = o ?? "");
180
202
  return t;
181
203
  }
182
- function ie(e, r) {
204
+ function ae(e, r) {
183
205
  const t = e.name.indexOf(":"), n = t === -1 ? "" : e.name.slice(0, t);
184
- return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && r[n] === oe;
206
+ return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && r[n] === se;
185
207
  }
186
208
  async function y(e, r, t, n) {
187
209
  let o = !1;
@@ -190,8 +212,8 @@ async function y(e, r, t, n) {
190
212
  if (a.type !== "element")
191
213
  continue;
192
214
  const i = S(t, a);
193
- if (ie(a, i)) {
194
- const u = await ae(
215
+ if (ae(a, i)) {
216
+ const u = await ce(
195
217
  a,
196
218
  r,
197
219
  i,
@@ -202,7 +224,7 @@ async function y(e, r, t, n) {
202
224
  }
203
225
  return o;
204
226
  }
205
- async function ae(e, r, t, n) {
227
+ async function ce(e, r, t, n) {
206
228
  const o = n.stack[n.stack.length - 1];
207
229
  if (e.attributes.xpointer)
208
230
  throw new Error(
@@ -225,11 +247,11 @@ async function ae(e, r, t, n) {
225
247
  throw new Error(
226
248
  `Circular xi:include: ${[...n.stack, i].join(" -> ")}`
227
249
  );
228
- if (n.stack.length >= N)
229
- throw new Error(`xi:include nesting exceeds ${N} levels`);
230
- const u = await j(i);
250
+ if (n.stack.length >= J)
251
+ throw new Error(`xi:include nesting exceeds ${J} levels`);
252
+ const u = await A(i);
231
253
  if (u === void 0) {
232
- const h = je(e, t);
254
+ const h = We(e, t);
233
255
  if (h)
234
256
  return await y(h, r, t, n), h.children;
235
257
  throw new Error(`xi:include target not found: ${s} (in ${o})`);
@@ -254,13 +276,13 @@ async function ae(e, r, t, n) {
254
276
  (h) => h.type === "element"
255
277
  );
256
278
  for (const h of f)
257
- Re(h, i);
279
+ Ce(h, i);
258
280
  return f;
259
281
  }
260
- function J(e) {
282
+ function z(e) {
261
283
  return e.name === "docinfo";
262
284
  }
263
- async function Ae(e, r, t) {
285
+ async function Ue(e, r, t) {
264
286
  try {
265
287
  const o = x(e).children.find(
266
288
  (c) => c.type === "element"
@@ -275,19 +297,19 @@ async function Ae(e, r, t) {
275
297
  if (c.type !== "element")
276
298
  continue;
277
299
  const f = S(u, c);
278
- if (J(c))
279
- return await y(c, a, f, i), $(c);
280
- if (ie(c, f)) {
281
- const m = (await ae(
300
+ if (z(c))
301
+ return await y(c, a, f, i), E(c);
302
+ if (ae(c, f)) {
303
+ const m = (await ce(
282
304
  c,
283
305
  a,
284
306
  f,
285
307
  i
286
308
  )).find(
287
- (p) => p.type === "element" && J(p)
309
+ (p) => p.type === "element" && z(p)
288
310
  );
289
311
  if (m)
290
- return $(m);
312
+ return E(m);
291
313
  continue;
292
314
  }
293
315
  break;
@@ -297,33 +319,33 @@ async function Ae(e, r, t) {
297
319
  return;
298
320
  }
299
321
  }
300
- function je(e, r) {
322
+ function We(e, r) {
301
323
  for (const t of e.children) {
302
324
  if (t.type !== "element")
303
325
  continue;
304
326
  const n = S(r, t), o = t.name.indexOf(":"), s = o === -1 ? "" : t.name.slice(0, o);
305
- if ((o === -1 ? t.name : t.name.slice(o + 1)) === "fallback" && n[s] === oe)
327
+ if ((o === -1 ? t.name : t.name.slice(o + 1)) === "fallback" && n[s] === se)
306
328
  return t;
307
329
  }
308
330
  }
309
- function ce(e) {
331
+ function le(e) {
310
332
  return typeof e == "object" && e !== null && e.type === "element";
311
333
  }
312
- function Xe(e) {
334
+ function Be(e) {
313
335
  return /^(pf|xhtml):/.test(e.name);
314
336
  }
315
- function Le(e, r, t) {
316
- const n = [], o = e.children.find(ce);
337
+ function _e(e, r, t) {
338
+ const n = [], o = e.children.find(le);
317
339
  if (o) {
318
340
  const s = t?.parentId ?? "root";
319
- le(o, s, t?.position ?? 1, r, s, n);
341
+ ue(o, s, t?.position ?? 1, r, s, n);
320
342
  }
321
343
  return n;
322
344
  }
323
- function le(e, r, t, n, o, s) {
324
- const a = Me(e) ?? n;
345
+ function ue(e, r, t, n, o, s) {
346
+ const a = Fe(e) ?? n;
325
347
  let i, u;
326
- if (Xe(e))
348
+ if (Be(e))
327
349
  u = "root";
328
350
  else {
329
351
  const f = e.attributes.label ?? e.attributes["xml:id"];
@@ -338,7 +360,7 @@ function le(e, r, t, n, o, s) {
338
360
  }
339
361
  let c = 0;
340
362
  for (const f of e.children)
341
- ce(f) && (c += 1, le(
363
+ le(f) && (c += 1, ue(
342
364
  f,
343
365
  u,
344
366
  c,
@@ -347,61 +369,61 @@ function le(e, r, t, n, o, s) {
347
369
  s
348
370
  ));
349
371
  }
350
- function at(e, r) {
372
+ function ht(e, r) {
351
373
  let t;
352
374
  for (const n of e)
353
375
  n.line <= r && (t = n);
354
376
  return t ?? e[0];
355
377
  }
356
- function Fe(e) {
378
+ function Oe(e) {
357
379
  const r = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
358
380
  return /<\s*slide(?:show)?[\s/>]/.test(r) ? "slides" : "html";
359
381
  }
360
- function Ce() {
361
- return we(I(), "xsl");
382
+ function He() {
383
+ return be(I(), "xsl");
362
384
  }
363
- function Ue() {
385
+ function Ne() {
364
386
  return "Suspending" in WebAssembly;
365
387
  }
366
- function We() {
367
- if (!Ue())
388
+ function Je() {
389
+ if (!Ne())
368
390
  throw new Error(
369
391
  "WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
370
392
  );
371
393
  }
372
- function z(e) {
394
+ function K(e) {
373
395
  return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
374
396
  }
375
- function Be(e) {
397
+ function ze(e) {
376
398
  return e.replace(
377
399
  /from '\.\/(https:\/\/[^']+)'/g,
378
400
  (r, t) => `from '${t}'`
379
401
  );
380
402
  }
381
- const _e = "https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@latest/dist/";
382
- function Oe(e) {
403
+ const Ke = "https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@latest/dist/";
404
+ function Ge(e) {
383
405
  return e.replace(
384
406
  /(<link\b[^>]*\bhref=["'])_static\//gi,
385
- `$1${_e}_static/`
407
+ `$1${Ke}_static/`
386
408
  );
387
409
  }
388
- function He(e) {
410
+ function Ve(e) {
389
411
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
390
412
  }
391
- async function V(e) {
392
- const r = await j(e);
413
+ async function G(e) {
414
+ const r = await A(e);
393
415
  if (r === void 0)
394
416
  throw new Error(
395
417
  `Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
396
418
  );
397
419
  return r;
398
420
  }
399
- async function Ne(e, r) {
400
- const t = l.resolve(e), n = await j(t);
421
+ async function Ye(e, r) {
422
+ const t = l.resolve(e), n = await A(t);
401
423
  if (n !== void 0)
402
- return Ae(n, t, r);
424
+ return Ue(n, t, r);
403
425
  }
404
- function Je(e, r, t, n) {
426
+ function qe(e, r, t, n) {
405
427
  const o = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), s = t === "slides" ? "slideshow" : r === "chapter" || r === "part" ? "book" : "article";
406
428
  return `<pretext>
407
429
  ${n?.trim() ? `${n.trim()}
@@ -412,50 +434,50 @@ ${o}
412
434
  </pretext>
413
435
  `;
414
436
  }
415
- let ue = !1;
416
- function ze(e) {
437
+ let de = !1;
438
+ function Ze(e) {
417
439
  return e instanceof Error && /\bAborted\(/.test(e.message);
418
440
  }
419
- function Ve(e) {
441
+ function Qe(e) {
420
442
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
421
443
  }
422
- function Ye() {
423
- if (ue)
444
+ function et() {
445
+ if (de)
424
446
  throw new Error(
425
447
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
426
448
  );
427
449
  }
428
- function Y(e) {
429
- if (ze(e))
430
- throw ue = !0, new Error(
450
+ function V(e) {
451
+ if (Ze(e))
452
+ throw de = !0, new Error(
431
453
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
432
454
  { cause: e }
433
455
  );
434
- if (Ve(e))
456
+ if (Qe(e))
435
457
  throw new Error(
436
458
  "The WebAssembly renderer hit a memory fault. Most often the document is too large for this build's stack — whole-book builds are a known limitation, so try a smaller document, or see the README about rebuilding libxslt-wasm with a larger stack. The same fault also results from running two renders concurrently against the shared libxslt state.",
437
459
  { cause: e }
438
460
  );
439
461
  }
440
- let k;
441
- async function de() {
442
- return k || (k = (async () => {
462
+ let P;
463
+ async function fe() {
464
+ return P || (P = (async () => {
443
465
  const [e, r] = await Promise.all([
444
466
  import("@pretextbook/libxslt-wasm"),
445
467
  import("@pretextbook/libxslt-wasm/exslt")
446
468
  ]);
447
469
  return r.registerAll(), e;
448
- })()), k;
470
+ })()), P;
449
471
  }
450
- const D = /* @__PURE__ */ new Map(), qe = {
472
+ const D = /* @__PURE__ */ new Map(), tt = {
451
473
  html: "preview-html.xsl",
452
474
  slides: "preview-revealjs.xsl"
453
475
  };
454
- async function Ge(e, r) {
455
- const t = qe[r], n = `${r}\0${e}`;
476
+ async function rt(e, r) {
477
+ const t = tt[r], n = `${r}\0${e}`;
456
478
  let o = D.get(n);
457
479
  return o || (o = (async () => {
458
- const { XmlDocument: s, XsltStylesheet: a } = await de(), i = ne(e), u = await Q(I(), `/${t}`);
480
+ const { XmlDocument: s, XsltStylesheet: a } = await fe(), i = oe(e), u = await Q(I(), `/${t}`);
459
481
  if (u === void 0)
460
482
  throw new Error(
461
483
  `Could not read ${t} from ${I()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
@@ -467,20 +489,20 @@ async function Ge(e, r) {
467
489
  return a.fromXmlDocument(f);
468
490
  })(), D.set(n, o), o.catch(() => D.delete(n))), o;
469
491
  }
470
- let q = Promise.resolve();
471
- function Ze(e) {
472
- const r = q.then(
473
- () => G(e),
474
- () => G(e)
492
+ let Y = Promise.resolve();
493
+ function nt(e) {
494
+ const r = Y.then(
495
+ () => q(e),
496
+ () => q(e)
475
497
  );
476
- return q = r.catch(() => {
498
+ return Y = r.catch(() => {
477
499
  }), r;
478
500
  }
479
- async function G(e) {
480
- We(), Ye();
481
- const { XmlDocument: r } = await de(), t = l.resolve(e.sourcePath), n = l.resolve(
501
+ async function q(e) {
502
+ Je(), et();
503
+ const { XmlDocument: r } = await fe(), t = l.resolve(e.sourcePath), n = l.resolve(
482
504
  e.projectDir ?? l.dirname(t)
483
- ), o = e.sourceContent ?? await V(t), s = l.relative(n, t);
505
+ ), o = e.sourceContent ?? await G(t), s = l.relative(n, t);
484
506
  if (s.startsWith(".."))
485
507
  throw new Error(
486
508
  `sourcePath (${t}) must live inside projectDir (${n})`
@@ -488,66 +510,66 @@ async function G(e) {
488
510
  const a = l.relative(
489
511
  n,
490
512
  l.resolve(e.mainSourcePath ?? t)
491
- ), i = a.startsWith("..") ? s : a, u = ne(n);
513
+ ), i = a.startsWith("..") ? s : a, u = oe(n);
492
514
  try {
493
515
  let c, f = `${u}/__pretext-preview-publication.xml`;
494
516
  if (e.publicationPath) {
495
517
  const d = l.resolve(e.publicationPath);
496
- c = await V(d);
518
+ c = await G(d);
497
519
  const v = l.relative(n, d);
498
520
  v.startsWith("..") || (f = `${u}/${v.split(l.sep).join("/")}`);
499
521
  }
500
522
  let h, m;
501
523
  if (e.sourceMap) {
502
- const d = await se(
524
+ const d = await ie(
503
525
  o,
504
526
  t,
505
527
  n
506
528
  );
507
529
  h = d.tree, m = d.content;
508
530
  } else
509
- m = await Ie(
531
+ m = await Xe(
510
532
  o,
511
533
  t,
512
534
  n
513
535
  );
514
- const p = e.target ?? Fe(m), fe = await Ge(e.xslDir ?? Ce(), p), L = ke(c, {
536
+ const p = e.target ?? Oe(m), he = await rt(e.xslDir ?? He(), p), X = Ae(c, {
515
537
  cssTheme: e.cssTheme,
516
538
  revealTheme: e.revealTheme,
517
539
  target: p
518
540
  });
519
- Te(f, L);
520
- const T = De(L), F = l.dirname(l.resolve(n, i)), C = T.external !== void 0 && T.generated !== void 0 ? {
541
+ De(f, X);
542
+ const T = je(X), F = l.dirname(l.resolve(n, i)), C = T.external !== void 0 && T.generated !== void 0 ? {
521
543
  external: l.resolve(F, T.external),
522
544
  generated: l.resolve(F, T.generated)
523
- } : void 0, E = He(m);
545
+ } : void 0, $ = Ve(m);
524
546
  let U = { parentId: "root", position: 1 };
525
- if (E !== "pretext" && E !== "mathbook")
547
+ if ($ !== "pretext" && $ !== "mathbook")
526
548
  if (e.fragment) {
527
- const d = e.docinfo ?? (e.docinfoSourcePath ? await Ne(e.docinfoSourcePath, n) : void 0);
528
- m = Je(
549
+ const d = e.docinfo ?? (e.docinfoSourcePath ? await Ye(e.docinfoSourcePath, n) : void 0);
550
+ m = qe(
529
551
  m,
530
- E,
552
+ $,
531
553
  p,
532
554
  d
533
555
  ), U = { parentId: d?.trim() ? "root-1-2" : "root-1-1", position: 2 };
534
556
  } else
535
557
  throw new Error(
536
- `The document root is <${E ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
558
+ `The document root is <${$ ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
537
559
  );
538
- const W = h ? Le(h, t, U) : void 0, B = await r.fromString(m, {
560
+ const W = h ? _e(h, t, U) : void 0, B = await r.fromString(m, {
539
561
  url: `${u}/${i.split(l.sep).join("/")}`,
540
562
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
541
563
  }), _ = {
542
- publisher: z(f)
564
+ publisher: K(f)
543
565
  };
544
566
  for (const [d, v] of Object.entries(e.stringParams ?? {}))
545
- _[d] = z(v);
546
- let P;
567
+ _[d] = K(v);
568
+ let k;
547
569
  try {
548
- P = await fe.apply(B, _);
570
+ k = await he.apply(B, _);
549
571
  } catch (d) {
550
- throw Y(d), new Error(
572
+ throw V(d), new Error(
551
573
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
552
574
  { cause: d }
553
575
  );
@@ -555,22 +577,22 @@ async function G(e) {
555
577
  B.delete();
556
578
  }
557
579
  try {
558
- let d = Be(P.toHtmlString());
559
- return p === "slides" ? (d = Oe(d), d = me(d, e.revealView ?? "scroll", {
580
+ let d = ze(k.toHtmlString());
581
+ return (e.openKnowls ?? !0) && (d = Te(d)), p === "slides" ? (d = Ge(d), d = pe(d, e.revealView ?? "scroll", {
560
582
  zoom: e.revealZoom
561
- })) : e.theme && (d = pe(d, e.theme)), {
583
+ })) : e.theme && (d = we(d, e.theme)), {
562
584
  html: d,
563
585
  target: p,
564
586
  ...W ? { sourceMap: W } : {},
565
587
  ...C ? { assetDirs: C } : {}
566
588
  };
567
589
  } catch (d) {
568
- throw Y(d), d;
590
+ throw V(d), d;
569
591
  } finally {
570
- P.delete();
592
+ k.delete();
571
593
  }
572
594
  } finally {
573
- xe(u);
595
+ Pe(u);
574
596
  }
575
597
  }
576
598
  const Z = `Usage: pretext-html <source.ptx> [options]
@@ -600,9 +622,13 @@ Options:
600
622
  xi:includes (used when --docinfo is not given)
601
623
  --source-map <file> Also write a JSON source map: HTML id → source
602
624
  file/line for every element (for editor sync)
625
+ --no-open-knowls Leave solutions, hints and other born-hidden
626
+ knowls collapsed, as a real PreTeXt build does.
627
+ They are expanded by default, since these pages
628
+ are previews of work in progress
603
629
  -h, --help Show this help
604
630
  `;
605
- function Qe(e) {
631
+ function ot(e) {
606
632
  let r, t, n, o;
607
633
  const s = {}, a = {};
608
634
  for (let i = 0; i < e.length; i++) {
@@ -635,6 +661,9 @@ function Qe(e) {
635
661
  case "--fragment":
636
662
  s.fragment = !0;
637
663
  break;
664
+ case "--no-open-knowls":
665
+ s.openKnowls = !1;
666
+ break;
638
667
  case "--docinfo":
639
668
  n = c();
640
669
  break;
@@ -670,25 +699,26 @@ function Qe(e) {
670
699
  sourceMapPath: o
671
700
  };
672
701
  }
673
- async function ct(e) {
674
- const { options: r, output: t, docinfoPath: n, sourceMapPath: o } = Qe(e);
675
- n && (r.docinfo = await A(n, "utf8"));
676
- const s = Date.now(), { html: a, sourceMap: i } = await Ze(r);
702
+ async function mt(e) {
703
+ const { options: r, output: t, docinfoPath: n, sourceMapPath: o } = ot(e);
704
+ n && (r.docinfo = await R(n, "utf8"));
705
+ const s = Date.now(), { html: a, sourceMap: i } = await nt(r);
677
706
  b.stderr.write(`pretext-html: rendered in ${Date.now() - s}ms
678
707
  `), o && i && (await O(o, JSON.stringify(i, null, 2)), b.stderr.write(`pretext-html: wrote ${o}
679
708
  `)), t ? (await O(t, a), b.stderr.write(`pretext-html: wrote ${t}
680
709
  `)) : b.stdout.write(a);
681
710
  }
682
711
  export {
683
- Fe as a,
684
- ke as b,
685
- it as c,
686
- Ce as d,
687
- at as f,
688
- Ue as i,
689
- ct as m,
690
- Qe as p,
691
- Ze as r,
692
- st as s,
693
- z as x
712
+ Oe as a,
713
+ Ae as b,
714
+ ft as c,
715
+ He as d,
716
+ ht as f,
717
+ Ne as i,
718
+ mt as m,
719
+ Te as o,
720
+ ot as p,
721
+ nt as r,
722
+ dt as s,
723
+ K as x
694
724
  };