@pretextbook/pretext-html 0.1.1 → 0.3.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.
Files changed (121) hide show
  1. package/README.md +82 -1
  2. package/assets/preview-html.xsl +0 -0
  3. package/assets/upstream.json +0 -0
  4. package/assets/xsl/README.md +0 -0
  5. package/assets/xsl/entities.ent +0 -0
  6. package/assets/xsl/extract-asymptote.xsl +0 -0
  7. package/assets/xsl/extract-biblio-csl.xsl +0 -0
  8. package/assets/xsl/extract-datafile.xsl +0 -0
  9. package/assets/xsl/extract-dynamic.xsl +0 -0
  10. package/assets/xsl/extract-identity.xsl +0 -0
  11. package/assets/xsl/extract-interactive.xsl +0 -0
  12. package/assets/xsl/extract-latex-image.xsl +0 -0
  13. package/assets/xsl/extract-mermaid.xsl +0 -0
  14. package/assets/xsl/extract-mom.xsl +0 -0
  15. package/assets/xsl/extract-pg.xsl +0 -0
  16. package/assets/xsl/extract-prefigure.xsl +0 -0
  17. package/assets/xsl/extract-qrcode.xsl +0 -0
  18. package/assets/xsl/extract-runestone-page-template.xsl +0 -0
  19. package/assets/xsl/extract-sageplot.xsl +0 -0
  20. package/assets/xsl/extract-stack.xsl +0 -0
  21. package/assets/xsl/extract-trace.xsl +0 -0
  22. package/assets/xsl/extract-youtube.xsl +0 -0
  23. package/assets/xsl/html-symbols.xsl +0 -0
  24. package/assets/xsl/latex/pretext-latex-AIM.xsl +0 -0
  25. package/assets/xsl/latex/pretext-latex-CLP.xsl +0 -0
  26. package/assets/xsl/latex/pretext-latex-chaos.xsl +0 -0
  27. package/assets/xsl/latex/pretext-latex-dyslexic-font.xsl +0 -0
  28. package/assets/xsl/latex/pretext-latex-guide.xsl +0 -0
  29. package/assets/xsl/latex/pretext-latex-texstyle.xsl +0 -0
  30. package/assets/xsl/localizations/README.md +0 -0
  31. package/assets/xsl/localizations/af-ZA.xml +0 -0
  32. package/assets/xsl/localizations/bg-BG.xml +0 -0
  33. package/assets/xsl/localizations/ca-ES.xml +0 -0
  34. package/assets/xsl/localizations/cs-CZ.xml +0 -0
  35. package/assets/xsl/localizations/de-DE.xml +0 -0
  36. package/assets/xsl/localizations/en-US.xml +0 -0
  37. package/assets/xsl/localizations/es-ES.xml +0 -0
  38. package/assets/xsl/localizations/fi-FI.xml +0 -0
  39. package/assets/xsl/localizations/fr-CA.xml +0 -0
  40. package/assets/xsl/localizations/fr-FR.xml +0 -0
  41. package/assets/xsl/localizations/hu-HU.xml +0 -0
  42. package/assets/xsl/localizations/it-IT.xml +0 -0
  43. package/assets/xsl/localizations/ku-CKB.xml +0 -0
  44. package/assets/xsl/localizations/localizations.xml +0 -0
  45. package/assets/xsl/localizations/nl-NL.xml +0 -0
  46. package/assets/xsl/localizations/pt-BR.xml +0 -0
  47. package/assets/xsl/localizations/pt-PT.xml +0 -0
  48. package/assets/xsl/localizations/zh-HANS.xml +0 -0
  49. package/assets/xsl/pretext-assembly.xsl +0 -0
  50. package/assets/xsl/pretext-basic-html.xsl +0 -0
  51. package/assets/xsl/pretext-beamer.xsl +0 -0
  52. package/assets/xsl/pretext-braille-preprint.xsl +0 -0
  53. package/assets/xsl/pretext-common.xsl +0 -0
  54. package/assets/xsl/pretext-dynamic.xsl +0 -0
  55. package/assets/xsl/pretext-epub.xsl +0 -0
  56. package/assets/xsl/pretext-fo.xsl +0 -0
  57. package/assets/xsl/pretext-html.xsl +0 -0
  58. package/assets/xsl/pretext-json-manifest.xsl +0 -0
  59. package/assets/xsl/pretext-jupyter.xsl +0 -0
  60. package/assets/xsl/pretext-latex-classic.xsl +0 -0
  61. package/assets/xsl/pretext-latex-common.xsl +0 -0
  62. package/assets/xsl/pretext-latex.xsl +0 -0
  63. package/assets/xsl/pretext-litprog.xsl +0 -0
  64. package/assets/xsl/pretext-merge.xsl +0 -0
  65. package/assets/xsl/pretext-numbers.xsl +0 -0
  66. package/assets/xsl/pretext-revealjs.xsl +0 -0
  67. package/assets/xsl/pretext-runestone-fitb.xsl +0 -0
  68. package/assets/xsl/pretext-runestone-static.xsl +0 -0
  69. package/assets/xsl/pretext-runestone.xsl +0 -0
  70. package/assets/xsl/pretext-sage-doctest.xsl +0 -0
  71. package/assets/xsl/pretext-smc.xsl +0 -0
  72. package/assets/xsl/pretext-solution-manual-latex.xsl +0 -0
  73. package/assets/xsl/pretext-text-utilities.xsl +0 -0
  74. package/assets/xsl/pretext-text.xsl +0 -0
  75. package/assets/xsl/pretext-units.xsl +0 -0
  76. package/assets/xsl/pretext-view-source.xsl +0 -0
  77. package/assets/xsl/pretext-ww-problem-sets.xsl +0 -0
  78. package/assets/xsl/publisher-variables.xsl +0 -0
  79. package/assets/xsl/support/README.md +0 -0
  80. package/assets/xsl/support/extract-math.xsl +0 -0
  81. package/assets/xsl/support/package-math.xsl +0 -0
  82. package/assets/xsl/support/play-button/README.md +0 -0
  83. package/assets/xsl/support/play-button/play-button.png +0 -0
  84. package/assets/xsl/support/play-button/play-button.svg +0 -0
  85. package/assets/xsl/support/pretext-pg-macros.xsl +0 -0
  86. package/assets/xsl/support/webpack_static_imports.xml +0 -0
  87. package/assets/xsl/tests/README.md +0 -0
  88. package/assets/xsl/tests/null.xml +0 -0
  89. package/assets/xsl/tests/pretext-text-utilities-test.xsl +0 -0
  90. package/assets/xsl/utilities/README.md +0 -0
  91. package/assets/xsl/utilities/author-report.xsl +0 -0
  92. package/assets/xsl/utilities/deprecate-autoname.sed +0 -0
  93. package/assets/xsl/utilities/deprecate-index.sed +0 -0
  94. package/assets/xsl/utilities/fix-deprecations.xsl +0 -0
  95. package/assets/xsl/utilities/pretext-enhanced-source.xsl +0 -0
  96. package/assets/xsl/utilities/report-publisher-variables.xsl +0 -0
  97. package/assets/xsl/xml-to-json.xsl +0 -0
  98. package/assets/xsl/xml-to-string.xsl +0 -0
  99. package/assets/xsl-bundle.json +1 -0
  100. package/dist/assets.d.ts +43 -0
  101. package/dist/assets.js +76 -0
  102. package/dist/cli-CzoinNle.js +639 -0
  103. package/dist/cli.d.ts +0 -0
  104. package/dist/cli.js +1 -1
  105. package/dist/host.browser.d.ts +29 -0
  106. package/dist/host.d.ts +41 -0
  107. package/dist/index.browser.d.ts +29 -0
  108. package/dist/index.browser.js +701 -0
  109. package/dist/index.d.ts +8 -0
  110. package/dist/index.js +20 -13
  111. package/dist/internal/posix-path.d.ts +59 -0
  112. package/dist/missing-asset.d.ts +31 -0
  113. package/dist/mounts.d.ts +18 -0
  114. package/dist/publication.d.ts +27 -0
  115. package/dist/renderer.d.ts +33 -1
  116. package/dist/sourcemap.d.ts +0 -0
  117. package/dist/theme.d.ts +0 -0
  118. package/dist/theme.js +0 -0
  119. package/dist/xinclude.d.ts +0 -0
  120. package/package.json +17 -3
  121. package/dist/cli-BQizBK0N.js +0 -555
