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