@pretextbook/import 0.8.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/README.md +37 -0
- package/dist/convert-worker.cjs +1 -1
- package/dist/convert-worker.js +1 -1
- package/dist/import-mode-CV7gCDzF.cjs +3 -0
- package/dist/import-mode-DQ8g5P8P.js +122 -0
- package/dist/import.css +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +10 -6
- package/dist/index.js +524 -214
- package/dist/lib/assets/images.d.ts +49 -0
- package/dist/lib/detect-snippet-format.d.ts +32 -0
- package/dist/lib/import-mode.d.ts +22 -0
- package/dist/lib/insert/dedupe-ids.d.ts +36 -0
- package/dist/lib/insert/destination.d.ts +21 -0
- package/dist/lib/insert/index.d.ts +4 -0
- package/dist/lib/insert/prepare.d.ts +44 -0
- package/dist/lib/insert/retarget.d.ts +35 -0
- package/dist/lib/layout/xml-scan.d.ts +28 -0
- package/dist/lib/pandoc/formats.d.ts +40 -0
- package/dist/lib/pandoc/index.d.ts +3 -0
- package/dist/lib/pandoc/pandoc-engine.d.ts +24 -0
- package/dist/lib/pandoc/remote-pandoc.d.ts +74 -0
- package/dist/lib/pool/division-pool.d.ts +5 -0
- package/dist/lib/pool/index.d.ts +5 -1
- package/dist/lib/pool/place-divisions.d.ts +25 -0
- package/dist/lib/pool/placeholders.d.ts +4 -0
- package/dist/lib/pool/refs.d.ts +8 -0
- package/dist/lib/pool/serialize-destination.d.ts +24 -0
- package/dist/lib/pool/serialize-files.d.ts +1 -2
- package/dist/lib/pool/serialize-insert-records.d.ts +22 -0
- package/dist/lib/pool/serialize-insert.d.ts +44 -0
- package/dist/lib/pool/serialize-plus.d.ts +4 -4
- package/dist/lib/pool/serialize-records.d.ts +11 -0
- package/dist/lib/pretext-divisions.d.ts +25 -0
- package/dist/lib/select/divisions.d.ts +44 -0
- package/dist/lib/types.d.ts +82 -2
- package/dist/lib/upload.d.ts +56 -4
- package/dist/react/import-wizard.d.ts +45 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react.cjs +2 -2
- package/dist/react.js +655 -498
- package/dist/upload-BnRj1gU1.cjs +135 -0
- package/dist/upload-H_OCZBBn.js +7648 -0
- package/package.json +1 -1
- package/dist/import-mode-BCGuSwkM.js +0 -112
- package/dist/import-mode-D1gOJw3N.cjs +0 -3
- package/dist/upload-BmErkg8I.js +0 -7140
- package/dist/upload-BtS22hIH.cjs +0 -135
package/dist/index.js
CHANGED
|
@@ -1,7 +1,65 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
import { C as
|
|
3
|
-
import { a as
|
|
4
|
-
const
|
|
1
|
+
import { i as K, d as W, r as H, a as U, f as y, b as C, w as S, s as R, e as G, c as q, p as V, g as $, h as Z, j as Y } from "./upload-H_OCZBBn.js";
|
|
2
|
+
import { C as Re, D as ke, L as De, k as Me, l as Oe, M as Ne, m as je, P as Xe, n as ze, o as Be, q as Ke, t as We, u as He, v as Ue, x as Ge, y as qe, z as Ve, A as Ze, B as Ye, E as Je, F as Qe, G as et, H as tt, I as nt, J as rt, K as ot, N as st, O as at, Q as it, R as ct, S as lt, T as ut, U as pt, V as dt, W as mt, X as ft, Y as ht, Z as gt, _ as wt, $ as xt, a0 as Tt, a1 as Pt, a2 as Et, a3 as St, a4 as bt, a5 as vt, a6 as It, a7 as _t, a8 as $t, a9 as At, aa as Ft, ab as Lt, ac as yt, ad as Ct, ae as Rt, af as kt, ag as Dt, ah as Mt, ai as Ot, aj as Nt, ak as jt, al as Xt, am as zt } from "./upload-H_OCZBBn.js";
|
|
3
|
+
import { D as Kt, a as Wt, d as Ht, b as Ut, c as Gt, f as qt, e as Vt, g as Zt, h as Yt, p as Jt, r as Qt } from "./import-mode-DQ8g5P8P.js";
|
|
4
|
+
const J = /\$(?![\s$])([^$\n]{1,200})\$/;
|
|
5
|
+
function Q(e) {
|
|
6
|
+
const t = J.exec(e);
|
|
7
|
+
if (!t)
|
|
8
|
+
return !1;
|
|
9
|
+
const r = t[1];
|
|
10
|
+
return /[\\^_{}]/.test(r) || /^[A-Za-z]'?$/.test(r.trim());
|
|
11
|
+
}
|
|
12
|
+
const ee = [
|
|
13
|
+
// \begin{...} / \end{...} — unambiguous.
|
|
14
|
+
{ pattern: /\\(?:begin|end)\{[a-zA-Z*]+\}/, weight: 3 },
|
|
15
|
+
// Display math, either delimiter style.
|
|
16
|
+
{ pattern: /\\\[[\s\S]*?\\\]|\$\$[\s\S]*?\$\$/, weight: 3 },
|
|
17
|
+
// A command taking an argument: \emph{...}, \frac{...}{...}.
|
|
18
|
+
{ pattern: /\\[a-zA-Z]+\s*\{/, weight: 2 },
|
|
19
|
+
// Inline math delimiters \( ... \).
|
|
20
|
+
{ pattern: /\\\([\s\S]*?\\\)/, weight: 2 },
|
|
21
|
+
// A bare command: \alpha, \ldots, \\.
|
|
22
|
+
{ pattern: /\\[a-zA-Z]+\b/, weight: 1 },
|
|
23
|
+
// Label/ref machinery is a strong hint even without braces nearby.
|
|
24
|
+
{ pattern: /\\(?:label|ref|eqref|cite)\b/, weight: 2 }
|
|
25
|
+
], te = [
|
|
26
|
+
// ATX heading.
|
|
27
|
+
{ pattern: /^#{1,6}\s+\S/m, weight: 3 },
|
|
28
|
+
// Fenced code block.
|
|
29
|
+
{ pattern: /^\s*```/m, weight: 3 },
|
|
30
|
+
// Bullet list.
|
|
31
|
+
{ pattern: /^\s*[-*+]\s+\S/m, weight: 2 },
|
|
32
|
+
// Ordered list.
|
|
33
|
+
{ pattern: /^\s*\d+[.)]\s+\S/m, weight: 2 },
|
|
34
|
+
// Strong emphasis.
|
|
35
|
+
{ pattern: /\*\*[^\s*][^*]*\*\*/, weight: 2 },
|
|
36
|
+
// Inline link.
|
|
37
|
+
{ pattern: /\[[^\]\n]+\]\([^)\s]+\)/, weight: 2 },
|
|
38
|
+
// Blockquote.
|
|
39
|
+
{ pattern: /^\s*>\s+\S/m, weight: 2 },
|
|
40
|
+
// Underscore emphasis, bounded so snake_case_names do not count.
|
|
41
|
+
{ pattern: /(?:^|\s)_[^_\s][^_\n]*_(?:\s|[.,;:!?]|$)/, weight: 1 },
|
|
42
|
+
// Inline code span.
|
|
43
|
+
{ pattern: /`[^`\n]+`/, weight: 1 }
|
|
44
|
+
], ne = 2;
|
|
45
|
+
function A(e, t) {
|
|
46
|
+
return t.reduce(
|
|
47
|
+
(r, { pattern: n, weight: o }) => r + (n.test(e) ? o : 0),
|
|
48
|
+
0
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
function re(e) {
|
|
52
|
+
return { latex: A(e, ee) + (Q(e) ? 2 : 0), markdown: A(e, te) };
|
|
53
|
+
}
|
|
54
|
+
function ve(e) {
|
|
55
|
+
const t = e.trim();
|
|
56
|
+
if (!t || t.startsWith("<"))
|
|
57
|
+
return;
|
|
58
|
+
const { latex: r, markdown: n } = re(t);
|
|
59
|
+
if (!(Math.max(r, n) < ne))
|
|
60
|
+
return r >= n ? "latex" : "markdown";
|
|
61
|
+
}
|
|
62
|
+
const oe = {
|
|
5
63
|
png: "image/png",
|
|
6
64
|
jpg: "image/jpeg",
|
|
7
65
|
jpeg: "image/jpeg",
|
|
@@ -15,20 +73,45 @@ const M = {
|
|
|
15
73
|
webp: "image/webp",
|
|
16
74
|
ico: "image/vnd.microsoft.icon"
|
|
17
75
|
};
|
|
18
|
-
function
|
|
19
|
-
const
|
|
20
|
-
return
|
|
76
|
+
function se(e) {
|
|
77
|
+
const t = e.split(".").pop()?.toLowerCase() ?? "";
|
|
78
|
+
return oe[t] ?? "application/octet-stream";
|
|
21
79
|
}
|
|
22
80
|
const P = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
for (let
|
|
26
|
-
const
|
|
27
|
-
|
|
81
|
+
function ae(e) {
|
|
82
|
+
const t = e.length, r = [];
|
|
83
|
+
for (let n = 0; n < t; n += 3) {
|
|
84
|
+
const o = e[n], i = n + 1 < t, s = n + 2 < t, a = i ? e[n + 1] : 0, c = s ? e[n + 2] : 0;
|
|
85
|
+
r.push(P[o >> 2]), r.push(P[(o & 3) << 4 | a >> 4]), r.push(i ? P[(a & 15) << 2 | c >> 6] : "="), r.push(s ? P[c & 63] : "=");
|
|
28
86
|
}
|
|
29
|
-
return
|
|
87
|
+
return r.join("");
|
|
88
|
+
}
|
|
89
|
+
function k(e) {
|
|
90
|
+
return {
|
|
91
|
+
ref: e.ref,
|
|
92
|
+
fileName: e.fileName,
|
|
93
|
+
contentType: se(e.fileName),
|
|
94
|
+
data: ae(e.data)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function D(e) {
|
|
98
|
+
return {
|
|
99
|
+
ref: e.xmlId,
|
|
100
|
+
source: e.content,
|
|
101
|
+
sourceFormat: e.sourceFormat,
|
|
102
|
+
isRoot: e.isRoot
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function ie(e) {
|
|
106
|
+
return {
|
|
107
|
+
title: e.title,
|
|
108
|
+
docinfo: e.docinfo,
|
|
109
|
+
documentKind: e.documentKind,
|
|
110
|
+
divisions: e.divisions.map(D),
|
|
111
|
+
assets: e.assets.map(k)
|
|
112
|
+
};
|
|
30
113
|
}
|
|
31
|
-
function
|
|
114
|
+
function ce(e) {
|
|
32
115
|
return {
|
|
33
116
|
ref: e.ref,
|
|
34
117
|
kind: "file",
|
|
@@ -36,82 +119,97 @@ function $(e) {
|
|
|
36
119
|
short_description: e.fileName,
|
|
37
120
|
file: {
|
|
38
121
|
filename: e.fileName,
|
|
39
|
-
content_type:
|
|
40
|
-
data:
|
|
122
|
+
content_type: e.contentType,
|
|
123
|
+
data: e.data
|
|
41
124
|
}
|
|
42
125
|
};
|
|
43
126
|
}
|
|
44
|
-
function
|
|
127
|
+
function le(e) {
|
|
45
128
|
return {
|
|
46
129
|
title: e.title,
|
|
47
130
|
docinfo: e.docinfo,
|
|
48
131
|
document_type: e.documentKind,
|
|
49
|
-
divisions_attributes: e.divisions.map((
|
|
50
|
-
ref:
|
|
51
|
-
source:
|
|
52
|
-
source_format:
|
|
53
|
-
is_root:
|
|
132
|
+
divisions_attributes: e.divisions.map((t) => ({
|
|
133
|
+
ref: t.ref,
|
|
134
|
+
source: t.source,
|
|
135
|
+
source_format: t.sourceFormat,
|
|
136
|
+
is_root: t.isRoot
|
|
54
137
|
})),
|
|
55
|
-
assets_attributes: e.assets.map(
|
|
138
|
+
assets_attributes: e.assets.map(ce)
|
|
56
139
|
};
|
|
57
140
|
}
|
|
58
|
-
|
|
141
|
+
function Ie(e) {
|
|
142
|
+
return le(ie(e));
|
|
143
|
+
}
|
|
144
|
+
function _e(e, t) {
|
|
145
|
+
const { root: r, entries: n } = K(e, t), o = new Set(n.map((s) => s.xmlId)), i = e.divisions.filter(
|
|
146
|
+
(s) => !o.has(s.xmlId) && !(t.unwrapRoot && s.xmlId === r.xmlId)
|
|
147
|
+
);
|
|
148
|
+
return {
|
|
149
|
+
divisions: [...n, ...i].map(D),
|
|
150
|
+
assets: e.assets.map(k),
|
|
151
|
+
placeholders: n.map(
|
|
152
|
+
(s) => `<plus:${s.type} ref="${s.xmlId}"/>`
|
|
153
|
+
)
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const E = {
|
|
59
157
|
mainSourcePath: "source/main.ptx",
|
|
60
158
|
publicationPath: "publication/publication.ptx",
|
|
61
159
|
projectFilePath: "project.ptx",
|
|
62
160
|
docinfoPath: "source/docinfo.ptx"
|
|
63
161
|
};
|
|
64
|
-
function
|
|
65
|
-
return
|
|
162
|
+
function M(e) {
|
|
163
|
+
return y(e, "pretext") ? e : `<pretext>
|
|
66
164
|
${e}
|
|
67
165
|
</pretext>`;
|
|
68
166
|
}
|
|
69
|
-
function
|
|
70
|
-
const
|
|
71
|
-
return e.forEach((
|
|
72
|
-
const
|
|
73
|
-
let
|
|
74
|
-
if (
|
|
75
|
-
const m =
|
|
76
|
-
|
|
167
|
+
function O(e, t, r) {
|
|
168
|
+
const n = /* @__PURE__ */ new Map(), o = [], i = `${t}-`;
|
|
169
|
+
return e.forEach((s, a) => {
|
|
170
|
+
const c = s.attributes["xml:id"];
|
|
171
|
+
let l;
|
|
172
|
+
if (c) {
|
|
173
|
+
const m = q(c);
|
|
174
|
+
l = m.startsWith(i) ? m : `${i}${m}`;
|
|
77
175
|
} else
|
|
78
|
-
|
|
176
|
+
l = `${i}${V(a + 1, e.length)}`, r.push({
|
|
79
177
|
action: "anomaly",
|
|
80
178
|
severity: "info",
|
|
81
179
|
kind: "structure",
|
|
82
180
|
category: "missing_xml_id",
|
|
83
|
-
macro:
|
|
181
|
+
macro: s.name,
|
|
84
182
|
occurrences: 1,
|
|
85
|
-
message: `<${
|
|
183
|
+
message: `<${s.name}> at position ${a + 1} has no xml:id; using \`${l}\` as filename.`
|
|
86
184
|
});
|
|
87
|
-
const p =
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
span:
|
|
92
|
-
slug:
|
|
93
|
-
filename: `${
|
|
185
|
+
const p = n.get(l) ?? 0;
|
|
186
|
+
n.set(l, p + 1);
|
|
187
|
+
const u = p === 0 ? l : `${l}-${p + 1}`;
|
|
188
|
+
o.push({
|
|
189
|
+
span: s,
|
|
190
|
+
slug: u,
|
|
191
|
+
filename: `${u}.ptx`
|
|
94
192
|
});
|
|
95
|
-
}),
|
|
193
|
+
}), o;
|
|
96
194
|
}
|
|
97
|
-
function
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
195
|
+
function ue(e, t, r, n) {
|
|
196
|
+
const o = C(e, "section");
|
|
197
|
+
if (o.length === 0)
|
|
100
198
|
return e;
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
return
|
|
104
|
-
start:
|
|
105
|
-
end:
|
|
106
|
-
replacement: `<xi:include href="${
|
|
199
|
+
const s = O(o, "sec", n).map((a) => {
|
|
200
|
+
const c = `source/${t}/${a.filename}`;
|
|
201
|
+
return r[c] = S(a.span.outer), {
|
|
202
|
+
start: a.span.start,
|
|
203
|
+
end: a.span.end,
|
|
204
|
+
replacement: `<xi:include href="${t}/${a.filename}"/>`
|
|
107
205
|
};
|
|
108
206
|
});
|
|
109
|
-
return
|
|
207
|
+
return R(e, s);
|
|
110
208
|
}
|
|
111
|
-
function
|
|
112
|
-
const
|
|
113
|
-
if (!
|
|
114
|
-
return
|
|
209
|
+
function pe(e, t, r) {
|
|
210
|
+
const n = y(e, "book");
|
|
211
|
+
if (!n)
|
|
212
|
+
return r.push({
|
|
115
213
|
action: "anomaly",
|
|
116
214
|
severity: "warning",
|
|
117
215
|
kind: "structure",
|
|
@@ -119,200 +217,412 @@ function N(e, s, o) {
|
|
|
119
217
|
macro: "book",
|
|
120
218
|
occurrences: 1,
|
|
121
219
|
message: "Document was treated as a book but no <book> element found; emitting as a single file."
|
|
122
|
-
}),
|
|
123
|
-
const
|
|
124
|
-
let
|
|
125
|
-
if (
|
|
126
|
-
const p =
|
|
127
|
-
let m =
|
|
128
|
-
if (
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
220
|
+
}), N(e, t);
|
|
221
|
+
const o = {}, i = C(n.inner, "chapter");
|
|
222
|
+
let s = n.inner;
|
|
223
|
+
if (t.splitChapters && i.length > 0) {
|
|
224
|
+
const p = O(i, "ch", r).map((u) => {
|
|
225
|
+
let m = u.span.outer;
|
|
226
|
+
if (t.splitSections) {
|
|
227
|
+
const d = u.span.inner, f = ue(
|
|
228
|
+
d,
|
|
229
|
+
u.slug,
|
|
230
|
+
o,
|
|
231
|
+
r
|
|
134
232
|
);
|
|
135
|
-
m =
|
|
233
|
+
m = u.span.outer.slice(0, u.span.startTagEnd - u.span.start) + f + u.span.outer.slice(u.span.contentEnd - u.span.start);
|
|
136
234
|
}
|
|
137
|
-
const
|
|
138
|
-
return
|
|
139
|
-
start:
|
|
140
|
-
end:
|
|
141
|
-
replacement: `<xi:include href="${
|
|
235
|
+
const h = `source/${u.filename}`;
|
|
236
|
+
return o[h] = S(m), {
|
|
237
|
+
start: u.span.start,
|
|
238
|
+
end: u.span.end,
|
|
239
|
+
replacement: `<xi:include href="${u.filename}"/>`
|
|
142
240
|
};
|
|
143
241
|
});
|
|
144
|
-
|
|
242
|
+
s = R(n.inner, p);
|
|
145
243
|
}
|
|
146
|
-
const
|
|
147
|
-
return
|
|
148
|
-
|
|
149
|
-
),
|
|
244
|
+
const a = e.slice(n.start, n.startTagEnd) + s + e.slice(n.contentEnd, n.end), c = e.slice(0, n.start) + a + e.slice(n.end);
|
|
245
|
+
return o[t.mainSourcePath] = S(
|
|
246
|
+
G(M(c.trim()))
|
|
247
|
+
), o;
|
|
150
248
|
}
|
|
151
|
-
function
|
|
152
|
-
const
|
|
153
|
-
return t
|
|
154
|
-
|
|
155
|
-
),
|
|
249
|
+
function N(e, t, r) {
|
|
250
|
+
const n = {};
|
|
251
|
+
return n[t.mainSourcePath] = S(
|
|
252
|
+
M(e.trim())
|
|
253
|
+
), n;
|
|
156
254
|
}
|
|
157
|
-
function
|
|
158
|
-
const
|
|
159
|
-
splitChapters:
|
|
160
|
-
splitSections:
|
|
161
|
-
mainSourcePath:
|
|
162
|
-
publicationPath:
|
|
163
|
-
projectFilePath:
|
|
164
|
-
docinfoPath:
|
|
165
|
-
},
|
|
166
|
-
return
|
|
167
|
-
mainSource:
|
|
168
|
-
publication:
|
|
169
|
-
}),
|
|
255
|
+
function $e(e, t = {}) {
|
|
256
|
+
const r = [], n = t.documentKind ?? W(e), o = {
|
|
257
|
+
splitChapters: t.splitChapters ?? n === "book",
|
|
258
|
+
splitSections: t.splitSections ?? !1,
|
|
259
|
+
mainSourcePath: t.mainSourcePath ?? E.mainSourcePath,
|
|
260
|
+
publicationPath: t.publicationPath ?? E.publicationPath,
|
|
261
|
+
projectFilePath: t.projectFilePath ?? E.projectFilePath,
|
|
262
|
+
docinfoPath: t.docinfoPath ?? E.docinfoPath
|
|
263
|
+
}, i = n === "book" ? pe(e, o, r) : N(e, o);
|
|
264
|
+
return i[o.projectFilePath] = H({
|
|
265
|
+
mainSource: o.mainSourcePath,
|
|
266
|
+
publication: o.publicationPath
|
|
267
|
+
}), i[o.publicationPath] = U(), { files: i, documentKind: n, warnings: r };
|
|
170
268
|
}
|
|
171
|
-
class
|
|
269
|
+
class de extends Error {
|
|
172
270
|
constructor() {
|
|
173
271
|
super("Import cancelled."), this.name = "ConversionCancelledError";
|
|
174
272
|
}
|
|
175
273
|
}
|
|
176
|
-
let
|
|
177
|
-
function
|
|
178
|
-
const
|
|
179
|
-
let
|
|
180
|
-
const
|
|
274
|
+
let me = 0;
|
|
275
|
+
function fe(e, t, r = {}) {
|
|
276
|
+
const n = `convert-${me++}`, o = e(), { assets: i = {}, ...s } = r;
|
|
277
|
+
let a;
|
|
278
|
+
const c = new Promise((p, u) => {
|
|
181
279
|
let m = !1;
|
|
182
|
-
const
|
|
183
|
-
m || (m = !0,
|
|
280
|
+
const h = (d) => {
|
|
281
|
+
m || (m = !0, o.terminate(), d());
|
|
184
282
|
};
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
if (!(!
|
|
188
|
-
if (
|
|
189
|
-
|
|
283
|
+
a = () => h(() => u(new de())), o.addEventListener("message", (d) => {
|
|
284
|
+
const f = d.data;
|
|
285
|
+
if (!(!f || f.requestId !== n)) {
|
|
286
|
+
if (f.type === "result") {
|
|
287
|
+
h(() => p(f.result));
|
|
190
288
|
return;
|
|
191
289
|
}
|
|
192
|
-
|
|
290
|
+
h(() => u(new Error(f.message)));
|
|
193
291
|
}
|
|
194
|
-
}),
|
|
195
|
-
const
|
|
196
|
-
|
|
292
|
+
}), o.addEventListener("error", (d) => {
|
|
293
|
+
const f = typeof d == "object" && d && "message" in d ? String(d.message) : "The import worker failed to start.";
|
|
294
|
+
h(() => u(new Error(f)));
|
|
197
295
|
});
|
|
198
|
-
}),
|
|
296
|
+
}), l = [
|
|
199
297
|
...new Set(
|
|
200
|
-
Object.values(
|
|
298
|
+
Object.values(i).map((p) => p.buffer).filter(
|
|
201
299
|
(p) => p instanceof ArrayBuffer
|
|
202
300
|
)
|
|
203
301
|
)
|
|
204
302
|
];
|
|
205
|
-
return
|
|
206
|
-
{ type: "convert", requestId:
|
|
207
|
-
|
|
208
|
-
), { result:
|
|
303
|
+
return o.postMessage(
|
|
304
|
+
{ type: "convert", requestId: n, files: t, assets: i, options: s },
|
|
305
|
+
l
|
|
306
|
+
), { result: c, cancel: () => a?.() };
|
|
209
307
|
}
|
|
210
|
-
function
|
|
308
|
+
function Ae(e) {
|
|
211
309
|
const {
|
|
212
|
-
createWorker:
|
|
213
|
-
id:
|
|
214
|
-
label:
|
|
215
|
-
description:
|
|
216
|
-
acceptExtensions:
|
|
310
|
+
createWorker: t,
|
|
311
|
+
id: r = "worker",
|
|
312
|
+
label: n = "Built-in converter",
|
|
313
|
+
description: o = "Create a new project starting with LaTeX, Markdown, or PreTeXt files.",
|
|
314
|
+
acceptExtensions: i
|
|
217
315
|
} = e;
|
|
218
|
-
let
|
|
219
|
-
const
|
|
220
|
-
|
|
316
|
+
let s = null;
|
|
317
|
+
const a = async (c, l) => {
|
|
318
|
+
s?.cancel(), s = fe(t, c, l);
|
|
221
319
|
try {
|
|
222
|
-
return await
|
|
320
|
+
return await s.result;
|
|
223
321
|
} finally {
|
|
224
|
-
|
|
322
|
+
s = null;
|
|
225
323
|
}
|
|
226
324
|
};
|
|
227
325
|
return {
|
|
228
|
-
id:
|
|
229
|
-
label:
|
|
230
|
-
description:
|
|
231
|
-
acceptExtensions:
|
|
232
|
-
prepare: async (
|
|
233
|
-
const { files:
|
|
326
|
+
id: r,
|
|
327
|
+
label: n,
|
|
328
|
+
description: o,
|
|
329
|
+
acceptExtensions: i,
|
|
330
|
+
prepare: async (c) => {
|
|
331
|
+
const { files: l, assets: p } = await $(c);
|
|
234
332
|
return {
|
|
235
|
-
fileName:
|
|
236
|
-
files:
|
|
333
|
+
fileName: c.name,
|
|
334
|
+
files: l,
|
|
237
335
|
assets: p,
|
|
238
|
-
analysis:
|
|
336
|
+
analysis: Z(l)
|
|
239
337
|
};
|
|
240
338
|
},
|
|
241
|
-
convertPrepared: (
|
|
242
|
-
convertFile: async (
|
|
243
|
-
const { files: p, assets:
|
|
244
|
-
return
|
|
339
|
+
convertPrepared: (c, l) => a(c.files, { ...l, assets: c.assets }),
|
|
340
|
+
convertFile: async (c, l) => {
|
|
341
|
+
const { files: p, assets: u } = await $(c);
|
|
342
|
+
return a(p, { ...l, assets: u });
|
|
245
343
|
},
|
|
246
344
|
cancel: () => {
|
|
247
|
-
|
|
345
|
+
s?.cancel(), s = null;
|
|
248
346
|
}
|
|
249
347
|
};
|
|
250
348
|
}
|
|
349
|
+
const he = {
|
|
350
|
+
".docx": "docx",
|
|
351
|
+
".odt": "odt",
|
|
352
|
+
".epub": "epub",
|
|
353
|
+
".tex": "latex",
|
|
354
|
+
".ltx": "latex",
|
|
355
|
+
".md": "markdown",
|
|
356
|
+
".markdown": "markdown",
|
|
357
|
+
".html": "html",
|
|
358
|
+
".htm": "html",
|
|
359
|
+
".rst": "rst",
|
|
360
|
+
".org": "org",
|
|
361
|
+
".ipynb": "ipynb",
|
|
362
|
+
".typ": "typst",
|
|
363
|
+
".xml": "docbook",
|
|
364
|
+
".textile": "textile"
|
|
365
|
+
}, Fe = /* @__PURE__ */ new Set(["docx", "odt", "epub"]), j = [
|
|
366
|
+
".docx",
|
|
367
|
+
".odt",
|
|
368
|
+
".epub",
|
|
369
|
+
".html",
|
|
370
|
+
".htm",
|
|
371
|
+
".rst",
|
|
372
|
+
".org",
|
|
373
|
+
".ipynb",
|
|
374
|
+
".typ",
|
|
375
|
+
".textile",
|
|
376
|
+
".tex",
|
|
377
|
+
".ltx",
|
|
378
|
+
".md",
|
|
379
|
+
".markdown"
|
|
380
|
+
];
|
|
381
|
+
function X(e) {
|
|
382
|
+
const t = e.lastIndexOf(".");
|
|
383
|
+
return t <= 0 ? "" : e.slice(t).toLowerCase();
|
|
384
|
+
}
|
|
385
|
+
function ge(e) {
|
|
386
|
+
return he[X(e)];
|
|
387
|
+
}
|
|
388
|
+
function we(e) {
|
|
389
|
+
const {
|
|
390
|
+
convertToPretext: t,
|
|
391
|
+
id: r = "pandoc",
|
|
392
|
+
label: n = "Pandoc",
|
|
393
|
+
description: o = "Convert Word, OpenOffice, EPUB, HTML, reStructuredText, and more.",
|
|
394
|
+
acceptExtensions: i = j
|
|
395
|
+
} = e;
|
|
396
|
+
return {
|
|
397
|
+
id: r,
|
|
398
|
+
label: n,
|
|
399
|
+
description: o,
|
|
400
|
+
acceptExtensions: i,
|
|
401
|
+
convertFile: async (s, a) => {
|
|
402
|
+
const c = await t(s, a);
|
|
403
|
+
if (!c.trim())
|
|
404
|
+
throw new Error(
|
|
405
|
+
`Pandoc produced no output for ${s.name}. The file may be empty or in an unexpected format.`
|
|
406
|
+
);
|
|
407
|
+
const l = Y(
|
|
408
|
+
{ "source.ptx": c },
|
|
409
|
+
{
|
|
410
|
+
documentKind: a.documentKind,
|
|
411
|
+
splitChapters: a.splitChapters,
|
|
412
|
+
splitSections: a.splitSections,
|
|
413
|
+
splitLevel: a.splitLevel
|
|
414
|
+
}
|
|
415
|
+
);
|
|
416
|
+
return "pretextError" in l || (l.sourceName = s.name, l.sourcePath = s.name), l;
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
const xe = 3e4;
|
|
421
|
+
function Te(e) {
|
|
422
|
+
const t = /<pre>([\s\S]*?)<\/pre>/i.exec(e);
|
|
423
|
+
return (t ? t[1] : e).replace(/<[^>]+>/g, "").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&").trim();
|
|
424
|
+
}
|
|
425
|
+
function Pe(e, t, r) {
|
|
426
|
+
const n = Ee(Te(t)), o = n ? ` (${L(n)})` : "";
|
|
427
|
+
switch (e) {
|
|
428
|
+
case 400:
|
|
429
|
+
return `The pandoc server will not convert ${r}${o}.${x(r)}`;
|
|
430
|
+
case 401:
|
|
431
|
+
case 403:
|
|
432
|
+
return `The pandoc server rejected this site's credentials, so ${r} was never converted. Nothing is wrong with your file — this is a configuration problem with the service, and worth reporting.${x(r)}`;
|
|
433
|
+
case 404:
|
|
434
|
+
return `The pandoc conversion service could not be found at the address this site is configured to use. Nothing is wrong with your file — this is a configuration problem worth reporting.${x(r)}`;
|
|
435
|
+
case 413:
|
|
436
|
+
return `${r} is too large for the pandoc server to accept. Splitting it into chapters and importing them one at a time should get through.`;
|
|
437
|
+
case 422:
|
|
438
|
+
return `Pandoc could not read ${r}${o}. The file may be damaged, or may use features pandoc does not support.`;
|
|
439
|
+
case 503:
|
|
440
|
+
return `The pandoc server is running without its PreTeXt writer, so it cannot convert anything right now. Nothing is wrong with your file — this is a problem with the service, and worth reporting.${x(r)}`;
|
|
441
|
+
case 504:
|
|
442
|
+
return `Converting ${r} took longer than the pandoc server allows. Splitting it into chapters and importing them one at a time usually works.`;
|
|
443
|
+
default: {
|
|
444
|
+
const i = n ? `(HTTP ${e}: ${L(n)})` : `(HTTP ${e})`;
|
|
445
|
+
return `The pandoc server could not convert ${r} ${i}.${x(r)}`;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const F = 300;
|
|
450
|
+
function Ee(e) {
|
|
451
|
+
return e.replace(/\s+/g, " ").trim();
|
|
452
|
+
}
|
|
453
|
+
function L(e) {
|
|
454
|
+
return e.length <= F ? e : `${e.slice(0, F).trimEnd()}…`;
|
|
455
|
+
}
|
|
456
|
+
const Se = /* @__PURE__ */ new Set([
|
|
457
|
+
".tex",
|
|
458
|
+
".ltx",
|
|
459
|
+
".md",
|
|
460
|
+
".markdown"
|
|
461
|
+
]);
|
|
462
|
+
function x(e) {
|
|
463
|
+
return Se.has(X(e)) ? " You can import this file with the built-in converter instead." : "";
|
|
464
|
+
}
|
|
465
|
+
function Le(e) {
|
|
466
|
+
const {
|
|
467
|
+
url: t,
|
|
468
|
+
token: r,
|
|
469
|
+
headers: n,
|
|
470
|
+
credentials: o,
|
|
471
|
+
standalone: i = !0,
|
|
472
|
+
from: s,
|
|
473
|
+
timeoutMs: a = xe,
|
|
474
|
+
fetchImpl: c,
|
|
475
|
+
id: l = "pandoc-remote",
|
|
476
|
+
label: p = "Pandoc (server)",
|
|
477
|
+
description: u = "Convert Word, OpenOffice, EPUB, HTML, reStructuredText, and more — no local install needed.",
|
|
478
|
+
acceptExtensions: m = j
|
|
479
|
+
} = e;
|
|
480
|
+
return we({
|
|
481
|
+
convertToPretext: async (d, f) => {
|
|
482
|
+
const b = c ?? globalThis.fetch;
|
|
483
|
+
if (typeof b != "function")
|
|
484
|
+
throw new Error(
|
|
485
|
+
"This environment has no fetch; pass fetchImpl to createRemotePandocEngine."
|
|
486
|
+
);
|
|
487
|
+
const v = s ?? ge(d.name);
|
|
488
|
+
if (!v)
|
|
489
|
+
throw new Error(
|
|
490
|
+
`Pandoc cannot determine a format for ${d.name}. Supported extensions: ${m.join(", ")}.`
|
|
491
|
+
);
|
|
492
|
+
const g = new FormData();
|
|
493
|
+
r && g.set("token", r), g.set("file", d, d.name), g.set("from", v), i && g.set("standalone", "yes");
|
|
494
|
+
const I = new AbortController(), z = setTimeout(() => I.abort(), a);
|
|
495
|
+
let T;
|
|
496
|
+
try {
|
|
497
|
+
T = await b(t, {
|
|
498
|
+
method: "POST",
|
|
499
|
+
body: g,
|
|
500
|
+
headers: n,
|
|
501
|
+
credentials: o,
|
|
502
|
+
signal: I.signal
|
|
503
|
+
});
|
|
504
|
+
} catch (w) {
|
|
505
|
+
if (w instanceof Error && w.name === "AbortError")
|
|
506
|
+
throw new Error(
|
|
507
|
+
`Pandoc conversion of ${d.name} timed out after ${Math.round(a / 1e3)}s.`
|
|
508
|
+
);
|
|
509
|
+
const B = w instanceof Error ? w.message : String(w);
|
|
510
|
+
throw new Error(`Could not reach the pandoc server: ${B}`);
|
|
511
|
+
} finally {
|
|
512
|
+
clearTimeout(z);
|
|
513
|
+
}
|
|
514
|
+
const _ = await T.text();
|
|
515
|
+
if (!T.ok)
|
|
516
|
+
throw new Error(
|
|
517
|
+
Pe(T.status, _, d.name)
|
|
518
|
+
);
|
|
519
|
+
return _;
|
|
520
|
+
},
|
|
521
|
+
id: l,
|
|
522
|
+
label: p,
|
|
523
|
+
description: u,
|
|
524
|
+
acceptExtensions: m
|
|
525
|
+
});
|
|
526
|
+
}
|
|
251
527
|
export {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
528
|
+
Re as CLEAN_RULES,
|
|
529
|
+
de as ConversionCancelledError,
|
|
530
|
+
Kt as DEFAULT_IMPORT_MODE,
|
|
531
|
+
xe as DEFAULT_REMOTE_PANDOC_TIMEOUT_MS,
|
|
532
|
+
ke as DIVISION_LADDER,
|
|
533
|
+
De as LADDER_OVERFLOW_TAG,
|
|
534
|
+
Me as LATEX_DIVISION_COMMANDS,
|
|
535
|
+
Oe as LATEX_FORMAT_MARKERS,
|
|
536
|
+
Ne as MARKDOWN_FORMAT_MARKERS,
|
|
537
|
+
je as MAX_SUGGESTED_SPLIT_LEVEL,
|
|
538
|
+
j as PANDOC_ACCEPT_EXTENSIONS,
|
|
539
|
+
Fe as PANDOC_BINARY_FORMATS,
|
|
540
|
+
he as PANDOC_EXTENSION_FORMATS,
|
|
541
|
+
Xe as PRETEXT_DIVISION_TAGS,
|
|
542
|
+
ze as PRETEXT_ROOT_TAGS,
|
|
543
|
+
Be as PROJECT_DESTINATION,
|
|
544
|
+
Z as analyzeImportSources,
|
|
545
|
+
Ke as applyLatexFixes,
|
|
546
|
+
Wt as assetsForImportMode,
|
|
547
|
+
We as attachLatexRoots,
|
|
548
|
+
He as attachMarkdownRoots,
|
|
549
|
+
Ue as buildDivisionPool,
|
|
550
|
+
Ge as buildNativeDivisionPool,
|
|
551
|
+
$e as buildPretextProjectFiles,
|
|
552
|
+
qe as carryOverProjectFiles,
|
|
553
|
+
Ve as cleanLatex,
|
|
554
|
+
Ze as cleanLatexInChunks,
|
|
555
|
+
Ye as cleanLatexText,
|
|
556
|
+
Je as convertLatexToPretext,
|
|
557
|
+
Qe as convertMarkdownToPretext,
|
|
558
|
+
et as convertSourceToPretext,
|
|
559
|
+
we as createPandocEngine,
|
|
560
|
+
Le as createRemotePandocEngine,
|
|
561
|
+
Ae as createWorkerEngine,
|
|
562
|
+
tt as dedupeXmlIds,
|
|
563
|
+
nt as defaultAttachLevel,
|
|
564
|
+
rt as defaultManifestTarget,
|
|
565
|
+
Pe as describeRemotePandocFailure,
|
|
566
|
+
W as detectDocumentKind,
|
|
567
|
+
ve as detectSnippetFormat,
|
|
568
|
+
ot as detectSourceFormat,
|
|
569
|
+
Ht as diffHunks,
|
|
570
|
+
Ut as diffLines,
|
|
571
|
+
Gt as diffStats,
|
|
572
|
+
st as divisionChildRefs,
|
|
573
|
+
at as divisionsAtLevel,
|
|
574
|
+
it as expandPretextIncludes,
|
|
575
|
+
Te as extractPandocErrorDetail,
|
|
576
|
+
$ as extractUpload,
|
|
577
|
+
qt as fileChangesForImport,
|
|
578
|
+
X as fileExtension,
|
|
579
|
+
ct as filePrefixForDivision,
|
|
580
|
+
Vt as filesForImportMode,
|
|
581
|
+
lt as findLatexFixes,
|
|
582
|
+
ut as findLatexHeaders,
|
|
583
|
+
pt as findProjectManifest,
|
|
584
|
+
dt as fixesToWarnings,
|
|
585
|
+
Zt as formatWarningLine,
|
|
586
|
+
mt as getConversionErrorMessage,
|
|
587
|
+
ft as getLatexCleanDiagnostics,
|
|
588
|
+
ht as handleImportUploadFile,
|
|
589
|
+
Yt as hasNativeImportMode,
|
|
590
|
+
Y as importProjectFromFiles,
|
|
591
|
+
gt as isDivisionTag,
|
|
592
|
+
wt as ladderDepth,
|
|
593
|
+
xt as latexDivisionHierarchy,
|
|
594
|
+
Tt as latexFixesToCodeActions,
|
|
595
|
+
Pt as mergeChunksAtLevel,
|
|
596
|
+
Et as normalizePretextSource,
|
|
597
|
+
St as outlineDivisions,
|
|
598
|
+
ge as pandocFormatForFileName,
|
|
599
|
+
bt as parseLatexDivisions,
|
|
600
|
+
vt as parseProjectManifest,
|
|
601
|
+
It as prepareInsertSource,
|
|
602
|
+
Jt as projectForImportMode,
|
|
603
|
+
_t as pruneDivisions,
|
|
604
|
+
$t as rebuildImport,
|
|
605
|
+
le as recordsToPlusPayload,
|
|
606
|
+
At as relayoutImport,
|
|
607
|
+
H as renderProjectPtx,
|
|
608
|
+
Ft as renderProjectPtxFromManifest,
|
|
609
|
+
U as renderPublicationPtx,
|
|
610
|
+
Lt as reselectImport,
|
|
611
|
+
Qt as resolveImportMode,
|
|
612
|
+
yt as resolveImportSplitLevel,
|
|
613
|
+
Ct as resolveSplitLevel,
|
|
614
|
+
Rt as retargetFragment,
|
|
615
|
+
kt as retargetFragmentToDepth,
|
|
616
|
+
Dt as retargetImport,
|
|
617
|
+
fe as runConversionInWorker,
|
|
618
|
+
Mt as sanitizeRef,
|
|
619
|
+
re as scoreSnippetFormats,
|
|
620
|
+
Ot as serializeForDestination,
|
|
621
|
+
Nt as serializeInsertFiles,
|
|
622
|
+
_e as serializeInsertToRecords,
|
|
623
|
+
jt as serializeProjectToFiles,
|
|
624
|
+
Ie as serializeProjectToPlusPayload,
|
|
625
|
+
ie as serializeProjectToRecords,
|
|
626
|
+
Xt as shiftLadderTag,
|
|
627
|
+
zt as suggestSplitLevel
|
|
318
628
|
};
|