@fiduswriter/books-document 0.1.1 → 0.1.2

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.
Files changed (80) hide show
  1. package/README.md +3 -3
  2. package/dist/exporter/bits/index.d.ts.map +1 -1
  3. package/dist/exporter/bits/index.js +7 -3
  4. package/dist/exporter/bits/index.js.map +1 -1
  5. package/dist/exporter/bits/templates.d.ts.map +1 -1
  6. package/dist/exporter/bits/templates.js.map +1 -1
  7. package/dist/exporter/docx/index.d.ts.map +1 -1
  8. package/dist/exporter/docx/index.js +4 -2
  9. package/dist/exporter/docx/index.js.map +1 -1
  10. package/dist/exporter/docx/render.d.ts.map +1 -1
  11. package/dist/exporter/docx/render.js.map +1 -1
  12. package/dist/exporter/epub/index.d.ts.map +1 -1
  13. package/dist/exporter/epub/index.js +12 -5
  14. package/dist/exporter/epub/index.js.map +1 -1
  15. package/dist/exporter/epub/templates.d.ts.map +1 -1
  16. package/dist/exporter/epub/templates.js.map +1 -1
  17. package/dist/exporter/epub/tools.d.ts.map +1 -1
  18. package/dist/exporter/epub/tools.js.map +1 -1
  19. package/dist/exporter/html/index.d.ts.map +1 -1
  20. package/dist/exporter/html/index.js +5 -2
  21. package/dist/exporter/html/index.js.map +1 -1
  22. package/dist/exporter/html/templates.d.ts.map +1 -1
  23. package/dist/exporter/html/templates.js +1 -3
  24. package/dist/exporter/html/templates.js.map +1 -1
  25. package/dist/exporter/html/tools.d.ts.map +1 -1
  26. package/dist/exporter/html/tools.js +2 -1
  27. package/dist/exporter/html/tools.js.map +1 -1
  28. package/dist/exporter/latex/index.d.ts.map +1 -1
  29. package/dist/exporter/latex/index.js.map +1 -1
  30. package/dist/exporter/latex/templates.d.ts.map +1 -1
  31. package/dist/exporter/latex/templates.js.map +1 -1
  32. package/dist/exporter/native/index.d.ts.map +1 -1
  33. package/dist/exporter/native/index.js +1 -1
  34. package/dist/exporter/native/index.js.map +1 -1
  35. package/dist/exporter/odt/index.d.ts.map +1 -1
  36. package/dist/exporter/odt/index.js +4 -2
  37. package/dist/exporter/odt/index.js.map +1 -1
  38. package/dist/exporter/odt/render.d.ts.map +1 -1
  39. package/dist/exporter/odt/render.js.map +1 -1
  40. package/dist/exporter/print/index.d.ts.map +1 -1
  41. package/dist/exporter/print/index.js +1 -2
  42. package/dist/exporter/print/index.js.map +1 -1
  43. package/dist/exporter/print/templates.js.map +1 -1
  44. package/dist/exporter/tools.d.ts.map +1 -1
  45. package/dist/exporter/tools.js +4 -2
  46. package/dist/exporter/tools.js.map +1 -1
  47. package/dist/importer/native/index.d.ts.map +1 -1
  48. package/dist/importer/native/index.js +6 -5
  49. package/dist/importer/native/index.js.map +1 -1
  50. package/dist/importer/native/reader.d.ts.map +1 -1
  51. package/dist/importer/native/reader.js +3 -1
  52. package/dist/importer/native/reader.js.map +1 -1
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js.map +1 -1
  55. package/dist/types.d.ts.map +1 -1
  56. package/package.json +103 -93
  57. package/src/exporter/bits/index.ts +31 -27
  58. package/src/exporter/bits/templates.ts +4 -4
  59. package/src/exporter/docx/index.ts +32 -33
  60. package/src/exporter/docx/render.ts +17 -16
  61. package/src/exporter/epub/index.ts +43 -23
  62. package/src/exporter/epub/templates.ts +14 -12
  63. package/src/exporter/epub/tools.ts +5 -3
  64. package/src/exporter/html/index.ts +46 -32
  65. package/src/exporter/html/templates.ts +13 -15
  66. package/src/exporter/html/tools.ts +9 -4
  67. package/src/exporter/latex/index.ts +20 -17
  68. package/src/exporter/latex/templates.ts +6 -2
  69. package/src/exporter/native/index.ts +14 -14
  70. package/src/exporter/odt/index.ts +26 -27
  71. package/src/exporter/odt/render.ts +17 -16
  72. package/src/exporter/print/index.ts +11 -15
  73. package/src/exporter/print/templates.ts +1 -1
  74. package/src/exporter/tools.ts +44 -15
  75. package/src/importer/native/index.ts +30 -23
  76. package/src/importer/native/reader.ts +18 -9
  77. package/src/index.ts +1 -1
  78. package/src/modules.d.ts +1 -1
  79. package/src/types.ts +2 -2
  80. package/src/global.d.ts +0 -2
