@pretextbook/pretext-html 0.7.0 → 0.8.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 +31 -2
- package/assets/upstream.json +1 -1
- package/assets/xsl/README.md +25 -24
- package/assets/xsl/entities.ent +11 -0
- package/assets/xsl/localizations/README.md +24 -24
- package/assets/xsl/pretext-assembly.xsl +2 -6
- package/assets/xsl/pretext-common.xsl +19 -2
- package/assets/xsl/pretext-epub.xsl +4 -1
- package/assets/xsl/pretext-fo.xsl +17 -19
- package/assets/xsl/pretext-html.xsl +203 -40
- package/assets/xsl/pretext-latex-common.xsl +28 -17
- package/assets/xsl/pretext-revealjs.xsl +1 -3
- package/assets/xsl/pretext-runestone.xsl +5 -21
- package/assets/xsl/publisher-variables.xsl +70 -111
- package/assets/xsl/support/play-button/README.md +1 -3
- package/assets/xsl/tests/README.md +1 -1
- package/assets/xsl/utilities/README.md +6 -8
- package/assets/xsl-bundle.json +1 -1
- package/dist/{cli-D0m0Ha1j.js → cli-Bcn4t3B1.js} +233 -218
- package/dist/cli.js +1 -1
- package/dist/html-static.d.ts +20 -0
- package/dist/index.browser.js +265 -250
- package/dist/index.js +1 -1
- package/dist/renderer.d.ts +5 -1
- package/package.json +2 -1
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { readFile as
|
|
2
|
-
import * as
|
|
1
|
+
import { readFile as M, writeFile as W } from "node:fs/promises";
|
|
2
|
+
import * as v from "node:process";
|
|
3
3
|
import * as l from "node:path";
|
|
4
|
-
import { fileURLToPath as
|
|
4
|
+
import { fileURLToPath as we } from "node:url";
|
|
5
5
|
import { fromXml as y } from "xast-util-from-xml";
|
|
6
|
-
import { toXml as
|
|
7
|
-
import { injectRevealBridge as
|
|
8
|
-
import { injectThemeBridge as
|
|
9
|
-
const ge = "ptxPreviewBannerDismissed",
|
|
10
|
-
function
|
|
6
|
+
import { toXml as S } from "xast-util-to-xml";
|
|
7
|
+
import { injectRevealBridge as be } from "./reveal.js";
|
|
8
|
+
import { injectThemeBridge as ve } from "./theme.js";
|
|
9
|
+
const ge = "ptxPreviewBannerDismissed", xe = "About live preview";
|
|
10
|
+
function H(e) {
|
|
11
11
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function ye(e) {
|
|
14
14
|
return [
|
|
15
15
|
'<div id="ptx-preview-banner" class="ptx-preview-banner" role="note">',
|
|
16
|
-
` <span class="ptx-preview-banner-text">${
|
|
16
|
+
` <span class="ptx-preview-banner-text">${H(e)}</span>`,
|
|
17
17
|
' <button type="button" class="ptx-preview-banner-dismiss" aria-label="Dismiss">×</button>',
|
|
18
18
|
"</div>",
|
|
19
|
-
`<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${
|
|
19
|
+
`<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${H(xe)}</button>`
|
|
20
20
|
].join(`
|
|
21
21
|
`);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function Ee() {
|
|
24
24
|
return [
|
|
25
25
|
"<style>",
|
|
26
26
|
".ptx-preview-banner {",
|
|
@@ -81,7 +81,7 @@ function ye() {
|
|
|
81
81
|
].join(`
|
|
82
82
|
`);
|
|
83
83
|
}
|
|
84
|
-
function
|
|
84
|
+
function Te() {
|
|
85
85
|
return [
|
|
86
86
|
"<script>",
|
|
87
87
|
"(function () {",
|
|
@@ -122,16 +122,16 @@ function Ee() {
|
|
|
122
122
|
].join(`
|
|
123
123
|
`);
|
|
124
124
|
}
|
|
125
|
-
const
|
|
126
|
-
function
|
|
127
|
-
const t =
|
|
125
|
+
const Se = "<!--ptx-preview-banner-->", $e = "<!--/ptx-preview-banner-->", ke = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
|
|
126
|
+
function Pe(e, r) {
|
|
127
|
+
const t = ke.exec(e), n = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
|
|
128
128
|
if (!/<body[^>]*>/i.test(n))
|
|
129
129
|
return n;
|
|
130
130
|
const o = `
|
|
131
|
-
${
|
|
132
|
-
${ye()}
|
|
133
|
-
${xe(r.message)}
|
|
131
|
+
${Se}
|
|
134
132
|
${Ee()}
|
|
133
|
+
${ye(r.message)}
|
|
134
|
+
${Te()}
|
|
135
135
|
${$e}`;
|
|
136
136
|
return n.replace(/<body([^>]*)>/i, `<body$1>${o}`);
|
|
137
137
|
}
|
|
@@ -144,57 +144,64 @@ async function ee(e, r) {
|
|
|
144
144
|
return;
|
|
145
145
|
}
|
|
146
146
|
try {
|
|
147
|
-
return new Uint8Array(await
|
|
147
|
+
return new Uint8Array(await M(n));
|
|
148
148
|
} catch {
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
-
async function
|
|
152
|
+
async function B(e) {
|
|
153
153
|
try {
|
|
154
|
-
return await
|
|
154
|
+
return await M(e, "utf8");
|
|
155
155
|
} catch {
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
let te;
|
|
160
|
-
function
|
|
160
|
+
function kt(e) {
|
|
161
161
|
te = e;
|
|
162
162
|
}
|
|
163
|
-
function
|
|
164
|
-
return te ?? process.env.PRETEXT_HTML_ASSETS ?? l.resolve(l.dirname(
|
|
163
|
+
function j() {
|
|
164
|
+
return te ?? process.env.PRETEXT_HTML_ASSETS ?? l.resolve(l.dirname(we(import.meta.url)), "..", "assets");
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function Ie(e, r) {
|
|
167
167
|
return l.join(e, r);
|
|
168
168
|
}
|
|
169
|
-
const De = "
|
|
170
|
-
|
|
169
|
+
const re = "2.46.0", De = "8.2.1", Re = [
|
|
170
|
+
"prefix-runtime.ed2cce180827a7ad.bundle.js",
|
|
171
|
+
"prefix-926.5c7038c8ef173faf.bundle.js",
|
|
172
|
+
"prefix-runestone.1f660864c47fc762.bundle.js"
|
|
173
|
+
], je = [
|
|
174
|
+
"prefix-926.229729d09512acc9.css",
|
|
175
|
+
"prefix-runestone.8086b62682b271d1.css"
|
|
176
|
+
], Le = "born-hidden-knowl", Ae = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
|
|
177
|
+
function Me(e) {
|
|
171
178
|
const r = /\bclass="([^"]*)"/.exec(e);
|
|
172
179
|
return r ? r[1].trim().split(/\s+/) : [];
|
|
173
180
|
}
|
|
174
|
-
function
|
|
181
|
+
function Be(e) {
|
|
175
182
|
return /(^|\s)open(\s|=|$)/.test(e);
|
|
176
183
|
}
|
|
177
|
-
function
|
|
178
|
-
return
|
|
184
|
+
function J(e) {
|
|
185
|
+
return Be(e) ? e : ` open${e}`;
|
|
179
186
|
}
|
|
180
|
-
function
|
|
187
|
+
function _e(e) {
|
|
181
188
|
return e.replace(
|
|
182
|
-
|
|
189
|
+
Ae,
|
|
183
190
|
(r, t, n, o) => {
|
|
184
|
-
if (!
|
|
191
|
+
if (!Me(t).includes(Le))
|
|
185
192
|
return r;
|
|
186
|
-
const s = `<details${
|
|
187
|
-
return o === void 0 ? `${s}${n}` : `${s}${n}<summary${
|
|
193
|
+
const s = `<details${J(t)}>`;
|
|
194
|
+
return o === void 0 ? `${s}${n}` : `${s}${n}<summary${J(o)}>`;
|
|
188
195
|
}
|
|
189
196
|
);
|
|
190
197
|
}
|
|
191
|
-
const
|
|
192
|
-
let L,
|
|
193
|
-
function
|
|
194
|
-
|
|
198
|
+
const _ = /* @__PURE__ */ new Map(), ne = /* @__PURE__ */ new Map();
|
|
199
|
+
let L, Ce = 0, oe = ee;
|
|
200
|
+
function Pt(e) {
|
|
201
|
+
oe = e;
|
|
195
202
|
}
|
|
196
|
-
function
|
|
197
|
-
const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n =
|
|
203
|
+
function Oe(e, r) {
|
|
204
|
+
const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n = ne.get(t);
|
|
198
205
|
if (n !== void 0)
|
|
199
206
|
return Promise.resolve(new Response(n, { status: 200 }));
|
|
200
207
|
let o;
|
|
@@ -203,32 +210,32 @@ function Be(e, r) {
|
|
|
203
210
|
} catch {
|
|
204
211
|
o = "";
|
|
205
212
|
}
|
|
206
|
-
const s =
|
|
207
|
-
return s !== void 0 ?
|
|
213
|
+
const s = _.get(o);
|
|
214
|
+
return s !== void 0 ? Ne(s, t) : L(e, r);
|
|
208
215
|
}
|
|
209
|
-
const
|
|
210
|
-
async function
|
|
211
|
-
const t = decodeURIComponent(new URL(r).pathname), n = await
|
|
216
|
+
const Xe = '<?xml version="1.0"?><pretext-preview-missing-file/>';
|
|
217
|
+
async function Ne(e, r) {
|
|
218
|
+
const t = decodeURIComponent(new URL(r).pathname), n = await oe(e, t);
|
|
212
219
|
if (n === void 0)
|
|
213
|
-
return new Response(
|
|
220
|
+
return new Response(Xe, { status: 200 });
|
|
214
221
|
const o = typeof n == "string" ? n : new Uint8Array(n);
|
|
215
222
|
return new Response(o, { status: 200 });
|
|
216
223
|
}
|
|
217
|
-
function
|
|
218
|
-
L || (L = globalThis.fetch, globalThis.fetch =
|
|
224
|
+
function se() {
|
|
225
|
+
L || (L = globalThis.fetch, globalThis.fetch = Oe);
|
|
219
226
|
}
|
|
220
|
-
function
|
|
221
|
-
|
|
222
|
-
const r = `mnt${++
|
|
223
|
-
return
|
|
227
|
+
function ie(e) {
|
|
228
|
+
se();
|
|
229
|
+
const r = `mnt${++Ce}.ptx.invalid`;
|
|
230
|
+
return _.set(r, e), `http://${r}`;
|
|
224
231
|
}
|
|
225
|
-
function
|
|
226
|
-
|
|
232
|
+
function Fe(e) {
|
|
233
|
+
_.delete(new URL(e).host);
|
|
227
234
|
}
|
|
228
|
-
function
|
|
229
|
-
|
|
235
|
+
function Ue(e, r) {
|
|
236
|
+
se(), ne.set(e, r);
|
|
230
237
|
}
|
|
231
|
-
const
|
|
238
|
+
const A = `<?xml version="1.0" encoding="UTF-8"?>
|
|
232
239
|
<publication>
|
|
233
240
|
<source>
|
|
234
241
|
<directories external="../assets" generated="../generated-assets" />
|
|
@@ -237,31 +244,31 @@ const R = `<?xml version="1.0" encoding="UTF-8"?>
|
|
|
237
244
|
<platform portable="yes"/>
|
|
238
245
|
</html>
|
|
239
246
|
</publication>
|
|
240
|
-
`,
|
|
241
|
-
function
|
|
247
|
+
`, We = ["theme", "style", "shell"];
|
|
248
|
+
function b(e, r) {
|
|
242
249
|
for (const t of e.children)
|
|
243
250
|
if (t.type === "element" && t.name === r)
|
|
244
251
|
return t;
|
|
245
252
|
}
|
|
246
253
|
function g(e, r) {
|
|
247
|
-
let t =
|
|
254
|
+
let t = b(e, r);
|
|
248
255
|
return t || (t = { type: "element", name: r, attributes: {}, children: [] }, e.children.push(t)), t;
|
|
249
256
|
}
|
|
250
|
-
function
|
|
251
|
-
const t =
|
|
252
|
-
if (t &&
|
|
257
|
+
function He(e, r) {
|
|
258
|
+
const t = b(e, "css");
|
|
259
|
+
if (t && We.some((o) => t.attributes?.[o]))
|
|
253
260
|
return;
|
|
254
261
|
const n = t ?? g(e, "css");
|
|
255
262
|
n.attributes = { ...n.attributes, theme: r };
|
|
256
263
|
}
|
|
257
|
-
function
|
|
258
|
-
const t =
|
|
264
|
+
function Je(e, r) {
|
|
265
|
+
const t = b(e, "appearance");
|
|
259
266
|
if (t?.attributes?.theme)
|
|
260
267
|
return;
|
|
261
268
|
const n = t ?? g(e, "appearance");
|
|
262
269
|
n.attributes = { ...n.attributes, theme: r };
|
|
263
270
|
}
|
|
264
|
-
function
|
|
271
|
+
function Ke(e) {
|
|
265
272
|
const r = g(e, "resources");
|
|
266
273
|
r.attributes = {
|
|
267
274
|
...r.attributes,
|
|
@@ -269,30 +276,30 @@ function Ue(e) {
|
|
|
269
276
|
math: "online"
|
|
270
277
|
};
|
|
271
278
|
}
|
|
272
|
-
function
|
|
279
|
+
function ze(e, r = {}) {
|
|
273
280
|
const t = r.cssTheme?.trim(), n = r.revealTheme?.trim(), o = r.target === "slides";
|
|
274
281
|
if (!e && !t && !o)
|
|
275
|
-
return
|
|
276
|
-
const s = y(e ??
|
|
282
|
+
return A;
|
|
283
|
+
const s = y(e ?? A), a = b(s, "publication");
|
|
277
284
|
if (!a)
|
|
278
285
|
throw new Error(
|
|
279
286
|
"Invalid publication file: no root <publication> element found"
|
|
280
287
|
);
|
|
281
288
|
const i = g(a, "html"), u = g(i, "platform");
|
|
282
|
-
if (u.attributes = { ...u.attributes, portable: "yes" }, t &&
|
|
289
|
+
if (u.attributes = { ...u.attributes, portable: "yes" }, t && He(i, t), o) {
|
|
283
290
|
const c = g(a, "revealjs");
|
|
284
|
-
|
|
291
|
+
Ke(c), n && Je(c, n);
|
|
285
292
|
}
|
|
286
|
-
return
|
|
293
|
+
return S(s);
|
|
287
294
|
}
|
|
288
|
-
function
|
|
295
|
+
function K(e) {
|
|
289
296
|
if (!(e === void 0 || e === "" || e.startsWith("/")))
|
|
290
297
|
return e.endsWith("/") ? e : `${e}/`;
|
|
291
298
|
}
|
|
292
|
-
function
|
|
293
|
-
const r = y(e ??
|
|
299
|
+
function Ye(e) {
|
|
300
|
+
const r = y(e ?? A), t = b(r, "publication"), n = t && b(t, "source"), o = n && b(n, "directories"), s = K(
|
|
294
301
|
o?.attributes?.external ?? void 0
|
|
295
|
-
), a =
|
|
302
|
+
), a = K(
|
|
296
303
|
o?.attributes?.generated ?? void 0
|
|
297
304
|
);
|
|
298
305
|
return {
|
|
@@ -301,11 +308,11 @@ function He(e) {
|
|
|
301
308
|
managed: s !== void 0 && a !== void 0
|
|
302
309
|
};
|
|
303
310
|
}
|
|
304
|
-
const
|
|
305
|
-
async function
|
|
306
|
-
return e.includes("include") ? (await
|
|
311
|
+
const ae = "http://www.w3.org/2001/XInclude", z = 64;
|
|
312
|
+
async function Ve(e, r, t) {
|
|
313
|
+
return e.includes("include") ? (await ce(e, r, t)).content : e;
|
|
307
314
|
}
|
|
308
|
-
async function
|
|
315
|
+
async function ce(e, r, t) {
|
|
309
316
|
const n = y(e), o = {
|
|
310
317
|
projectDir: l.resolve(t),
|
|
311
318
|
stack: [l.resolve(r)]
|
|
@@ -315,24 +322,24 @@ async function ae(e, r, t) {
|
|
|
315
322
|
{ "": "" },
|
|
316
323
|
o
|
|
317
324
|
);
|
|
318
|
-
return { tree: n, content: s ?
|
|
325
|
+
return { tree: n, content: s ? S(n) : e };
|
|
319
326
|
}
|
|
320
|
-
function
|
|
327
|
+
function Ge(e) {
|
|
321
328
|
return e.data?.ptxIncludedFile;
|
|
322
329
|
}
|
|
323
|
-
function
|
|
330
|
+
function qe(e, r) {
|
|
324
331
|
const t = e.data ?? (e.data = {});
|
|
325
332
|
t.ptxIncludedFile = r;
|
|
326
333
|
}
|
|
327
|
-
function
|
|
334
|
+
function $(e, r) {
|
|
328
335
|
let t = e;
|
|
329
336
|
for (const [n, o] of Object.entries(r.attributes))
|
|
330
337
|
(n === "xmlns" || n.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[n === "xmlns" ? "" : n.slice(6)] = o ?? "");
|
|
331
338
|
return t;
|
|
332
339
|
}
|
|
333
|
-
function
|
|
340
|
+
function le(e, r) {
|
|
334
341
|
const t = e.name.indexOf(":"), n = t === -1 ? "" : e.name.slice(0, t);
|
|
335
|
-
return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && r[n] ===
|
|
342
|
+
return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && r[n] === ae;
|
|
336
343
|
}
|
|
337
344
|
async function x(e, r, t, n) {
|
|
338
345
|
let o = !1;
|
|
@@ -340,9 +347,9 @@ async function x(e, r, t, n) {
|
|
|
340
347
|
const a = e.children[s];
|
|
341
348
|
if (a.type !== "element")
|
|
342
349
|
continue;
|
|
343
|
-
const i =
|
|
344
|
-
if (
|
|
345
|
-
const u = await
|
|
350
|
+
const i = $(t, a);
|
|
351
|
+
if (le(a, i)) {
|
|
352
|
+
const u = await ue(
|
|
346
353
|
a,
|
|
347
354
|
r,
|
|
348
355
|
i,
|
|
@@ -353,7 +360,7 @@ async function x(e, r, t, n) {
|
|
|
353
360
|
}
|
|
354
361
|
return o;
|
|
355
362
|
}
|
|
356
|
-
async function
|
|
363
|
+
async function ue(e, r, t, n) {
|
|
357
364
|
const o = n.stack[n.stack.length - 1];
|
|
358
365
|
if (e.attributes.xpointer)
|
|
359
366
|
throw new Error(
|
|
@@ -376,11 +383,11 @@ async function le(e, r, t, n) {
|
|
|
376
383
|
throw new Error(
|
|
377
384
|
`Circular xi:include: ${[...n.stack, i].join(" -> ")}`
|
|
378
385
|
);
|
|
379
|
-
if (n.stack.length >=
|
|
380
|
-
throw new Error(`xi:include nesting exceeds ${
|
|
381
|
-
const u = await
|
|
386
|
+
if (n.stack.length >= z)
|
|
387
|
+
throw new Error(`xi:include nesting exceeds ${z} levels`);
|
|
388
|
+
const u = await B(i);
|
|
382
389
|
if (u === void 0) {
|
|
383
|
-
const p =
|
|
390
|
+
const p = Qe(e, t);
|
|
384
391
|
if (p)
|
|
385
392
|
return await x(p, r, t, n), p.children;
|
|
386
393
|
throw new Error(`xi:include target not found: ${s} (in ${o})`);
|
|
@@ -405,13 +412,13 @@ async function le(e, r, t, n) {
|
|
|
405
412
|
(p) => p.type === "element"
|
|
406
413
|
);
|
|
407
414
|
for (const p of f)
|
|
408
|
-
|
|
415
|
+
qe(p, i);
|
|
409
416
|
return f;
|
|
410
417
|
}
|
|
411
|
-
function
|
|
418
|
+
function Y(e) {
|
|
412
419
|
return e.name === "docinfo";
|
|
413
420
|
}
|
|
414
|
-
async function
|
|
421
|
+
async function Ze(e, r, t) {
|
|
415
422
|
try {
|
|
416
423
|
const o = y(e).children.find(
|
|
417
424
|
(c) => c.type === "element"
|
|
@@ -421,24 +428,24 @@ async function Ye(e, r, t) {
|
|
|
421
428
|
const s = l.resolve(r), a = l.dirname(s), i = {
|
|
422
429
|
projectDir: l.resolve(t),
|
|
423
430
|
stack: [s]
|
|
424
|
-
}, u =
|
|
431
|
+
}, u = $({ "": "" }, o);
|
|
425
432
|
for (const c of o.children) {
|
|
426
433
|
if (c.type !== "element")
|
|
427
434
|
continue;
|
|
428
|
-
const f =
|
|
429
|
-
if (
|
|
430
|
-
return await x(c, a, f, i),
|
|
431
|
-
if (
|
|
432
|
-
const m = (await
|
|
435
|
+
const f = $(u, c);
|
|
436
|
+
if (Y(c))
|
|
437
|
+
return await x(c, a, f, i), S(c);
|
|
438
|
+
if (le(c, f)) {
|
|
439
|
+
const m = (await ue(
|
|
433
440
|
c,
|
|
434
441
|
a,
|
|
435
442
|
f,
|
|
436
443
|
i
|
|
437
444
|
)).find(
|
|
438
|
-
(h) => h.type === "element" &&
|
|
445
|
+
(h) => h.type === "element" && Y(h)
|
|
439
446
|
);
|
|
440
447
|
if (m)
|
|
441
|
-
return
|
|
448
|
+
return S(m);
|
|
442
449
|
continue;
|
|
443
450
|
}
|
|
444
451
|
break;
|
|
@@ -448,33 +455,33 @@ async function Ye(e, r, t) {
|
|
|
448
455
|
return;
|
|
449
456
|
}
|
|
450
457
|
}
|
|
451
|
-
function
|
|
458
|
+
function Qe(e, r) {
|
|
452
459
|
for (const t of e.children) {
|
|
453
460
|
if (t.type !== "element")
|
|
454
461
|
continue;
|
|
455
|
-
const n =
|
|
456
|
-
if ((o === -1 ? t.name : t.name.slice(o + 1)) === "fallback" && n[s] ===
|
|
462
|
+
const n = $(r, t), o = t.name.indexOf(":"), s = o === -1 ? "" : t.name.slice(0, o);
|
|
463
|
+
if ((o === -1 ? t.name : t.name.slice(o + 1)) === "fallback" && n[s] === ae)
|
|
457
464
|
return t;
|
|
458
465
|
}
|
|
459
466
|
}
|
|
460
|
-
function
|
|
467
|
+
function de(e) {
|
|
461
468
|
return typeof e == "object" && e !== null && e.type === "element";
|
|
462
469
|
}
|
|
463
|
-
function
|
|
470
|
+
function et(e) {
|
|
464
471
|
return /^(pf|xhtml):/.test(e.name);
|
|
465
472
|
}
|
|
466
|
-
function
|
|
467
|
-
const n = [], o = e.children.find(
|
|
473
|
+
function tt(e, r, t) {
|
|
474
|
+
const n = [], o = e.children.find(de);
|
|
468
475
|
if (o) {
|
|
469
476
|
const s = t?.parentId ?? "root";
|
|
470
|
-
|
|
477
|
+
fe(o, s, t?.position ?? 1, r, s, n);
|
|
471
478
|
}
|
|
472
479
|
return n;
|
|
473
480
|
}
|
|
474
|
-
function
|
|
475
|
-
const a =
|
|
481
|
+
function fe(e, r, t, n, o, s) {
|
|
482
|
+
const a = Ge(e) ?? n;
|
|
476
483
|
let i, u;
|
|
477
|
-
if (
|
|
484
|
+
if (et(e))
|
|
478
485
|
u = "root";
|
|
479
486
|
else {
|
|
480
487
|
const f = e.attributes.label ?? e.attributes["xml:id"];
|
|
@@ -489,7 +496,7 @@ function de(e, r, t, n, o, s) {
|
|
|
489
496
|
}
|
|
490
497
|
let c = 0;
|
|
491
498
|
for (const f of e.children)
|
|
492
|
-
|
|
499
|
+
de(f) && (c += 1, fe(
|
|
493
500
|
f,
|
|
494
501
|
u,
|
|
495
502
|
c,
|
|
@@ -498,61 +505,67 @@ function de(e, r, t, n, o, s) {
|
|
|
498
505
|
s
|
|
499
506
|
));
|
|
500
507
|
}
|
|
501
|
-
function
|
|
508
|
+
function It(e, r) {
|
|
502
509
|
let t;
|
|
503
510
|
for (const n of e)
|
|
504
511
|
n.line <= r && (t = n);
|
|
505
512
|
return t ?? e[0];
|
|
506
513
|
}
|
|
507
|
-
function
|
|
514
|
+
function rt(e) {
|
|
508
515
|
const r = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
|
|
509
516
|
return /<\s*slide(?:show)?[\s/>]/.test(r) ? "slides" : "html";
|
|
510
517
|
}
|
|
511
|
-
function
|
|
512
|
-
return
|
|
518
|
+
function nt() {
|
|
519
|
+
return Ie(j(), "xsl");
|
|
513
520
|
}
|
|
514
|
-
function
|
|
521
|
+
function ot() {
|
|
515
522
|
return "Suspending" in WebAssembly;
|
|
516
523
|
}
|
|
517
|
-
function
|
|
518
|
-
if (!
|
|
524
|
+
function st() {
|
|
525
|
+
if (!ot())
|
|
519
526
|
throw new Error(
|
|
520
527
|
"WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
|
|
521
528
|
);
|
|
522
529
|
}
|
|
523
|
-
function
|
|
530
|
+
function I(e) {
|
|
524
531
|
return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
|
|
525
532
|
}
|
|
526
|
-
function
|
|
533
|
+
function it(e) {
|
|
527
534
|
return e.replace(
|
|
528
535
|
/from '\.\/(https:\/\/[^']+)'/g,
|
|
529
536
|
(r, t) => `from '${t}'`
|
|
530
537
|
);
|
|
531
538
|
}
|
|
532
|
-
const
|
|
533
|
-
|
|
539
|
+
const at = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${re}/dist/`, ct = {
|
|
540
|
+
"cli.version": re,
|
|
541
|
+
// Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
|
|
542
|
+
"rs-js": Re.join(":"),
|
|
543
|
+
"rs-css": je.join(":"),
|
|
544
|
+
"rs-version": De
|
|
545
|
+
};
|
|
546
|
+
function lt(e) {
|
|
534
547
|
return e.replace(
|
|
535
548
|
/(<link\b[^>]*\bhref=["'])_static\//gi,
|
|
536
|
-
`$1${
|
|
549
|
+
`$1${at}_static/`
|
|
537
550
|
);
|
|
538
551
|
}
|
|
539
|
-
function
|
|
552
|
+
function ut(e) {
|
|
540
553
|
return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
|
|
541
554
|
}
|
|
542
|
-
async function
|
|
543
|
-
const r = await
|
|
555
|
+
async function V(e) {
|
|
556
|
+
const r = await B(e);
|
|
544
557
|
if (r === void 0)
|
|
545
558
|
throw new Error(
|
|
546
559
|
`Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
|
|
547
560
|
);
|
|
548
561
|
return r;
|
|
549
562
|
}
|
|
550
|
-
async function
|
|
551
|
-
const t = l.resolve(e), n = await
|
|
563
|
+
async function dt(e, r) {
|
|
564
|
+
const t = l.resolve(e), n = await B(t);
|
|
552
565
|
if (n !== void 0)
|
|
553
|
-
return
|
|
566
|
+
return Ze(n, t, r);
|
|
554
567
|
}
|
|
555
|
-
function
|
|
568
|
+
function ft(e, r, t, n) {
|
|
556
569
|
const o = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), s = t === "slides" ? "slideshow" : r === "chapter" || r === "part" ? "book" : "article";
|
|
557
570
|
return `<pretext>
|
|
558
571
|
${n?.trim() ? `${n.trim()}
|
|
@@ -563,75 +576,75 @@ ${o}
|
|
|
563
576
|
</pretext>
|
|
564
577
|
`;
|
|
565
578
|
}
|
|
566
|
-
let
|
|
567
|
-
function
|
|
579
|
+
let pe = !1;
|
|
580
|
+
function pt(e) {
|
|
568
581
|
return e instanceof Error && /\bAborted\(/.test(e.message);
|
|
569
582
|
}
|
|
570
|
-
function
|
|
583
|
+
function mt(e) {
|
|
571
584
|
return e instanceof Error && /memory access|out of bounds/i.test(e.message);
|
|
572
585
|
}
|
|
573
|
-
function
|
|
574
|
-
if (
|
|
586
|
+
function ht() {
|
|
587
|
+
if (pe)
|
|
575
588
|
throw new Error(
|
|
576
589
|
"The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
|
|
577
590
|
);
|
|
578
591
|
}
|
|
579
592
|
function G(e) {
|
|
580
|
-
if (
|
|
581
|
-
throw
|
|
593
|
+
if (pt(e))
|
|
594
|
+
throw pe = !0, new Error(
|
|
582
595
|
"The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
|
|
583
596
|
{ cause: e }
|
|
584
597
|
);
|
|
585
|
-
if (
|
|
598
|
+
if (mt(e))
|
|
586
599
|
throw new Error(
|
|
587
600
|
"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.",
|
|
588
601
|
{ cause: e }
|
|
589
602
|
);
|
|
590
603
|
}
|
|
591
|
-
let
|
|
592
|
-
async function
|
|
593
|
-
return
|
|
604
|
+
let D;
|
|
605
|
+
async function me() {
|
|
606
|
+
return D || (D = (async () => {
|
|
594
607
|
const [e, r] = await Promise.all([
|
|
595
608
|
import("@pretextbook/libxslt-wasm"),
|
|
596
609
|
import("@pretextbook/libxslt-wasm/exslt")
|
|
597
610
|
]);
|
|
598
611
|
return r.registerAll(), e;
|
|
599
|
-
})()),
|
|
612
|
+
})()), D;
|
|
600
613
|
}
|
|
601
|
-
const
|
|
614
|
+
const R = /* @__PURE__ */ new Map(), wt = {
|
|
602
615
|
html: "preview-html.xsl",
|
|
603
616
|
slides: "preview-revealjs.xsl"
|
|
604
617
|
};
|
|
605
|
-
async function
|
|
606
|
-
const t =
|
|
607
|
-
let o =
|
|
618
|
+
async function bt(e, r) {
|
|
619
|
+
const t = wt[r], n = `${r}\0${e}`;
|
|
620
|
+
let o = R.get(n);
|
|
608
621
|
return o || (o = (async () => {
|
|
609
|
-
const { XmlDocument: s, XsltStylesheet: a } = await
|
|
622
|
+
const { XmlDocument: s, XsltStylesheet: a } = await me(), i = ie(e), u = await ee(j(), `/${t}`);
|
|
610
623
|
if (u === void 0)
|
|
611
624
|
throw new Error(
|
|
612
|
-
`Could not read ${t} from ${
|
|
625
|
+
`Could not read ${t} from ${j()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
|
|
613
626
|
);
|
|
614
627
|
const c = new TextDecoder().decode(u), f = await s.fromString(c, {
|
|
615
628
|
url: `${i}/${t}`,
|
|
616
629
|
options: { noEnt: !0, dtdLoad: !0, huge: !0 }
|
|
617
630
|
});
|
|
618
631
|
return a.fromXmlDocument(f);
|
|
619
|
-
})(),
|
|
632
|
+
})(), R.set(n, o), o.catch(() => R.delete(n))), o;
|
|
620
633
|
}
|
|
621
|
-
let
|
|
622
|
-
function
|
|
623
|
-
const r =
|
|
634
|
+
let q = Promise.resolve();
|
|
635
|
+
function vt(e) {
|
|
636
|
+
const r = q.then(
|
|
624
637
|
() => Z(e),
|
|
625
638
|
() => Z(e)
|
|
626
639
|
);
|
|
627
|
-
return
|
|
640
|
+
return q = r.catch(() => {
|
|
628
641
|
}), r;
|
|
629
642
|
}
|
|
630
643
|
async function Z(e) {
|
|
631
|
-
|
|
632
|
-
const { XmlDocument: r } = await
|
|
644
|
+
st(), ht();
|
|
645
|
+
const { XmlDocument: r } = await me(), t = l.resolve(e.sourcePath), n = l.resolve(
|
|
633
646
|
e.projectDir ?? l.dirname(t)
|
|
634
|
-
), o = e.sourceContent ?? await
|
|
647
|
+
), o = e.sourceContent ?? await V(t), s = l.relative(n, t);
|
|
635
648
|
if (s.startsWith(".."))
|
|
636
649
|
throw new Error(
|
|
637
650
|
`sourcePath (${t}) must live inside projectDir (${n})`
|
|
@@ -639,89 +652,91 @@ async function Z(e) {
|
|
|
639
652
|
const a = l.relative(
|
|
640
653
|
n,
|
|
641
654
|
l.resolve(e.mainSourcePath ?? t)
|
|
642
|
-
), i = a.startsWith("..") ? s : a, u =
|
|
655
|
+
), i = a.startsWith("..") ? s : a, u = ie(n);
|
|
643
656
|
try {
|
|
644
657
|
let c, f = `${u}/__pretext-preview-publication.xml`;
|
|
645
658
|
if (e.publicationPath) {
|
|
646
659
|
const d = l.resolve(e.publicationPath);
|
|
647
|
-
c = await
|
|
648
|
-
const
|
|
649
|
-
|
|
660
|
+
c = await V(d);
|
|
661
|
+
const w = l.relative(n, d);
|
|
662
|
+
w.startsWith("..") || (f = `${u}/${w.split(l.sep).join("/")}`);
|
|
650
663
|
}
|
|
651
664
|
let p, m;
|
|
652
665
|
if (e.sourceMap) {
|
|
653
|
-
const d = await
|
|
666
|
+
const d = await ce(
|
|
654
667
|
o,
|
|
655
668
|
t,
|
|
656
669
|
n
|
|
657
670
|
);
|
|
658
671
|
p = d.tree, m = d.content;
|
|
659
672
|
} else
|
|
660
|
-
m = await
|
|
673
|
+
m = await Ve(
|
|
661
674
|
o,
|
|
662
675
|
t,
|
|
663
676
|
n
|
|
664
677
|
);
|
|
665
|
-
const h = e.target ??
|
|
678
|
+
const h = e.target ?? rt(m), he = await bt(e.xslDir ?? nt(), h), C = ze(c, {
|
|
666
679
|
cssTheme: e.cssTheme,
|
|
667
680
|
revealTheme: e.revealTheme,
|
|
668
681
|
target: h
|
|
669
682
|
});
|
|
670
|
-
|
|
671
|
-
const E =
|
|
672
|
-
external: l.resolve(
|
|
673
|
-
generated: l.resolve(
|
|
674
|
-
} : void 0, T =
|
|
675
|
-
let
|
|
683
|
+
Ue(f, C);
|
|
684
|
+
const E = Ye(C), O = l.dirname(l.resolve(n, i)), X = E.external !== void 0 && E.generated !== void 0 ? {
|
|
685
|
+
external: l.resolve(O, E.external),
|
|
686
|
+
generated: l.resolve(O, E.generated)
|
|
687
|
+
} : void 0, T = ut(m);
|
|
688
|
+
let N = { parentId: "root", position: 1 };
|
|
676
689
|
if (T !== "pretext" && T !== "mathbook")
|
|
677
690
|
if (e.fragment) {
|
|
678
|
-
const d = e.docinfo ?? (e.docinfoSourcePath ? await
|
|
679
|
-
m =
|
|
691
|
+
const d = e.docinfo ?? (e.docinfoSourcePath ? await dt(e.docinfoSourcePath, n) : void 0);
|
|
692
|
+
m = ft(
|
|
680
693
|
m,
|
|
681
694
|
T,
|
|
682
695
|
h,
|
|
683
696
|
d
|
|
684
|
-
),
|
|
697
|
+
), N = { parentId: d?.trim() ? "root-1-2" : "root-1-1", position: 2 };
|
|
685
698
|
} else
|
|
686
699
|
throw new Error(
|
|
687
700
|
`The document root is <${T ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
|
|
688
701
|
);
|
|
689
|
-
const
|
|
702
|
+
const F = p ? tt(p, t, N) : void 0, U = await r.fromString(m, {
|
|
690
703
|
url: `${u}/${i.split(l.sep).join("/")}`,
|
|
691
704
|
options: { noEnt: !0, dtdLoad: !0, huge: !0 }
|
|
692
|
-
}),
|
|
693
|
-
publisher:
|
|
705
|
+
}), k = {
|
|
706
|
+
publisher: I(f)
|
|
694
707
|
};
|
|
695
|
-
for (const [d,
|
|
696
|
-
|
|
697
|
-
|
|
708
|
+
for (const [d, w] of Object.entries(ct))
|
|
709
|
+
k[d] = I(w);
|
|
710
|
+
for (const [d, w] of Object.entries(e.stringParams ?? {}))
|
|
711
|
+
k[d] = I(w);
|
|
712
|
+
let P;
|
|
698
713
|
try {
|
|
699
|
-
|
|
714
|
+
P = await he.apply(U, k);
|
|
700
715
|
} catch (d) {
|
|
701
716
|
throw G(d), new Error(
|
|
702
717
|
"PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
|
|
703
718
|
{ cause: d }
|
|
704
719
|
);
|
|
705
720
|
} finally {
|
|
706
|
-
|
|
721
|
+
U.delete();
|
|
707
722
|
}
|
|
708
723
|
try {
|
|
709
|
-
let d =
|
|
710
|
-
return (e.openKnowls ?? !0) && (d =
|
|
724
|
+
let d = it(P.toHtmlString());
|
|
725
|
+
return (e.openKnowls ?? !0) && (d = _e(d)), h === "slides" ? (d = lt(d), d = be(d, e.revealView ?? "scroll", {
|
|
711
726
|
zoom: e.revealZoom
|
|
712
|
-
})) : e.theme && (d =
|
|
727
|
+
})) : e.theme && (d = ve(d, e.theme)), e.previewBanner && (d = Pe(d, e.previewBanner)), {
|
|
713
728
|
html: d,
|
|
714
729
|
target: h,
|
|
715
|
-
...
|
|
730
|
+
...F ? { sourceMap: F } : {},
|
|
716
731
|
...X ? { assetDirs: X } : {}
|
|
717
732
|
};
|
|
718
733
|
} catch (d) {
|
|
719
734
|
throw G(d), d;
|
|
720
735
|
} finally {
|
|
721
|
-
|
|
736
|
+
P.delete();
|
|
722
737
|
}
|
|
723
738
|
} finally {
|
|
724
|
-
|
|
739
|
+
Fe(u);
|
|
725
740
|
}
|
|
726
741
|
}
|
|
727
742
|
const Q = `Usage: pretext-html <source.ptx> [options]
|
|
@@ -757,7 +772,7 @@ Options:
|
|
|
757
772
|
are previews of work in progress
|
|
758
773
|
-h, --help Show this help
|
|
759
774
|
`;
|
|
760
|
-
function
|
|
775
|
+
function gt(e) {
|
|
761
776
|
let r, t, n, o;
|
|
762
777
|
const s = {}, a = {};
|
|
763
778
|
for (let i = 0; i < e.length; i++) {
|
|
@@ -769,7 +784,7 @@ function mt(e) {
|
|
|
769
784
|
switch (u) {
|
|
770
785
|
case "-h":
|
|
771
786
|
case "--help":
|
|
772
|
-
|
|
787
|
+
v.stdout.write(Q), v.exit(0);
|
|
773
788
|
break;
|
|
774
789
|
case "-o":
|
|
775
790
|
case "--output":
|
|
@@ -828,29 +843,29 @@ function mt(e) {
|
|
|
828
843
|
sourceMapPath: o
|
|
829
844
|
};
|
|
830
845
|
}
|
|
831
|
-
async function
|
|
832
|
-
const { options: r, output: t, docinfoPath: n, sourceMapPath: o } =
|
|
833
|
-
n && (r.docinfo = await
|
|
834
|
-
const s = Date.now(), { html: a, sourceMap: i } = await
|
|
835
|
-
|
|
836
|
-
`), o && i && (await
|
|
837
|
-
`)), t ? (await
|
|
838
|
-
`)) :
|
|
846
|
+
async function Dt(e) {
|
|
847
|
+
const { options: r, output: t, docinfoPath: n, sourceMapPath: o } = gt(e);
|
|
848
|
+
n && (r.docinfo = await M(n, "utf8"));
|
|
849
|
+
const s = Date.now(), { html: a, sourceMap: i } = await vt(r);
|
|
850
|
+
v.stderr.write(`pretext-html: rendered in ${Date.now() - s}ms
|
|
851
|
+
`), o && i && (await W(o, JSON.stringify(i, null, 2)), v.stderr.write(`pretext-html: wrote ${o}
|
|
852
|
+
`)), t ? (await W(t, a), v.stderr.write(`pretext-html: wrote ${t}
|
|
853
|
+
`)) : v.stdout.write(a);
|
|
839
854
|
}
|
|
840
855
|
export {
|
|
841
856
|
ge as P,
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
857
|
+
rt as a,
|
|
858
|
+
ze as b,
|
|
859
|
+
ot as c,
|
|
860
|
+
nt as d,
|
|
861
|
+
Pt as e,
|
|
862
|
+
It as f,
|
|
863
|
+
gt as g,
|
|
864
|
+
Pe as i,
|
|
865
|
+
Dt as m,
|
|
866
|
+
_e as o,
|
|
867
|
+
Te as p,
|
|
868
|
+
vt as r,
|
|
869
|
+
kt as s,
|
|
870
|
+
I as x
|
|
856
871
|
};
|