@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
package/package.json CHANGED
@@ -1,101 +1,111 @@
1
1
  {
2
- "name": "@fiduswriter/books-document",
3
- "version": "0.1.1",
4
- "description": "Fidus Writer book importers and exporters",
5
- "repository": {
6
- "type": "git",
7
- "url": "ssh://git@codeberg.org/fiduswriter/fiduswriter-books-document.git"
8
- },
9
- "license": "AGPL-3.0",
10
- "author": "Johannes Wilm",
11
- "type": "module",
12
- "main": "./dist/index.js",
13
- "types": "./dist/index.d.ts",
14
- "exports": {
15
- ".": {
16
- "types": "./dist/index.d.ts",
17
- "default": "./dist/index.js"
2
+ "name": "@fiduswriter/books-document",
3
+ "version": "0.1.2",
4
+ "description": "Fidus Writer book importers and exporters",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "ssh://git@codeberg.org/fiduswriter/fiduswriter-books-document.git"
18
8
  },
19
- "./schema": {
20
- "types": "./dist/schema/index.d.ts",
21
- "default": "./dist/schema/index.js"
9
+ "license": "AGPL-3.0",
10
+ "author": "Johannes Wilm",
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ },
19
+ "./schema": {
20
+ "types": "./dist/schema/index.d.ts",
21
+ "default": "./dist/schema/index.js"
22
+ },
23
+ "./importer/native": {
24
+ "types": "./dist/importer/native/index.d.ts",
25
+ "default": "./dist/importer/native/index.js"
26
+ },
27
+ "./exporter/native": {
28
+ "types": "./dist/exporter/native/index.d.ts",
29
+ "default": "./dist/exporter/native/index.js"
30
+ },
31
+ "./exporter/html": {
32
+ "types": "./dist/exporter/html/index.d.ts",
33
+ "default": "./dist/exporter/html/index.js"
34
+ },
35
+ "./exporter/epub": {
36
+ "types": "./dist/exporter/epub/index.d.ts",
37
+ "default": "./dist/exporter/epub/index.js"
38
+ },
39
+ "./exporter/latex": {
40
+ "types": "./dist/exporter/latex/index.d.ts",
41
+ "default": "./dist/exporter/latex/index.js"
42
+ },
43
+ "./exporter/docx": {
44
+ "types": "./dist/exporter/docx/index.d.ts",
45
+ "default": "./dist/exporter/docx/index.js"
46
+ },
47
+ "./exporter/odt": {
48
+ "types": "./dist/exporter/odt/index.d.ts",
49
+ "default": "./dist/exporter/odt/index.js"
50
+ },
51
+ "./exporter/print": {
52
+ "types": "./dist/exporter/print/index.d.ts",
53
+ "default": "./dist/exporter/print/index.js"
54
+ },
55
+ "./exporter/bits": {
56
+ "types": "./dist/exporter/bits/index.d.ts",
57
+ "default": "./dist/exporter/bits/index.js"
58
+ },
59
+ "./exporter/tools": {
60
+ "types": "./dist/exporter/tools.d.ts",
61
+ "default": "./dist/exporter/tools.js"
62
+ },
63
+ "./i18n": {
64
+ "types": "./dist/i18n.d.ts",
65
+ "default": "./dist/i18n.js"
66
+ }
22
67
  },
23
- "./importer/native": {
24
- "types": "./dist/importer/native/index.d.ts",
25
- "default": "./dist/importer/native/index.js"
68
+ "directories": {
69
+ "test": "test"
26
70
  },
27
- "./exporter/native": {
28
- "types": "./dist/exporter/native/index.d.ts",
29
- "default": "./dist/exporter/native/index.js"
71
+ "files": [
72
+ "dist/",
73
+ "src/",
74
+ "README.md",
75
+ "LICENSE"
76
+ ],
77
+ "scripts": {
78
+ "build": "tsc",
79
+ "prepare": "npm run build",
80
+ "prepublishOnly": "npm run build",
81
+ "typecheck": "tsc --noEmit",
82
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js",
83
+ "lint": "eslint src test",
84
+ "lint:fix": "eslint src test --fix",
85
+ "format": "prettier --write .",
86
+ "format:check": "prettier --check ."
30
87
  },
31
- "./exporter/html": {
32
- "types": "./dist/exporter/html/index.d.ts",
33
- "default": "./dist/exporter/html/index.js"
88
+ "dependencies": {
89
+ "@fiduswriter/document": "^0.2.0",
90
+ "@vivliostyle/print": "^2.42.0",
91
+ "biblatex-csl-converter": "^3.0.0",
92
+ "downloadjs": "^1.4.7",
93
+ "fast-deep-equal": "^3.1.3",
94
+ "fwtoolkit": "^0.1.3",
95
+ "jszip": "^3.10.1",
96
+ "pretty": "^2.0.0"
34
97
  },
35
- "./exporter/epub": {
36
- "types": "./dist/exporter/epub/index.d.ts",
37
- "default": "./dist/exporter/epub/index.js"
38
- },
39
- "./exporter/latex": {
40
- "types": "./dist/exporter/latex/index.d.ts",
41
- "default": "./dist/exporter/latex/index.js"
42
- },
43
- "./exporter/docx": {
44
- "types": "./dist/exporter/docx/index.d.ts",
45
- "default": "./dist/exporter/docx/index.js"
46
- },
47
- "./exporter/odt": {
48
- "types": "./dist/exporter/odt/index.d.ts",
49
- "default": "./dist/exporter/odt/index.js"
50
- },
51
- "./exporter/print": {
52
- "types": "./dist/exporter/print/index.d.ts",
53
- "default": "./dist/exporter/print/index.js"
54
- },
55
- "./exporter/bits": {
56
- "types": "./dist/exporter/bits/index.d.ts",
57
- "default": "./dist/exporter/bits/index.js"
58
- },
59
- "./exporter/tools": {
60
- "types": "./dist/exporter/tools.d.ts",
61
- "default": "./dist/exporter/tools.js"
62
- },
63
- "./i18n": {
64
- "types": "./dist/i18n.d.ts",
65
- "default": "./dist/i18n.js"
98
+ "devDependencies": {
99
+ "@types/node": "^26.0.1",
100
+ "jest": "^30.4.2",
101
+ "ts-jest": "^29.1.2",
102
+ "ts-jest-resolver": "^2.0.1",
103
+ "typescript": "^6.0.3",
104
+ "@eslint/js": "^10.0.1",
105
+ "eslint": "^10.6.0",
106
+ "globals": "^15.15.0",
107
+ "prettier": "^3.8.5",
108
+ "typescript-eslint": "^8.62.0",
109
+ "prosemirror-model": "^1.25.0"
66
110
  }
67
- },
68
- "directories": {
69
- "test": "test"
70
- },
71
- "files": [
72
- "dist/",
73
- "src/",
74
- "README.md",
75
- "LICENSE"
76
- ],
77
- "scripts": {
78
- "build": "tsc",
79
- "prepare": "npm run build",
80
- "prepublishOnly": "npm run build",
81
- "typecheck": "tsc --noEmit",
82
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js"
83
- },
84
- "dependencies": {
85
- "@fiduswriter/document": "^0.2.0",
86
- "@vivliostyle/print": "^2.42.0",
87
- "biblatex-csl-converter": "^3.0.0",
88
- "downloadjs": "^1.4.7",
89
- "fast-deep-equal": "^3.1.3",
90
- "fwtoolkit": "^0.1.3",
91
- "jszip": "^3.10.1",
92
- "pretty": "^2.0.0"
93
- },
94
- "devDependencies": {
95
- "@types/node": "^26.0.1",
96
- "jest": "^30.4.2",
97
- "ts-jest": "^29.1.2",
98
- "ts-jest-resolver": "^2.0.1",
99
- "typescript": "^6.0.3"
100
- }
101
111
  }
@@ -2,17 +2,17 @@
2
2
  * BITS (Book Interchange Tag Suite) book exporter.
3
3
  */
4
4
 
5
- import type {Schema} from "prosemirror-model"
5
+ import type { Schema } from "prosemirror-model"
6
6
  import pretty from "pretty"
7
- import {JATSExporterConverter} from "@fiduswriter/document/exporter/jats/convert"
8
- import {darManifest} from "@fiduswriter/document/exporter/jats/templates"
9
- import {createSlug} from "@fiduswriter/document/exporter/tools/file"
10
- import {ZipFileCreator} from "@fiduswriter/document/exporter/tools/zip"
11
- import {addAlert} from "fwtoolkit"
7
+ import { JATSExporterConverter } from "@fiduswriter/document/exporter/jats/convert"
8
+ import { darManifest } from "@fiduswriter/document/exporter/jats/templates"
9
+ import { createSlug } from "@fiduswriter/document/exporter/tools/file"
10
+ import { ZipFileCreator } from "@fiduswriter/document/exporter/tools/zip"
11
+ import { addAlert, gettext } from "fwtoolkit"
12
12
 
13
- import type {Book, CSL, DocumentListEntry, User} from "../../types.js"
14
- import {getMissingChapterData} from "../tools.js"
15
- import {bitsTemplate} from "./templates.js"
13
+ import type { Book, CSL, DocumentListEntry, User } from "../../types.js"
14
+ import { getMissingChapterData } from "../tools.js"
15
+ import { bitsTemplate } from "./templates.js"
16
16
 
17
17
  interface TextFile {
18
18
  filename: string
@@ -73,37 +73,39 @@ export class BITSBookExporter {
73
73
  export(): Promise<Blob> {
74
74
  this.book.chapters.sort((a, b) => (a.number > b.number ? 1 : -1))
75
75
 
76
- const imageDict: Record<string, {image: string; title?: string}> = {}
76
+ const imageDict: Record<string, { image: string; title?: string }> = {}
77
77
  return Promise.all(
78
78
  this.book.chapters.map(chapter => {
79
79
  const doc = this.docList.find(d => d.id === chapter.text)
80
80
  if (!doc) {
81
- return Promise.resolve({front: "", body: "", back: ""})
81
+ return Promise.resolve({ front: "", body: "", back: "" })
82
82
  }
83
83
  const converter = new JATSExporterConverter(
84
84
  this.type,
85
85
  doc,
86
86
  this.csl,
87
- {db: doc.images || {}},
88
- {db: doc.bibliography || {}}
87
+ { db: doc.images || {} },
88
+ { db: doc.bibliography || {} }
89
89
  )
90
- return converter.init().then(({front, body, back, imageIds}) => {
91
- imageIds.forEach(
92
- (imageId: string | number) =>
93
- (imageDict[imageId] = doc.images?.[imageId] as {
94
- image: string
95
- title?: string
96
- })
97
- )
98
- return {front, body, back}
99
- })
90
+ return converter
91
+ .init()
92
+ .then(({ front, body, back, imageIds }) => {
93
+ imageIds.forEach(
94
+ (imageId: string | number) =>
95
+ (imageDict[imageId] = doc.images?.[imageId] as {
96
+ image: string
97
+ title?: string
98
+ })
99
+ )
100
+ return { front, body, back }
101
+ })
100
102
  })
101
103
  ).then(chapters => this.createFiles(chapters, imageDict))
102
104
  }
103
105
 
104
106
  createFiles(
105
- chapters: Array<{front: string; body: string; back: string}>,
106
- imageDict: Record<string, {image: string; title?: string}>
107
+ chapters: Array<{ front: string; body: string; back: string }>,
108
+ imageDict: Record<string, { image: string; title?: string }>
107
109
  ): Promise<Blob> {
108
110
  const images = Object.values(imageDict).map(image => ({
109
111
  filename: image.image.split("/").pop()?.split("?")[0] || "",
@@ -116,7 +118,9 @@ export class BITSBookExporter {
116
118
  this.textFiles = [
117
119
  {
118
120
  filename: "manuscript.xml",
119
- contents: pretty(bitsTemplate(this.book, chapters), {ocd: true})
121
+ contents: pretty(bitsTemplate(this.book, chapters), {
122
+ ocd: true
123
+ })
120
124
  },
121
125
  {
122
126
  filename: "manifest.xml",
@@ -126,7 +130,7 @@ export class BITSBookExporter {
126
130
  type: this.type,
127
131
  images
128
132
  }),
129
- {ocd: true}
133
+ { ocd: true }
130
134
  )
131
135
  }
132
136
  ]
@@ -1,13 +1,13 @@
1
- import {escapeText} from "fwtoolkit"
1
+ import { escapeText } from "fwtoolkit"
2
2
 
3
- import type {Book, BitsTemplateParams} from "../../types.js"
3
+ import type { Book, BitsTemplateParams } from "../../types.js"
4
4
 
5
- const bookPartTemplate = ({front, body, back}: BitsTemplateParams) =>
5
+ const bookPartTemplate = ({ front, body, back }: BitsTemplateParams) =>
6
6
  `<book-part book-part-type="chapter" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ali="http://www.niso.org/schemas/ali/1.0/" xmlns:mml="http://www.w3.org/1998/Math/MathML">${front}${body}${back}</book-part>`
7
7
 
8
8
  export const bitsTemplate = (
9
9
  book: Book,
10
- chapters: Array<{front: string; body: string; back: string}>
10
+ chapters: Array<{ front: string; body: string; back: string }>
11
11
  ) => {
12
12
  const updated = new Date((book.updated || 0) * 1000)
13
13
  return `<?xml version="1.0" encoding="UTF-8"?>
@@ -2,31 +2,31 @@
2
2
  * DOCX 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"
14
-
15
- import {DOCXExporterCitations} from "@fiduswriter/document/exporter/docx/citations"
16
- import {DOCXExporterComments} from "@fiduswriter/document/exporter/docx/comments"
17
- import {DOCXExporterFootnotes} from "@fiduswriter/document/exporter/docx/footnotes"
18
- import {DOCXExporterImages} from "@fiduswriter/document/exporter/docx/images"
19
- import {DOCXExporterLists} from "@fiduswriter/document/exporter/docx/lists"
20
- import {DOCXExporterMath} from "@fiduswriter/document/exporter/docx/math"
21
- import {DOCXExporterMetadata} from "@fiduswriter/document/exporter/docx/metadata"
22
- import {DOCXExporterRels} from "@fiduswriter/document/exporter/docx/rels"
23
- import {DOCXExporterRichtext} from "@fiduswriter/document/exporter/docx/richtext"
24
- import {DOCXExporterTables} from "@fiduswriter/document/exporter/docx/tables"
25
- import {moveFootnoteComments} from "@fiduswriter/document/exporter/docx/tools"
26
-
27
- import type {Book, DocumentListEntry} from "../../types.js"
28
- import {getMissingChapterData} from "../tools.js"
29
- import {DOCXBookExporterRender} from "./render.js"
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
+
15
+ import { DOCXExporterCitations } from "@fiduswriter/document/exporter/docx/citations"
16
+ import { DOCXExporterComments } from "@fiduswriter/document/exporter/docx/comments"
17
+ import { DOCXExporterFootnotes } from "@fiduswriter/document/exporter/docx/footnotes"
18
+ import { DOCXExporterImages } from "@fiduswriter/document/exporter/docx/images"
19
+ import { DOCXExporterLists } from "@fiduswriter/document/exporter/docx/lists"
20
+ import { DOCXExporterMath } from "@fiduswriter/document/exporter/docx/math"
21
+ import { DOCXExporterMetadata } from "@fiduswriter/document/exporter/docx/metadata"
22
+ import { DOCXExporterRels } from "@fiduswriter/document/exporter/docx/rels"
23
+ import { DOCXExporterRichtext } from "@fiduswriter/document/exporter/docx/richtext"
24
+ import { DOCXExporterTables } from "@fiduswriter/document/exporter/docx/tables"
25
+ import { moveFootnoteComments } from "@fiduswriter/document/exporter/docx/tools"
26
+
27
+ import type { Book, DocumentListEntry } from "../../types.js"
28
+ import { getMissingChapterData } from "../tools.js"
29
+ import { DOCXBookExporterRender } from "./render.js"
30
30
 
31
31
  export class DOCXBookExporter {
32
32
  schema: Schema
@@ -70,12 +70,9 @@ export class DOCXBookExporter {
70
70
  )
71
71
  return false
72
72
  }
73
- return getMissingChapterData(
74
- this.book,
75
- this.docList,
76
- this.schema,
77
- {rawContent: true}
78
- ).then(() => this.export())
73
+ return getMissingChapterData(this.book, this.docList, this.schema, {
74
+ rawContent: true
75
+ }).then(() => this.export())
79
76
  }
80
77
 
81
78
  export(): Promise<Blob> {
@@ -98,7 +95,9 @@ export class DOCXBookExporter {
98
95
  .then(() => math.init())
99
96
  .then(() => render.init())
100
97
  .then(() => rels.init())
101
- .then(() => this.exportChapters(xml as any, render, rels, math, tables))
98
+ .then(() =>
99
+ this.exportChapters(xml as any, render, rels, math, tables)
100
+ )
102
101
  .then(() => xml.prepareBlob())
103
102
  .then(blob => this.download(blob))
104
103
  }
@@ -125,7 +124,7 @@ export class DOCXBookExporter {
125
124
 
126
125
  const images = new DOCXExporterImages(
127
126
  docContent as any,
128
- {db: doc.images || {}},
127
+ { db: doc.images || {} },
129
128
  xml,
130
129
  rels
131
130
  )
@@ -133,7 +132,7 @@ export class DOCXBookExporter {
133
132
  const citations = new DOCXExporterCitations(
134
133
  docContent,
135
134
  doc.settings,
136
- {db: doc.bibliography || {}},
135
+ { db: doc.bibliography || {} },
137
136
  this.csl,
138
137
  xml
139
138
  )
@@ -142,8 +141,8 @@ export class DOCXBookExporter {
142
141
  doc as any,
143
142
  docContent,
144
143
  doc.settings,
145
- {db: doc.images || {}},
146
- {db: doc.bibliography || {}},
144
+ { db: doc.images || {} },
145
+ { db: doc.bibliography || {} },
147
146
  xml,
148
147
  citations,
149
148
  this.csl,
@@ -214,7 +213,7 @@ export class DOCXBookExporter {
214
213
 
215
214
  getBaseMetadata(): Record<string, unknown> {
216
215
  const authors = this.book.metadata.author?.length
217
- ? [{institution: this.book.metadata.author}]
216
+ ? [{ institution: this.book.metadata.author }]
218
217
  : []
219
218
  const keywords = this.book.metadata.keywords?.length
220
219
  ? this.book.metadata.keywords
@@ -1,4 +1,4 @@
1
- import {DOCXExporterRender} from "@fiduswriter/document/exporter/docx/render"
1
+ import { DOCXExporterRender } from "@fiduswriter/document/exporter/docx/render"
2
2
 
3
3
  export class DOCXBookExporterRender extends DOCXExporterRender {
4
4
  preamble: any
@@ -47,7 +47,8 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
47
47
  }
48
48
 
49
49
  render(...args: any[]): void {
50
- const [docContent, pmBib, settings, richtext, citations, chapterIndex] = args
50
+ const [docContent, pmBib, settings, richtext, citations, chapterIndex] =
51
+ args
51
52
  this.text = this.bodyTemplate.cloneNode(true)
52
53
  const bodyBookmark = (this.text as any).query("w:bookmarkStart", {
53
54
  "w:name": "body"
@@ -75,19 +76,19 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
75
76
  series_position
76
77
  }: Record<string, unknown>): void {
77
78
  const tags = [
78
- {title: "book.title", content: title},
79
- {title: "book.subtitle", content: subtitle},
80
- {title: "book.version", content: version},
81
- {title: "book.publisher", content: publisher},
82
- {title: "book.copyright", content: copyright},
83
- {title: "book.author", content: author},
84
- {title: "book.keywords", content: keywords},
85
- {title: "book.language", content: language},
86
- {title: "book.description", content: description},
87
- {title: "book.isbn", content: isbn},
88
- {title: "book.publication_date", content: publication_date},
89
- {title: "book.series_title", content: series_title},
90
- {title: "book.series_position", content: series_position}
79
+ { title: "book.title", content: title },
80
+ { title: "book.subtitle", content: subtitle },
81
+ { title: "book.version", content: version },
82
+ { title: "book.publisher", content: publisher },
83
+ { title: "book.copyright", content: copyright },
84
+ { title: "book.author", content: author },
85
+ { title: "book.keywords", content: keywords },
86
+ { title: "book.language", content: language },
87
+ { title: "book.description", content: description },
88
+ { title: "book.isbn", content: isbn },
89
+ { title: "book.publication_date", content: publication_date },
90
+ { title: "book.series_title", content: series_title },
91
+ { title: "book.series_position", content: series_position }
91
92
  ]
92
93
  const usedTags: any[] = []
93
94
  const ambles = [this.preamble, this.postamble]
@@ -98,7 +99,7 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
98
99
  tags.forEach(tag => {
99
100
  const tagString = tag.title
100
101
  if (text.includes(`{${tagString}}`)) {
101
- usedTags.push(Object.assign({block}, tag))
102
+ usedTags.push(Object.assign({ block }, tag))
102
103
  }
103
104
  })
104
105
  })
@@ -2,17 +2,23 @@
2
2
  * EPUB book exporter.
3
3
  */
4
4
 
5
- import type {Schema} from "prosemirror-model"
6
- import {HTMLExporterConvert} from "@fiduswriter/document/exporter/html/convert"
7
- import {htmlExportTemplate} from "@fiduswriter/document/exporter/html/templates"
8
- import {removeHidden} from "@fiduswriter/document/exporter/tools/doc_content"
9
- import {createSlug} from "@fiduswriter/document/exporter/tools/file"
10
- import {ZipFileCreator} from "@fiduswriter/document/exporter/tools/zip"
11
- import {addAlert, get, staticUrl} from "fwtoolkit"
5
+ import type { Schema } from "prosemirror-model"
6
+ import { HTMLExporterConvert } from "@fiduswriter/document/exporter/html/convert"
7
+ import { htmlExportTemplate } from "@fiduswriter/document/exporter/html/templates"
8
+ import { removeHidden } from "@fiduswriter/document/exporter/tools/doc_content"
9
+ import { createSlug } from "@fiduswriter/document/exporter/tools/file"
10
+ import { ZipFileCreator } from "@fiduswriter/document/exporter/tools/zip"
11
+ import { addAlert, get, gettext, staticUrl } from "fwtoolkit"
12
12
  import pretty from "pretty"
13
13
 
14
- import type {Book, BookStyles, CSL, DocumentListEntry, User} from "../../types.js"
15
- import {getMissingChapterData} from "../tools.js"
14
+ import type {
15
+ Book,
16
+ BookStyles,
17
+ CSL,
18
+ DocumentListEntry,
19
+ User
20
+ } from "../../types.js"
21
+ import { getMissingChapterData } from "../tools.js"
16
22
  import {
17
23
  containerTemplate,
18
24
  epubBookCopyrightTemplate,
@@ -104,7 +110,7 @@ export class EpubBookExporter {
104
110
  this.images = []
105
111
  this.fontFiles = []
106
112
  this.httpFiles = []
107
- this.styleSheets = [{url: staticUrl("css/book.css")}]
113
+ this.styleSheets = [{ url: staticUrl("css/book.css") }]
108
114
  this.chapters = []
109
115
  this.contentItems = []
110
116
  this.includeZips = []
@@ -142,7 +148,10 @@ export class EpubBookExporter {
142
148
  )
143
149
  })
144
150
 
145
- this.styleSheets.push({contents, filename: `css/${bookStyle.slug}.css`})
151
+ this.styleSheets.push({
152
+ contents,
153
+ filename: `css/${bookStyle.slug}.css`
154
+ })
146
155
  this.fontFiles = this.fontFiles.concat(
147
156
  bookStyle.bookstylefile_set.map(([url, filename]) => ({
148
157
  filename: `css/media/${filename}`,
@@ -162,7 +171,9 @@ export class EpubBookExporter {
162
171
  if (coverImage?.image) {
163
172
  this.images.push({
164
173
  url: coverImage.image.split("?")[0],
165
- filename: coverImage.image.split("/").pop()?.split("?")[0] || "cover",
174
+ filename:
175
+ coverImage.image.split("/").pop()?.split("?")[0] ||
176
+ "cover",
166
177
  coverImage: true
167
178
  })
168
179
 
@@ -201,15 +212,17 @@ export class EpubBookExporter {
201
212
  return false
202
213
  }
203
214
 
204
- const docContent = removeHidden(doc.content as any) as any
215
+ const docContent = removeHidden(
216
+ doc.content as any
217
+ ) as any
205
218
 
206
219
  const converter = new HTMLExporterConvert(
207
220
  doc.title,
208
221
  doc.settings,
209
222
  docContent,
210
223
  htmlExportTemplate,
211
- {db: doc.images || {}},
212
- {db: doc.bibliography || {}},
224
+ { db: doc.images || {} },
225
+ { db: doc.bibliography || {} },
213
226
  this.csl,
214
227
  this.styleSheets,
215
228
  {
@@ -220,7 +233,7 @@ export class EpubBookExporter {
220
233
  idPrefix: `c-${chapter.number}-`
221
234
  }
222
235
  )
223
- const {html, imageIds, metaData, extraStyleSheets} =
236
+ const { html, imageIds, metaData, extraStyleSheets } =
224
237
  await converter.init()
225
238
 
226
239
  if (!html) {
@@ -229,7 +242,10 @@ export class EpubBookExporter {
229
242
 
230
243
  imageIds.forEach((id: string | number) => {
231
244
  const image = doc.images?.[id]
232
- if (image?.image && typeof image.image === "string") {
245
+ if (
246
+ image?.image &&
247
+ typeof image.image === "string"
248
+ ) {
233
249
  this.images.push({
234
250
  filename: `images/${image.image.split("/").pop()}`,
235
251
  url: image.image
@@ -238,8 +254,8 @@ export class EpubBookExporter {
238
254
  })
239
255
 
240
256
  await Promise.all(
241
- extraStyleSheets.map(
242
- async (sheet: StyleSheet) => this.loadStyle(sheet)
257
+ extraStyleSheets.map(async (sheet: StyleSheet) =>
258
+ this.loadStyle(sheet)
243
259
  )
244
260
  )
245
261
 
@@ -286,7 +302,9 @@ export class EpubBookExporter {
286
302
  })
287
303
  }
288
304
  items = items.concat(
289
- (chapter.metaData.toc as Array<Record<string, unknown>>).map(item => ({
305
+ (
306
+ chapter.metaData.toc as Array<Record<string, unknown>>
307
+ ).map(item => ({
290
308
  ...item,
291
309
  docNum: chapter.number,
292
310
  link: `document-${chapter.number}.xhtml#c-${chapter.number}-${item.id}`
@@ -394,13 +412,15 @@ export class EpubBookExporter {
394
412
  ) {
395
413
  return file
396
414
  }
397
- return Object.assign({}, file, {filename: `EPUB/${file.filename}`})
415
+ return Object.assign({}, file, {
416
+ filename: `EPUB/${file.filename}`
417
+ })
398
418
  })
399
419
  this.fontFiles = this.fontFiles.map(file =>
400
- Object.assign({}, file, {filename: `EPUB/${file.filename}`})
420
+ Object.assign({}, file, { filename: `EPUB/${file.filename}` })
401
421
  )
402
422
  this.includeZips = this.includeZips.map(file =>
403
- Object.assign({}, file, {directory: `EPUB/${file.directory}`})
423
+ Object.assign({}, file, { directory: `EPUB/${file.directory}` })
404
424
  )
405
425
  }
406
426