@@ -1,9 +1,9 @@
1
- import {LANGUAGES} from "@fiduswriter/document/schema/const"
2
- import {escapeText, localizeDate} from "fwtoolkit"
3
- import {mathliveOpfIncludes} from "@fiduswriter/document/mathlive/opf_includes"
1
+ import { LANGUAGES } from "@fiduswriter/document/schema/const"
2
+ import { escapeText, localizeDate } from "fwtoolkit"
3
+ import { mathliveOpfIncludes } from "@fiduswriter/document/mathlive/opf_includes"
4
4
 
5
- import type {Book} from "../../types.js"
6
- import {bookTerm} from "../../i18n.js"
5
+ import type { Book } from "../../types.js"
6
+ import { bookTerm } from "../../i18n.js"
7
7
 
8
8
  export const containerTemplate = () => `<?xml version="1.0" encoding="UTF-8"?>
9
9
  <container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
@@ -184,11 +184,11 @@ export const epubBookOpfTemplate = ({
184
184
  idType: string
185
185
  date: string
186
186
  modified: string
187
- styleSheets: Array<{filename: string}>
187
+ styleSheets: Array<{ filename: string }>
188
188
  math: boolean
189
- images: Array<{coverImage?: boolean; filename: string; mimeType?: string}>
190
- fontFiles: Array<{filename: string; mimeType?: string}>
191
- chapters: Array<{number: number}>
189
+ images: Array<{ coverImage?: boolean; filename: string; mimeType?: string }>
190
+ fontFiles: Array<{ filename: string; mimeType?: string }>
191
+ chapters: Array<{ number: number }>
192
192
  user: Record<string, string>
193
193
  }) => `<?xml version="1.0" encoding="UTF-8"?>
194
194
  <package xmlns="http://www.idpf.org/2007/opf" version="3.0"
