@pretextbook/pretext-html 0.4.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.
- package/README.md +92 -1
- package/assets/preview-html.xsl +14 -0
- package/assets/preview-revealjs.xsl +85 -0
- package/assets/upstream.json +1 -1
- package/assets/xsl/LICENSE-pretext +16 -0
- package/assets/xsl/entities.ent +7 -0
- package/assets/xsl/extract-biblio-csl.xsl +5 -3
- package/assets/xsl/extract-dynamic.xsl +14 -12
- package/assets/xsl/extract-interactive.xsl +2 -2
- package/assets/xsl/extract-pg.xsl +12 -9
- package/assets/xsl/extract-qrcode.xsl +1 -1
- package/assets/xsl/extract-trace.xsl +3 -3
- package/assets/xsl/extract-youtube.xsl +1 -1
- package/assets/xsl/latex/pretext-latex-texstyle.xsl +3 -3
- package/assets/xsl/pretext-assembly.xsl +362 -357
- package/assets/xsl/pretext-braille-preprint.xsl +1 -1
- package/assets/xsl/pretext-common.xsl +101 -90
- package/assets/xsl/pretext-epub.xsl +17 -6
- package/assets/xsl/pretext-fo.xsl +10 -10
- package/assets/xsl/pretext-html.xsl +83 -60
- package/assets/xsl/pretext-latex-common.xsl +8 -8
- package/assets/xsl/pretext-numbers.xsl +35 -35
- package/assets/xsl/pretext-revealjs.xsl +1 -1
- package/assets/xsl/pretext-runestone-fitb.xsl +14 -13
- package/assets/xsl/pretext-runestone-static.xsl +17 -17
- package/assets/xsl/pretext-runestone.xsl +33 -31
- package/assets/xsl/pretext-view-source.xsl +5 -3
- package/assets/xsl/pretext-ww-problem-sets.xsl +6 -1
- package/assets/xsl/publisher-variables.xsl +23 -47
- package/assets/xsl-bundle.json +1 -1
- package/dist/cli-DF7XOWN7.js +724 -0
- package/dist/cli.js +1 -1
- package/dist/index.browser.d.ts +6 -0
- package/dist/index.browser.js +501 -332
- package/dist/index.d.ts +6 -0
- package/dist/index.js +25 -19
- package/dist/knowls.d.ts +43 -0
- package/dist/publication.d.ts +25 -19
- package/dist/renderer.d.ts +61 -0
- package/dist/reveal.d.ts +77 -0
- package/dist/reveal.js +110 -0
- package/dist/target.d.ts +34 -0
- package/package.json +12 -1
- package/dist/cli-Cp6C0sif.js +0 -654
package/dist/cli-Cp6C0sif.js
DELETED
|
@@ -1,654 +0,0 @@
|
|
|
1
|
-
import { readFile as j, writeFile as _ } from "node:fs/promises";
|
|
2
|
-
import * as w from "node:process";
|
|
3
|
-
import * as c from "node:path";
|
|
4
|
-
import { fileURLToPath as fe } from "node:url";
|
|
5
|
-
import { fromXml as v } from "xast-util-from-xml";
|
|
6
|
-
import { toXml as T } from "xast-util-to-xml";
|
|
7
|
-
import { injectThemeBridge as he } from "./theme.js";
|
|
8
|
-
async function Z(e, r) {
|
|
9
|
-
const t = c.resolve(e), n = c.resolve(t, `.${c.posix.normalize(r)}`);
|
|
10
|
-
if (n !== t && !n.startsWith(t + c.sep)) {
|
|
11
|
-
console.error(
|
|
12
|
-
`pretext-html: refusing to serve ${r} from outside ${t}`
|
|
13
|
-
);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
return new Uint8Array(await j(n));
|
|
18
|
-
} catch {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async function F(e) {
|
|
23
|
-
try {
|
|
24
|
-
return await j(e, "utf8");
|
|
25
|
-
} catch {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
let K;
|
|
30
|
-
function Qe(e) {
|
|
31
|
-
K = e;
|
|
32
|
-
}
|
|
33
|
-
function I() {
|
|
34
|
-
return K ?? process.env.PRETEXT_HTML_ASSETS ?? c.resolve(c.dirname(fe(import.meta.url)), "..", "assets");
|
|
35
|
-
}
|
|
36
|
-
function me(e, r) {
|
|
37
|
-
return c.join(e, r);
|
|
38
|
-
}
|
|
39
|
-
const L = /* @__PURE__ */ new Map(), ee = /* @__PURE__ */ new Map();
|
|
40
|
-
let M, pe = 0, te = Z;
|
|
41
|
-
function Ve(e) {
|
|
42
|
-
te = e;
|
|
43
|
-
}
|
|
44
|
-
function we(e, r) {
|
|
45
|
-
const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n = ee.get(t);
|
|
46
|
-
if (n !== void 0)
|
|
47
|
-
return Promise.resolve(new Response(n, { status: 200 }));
|
|
48
|
-
let o;
|
|
49
|
-
try {
|
|
50
|
-
o = new URL(t).host;
|
|
51
|
-
} catch {
|
|
52
|
-
o = "";
|
|
53
|
-
}
|
|
54
|
-
const i = L.get(o);
|
|
55
|
-
return i !== void 0 ? ge(i, t) : M(e, r);
|
|
56
|
-
}
|
|
57
|
-
const be = '<?xml version="1.0"?><pretext-preview-missing-file/>';
|
|
58
|
-
async function ge(e, r) {
|
|
59
|
-
const t = decodeURIComponent(new URL(r).pathname), n = await te(e, t);
|
|
60
|
-
if (n === void 0)
|
|
61
|
-
return new Response(be, { status: 200 });
|
|
62
|
-
const o = typeof n == "string" ? n : new Uint8Array(n);
|
|
63
|
-
return new Response(o, { status: 200 });
|
|
64
|
-
}
|
|
65
|
-
function re() {
|
|
66
|
-
M || (M = globalThis.fetch, globalThis.fetch = we);
|
|
67
|
-
}
|
|
68
|
-
function ne(e) {
|
|
69
|
-
re();
|
|
70
|
-
const r = `mnt${++pe}.ptx.invalid`;
|
|
71
|
-
return L.set(r, e), `http://${r}`;
|
|
72
|
-
}
|
|
73
|
-
function ye(e) {
|
|
74
|
-
L.delete(new URL(e).host);
|
|
75
|
-
}
|
|
76
|
-
function xe(e, r) {
|
|
77
|
-
re(), ee.set(e, r);
|
|
78
|
-
}
|
|
79
|
-
const A = `<?xml version="1.0" encoding="UTF-8"?>
|
|
80
|
-
<publication>
|
|
81
|
-
<source>
|
|
82
|
-
<directories external="../assets" generated="../generated-assets" />
|
|
83
|
-
</source>
|
|
84
|
-
<html>
|
|
85
|
-
<platform portable="yes"/>
|
|
86
|
-
</html>
|
|
87
|
-
</publication>
|
|
88
|
-
`, ve = ["theme", "style", "shell"];
|
|
89
|
-
function b(e, r) {
|
|
90
|
-
for (const t of e.children)
|
|
91
|
-
if (t.type === "element" && t.name === r)
|
|
92
|
-
return t;
|
|
93
|
-
}
|
|
94
|
-
function X(e, r) {
|
|
95
|
-
let t = b(e, r);
|
|
96
|
-
return t || (t = { type: "element", name: r, attributes: {}, children: [] }, e.children.push(t)), t;
|
|
97
|
-
}
|
|
98
|
-
function Ee(e, r) {
|
|
99
|
-
const t = b(e, "css");
|
|
100
|
-
if (t && ve.some((o) => t.attributes?.[o]))
|
|
101
|
-
return;
|
|
102
|
-
const n = t ?? X(e, "css");
|
|
103
|
-
n.attributes = { ...n.attributes, theme: r };
|
|
104
|
-
}
|
|
105
|
-
function Te(e, r) {
|
|
106
|
-
const t = r?.trim();
|
|
107
|
-
if (!e && !t)
|
|
108
|
-
return A;
|
|
109
|
-
const n = v(e ?? A), o = b(n, "publication");
|
|
110
|
-
if (!o)
|
|
111
|
-
throw new Error(
|
|
112
|
-
"Invalid publication file: no root <publication> element found"
|
|
113
|
-
);
|
|
114
|
-
const i = X(o, "html"), a = X(i, "platform");
|
|
115
|
-
return a.attributes = { ...a.attributes, portable: "yes" }, t && Ee(i, t), T(n);
|
|
116
|
-
}
|
|
117
|
-
function H(e) {
|
|
118
|
-
if (!(e === void 0 || e === "" || e.startsWith("/")))
|
|
119
|
-
return e.endsWith("/") ? e : `${e}/`;
|
|
120
|
-
}
|
|
121
|
-
function $e(e) {
|
|
122
|
-
const r = v(e ?? A), t = b(r, "publication"), n = t && b(t, "source"), o = n && b(n, "directories"), i = H(
|
|
123
|
-
o?.attributes?.external ?? void 0
|
|
124
|
-
), a = H(
|
|
125
|
-
o?.attributes?.generated ?? void 0
|
|
126
|
-
);
|
|
127
|
-
return {
|
|
128
|
-
external: i,
|
|
129
|
-
generated: a,
|
|
130
|
-
managed: i !== void 0 && a !== void 0
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
const oe = "http://www.w3.org/2001/XInclude", N = 64;
|
|
134
|
-
async function Pe(e, r, t) {
|
|
135
|
-
return e.includes("include") ? (await ie(e, r, t)).content : e;
|
|
136
|
-
}
|
|
137
|
-
async function ie(e, r, t) {
|
|
138
|
-
const n = v(e), o = {
|
|
139
|
-
projectDir: c.resolve(t),
|
|
140
|
-
stack: [c.resolve(r)]
|
|
141
|
-
}, i = await x(
|
|
142
|
-
n,
|
|
143
|
-
c.dirname(c.resolve(r)),
|
|
144
|
-
{ "": "" },
|
|
145
|
-
o
|
|
146
|
-
);
|
|
147
|
-
return { tree: n, content: i ? T(n) : e };
|
|
148
|
-
}
|
|
149
|
-
function ke(e) {
|
|
150
|
-
return e.data?.ptxIncludedFile;
|
|
151
|
-
}
|
|
152
|
-
function Se(e, r) {
|
|
153
|
-
const t = e.data ?? (e.data = {});
|
|
154
|
-
t.ptxIncludedFile = r;
|
|
155
|
-
}
|
|
156
|
-
function $(e, r) {
|
|
157
|
-
let t = e;
|
|
158
|
-
for (const [n, o] of Object.entries(r.attributes))
|
|
159
|
-
(n === "xmlns" || n.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[n === "xmlns" ? "" : n.slice(6)] = o ?? "");
|
|
160
|
-
return t;
|
|
161
|
-
}
|
|
162
|
-
function se(e, r) {
|
|
163
|
-
const t = e.name.indexOf(":"), n = t === -1 ? "" : e.name.slice(0, t);
|
|
164
|
-
return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && r[n] === oe;
|
|
165
|
-
}
|
|
166
|
-
async function x(e, r, t, n) {
|
|
167
|
-
let o = !1;
|
|
168
|
-
for (let i = 0; i < e.children.length; i++) {
|
|
169
|
-
const a = e.children[i];
|
|
170
|
-
if (a.type !== "element")
|
|
171
|
-
continue;
|
|
172
|
-
const s = $(t, a);
|
|
173
|
-
if (se(a, s)) {
|
|
174
|
-
const u = await ae(
|
|
175
|
-
a,
|
|
176
|
-
r,
|
|
177
|
-
s,
|
|
178
|
-
n
|
|
179
|
-
);
|
|
180
|
-
e.children.splice(i, 1, ...u), i += u.length - 1, o = !0;
|
|
181
|
-
} else await x(a, r, s, n) && (o = !0);
|
|
182
|
-
}
|
|
183
|
-
return o;
|
|
184
|
-
}
|
|
185
|
-
async function ae(e, r, t, n) {
|
|
186
|
-
const o = n.stack[n.stack.length - 1];
|
|
187
|
-
if (e.attributes.xpointer)
|
|
188
|
-
throw new Error(
|
|
189
|
-
`xi:include with xpointer is not supported by the JS preview build (in ${o})`
|
|
190
|
-
);
|
|
191
|
-
const i = e.attributes.href;
|
|
192
|
-
if (!i)
|
|
193
|
-
throw new Error(`xi:include without href (in ${o})`);
|
|
194
|
-
let a = i;
|
|
195
|
-
try {
|
|
196
|
-
a = decodeURIComponent(i);
|
|
197
|
-
} catch {
|
|
198
|
-
}
|
|
199
|
-
const s = c.resolve(r, a);
|
|
200
|
-
if (s !== n.projectDir && !s.startsWith(n.projectDir + c.sep))
|
|
201
|
-
throw new Error(
|
|
202
|
-
`xi:include escapes the project directory: ${i} (in ${o})`
|
|
203
|
-
);
|
|
204
|
-
if (n.stack.includes(s))
|
|
205
|
-
throw new Error(
|
|
206
|
-
`Circular xi:include: ${[...n.stack, s].join(" -> ")}`
|
|
207
|
-
);
|
|
208
|
-
if (n.stack.length >= N)
|
|
209
|
-
throw new Error(`xi:include nesting exceeds ${N} levels`);
|
|
210
|
-
const u = await F(s);
|
|
211
|
-
if (u === void 0) {
|
|
212
|
-
const d = Ie(e, t);
|
|
213
|
-
if (d)
|
|
214
|
-
return await x(d, r, t, n), d.children;
|
|
215
|
-
throw new Error(`xi:include target not found: ${i} (in ${o})`);
|
|
216
|
-
}
|
|
217
|
-
if (e.attributes.parse === "text")
|
|
218
|
-
return [{ type: "text", value: u }];
|
|
219
|
-
let l;
|
|
220
|
-
try {
|
|
221
|
-
l = v(u);
|
|
222
|
-
} catch (d) {
|
|
223
|
-
throw new Error(
|
|
224
|
-
`Could not parse xi:include target ${s} as XML: ${d instanceof Error ? d.message : d}. (Included files must be well-formed, with a single root element.)`
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
n.stack.push(s);
|
|
228
|
-
try {
|
|
229
|
-
await x(l, c.dirname(s), { "": "" }, n);
|
|
230
|
-
} finally {
|
|
231
|
-
n.stack.pop();
|
|
232
|
-
}
|
|
233
|
-
const f = l.children.filter(
|
|
234
|
-
(d) => d.type === "element"
|
|
235
|
-
);
|
|
236
|
-
for (const d of f)
|
|
237
|
-
Se(d, s);
|
|
238
|
-
return f;
|
|
239
|
-
}
|
|
240
|
-
function J(e) {
|
|
241
|
-
return e.name === "docinfo";
|
|
242
|
-
}
|
|
243
|
-
async function De(e, r, t) {
|
|
244
|
-
try {
|
|
245
|
-
const o = v(e).children.find(
|
|
246
|
-
(l) => l.type === "element"
|
|
247
|
-
);
|
|
248
|
-
if (!o)
|
|
249
|
-
return;
|
|
250
|
-
const i = c.resolve(r), a = c.dirname(i), s = {
|
|
251
|
-
projectDir: c.resolve(t),
|
|
252
|
-
stack: [i]
|
|
253
|
-
}, u = $({ "": "" }, o);
|
|
254
|
-
for (const l of o.children) {
|
|
255
|
-
if (l.type !== "element")
|
|
256
|
-
continue;
|
|
257
|
-
const f = $(u, l);
|
|
258
|
-
if (J(l))
|
|
259
|
-
return await x(l, a, f, s), T(l);
|
|
260
|
-
if (se(l, f)) {
|
|
261
|
-
const g = (await ae(
|
|
262
|
-
l,
|
|
263
|
-
a,
|
|
264
|
-
f,
|
|
265
|
-
s
|
|
266
|
-
)).find(
|
|
267
|
-
(m) => m.type === "element" && J(m)
|
|
268
|
-
);
|
|
269
|
-
if (g)
|
|
270
|
-
return T(g);
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
return;
|
|
276
|
-
} catch {
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
function Ie(e, r) {
|
|
281
|
-
for (const t of e.children) {
|
|
282
|
-
if (t.type !== "element")
|
|
283
|
-
continue;
|
|
284
|
-
const n = $(r, t), o = t.name.indexOf(":"), i = o === -1 ? "" : t.name.slice(0, o);
|
|
285
|
-
if ((o === -1 ? t.name : t.name.slice(o + 1)) === "fallback" && n[i] === oe)
|
|
286
|
-
return t;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
function ce(e) {
|
|
290
|
-
return typeof e == "object" && e !== null && e.type === "element";
|
|
291
|
-
}
|
|
292
|
-
function Me(e) {
|
|
293
|
-
return /^(pf|xhtml):/.test(e.name);
|
|
294
|
-
}
|
|
295
|
-
function Ae(e, r, t) {
|
|
296
|
-
const n = [], o = e.children.find(ce);
|
|
297
|
-
if (o) {
|
|
298
|
-
const i = t?.parentId ?? "root";
|
|
299
|
-
le(o, i, t?.position ?? 1, r, i, n);
|
|
300
|
-
}
|
|
301
|
-
return n;
|
|
302
|
-
}
|
|
303
|
-
function le(e, r, t, n, o, i) {
|
|
304
|
-
const a = ke(e) ?? n;
|
|
305
|
-
let s, u;
|
|
306
|
-
if (Me(e))
|
|
307
|
-
u = "root";
|
|
308
|
-
else {
|
|
309
|
-
const f = e.attributes.label ?? e.attributes["xml:id"];
|
|
310
|
-
s = f ?? `${r}-${t}`, i.push({
|
|
311
|
-
id: s,
|
|
312
|
-
file: a,
|
|
313
|
-
line: e.position?.start.line ?? 1,
|
|
314
|
-
column: e.position?.start.column ?? 1,
|
|
315
|
-
endLine: e.position?.end.line ?? e.position?.start.line ?? 1,
|
|
316
|
-
parent: o
|
|
317
|
-
}), u = s;
|
|
318
|
-
}
|
|
319
|
-
let l = 0;
|
|
320
|
-
for (const f of e.children)
|
|
321
|
-
ce(f) && (l += 1, le(
|
|
322
|
-
f,
|
|
323
|
-
u,
|
|
324
|
-
l,
|
|
325
|
-
a,
|
|
326
|
-
s ?? o,
|
|
327
|
-
i
|
|
328
|
-
));
|
|
329
|
-
}
|
|
330
|
-
function Ze(e, r) {
|
|
331
|
-
let t;
|
|
332
|
-
for (const n of e)
|
|
333
|
-
n.line <= r && (t = n);
|
|
334
|
-
return t ?? e[0];
|
|
335
|
-
}
|
|
336
|
-
function Xe() {
|
|
337
|
-
return me(I(), "xsl");
|
|
338
|
-
}
|
|
339
|
-
function je() {
|
|
340
|
-
return "Suspending" in WebAssembly;
|
|
341
|
-
}
|
|
342
|
-
function Fe() {
|
|
343
|
-
if (!je())
|
|
344
|
-
throw new Error(
|
|
345
|
-
"WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
function z(e) {
|
|
349
|
-
return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
|
|
350
|
-
}
|
|
351
|
-
function Le(e) {
|
|
352
|
-
return e.replace(
|
|
353
|
-
/from '\.\/(https:\/\/[^']+)'/g,
|
|
354
|
-
(r, t) => `from '${t}'`
|
|
355
|
-
);
|
|
356
|
-
}
|
|
357
|
-
function Re(e) {
|
|
358
|
-
return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
|
|
359
|
-
}
|
|
360
|
-
async function q(e) {
|
|
361
|
-
const r = await F(e);
|
|
362
|
-
if (r === void 0)
|
|
363
|
-
throw new Error(
|
|
364
|
-
`Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
|
|
365
|
-
);
|
|
366
|
-
return r;
|
|
367
|
-
}
|
|
368
|
-
async function Ue(e, r) {
|
|
369
|
-
const t = c.resolve(e), n = await F(t);
|
|
370
|
-
if (n !== void 0)
|
|
371
|
-
return De(n, t, r);
|
|
372
|
-
}
|
|
373
|
-
function Ce(e, r, t) {
|
|
374
|
-
const n = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = r === "chapter" || r === "part" ? "book" : "article";
|
|
375
|
-
return `<pretext>
|
|
376
|
-
${t?.trim() ? `${t.trim()}
|
|
377
|
-
` : ""}<${o}>
|
|
378
|
-
<title/>
|
|
379
|
-
${n}
|
|
380
|
-
</${o}>
|
|
381
|
-
</pretext>
|
|
382
|
-
`;
|
|
383
|
-
}
|
|
384
|
-
let ue = !1;
|
|
385
|
-
function We(e) {
|
|
386
|
-
return e instanceof Error && /\bAborted\(/.test(e.message);
|
|
387
|
-
}
|
|
388
|
-
function Be(e) {
|
|
389
|
-
return e instanceof Error && /memory access|out of bounds/i.test(e.message);
|
|
390
|
-
}
|
|
391
|
-
function Oe() {
|
|
392
|
-
if (ue)
|
|
393
|
-
throw new Error(
|
|
394
|
-
"The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
|
|
395
|
-
);
|
|
396
|
-
}
|
|
397
|
-
function G(e) {
|
|
398
|
-
if (We(e))
|
|
399
|
-
throw ue = !0, new Error(
|
|
400
|
-
"The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
|
|
401
|
-
{ cause: e }
|
|
402
|
-
);
|
|
403
|
-
if (Be(e))
|
|
404
|
-
throw new Error(
|
|
405
|
-
"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.",
|
|
406
|
-
{ cause: e }
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
let S;
|
|
410
|
-
async function de() {
|
|
411
|
-
return S || (S = (async () => {
|
|
412
|
-
const [e, r] = await Promise.all([
|
|
413
|
-
import("@pretextbook/libxslt-wasm"),
|
|
414
|
-
import("@pretextbook/libxslt-wasm/exslt")
|
|
415
|
-
]);
|
|
416
|
-
return r.registerAll(), e;
|
|
417
|
-
})()), S;
|
|
418
|
-
}
|
|
419
|
-
const D = /* @__PURE__ */ new Map();
|
|
420
|
-
async function _e(e) {
|
|
421
|
-
const r = e;
|
|
422
|
-
let t = D.get(r);
|
|
423
|
-
return t || (t = (async () => {
|
|
424
|
-
const { XmlDocument: n, XsltStylesheet: o } = await de(), i = ne(r), a = await Z(
|
|
425
|
-
I(),
|
|
426
|
-
"/preview-html.xsl"
|
|
427
|
-
);
|
|
428
|
-
if (a === void 0)
|
|
429
|
-
throw new Error(
|
|
430
|
-
`Could not read preview-html.xsl from ${I()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
|
|
431
|
-
);
|
|
432
|
-
const s = new TextDecoder().decode(a), u = await n.fromString(s, {
|
|
433
|
-
url: `${i}/preview-html.xsl`,
|
|
434
|
-
options: { noEnt: !0, dtdLoad: !0, huge: !0 }
|
|
435
|
-
});
|
|
436
|
-
return o.fromXmlDocument(u);
|
|
437
|
-
})(), D.set(r, t), t.catch(() => D.delete(r))), t;
|
|
438
|
-
}
|
|
439
|
-
let Y = Promise.resolve();
|
|
440
|
-
function He(e) {
|
|
441
|
-
const r = Y.then(
|
|
442
|
-
() => Q(e),
|
|
443
|
-
() => Q(e)
|
|
444
|
-
);
|
|
445
|
-
return Y = r.catch(() => {
|
|
446
|
-
}), r;
|
|
447
|
-
}
|
|
448
|
-
async function Q(e) {
|
|
449
|
-
Fe(), Oe();
|
|
450
|
-
const { XmlDocument: r } = await de(), t = await _e(e.xslDir ?? Xe()), n = c.resolve(e.sourcePath), o = c.resolve(
|
|
451
|
-
e.projectDir ?? c.dirname(n)
|
|
452
|
-
), i = e.sourceContent ?? await q(n), a = c.relative(o, n);
|
|
453
|
-
if (a.startsWith(".."))
|
|
454
|
-
throw new Error(
|
|
455
|
-
`sourcePath (${n}) must live inside projectDir (${o})`
|
|
456
|
-
);
|
|
457
|
-
const s = c.relative(
|
|
458
|
-
o,
|
|
459
|
-
c.resolve(e.mainSourcePath ?? n)
|
|
460
|
-
), u = s.startsWith("..") ? a : s, l = ne(o);
|
|
461
|
-
try {
|
|
462
|
-
let f, d = `${l}/__pretext-preview-publication.xml`;
|
|
463
|
-
if (e.publicationPath) {
|
|
464
|
-
const h = c.resolve(e.publicationPath);
|
|
465
|
-
f = await q(h);
|
|
466
|
-
const y = c.relative(o, h);
|
|
467
|
-
y.startsWith("..") || (d = `${l}/${y.split(c.sep).join("/")}`);
|
|
468
|
-
}
|
|
469
|
-
const g = Te(
|
|
470
|
-
f,
|
|
471
|
-
e.cssTheme
|
|
472
|
-
);
|
|
473
|
-
xe(d, g);
|
|
474
|
-
const m = $e(g), R = c.dirname(c.resolve(o, u)), U = m.external !== void 0 && m.generated !== void 0 ? {
|
|
475
|
-
external: c.resolve(R, m.external),
|
|
476
|
-
generated: c.resolve(R, m.generated)
|
|
477
|
-
} : void 0;
|
|
478
|
-
let P, p;
|
|
479
|
-
if (e.sourceMap) {
|
|
480
|
-
const h = await ie(
|
|
481
|
-
i,
|
|
482
|
-
n,
|
|
483
|
-
o
|
|
484
|
-
);
|
|
485
|
-
P = h.tree, p = h.content;
|
|
486
|
-
} else
|
|
487
|
-
p = await Pe(
|
|
488
|
-
i,
|
|
489
|
-
n,
|
|
490
|
-
o
|
|
491
|
-
);
|
|
492
|
-
const E = Re(p);
|
|
493
|
-
let C = { parentId: "root", position: 1 };
|
|
494
|
-
if (E !== "pretext" && E !== "mathbook")
|
|
495
|
-
if (e.fragment) {
|
|
496
|
-
const h = e.docinfo ?? (e.docinfoSourcePath ? await Ue(e.docinfoSourcePath, o) : void 0);
|
|
497
|
-
p = Ce(p, E, h), C = { parentId: h?.trim() ? "root-1-2" : "root-1-1", position: 2 };
|
|
498
|
-
} else
|
|
499
|
-
throw new Error(
|
|
500
|
-
`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.`
|
|
501
|
-
);
|
|
502
|
-
const W = P ? Ae(P, n, C) : void 0, B = await r.fromString(p, {
|
|
503
|
-
url: `${l}/${u.split(c.sep).join("/")}`,
|
|
504
|
-
options: { noEnt: !0, dtdLoad: !0, huge: !0 }
|
|
505
|
-
}), O = {
|
|
506
|
-
publisher: z(d)
|
|
507
|
-
};
|
|
508
|
-
for (const [h, y] of Object.entries(e.stringParams ?? {}))
|
|
509
|
-
O[h] = z(y);
|
|
510
|
-
let k;
|
|
511
|
-
try {
|
|
512
|
-
k = await t.apply(B, O);
|
|
513
|
-
} catch (h) {
|
|
514
|
-
throw G(h), new Error(
|
|
515
|
-
"PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
|
|
516
|
-
{ cause: h }
|
|
517
|
-
);
|
|
518
|
-
} finally {
|
|
519
|
-
B.delete();
|
|
520
|
-
}
|
|
521
|
-
try {
|
|
522
|
-
let h = Le(k.toHtmlString());
|
|
523
|
-
return e.theme && (h = he(h, e.theme)), {
|
|
524
|
-
html: h,
|
|
525
|
-
...W ? { sourceMap: W } : {},
|
|
526
|
-
...U ? { assetDirs: U } : {}
|
|
527
|
-
};
|
|
528
|
-
} catch (h) {
|
|
529
|
-
throw G(h), h;
|
|
530
|
-
} finally {
|
|
531
|
-
k.delete();
|
|
532
|
-
}
|
|
533
|
-
} finally {
|
|
534
|
-
ye(l);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
const V = `Usage: pretext-html <source.ptx> [options]
|
|
538
|
-
|
|
539
|
-
Render a PreTeXt document to a single standalone HTML page (portable build:
|
|
540
|
-
one page, css/js/MathJax from CDN). No PreTeXt installation required.
|
|
541
|
-
|
|
542
|
-
Options:
|
|
543
|
-
-o, --output <file> Write HTML to a file instead of stdout
|
|
544
|
-
--publication <file> Publication file (portable html is forced on)
|
|
545
|
-
--css-theme <name> HTML theme to use when the publication file names
|
|
546
|
-
none of its own: default-modern (PreTeXt's default),
|
|
547
|
-
denver, tacoma, salem, greeley or boulder
|
|
548
|
-
--project-dir <dir> Directory served to the transform for xi:includes
|
|
549
|
-
(default: the source file's directory)
|
|
550
|
-
--param <name=value> Extra XSLT string parameter (repeatable)
|
|
551
|
-
--xsl-dir <dir> Use PreTeXt stylesheets from this directory
|
|
552
|
-
instead of the vendored copy
|
|
553
|
-
--fragment Allow a non-root source file: wrap the fragment
|
|
554
|
-
in a minimal <pretext> document (an <article>,
|
|
555
|
-
or a <book> for <chapter>/<part> fragments)
|
|
556
|
-
--docinfo <file> File whose contents (a <docinfo> element) are
|
|
557
|
-
injected into the wrapper in --fragment mode, so
|
|
558
|
-
the fragment keeps the project's LaTeX macros
|
|
559
|
-
--docinfo-source <file> Complete source file (e.g. main.ptx) to lift the
|
|
560
|
-
<docinfo> from for --fragment mode, resolving
|
|
561
|
-
xi:includes (used when --docinfo is not given)
|
|
562
|
-
--source-map <file> Also write a JSON source map: HTML id → source
|
|
563
|
-
file/line for every element (for editor sync)
|
|
564
|
-
-h, --help Show this help
|
|
565
|
-
`;
|
|
566
|
-
function Ne(e) {
|
|
567
|
-
let r, t, n, o;
|
|
568
|
-
const i = {}, a = {};
|
|
569
|
-
for (let s = 0; s < e.length; s++) {
|
|
570
|
-
const u = e[s], l = () => {
|
|
571
|
-
if (s += 1, s >= e.length)
|
|
572
|
-
throw new Error(`Missing value for ${u}`);
|
|
573
|
-
return e[s];
|
|
574
|
-
};
|
|
575
|
-
switch (u) {
|
|
576
|
-
case "-h":
|
|
577
|
-
case "--help":
|
|
578
|
-
w.stdout.write(V), w.exit(0);
|
|
579
|
-
break;
|
|
580
|
-
case "-o":
|
|
581
|
-
case "--output":
|
|
582
|
-
t = l();
|
|
583
|
-
break;
|
|
584
|
-
case "--publication":
|
|
585
|
-
i.publicationPath = l();
|
|
586
|
-
break;
|
|
587
|
-
case "--css-theme":
|
|
588
|
-
i.cssTheme = l();
|
|
589
|
-
break;
|
|
590
|
-
case "--project-dir":
|
|
591
|
-
i.projectDir = l();
|
|
592
|
-
break;
|
|
593
|
-
case "--xsl-dir":
|
|
594
|
-
i.xslDir = l();
|
|
595
|
-
break;
|
|
596
|
-
case "--fragment":
|
|
597
|
-
i.fragment = !0;
|
|
598
|
-
break;
|
|
599
|
-
case "--docinfo":
|
|
600
|
-
n = l();
|
|
601
|
-
break;
|
|
602
|
-
case "--docinfo-source":
|
|
603
|
-
i.docinfoSourcePath = l();
|
|
604
|
-
break;
|
|
605
|
-
case "--source-map":
|
|
606
|
-
o = l(), i.sourceMap = !0;
|
|
607
|
-
break;
|
|
608
|
-
case "--param": {
|
|
609
|
-
const f = l(), d = f.indexOf("=");
|
|
610
|
-
if (d === -1)
|
|
611
|
-
throw new Error(`--param expects name=value, got: ${f}`);
|
|
612
|
-
a[f.slice(0, d)] = f.slice(d + 1);
|
|
613
|
-
break;
|
|
614
|
-
}
|
|
615
|
-
default:
|
|
616
|
-
if (u.startsWith("-"))
|
|
617
|
-
throw new Error(`Unknown option: ${u}`);
|
|
618
|
-
if (r)
|
|
619
|
-
throw new Error(`Unexpected extra argument: ${u}`);
|
|
620
|
-
r = u;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
if (!r)
|
|
624
|
-
throw new Error(`No source file given.
|
|
625
|
-
|
|
626
|
-
` + V);
|
|
627
|
-
return Object.keys(a).length > 0 && (i.stringParams = a), {
|
|
628
|
-
options: { ...i, sourcePath: r },
|
|
629
|
-
output: t,
|
|
630
|
-
docinfoPath: n,
|
|
631
|
-
sourceMapPath: o
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
async function Ke(e) {
|
|
635
|
-
const { options: r, output: t, docinfoPath: n, sourceMapPath: o } = Ne(e);
|
|
636
|
-
n && (r.docinfo = await j(n, "utf8"));
|
|
637
|
-
const i = Date.now(), { html: a, sourceMap: s } = await He(r);
|
|
638
|
-
w.stderr.write(`pretext-html: rendered in ${Date.now() - i}ms
|
|
639
|
-
`), o && s && (await _(o, JSON.stringify(s, null, 2)), w.stderr.write(`pretext-html: wrote ${o}
|
|
640
|
-
`)), t ? (await _(t, a), w.stderr.write(`pretext-html: wrote ${t}
|
|
641
|
-
`)) : w.stdout.write(a);
|
|
642
|
-
}
|
|
643
|
-
export {
|
|
644
|
-
Te as a,
|
|
645
|
-
Ve as b,
|
|
646
|
-
Xe as d,
|
|
647
|
-
Ze as f,
|
|
648
|
-
je as i,
|
|
649
|
-
Ke as m,
|
|
650
|
-
Ne as p,
|
|
651
|
-
He as r,
|
|
652
|
-
Qe as s,
|
|
653
|
-
z as x
|
|
654
|
-
};
|