@pretextbook/pretext-html 0.9.0 → 0.10.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/dist/{cli-BUrNZxov.js → cli-BONFCRgl.js} +128 -127
- package/dist/cli.js +1 -1
- package/dist/index.browser.d.ts +4 -0
- package/dist/index.browser.js +367 -362
- package/dist/index.js +1 -1
- package/dist/renderer.d.ts +18 -0
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { readFile as W, writeFile as Z } from "node:fs/promises";
|
|
2
2
|
import * as y from "node:process";
|
|
3
|
-
import * as
|
|
3
|
+
import * as u from "node:path";
|
|
4
4
|
import { fileURLToPath as Ae } from "node:url";
|
|
5
5
|
import { fromXml as E } from "xast-util-from-xml";
|
|
6
6
|
import { toXml as I } from "xast-util-to-xml";
|
|
7
7
|
import { injectRevealBridge as Le } from "./reveal.js";
|
|
8
8
|
import { injectThemeBridge as Me } from "./theme.js";
|
|
9
|
-
const
|
|
9
|
+
const _e = "ptxPreviewBannerDismissed", je = "About live preview";
|
|
10
10
|
function Q(e) {
|
|
11
11
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
12
12
|
}
|
|
@@ -16,7 +16,7 @@ function Be(e) {
|
|
|
16
16
|
` <span class="ptx-preview-banner-text">${Q(e)}</span>`,
|
|
17
17
|
' <button type="button" class="ptx-preview-banner-dismiss" aria-label="Dismiss">×</button>',
|
|
18
18
|
"</div>",
|
|
19
|
-
`<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${Q(
|
|
19
|
+
`<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${Q(je)}</button>`
|
|
20
20
|
].join(`
|
|
21
21
|
`);
|
|
22
22
|
}
|
|
@@ -85,7 +85,7 @@ function Ce() {
|
|
|
85
85
|
return [
|
|
86
86
|
"<script>",
|
|
87
87
|
"(function () {",
|
|
88
|
-
" var KEY = " + JSON.stringify(
|
|
88
|
+
" var KEY = " + JSON.stringify(_e) + ";",
|
|
89
89
|
' var banner = document.getElementById("ptx-preview-banner");',
|
|
90
90
|
' var restore = document.getElementById("ptx-preview-banner-restore");',
|
|
91
91
|
" if (!banner || !restore) { return; }",
|
|
@@ -136,8 +136,8 @@ ${Ne}`;
|
|
|
136
136
|
return n.replace(/<body([^>]*)>/i, `<body$1>${o}`);
|
|
137
137
|
}
|
|
138
138
|
async function de(e, r) {
|
|
139
|
-
const t =
|
|
140
|
-
if (n !== t && !n.startsWith(t +
|
|
139
|
+
const t = u.resolve(e), n = u.resolve(t, `.${u.posix.normalize(r)}`);
|
|
140
|
+
if (n !== t && !n.startsWith(t + u.sep)) {
|
|
141
141
|
console.error(
|
|
142
142
|
`pretext-html: refusing to serve ${r} from outside ${t}`
|
|
143
143
|
);
|
|
@@ -161,10 +161,10 @@ function en(e) {
|
|
|
161
161
|
fe = e;
|
|
162
162
|
}
|
|
163
163
|
function C() {
|
|
164
|
-
return fe ?? process.env.PRETEXT_HTML_ASSETS ??
|
|
164
|
+
return fe ?? process.env.PRETEXT_HTML_ASSETS ?? u.resolve(u.dirname(Ae(import.meta.url)), "..", "assets");
|
|
165
165
|
}
|
|
166
166
|
function We(e, r) {
|
|
167
|
-
return
|
|
167
|
+
return u.join(e, r);
|
|
168
168
|
}
|
|
169
169
|
const pe = "2.48.1", He = "8.2.4", Je = [
|
|
170
170
|
"prefix-runtime.40bd1420d3277749.bundle.js",
|
|
@@ -195,13 +195,13 @@ function qe(e) {
|
|
|
195
195
|
}
|
|
196
196
|
);
|
|
197
197
|
}
|
|
198
|
-
const H = /* @__PURE__ */ new Map(),
|
|
199
|
-
let F, Ze = 0,
|
|
198
|
+
const H = /* @__PURE__ */ new Map(), me = /* @__PURE__ */ new Map();
|
|
199
|
+
let F, Ze = 0, he = de;
|
|
200
200
|
function tn(e) {
|
|
201
|
-
|
|
201
|
+
he = e;
|
|
202
202
|
}
|
|
203
203
|
function Qe(e, r) {
|
|
204
|
-
const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n =
|
|
204
|
+
const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n = me.get(t);
|
|
205
205
|
if (n !== void 0)
|
|
206
206
|
return Promise.resolve(new Response(n, { status: 200 }));
|
|
207
207
|
let o;
|
|
@@ -215,7 +215,7 @@ function Qe(e, r) {
|
|
|
215
215
|
}
|
|
216
216
|
const et = '<?xml version="1.0"?><pretext-preview-missing-file/>';
|
|
217
217
|
async function tt(e, r) {
|
|
218
|
-
const t = decodeURIComponent(new URL(r).pathname), n = await
|
|
218
|
+
const t = decodeURIComponent(new URL(r).pathname), n = await he(e, t);
|
|
219
219
|
if (n === void 0)
|
|
220
220
|
return new Response(et, { status: 200 });
|
|
221
221
|
const o = typeof n == "string" ? n : new Uint8Array(n);
|
|
@@ -233,7 +233,7 @@ function nt(e) {
|
|
|
233
233
|
H.delete(new URL(e).host);
|
|
234
234
|
}
|
|
235
235
|
function rt(e, r) {
|
|
236
|
-
we(),
|
|
236
|
+
we(), me.set(e, r);
|
|
237
237
|
}
|
|
238
238
|
const N = `<?xml version="1.0" encoding="UTF-8"?>
|
|
239
239
|
<publication>
|
|
@@ -314,11 +314,11 @@ async function ut(e, r, t) {
|
|
|
314
314
|
}
|
|
315
315
|
async function J(e, r, t) {
|
|
316
316
|
const n = E(e), o = {
|
|
317
|
-
projectDir:
|
|
318
|
-
stack: [
|
|
317
|
+
projectDir: u.resolve(t),
|
|
318
|
+
stack: [u.resolve(r)]
|
|
319
319
|
}, i = await P(
|
|
320
320
|
n,
|
|
321
|
-
|
|
321
|
+
u.dirname(u.resolve(r)),
|
|
322
322
|
{ "": "" },
|
|
323
323
|
o
|
|
324
324
|
);
|
|
@@ -374,8 +374,8 @@ async function xe(e, r, t, n) {
|
|
|
374
374
|
s = decodeURIComponent(i);
|
|
375
375
|
} catch {
|
|
376
376
|
}
|
|
377
|
-
const a =
|
|
378
|
-
if (a !== n.projectDir && !a.startsWith(n.projectDir +
|
|
377
|
+
const a = u.resolve(r, s);
|
|
378
|
+
if (a !== n.projectDir && !a.startsWith(n.projectDir + u.sep))
|
|
379
379
|
throw new Error(
|
|
380
380
|
`xi:include escapes the project directory: ${i} (in ${o})`
|
|
381
381
|
);
|
|
@@ -387,7 +387,7 @@ async function xe(e, r, t, n) {
|
|
|
387
387
|
throw new Error(`xi:include nesting exceeds ${ne} levels`);
|
|
388
388
|
const l = await M(a);
|
|
389
389
|
if (l === void 0) {
|
|
390
|
-
const p =
|
|
390
|
+
const p = mt(e, t);
|
|
391
391
|
if (p)
|
|
392
392
|
return await P(p, r, t, n), p.children;
|
|
393
393
|
throw new Error(`xi:include target not found: ${i} (in ${o})`);
|
|
@@ -404,7 +404,7 @@ async function xe(e, r, t, n) {
|
|
|
404
404
|
}
|
|
405
405
|
n.stack.push(a);
|
|
406
406
|
try {
|
|
407
|
-
await P(c,
|
|
407
|
+
await P(c, u.dirname(a), { "": "" }, n);
|
|
408
408
|
} finally {
|
|
409
409
|
n.stack.pop();
|
|
410
410
|
}
|
|
@@ -425,8 +425,8 @@ async function pt(e, r, t) {
|
|
|
425
425
|
);
|
|
426
426
|
if (!o)
|
|
427
427
|
return;
|
|
428
|
-
const i =
|
|
429
|
-
projectDir:
|
|
428
|
+
const i = u.resolve(r), s = u.dirname(i), a = {
|
|
429
|
+
projectDir: u.resolve(t),
|
|
430
430
|
stack: [i]
|
|
431
431
|
}, l = L({ "": "" }, o);
|
|
432
432
|
for (const c of o.children) {
|
|
@@ -436,16 +436,16 @@ async function pt(e, r, t) {
|
|
|
436
436
|
if (re(c))
|
|
437
437
|
return await P(c, s, f, a), I(c);
|
|
438
438
|
if (ve(c, f)) {
|
|
439
|
-
const
|
|
439
|
+
const m = (await xe(
|
|
440
440
|
c,
|
|
441
441
|
s,
|
|
442
442
|
f,
|
|
443
443
|
a
|
|
444
444
|
)).find(
|
|
445
|
-
(
|
|
445
|
+
(h) => h.type === "element" && re(h)
|
|
446
446
|
);
|
|
447
|
-
if (
|
|
448
|
-
return I(
|
|
447
|
+
if (m)
|
|
448
|
+
return I(m);
|
|
449
449
|
continue;
|
|
450
450
|
}
|
|
451
451
|
break;
|
|
@@ -455,7 +455,7 @@ async function pt(e, r, t) {
|
|
|
455
455
|
return;
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
|
-
function
|
|
458
|
+
function mt(e, r) {
|
|
459
459
|
for (const t of e.children) {
|
|
460
460
|
if (t.type !== "element")
|
|
461
461
|
continue;
|
|
@@ -467,7 +467,7 @@ function ht(e, r) {
|
|
|
467
467
|
function ye(e) {
|
|
468
468
|
return typeof e == "object" && e !== null && e.type === "element";
|
|
469
469
|
}
|
|
470
|
-
function
|
|
470
|
+
function ht(e) {
|
|
471
471
|
return /^(pf|xhtml):/.test(e.name);
|
|
472
472
|
}
|
|
473
473
|
function wt(e, r, t) {
|
|
@@ -481,7 +481,7 @@ function wt(e, r, t) {
|
|
|
481
481
|
function Te(e, r, t, n, o, i) {
|
|
482
482
|
const s = dt(e) ?? n;
|
|
483
483
|
let a, l;
|
|
484
|
-
if (
|
|
484
|
+
if (ht(e))
|
|
485
485
|
l = "root";
|
|
486
486
|
else {
|
|
487
487
|
const f = e.attributes.label ?? e.attributes["xml:id"];
|
|
@@ -554,7 +554,7 @@ const Ee = /* @__PURE__ */ new Set([
|
|
|
554
554
|
"subtitle",
|
|
555
555
|
"caption"
|
|
556
556
|
]);
|
|
557
|
-
function
|
|
557
|
+
function g(e) {
|
|
558
558
|
return e.type === "element";
|
|
559
559
|
}
|
|
560
560
|
function Ie(e) {
|
|
@@ -562,7 +562,7 @@ function Ie(e) {
|
|
|
562
562
|
}
|
|
563
563
|
function X(e, r) {
|
|
564
564
|
for (const t of e.children) {
|
|
565
|
-
if (!
|
|
565
|
+
if (!g(t)) continue;
|
|
566
566
|
if (Ie(t) === r) return t;
|
|
567
567
|
const n = X(t, r);
|
|
568
568
|
if (n) return n;
|
|
@@ -570,7 +570,7 @@ function X(e, r) {
|
|
|
570
570
|
}
|
|
571
571
|
function A(e, r) {
|
|
572
572
|
for (const t of e.children) {
|
|
573
|
-
if (!
|
|
573
|
+
if (!g(t)) continue;
|
|
574
574
|
if (t === r) return [t];
|
|
575
575
|
const n = A(t, r);
|
|
576
576
|
if (n) return [t, ...n];
|
|
@@ -586,7 +586,7 @@ function vt(e, r) {
|
|
|
586
586
|
}
|
|
587
587
|
function Pe(e) {
|
|
588
588
|
if (!$e.has(e.name)) {
|
|
589
|
-
e.children = e.children.filter(
|
|
589
|
+
e.children = e.children.filter(g);
|
|
590
590
|
for (const r of e.children)
|
|
591
591
|
Pe(r);
|
|
592
592
|
}
|
|
@@ -594,7 +594,7 @@ function Pe(e) {
|
|
|
594
594
|
function U(e, r) {
|
|
595
595
|
const t = [];
|
|
596
596
|
for (const n of e.children)
|
|
597
|
-
|
|
597
|
+
g(n) && (r.has(n) || gt.has(n.name) || $e.has(n.name) ? t.push(n) : ke.has(n.name) && (U(n, r), t.push(n)));
|
|
598
598
|
e.children = t;
|
|
599
599
|
}
|
|
600
600
|
function xt(e) {
|
|
@@ -610,14 +610,14 @@ function xt(e) {
|
|
|
610
610
|
s && r.add(s);
|
|
611
611
|
}
|
|
612
612
|
for (const o of n.children)
|
|
613
|
-
|
|
613
|
+
g(o) && t(o);
|
|
614
614
|
};
|
|
615
615
|
return t(e), r;
|
|
616
616
|
}
|
|
617
617
|
function yt(e, r, t) {
|
|
618
618
|
const n = (o) => {
|
|
619
619
|
for (const [i, s] of o.children.entries())
|
|
620
|
-
if (
|
|
620
|
+
if (g(s)) {
|
|
621
621
|
if (Ie(s) === r)
|
|
622
622
|
return o.children[i] = t, !0;
|
|
623
623
|
if (n(s)) return !0;
|
|
@@ -632,33 +632,33 @@ function Tt(e, r) {
|
|
|
632
632
|
const n = A(e, t);
|
|
633
633
|
if (!n) return;
|
|
634
634
|
const o = n.filter(
|
|
635
|
-
(
|
|
635
|
+
(m) => m.name !== "pretext" && m.name !== "mathbook"
|
|
636
636
|
), i = o[0], s = i?.name === "book" && i.children.some(
|
|
637
|
-
(
|
|
637
|
+
(m) => g(m) && m.name === "part"
|
|
638
638
|
), a = vt(o, s), l = new Set(n), c = xt(t), f = /* @__PURE__ */ new Set();
|
|
639
639
|
if (c.size > 0)
|
|
640
|
-
for (const
|
|
641
|
-
const
|
|
642
|
-
if (!
|
|
643
|
-
const R = A(e,
|
|
640
|
+
for (const m of c) {
|
|
641
|
+
const h = X(e, m);
|
|
642
|
+
if (!h || h === t) continue;
|
|
643
|
+
const R = A(e, h);
|
|
644
644
|
if (!R) continue;
|
|
645
|
-
const
|
|
646
|
-
if (
|
|
647
|
-
f.add(
|
|
648
|
-
for (const
|
|
649
|
-
l.add(
|
|
645
|
+
const v = [...R].reverse().find((b) => ke.has(b.name));
|
|
646
|
+
if (v && v !== t) {
|
|
647
|
+
f.add(v);
|
|
648
|
+
for (const b of A(e, v) ?? [])
|
|
649
|
+
l.add(b);
|
|
650
650
|
}
|
|
651
651
|
}
|
|
652
|
-
for (const
|
|
653
|
-
if (
|
|
654
|
-
U(
|
|
652
|
+
for (const m of n) {
|
|
653
|
+
if (m === t) break;
|
|
654
|
+
U(m, l);
|
|
655
655
|
}
|
|
656
|
-
for (const
|
|
657
|
-
Pe(
|
|
658
|
-
const p = e.children.find(
|
|
656
|
+
for (const m of f)
|
|
657
|
+
Pe(m);
|
|
658
|
+
const p = e.children.find(g);
|
|
659
659
|
return p && !n.includes(p) && U(p, l), { content: I(e), divisionId: r, level: a };
|
|
660
660
|
}
|
|
661
|
-
const Et = "This live preview shows a single division, so links into the rest of the document do not work here.", St = /<a\b([^>]*)>/g, kt = /\sid="([^"]*)"/g,
|
|
661
|
+
const Et = "This live preview shows a single division, so links into the rest of the document do not work here.", St = /<a\b([^>]*)>/g, kt = /\sid="([^"]*)"/g, j = /\shref="([^"]*)"/, $t = /\\href\{([^{}]*)\}/g, oe = /\stitle="([^"]*)"/;
|
|
662
662
|
function It(e) {
|
|
663
663
|
const r = /* @__PURE__ */ new Set();
|
|
664
664
|
for (const t of e.matchAll(kt))
|
|
@@ -680,14 +680,14 @@ function ie(e, r) {
|
|
|
680
680
|
function Rt(e, r = {}) {
|
|
681
681
|
const t = r.offPageMessage ?? Et, n = It(e);
|
|
682
682
|
return e.replace(St, (i, s) => {
|
|
683
|
-
const a =
|
|
683
|
+
const a = j.exec(s);
|
|
684
684
|
if (!a) return i;
|
|
685
685
|
const l = ie(a[1], n);
|
|
686
686
|
if (l.kind === "keep") return i;
|
|
687
687
|
if (l.kind === "same-page")
|
|
688
|
-
return `<a${s.replace(
|
|
688
|
+
return `<a${s.replace(j, ` href="#${l.id}"`)}>`;
|
|
689
689
|
const c = oe.exec(s), f = Pt(t), p = c ? `${c[1]} — ${f}` : f;
|
|
690
|
-
return `<a${s.replace(
|
|
690
|
+
return `<a${s.replace(j, "").replace(oe, "")} title="${p}" aria-disabled="true" style="cursor:default">`;
|
|
691
691
|
}).replace($t, (i, s) => {
|
|
692
692
|
const a = ie(s, n);
|
|
693
693
|
return a.kind === "same-page" ? `\\href{#${a.id}}` : i;
|
|
@@ -714,7 +714,7 @@ function Mt(e) {
|
|
|
714
714
|
(r, t) => `from '${t}'`
|
|
715
715
|
);
|
|
716
716
|
}
|
|
717
|
-
const
|
|
717
|
+
const _t = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${pe}/dist/`, jt = {
|
|
718
718
|
"cli.version": pe,
|
|
719
719
|
// Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
|
|
720
720
|
"rs-js": Je.join(":"),
|
|
@@ -724,7 +724,7 @@ const jt = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${pe}/dist/`, _t
|
|
|
724
724
|
function Bt(e) {
|
|
725
725
|
return e.replace(
|
|
726
726
|
/(<link\b[^>]*\bhref=["'])_static\//gi,
|
|
727
|
-
`$1${
|
|
727
|
+
`$1${_t}_static/`
|
|
728
728
|
);
|
|
729
729
|
}
|
|
730
730
|
function Ot(e) {
|
|
@@ -739,7 +739,7 @@ async function se(e) {
|
|
|
739
739
|
return r;
|
|
740
740
|
}
|
|
741
741
|
async function Ct(e, r) {
|
|
742
|
-
const t =
|
|
742
|
+
const t = u.resolve(e), n = await M(t);
|
|
743
743
|
if (n !== void 0)
|
|
744
744
|
return pt(n, t, r);
|
|
745
745
|
}
|
|
@@ -754,23 +754,23 @@ ${o}
|
|
|
754
754
|
</pretext>
|
|
755
755
|
`;
|
|
756
756
|
}
|
|
757
|
-
async function Nt(e, r, t) {
|
|
758
|
-
const
|
|
759
|
-
(
|
|
760
|
-
),
|
|
761
|
-
if (!
|
|
762
|
-
const
|
|
763
|
-
if (
|
|
764
|
-
let
|
|
757
|
+
async function Nt(e, r, t, n) {
|
|
758
|
+
const o = E(e).children.find(
|
|
759
|
+
(f) => f.type === "element"
|
|
760
|
+
), i = o?.attributes["xml:id"];
|
|
761
|
+
if (!o || !i) return;
|
|
762
|
+
const s = u.resolve(r), a = n ?? await M(s);
|
|
763
|
+
if (a === void 0) return;
|
|
764
|
+
let l;
|
|
765
765
|
try {
|
|
766
|
-
|
|
766
|
+
l = (await J(a, s, t)).tree;
|
|
767
767
|
} catch {
|
|
768
768
|
return;
|
|
769
769
|
}
|
|
770
|
-
if (!yt(
|
|
771
|
-
const
|
|
772
|
-
if (
|
|
773
|
-
return { ...
|
|
770
|
+
if (!yt(l, i, o)) return;
|
|
771
|
+
const c = Tt(l, i);
|
|
772
|
+
if (c)
|
|
773
|
+
return { ...c, tree: l };
|
|
774
774
|
}
|
|
775
775
|
let Re = !1;
|
|
776
776
|
function Xt(e) {
|
|
@@ -838,111 +838,112 @@ function zt(e) {
|
|
|
838
838
|
}
|
|
839
839
|
async function le(e) {
|
|
840
840
|
Lt(), Wt();
|
|
841
|
-
const { XmlDocument: r } = await De(), t =
|
|
842
|
-
e.projectDir ??
|
|
843
|
-
), o = e.sourceContent ?? await se(t), i =
|
|
841
|
+
const { XmlDocument: r } = await De(), t = u.resolve(e.sourcePath), n = u.resolve(
|
|
842
|
+
e.projectDir ?? u.dirname(t)
|
|
843
|
+
), o = e.sourceContent ?? await se(t), i = u.relative(n, t);
|
|
844
844
|
if (i.startsWith(".."))
|
|
845
845
|
throw new Error(
|
|
846
846
|
`sourcePath (${t}) must live inside projectDir (${n})`
|
|
847
847
|
);
|
|
848
|
-
const s =
|
|
848
|
+
const s = u.relative(
|
|
849
849
|
n,
|
|
850
|
-
|
|
850
|
+
u.resolve(e.mainSourcePath ?? t)
|
|
851
851
|
), a = s.startsWith("..") ? i : s, l = be(n);
|
|
852
852
|
try {
|
|
853
853
|
let c, f = `${l}/__pretext-preview-publication.xml`;
|
|
854
854
|
if (e.publicationPath) {
|
|
855
|
-
const
|
|
856
|
-
c = await se(
|
|
857
|
-
const
|
|
858
|
-
|
|
855
|
+
const d = u.resolve(e.publicationPath);
|
|
856
|
+
c = await se(d);
|
|
857
|
+
const w = u.relative(n, d);
|
|
858
|
+
w.startsWith("..") || (f = `${l}/${w.split(u.sep).join("/")}`);
|
|
859
859
|
}
|
|
860
|
-
let p,
|
|
860
|
+
let p, m;
|
|
861
861
|
if (e.sourceMap) {
|
|
862
|
-
const
|
|
862
|
+
const d = await J(
|
|
863
863
|
o,
|
|
864
864
|
t,
|
|
865
865
|
n
|
|
866
866
|
);
|
|
867
|
-
p =
|
|
867
|
+
p = d.tree, m = d.content;
|
|
868
868
|
} else
|
|
869
|
-
|
|
869
|
+
m = await ut(
|
|
870
870
|
o,
|
|
871
871
|
t,
|
|
872
872
|
n
|
|
873
873
|
);
|
|
874
|
-
const
|
|
874
|
+
const h = e.target ?? bt(m), R = await Jt(e.xslDir ?? Dt(), h), v = ct(c, {
|
|
875
875
|
cssTheme: e.cssTheme,
|
|
876
876
|
revealTheme: e.revealTheme,
|
|
877
|
-
target:
|
|
877
|
+
target: h
|
|
878
878
|
});
|
|
879
|
-
rt(f,
|
|
880
|
-
const
|
|
881
|
-
external:
|
|
882
|
-
generated:
|
|
883
|
-
} : void 0, D = Ot(
|
|
879
|
+
rt(f, v);
|
|
880
|
+
const b = lt(v), z = u.dirname(u.resolve(n, a)), K = b.external !== void 0 && b.generated !== void 0 ? {
|
|
881
|
+
external: u.resolve(z, b.external),
|
|
882
|
+
generated: u.resolve(z, b.generated)
|
|
883
|
+
} : void 0, D = Ot(m);
|
|
884
884
|
let V = { parentId: "root", position: 1 }, S, G = t;
|
|
885
885
|
if (D !== "pretext" && D !== "mathbook") {
|
|
886
886
|
if (!e.fragment)
|
|
887
887
|
throw new Error(
|
|
888
888
|
`The document root is <${D ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
|
|
889
889
|
);
|
|
890
|
-
if (e.contextSourcePath) {
|
|
891
|
-
const u = await Nt(
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
n
|
|
890
|
+
if (e.contextSourcePath || e.contextSourceContent) {
|
|
891
|
+
const d = e.contextSourcePath ?? u.join(u.dirname(t), "__pretext-preview-context.ptx"), w = await Nt(
|
|
892
|
+
m,
|
|
893
|
+
d,
|
|
894
|
+
n,
|
|
895
|
+
e.contextSourceContent
|
|
895
896
|
);
|
|
896
|
-
|
|
897
|
+
w && (m = w.content, p = e.sourceMap ? w.tree : void 0, G = u.resolve(d), S = { divisionId: w.divisionId, level: w.level });
|
|
897
898
|
}
|
|
898
899
|
if (!S) {
|
|
899
|
-
const
|
|
900
|
-
|
|
901
|
-
h,
|
|
902
|
-
D,
|
|
900
|
+
const d = e.docinfo ?? (e.docinfoSourcePath ? await Ct(e.docinfoSourcePath, n) : void 0);
|
|
901
|
+
m = Ft(
|
|
903
902
|
m,
|
|
904
|
-
|
|
905
|
-
|
|
903
|
+
D,
|
|
904
|
+
h,
|
|
905
|
+
d
|
|
906
|
+
), V = { parentId: d?.trim() ? "root-1-2" : "root-1-1", position: 2 };
|
|
906
907
|
}
|
|
907
908
|
}
|
|
908
|
-
const Y = p ? wt(p, G, V) : void 0, q = await r.fromString(
|
|
909
|
-
url: `${l}/${a.split(
|
|
909
|
+
const Y = p ? wt(p, G, V) : void 0, q = await r.fromString(m, {
|
|
910
|
+
url: `${l}/${a.split(u.sep).join("/")}`,
|
|
910
911
|
options: { noEnt: !0, dtdLoad: !0, huge: !0 }
|
|
911
912
|
}), k = {
|
|
912
913
|
publisher: $(f)
|
|
913
914
|
};
|
|
914
|
-
for (const [
|
|
915
|
-
k[
|
|
915
|
+
for (const [d, w] of Object.entries(jt))
|
|
916
|
+
k[d] = $(w);
|
|
916
917
|
S && (k.subtree = $(S.divisionId), k["subtree-level"] = $(String(S.level)));
|
|
917
|
-
for (const [
|
|
918
|
-
k[
|
|
919
|
-
let
|
|
918
|
+
for (const [d, w] of Object.entries(e.stringParams ?? {}))
|
|
919
|
+
k[d] = $(w);
|
|
920
|
+
let _;
|
|
920
921
|
try {
|
|
921
|
-
|
|
922
|
-
} catch (
|
|
923
|
-
throw ae(
|
|
922
|
+
_ = await R.apply(q, k);
|
|
923
|
+
} catch (d) {
|
|
924
|
+
throw ae(d), new Error(
|
|
924
925
|
"PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
|
|
925
|
-
{ cause:
|
|
926
|
+
{ cause: d }
|
|
926
927
|
);
|
|
927
928
|
} finally {
|
|
928
929
|
q.delete();
|
|
929
930
|
}
|
|
930
931
|
try {
|
|
931
|
-
let
|
|
932
|
-
return
|
|
932
|
+
let d = Mt(_.toHtmlString());
|
|
933
|
+
return d = Rt(d, {
|
|
933
934
|
...e.offPageMessage !== void 0 ? { offPageMessage: e.offPageMessage } : {}
|
|
934
|
-
}), (e.openKnowls ?? !0) && (
|
|
935
|
+
}), (e.openKnowls ?? !0) && (d = qe(d)), h === "slides" ? (d = Bt(d), d = Le(d, e.revealView ?? "scroll", {
|
|
935
936
|
zoom: e.revealZoom
|
|
936
|
-
})) : e.theme && (
|
|
937
|
-
html:
|
|
938
|
-
target:
|
|
937
|
+
})) : e.theme && (d = Me(d, e.theme)), e.previewBanner && (d = Ue(d, e.previewBanner)), {
|
|
938
|
+
html: d,
|
|
939
|
+
target: h,
|
|
939
940
|
...Y ? { sourceMap: Y } : {},
|
|
940
941
|
...K ? { assetDirs: K } : {}
|
|
941
942
|
};
|
|
942
|
-
} catch (
|
|
943
|
-
throw ae(
|
|
943
|
+
} catch (d) {
|
|
944
|
+
throw ae(d), d;
|
|
944
945
|
} finally {
|
|
945
|
-
|
|
946
|
+
_.delete();
|
|
946
947
|
}
|
|
947
948
|
} finally {
|
|
948
949
|
nt(l);
|
|
@@ -1076,7 +1077,7 @@ async function rn(e) {
|
|
|
1076
1077
|
}
|
|
1077
1078
|
export {
|
|
1078
1079
|
Et as O,
|
|
1079
|
-
|
|
1080
|
+
_e as P,
|
|
1080
1081
|
bt as a,
|
|
1081
1082
|
Tt as b,
|
|
1082
1083
|
vt as c,
|
package/dist/cli.js
CHANGED
package/dist/index.browser.d.ts
CHANGED
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
* only as a virtual base for URL and xi:include resolution.
|
|
15
15
|
* - **`xi:include`s are not resolved from disk.** Pre-merge them, or pass the
|
|
16
16
|
* already-merged document as `sourceContent`.
|
|
17
|
+
* - **Use `contextSourceContent`, not `contextSourcePath`**, to place a
|
|
18
|
+
* fragment in its document for correct numbering and resolved `<xref>`s
|
|
19
|
+
* (see `RenderOptions.contextSourceContent`) — `contextSourcePath` alone
|
|
20
|
+
* is unreadable for the same reason `sourcePath` alone is.
|
|
17
21
|
* - **Assets come from jsDelivr by default**, version-pinned to this package.
|
|
18
22
|
* Call `setAssetsBase()` before the first render to self-host.
|
|
19
23
|
*/
|