@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/index.js CHANGED
@@ -1,15 +1,15 @@
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);
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 r = t[1];
10
- return /[\\^_{}]/.test(r) || /^[A-Za-z]'?$/.test(r.trim());
9
+ const n = t[1];
10
+ return /[\\^_{}]/.test(n) || /^[A-Za-z]'?$/.test(n.trim());
11
11
  }
12
- const ee = [
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
- ], te = [
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
- ], ne = 2;
45
- function A(e, t) {
44
+ ], se = 2;
45
+ function $(e, t) {
46
46
  return t.reduce(
47
- (r, { pattern: n, weight: o }) => r + (n.test(e) ? o : 0),
47
+ (n, { pattern: r, weight: s }) => n + (r.test(e) ? s : 0),
48
48
  0
49
49
  );
50
50
  }
51
- function re(e) {
52
- return { latex: A(e, ee) + (Q(e) ? 2 : 0), markdown: A(e, te) };
51
+ function oe(e) {
52
+ return { latex: $(e, ne) + (te(e) ? 2 : 0), markdown: $(e, re) };
53
53
  }
54
- function ve(e) {
54
+ function Fe(e) {
55
55
  const t = e.trim();
56
56
  if (!t || t.startsWith("<"))
57
57
  return;
58
- const { latex: r, markdown: n } = re(t);
59
- if (!(Math.max(r, n) < ne))
60
- return r >= n ? "latex" : "markdown";
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 oe = {
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 se(e) {
76
+ function ie(e) {
77
77
  const t = e.split(".").pop()?.toLowerCase() ?? "";
78
- return oe[t] ?? "application/octet-stream";
78
+ return ae[t] ?? "application/octet-stream";
79
79
  }
80
80
  const P = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
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] : "=");
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 r.join("");
87
+ return n.join("");
88
88
  }
89
- function k(e) {
89
+ function D(e) {
90
90
  return {
91
91
  ref: e.ref,
92
92
  fileName: e.fileName,
93
- contentType: se(e.fileName),
94
- data: ae(e.data)
93
+ contentType: ie(e.fileName),
94
+ data: ce(e.data)
95
95
  };
96
96
  }
97
- function D(e) {
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 ie(e) {
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(D),
111
- assets: e.assets.map(k)
110
+ divisions: e.divisions.map(M),
111
+ assets: e.assets.map(D)
112
112
  };
113
113
  }
114
- function ce(e) {
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 le(e) {
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(ce)
138
+ assets_attributes: e.assets.map(ue)
139
139
  };
140
140
  }
141
- function Ie(e) {
142
- return le(ie(e));
141
+ function Le(e) {
142
+ return pe(le(e));
143
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)
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: [...n, ...i].map(D),
150
- assets: e.assets.map(k),
151
- placeholders: n.map(
152
- (s) => `<plus:${s.type} ref="${s.xmlId}"/>`
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 M(e) {
163
- return y(e, "pretext") ? e : `<pretext>
194
+ function O(e) {
195
+ return C(e, "pretext") ? e : `<pretext>
164
196
  ${e}
165
197
  </pretext>`;
166
198
  }
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"];
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 = q(c);
174
- l = m.startsWith(i) ? m : `${i}${m}`;
205
+ const m = Z(c);
206
+ l = m.startsWith(a) ? m : `${a}${m}`;
175
207
  } else
176
- l = `${i}${V(a + 1, e.length)}`, r.push({
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: s.name,
213
+ macro: o.name,
182
214
  occurrences: 1,
183
- message: `<${s.name}> at position ${a + 1} has no xml:id; using \`${l}\` as filename.`
215
+ message: `<${o.name}> at position ${i + 1} has no xml:id; using \`${l}\` as filename.`
184
216
  });
185
- const p = n.get(l) ?? 0;
186
- n.set(l, p + 1);
217
+ const p = r.get(l) ?? 0;
218
+ r.set(l, p + 1);
187
219
  const u = p === 0 ? l : `${l}-${p + 1}`;
188
- o.push({
189
- span: s,
220
+ s.push({
221
+ span: o,
190
222
  slug: u,
191
223
  filename: `${u}.ptx`
192
224
  });
193
- }), o;
225
+ }), s;
194
226
  }
195
- function ue(e, t, r, n) {
196
- const o = C(e, "section");
197
- if (o.length === 0)
227
+ function he(e, t, n, r) {
228
+ const s = k(e, "section");
229
+ if (s.length === 0)
198
230
  return e;
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}"/>`
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, s);
239
+ return R(e, o);
208
240
  }