@@ -296,7 +296,9 @@ export const epubBookOpfTemplate = ({
296
296
  ${book.cover_image ? '<itemref idref="cover" linear="no"/>' : ""}
297
297
  <itemref idref="titlepage" linear="yes"/>
298
298
  ${chapters
299
- .map(chapter => `<itemref idref="t${chapter.number}" linear="yes" />`)
299
+ .map(
300
+ chapter => `<itemref idref="t${chapter.number}" linear="yes" />`
301
+ )
300
302
  .join("")}
301
303
  <itemref idref="copyright" linear="yes"/>
302
304
  <itemref idref="nav" linear="no"/>
@@ -316,7 +318,7 @@ export const navTemplate = ({
316
318
  }: {
317
319
  shortLang: string
318
320
  toc: TocItem[]
319
- styleSheets: Array<{filename: string}>
321
+ styleSheets: Array<{ filename: string }>
320
322
  }) =>
321
323
  `<?xml version="1.0" encoding="UTF-8"?>
322
324
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="${shortLang}"
@@ -384,7 +386,7 @@ export const ncxTemplate = ({
384
386
 
385
387
  const renderNcxItems = (
386
388
  items: TocItem[],
387
- counter: {count: number} = {count: 1}
389
+ counter: { count: number } = { count: 1 }
388
390
  ): string =>
389
391
  items
390
392
  .map(
@@ -55,9 +55,11 @@ export function buildHierarchy(
55
55
  parentLevel--
56
56
  }
57
57
  if (parent) {
58
- ;(idMap[parent.id as string | number].children as Array<
59
- Record<string, unknown>
60
- >).push(node)
58
+ ;(
59
+ idMap[parent.id as string | number].children as Array<
60
+ Record<string, unknown>
61
+ >
62
+ ).push(node)
61
63
  } else {
62
64
  root.push(node)
63
65
  }
@@ -2,17 +2,22 @@
2
2
  * HTML book exporter.
3
3
  */
4
4
 
5
- import type {Schema} from "prosemirror-model"
6
- import type {CSL, User} from "@fiduswriter/document"
7
- import {HTMLExporter} from "@fiduswriter/document/exporter/html/index"
8
- import {createSlug} from "@fiduswriter/document/exporter/tools/file"
9
- import {ZipFileCreator} from "@fiduswriter/document/exporter/tools/zip"
10
- import {LANGUAGES} from "@fiduswriter/document/schema/const"
11
- import {addAlert, get, staticUrl} from "fwtoolkit"
5
+ import type { Schema } from "prosemirror-model"
6
+ import type { CSL, User } from "@fiduswriter/document"
7
+ import { HTMLExporter } from "@fiduswriter/document/exporter/html/index"
8
+ import { createSlug } from "@fiduswriter/document/exporter/tools/file"
9
+ import { ZipFileCreator } from "@fiduswriter/document/exporter/tools/zip"
10
+ import { LANGUAGES } from "@fiduswriter/document/schema/const"
11
+ import { addAlert, get, gettext, staticUrl } from "fwtoolkit"
12
12
  import pretty from "pretty"
13
13
 
14
- import type {Book, BookStyle, BookStyles, DocumentListEntry} from "../../types.js"
15
- import {getMissingChapterData} from "../tools.js"
14
+ import type {
15
+ Book,
16
+ BookStyle,
17
+ BookStyles,
18
+ DocumentListEntry
19
+ } from "../../types.js"
20
+ import { getMissingChapterData } from "../tools.js"
16
21
  import {
17
22
  htmlBookChapterTemplate,
18
23
  htmlBookExportTemplate,
@@ -22,7 +27,7 @@ import {
22
27
  singleFileHTMLBookChapterTemplate,
23
28
  singleFileHTMLBookTemplate
24
29
  } from "./templates.js"
25
- import {orderLinks} from "./tools.js"
30
+ import { orderLinks } from "./tools.js"
26
31
 
27
32
  interface StyleSheet {
28
33
  url?: string
@@ -84,7 +89,7 @@ export class HTMLBookExporter {
84
89
  docList: DocumentListEntry[],
85
90
  updated: any,
86
91
  multiDoc = true,
87
- {relativeUrls = true} = {}
92
+ { relativeUrls = true } = {}
88
93
  ) {
89
94
  this.schema = schema
90
95
  this.csl = csl
@@ -109,7 +114,7 @@ export class HTMLBookExporter {
109
114
  : htmlBookIndexBodyTemplate
110
115
  this.singleFileHTMLBookTemplate = singleFileHTMLBookTemplate
111
116
  this.singleFileHTMLBookCSSTemplate = singleFileHTMLBookCSSTemplate
112
- this.styleSheets = [{url: staticUrl("css/book.css")}]
117
+ this.styleSheets = [{ url: staticUrl("css/book.css") }]
113
118
  }
114
119
 
115
120
  async init(): Promise<Blob | false | void> {
@@ -165,8 +170,8 @@ export class HTMLBookExporter {
165
170
  continue
166
171
  }
167
172
 
168
- const imageDB = {db: doc.images || {}}
169
- const bibDB = {db: doc.bibliography || {}}
173
+ const imageDB = { db: doc.images || {} }
174
+ const bibDB = { db: doc.bibliography || {} }
170
175
  const styleSheets = this.styleSheets.slice()
171
176
 
172
177
  const options = {
@@ -198,7 +203,7 @@ export class HTMLBookExporter {
198
203
  )
199
204
 
200
205
  await documentHTMLExporter.process()
201
- const {metaData, converter, textFiles, httpFiles} =
206
+ const { metaData, converter, textFiles, httpFiles } =
202
207
  documentHTMLExporter.getProcessedFiles() as any
203
208
 
204
209
  const contents = textFiles.find(
@@ -219,7 +224,7 @@ export class HTMLBookExporter {
219
224
 
220
225
  if (converter.features.math) {
221
226
  this.math = true
222
- styleSheets.push({filename: "css/mathlive.css"})
227
+ styleSheets.push({ filename: "css/mathlive.css" })
223
228
  }
224
229
 
225
230
  if (converter.citations.bibCSS) {
@@ -228,7 +233,7 @@ export class HTMLBookExporter {
228
233
  ocd: true
229
234
  })
230
235
  }
231
- styleSheets.push({filename: "css/bibliography.css"})
236
+ styleSheets.push({ filename: "css/bibliography.css" })
232
237
  }
233
238
 
234
239
  const chapterHTML = this.chapterTemplate({
@@ -242,7 +247,7 @@ export class HTMLBookExporter {
242
247
 
243
248
  this.textFiles.push({
244
249
  filename: `document-${chapterNumber}.html`,
245
- contents: pretty(chapterHTML, {ocd: true})
250
+ contents: pretty(chapterHTML, { ocd: true })
246
251
  })
247
252
 
248
253
  this.chapters.push({
@@ -321,7 +326,7 @@ export class HTMLBookExporter {
321
326
  language,
322
327
  multiDoc: this.multiDoc
323
328
  }),
324
- {ocd: true}
329
+ { ocd: true }
325
330
  )
326
331
  })
327
332
  if (!this.multiDoc) {
@@ -335,15 +340,15 @@ export class HTMLBookExporter {
335
340
  if (this.bibCSS) {
336
341
  styleSheets.push(
337
342
  this.relativeUrls
338
- ? {filename: "css/bibliography.css"}
339
- : {contents: this.bibCSS}
343
+ ? { filename: "css/bibliography.css" }
344
+ : { contents: this.bibCSS }
340
345
  )
341
346
  }
342
347
  if (this.math) {
343
348
  styleSheets.push(
344
349
  this.relativeUrls
345
- ? {filename: "css/mathlive.css"}
346
- : {filename: staticUrl("css/mathlive.css")}
350
+ ? { filename: "css/mathlive.css" }
351
+ : { filename: staticUrl("css/mathlive.css") }
347
352
  )
348
353
  }
349
354
  let html = ""
@@ -355,8 +360,12 @@ export class HTMLBookExporter {
355
360
  if (b.filename === "index.html") {
356
361
  return 1
357
362
  }
358
- const aNum = Number.parseInt(a.filename.match(/\d+/g)?.[0] || "0")
359
- const bNum = Number.parseInt(b.filename.match(/\d+/g)?.[0] || "0")
363
+ const aNum = Number.parseInt(
364
+ a.filename.match(/\d+/g)?.[0] || "0"
365
+ )
366
+ const bNum = Number.parseInt(
367
+ b.filename.match(/\d+/g)?.[0] || "0"
368
+ )
360
369
  if (aNum < bNum) {
361
370
  return -1
362
371
  }
@@ -365,7 +374,7 @@ export class HTMLBookExporter {
365
374
  }
366
375
  return 0
367
376
  })
368
- .filter(({filename, contents}) => {
377
+ .filter(({ filename, contents }) => {
369
378
  if (filename.slice(-5) !== ".html") {
370
379
  return true
371
380
  }
@@ -387,7 +396,7 @@ export class HTMLBookExporter {
387
396
 
388
397
  this.textFiles.push({
389
398
  filename: "index.html",
390
- contents: pretty(htmlDoc, {ocd: true})
399
+ contents: pretty(htmlDoc, { ocd: true })
391
400
  })
392
401
  }
393
402
 
@@ -407,12 +416,17 @@ export class HTMLBookExporter {
407
416
  ))
408
417
  )
409
418
 
410
- this.styleSheets.push({contents, filename: `css/${bookStyle.slug}.css`})
419
+ this.styleSheets.push({
420
+ contents,
421
+ filename: `css/${bookStyle.slug}.css`
422
+ })
411
423
  this.httpFiles = this.httpFiles.concat(
412
- bookStyle.bookstylefile_set.map(([url, filename]: [string, string]) => ({
413
- filename: `css/media/${filename}`,
414
- url
415
- }))
424
+ bookStyle.bookstylefile_set.map(
425
+ ([url, filename]: [string, string]) => ({
426
+ filename: `css/media/${filename}`,
427
+ url
428
+ })
429
+ )
416
430
  )
417
431
  return true
418
432
  }
@@ -1,13 +1,15 @@
1
- import {escapeText, localizeDate} from "fwtoolkit"
1
+ import { escapeText, localizeDate } from "fwtoolkit"
2
2
 
3
- import type {Book} from "../../types.js"
4
- import {bookTerm} from "../../i18n.js"
3
+ import type { Book } from "../../types.js"
4
+ import { bookTerm } from "../../i18n.js"
5
5
 
6
- export const htmlBookChapterTemplate = ({body, back}: Record<string, unknown>) =>
7
- `${body}${back}`
6
+ export const htmlBookChapterTemplate = ({
7
+ body,
8
+ back
9
+ }: Record<string, unknown>) => `${body}${back}`
8
10
 
9
11
  interface HtmlBookExportParams {
10
- styleSheets: Array<{filename: string}>
12
+ styleSheets: Array<{ filename: string }>
11
13
  part?: string
12
14
  currentPart?: string
13
15
  contents: string
@@ -41,11 +43,7 @@ export const htmlBookExportTemplate = ({
41
43
  ? ` ${currentPart.toLowerCase().replace(/[^a-z]/g, "")}`
42
44
  : ""
43
45
  }">
44
- ${
45
- part?.length
46
- ? `<h1 class="part">${escapeText(part)}</h1>`
47
- : ""
48
- }
46
+ ${part?.length ? `<h1 class="part">${escapeText(part)}</h1>` : ""}
49
47
  ${contents}
50
48
  </body>
51
49
  </html>`
@@ -75,7 +73,7 @@ const htmlBookIndexItemTemplate = ({
75
73
  ? `<ol>
76
74
  ${(item.subItems as Array<Record<string, unknown>>)
77
75
  .map(subItem =>
78
- htmlBookIndexItemTemplate({item: subItem, multiDoc})
76
+ htmlBookIndexItemTemplate({ item: subItem, multiDoc })
79
77
  )
80
78
  .join("")}
81
79
  </ol>`
@@ -178,7 +176,7 @@ export const htmlBookIndexBodyTemplate = ({
178
176
  <div class="tocpage frontmatter">
179
177
  <nav role="doc-toc"><ol>
180
178
  ${contentItems
181
- .map(item => htmlBookIndexItemTemplate({item, multiDoc}))
179
+ .map(item => htmlBookIndexItemTemplate({ item, multiDoc }))
182
180
  .join("")}
183
181
  </ol></nav>
184
182
  </div>`
@@ -188,7 +186,7 @@ interface HtmlBookIndexParams {
188
186
  contentItems: Array<Record<string, unknown>>
189
187
  language: string
190
188
  creator: string
191
- styleSheets: Array<{filename: string}>
189
+ styleSheets: Array<{ filename: string }>
192
190
  multiDoc: boolean
193
191
  }
194
192
 
@@ -251,7 +249,7 @@ export const singleFileHTMLBookTemplate = ({
251
249
  <style>
252
250
  ${css}
253
251
  </style>
254
- ${(styleSheets as Array<{filename?: string; contents?: string}>)
252
+ ${(styleSheets as Array<{ filename?: string; contents?: string }>)
255
253
  .map(sheet =>
256
254
  sheet.filename
257
255
  ? `<link type="text/css" rel="stylesheet" href="${sheet.filename}" />`
@@ -5,10 +5,15 @@ export function orderLinks(
5
5
  contentItems[i].subItems = []
6
6
  if (i > 0) {
7
7
  for (let j = i - 1; j > -1; j--) {
8
- if ((contentItems[j].level as number) < (contentItems[i].level as number)) {
9
- ;(contentItems[j].subItems as Array<Record<string, unknown>>).push(
10
- contentItems[i]
11
- )
8
+ if (
9
+ (contentItems[j].level as number) <
10
+ (contentItems[i].level as number)
11
+ ) {
12
+ ;(
13
+ contentItems[j].subItems as Array<
14
+ Record<string, unknown>
15
+ >
16
+ ).push(contentItems[i])
12
17
  contentItems[i].delete = true
13
18
  break
14
19
  }
@@ -2,17 +2,17 @@
2
2
  * LaTeX book exporter.
3
3
  */
4
4
 
5
- import type {Schema} from "prosemirror-model"
6
- import type {User} from "@fiduswriter/document"
7
- import {BibLatexExporter} from "biblatex-csl-converter"
8
- import {LatexExporterConvert} from "@fiduswriter/document/exporter/latex/convert"
9
- import {removeHidden} from "@fiduswriter/document/exporter/tools/doc_content"
10
- import {createSlug} from "@fiduswriter/document/exporter/tools/file"
11
- import {ZipFileCreator} from "@fiduswriter/document/exporter/tools/zip"
5
+ import type { Schema } from "prosemirror-model"
6
+ import type { User } from "@fiduswriter/document"
7
+ import { BibLatexExporter } from "biblatex-csl-converter"
8
+ import { LatexExporterConvert } from "@fiduswriter/document/exporter/latex/convert"
9
+ import { removeHidden } from "@fiduswriter/document/exporter/tools/doc_content"
10
+ import { createSlug } from "@fiduswriter/document/exporter/tools/file"
11
+ import { ZipFileCreator } from "@fiduswriter/document/exporter/tools/zip"
12
12
 
13
- import type {Book, DocumentListEntry} from "../../types.js"
14
- import {getMissingChapterData} from "../tools.js"
15
- import {bookTexTemplate} from "./templates.js"
13
+ import type { Book, DocumentListEntry } from "../../types.js"
14
+ import { getMissingChapterData } from "../tools.js"
15
+ import { bookTexTemplate } from "./templates.js"
16
16
 
17
17
  interface TextFile {
18
18
  filename: string
@@ -65,7 +65,7 @@ export class LatexBookExporter {
65
65
  let imageIds: string[] = []
66
66
  const features: Record<string, boolean> = {}
67
67
  const combinedBibliography: Record<string, unknown> = {}
68
- const combinedImages: Record<string, {image: string}> = {}
68
+ const combinedImages: Record<string, { image: string }> = {}
69
69
  this.book.chapters.forEach((chapter, index) => {
70
70
  const doc = this.docList.find(d => d.id === chapter.text)
71
71
  if (!doc) {
@@ -73,8 +73,8 @@ export class LatexBookExporter {
73
73
  }
74
74
  const converter = new LatexExporterConvert(
75
75
  this as any,
76
- {db: doc.images || {}},
77
- {db: doc.bibliography || {}},
76
+ { db: doc.images || {} },
77
+ { db: doc.bibliography || {} },
78
78
  doc.settings
79
79
  )
80
80
  const chapterContent = removeHidden(doc.content as any)
@@ -87,7 +87,10 @@ export class LatexBookExporter {
87
87
  ...new Set(bibIds.concat(Object.keys(convertedDoc.usedBibDB)))
88
88
  ]
89
89
  imageIds = [...new Set(imageIds.concat(convertedDoc.imageIds))]
90
- Object.assign(features, converter.features as Record<string, boolean>)
90
+ Object.assign(
91
+ features,
92
+ converter.features as Record<string, boolean>
93
+ )
91
94
  Object.keys(convertedDoc.usedBibDB).forEach(
92
95
  bibId =>
93
96
  (combinedBibliography[bibId] = doc.bibliography?.[bibId])
@@ -120,9 +123,9 @@ export class LatexBookExporter {
120
123
  })
121
124
  const bookConverter = new LatexExporterConvert(
122
125
  this as any,
123
- {db: combinedImages as any},
124
- {db: combinedBibliography as any},
125
- {language: this.book.settings.language, bibliography_header: {}}
126
+ { db: combinedImages as any },
127
+ { db: combinedBibliography as any },
128
+ { language: this.book.settings.language, bibliography_header: {} }
126
129
  )
127
130
  bookConverter.features = features
128
131
  const preamble = bookConverter.assemblePreamble()
@@ -1,7 +1,11 @@
1
- import type {BookTexTemplateParams} from "../../types.js"
1
+ import type { BookTexTemplateParams } from "../../types.js"
2
2
 
3
3
  /** A template to create the latex book.tex file. */
4
- export const bookTexTemplate = ({preamble, book, epilogue}: BookTexTemplateParams) =>
4
+ export const bookTexTemplate = ({
5
+ preamble,
6
+ book,
7
+ epilogue
8
+ }: BookTexTemplateParams) =>
5
9
  `\\documentclass[11pt]{book}
6
10
  ${preamble}
7
11
  \\usepackage{docmute}
@@ -2,15 +2,15 @@
2
2
  * Native `.fidusbook` exporter.
3
3
  */
4
4
 
5
- import type {Schema} from "prosemirror-model"
6
- import {ShrinkFidus} from "@fiduswriter/document/exporter/native/shrink"
7
- import {createSlug} from "@fiduswriter/document/exporter/tools/file"
8
- import {ZipFileCreator} from "@fiduswriter/document/exporter/tools/zip"
9
- import {addAlert} from "fwtoolkit"
5
+ import type { Schema } from "prosemirror-model"
6
+ import { ShrinkFidus } from "@fiduswriter/document/exporter/native/shrink"
7
+ import { createSlug } from "@fiduswriter/document/exporter/tools/file"
8
+ import { ZipFileCreator } from "@fiduswriter/document/exporter/tools/zip"
9
+ import { addAlert, gettext } from "fwtoolkit"
10
10
 
11
- import {FIDUSBOOK_VERSION} from "../../schema/index.js"
12
- import type {Book, DocumentListEntry, User} from "../../types.js"
13
- import {getMissingChapterData} from "../tools.js"
11
+ import { FIDUSBOOK_VERSION } from "../../schema/index.js"
12
+ import type { Book, DocumentListEntry, User } from "../../types.js"
13
+ import { getMissingChapterData } from "../tools.js"
14
14
 
15
15
  interface FileInclude {
16
16
  url: string
@@ -22,7 +22,7 @@ interface TextFile {
22
22
  contents: string
23
23
  }
24
24
 
25
- export {FIDUSBOOK_VERSION}
25
+ export { FIDUSBOOK_VERSION }
26
26
 
27
27
  export class NativeBookExporter {
28
28
  schema: Schema
@@ -100,7 +100,7 @@ export class NativeBookExporter {
100
100
  file_type: coverImage.file_type,
101
101
  image: `cover/${filename}`
102
102
  }
103
- httpFiles.push({url: imageUrl, filename: `cover/${filename}`})
103
+ httpFiles.push({ url: imageUrl, filename: `cover/${filename}` })
104
104
  }
105
105
 
106
106
  const processChapter = (index: number): Promise<void> => {
@@ -115,8 +115,8 @@ export class NativeBookExporter {
115
115
 
116
116
  const shrinker = new ShrinkFidus(
117
117
  doc as any,
118
- {db: doc.images || {}},
119
- {db: doc.bibliography || {}},
118
+ { db: doc.images || {} },
119
+ { db: doc.bibliography || {} },
120
120
  true
121
121
  )
122
122
 
@@ -160,8 +160,8 @@ export class NativeBookExporter {
160
160
 
161
161
  return processChapter(0).then(() => {
162
162
  textFiles.push(
163
- {filename: "book.json", contents: JSON.stringify(bookData)},
164
- {filename: "filetype-version", contents: FIDUSBOOK_VERSION}
163
+ { filename: "book.json", contents: JSON.stringify(bookData) },
164
+ { filename: "filetype-version", contents: FIDUSBOOK_VERSION }
165
165
  )
166
166
 
167
167
  const zipper = new ZipFileCreator(
@@ -2,28 +2,28 @@
2
2
  * ODT book exporter.
3
3
  */
4
4
 
5
- import type {Schema} from "prosemirror-model"
6
- import type {CSL, User} from "@fiduswriter/document"
5
+ import type { Schema } from "prosemirror-model"
6
+ import type { CSL, User } from "@fiduswriter/document"
7
7
  import {
8
8
  fixTables,
9
9
  removeHidden
10
10
  } from "@fiduswriter/document/exporter/tools/doc_content"
11
- import {createSlug} from "@fiduswriter/document/exporter/tools/file"
12
- import {XmlZip} from "@fiduswriter/document/exporter/tools/xml_zip"
13
- import {addAlert} from "fwtoolkit"
11
+ import { createSlug } from "@fiduswriter/document/exporter/tools/file"
12
+ import { XmlZip } from "@fiduswriter/document/exporter/tools/xml_zip"
13
+ import { addAlert, gettext } from "fwtoolkit"
14
14
 
15
- import {ODTExporterCitations} from "@fiduswriter/document/exporter/odt/citations"
16
- import {ODTExporterImages} from "@fiduswriter/document/exporter/odt/images"
17
- import {ODTExporterFootnotes} from "@fiduswriter/document/exporter/odt/footnotes"
18
- import {ODTExporterMath} from "@fiduswriter/document/exporter/odt/math"
19
- import {ODTExporterMetadata} from "@fiduswriter/document/exporter/odt/metadata"
20
- import {ODTExporterRichtext} from "@fiduswriter/document/exporter/odt/richtext"
21
- import {ODTExporterStyles} from "@fiduswriter/document/exporter/odt/styles"
22
- import {ODTExporterTracks} from "@fiduswriter/document/exporter/odt/track"
15
+ import { ODTExporterCitations } from "@fiduswriter/document/exporter/odt/citations"
16
+ import { ODTExporterImages } from "@fiduswriter/document/exporter/odt/images"
17
+ import { ODTExporterFootnotes } from "@fiduswriter/document/exporter/odt/footnotes"
18
+ import { ODTExporterMath } from "@fiduswriter/document/exporter/odt/math"
19
+ import { ODTExporterMetadata } from "@fiduswriter/document/exporter/odt/metadata"
20
+ import { ODTExporterRichtext } from "@fiduswriter/document/exporter/odt/richtext"
21
+ import { ODTExporterStyles } from "@fiduswriter/document/exporter/odt/styles"
22
+ import { ODTExporterTracks } from "@fiduswriter/document/exporter/odt/track"
23
23
 
24
- import type {Book, DocumentListEntry} from "../../types.js"
25
- import {getMissingChapterData} from "../tools.js"
26
- import {ODTBookExporterRender} from "./render.js"
24
+ import type { Book, DocumentListEntry } from "../../types.js"
25
+ import { getMissingChapterData } from "../tools.js"
26
+ import { ODTBookExporterRender } from "./render.js"
27
27
 
28
28
  export class ODTBookExporter {
29
29
  schema: Schema
@@ -66,12 +66,9 @@ export class ODTBookExporter {
66
66
  )
67
67
  return false
68
68
  }
69
- return getMissingChapterData(
70
- this.book,
71
- this.docList,
72
- this.schema,
73
- {rawContent: true}
74
- ).then(() => this.export())
69
+ return getMissingChapterData(this.book, this.docList, this.schema, {
70
+ rawContent: true
71
+ }).then(() => this.export())
75
72
  }
76
73
 
77
74
  export(): Promise<Blob> {
@@ -94,7 +91,9 @@ export class ODTBookExporter {
94
91
  .then(() => render.init())
95
92
  .then(() => metadata.init())
96
93
  .then(() => math.init())
97
- .then(() => this.exportChapters(xml as any, render, styles, math, tracks))
94
+ .then(() =>
95
+ this.exportChapters(xml as any, render, styles, math, tracks)
96
+ )
98
97
  .then(() => xml.prepareBlob())
99
98
  .then(blob => this.download(blob))
100
99
  }
@@ -120,7 +119,7 @@ export class ODTBookExporter {
120
119
  docContent as any,
121
120
  doc.settings,
122
121
  styles,
123
- {db: doc.bibliography || {}},
122
+ { db: doc.bibliography || {} },
124
123
  this.csl
125
124
  )
126
125
  const footnotes = new ODTExporterFootnotes(
@@ -129,8 +128,8 @@ export class ODTBookExporter {
129
128
  xml,
130
129
  citations,
131
130
  styles,
132
- {db: doc.bibliography || {}},
133
- {db: doc.images || {}},
131
+ { db: doc.bibliography || {} },
132
+ { db: doc.images || {} },
134
133
  this.csl
135
134
  )
136
135
 
@@ -186,7 +185,7 @@ export class ODTBookExporter {
186
185
 
187
186
  getBaseMetadata(): Record<string, unknown> {
188
187
  const authors = this.book.metadata.author?.length
189
- ? [{institution: this.book.metadata.author}]
188
+ ? [{ institution: this.book.metadata.author }]
190
189
  : []
191
190
  const keywords = this.book.metadata.keywords?.length
192
191
  ? this.book.metadata.keywords
@@ -1,4 +1,4 @@
1
- import {ODTExporterRender} from "@fiduswriter/document/exporter/odt/render"
1
+ import { ODTExporterRender } from "@fiduswriter/document/exporter/odt/render"
2
2
 
3
3
  export class ODTBookExporterRender extends ODTExporterRender {
4
4
  styles: any
@@ -59,7 +59,8 @@ export class ODTBookExporterRender extends ODTExporterRender {
59
59
  }
60
60
 
61
61
  render(...args: any[]): void {
62
- const [docContent, pmBib, settings, richtext, citations, chapterIndex] = args
62
+ const [docContent, pmBib, settings, richtext, citations, chapterIndex] =
63
+ args
63
64
  this.text = this.bodyTemplate.cloneNode(true)
64
65
  const bodyBookmark = (this.text as any).query("text:bookmark", {
65
66
  "text:name": "body"
@@ -90,19 +91,19 @@ export class ODTBookExporterRender extends ODTExporterRender {
90
91
  series_position
91
92
  }: Record<string, unknown>): void {
92
93
  const tags = [
93
- {title: "book.title", content: title},
94
- {title: "book.subtitle", content: subtitle},
95
- {title: "book.version", content: version},
96
- {title: "book.publisher", content: publisher},
97
- {title: "book.copyright", content: copyright},
98
- {title: "book.author", content: author},
99
- {title: "book.keywords", content: keywords},
100
- {title: "book.language", content: language},
101
- {title: "book.description", content: description},
102
- {title: "book.isbn", content: isbn},
103
- {title: "book.publication_date", content: publication_date},
104
- {title: "book.series_title", content: series_title},
105
- {title: "book.series_position", content: series_position}
94
+ { title: "book.title", content: title },
95
+ { title: "book.subtitle", content: subtitle },
96
+ { title: "book.version", content: version },
97
+ { title: "book.publisher", content: publisher },
98
+ { title: "book.copyright", content: copyright },
99
+ { title: "book.author", content: author },
100
+ { title: "book.keywords", content: keywords },
101
+ { title: "book.language", content: language },
102
+ { title: "book.description", content: description },
103
+ { title: "book.isbn", content: isbn },
104
+ { title: "book.publication_date", content: publication_date },
105
+ { title: "book.series_title", content: series_title },
106
+ { title: "book.series_position", content: series_position }
106
107
  ]
107
108
  const usedTags: any[] = []
108
109
  const ambles = [this.preamble, this.postamble]
@@ -116,7 +117,7 @@ export class ODTBookExporterRender extends ODTExporterRender {
116
117
  tags.forEach(tag => {
117
118
  const tagString = tag.title
118
119
  if (text.includes(`{${tagString}}`)) {
119
- usedTags.push(Object.assign({block}, tag))
120
+ usedTags.push(Object.assign({ block }, tag))
120
121
  }
121
122
  })
122
123
  })