@@ -1,555 +0,0 @@
1
- import { readFile as m, writeFile as X } from "node:fs/promises";
2
- import * as w from "node:process";
3
- import * as c from "node:path";
4
- import { fileURLToPath as K } from "node:url";
5
- import { fromXml as $ } from "xast-util-from-xml";
6
- import { toXml as y } from "xast-util-to-xml";
7
- import { injectThemeBridge as Q } from "./theme.js";
8
- const T = /* @__PURE__ */ new Map(), W = /* @__PURE__ */ new Map();
9
- let S, ee = 0;
10
- function te(e, r) {
11
- const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n = W.get(t);
12
- if (n !== void 0)
13
- return Promise.resolve(new Response(n, { status: 200 }));
14
- let o;
15
- try {
16
- o = new URL(t).host;
17
- } catch {
18
- o = "";
19
- }
20
- const i = T.get(o);
21
- return i !== void 0 ? re(i, t) : S(e, r);
22
- }
23
- const F = '<?xml version="1.0"?><pretext-preview-missing-file/>';
24
- async function re(e, r) {
25
- const t = decodeURIComponent(new URL(r).pathname), n = c.resolve(e, "." + c.posix.normalize(t));
26
- if (n !== e && !n.startsWith(e + c.sep))
27
- return console.error(
28
- `pretext-html: refusing to serve ${t} from outside ${e}`
29
- ), new Response(F, { status: 200 });
30
- try {
31
- const o = await m(n);
32
- return new Response(new Uint8Array(o), { status: 200 });
33
- } catch {
34
- return new Response(F, { status: 200 });
35
- }
36
- }
37
- function B() {
38
- S || (S = globalThis.fetch, globalThis.fetch = te);
39
- }
40
- function N(e) {
41
- B();
42
- const r = `mnt${++ee}.ptx.invalid`;
43
- return T.set(r, c.resolve(e)), `http://${r}`;
44
- }
45
- function ne(e) {
46
- T.delete(new URL(e).host);
47
- }
48
- function oe(e, r) {
49
- B(), W.set(e, r);
50
- }
51
- const ie = `<?xml version="1.0" encoding="UTF-8"?>
52
- <publication>
53
- <source>
54
- <directories external="../assets" generated="../generated-assets" />
55
- </source>
56
- <html>
57
- <platform portable="yes"/>
58
- </html>
59
- </publication>
60
- `;
61
- function _(e, r) {
62
- for (const t of e.children)
63
- if (t.type === "element" && t.name === r)
64
- return t;
65
- }
66
- function M(e, r) {
67
- let t = _(e, r);
68
- return t || (t = { type: "element", name: r, attributes: {}, children: [] }, e.children.push(t)), t;
69
- }
70
- function L(e) {
71
- if (!e)
72
- return ie;
73
- const r = $(e), t = _(r, "publication");
74
- if (!t)
75
- throw new Error(
76
- "Invalid publication file: no root <publication> element found"
77
- );
78
- const n = M(t, "html"), o = M(n, "platform");
79
- return o.attributes = { ...o.attributes, portable: "yes" }, y(r);
80
- }
81
- const H = "http://www.w3.org/2001/XInclude", R = 64;
82
- async function se(e, r, t) {
83
- return e.includes("include") ? (await J(e, r, t)).content : e;
84
- }
85
- async function J(e, r, t) {
86
- const n = $(e), o = {
87
- projectDir: c.resolve(t),
88
- stack: [c.resolve(r)]
89
- }, i = await x(
90
- n,
91
- c.dirname(c.resolve(r)),
92
- { "": "" },
93
- o
94
- );
95
- return { tree: n, content: i ? y(n) : e };
96
- }
97
- function ae(e) {
98
- return e.data?.ptxIncludedFile;
99
- }
100
- function ce(e, r) {
101
- const t = e.data ?? (e.data = {});
102
- t.ptxIncludedFile = r;
103
- }
104
- function v(e, r) {
105
- let t = e;
106
- for (const [n, o] of Object.entries(r.attributes))
107
- (n === "xmlns" || n.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[n === "xmlns" ? "" : n.slice(6)] = o ?? "");
108
- return t;
109
- }
110
- function q(e, r) {
111
- const t = e.name.indexOf(":"), n = t === -1 ? "" : e.name.slice(0, t);
112
- return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && r[n] === H;
113
- }
114
- async function x(e, r, t, n) {
115
- let o = !1;
116
- for (let i = 0; i < e.children.length; i++) {
117
- const l = e.children[i];
118
- if (l.type !== "element")
119
- continue;
120
- const s = v(t, l);
121
- if (q(l, s)) {
122
- const f = await z(
123
- l,
124
- r,
125
- s,
126
- n
127
- );
128
- e.children.splice(i, 1, ...f), i += f.length - 1, o = !0;
129
- } else await x(l, r, s, n) && (o = !0);
130
- }
131
- return o;
132
- }
133
- async function z(e, r, t, n) {
134
- const o = n.stack[n.stack.length - 1];
135
- if (e.attributes.xpointer)
136
- throw new Error(
137
- `xi:include with xpointer is not supported by the JS preview build (in ${o})`
138
- );
139
- const i = e.attributes.href;
140
- if (!i)
141
- throw new Error(`xi:include without href (in ${o})`);
142
- let l = i;
143
- try {
144
- l = decodeURIComponent(i);
145
- } catch {
146
- }
147
- const s = c.resolve(r, l);
148
- if (s !== n.projectDir && !s.startsWith(n.projectDir + c.sep))
149
- throw new Error(
150
- `xi:include escapes the project directory: ${i} (in ${o})`
151
- );
152
- if (n.stack.includes(s))
153
- throw new Error(
154
- `Circular xi:include: ${[...n.stack, s].join(" -> ")}`
155
- );
156
- if (n.stack.length >= R)
157
- throw new Error(`xi:include nesting exceeds ${R} levels`);
158
- let f;
159
- try {
160
- f = await m(s, "utf8");
161
- } catch {
162
- const u = ue(e, t);
163
- if (u)
164
- return await x(u, r, t, n), u.children;
165
- throw new Error(`xi:include target not found: ${i} (in ${o})`);
166
- }
167
- if (e.attributes.parse === "text")
168
- return [{ type: "text", value: f }];
169
- let a;
170
- try {
171
- a = $(f);
172
- } catch (u) {
173
- throw new Error(
174
- `Could not parse xi:include target ${s} as XML: ${u instanceof Error ? u.message : u}. (Included files must be well-formed, with a single root element.)`
175
- );
176
- }
177
- n.stack.push(s);
178
- try {
179
- await x(a, c.dirname(s), { "": "" }, n);
180
- } finally {
181
- n.stack.pop();
182
- }
183
- const d = a.children.filter(
184
- (u) => u.type === "element"
185
- );
186
- for (const u of d)
187
- ce(u, s);
188
- return d;
189
- }
190
- function A(e) {
191
- return e.name === "docinfo";
192
- }
193
- async function le(e, r, t) {
194
- try {
195
- const o = $(e).children.find(
196
- (a) => a.type === "element"
197
- );
198
- if (!o)
199
- return;
200
- const i = c.resolve(r), l = c.dirname(i), s = {
201
- projectDir: c.resolve(t),
202
- stack: [i]
203
- }, f = v({ "": "" }, o);
204
- for (const a of o.children) {
205
- if (a.type !== "element")
206
- continue;
207
- const d = v(f, a);
208
- if (A(a))
209
- return await x(a, l, d, s), y(a);
210
- if (q(a, d)) {
211
- const h = (await z(
212
- a,
213
- l,
214
- d,
215
- s
216
- )).find(
217
- (g) => g.type === "element" && A(g)
218
- );
219
- if (h)
220
- return y(h);
221
- continue;
222
- }
223
- break;
224
- }
225
- return;
226
- } catch {
227
- return;
228
- }
229
- }
230
- function ue(e, r) {
231
- for (const t of e.children) {
232
- if (t.type !== "element")
233
- continue;
234
- const n = v(r, t), o = t.name.indexOf(":"), i = o === -1 ? "" : t.name.slice(0, o);
235
- if ((o === -1 ? t.name : t.name.slice(o + 1)) === "fallback" && n[i] === H)
236
- return t;
237
- }
238
- }
239
- function G(e) {
240
- return typeof e == "object" && e !== null && e.type === "element";
241
- }
242
- function fe(e) {
243
- return /^(pf|xhtml):/.test(e.name);
244
- }
245
- function de(e, r, t) {
246
- const n = [], o = e.children.find(G);
247
- if (o) {
248
- const i = t?.parentId ?? "root";
249
- Y(o, i, t?.position ?? 1, r, i, n);
250
- }
251
- return n;
252
- }
253
- function Y(e, r, t, n, o, i) {
254
- const l = ae(e) ?? n;
255
- let s, f;
256
- if (fe(e))
257
- f = "root";
258
- else {
259
- const d = e.attributes.label ?? e.attributes["xml:id"];
260
- s = d ?? `${r}-${t}`, i.push({
261
- id: s,
262
- file: l,
263
- line: e.position?.start.line ?? 1,
264
- column: e.position?.start.column ?? 1,
265
- endLine: e.position?.end.line ?? e.position?.start.line ?? 1,
266
- parent: o
267
- }), f = s;
268
- }
269
- let a = 0;
270
- for (const d of e.children)
271
- G(d) && (a += 1, Y(
272
- d,
273
- f,
274
- a,
275
- l,
276
- s ?? o,
277
- i
278
- ));
279
- }
280
- function De(e, r) {
281
- let t;
282
- for (const n of e)
283
- n.line <= r && (t = n);
284
- return t ?? e[0];
285
- }
286
- function V() {
287
- return process.env.PRETEXT_HTML_ASSETS ?? c.resolve(c.dirname(K(import.meta.url)), "..", "assets");
288
- }
289
- function pe() {
290
- return c.join(V(), "xsl");
291
- }
292
- function he() {
293
- return c.join(V(), "preview-html.xsl");
294
- }
295
- function me() {
296
- return "Suspending" in WebAssembly;
297
- }
298
- function we() {
299
- if (!me())
300
- throw new Error(
301
- "WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
302
- );
303
- }
304
- function U(e) {
305
- return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
306
- }
307
- function ge(e) {
308
- return e.replace(
309
- /from '\.\/(https:\/\/[^']+)'/g,
310
- (r, t) => `from '${t}'`
311
- );
312
- }
313
- function be(e) {
314
- return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
315
- }
316
- async function xe(e, r) {
317
- const t = c.resolve(e);
318
- let n;
319
- try {
320
- n = await m(t, "utf8");
321
- } catch {
322
- return;
323
- }
324
- return le(n, t, r);
325
- }
326
- function ye(e, r, t) {
327
- const n = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = r === "chapter" || r === "part" ? "book" : "article";
328
- return `<pretext>
329
- ${t?.trim() ? `${t.trim()}
330
- ` : ""}<${o}>
331
- <title/>
332
- ${n}
333
- </${o}>
334
- </pretext>
335
- `;
336
- }
337
- function C(e) {
338
- if (e instanceof Error && /memory access|out of bounds/i.test(e.message))
339
- throw new Error(
340
- "The document is too large for the current WebAssembly build (stack overflow). Whole-book builds are a known limitation; try a smaller document, or see the README about rebuilding libxslt-wasm with a larger stack.",
341
- { cause: e }
342
- );
343
- }
344
- let P;
345
- async function Z() {
346
- return P || (P = (async () => {
347
- const [e, r] = await Promise.all([
348
- import("@pretextbook/libxslt-wasm"),
349
- import("@pretextbook/libxslt-wasm/exslt")
350
- ]);
351
- return r.registerAll(), e;
352
- })()), P;
353
- }
354
- const k = /* @__PURE__ */ new Map();
355
- async function ve(e) {
356
- const r = c.resolve(e);
357
- let t = k.get(r);
358
- return t || (t = (async () => {
359
- const { XmlDocument: n, XsltStylesheet: o } = await Z(), i = N(r), l = await m(he(), "utf8"), s = await n.fromString(l, {
360
- url: `${i}/preview-html.xsl`,
361
- options: { noEnt: !0, dtdLoad: !0, huge: !0 }
362
- });
363
- return o.fromXmlDocument(s);
364
- })(), k.set(r, t), t.catch(() => k.delete(r))), t;
365
- }
366
- async function $e(e) {
367
- we();
368
- const { XmlDocument: r } = await Z(), t = await ve(e.xslDir ?? pe()), n = c.resolve(e.sourcePath), o = c.resolve(
369
- e.projectDir ?? c.dirname(n)
370
- ), i = e.sourceContent ?? await m(n, "utf8"), l = c.relative(o, n);
371
- if (l.startsWith(".."))
372
- throw new Error(
373
- `sourcePath (${n}) must live inside projectDir (${o})`
374
- );
375
- const s = N(o);
376
- try {
377
- let f, a = `${s}/__pretext-preview-publication.xml`;
378
- if (e.publicationPath) {
379
- const p = c.resolve(e.publicationPath);
380
- f = L(
381
- await m(p, "utf8")
382
- );
383
- const b = c.relative(o, p);
384
- b.startsWith("..") || (a = `${s}/${b.split(c.sep).join("/")}`);
385
- } else
386
- f = L();
387
- oe(a, f);
388
- let d, u;
389
- if (e.sourceMap) {
390
- const p = await J(
391
- i,
392
- n,
393
- o
394
- );
395
- d = p.tree, u = p.content;
396
- } else
397
- u = await se(
398
- i,
399
- n,
400
- o
401
- );
402
- const h = be(u);
403
- let g = { parentId: "root", position: 1 };
404
- if (h !== "pretext" && h !== "mathbook")
405
- if (e.fragment) {
406
- const p = e.docinfo ?? (e.docinfoSourcePath ? await xe(e.docinfoSourcePath, o) : void 0);
407
- u = ye(u, h, p), g = { parentId: p?.trim() ? "root-1-2" : "root-1-1", position: 2 };
408
- } else
409
- throw new Error(
410
- `The document root is <${h ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
411
- );
412
- const I = d ? de(d, n, g) : void 0, D = await r.fromString(u, {
413
- url: `${s}/${l.split(c.sep).join("/")}`,
414
- options: { noEnt: !0, dtdLoad: !0, huge: !0 }
415
- }), j = {
416
- publisher: U(a)
417
- };
418
- for (const [p, b] of Object.entries(e.stringParams ?? {}))
419
- j[p] = U(b);
420
- let E;
421
- try {
422
- E = await t.apply(D, j);
423
- } catch (p) {
424
- throw C(p), new Error(
425
- "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
426
- { cause: p }
427
- );
428
- } finally {
429
- D.delete();
430
- }
431
- try {
432
- let p = ge(E.toHtmlString());
433
- return e.theme && (p = Q(p, e.theme)), {
434
- html: p,
435
- ...I ? { sourceMap: I } : {}
436
- };
437
- } catch (p) {
438
- throw C(p), p;
439
- } finally {
440
- E.delete();
441
- }
442
- } finally {
443
- ne(s);
444
- }
445
- }
446
- const O = `Usage: pretext-html <source.ptx> [options]
447
-
448
- Render a PreTeXt document to a single standalone HTML page (portable build:
449
- one page, css/js/MathJax from CDN). No PreTeXt installation required.
450
-
451
- Options:
452
- -o, --output <file> Write HTML to a file instead of stdout
453
- --publication <file> Publication file (portable html is forced on)
454
- --project-dir <dir> Directory served to the transform for xi:includes
455
- (default: the source file's directory)
456
- --param <name=value> Extra XSLT string parameter (repeatable)
457
- --xsl-dir <dir> Use PreTeXt stylesheets from this directory
458
- instead of the vendored copy
459
- --fragment Allow a non-root source file: wrap the fragment
460
- in a minimal <pretext> document (an <article>,
461
- or a <book> for <chapter>/<part> fragments)
462
- --docinfo <file> File whose contents (a <docinfo> element) are
463
- injected into the wrapper in --fragment mode, so
464
- the fragment keeps the project's LaTeX macros
465
- --docinfo-source <file> Complete source file (e.g. main.ptx) to lift the
466
- <docinfo> from for --fragment mode, resolving
467
- xi:includes (used when --docinfo is not given)
468
- --source-map <file> Also write a JSON source map: HTML id → source
469
- file/line for every element (for editor sync)
470
- -h, --help Show this help
471
- `;
472
- function Ee(e) {
473
- let r, t, n, o;
474
- const i = {}, l = {};
475
- for (let s = 0; s < e.length; s++) {
476
- const f = e[s], a = () => {
477
- if (s += 1, s >= e.length)
478
- throw new Error(`Missing value for ${f}`);
479
- return e[s];
480
- };
481
- switch (f) {
482
- case "-h":
483
- case "--help":
484
- w.stdout.write(O), w.exit(0);
485
- break;
486
- case "-o":
487
- case "--output":
488
- t = a();
489
- break;
490
- case "--publication":
491
- i.publicationPath = a();
492
- break;
493
- case "--project-dir":
494
- i.projectDir = a();
495
- break;
496
- case "--xsl-dir":
497
- i.xslDir = a();
498
- break;
499
- case "--fragment":
500
- i.fragment = !0;
501
- break;
502
- case "--docinfo":
503
- n = a();
504
- break;
505
- case "--docinfo-source":
506
- i.docinfoSourcePath = a();
507
- break;
508
- case "--source-map":
509
- o = a(), i.sourceMap = !0;
510
- break;
511
- case "--param": {
512
- const d = a(), u = d.indexOf("=");
513
- if (u === -1)
514
- throw new Error(`--param expects name=value, got: ${d}`);
515
- l[d.slice(0, u)] = d.slice(u + 1);
516
- break;
517
- }
518
- default:
519
- if (f.startsWith("-"))
520
- throw new Error(`Unknown option: ${f}`);
521
- if (r)
522
- throw new Error(`Unexpected extra argument: ${f}`);
523
- r = f;
524
- }
525
- }
526
- if (!r)
527
- throw new Error(`No source file given.
528
-
529
- ` + O);
530
- return Object.keys(l).length > 0 && (i.stringParams = l), {
531
- options: { ...i, sourcePath: r },
532
- output: t,
533
- docinfoPath: n,
534
- sourceMapPath: o
535
- };
536
- }
537
- async function je(e) {
538
- const { options: r, output: t, docinfoPath: n, sourceMapPath: o } = Ee(e);
539
- n && (r.docinfo = await m(n, "utf8"));
540
- const i = Date.now(), { html: l, sourceMap: s } = await $e(r);
541
- w.stderr.write(`pretext-html: rendered in ${Date.now() - i}ms
542
- `), o && s && (await X(o, JSON.stringify(s, null, 2)), w.stderr.write(`pretext-html: wrote ${o}
543
- `)), t ? (await X(t, l), w.stderr.write(`pretext-html: wrote ${t}
544
- `)) : w.stdout.write(l);
545
- }
546
- export {
547
- L as a,
548
- pe as d,
549
- De as f,
550
- me as i,
551
- je as m,
552
- Ee as p,
553
- $e as r,
554
- U as x
555
- };