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