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