@pretextbook/pretext-html 0.3.0 → 0.4.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 +20 -9
- package/assets/preview-html.xsl +8 -4
- package/assets/upstream.json +1 -1
- package/assets/xsl/README.md +25 -24
- package/assets/xsl/entities.ent +20 -0
- package/assets/xsl/extract-biblio-csl.xsl +1 -1
- package/assets/xsl/extract-pg.xsl +111 -297
- package/assets/xsl/extract-qrcode.xsl +11 -1
- package/assets/xsl/extract-sageplot.xsl +1 -1
- package/assets/xsl/latex/pretext-latex-texstyle.xsl +1 -2
- package/assets/xsl/localizations/README.md +24 -24
- package/assets/xsl/pretext-assembly.xsl +101 -11
- package/assets/xsl/pretext-beamer.xsl +43 -146
- package/assets/xsl/pretext-braille-preprint.xsl +457 -201
- package/assets/xsl/pretext-common.xsl +388 -423
- package/assets/xsl/pretext-epub.xsl +301 -72
- package/assets/xsl/pretext-fo.xsl +70 -86
- package/assets/xsl/pretext-html.xsl +331 -259
- package/assets/xsl/pretext-jupyter.xsl +534 -322
- package/assets/xsl/pretext-latex-classic.xsl +14 -15
- package/assets/xsl/pretext-latex-common.xsl +385 -2389
- package/assets/xsl/pretext-latex.xsl +1995 -5
- package/assets/xsl/pretext-markdown.xsl +919 -0
- package/assets/xsl/pretext-numbers.xsl +22 -4
- package/assets/xsl/pretext-revealjs.xsl +241 -33
- package/assets/xsl/pretext-runestone-fitb.xsl +20 -22
- package/assets/xsl/pretext-runestone.xsl +3 -3
- package/assets/xsl/pretext-sage-doctest.xsl +2 -2
- package/assets/xsl/pretext-text-utilities.xsl +69 -1
- package/assets/xsl/pretext-text.xsl +1077 -107
- package/assets/xsl/publisher-variables.xsl +396 -452
- 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/utilities/report-publisher-variables.xsl +15 -0
- package/assets/xsl-bundle.json +1 -1
- package/dist/{cli-CzoinNle.js → cli-Cp6C0sif.js} +220 -205
- package/dist/cli.js +1 -1
- package/dist/index.browser.js +351 -342
- package/dist/index.js +1 -1
- package/dist/publication.d.ts +9 -1
- package/dist/renderer.d.ts +20 -0
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
1
1
|
import { fromXml as x } from "xast-util-from-xml";
|
|
2
|
-
import { toXml as
|
|
3
|
-
const
|
|
2
|
+
import { toXml as T } from "xast-util-to-xml";
|
|
3
|
+
const _ = "/";
|
|
4
4
|
function me(e) {
|
|
5
5
|
if (!e)
|
|
6
6
|
return ".";
|
|
7
|
-
const
|
|
8
|
-
for (const
|
|
9
|
-
if (!(!
|
|
10
|
-
if (
|
|
7
|
+
const n = e.startsWith("/"), t = e.length > 1 && e.endsWith("/"), r = [];
|
|
8
|
+
for (const o of e.split("/"))
|
|
9
|
+
if (!(!o || o === ".")) {
|
|
10
|
+
if (o === "..") {
|
|
11
11
|
const s = r[r.length - 1];
|
|
12
|
-
r.length > 0 && s !== ".." ? r.pop() :
|
|
12
|
+
r.length > 0 && s !== ".." ? r.pop() : n || r.push("..");
|
|
13
13
|
continue;
|
|
14
14
|
}
|
|
15
|
-
r.push(
|
|
15
|
+
r.push(o);
|
|
16
16
|
}
|
|
17
|
-
let
|
|
18
|
-
return
|
|
17
|
+
let i = r.join("/");
|
|
18
|
+
return n && (i = `/${i}`), i ? (t && !i.endsWith("/") && (i += "/"), i) : n ? "/" : ".";
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
let
|
|
20
|
+
function f(...e) {
|
|
21
|
+
let n = "";
|
|
22
22
|
for (let r = e.length - 1; r >= 0; r--) {
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
23
|
+
const i = e[r];
|
|
24
|
+
if (i && (n = n ? `${i}/${n}` : i, i.startsWith("/")))
|
|
25
25
|
break;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
return
|
|
27
|
+
n.startsWith("/") || (n = `/${n}`);
|
|
28
|
+
const t = me(n);
|
|
29
|
+
return t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
const
|
|
33
|
-
if (!
|
|
31
|
+
function y(e) {
|
|
32
|
+
const n = e.replace(/\/+$/, "");
|
|
33
|
+
if (!n)
|
|
34
34
|
return e.startsWith("/") ? "/" : ".";
|
|
35
|
-
const
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
function S(e,
|
|
39
|
-
const
|
|
40
|
-
let
|
|
41
|
-
for (;
|
|
42
|
-
|
|
43
|
-
return [...new Array(
|
|
44
|
-
}
|
|
45
|
-
const pe = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.
|
|
46
|
-
let
|
|
47
|
-
function
|
|
48
|
-
|
|
35
|
+
const t = n.lastIndexOf("/");
|
|
36
|
+
return t < 0 ? "." : t === 0 ? "/" : n.slice(0, t);
|
|
37
|
+
}
|
|
38
|
+
function S(e, n) {
|
|
39
|
+
const t = f(e).split("/").filter(Boolean), r = f(n).split("/").filter(Boolean);
|
|
40
|
+
let i = 0;
|
|
41
|
+
for (; i < t.length && i < r.length && t[i] === r[i]; )
|
|
42
|
+
i += 1;
|
|
43
|
+
return [...new Array(t.length - i).fill(".."), ...r.slice(i)].join("/");
|
|
44
|
+
}
|
|
45
|
+
const pe = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.4.0/assets";
|
|
46
|
+
let Q;
|
|
47
|
+
function Ve(e) {
|
|
48
|
+
Q = e.replace(/\/+$/, "");
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
return
|
|
50
|
+
function $() {
|
|
51
|
+
return Q ?? pe;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
return `${e.replace(/\/+$/, "")}/${
|
|
53
|
+
function Z(e, n) {
|
|
54
|
+
return `${e.replace(/\/+$/, "")}/${n.replace(/^\/+/, "")}`;
|
|
55
55
|
}
|
|
56
|
-
const
|
|
56
|
+
const O = /* @__PURE__ */ new Map();
|
|
57
57
|
function we(e) {
|
|
58
58
|
return `${e.replace(/\/+$/, "")}-bundle.json`;
|
|
59
59
|
}
|
|
60
60
|
function ge(e) {
|
|
61
|
-
let
|
|
62
|
-
return
|
|
61
|
+
let n = O.get(e);
|
|
62
|
+
return n || (n = (async () => {
|
|
63
63
|
try {
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
64
|
+
const t = await fetch(we(e));
|
|
65
|
+
if (!t.ok)
|
|
66
66
|
return /* @__PURE__ */ new Map();
|
|
67
|
-
const r = await
|
|
67
|
+
const r = await t.json();
|
|
68
68
|
return new Map(Object.entries(r));
|
|
69
69
|
} catch {
|
|
70
70
|
return /* @__PURE__ */ new Map();
|
|
71
71
|
}
|
|
72
|
-
})(),
|
|
72
|
+
})(), O.set(e, n)), n;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
return e ===
|
|
74
|
+
function be(e) {
|
|
75
|
+
return e === Z($(), "xsl");
|
|
76
76
|
}
|
|
77
|
-
async function
|
|
78
|
-
if (
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
return new TextEncoder().encode(
|
|
77
|
+
async function ee(e, n) {
|
|
78
|
+
if (be(e)) {
|
|
79
|
+
const o = (await ge(e)).get(n.replace(/^\/+/, ""));
|
|
80
|
+
if (o !== void 0)
|
|
81
|
+
return new TextEncoder().encode(o);
|
|
82
82
|
}
|
|
83
|
-
const
|
|
83
|
+
const t = `${e.replace(/\/+$/, "")}/`;
|
|
84
84
|
let r;
|
|
85
85
|
try {
|
|
86
|
-
r = new URL(
|
|
86
|
+
r = new URL(n.replace(/^\/+/, ""), t);
|
|
87
87
|
} catch {
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
|
-
if (!r.href.startsWith(
|
|
90
|
+
if (!r.href.startsWith(t)) {
|
|
91
91
|
console.error(
|
|
92
|
-
`pretext-html: refusing to serve ${
|
|
92
|
+
`pretext-html: refusing to serve ${n} from outside ${e}`
|
|
93
93
|
);
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
96
|
try {
|
|
97
|
-
const
|
|
98
|
-
return
|
|
97
|
+
const i = await fetch(r.href);
|
|
98
|
+
return i.ok ? new Uint8Array(await i.arrayBuffer()) : void 0;
|
|
99
99
|
} catch {
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
async function
|
|
103
|
+
async function R(e) {
|
|
104
104
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(e))
|
|
105
105
|
try {
|
|
106
|
-
const
|
|
107
|
-
return
|
|
106
|
+
const n = await fetch(e);
|
|
107
|
+
return n.ok ? await n.text() : void 0;
|
|
108
108
|
} catch {
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
const
|
|
113
|
-
let
|
|
114
|
-
function
|
|
115
|
-
|
|
112
|
+
const j = /* @__PURE__ */ new Map(), te = /* @__PURE__ */ new Map();
|
|
113
|
+
let P, ye = 0, ne = ee;
|
|
114
|
+
function Qe(e) {
|
|
115
|
+
ne = e;
|
|
116
116
|
}
|
|
117
|
-
function ve(e,
|
|
118
|
-
const
|
|
117
|
+
function ve(e, n) {
|
|
118
|
+
const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = te.get(t);
|
|
119
119
|
if (r !== void 0)
|
|
120
120
|
return Promise.resolve(new Response(r, { status: 200 }));
|
|
121
|
-
let
|
|
121
|
+
let i;
|
|
122
122
|
try {
|
|
123
|
-
|
|
123
|
+
i = new URL(t).host;
|
|
124
124
|
} catch {
|
|
125
|
-
|
|
125
|
+
i = "";
|
|
126
126
|
}
|
|
127
|
-
const
|
|
128
|
-
return
|
|
127
|
+
const o = j.get(i);
|
|
128
|
+
return o !== void 0 ? Ee(o, t) : P(e, n);
|
|
129
129
|
}
|
|
130
130
|
const xe = '<?xml version="1.0"?><pretext-preview-missing-file/>';
|
|
131
|
-
async function Ee(e,
|
|
132
|
-
const
|
|
131
|
+
async function Ee(e, n) {
|
|
132
|
+
const t = decodeURIComponent(new URL(n).pathname), r = await ne(e, t);
|
|
133
133
|
if (r === void 0)
|
|
134
134
|
return new Response(xe, { status: 200 });
|
|
135
|
-
const
|
|
136
|
-
return new Response(
|
|
135
|
+
const i = typeof r == "string" ? r : new Uint8Array(r);
|
|
136
|
+
return new Response(i, { status: 200 });
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
|
|
138
|
+
function re() {
|
|
139
|
+
P || (P = globalThis.fetch, globalThis.fetch = ve);
|
|
140
140
|
}
|
|
141
|
-
function
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
return
|
|
141
|
+
function ie(e) {
|
|
142
|
+
re();
|
|
143
|
+
const n = `mnt${++ye}.ptx.invalid`;
|
|
144
|
+
return j.set(n, e), `http://${n}`;
|
|
145
145
|
}
|
|
146
|
-
function
|
|
147
|
-
|
|
146
|
+
function Te(e) {
|
|
147
|
+
j.delete(new URL(e).host);
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
|
|
149
|
+
function $e(e, n) {
|
|
150
|
+
re(), te.set(e, n);
|
|
151
151
|
}
|
|
152
|
-
const
|
|
152
|
+
const L = `<?xml version="1.0" encoding="UTF-8"?>
|
|
153
153
|
<publication>
|
|
154
154
|
<source>
|
|
155
155
|
<directories external="../assets" generated="../generated-assets" />
|
|
@@ -158,181 +158,189 @@ const oe = `<?xml version="1.0" encoding="UTF-8"?>
|
|
|
158
158
|
<platform portable="yes"/>
|
|
159
159
|
</html>
|
|
160
160
|
</publication>
|
|
161
|
-
|
|
162
|
-
function
|
|
163
|
-
for (const
|
|
164
|
-
if (
|
|
165
|
-
return
|
|
166
|
-
}
|
|
167
|
-
function
|
|
168
|
-
let
|
|
169
|
-
return
|
|
170
|
-
}
|
|
171
|
-
function
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
161
|
+
`, Me = ["theme", "style", "shell"];
|
|
162
|
+
function w(e, n) {
|
|
163
|
+
for (const t of e.children)
|
|
164
|
+
if (t.type === "element" && t.name === n)
|
|
165
|
+
return t;
|
|
166
|
+
}
|
|
167
|
+
function F(e, n) {
|
|
168
|
+
let t = w(e, n);
|
|
169
|
+
return t || (t = { type: "element", name: n, attributes: {}, children: [] }, e.children.push(t)), t;
|
|
170
|
+
}
|
|
171
|
+
function ke(e, n) {
|
|
172
|
+
const t = w(e, "css");
|
|
173
|
+
if (t && Me.some((i) => t.attributes?.[i]))
|
|
174
|
+
return;
|
|
175
|
+
const r = t ?? F(e, "css");
|
|
176
|
+
r.attributes = { ...r.attributes, theme: n };
|
|
177
|
+
}
|
|
178
|
+
function De(e, n) {
|
|
179
|
+
const t = n?.trim();
|
|
180
|
+
if (!e && !t)
|
|
181
|
+
return L;
|
|
182
|
+
const r = x(e ?? L), i = w(r, "publication");
|
|
183
|
+
if (!i)
|
|
176
184
|
throw new Error(
|
|
177
185
|
"Invalid publication file: no root <publication> element found"
|
|
178
186
|
);
|
|
179
|
-
const
|
|
180
|
-
return
|
|
187
|
+
const o = F(i, "html"), s = F(o, "platform");
|
|
188
|
+
return s.attributes = { ...s.attributes, portable: "yes" }, t && ke(o, t), T(r);
|
|
181
189
|
}
|
|
182
|
-
function
|
|
190
|
+
function N(e) {
|
|
183
191
|
if (!(e === void 0 || e === "" || e.startsWith("/")))
|
|
184
192
|
return e.endsWith("/") ? e : `${e}/`;
|
|
185
193
|
}
|
|
186
|
-
function
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
), s =
|
|
190
|
-
|
|
194
|
+
function Se(e) {
|
|
195
|
+
const n = x(e ?? L), t = w(n, "publication"), r = t && w(t, "source"), i = r && w(r, "directories"), o = N(
|
|
196
|
+
i?.attributes?.external ?? void 0
|
|
197
|
+
), s = N(
|
|
198
|
+
i?.attributes?.generated ?? void 0
|
|
191
199
|
);
|
|
192
200
|
return {
|
|
193
|
-
external:
|
|
201
|
+
external: o,
|
|
194
202
|
generated: s,
|
|
195
|
-
managed:
|
|
203
|
+
managed: o !== void 0 && s !== void 0
|
|
196
204
|
};
|
|
197
205
|
}
|
|
198
|
-
const
|
|
199
|
-
async function
|
|
200
|
-
return e.includes("include") ? (await se(e,
|
|
206
|
+
const oe = "http://www.w3.org/2001/XInclude", z = 64;
|
|
207
|
+
async function Ie(e, n, t) {
|
|
208
|
+
return e.includes("include") ? (await se(e, n, t)).content : e;
|
|
201
209
|
}
|
|
202
|
-
async function se(e,
|
|
203
|
-
const r = x(e),
|
|
204
|
-
projectDir:
|
|
205
|
-
stack: [
|
|
206
|
-
},
|
|
210
|
+
async function se(e, n, t) {
|
|
211
|
+
const r = x(e), i = {
|
|
212
|
+
projectDir: f(t),
|
|
213
|
+
stack: [f(n)]
|
|
214
|
+
}, o = await v(
|
|
207
215
|
r,
|
|
208
|
-
|
|
216
|
+
y(f(n)),
|
|
209
217
|
{ "": "" },
|
|
210
|
-
|
|
218
|
+
i
|
|
211
219
|
);
|
|
212
|
-
return { tree: r, content:
|
|
220
|
+
return { tree: r, content: o ? T(r) : e };
|
|
213
221
|
}
|
|
214
|
-
function
|
|
222
|
+
function Ae(e) {
|
|
215
223
|
return e.data?.ptxIncludedFile;
|
|
216
224
|
}
|
|
217
|
-
function
|
|
218
|
-
const
|
|
219
|
-
|
|
225
|
+
function _e(e, n) {
|
|
226
|
+
const t = e.data ?? (e.data = {});
|
|
227
|
+
t.ptxIncludedFile = n;
|
|
220
228
|
}
|
|
221
|
-
function
|
|
222
|
-
let
|
|
223
|
-
for (const [r,
|
|
224
|
-
(r === "xmlns" || r.startsWith("xmlns:")) && (
|
|
225
|
-
return
|
|
229
|
+
function M(e, n) {
|
|
230
|
+
let t = e;
|
|
231
|
+
for (const [r, i] of Object.entries(n.attributes))
|
|
232
|
+
(r === "xmlns" || r.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
|
|
233
|
+
return t;
|
|
226
234
|
}
|
|
227
|
-
function ae(e,
|
|
228
|
-
const
|
|
229
|
-
return (
|
|
235
|
+
function ae(e, n) {
|
|
236
|
+
const t = e.name.indexOf(":"), r = t === -1 ? "" : e.name.slice(0, t);
|
|
237
|
+
return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === oe;
|
|
230
238
|
}
|
|
231
|
-
async function v(e,
|
|
232
|
-
let
|
|
233
|
-
for (let
|
|
234
|
-
const s = e.children[
|
|
239
|
+
async function v(e, n, t, r) {
|
|
240
|
+
let i = !1;
|
|
241
|
+
for (let o = 0; o < e.children.length; o++) {
|
|
242
|
+
const s = e.children[o];
|
|
235
243
|
if (s.type !== "element")
|
|
236
244
|
continue;
|
|
237
|
-
const a =
|
|
245
|
+
const a = M(t, s);
|
|
238
246
|
if (ae(s, a)) {
|
|
239
|
-
const
|
|
247
|
+
const u = await ce(
|
|
240
248
|
s,
|
|
241
|
-
|
|
249
|
+
n,
|
|
242
250
|
a,
|
|
243
251
|
r
|
|
244
252
|
);
|
|
245
|
-
e.children.splice(
|
|
246
|
-
} else await v(s,
|
|
253
|
+
e.children.splice(o, 1, ...u), o += u.length - 1, i = !0;
|
|
254
|
+
} else await v(s, n, a, r) && (i = !0);
|
|
247
255
|
}
|
|
248
|
-
return
|
|
256
|
+
return i;
|
|
249
257
|
}
|
|
250
|
-
async function ce(e,
|
|
251
|
-
const
|
|
258
|
+
async function ce(e, n, t, r) {
|
|
259
|
+
const i = r.stack[r.stack.length - 1];
|
|
252
260
|
if (e.attributes.xpointer)
|
|
253
261
|
throw new Error(
|
|
254
|
-
`xi:include with xpointer is not supported by the JS preview build (in ${
|
|
262
|
+
`xi:include with xpointer is not supported by the JS preview build (in ${i})`
|
|
255
263
|
);
|
|
256
|
-
const
|
|
257
|
-
if (!
|
|
258
|
-
throw new Error(`xi:include without href (in ${
|
|
259
|
-
let s =
|
|
264
|
+
const o = e.attributes.href;
|
|
265
|
+
if (!o)
|
|
266
|
+
throw new Error(`xi:include without href (in ${i})`);
|
|
267
|
+
let s = o;
|
|
260
268
|
try {
|
|
261
|
-
s = decodeURIComponent(
|
|
269
|
+
s = decodeURIComponent(o);
|
|
262
270
|
} catch {
|
|
263
271
|
}
|
|
264
|
-
const a =
|
|
265
|
-
if (a !== r.projectDir && !a.startsWith(r.projectDir +
|
|
272
|
+
const a = f(n, s);
|
|
273
|
+
if (a !== r.projectDir && !a.startsWith(r.projectDir + _))
|
|
266
274
|
throw new Error(
|
|
267
|
-
`xi:include escapes the project directory: ${
|
|
275
|
+
`xi:include escapes the project directory: ${o} (in ${i})`
|
|
268
276
|
);
|
|
269
277
|
if (r.stack.includes(a))
|
|
270
278
|
throw new Error(
|
|
271
279
|
`Circular xi:include: ${[...r.stack, a].join(" -> ")}`
|
|
272
280
|
);
|
|
273
|
-
if (r.stack.length >=
|
|
274
|
-
throw new Error(`xi:include nesting exceeds ${
|
|
275
|
-
const
|
|
276
|
-
if (
|
|
277
|
-
const
|
|
278
|
-
if (
|
|
279
|
-
return await v(
|
|
280
|
-
throw new Error(`xi:include target not found: ${
|
|
281
|
+
if (r.stack.length >= z)
|
|
282
|
+
throw new Error(`xi:include nesting exceeds ${z} levels`);
|
|
283
|
+
const u = await R(a);
|
|
284
|
+
if (u === void 0) {
|
|
285
|
+
const d = Le(e, t);
|
|
286
|
+
if (d)
|
|
287
|
+
return await v(d, n, t, r), d.children;
|
|
288
|
+
throw new Error(`xi:include target not found: ${o} (in ${i})`);
|
|
281
289
|
}
|
|
282
290
|
if (e.attributes.parse === "text")
|
|
283
|
-
return [{ type: "text", value:
|
|
291
|
+
return [{ type: "text", value: u }];
|
|
284
292
|
let c;
|
|
285
293
|
try {
|
|
286
|
-
c = x(
|
|
287
|
-
} catch (
|
|
294
|
+
c = x(u);
|
|
295
|
+
} catch (d) {
|
|
288
296
|
throw new Error(
|
|
289
|
-
`Could not parse xi:include target ${a} as XML: ${
|
|
297
|
+
`Could not parse xi:include target ${a} as XML: ${d instanceof Error ? d.message : d}. (Included files must be well-formed, with a single root element.)`
|
|
290
298
|
);
|
|
291
299
|
}
|
|
292
300
|
r.stack.push(a);
|
|
293
301
|
try {
|
|
294
|
-
await v(c,
|
|
302
|
+
await v(c, y(a), { "": "" }, r);
|
|
295
303
|
} finally {
|
|
296
304
|
r.stack.pop();
|
|
297
305
|
}
|
|
298
|
-
const
|
|
299
|
-
(
|
|
306
|
+
const h = c.children.filter(
|
|
307
|
+
(d) => d.type === "element"
|
|
300
308
|
);
|
|
301
|
-
for (const
|
|
302
|
-
|
|
303
|
-
return
|
|
309
|
+
for (const d of h)
|
|
310
|
+
_e(d, a);
|
|
311
|
+
return h;
|
|
304
312
|
}
|
|
305
|
-
function
|
|
313
|
+
function J(e) {
|
|
306
314
|
return e.name === "docinfo";
|
|
307
315
|
}
|
|
308
|
-
async function
|
|
316
|
+
async function Pe(e, n, t) {
|
|
309
317
|
try {
|
|
310
|
-
const
|
|
318
|
+
const i = x(e).children.find(
|
|
311
319
|
(c) => c.type === "element"
|
|
312
320
|
);
|
|
313
|
-
if (!
|
|
321
|
+
if (!i)
|
|
314
322
|
return;
|
|
315
|
-
const
|
|
316
|
-
projectDir:
|
|
317
|
-
stack: [
|
|
318
|
-
},
|
|
319
|
-
for (const c of
|
|
323
|
+
const o = f(n), s = y(o), a = {
|
|
324
|
+
projectDir: f(t),
|
|
325
|
+
stack: [o]
|
|
326
|
+
}, u = M({ "": "" }, i);
|
|
327
|
+
for (const c of i.children) {
|
|
320
328
|
if (c.type !== "element")
|
|
321
329
|
continue;
|
|
322
|
-
const
|
|
323
|
-
if (
|
|
324
|
-
return await v(c, s,
|
|
325
|
-
if (ae(c,
|
|
326
|
-
const
|
|
330
|
+
const h = M(u, c);
|
|
331
|
+
if (J(c))
|
|
332
|
+
return await v(c, s, h, a), T(c);
|
|
333
|
+
if (ae(c, h)) {
|
|
334
|
+
const g = (await ce(
|
|
327
335
|
c,
|
|
328
336
|
s,
|
|
329
|
-
|
|
337
|
+
h,
|
|
330
338
|
a
|
|
331
339
|
)).find(
|
|
332
|
-
(
|
|
340
|
+
(m) => m.type === "element" && J(m)
|
|
333
341
|
);
|
|
334
|
-
if (
|
|
335
|
-
return
|
|
342
|
+
if (g)
|
|
343
|
+
return T(g);
|
|
336
344
|
continue;
|
|
337
345
|
}
|
|
338
346
|
break;
|
|
@@ -342,74 +350,74 @@ async function Ie(e, t, n) {
|
|
|
342
350
|
return;
|
|
343
351
|
}
|
|
344
352
|
}
|
|
345
|
-
function
|
|
346
|
-
for (const
|
|
347
|
-
if (
|
|
353
|
+
function Le(e, n) {
|
|
354
|
+
for (const t of e.children) {
|
|
355
|
+
if (t.type !== "element")
|
|
348
356
|
continue;
|
|
349
|
-
const r =
|
|
350
|
-
if ((
|
|
351
|
-
return
|
|
357
|
+
const r = M(n, t), i = t.name.indexOf(":"), o = i === -1 ? "" : t.name.slice(0, i);
|
|
358
|
+
if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] === oe)
|
|
359
|
+
return t;
|
|
352
360
|
}
|
|
353
361
|
}
|
|
354
362
|
function le(e) {
|
|
355
363
|
return typeof e == "object" && e !== null && e.type === "element";
|
|
356
364
|
}
|
|
357
|
-
function
|
|
365
|
+
function Fe(e) {
|
|
358
366
|
return /^(pf|xhtml):/.test(e.name);
|
|
359
367
|
}
|
|
360
|
-
function
|
|
361
|
-
const r = [],
|
|
362
|
-
if (
|
|
363
|
-
const
|
|
364
|
-
|
|
368
|
+
function Re(e, n, t) {
|
|
369
|
+
const r = [], i = e.children.find(le);
|
|
370
|
+
if (i) {
|
|
371
|
+
const o = t?.parentId ?? "root";
|
|
372
|
+
ue(i, o, t?.position ?? 1, n, o, r);
|
|
365
373
|
}
|
|
366
374
|
return r;
|
|
367
375
|
}
|
|
368
|
-
function
|
|
369
|
-
const s =
|
|
370
|
-
let a,
|
|
371
|
-
if (
|
|
372
|
-
|
|
376
|
+
function ue(e, n, t, r, i, o) {
|
|
377
|
+
const s = Ae(e) ?? r;
|
|
378
|
+
let a, u;
|
|
379
|
+
if (Fe(e))
|
|
380
|
+
u = "root";
|
|
373
381
|
else {
|
|
374
|
-
const
|
|
375
|
-
a =
|
|
382
|
+
const h = e.attributes.label ?? e.attributes["xml:id"];
|
|
383
|
+
a = h ?? `${n}-${t}`, o.push({
|
|
376
384
|
id: a,
|
|
377
385
|
file: s,
|
|
378
386
|
line: e.position?.start.line ?? 1,
|
|
379
387
|
column: e.position?.start.column ?? 1,
|
|
380
388
|
endLine: e.position?.end.line ?? e.position?.start.line ?? 1,
|
|
381
|
-
parent:
|
|
382
|
-
}),
|
|
389
|
+
parent: i
|
|
390
|
+
}), u = a;
|
|
383
391
|
}
|
|
384
392
|
let c = 0;
|
|
385
|
-
for (const
|
|
386
|
-
le(
|
|
393
|
+
for (const h of e.children)
|
|
394
|
+
le(h) && (c += 1, ue(
|
|
395
|
+
h,
|
|
387
396
|
u,
|
|
388
|
-
d,
|
|
389
397
|
c,
|
|
390
398
|
s,
|
|
391
|
-
a ??
|
|
392
|
-
|
|
399
|
+
a ?? i,
|
|
400
|
+
o
|
|
393
401
|
));
|
|
394
402
|
}
|
|
395
|
-
function
|
|
396
|
-
let
|
|
403
|
+
function Ze(e, n) {
|
|
404
|
+
let t;
|
|
397
405
|
for (const r of e)
|
|
398
|
-
r.line <=
|
|
399
|
-
return
|
|
406
|
+
r.line <= n && (t = r);
|
|
407
|
+
return t ?? e[0];
|
|
400
408
|
}
|
|
401
|
-
const
|
|
402
|
-
function
|
|
409
|
+
const de = "pretext-html:set-theme";
|
|
410
|
+
function et(e) {
|
|
403
411
|
return e === "dark" || e === "light" || e === "system";
|
|
404
412
|
}
|
|
405
|
-
function
|
|
406
|
-
return { type:
|
|
413
|
+
function tt(e) {
|
|
414
|
+
return { type: de, theme: e };
|
|
407
415
|
}
|
|
408
|
-
function
|
|
416
|
+
function je(e) {
|
|
409
417
|
return [
|
|
410
418
|
"<script>",
|
|
411
419
|
"(function () {",
|
|
412
|
-
" var CFG = " + JSON.stringify({ msg:
|
|
420
|
+
" var CFG = " + JSON.stringify({ msg: de, initial: e }) + ";",
|
|
413
421
|
// Where the last requested theme is remembered so it survives an in-place
|
|
414
422
|
// document rewrite (same Window) and outranks the baked initial value.
|
|
415
423
|
" var KEY = '__ptxPreviewTheme';",
|
|
@@ -479,79 +487,79 @@ function Le(e) {
|
|
|
479
487
|
].join(`
|
|
480
488
|
`);
|
|
481
489
|
}
|
|
482
|
-
function
|
|
483
|
-
const
|
|
490
|
+
function We(e, n) {
|
|
491
|
+
const t = je(n);
|
|
484
492
|
return /<head[^>]*>/i.test(e) ? e.replace(/<head([^>]*)>/i, `<head$1>
|
|
485
|
-
${
|
|
493
|
+
${t}`) : e;
|
|
486
494
|
}
|
|
487
|
-
function
|
|
488
|
-
return
|
|
495
|
+
function Be() {
|
|
496
|
+
return Z($(), "xsl");
|
|
489
497
|
}
|
|
490
|
-
function
|
|
498
|
+
function Ce() {
|
|
491
499
|
return "Suspending" in WebAssembly;
|
|
492
500
|
}
|
|
493
|
-
function
|
|
494
|
-
if (!
|
|
501
|
+
function Xe() {
|
|
502
|
+
if (!Ce())
|
|
495
503
|
throw new Error(
|
|
496
504
|
"WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
|
|
497
505
|
);
|
|
498
506
|
}
|
|
499
|
-
function
|
|
500
|
-
return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((
|
|
507
|
+
function Y(e) {
|
|
508
|
+
return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
|
|
501
509
|
}
|
|
502
|
-
function
|
|
510
|
+
function Ue(e) {
|
|
503
511
|
return e.replace(
|
|
504
512
|
/from '\.\/(https:\/\/[^']+)'/g,
|
|
505
|
-
(
|
|
513
|
+
(n, t) => `from '${t}'`
|
|
506
514
|
);
|
|
507
515
|
}
|
|
508
|
-
function
|
|
516
|
+
function He(e) {
|
|
509
517
|
return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
|
|
510
518
|
}
|
|
511
|
-
async function
|
|
512
|
-
const
|
|
513
|
-
if (
|
|
519
|
+
async function G(e) {
|
|
520
|
+
const n = await R(e);
|
|
521
|
+
if (n === void 0)
|
|
514
522
|
throw new Error(
|
|
515
523
|
`Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
|
|
516
524
|
);
|
|
517
|
-
return
|
|
525
|
+
return n;
|
|
518
526
|
}
|
|
519
|
-
async function
|
|
520
|
-
const
|
|
527
|
+
async function Oe(e, n) {
|
|
528
|
+
const t = f(e), r = await R(t);
|
|
521
529
|
if (r !== void 0)
|
|
522
|
-
return
|
|
530
|
+
return Pe(r, t, n);
|
|
523
531
|
}
|
|
524
|
-
function
|
|
525
|
-
const r = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""),
|
|
532
|
+
function Ne(e, n, t) {
|
|
533
|
+
const r = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), i = n === "chapter" || n === "part" ? "book" : "article";
|
|
526
534
|
return `<pretext>
|
|
527
|
-
${
|
|
528
|
-
` : ""}<${
|
|
535
|
+
${t?.trim() ? `${t.trim()}
|
|
536
|
+
` : ""}<${i}>
|
|
529
537
|
<title/>
|
|
530
538
|
${r}
|
|
531
|
-
</${
|
|
539
|
+
</${i}>
|
|
532
540
|
</pretext>
|
|
533
541
|
`;
|
|
534
542
|
}
|
|
535
543
|
let fe = !1;
|
|
536
|
-
function
|
|
544
|
+
function ze(e) {
|
|
537
545
|
return e instanceof Error && /\bAborted\(/.test(e.message);
|
|
538
546
|
}
|
|
539
|
-
function
|
|
547
|
+
function Je(e) {
|
|
540
548
|
return e instanceof Error && /memory access|out of bounds/i.test(e.message);
|
|
541
549
|
}
|
|
542
|
-
function
|
|
550
|
+
function Ye() {
|
|
543
551
|
if (fe)
|
|
544
552
|
throw new Error(
|
|
545
553
|
"The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
|
|
546
554
|
);
|
|
547
555
|
}
|
|
548
|
-
function
|
|
549
|
-
if (
|
|
556
|
+
function K(e) {
|
|
557
|
+
if (ze(e))
|
|
550
558
|
throw fe = !0, new Error(
|
|
551
559
|
"The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
|
|
552
560
|
{ cause: e }
|
|
553
561
|
);
|
|
554
|
-
if (
|
|
562
|
+
if (Je(e))
|
|
555
563
|
throw new Error(
|
|
556
564
|
"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.",
|
|
557
565
|
{ cause: e }
|
|
@@ -560,142 +568,143 @@ function G(e) {
|
|
|
560
568
|
let I;
|
|
561
569
|
async function he() {
|
|
562
570
|
return I || (I = (async () => {
|
|
563
|
-
const [e,
|
|
571
|
+
const [e, n] = await Promise.all([
|
|
564
572
|
import("@pretextbook/libxslt-wasm"),
|
|
565
573
|
import("@pretextbook/libxslt-wasm/exslt")
|
|
566
574
|
]);
|
|
567
|
-
return
|
|
575
|
+
return n.registerAll(), e;
|
|
568
576
|
})()), I;
|
|
569
577
|
}
|
|
570
578
|
const A = /* @__PURE__ */ new Map();
|
|
571
|
-
async function
|
|
572
|
-
const
|
|
573
|
-
let
|
|
574
|
-
return
|
|
575
|
-
const { XmlDocument: r, XsltStylesheet:
|
|
576
|
-
|
|
579
|
+
async function Ge(e) {
|
|
580
|
+
const n = e;
|
|
581
|
+
let t = A.get(n);
|
|
582
|
+
return t || (t = (async () => {
|
|
583
|
+
const { XmlDocument: r, XsltStylesheet: i } = await he(), o = ie(n), s = await ee(
|
|
584
|
+
$(),
|
|
577
585
|
"/preview-html.xsl"
|
|
578
586
|
);
|
|
579
587
|
if (s === void 0)
|
|
580
588
|
throw new Error(
|
|
581
|
-
`Could not read preview-html.xsl from ${
|
|
589
|
+
`Could not read preview-html.xsl from ${$()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
|
|
582
590
|
);
|
|
583
|
-
const a = new TextDecoder().decode(s),
|
|
584
|
-
url: `${
|
|
591
|
+
const a = new TextDecoder().decode(s), u = await r.fromString(a, {
|
|
592
|
+
url: `${o}/preview-html.xsl`,
|
|
585
593
|
options: { noEnt: !0, dtdLoad: !0, huge: !0 }
|
|
586
594
|
});
|
|
587
|
-
return
|
|
588
|
-
})(), A.set(
|
|
589
|
-
}
|
|
590
|
-
let
|
|
591
|
-
function
|
|
592
|
-
const
|
|
593
|
-
() =>
|
|
594
|
-
() =>
|
|
595
|
+
return i.fromXmlDocument(u);
|
|
596
|
+
})(), A.set(n, t), t.catch(() => A.delete(n))), t;
|
|
597
|
+
}
|
|
598
|
+
let q = Promise.resolve();
|
|
599
|
+
function nt(e) {
|
|
600
|
+
const n = q.then(
|
|
601
|
+
() => V(e),
|
|
602
|
+
() => V(e)
|
|
595
603
|
);
|
|
596
|
-
return
|
|
597
|
-
}),
|
|
598
|
-
}
|
|
599
|
-
async function
|
|
600
|
-
|
|
601
|
-
const { XmlDocument:
|
|
602
|
-
e.projectDir ??
|
|
603
|
-
),
|
|
604
|
+
return q = n.catch(() => {
|
|
605
|
+
}), n;
|
|
606
|
+
}
|
|
607
|
+
async function V(e) {
|
|
608
|
+
Xe(), Ye();
|
|
609
|
+
const { XmlDocument: n } = await he(), t = await Ge(e.xslDir ?? Be()), r = f(e.sourcePath), i = f(
|
|
610
|
+
e.projectDir ?? y(r)
|
|
611
|
+
), o = e.sourceContent ?? await G(r), s = S(i, r);
|
|
604
612
|
if (s.startsWith(".."))
|
|
605
613
|
throw new Error(
|
|
606
|
-
`sourcePath (${r}) must live inside projectDir (${
|
|
614
|
+
`sourcePath (${r}) must live inside projectDir (${i})`
|
|
607
615
|
);
|
|
608
616
|
const a = S(
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
),
|
|
617
|
+
i,
|
|
618
|
+
f(e.mainSourcePath ?? r)
|
|
619
|
+
), u = a.startsWith("..") ? s : a, c = ie(i);
|
|
612
620
|
try {
|
|
613
|
-
let
|
|
621
|
+
let h, d = `${c}/__pretext-preview-publication.xml`;
|
|
614
622
|
if (e.publicationPath) {
|
|
615
|
-
const l =
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
);
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
623
|
+
const l = f(e.publicationPath);
|
|
624
|
+
h = await G(l);
|
|
625
|
+
const b = S(i, l);
|
|
626
|
+
b.startsWith("..") || (d = `${c}/${b.split(_).join("/")}`);
|
|
627
|
+
}
|
|
628
|
+
const g = De(
|
|
629
|
+
h,
|
|
630
|
+
e.cssTheme
|
|
631
|
+
);
|
|
632
|
+
$e(d, g);
|
|
633
|
+
const m = Se(g), W = y(f(i, u)), B = m.external !== void 0 && m.generated !== void 0 ? {
|
|
634
|
+
external: f(W, m.external),
|
|
635
|
+
generated: f(W, m.generated)
|
|
627
636
|
} : void 0;
|
|
628
|
-
let
|
|
637
|
+
let k, p;
|
|
629
638
|
if (e.sourceMap) {
|
|
630
639
|
const l = await se(
|
|
631
|
-
|
|
640
|
+
o,
|
|
632
641
|
r,
|
|
633
|
-
|
|
642
|
+
i
|
|
634
643
|
);
|
|
635
|
-
|
|
644
|
+
k = l.tree, p = l.content;
|
|
636
645
|
} else
|
|
637
|
-
p = await
|
|
638
|
-
|
|
646
|
+
p = await Ie(
|
|
647
|
+
o,
|
|
639
648
|
r,
|
|
640
|
-
|
|
649
|
+
i
|
|
641
650
|
);
|
|
642
|
-
const E =
|
|
643
|
-
let
|
|
651
|
+
const E = He(p);
|
|
652
|
+
let C = { parentId: "root", position: 1 };
|
|
644
653
|
if (E !== "pretext" && E !== "mathbook")
|
|
645
654
|
if (e.fragment) {
|
|
646
|
-
const l = e.docinfo ?? (e.docinfoSourcePath ? await
|
|
647
|
-
p =
|
|
655
|
+
const l = e.docinfo ?? (e.docinfoSourcePath ? await Oe(e.docinfoSourcePath, i) : void 0);
|
|
656
|
+
p = Ne(p, E, l), C = { parentId: l?.trim() ? "root-1-2" : "root-1-1", position: 2 };
|
|
648
657
|
} else
|
|
649
658
|
throw new Error(
|
|
650
659
|
`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.`
|
|
651
660
|
);
|
|
652
|
-
const
|
|
653
|
-
url: `${c}/${
|
|
661
|
+
const X = k ? Re(k, r, C) : void 0, U = await n.fromString(p, {
|
|
662
|
+
url: `${c}/${u.split(_).join("/")}`,
|
|
654
663
|
options: { noEnt: !0, dtdLoad: !0, huge: !0 }
|
|
655
|
-
}),
|
|
656
|
-
publisher:
|
|
664
|
+
}), H = {
|
|
665
|
+
publisher: Y(d)
|
|
657
666
|
};
|
|
658
|
-
for (const [l,
|
|
659
|
-
|
|
667
|
+
for (const [l, b] of Object.entries(e.stringParams ?? {}))
|
|
668
|
+
H[l] = Y(b);
|
|
660
669
|
let D;
|
|
661
670
|
try {
|
|
662
|
-
D = await
|
|
671
|
+
D = await t.apply(U, H);
|
|
663
672
|
} catch (l) {
|
|
664
|
-
throw
|
|
673
|
+
throw K(l), new Error(
|
|
665
674
|
"PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
|
|
666
675
|
{ cause: l }
|
|
667
676
|
);
|
|
668
677
|
} finally {
|
|
669
|
-
|
|
678
|
+
U.delete();
|
|
670
679
|
}
|
|
671
680
|
try {
|
|
672
|
-
let l =
|
|
673
|
-
return e.theme && (l =
|
|
681
|
+
let l = Ue(D.toHtmlString());
|
|
682
|
+
return e.theme && (l = We(l, e.theme)), {
|
|
674
683
|
html: l,
|
|
675
|
-
...
|
|
676
|
-
...
|
|
684
|
+
...X ? { sourceMap: X } : {},
|
|
685
|
+
...B ? { assetDirs: B } : {}
|
|
677
686
|
};
|
|
678
687
|
} catch (l) {
|
|
679
|
-
throw
|
|
688
|
+
throw K(l), l;
|
|
680
689
|
} finally {
|
|
681
690
|
D.delete();
|
|
682
691
|
}
|
|
683
692
|
} finally {
|
|
684
|
-
|
|
693
|
+
Te(c);
|
|
685
694
|
}
|
|
686
695
|
}
|
|
687
696
|
export {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
697
|
+
de as PREVIEW_THEME_MESSAGE,
|
|
698
|
+
Be as defaultXslDir,
|
|
699
|
+
Ze as findSourceMapEntry,
|
|
700
|
+
De as forcePortablePublication,
|
|
701
|
+
We as injectThemeBridge,
|
|
702
|
+
Ce as isJspiAvailable,
|
|
703
|
+
et as isPreviewTheme,
|
|
704
|
+
tt as previewThemeMessage,
|
|
705
|
+
nt as renderHtml,
|
|
706
|
+
Ve as setAssetsBase,
|
|
707
|
+
Qe as setMountReader,
|
|
708
|
+
je as themeBridgeScript,
|
|
709
|
+
Y as xpathStringLiteral
|
|
701
710
|
};
|