209
- function pe(e, t, r) {
210
- const n = y(e, "book");
211
- if (!n)
212
- return r.push({
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
- }), 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) => {
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 = ue(
259
+ const d = u.span.inner, f = he(
228
260
  d,
229
261
  u.slug,
230
- o,
231
- r
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 o[h] = S(m), {
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
- s = R(n.inner, p);
274
+ o = R(r.inner, p);
243
275
  }
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;
248
- }
249
- function N(e, t, r) {
250
- const n = {};
251
- return n[t.mainSourcePath] = S(
252
- M(e.trim())
253
- ), n;
254
- }
255
- function $e(e, t = {}) {
256
- const r = [], n = t.documentKind ?? W(e), o = {
257
- splitChapters: t.splitChapters ?? n === "book",
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
- }, 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 };
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 de extends Error {
301
+ class we extends Error {
270
302
  constructor() {
271
303
  super("Import cancelled."), this.name = "ConversionCancelledError";
272
304
  }
273
305
  }
274
- let me = 0;
275
- function fe(e, t, r = {}) {
276
- const n = `convert-${me++}`, o = e(), { assets: i = {}, ...s } = r;
277
- let a;
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, o.terminate(), d());
313
+ m || (m = !0, s.terminate(), d());
282
314
  };
283
- a = () => h(() => u(new de())), o.addEventListener("message", (d) => {
315
+ i = () => h(() => u(new we())), s.addEventListener("message", (d) => {
284
316
  const f = d.data;
285
- if (!(!f || f.requestId !== n)) {
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
- }), o.addEventListener("error", (d) => {
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(i).map((p) => p.buffer).filter(
330
+ Object.values(a).map((p) => p.buffer).filter(
299
331
  (p) => p instanceof ArrayBuffer
300
332
  )
301
333
  )
302
334
  ];
303
- return o.postMessage(
304
- { type: "convert", requestId: n, files: t, assets: i, options: s },
335
+ return s.postMessage(
336
+ { type: "convert", requestId: r, files: t, assets: a, options: o },
305
337
  l
306
- ), { result: c, cancel: () => a?.() };
338
+ ), { result: c, cancel: () => i?.() };
307
339
  }
308
- function Ae(e) {
340
+ function De(e) {
309
341
  const {
310
342
  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
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 s = null;
317
- const a = async (c, l) => {
318
- s?.cancel(), s = fe(t, c, l);
348
+ let o = null;
349
+ const i = async (c, l) => {
350
+ o?.cancel(), o = xe(t, c, l);
319
351
  try {
320
- return await s.result;
352
+ return await o.result;
321
353
  } finally {
322
- s = null;
354
+ o = null;
323
355
  }
324
356
  };
325
357
  return {
326
- id: r,
327
- label: n,
328
- description: o,
329
- acceptExtensions: i,
358
+ id: n,
359
+ label: r,
360
+ description: s,
361
+ acceptExtensions: a,
330
362
  prepare: async (c) => {
331
- const { files: l, assets: p } = await $(c);
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: Z(l)
368
+ analysis: J(l)
337
369
  };
338
370
  },
339
- convertPrepared: (c, l) => a(c.files, { ...l, assets: c.assets }),
371
+ convertPrepared: (c, l) => i(c.files, { ...l, assets: c.assets }),
340
372
  convertFile: async (c, l) => {
341
- const { files: p, assets: u } = await $(c);
342
- return a(p, { ...l, assets: u });
373
+ const { files: p, assets: u } = await A(c);
374
+ return i(p, { ...l, assets: u });
343
375
  },
344
376
  cancel: () => {
345
- s?.cancel(), s = null;
377
+ o?.cancel(), o = null;
346
378
  }
347
379
  };
348
380
  }
349
- const he = {
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
- }, Fe = /* @__PURE__ */ new Set(["docx", "odt", "epub"]), j = [
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 X(e) {
413
+ function z(e) {
382
414
  const t = e.lastIndexOf(".");
383
415
  return t <= 0 ? "" : e.slice(t).toLowerCase();
384
416
  }
385
- function ge(e) {
386
- return he[X(e)];
417
+ function Ee(e) {
418
+ return Pe[z(e)];
387
419
  }
388
- function we(e) {
420
+ function Se(e) {
389
421
  const {
390
422
  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
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: r,
398
- label: n,
399
- description: o,
400
- acceptExtensions: i,
401
- convertFile: async (s, a) => {
402
- const c = await t(s, a);
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 ${s.name}. The file may be empty or in an unexpected format.`
437
+ `Pandoc produced no output for ${o.name}. The file may be empty or in an unexpected format.`
406
438
  );
407
- const l = Y(
439
+ const l = Q(
408
440
  { "source.ptx": c },
409
441
  {
410
- documentKind: a.documentKind,
411
- splitChapters: a.splitChapters,
412
- splitSections: a.splitSections,
413
- splitLevel: a.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 = s.name, l.sourcePath = s.name), l;
448
+ return "pretextError" in l || (l.sourceName = o.name, l.sourcePath = o.name), l;
417
449
  }
418
450
  };
419
451
  }
420
- const xe = 3e4;
421
- function Te(e) {
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(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&amp;/g, "&").trim();
424
456
  }
425
- function Pe(e, t, r) {
426
- const n = Ee(Te(t)), o = n ? ` (${L(n)})` : "";
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 ${r}${o}.${x(r)}`;
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 ${r} was never converted. Nothing is wrong with your file — this is a configuration problem with the service, and worth reporting.${x(r)}`;
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.${x(r)}`;
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 `${r} is too large for the pandoc server to accept. Splitting it into chapters and importing them one at a time should get through.`;
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 ${r}${o}. The file may be damaged, or may use features pandoc does not support.`;
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.${x(r)}`;
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 ${r} took longer than the pandoc server allows. Splitting it into chapters and importing them one at a time usually works.`;
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 i = n ? `(HTTP ${e}: ${L(n)})` : `(HTTP ${e})`;
445
- return `The pandoc server could not convert ${r} ${i}.${x(r)}`;
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 F = 300;
450
- function Ee(e) {
481
+ const L = 300;
482
+ function _e(e) {
451
483
  return e.replace(/\s+/g, " ").trim();
452
484
  }
453
- function L(e) {
454
- return e.length <= F ? e : `${e.slice(0, F).trimEnd()}…`;
485
+ function y(e) {
486
+ return e.length <= L ? e : `${e.slice(0, L).trimEnd()}…`;
455
487
  }
456
- const Se = /* @__PURE__ */ new Set([
488
+ const Ae = /* @__PURE__ */ new Set([
457
489
  ".tex",
458
490
  ".ltx",
459
491
  ".md",
460
492
  ".markdown"
461
493
  ]);
462
- function x(e) {
463
- return Se.has(X(e)) ? " You can import this file with the built-in converter instead." : "";
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 Le(e) {
497
+ function Oe(e) {
466
498
  const {
467
499
  url: t,
468
- token: r,
469
- headers: n,
470
- credentials: o,
471
- standalone: i = !0,
472
- from: s,
473
- timeoutMs: a = xe,
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 = j
510
+ acceptExtensions: m = X
479
511
  } = e;
480
- return we({
512
+ return Se({
481
513
  convertToPretext: async (d, f) => {
482
- const b = c ?? globalThis.fetch;
483
- if (typeof b != "function")
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 v = s ?? ge(d.name);
488
- if (!v)
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
- 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;
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
- T = await b(t, {
529
+ x = await v(t, {
498
530
  method: "POST",
499
531
  body: g,
500
- headers: n,
501
- credentials: o,
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(a / 1e3)}s.`
539
+ `Pandoc conversion of ${d.name} timed out after ${Math.round(i / 1e3)}s.`
508
540
  );
509
- const B = w instanceof Error ? w.message : String(w);
510
- throw new Error(`Could not reach the pandoc server: ${B}`);
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(z);
544
+ clearTimeout(B);
513
545
  }
514
- const _ = await T.text();
515
- if (!T.ok)
546
+ const _ = await x.text();
547
+ if (!x.ok)
516
548
  throw new Error(
517
- Pe(T.status, _, d.name)
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
- 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
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
  };