@pretextbook/pretext-html 0.6.0 → 0.7.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/assets/upstream.json +1 -1
- package/assets/xsl/LICENSE-pretext +1 -1
- package/assets/xsl/README.md +43 -25
- package/assets/xsl/entities.ent +4 -4
- package/assets/xsl/extract-asymptote.xsl +5 -5
- package/assets/xsl/extract-biblio-csl.xsl +1 -1
- package/assets/xsl/extract-datafile.xsl +1 -1
- package/assets/xsl/extract-dynamic.xsl +1 -1
- package/assets/xsl/extract-identity.xsl +5 -5
- package/assets/xsl/extract-interactive.xsl +1 -1
- package/assets/xsl/extract-latex-image.xsl +5 -5
- package/assets/xsl/extract-mermaid.xsl +1 -1
- package/assets/xsl/extract-mom.xsl +5 -5
- package/assets/xsl/extract-pg.xsl +1 -1
- package/assets/xsl/extract-prefigure.xsl +5 -5
- package/assets/xsl/extract-qrcode.xsl +1 -1
- package/assets/xsl/extract-runestone-page-template.xsl +1 -1
- package/assets/xsl/extract-sageplot.xsl +5 -5
- package/assets/xsl/extract-stack.xsl +1 -1
- package/assets/xsl/extract-trace.xsl +1 -1
- package/assets/xsl/extract-youtube.xsl +5 -5
- package/assets/xsl/latex/pretext-latex-AIM.xsl +1 -1
- package/assets/xsl/latex/pretext-latex-chaos.xsl +1 -1
- package/assets/xsl/latex/pretext-latex-dyslexic-font.xsl +1 -1
- package/assets/xsl/latex/pretext-latex-guide.xsl +1 -1
- package/assets/xsl/localizations/README.md +25 -25
- package/assets/xsl/localizations/af-ZA.xml +1 -1
- package/assets/xsl/localizations/bg-BG.xml +1 -1
- package/assets/xsl/localizations/ca-ES.xml +1 -1
- package/assets/xsl/localizations/cs-CZ.xml +1 -1
- package/assets/xsl/localizations/de-DE.xml +1 -1
- package/assets/xsl/localizations/en-US.xml +1 -1
- package/assets/xsl/localizations/es-ES.xml +1 -1
- package/assets/xsl/localizations/fi-FI.xml +1 -1
- package/assets/xsl/localizations/fr-CA.xml +1 -1
- package/assets/xsl/localizations/fr-FR.xml +1 -1
- package/assets/xsl/localizations/hu-HU.xml +1 -1
- package/assets/xsl/localizations/it-IT.xml +1 -1
- package/assets/xsl/localizations/ku-CKB.xml +1 -1
- package/assets/xsl/localizations/localizations.xml +1 -1
- package/assets/xsl/localizations/nl-NL.xml +1 -1
- package/assets/xsl/localizations/pt-BR.xml +1 -1
- package/assets/xsl/localizations/pt-PT.xml +1 -1
- package/assets/xsl/localizations/zh-HANS.xml +1 -1
- package/assets/xsl/pretext-assembly.xsl +64 -1
- package/assets/xsl/pretext-basic-html.xsl +5 -5
- package/assets/xsl/pretext-braille-preprint.xsl +5 -5
- package/assets/xsl/pretext-common.xsl +104 -30
- package/assets/xsl/pretext-dynamic.xsl +1 -1
- package/assets/xsl/pretext-epub.xsl +90 -84
- package/assets/xsl/pretext-fo.xsl +1 -1
- package/assets/xsl/pretext-html.xsl +57 -34
- package/assets/xsl/pretext-json-manifest.xsl +1 -1
- package/assets/xsl/pretext-jupyter.xsl +5 -5
- package/assets/xsl/pretext-latex-classic.xsl +1 -1
- package/assets/xsl/pretext-latex-common.xsl +7 -5
- package/assets/xsl/pretext-latex.xsl +3 -3
- package/assets/xsl/pretext-litprog.xsl +9 -2
- package/assets/xsl/pretext-markdown.xsl +1 -1
- package/assets/xsl/pretext-numbers.xsl +1 -1
- package/assets/xsl/pretext-runestone-fitb.xsl +18 -0
- package/assets/xsl/pretext-runestone-static.xsl +13 -1
- package/assets/xsl/pretext-runestone.xsl +34 -6
- package/assets/xsl/pretext-sage-doctest.xsl +18 -0
- package/assets/xsl/pretext-solution-manual-latex.xsl +4 -4
- package/assets/xsl/pretext-text-utilities.xsl +1 -1
- package/assets/xsl/pretext-text.xsl +5 -5
- package/assets/xsl/pretext-units.xsl +5 -5
- package/assets/xsl/pretext-view-source.xsl +1 -1
- package/assets/xsl/pretext-ww-problem-sets.xsl +15 -12
- package/assets/xsl/publisher-variables.xsl +104 -36
- package/assets/xsl/support/README.md +19 -0
- package/assets/xsl/support/extract-math.xsl +1 -1
- package/assets/xsl/support/package-math.xsl +1 -1
- package/assets/xsl/support/play-button/README.md +3 -1
- package/assets/xsl/support/webpack_static_imports.xml +19 -0
- package/assets/xsl/tests/README.md +20 -1
- package/assets/xsl/tests/null.xml +19 -0
- package/assets/xsl/tests/pretext-text-utilities-test.xsl +1 -1
- package/assets/xsl/utilities/README.md +27 -6
- package/assets/xsl/utilities/author-report.xsl +1 -1
- package/assets/xsl/utilities/fix-deprecations.xsl +5 -5
- package/assets/xsl/utilities/pretext-enhanced-source.xsl +1 -1
- package/assets/xsl/utilities/report-publisher-variables.xsl +5 -5
- package/assets/xsl/xml-to-json.xsl +4 -4
- package/assets/xsl-bundle.json +1 -1
- package/dist/banner.d.ts +51 -0
- package/dist/{cli-DF7XOWN7.js → cli-D0m0Ha1j.js} +343 -211
- package/dist/cli.js +2 -2
- package/dist/index.browser.d.ts +2 -0
- package/dist/index.browser.js +528 -396
- package/dist/index.d.ts +2 -0
- package/dist/index.js +28 -25
- package/dist/renderer.d.ts +13 -0
- package/package.json +1 -1
- package/assets/xsl/pretext-smc.xsl +0 -492
|
@@ -1,12 +1,141 @@
|
|
|
1
|
-
import { readFile as
|
|
1
|
+
import { readFile as A, writeFile as U } from "node:fs/promises";
|
|
2
2
|
import * as b from "node:process";
|
|
3
3
|
import * as l from "node:path";
|
|
4
|
-
import { fileURLToPath as
|
|
5
|
-
import { fromXml as
|
|
6
|
-
import { toXml as
|
|
7
|
-
import { injectRevealBridge as
|
|
8
|
-
import { injectThemeBridge as
|
|
9
|
-
|
|
4
|
+
import { fileURLToPath as he } from "node:url";
|
|
5
|
+
import { fromXml as y } from "xast-util-from-xml";
|
|
6
|
+
import { toXml as $ } from "xast-util-to-xml";
|
|
7
|
+
import { injectRevealBridge as we } from "./reveal.js";
|
|
8
|
+
import { injectThemeBridge as be } from "./theme.js";
|
|
9
|
+
const ge = "ptxPreviewBannerDismissed", ve = "About live preview";
|
|
10
|
+
function N(e) {
|
|
11
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
12
|
+
}
|
|
13
|
+
function xe(e) {
|
|
14
|
+
return [
|
|
15
|
+
'<div id="ptx-preview-banner" class="ptx-preview-banner" role="note">',
|
|
16
|
+
` <span class="ptx-preview-banner-text">${N(e)}</span>`,
|
|
17
|
+
' <button type="button" class="ptx-preview-banner-dismiss" aria-label="Dismiss">×</button>',
|
|
18
|
+
"</div>",
|
|
19
|
+
`<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${N(ve)}</button>`
|
|
20
|
+
].join(`
|
|
21
|
+
`);
|
|
22
|
+
}
|
|
23
|
+
function ye() {
|
|
24
|
+
return [
|
|
25
|
+
"<style>",
|
|
26
|
+
".ptx-preview-banner {",
|
|
27
|
+
" display: flex;",
|
|
28
|
+
" align-items: center;",
|
|
29
|
+
" gap: 0.75em;",
|
|
30
|
+
" padding: 0.5em 1em;",
|
|
31
|
+
" font-size: 0.9em;",
|
|
32
|
+
" background: #fff8e1;",
|
|
33
|
+
" color: #6b5300;",
|
|
34
|
+
" border-bottom: 1px solid #f0c36d;",
|
|
35
|
+
"}",
|
|
36
|
+
// The [hidden] content attribute only hides an element via the
|
|
37
|
+
// user-agent stylesheet's `[hidden] { display: none }` rule, and a
|
|
38
|
+
// normal-priority *author* rule always wins over a normal-priority UA
|
|
39
|
+
// rule regardless of selector specificity — so the unconditional
|
|
40
|
+
// `display: flex` above would otherwise keep the banner visible even
|
|
41
|
+
// after previewBannerScript sets `banner.hidden = true`.
|
|
42
|
+
".ptx-preview-banner[hidden] {",
|
|
43
|
+
" display: none;",
|
|
44
|
+
"}",
|
|
45
|
+
".ptx-preview-banner-text {",
|
|
46
|
+
" flex: 1 1 auto;",
|
|
47
|
+
"}",
|
|
48
|
+
".ptx-preview-banner-dismiss {",
|
|
49
|
+
" flex: 0 0 auto;",
|
|
50
|
+
" background: transparent;",
|
|
51
|
+
" border: none;",
|
|
52
|
+
" font-size: 1.2em;",
|
|
53
|
+
" line-height: 1;",
|
|
54
|
+
" cursor: pointer;",
|
|
55
|
+
" color: inherit;",
|
|
56
|
+
" padding: 0 0.25em;",
|
|
57
|
+
"}",
|
|
58
|
+
"html.dark-mode .ptx-preview-banner {",
|
|
59
|
+
" background: #3a2f00;",
|
|
60
|
+
" color: #f2d27a;",
|
|
61
|
+
" border-bottom-color: #6b5300;",
|
|
62
|
+
"}",
|
|
63
|
+
".ptx-preview-banner-restore {",
|
|
64
|
+
" position: fixed;",
|
|
65
|
+
" right: 0.5em;",
|
|
66
|
+
" bottom: 0.5em;",
|
|
67
|
+
" z-index: 1000;",
|
|
68
|
+
" background: transparent;",
|
|
69
|
+
" border: none;",
|
|
70
|
+
" padding: 0.15em 0.4em;",
|
|
71
|
+
" font-size: 0.75em;",
|
|
72
|
+
" color: inherit;",
|
|
73
|
+
" opacity: 0.45;",
|
|
74
|
+
" text-decoration: underline;",
|
|
75
|
+
" cursor: pointer;",
|
|
76
|
+
"}",
|
|
77
|
+
".ptx-preview-banner-restore:hover {",
|
|
78
|
+
" opacity: 0.85;",
|
|
79
|
+
"}",
|
|
80
|
+
"</style>"
|
|
81
|
+
].join(`
|
|
82
|
+
`);
|
|
83
|
+
}
|
|
84
|
+
function Ee() {
|
|
85
|
+
return [
|
|
86
|
+
"<script>",
|
|
87
|
+
"(function () {",
|
|
88
|
+
" var KEY = " + JSON.stringify(ge) + ";",
|
|
89
|
+
' var banner = document.getElementById("ptx-preview-banner");',
|
|
90
|
+
' var restore = document.getElementById("ptx-preview-banner-restore");',
|
|
91
|
+
" if (!banner || !restore) { return; }",
|
|
92
|
+
// localStorage can throw (disabled cookies/storage, sandboxed iframe);
|
|
93
|
+
// fall back to always showing the banner rather than crashing the page.
|
|
94
|
+
" function isDismissed() {",
|
|
95
|
+
" try { return window.localStorage.getItem(KEY) === '1'; }",
|
|
96
|
+
" catch (e) { return false; }",
|
|
97
|
+
" }",
|
|
98
|
+
" function setDismissed(value) {",
|
|
99
|
+
" try {",
|
|
100
|
+
" if (value) { window.localStorage.setItem(KEY, '1'); }",
|
|
101
|
+
" else { window.localStorage.removeItem(KEY); }",
|
|
102
|
+
" } catch (e) {}",
|
|
103
|
+
" }",
|
|
104
|
+
" function apply(dismissed) {",
|
|
105
|
+
" banner.hidden = dismissed;",
|
|
106
|
+
" restore.hidden = !dismissed;",
|
|
107
|
+
" }",
|
|
108
|
+
" apply(isDismissed());",
|
|
109
|
+
' var dismissBtn = banner.querySelector(".ptx-preview-banner-dismiss");',
|
|
110
|
+
" if (dismissBtn) {",
|
|
111
|
+
" dismissBtn.addEventListener('click', function () {",
|
|
112
|
+
" setDismissed(true);",
|
|
113
|
+
" apply(true);",
|
|
114
|
+
" });",
|
|
115
|
+
" }",
|
|
116
|
+
" restore.addEventListener('click', function () {",
|
|
117
|
+
" setDismissed(false);",
|
|
118
|
+
" apply(false);",
|
|
119
|
+
" });",
|
|
120
|
+
"})();",
|
|
121
|
+
"<\/script>"
|
|
122
|
+
].join(`
|
|
123
|
+
`);
|
|
124
|
+
}
|
|
125
|
+
const Te = "<!--ptx-preview-banner-->", $e = "<!--/ptx-preview-banner-->", Se = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
|
|
126
|
+
function ke(e, r) {
|
|
127
|
+
const t = Se.exec(e), n = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
|
|
128
|
+
if (!/<body[^>]*>/i.test(n))
|
|
129
|
+
return n;
|
|
130
|
+
const o = `
|
|
131
|
+
${Te}
|
|
132
|
+
${ye()}
|
|
133
|
+
${xe(r.message)}
|
|
134
|
+
${Ee()}
|
|
135
|
+
${$e}`;
|
|
136
|
+
return n.replace(/<body([^>]*)>/i, `<body$1>${o}`);
|
|
137
|
+
}
|
|
138
|
+
async function ee(e, r) {
|
|
10
139
|
const t = l.resolve(e), n = l.resolve(t, `.${l.posix.normalize(r)}`);
|
|
11
140
|
if (n !== t && !n.startsWith(t + l.sep)) {
|
|
12
141
|
console.error(
|
|
@@ -15,57 +144,57 @@ async function Q(e, r) {
|
|
|
15
144
|
return;
|
|
16
145
|
}
|
|
17
146
|
try {
|
|
18
|
-
return new Uint8Array(await
|
|
147
|
+
return new Uint8Array(await A(n));
|
|
19
148
|
} catch {
|
|
20
149
|
return;
|
|
21
150
|
}
|
|
22
151
|
}
|
|
23
|
-
async function
|
|
152
|
+
async function j(e) {
|
|
24
153
|
try {
|
|
25
|
-
return await
|
|
154
|
+
return await A(e, "utf8");
|
|
26
155
|
} catch {
|
|
27
156
|
return;
|
|
28
157
|
}
|
|
29
158
|
}
|
|
30
|
-
let
|
|
31
|
-
function
|
|
32
|
-
|
|
159
|
+
let te;
|
|
160
|
+
function yt(e) {
|
|
161
|
+
te = e;
|
|
33
162
|
}
|
|
34
163
|
function I() {
|
|
35
|
-
return
|
|
164
|
+
return te ?? process.env.PRETEXT_HTML_ASSETS ?? l.resolve(l.dirname(he(import.meta.url)), "..", "assets");
|
|
36
165
|
}
|
|
37
|
-
function
|
|
166
|
+
function Pe(e, r) {
|
|
38
167
|
return l.join(e, r);
|
|
39
168
|
}
|
|
40
|
-
const
|
|
41
|
-
function
|
|
169
|
+
const De = "born-hidden-knowl", Ie = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
|
|
170
|
+
function Le(e) {
|
|
42
171
|
const r = /\bclass="([^"]*)"/.exec(e);
|
|
43
172
|
return r ? r[1].trim().split(/\s+/) : [];
|
|
44
173
|
}
|
|
45
|
-
function
|
|
174
|
+
function Re(e) {
|
|
46
175
|
return /(^|\s)open(\s|=|$)/.test(e);
|
|
47
176
|
}
|
|
48
177
|
function H(e) {
|
|
49
|
-
return
|
|
178
|
+
return Re(e) ? e : ` open${e}`;
|
|
50
179
|
}
|
|
51
|
-
function
|
|
180
|
+
function Ae(e) {
|
|
52
181
|
return e.replace(
|
|
53
|
-
|
|
182
|
+
Ie,
|
|
54
183
|
(r, t, n, o) => {
|
|
55
|
-
if (!
|
|
184
|
+
if (!Le(t).includes(De))
|
|
56
185
|
return r;
|
|
57
186
|
const s = `<details${H(t)}>`;
|
|
58
187
|
return o === void 0 ? `${s}${n}` : `${s}${n}<summary${H(o)}>`;
|
|
59
188
|
}
|
|
60
189
|
);
|
|
61
190
|
}
|
|
62
|
-
const
|
|
63
|
-
let L,
|
|
64
|
-
function
|
|
65
|
-
|
|
191
|
+
const B = /* @__PURE__ */ new Map(), re = /* @__PURE__ */ new Map();
|
|
192
|
+
let L, je = 0, ne = ee;
|
|
193
|
+
function Et(e) {
|
|
194
|
+
ne = e;
|
|
66
195
|
}
|
|
67
|
-
function
|
|
68
|
-
const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n =
|
|
196
|
+
function Be(e, r) {
|
|
197
|
+
const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n = re.get(t);
|
|
69
198
|
if (n !== void 0)
|
|
70
199
|
return Promise.resolve(new Response(n, { status: 200 }));
|
|
71
200
|
let o;
|
|
@@ -74,32 +203,32 @@ function Ee(e, r) {
|
|
|
74
203
|
} catch {
|
|
75
204
|
o = "";
|
|
76
205
|
}
|
|
77
|
-
const s =
|
|
78
|
-
return s !== void 0 ?
|
|
206
|
+
const s = B.get(o);
|
|
207
|
+
return s !== void 0 ? Ce(s, t) : L(e, r);
|
|
79
208
|
}
|
|
80
|
-
const
|
|
81
|
-
async function
|
|
82
|
-
const t = decodeURIComponent(new URL(r).pathname), n = await
|
|
209
|
+
const Me = '<?xml version="1.0"?><pretext-preview-missing-file/>';
|
|
210
|
+
async function Ce(e, r) {
|
|
211
|
+
const t = decodeURIComponent(new URL(r).pathname), n = await ne(e, t);
|
|
83
212
|
if (n === void 0)
|
|
84
|
-
return new Response(
|
|
213
|
+
return new Response(Me, { status: 200 });
|
|
85
214
|
const o = typeof n == "string" ? n : new Uint8Array(n);
|
|
86
215
|
return new Response(o, { status: 200 });
|
|
87
216
|
}
|
|
88
|
-
function
|
|
89
|
-
L || (L = globalThis.fetch, globalThis.fetch =
|
|
217
|
+
function oe() {
|
|
218
|
+
L || (L = globalThis.fetch, globalThis.fetch = Be);
|
|
90
219
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
const r = `mnt${
|
|
94
|
-
return
|
|
220
|
+
function se(e) {
|
|
221
|
+
oe();
|
|
222
|
+
const r = `mnt${++je}.ptx.invalid`;
|
|
223
|
+
return B.set(r, e), `http://${r}`;
|
|
95
224
|
}
|
|
96
|
-
function
|
|
97
|
-
|
|
225
|
+
function Xe(e) {
|
|
226
|
+
B.delete(new URL(e).host);
|
|
98
227
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
228
|
+
function Fe(e, r) {
|
|
229
|
+
oe(), re.set(e, r);
|
|
101
230
|
}
|
|
102
|
-
const
|
|
231
|
+
const R = `<?xml version="1.0" encoding="UTF-8"?>
|
|
103
232
|
<publication>
|
|
104
233
|
<source>
|
|
105
234
|
<directories external="../assets" generated="../generated-assets" />
|
|
@@ -108,7 +237,7 @@ const M = `<?xml version="1.0" encoding="UTF-8"?>
|
|
|
108
237
|
<platform portable="yes"/>
|
|
109
238
|
</html>
|
|
110
239
|
</publication>
|
|
111
|
-
`,
|
|
240
|
+
`, _e = ["theme", "style", "shell"];
|
|
112
241
|
function w(e, r) {
|
|
113
242
|
for (const t of e.children)
|
|
114
243
|
if (t.type === "element" && t.name === r)
|
|
@@ -118,21 +247,21 @@ function g(e, r) {
|
|
|
118
247
|
let t = w(e, r);
|
|
119
248
|
return t || (t = { type: "element", name: r, attributes: {}, children: [] }, e.children.push(t)), t;
|
|
120
249
|
}
|
|
121
|
-
function
|
|
250
|
+
function Oe(e, r) {
|
|
122
251
|
const t = w(e, "css");
|
|
123
|
-
if (t &&
|
|
252
|
+
if (t && _e.some((o) => t.attributes?.[o]))
|
|
124
253
|
return;
|
|
125
254
|
const n = t ?? g(e, "css");
|
|
126
255
|
n.attributes = { ...n.attributes, theme: r };
|
|
127
256
|
}
|
|
128
|
-
function
|
|
257
|
+
function We(e, r) {
|
|
129
258
|
const t = w(e, "appearance");
|
|
130
259
|
if (t?.attributes?.theme)
|
|
131
260
|
return;
|
|
132
261
|
const n = t ?? g(e, "appearance");
|
|
133
262
|
n.attributes = { ...n.attributes, theme: r };
|
|
134
263
|
}
|
|
135
|
-
function
|
|
264
|
+
function Ue(e) {
|
|
136
265
|
const r = g(e, "resources");
|
|
137
266
|
r.attributes = {
|
|
138
267
|
...r.attributes,
|
|
@@ -140,30 +269,30 @@ function Re(e) {
|
|
|
140
269
|
math: "online"
|
|
141
270
|
};
|
|
142
271
|
}
|
|
143
|
-
function
|
|
272
|
+
function Ne(e, r = {}) {
|
|
144
273
|
const t = r.cssTheme?.trim(), n = r.revealTheme?.trim(), o = r.target === "slides";
|
|
145
274
|
if (!e && !t && !o)
|
|
146
|
-
return
|
|
147
|
-
const s =
|
|
275
|
+
return R;
|
|
276
|
+
const s = y(e ?? R), a = w(s, "publication");
|
|
148
277
|
if (!a)
|
|
149
278
|
throw new Error(
|
|
150
279
|
"Invalid publication file: no root <publication> element found"
|
|
151
280
|
);
|
|
152
281
|
const i = g(a, "html"), u = g(i, "platform");
|
|
153
|
-
if (u.attributes = { ...u.attributes, portable: "yes" }, t &&
|
|
282
|
+
if (u.attributes = { ...u.attributes, portable: "yes" }, t && Oe(i, t), o) {
|
|
154
283
|
const c = g(a, "revealjs");
|
|
155
|
-
|
|
284
|
+
Ue(c), n && We(c, n);
|
|
156
285
|
}
|
|
157
|
-
return
|
|
286
|
+
return $(s);
|
|
158
287
|
}
|
|
159
|
-
function
|
|
288
|
+
function J(e) {
|
|
160
289
|
if (!(e === void 0 || e === "" || e.startsWith("/")))
|
|
161
290
|
return e.endsWith("/") ? e : `${e}/`;
|
|
162
291
|
}
|
|
163
|
-
function
|
|
164
|
-
const r =
|
|
292
|
+
function He(e) {
|
|
293
|
+
const r = y(e ?? R), t = w(r, "publication"), n = t && w(t, "source"), o = n && w(n, "directories"), s = J(
|
|
165
294
|
o?.attributes?.external ?? void 0
|
|
166
|
-
), a =
|
|
295
|
+
), a = J(
|
|
167
296
|
o?.attributes?.generated ?? void 0
|
|
168
297
|
);
|
|
169
298
|
return {
|
|
@@ -172,26 +301,26 @@ function je(e) {
|
|
|
172
301
|
managed: s !== void 0 && a !== void 0
|
|
173
302
|
};
|
|
174
303
|
}
|
|
175
|
-
const
|
|
176
|
-
async function
|
|
177
|
-
return e.includes("include") ? (await
|
|
304
|
+
const ie = "http://www.w3.org/2001/XInclude", K = 64;
|
|
305
|
+
async function Je(e, r, t) {
|
|
306
|
+
return e.includes("include") ? (await ae(e, r, t)).content : e;
|
|
178
307
|
}
|
|
179
|
-
async function
|
|
180
|
-
const n =
|
|
308
|
+
async function ae(e, r, t) {
|
|
309
|
+
const n = y(e), o = {
|
|
181
310
|
projectDir: l.resolve(t),
|
|
182
311
|
stack: [l.resolve(r)]
|
|
183
|
-
}, s = await
|
|
312
|
+
}, s = await x(
|
|
184
313
|
n,
|
|
185
314
|
l.dirname(l.resolve(r)),
|
|
186
315
|
{ "": "" },
|
|
187
316
|
o
|
|
188
317
|
);
|
|
189
|
-
return { tree: n, content: s ?
|
|
318
|
+
return { tree: n, content: s ? $(n) : e };
|
|
190
319
|
}
|
|
191
|
-
function
|
|
320
|
+
function Ke(e) {
|
|
192
321
|
return e.data?.ptxIncludedFile;
|
|
193
322
|
}
|
|
194
|
-
function
|
|
323
|
+
function ze(e, r) {
|
|
195
324
|
const t = e.data ?? (e.data = {});
|
|
196
325
|
t.ptxIncludedFile = r;
|
|
197
326
|
}
|
|
@@ -201,30 +330,30 @@ function S(e, r) {
|
|
|
201
330
|
(n === "xmlns" || n.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[n === "xmlns" ? "" : n.slice(6)] = o ?? "");
|
|
202
331
|
return t;
|
|
203
332
|
}
|
|
204
|
-
function
|
|
333
|
+
function ce(e, r) {
|
|
205
334
|
const t = e.name.indexOf(":"), n = t === -1 ? "" : e.name.slice(0, t);
|
|
206
|
-
return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && r[n] ===
|
|
335
|
+
return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && r[n] === ie;
|
|
207
336
|
}
|
|
208
|
-
async function
|
|
337
|
+
async function x(e, r, t, n) {
|
|
209
338
|
let o = !1;
|
|
210
339
|
for (let s = 0; s < e.children.length; s++) {
|
|
211
340
|
const a = e.children[s];
|
|
212
341
|
if (a.type !== "element")
|
|
213
342
|
continue;
|
|
214
343
|
const i = S(t, a);
|
|
215
|
-
if (
|
|
216
|
-
const u = await
|
|
344
|
+
if (ce(a, i)) {
|
|
345
|
+
const u = await le(
|
|
217
346
|
a,
|
|
218
347
|
r,
|
|
219
348
|
i,
|
|
220
349
|
n
|
|
221
350
|
);
|
|
222
351
|
e.children.splice(s, 1, ...u), s += u.length - 1, o = !0;
|
|
223
|
-
} else await
|
|
352
|
+
} else await x(a, r, i, n) && (o = !0);
|
|
224
353
|
}
|
|
225
354
|
return o;
|
|
226
355
|
}
|
|
227
|
-
async function
|
|
356
|
+
async function le(e, r, t, n) {
|
|
228
357
|
const o = n.stack[n.stack.length - 1];
|
|
229
358
|
if (e.attributes.xpointer)
|
|
230
359
|
throw new Error(
|
|
@@ -247,44 +376,44 @@ async function ce(e, r, t, n) {
|
|
|
247
376
|
throw new Error(
|
|
248
377
|
`Circular xi:include: ${[...n.stack, i].join(" -> ")}`
|
|
249
378
|
);
|
|
250
|
-
if (n.stack.length >=
|
|
251
|
-
throw new Error(`xi:include nesting exceeds ${
|
|
252
|
-
const u = await
|
|
379
|
+
if (n.stack.length >= K)
|
|
380
|
+
throw new Error(`xi:include nesting exceeds ${K} levels`);
|
|
381
|
+
const u = await j(i);
|
|
253
382
|
if (u === void 0) {
|
|
254
|
-
const
|
|
255
|
-
if (
|
|
256
|
-
return await
|
|
383
|
+
const p = qe(e, t);
|
|
384
|
+
if (p)
|
|
385
|
+
return await x(p, r, t, n), p.children;
|
|
257
386
|
throw new Error(`xi:include target not found: ${s} (in ${o})`);
|
|
258
387
|
}
|
|
259
388
|
if (e.attributes.parse === "text")
|
|
260
389
|
return [{ type: "text", value: u }];
|
|
261
390
|
let c;
|
|
262
391
|
try {
|
|
263
|
-
c =
|
|
264
|
-
} catch (
|
|
392
|
+
c = y(u);
|
|
393
|
+
} catch (p) {
|
|
265
394
|
throw new Error(
|
|
266
|
-
`Could not parse xi:include target ${i} as XML: ${
|
|
395
|
+
`Could not parse xi:include target ${i} as XML: ${p instanceof Error ? p.message : p}. (Included files must be well-formed, with a single root element.)`
|
|
267
396
|
);
|
|
268
397
|
}
|
|
269
398
|
n.stack.push(i);
|
|
270
399
|
try {
|
|
271
|
-
await
|
|
400
|
+
await x(c, l.dirname(i), { "": "" }, n);
|
|
272
401
|
} finally {
|
|
273
402
|
n.stack.pop();
|
|
274
403
|
}
|
|
275
404
|
const f = c.children.filter(
|
|
276
|
-
(
|
|
405
|
+
(p) => p.type === "element"
|
|
277
406
|
);
|
|
278
|
-
for (const
|
|
279
|
-
|
|
407
|
+
for (const p of f)
|
|
408
|
+
ze(p, i);
|
|
280
409
|
return f;
|
|
281
410
|
}
|
|
282
411
|
function z(e) {
|
|
283
412
|
return e.name === "docinfo";
|
|
284
413
|
}
|
|
285
|
-
async function
|
|
414
|
+
async function Ye(e, r, t) {
|
|
286
415
|
try {
|
|
287
|
-
const o =
|
|
416
|
+
const o = y(e).children.find(
|
|
288
417
|
(c) => c.type === "element"
|
|
289
418
|
);
|
|
290
419
|
if (!o)
|
|
@@ -298,18 +427,18 @@ async function Ue(e, r, t) {
|
|
|
298
427
|
continue;
|
|
299
428
|
const f = S(u, c);
|
|
300
429
|
if (z(c))
|
|
301
|
-
return await
|
|
302
|
-
if (
|
|
303
|
-
const m = (await
|
|
430
|
+
return await x(c, a, f, i), $(c);
|
|
431
|
+
if (ce(c, f)) {
|
|
432
|
+
const m = (await le(
|
|
304
433
|
c,
|
|
305
434
|
a,
|
|
306
435
|
f,
|
|
307
436
|
i
|
|
308
437
|
)).find(
|
|
309
|
-
(
|
|
438
|
+
(h) => h.type === "element" && z(h)
|
|
310
439
|
);
|
|
311
440
|
if (m)
|
|
312
|
-
return
|
|
441
|
+
return $(m);
|
|
313
442
|
continue;
|
|
314
443
|
}
|
|
315
444
|
break;
|
|
@@ -319,33 +448,33 @@ async function Ue(e, r, t) {
|
|
|
319
448
|
return;
|
|
320
449
|
}
|
|
321
450
|
}
|
|
322
|
-
function
|
|
451
|
+
function qe(e, r) {
|
|
323
452
|
for (const t of e.children) {
|
|
324
453
|
if (t.type !== "element")
|
|
325
454
|
continue;
|
|
326
455
|
const n = S(r, t), o = t.name.indexOf(":"), s = o === -1 ? "" : t.name.slice(0, o);
|
|
327
|
-
if ((o === -1 ? t.name : t.name.slice(o + 1)) === "fallback" && n[s] ===
|
|
456
|
+
if ((o === -1 ? t.name : t.name.slice(o + 1)) === "fallback" && n[s] === ie)
|
|
328
457
|
return t;
|
|
329
458
|
}
|
|
330
459
|
}
|
|
331
|
-
function
|
|
460
|
+
function ue(e) {
|
|
332
461
|
return typeof e == "object" && e !== null && e.type === "element";
|
|
333
462
|
}
|
|
334
|
-
function
|
|
463
|
+
function Ge(e) {
|
|
335
464
|
return /^(pf|xhtml):/.test(e.name);
|
|
336
465
|
}
|
|
337
|
-
function
|
|
338
|
-
const n = [], o = e.children.find(
|
|
466
|
+
function Ve(e, r, t) {
|
|
467
|
+
const n = [], o = e.children.find(ue);
|
|
339
468
|
if (o) {
|
|
340
469
|
const s = t?.parentId ?? "root";
|
|
341
|
-
|
|
470
|
+
de(o, s, t?.position ?? 1, r, s, n);
|
|
342
471
|
}
|
|
343
472
|
return n;
|
|
344
473
|
}
|
|
345
|
-
function
|
|
346
|
-
const a =
|
|
474
|
+
function de(e, r, t, n, o, s) {
|
|
475
|
+
const a = Ke(e) ?? n;
|
|
347
476
|
let i, u;
|
|
348
|
-
if (
|
|
477
|
+
if (Ge(e))
|
|
349
478
|
u = "root";
|
|
350
479
|
else {
|
|
351
480
|
const f = e.attributes.label ?? e.attributes["xml:id"];
|
|
@@ -360,7 +489,7 @@ function ue(e, r, t, n, o, s) {
|
|
|
360
489
|
}
|
|
361
490
|
let c = 0;
|
|
362
491
|
for (const f of e.children)
|
|
363
|
-
|
|
492
|
+
ue(f) && (c += 1, de(
|
|
364
493
|
f,
|
|
365
494
|
u,
|
|
366
495
|
c,
|
|
@@ -369,61 +498,61 @@ function ue(e, r, t, n, o, s) {
|
|
|
369
498
|
s
|
|
370
499
|
));
|
|
371
500
|
}
|
|
372
|
-
function
|
|
501
|
+
function Tt(e, r) {
|
|
373
502
|
let t;
|
|
374
503
|
for (const n of e)
|
|
375
504
|
n.line <= r && (t = n);
|
|
376
505
|
return t ?? e[0];
|
|
377
506
|
}
|
|
378
|
-
function
|
|
507
|
+
function Ze(e) {
|
|
379
508
|
const r = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
|
|
380
509
|
return /<\s*slide(?:show)?[\s/>]/.test(r) ? "slides" : "html";
|
|
381
510
|
}
|
|
382
|
-
function
|
|
383
|
-
return
|
|
511
|
+
function Qe() {
|
|
512
|
+
return Pe(I(), "xsl");
|
|
384
513
|
}
|
|
385
|
-
function
|
|
514
|
+
function et() {
|
|
386
515
|
return "Suspending" in WebAssembly;
|
|
387
516
|
}
|
|
388
|
-
function
|
|
389
|
-
if (!
|
|
517
|
+
function tt() {
|
|
518
|
+
if (!et())
|
|
390
519
|
throw new Error(
|
|
391
520
|
"WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
|
|
392
521
|
);
|
|
393
522
|
}
|
|
394
|
-
function
|
|
523
|
+
function Y(e) {
|
|
395
524
|
return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
|
|
396
525
|
}
|
|
397
|
-
function
|
|
526
|
+
function rt(e) {
|
|
398
527
|
return e.replace(
|
|
399
528
|
/from '\.\/(https:\/\/[^']+)'/g,
|
|
400
529
|
(r, t) => `from '${t}'`
|
|
401
530
|
);
|
|
402
531
|
}
|
|
403
|
-
const
|
|
404
|
-
function
|
|
532
|
+
const nt = "https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@latest/dist/";
|
|
533
|
+
function ot(e) {
|
|
405
534
|
return e.replace(
|
|
406
535
|
/(<link\b[^>]*\bhref=["'])_static\//gi,
|
|
407
|
-
`$1${
|
|
536
|
+
`$1${nt}_static/`
|
|
408
537
|
);
|
|
409
538
|
}
|
|
410
|
-
function
|
|
539
|
+
function st(e) {
|
|
411
540
|
return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
|
|
412
541
|
}
|
|
413
|
-
async function
|
|
414
|
-
const r = await
|
|
542
|
+
async function q(e) {
|
|
543
|
+
const r = await j(e);
|
|
415
544
|
if (r === void 0)
|
|
416
545
|
throw new Error(
|
|
417
546
|
`Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
|
|
418
547
|
);
|
|
419
548
|
return r;
|
|
420
549
|
}
|
|
421
|
-
async function
|
|
422
|
-
const t = l.resolve(e), n = await
|
|
550
|
+
async function it(e, r) {
|
|
551
|
+
const t = l.resolve(e), n = await j(t);
|
|
423
552
|
if (n !== void 0)
|
|
424
|
-
return
|
|
553
|
+
return Ye(n, t, r);
|
|
425
554
|
}
|
|
426
|
-
function
|
|
555
|
+
function at(e, r, t, n) {
|
|
427
556
|
const o = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), s = t === "slides" ? "slideshow" : r === "chapter" || r === "part" ? "book" : "article";
|
|
428
557
|
return `<pretext>
|
|
429
558
|
${n?.trim() ? `${n.trim()}
|
|
@@ -434,33 +563,33 @@ ${o}
|
|
|
434
563
|
</pretext>
|
|
435
564
|
`;
|
|
436
565
|
}
|
|
437
|
-
let
|
|
438
|
-
function
|
|
566
|
+
let fe = !1;
|
|
567
|
+
function ct(e) {
|
|
439
568
|
return e instanceof Error && /\bAborted\(/.test(e.message);
|
|
440
569
|
}
|
|
441
|
-
function
|
|
570
|
+
function lt(e) {
|
|
442
571
|
return e instanceof Error && /memory access|out of bounds/i.test(e.message);
|
|
443
572
|
}
|
|
444
|
-
function
|
|
445
|
-
if (
|
|
573
|
+
function ut() {
|
|
574
|
+
if (fe)
|
|
446
575
|
throw new Error(
|
|
447
576
|
"The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
|
|
448
577
|
);
|
|
449
578
|
}
|
|
450
|
-
function
|
|
451
|
-
if (
|
|
452
|
-
throw
|
|
579
|
+
function G(e) {
|
|
580
|
+
if (ct(e))
|
|
581
|
+
throw fe = !0, new Error(
|
|
453
582
|
"The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
|
|
454
583
|
{ cause: e }
|
|
455
584
|
);
|
|
456
|
-
if (
|
|
585
|
+
if (lt(e))
|
|
457
586
|
throw new Error(
|
|
458
587
|
"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.",
|
|
459
588
|
{ cause: e }
|
|
460
589
|
);
|
|
461
590
|
}
|
|
462
591
|
let P;
|
|
463
|
-
async function
|
|
592
|
+
async function pe() {
|
|
464
593
|
return P || (P = (async () => {
|
|
465
594
|
const [e, r] = await Promise.all([
|
|
466
595
|
import("@pretextbook/libxslt-wasm"),
|
|
@@ -469,15 +598,15 @@ async function fe() {
|
|
|
469
598
|
return r.registerAll(), e;
|
|
470
599
|
})()), P;
|
|
471
600
|
}
|
|
472
|
-
const D = /* @__PURE__ */ new Map(),
|
|
601
|
+
const D = /* @__PURE__ */ new Map(), dt = {
|
|
473
602
|
html: "preview-html.xsl",
|
|
474
603
|
slides: "preview-revealjs.xsl"
|
|
475
604
|
};
|
|
476
|
-
async function
|
|
477
|
-
const t =
|
|
605
|
+
async function ft(e, r) {
|
|
606
|
+
const t = dt[r], n = `${r}\0${e}`;
|
|
478
607
|
let o = D.get(n);
|
|
479
608
|
return o || (o = (async () => {
|
|
480
|
-
const { XmlDocument: s, XsltStylesheet: a } = await
|
|
609
|
+
const { XmlDocument: s, XsltStylesheet: a } = await pe(), i = se(e), u = await ee(I(), `/${t}`);
|
|
481
610
|
if (u === void 0)
|
|
482
611
|
throw new Error(
|
|
483
612
|
`Could not read ${t} from ${I()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
|
|
@@ -489,20 +618,20 @@ async function rt(e, r) {
|
|
|
489
618
|
return a.fromXmlDocument(f);
|
|
490
619
|
})(), D.set(n, o), o.catch(() => D.delete(n))), o;
|
|
491
620
|
}
|
|
492
|
-
let
|
|
493
|
-
function
|
|
494
|
-
const r =
|
|
495
|
-
() =>
|
|
496
|
-
() =>
|
|
621
|
+
let V = Promise.resolve();
|
|
622
|
+
function pt(e) {
|
|
623
|
+
const r = V.then(
|
|
624
|
+
() => Z(e),
|
|
625
|
+
() => Z(e)
|
|
497
626
|
);
|
|
498
|
-
return
|
|
627
|
+
return V = r.catch(() => {
|
|
499
628
|
}), r;
|
|
500
629
|
}
|
|
501
|
-
async function
|
|
502
|
-
|
|
503
|
-
const { XmlDocument: r } = await
|
|
630
|
+
async function Z(e) {
|
|
631
|
+
tt(), ut();
|
|
632
|
+
const { XmlDocument: r } = await pe(), t = l.resolve(e.sourcePath), n = l.resolve(
|
|
504
633
|
e.projectDir ?? l.dirname(t)
|
|
505
|
-
), o = e.sourceContent ?? await
|
|
634
|
+
), o = e.sourceContent ?? await q(t), s = l.relative(n, t);
|
|
506
635
|
if (s.startsWith(".."))
|
|
507
636
|
throw new Error(
|
|
508
637
|
`sourcePath (${t}) must live inside projectDir (${n})`
|
|
@@ -510,92 +639,92 @@ async function q(e) {
|
|
|
510
639
|
const a = l.relative(
|
|
511
640
|
n,
|
|
512
641
|
l.resolve(e.mainSourcePath ?? t)
|
|
513
|
-
), i = a.startsWith("..") ? s : a, u =
|
|
642
|
+
), i = a.startsWith("..") ? s : a, u = se(n);
|
|
514
643
|
try {
|
|
515
644
|
let c, f = `${u}/__pretext-preview-publication.xml`;
|
|
516
645
|
if (e.publicationPath) {
|
|
517
646
|
const d = l.resolve(e.publicationPath);
|
|
518
|
-
c = await
|
|
647
|
+
c = await q(d);
|
|
519
648
|
const v = l.relative(n, d);
|
|
520
649
|
v.startsWith("..") || (f = `${u}/${v.split(l.sep).join("/")}`);
|
|
521
650
|
}
|
|
522
|
-
let
|
|
651
|
+
let p, m;
|
|
523
652
|
if (e.sourceMap) {
|
|
524
|
-
const d = await
|
|
653
|
+
const d = await ae(
|
|
525
654
|
o,
|
|
526
655
|
t,
|
|
527
656
|
n
|
|
528
657
|
);
|
|
529
|
-
|
|
658
|
+
p = d.tree, m = d.content;
|
|
530
659
|
} else
|
|
531
|
-
m = await
|
|
660
|
+
m = await Je(
|
|
532
661
|
o,
|
|
533
662
|
t,
|
|
534
663
|
n
|
|
535
664
|
);
|
|
536
|
-
const
|
|
665
|
+
const h = e.target ?? Ze(m), me = await ft(e.xslDir ?? Qe(), h), M = Ne(c, {
|
|
537
666
|
cssTheme: e.cssTheme,
|
|
538
667
|
revealTheme: e.revealTheme,
|
|
539
|
-
target:
|
|
668
|
+
target: h
|
|
540
669
|
});
|
|
541
|
-
|
|
542
|
-
const
|
|
543
|
-
external: l.resolve(
|
|
544
|
-
generated: l.resolve(
|
|
545
|
-
} : void 0,
|
|
546
|
-
let
|
|
547
|
-
if (
|
|
670
|
+
Fe(f, M);
|
|
671
|
+
const E = He(M), C = l.dirname(l.resolve(n, i)), X = E.external !== void 0 && E.generated !== void 0 ? {
|
|
672
|
+
external: l.resolve(C, E.external),
|
|
673
|
+
generated: l.resolve(C, E.generated)
|
|
674
|
+
} : void 0, T = st(m);
|
|
675
|
+
let F = { parentId: "root", position: 1 };
|
|
676
|
+
if (T !== "pretext" && T !== "mathbook")
|
|
548
677
|
if (e.fragment) {
|
|
549
|
-
const d = e.docinfo ?? (e.docinfoSourcePath ? await
|
|
550
|
-
m =
|
|
678
|
+
const d = e.docinfo ?? (e.docinfoSourcePath ? await it(e.docinfoSourcePath, n) : void 0);
|
|
679
|
+
m = at(
|
|
551
680
|
m,
|
|
552
|
-
|
|
553
|
-
|
|
681
|
+
T,
|
|
682
|
+
h,
|
|
554
683
|
d
|
|
555
|
-
),
|
|
684
|
+
), F = { parentId: d?.trim() ? "root-1-2" : "root-1-1", position: 2 };
|
|
556
685
|
} else
|
|
557
686
|
throw new Error(
|
|
558
|
-
`The document root is <${
|
|
687
|
+
`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.`
|
|
559
688
|
);
|
|
560
|
-
const
|
|
689
|
+
const _ = p ? Ve(p, t, F) : void 0, O = await r.fromString(m, {
|
|
561
690
|
url: `${u}/${i.split(l.sep).join("/")}`,
|
|
562
691
|
options: { noEnt: !0, dtdLoad: !0, huge: !0 }
|
|
563
|
-
}),
|
|
564
|
-
publisher:
|
|
692
|
+
}), W = {
|
|
693
|
+
publisher: Y(f)
|
|
565
694
|
};
|
|
566
695
|
for (const [d, v] of Object.entries(e.stringParams ?? {}))
|
|
567
|
-
|
|
696
|
+
W[d] = Y(v);
|
|
568
697
|
let k;
|
|
569
698
|
try {
|
|
570
|
-
k = await
|
|
699
|
+
k = await me.apply(O, W);
|
|
571
700
|
} catch (d) {
|
|
572
|
-
throw
|
|
701
|
+
throw G(d), new Error(
|
|
573
702
|
"PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
|
|
574
703
|
{ cause: d }
|
|
575
704
|
);
|
|
576
705
|
} finally {
|
|
577
|
-
|
|
706
|
+
O.delete();
|
|
578
707
|
}
|
|
579
708
|
try {
|
|
580
|
-
let d =
|
|
581
|
-
return (e.openKnowls ?? !0) && (d =
|
|
709
|
+
let d = rt(k.toHtmlString());
|
|
710
|
+
return (e.openKnowls ?? !0) && (d = Ae(d)), h === "slides" ? (d = ot(d), d = we(d, e.revealView ?? "scroll", {
|
|
582
711
|
zoom: e.revealZoom
|
|
583
|
-
})) : e.theme && (d =
|
|
712
|
+
})) : e.theme && (d = be(d, e.theme)), e.previewBanner && (d = ke(d, e.previewBanner)), {
|
|
584
713
|
html: d,
|
|
585
|
-
target:
|
|
586
|
-
...
|
|
587
|
-
...
|
|
714
|
+
target: h,
|
|
715
|
+
..._ ? { sourceMap: _ } : {},
|
|
716
|
+
...X ? { assetDirs: X } : {}
|
|
588
717
|
};
|
|
589
718
|
} catch (d) {
|
|
590
|
-
throw
|
|
719
|
+
throw G(d), d;
|
|
591
720
|
} finally {
|
|
592
721
|
k.delete();
|
|
593
722
|
}
|
|
594
723
|
} finally {
|
|
595
|
-
|
|
724
|
+
Xe(u);
|
|
596
725
|
}
|
|
597
726
|
}
|
|
598
|
-
const
|
|
727
|
+
const Q = `Usage: pretext-html <source.ptx> [options]
|
|
599
728
|
|
|
600
729
|
Render a PreTeXt document to a single standalone HTML page (portable build:
|
|
601
730
|
one page, css/js/MathJax from CDN). No PreTeXt installation required.
|
|
@@ -628,7 +757,7 @@ Options:
|
|
|
628
757
|
are previews of work in progress
|
|
629
758
|
-h, --help Show this help
|
|
630
759
|
`;
|
|
631
|
-
function
|
|
760
|
+
function mt(e) {
|
|
632
761
|
let r, t, n, o;
|
|
633
762
|
const s = {}, a = {};
|
|
634
763
|
for (let i = 0; i < e.length; i++) {
|
|
@@ -640,7 +769,7 @@ function ot(e) {
|
|
|
640
769
|
switch (u) {
|
|
641
770
|
case "-h":
|
|
642
771
|
case "--help":
|
|
643
|
-
b.stdout.write(
|
|
772
|
+
b.stdout.write(Q), b.exit(0);
|
|
644
773
|
break;
|
|
645
774
|
case "-o":
|
|
646
775
|
case "--output":
|
|
@@ -674,10 +803,10 @@ function ot(e) {
|
|
|
674
803
|
o = c(), s.sourceMap = !0;
|
|
675
804
|
break;
|
|
676
805
|
case "--param": {
|
|
677
|
-
const f = c(),
|
|
678
|
-
if (
|
|
806
|
+
const f = c(), p = f.indexOf("=");
|
|
807
|
+
if (p === -1)
|
|
679
808
|
throw new Error(`--param expects name=value, got: ${f}`);
|
|
680
|
-
a[f.slice(0,
|
|
809
|
+
a[f.slice(0, p)] = f.slice(p + 1);
|
|
681
810
|
break;
|
|
682
811
|
}
|
|
683
812
|
default:
|
|
@@ -691,7 +820,7 @@ function ot(e) {
|
|
|
691
820
|
if (!r)
|
|
692
821
|
throw new Error(`No source file given.
|
|
693
822
|
|
|
694
|
-
` +
|
|
823
|
+
` + Q);
|
|
695
824
|
return Object.keys(a).length > 0 && (s.stringParams = a), {
|
|
696
825
|
options: { ...s, sourcePath: r },
|
|
697
826
|
output: t,
|
|
@@ -699,26 +828,29 @@ function ot(e) {
|
|
|
699
828
|
sourceMapPath: o
|
|
700
829
|
};
|
|
701
830
|
}
|
|
702
|
-
async function
|
|
703
|
-
const { options: r, output: t, docinfoPath: n, sourceMapPath: o } =
|
|
704
|
-
n && (r.docinfo = await
|
|
705
|
-
const s = Date.now(), { html: a, sourceMap: i } = await
|
|
831
|
+
async function $t(e) {
|
|
832
|
+
const { options: r, output: t, docinfoPath: n, sourceMapPath: o } = mt(e);
|
|
833
|
+
n && (r.docinfo = await A(n, "utf8"));
|
|
834
|
+
const s = Date.now(), { html: a, sourceMap: i } = await pt(r);
|
|
706
835
|
b.stderr.write(`pretext-html: rendered in ${Date.now() - s}ms
|
|
707
|
-
`), o && i && (await
|
|
708
|
-
`)), t ? (await
|
|
836
|
+
`), o && i && (await U(o, JSON.stringify(i, null, 2)), b.stderr.write(`pretext-html: wrote ${o}
|
|
837
|
+
`)), t ? (await U(t, a), b.stderr.write(`pretext-html: wrote ${t}
|
|
709
838
|
`)) : b.stdout.write(a);
|
|
710
839
|
}
|
|
711
840
|
export {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
841
|
+
ge as P,
|
|
842
|
+
Ze as a,
|
|
843
|
+
Ne as b,
|
|
844
|
+
et as c,
|
|
845
|
+
Qe as d,
|
|
846
|
+
Et as e,
|
|
847
|
+
Tt as f,
|
|
848
|
+
mt as g,
|
|
849
|
+
ke as i,
|
|
850
|
+
$t as m,
|
|
851
|
+
Ae as o,
|
|
852
|
+
Ee as p,
|
|
853
|
+
pt as r,
|
|
854
|
+
yt as s,
|
|
855
|
+
Y as x
|
|
724
856
|
};
|