@fiduswriter/books-document 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -10
- package/dist/exporter/bits/index.d.ts +2 -2
- package/dist/exporter/bits/index.d.ts.map +1 -1
- package/dist/exporter/bits/index.js +1 -1
- package/dist/exporter/bits/index.js.map +1 -1
- package/dist/exporter/docx/index.d.ts +9 -5
- package/dist/exporter/docx/index.d.ts.map +1 -1
- package/dist/exporter/docx/index.js +2 -1
- package/dist/exporter/docx/index.js.map +1 -1
- package/dist/exporter/docx/render.d.ts +12 -7
- package/dist/exporter/docx/render.d.ts.map +1 -1
- package/dist/exporter/docx/render.js +18 -11
- package/dist/exporter/docx/render.js.map +1 -1
- package/dist/exporter/epub/index.d.ts +2 -1
- package/dist/exporter/epub/index.d.ts.map +1 -1
- package/dist/exporter/epub/index.js +3 -3
- package/dist/exporter/epub/index.js.map +1 -1
- package/dist/exporter/html/index.d.ts +9 -8
- package/dist/exporter/html/index.d.ts.map +1 -1
- package/dist/exporter/html/index.js +5 -5
- package/dist/exporter/html/index.js.map +1 -1
- package/dist/exporter/latex/index.d.ts +4 -2
- package/dist/exporter/latex/index.d.ts.map +1 -1
- package/dist/exporter/latex/index.js +7 -2
- package/dist/exporter/latex/index.js.map +1 -1
- package/dist/exporter/native/index.d.ts +2 -2
- package/dist/exporter/native/index.d.ts.map +1 -1
- package/dist/exporter/native/index.js +1 -1
- package/dist/exporter/native/index.js.map +1 -1
- package/dist/exporter/odt/index.d.ts +9 -5
- package/dist/exporter/odt/index.d.ts.map +1 -1
- package/dist/exporter/odt/index.js +2 -1
- package/dist/exporter/odt/index.js.map +1 -1
- package/dist/exporter/odt/render.d.ts +14 -8
- package/dist/exporter/odt/render.d.ts.map +1 -1
- package/dist/exporter/odt/render.js +22 -15
- package/dist/exporter/odt/render.js.map +1 -1
- package/dist/exporter/print/index.d.ts.map +1 -1
- package/dist/exporter/print/index.js +3 -1
- package/dist/exporter/print/index.js.map +1 -1
- package/dist/exporter/tools.d.ts.map +1 -1
- package/dist/exporter/tools.js.map +1 -1
- package/dist/importer/native/index.js.map +1 -1
- package/package.json +18 -6
- package/src/exporter/bits/index.ts +3 -3
- package/src/exporter/docx/index.ts +26 -22
- package/src/exporter/docx/render.ts +67 -32
- package/src/exporter/epub/index.ts +28 -18
- package/src/exporter/html/index.ts +23 -19
- package/src/exporter/latex/index.ts +18 -12
- package/src/exporter/native/index.ts +5 -4
- package/src/exporter/odt/index.ts +23 -19
- package/src/exporter/odt/render.ts +69 -34
- package/src/exporter/print/index.ts +3 -1
- package/src/exporter/tools.ts +5 -4
- package/src/importer/native/index.ts +6 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiduswriter/books-document",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Fidus Writer book importers and exporters",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -76,22 +76,23 @@
|
|
|
76
76
|
],
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build": "tsc",
|
|
79
|
-
"prepare": "
|
|
79
|
+
"prepare": "husky",
|
|
80
80
|
"prepublishOnly": "npm run build",
|
|
81
81
|
"typecheck": "tsc --noEmit",
|
|
82
82
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js",
|
|
83
83
|
"lint": "eslint src test",
|
|
84
84
|
"lint:fix": "eslint src test --fix",
|
|
85
85
|
"format": "prettier --write .",
|
|
86
|
-
"format:check": "prettier --check ."
|
|
86
|
+
"format:check": "prettier --check .",
|
|
87
|
+
"install-hooks": "husky"
|
|
87
88
|
},
|
|
88
89
|
"dependencies": {
|
|
89
90
|
"@fiduswriter/document": "^0.2.20",
|
|
90
91
|
"@vivliostyle/print": "^2.42.0",
|
|
91
|
-
"bibliojson": "^4.0.
|
|
92
|
+
"bibliojson": "^4.0.4",
|
|
92
93
|
"downloadjs": "^1.4.7",
|
|
93
94
|
"fast-deep-equal": "^3.1.3",
|
|
94
|
-
"fwtoolkit": "^0.
|
|
95
|
+
"fwtoolkit": "^0.2.0",
|
|
95
96
|
"jszip": "^3.10.1",
|
|
96
97
|
"pretty": "^2.0.0"
|
|
97
98
|
},
|
|
@@ -106,6 +107,17 @@
|
|
|
106
107
|
"globals": "^15.15.0",
|
|
107
108
|
"prettier": "^3.8.5",
|
|
108
109
|
"typescript-eslint": "^8.62.0",
|
|
109
|
-
"prosemirror-model": "^1.25.0"
|
|
110
|
+
"prosemirror-model": "^1.25.0",
|
|
111
|
+
"husky": "^9.1.7",
|
|
112
|
+
"lint-staged": "^17.0.8"
|
|
113
|
+
},
|
|
114
|
+
"lint-staged": {
|
|
115
|
+
"*.{ts,js,mjs,css,md,json,html}": [
|
|
116
|
+
"prettier --write"
|
|
117
|
+
],
|
|
118
|
+
"*.{ts,js,mjs}": [
|
|
119
|
+
"eslint --fix",
|
|
120
|
+
"sh -c 'npm run typecheck'"
|
|
121
|
+
]
|
|
110
122
|
}
|
|
111
123
|
}
|
|
@@ -32,7 +32,7 @@ export class BITSBookExporter {
|
|
|
32
32
|
book: Book
|
|
33
33
|
user: User
|
|
34
34
|
docList: DocumentListEntry[]
|
|
35
|
-
updated:
|
|
35
|
+
updated: number
|
|
36
36
|
type: string
|
|
37
37
|
textFiles: TextFile[]
|
|
38
38
|
httpFiles: HttpFile[]
|
|
@@ -45,7 +45,7 @@ export class BITSBookExporter {
|
|
|
45
45
|
book: Book,
|
|
46
46
|
user: User,
|
|
47
47
|
docList: DocumentListEntry[],
|
|
48
|
-
updated:
|
|
48
|
+
updated: number
|
|
49
49
|
) {
|
|
50
50
|
this.schema = schema
|
|
51
51
|
this.csl = csl
|
|
@@ -156,7 +156,7 @@ export class BITSBookExporter {
|
|
|
156
156
|
this.httpFiles,
|
|
157
157
|
undefined,
|
|
158
158
|
undefined,
|
|
159
|
-
this.updated
|
|
159
|
+
new Date(this.updated * 1000)
|
|
160
160
|
)
|
|
161
161
|
return zipper.init().then(blob => {
|
|
162
162
|
this.progressCallback?.(gettext("BITS book export complete."), 100)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type {Schema} from "prosemirror-model"
|
|
6
|
-
import type {CSL, User} from "@fiduswriter/document"
|
|
6
|
+
import type {CSL, ExportMetadata, FidusNode, User} from "@fiduswriter/document"
|
|
7
7
|
import type {ProgressCallback} from "@fiduswriter/document/exporter/tools/progress"
|
|
8
8
|
import {
|
|
9
9
|
fixTables,
|
|
@@ -36,7 +36,7 @@ export class DOCXBookExporter {
|
|
|
36
36
|
user: User
|
|
37
37
|
docList: DocumentListEntry[]
|
|
38
38
|
templateUrl: string
|
|
39
|
-
updated:
|
|
39
|
+
updated: number
|
|
40
40
|
textFiles: Array<Record<string, unknown>>
|
|
41
41
|
httpFiles: Array<Record<string, unknown>>
|
|
42
42
|
mimeType: string
|
|
@@ -48,7 +48,7 @@ export class DOCXBookExporter {
|
|
|
48
48
|
book: Book,
|
|
49
49
|
user: User,
|
|
50
50
|
docList: DocumentListEntry[],
|
|
51
|
-
updated:
|
|
51
|
+
updated: number
|
|
52
52
|
) {
|
|
53
53
|
this.schema = schema
|
|
54
54
|
this.csl = csl
|
|
@@ -88,13 +88,14 @@ export class DOCXBookExporter {
|
|
|
88
88
|
this.book.chapters.sort((a, b) => (a.number > b.number ? 1 : -1))
|
|
89
89
|
const xml = new XmlZip(this.templateUrl, this.mimeType)
|
|
90
90
|
|
|
91
|
-
const tables = new DOCXExporterTables(xml
|
|
92
|
-
const math = new DOCXExporterMath(xml
|
|
93
|
-
const render = new DOCXBookExporterRender(xml
|
|
94
|
-
const rels = new DOCXExporterRels(xml
|
|
91
|
+
const tables = new DOCXExporterTables(xml)
|
|
92
|
+
const math = new DOCXExporterMath(xml)
|
|
93
|
+
const render = new DOCXBookExporterRender(xml)
|
|
94
|
+
const rels = new DOCXExporterRels(xml, "document")
|
|
95
95
|
const metadata = new DOCXExporterMetadata(
|
|
96
|
-
xml
|
|
97
|
-
this.getBaseMetadata()
|
|
96
|
+
xml,
|
|
97
|
+
this.getBaseMetadata(),
|
|
98
|
+
this.csl
|
|
98
99
|
)
|
|
99
100
|
|
|
100
101
|
return xml
|
|
@@ -104,7 +105,7 @@ export class DOCXBookExporter {
|
|
|
104
105
|
.then(() => math.init())
|
|
105
106
|
.then(() => render.init())
|
|
106
107
|
.then(() => rels.init())
|
|
107
|
-
.then(() => this.exportChapters(xml
|
|
108
|
+
.then(() => this.exportChapters(xml, render, rels, math, tables))
|
|
108
109
|
.then(() => {
|
|
109
110
|
this.progressCallback?.(gettext("Finalizing DOCX book..."), 90)
|
|
110
111
|
return xml.prepareBlob()
|
|
@@ -119,11 +120,11 @@ export class DOCXBookExporter {
|
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
exportChapters(
|
|
122
|
-
xml:
|
|
123
|
+
xml: XmlZip,
|
|
123
124
|
render: DOCXBookExporterRender,
|
|
124
|
-
rels:
|
|
125
|
-
math:
|
|
126
|
-
tables:
|
|
125
|
+
rels: DOCXExporterRels,
|
|
126
|
+
math: DOCXExporterMath,
|
|
127
|
+
tables: DOCXExporterTables
|
|
127
128
|
): Promise<void> {
|
|
128
129
|
return this.book.chapters
|
|
129
130
|
.map((chapter, chapterIndex) => {
|
|
@@ -134,12 +135,14 @@ export class DOCXBookExporter {
|
|
|
134
135
|
}
|
|
135
136
|
const docContent = moveFootnoteComments(
|
|
136
137
|
fixTables(
|
|
137
|
-
removeHidden(
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
removeHidden(
|
|
139
|
+
doc.rawContent as unknown as FidusNode
|
|
140
|
+
) as FidusNode
|
|
141
|
+
)
|
|
142
|
+
)
|
|
140
143
|
|
|
141
144
|
const images = new DOCXExporterImages(
|
|
142
|
-
docContent
|
|
145
|
+
docContent,
|
|
143
146
|
{db: doc.images || {}},
|
|
144
147
|
xml,
|
|
145
148
|
rels
|
|
@@ -154,7 +157,7 @@ export class DOCXBookExporter {
|
|
|
154
157
|
)
|
|
155
158
|
|
|
156
159
|
const footnotes = new DOCXExporterFootnotes(
|
|
157
|
-
doc
|
|
160
|
+
doc,
|
|
158
161
|
docContent,
|
|
159
162
|
doc.settings,
|
|
160
163
|
{db: doc.images || {}},
|
|
@@ -169,7 +172,7 @@ export class DOCXBookExporter {
|
|
|
169
172
|
)
|
|
170
173
|
|
|
171
174
|
const richtext = new DOCXExporterRichtext(
|
|
172
|
-
doc
|
|
175
|
+
doc,
|
|
173
176
|
doc.settings,
|
|
174
177
|
lists,
|
|
175
178
|
footnotes,
|
|
@@ -197,7 +200,7 @@ export class DOCXBookExporter {
|
|
|
197
200
|
.then(() => {
|
|
198
201
|
const pmBib = footnotes.pmBib || citations.pmBib
|
|
199
202
|
render.render(
|
|
200
|
-
docContent
|
|
203
|
+
docContent,
|
|
201
204
|
pmBib,
|
|
202
205
|
doc.settings,
|
|
203
206
|
richtext,
|
|
@@ -227,7 +230,7 @@ export class DOCXBookExporter {
|
|
|
227
230
|
.then(() => render.assemble())
|
|
228
231
|
}
|
|
229
232
|
|
|
230
|
-
getBaseMetadata():
|
|
233
|
+
getBaseMetadata(): ExportMetadata {
|
|
231
234
|
const authors = this.book.metadata.author?.length
|
|
232
235
|
? [{institution: this.book.metadata.author}]
|
|
233
236
|
: []
|
|
@@ -238,6 +241,7 @@ export class DOCXBookExporter {
|
|
|
238
241
|
: []
|
|
239
242
|
return {
|
|
240
243
|
authors,
|
|
244
|
+
contributors: [],
|
|
241
245
|
keywords,
|
|
242
246
|
title: this.book.title,
|
|
243
247
|
language: this.book.settings.language
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
+
import {XMLElement} from "@fiduswriter/document/exporter/tools/xml"
|
|
2
|
+
import type {XmlZip} from "@fiduswriter/document/exporter/tools/xml_zip"
|
|
3
|
+
import {DOCXExporterCitations} from "@fiduswriter/document/exporter/docx/citations"
|
|
1
4
|
import {DOCXExporterRender} from "@fiduswriter/document/exporter/docx/render"
|
|
5
|
+
import {DOCXExporterRichtext} from "@fiduswriter/document/exporter/docx/richtext"
|
|
6
|
+
import type {DocSettings, FidusNode} from "@fiduswriter/document"
|
|
7
|
+
|
|
8
|
+
interface TagData {
|
|
9
|
+
title: string
|
|
10
|
+
content?: string | unknown[]
|
|
11
|
+
block: XMLElement
|
|
12
|
+
dimensions?: {width: number; height: number}
|
|
13
|
+
}
|
|
2
14
|
|
|
3
15
|
export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
4
|
-
preamble:
|
|
5
|
-
bodyTemplate:
|
|
6
|
-
postamble:
|
|
7
|
-
fileXML:
|
|
8
|
-
bodyParts:
|
|
16
|
+
preamble: XMLElement | null
|
|
17
|
+
bodyTemplate: XMLElement | null
|
|
18
|
+
postamble: XMLElement | null
|
|
19
|
+
fileXML: XMLElement | null
|
|
20
|
+
bodyParts: XMLElement[]
|
|
9
21
|
|
|
10
|
-
constructor(xml:
|
|
22
|
+
constructor(xml: XmlZip) {
|
|
11
23
|
super(xml)
|
|
12
24
|
|
|
13
25
|
this.preamble = null
|
|
@@ -19,14 +31,16 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
|
19
31
|
|
|
20
32
|
init(): Promise<void> {
|
|
21
33
|
return super.init().then(() => {
|
|
22
|
-
this.fileXML = this.text
|
|
23
|
-
const text = this.fileXML.query("w:body")
|
|
34
|
+
this.fileXML = this.text as XMLElement
|
|
35
|
+
const text = this.fileXML.query("w:body") as XMLElement
|
|
24
36
|
this.preamble = text.cloneNode(false)
|
|
25
37
|
this.bodyTemplate = text.cloneNode(false)
|
|
26
38
|
this.postamble = text.cloneNode(false)
|
|
27
|
-
let currentSection = this.bodyTemplate
|
|
28
|
-
const textChildren = Array.from(text.children)
|
|
29
|
-
|
|
39
|
+
let currentSection: XMLElement | null = this.bodyTemplate
|
|
40
|
+
const textChildren = Array.from(text.children).filter(
|
|
41
|
+
(node): node is XMLElement => node instanceof XMLElement
|
|
42
|
+
)
|
|
43
|
+
textChildren.forEach(node => {
|
|
30
44
|
const bookmarkStart = node.query("w:bookmarkStart")
|
|
31
45
|
if (bookmarkStart) {
|
|
32
46
|
const bookmarkName = String(
|
|
@@ -40,22 +54,35 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
|
40
54
|
currentSection = this.postamble
|
|
41
55
|
}
|
|
42
56
|
}
|
|
43
|
-
currentSection
|
|
57
|
+
currentSection!.appendChild(node)
|
|
44
58
|
})
|
|
45
59
|
return Promise.resolve()
|
|
46
60
|
})
|
|
47
61
|
}
|
|
48
62
|
|
|
49
|
-
render(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
render(
|
|
64
|
+
docContent: FidusNode,
|
|
65
|
+
pmBib: unknown,
|
|
66
|
+
settings: DocSettings,
|
|
67
|
+
richtext: DOCXExporterRichtext,
|
|
68
|
+
citations: DOCXExporterCitations,
|
|
69
|
+
chapterIndex = 0
|
|
70
|
+
): void {
|
|
71
|
+
this.text = this.bodyTemplate!.cloneNode(true)
|
|
72
|
+
const textEl = this.text as XMLElement
|
|
73
|
+
const bodyBookmark = textEl.query("w:bookmarkStart", {
|
|
53
74
|
"w:name": "body"
|
|
54
75
|
})
|
|
55
76
|
if (bodyBookmark) {
|
|
56
77
|
bodyBookmark.setAttribute("w:name", `chapter ${chapterIndex + 1}`)
|
|
57
78
|
}
|
|
58
|
-
super.render(
|
|
79
|
+
super.render(
|
|
80
|
+
docContent,
|
|
81
|
+
pmBib as false | FidusNode,
|
|
82
|
+
settings,
|
|
83
|
+
richtext,
|
|
84
|
+
citations
|
|
85
|
+
)
|
|
59
86
|
this.bodyParts.push(this.text)
|
|
60
87
|
}
|
|
61
88
|
|
|
@@ -89,31 +116,39 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
|
89
116
|
{title: "book.series_title", content: series_title},
|
|
90
117
|
{title: "book.series_position", content: series_position}
|
|
91
118
|
]
|
|
92
|
-
const usedTags:
|
|
93
|
-
|
|
119
|
+
const usedTags: Array<{
|
|
120
|
+
title: string
|
|
121
|
+
content?: string | unknown[]
|
|
122
|
+
block: XMLElement
|
|
123
|
+
}> = []
|
|
124
|
+
const ambles = [this.preamble, this.postamble].filter(
|
|
125
|
+
(amble): amble is XMLElement => amble !== null
|
|
126
|
+
)
|
|
94
127
|
ambles.forEach(amble => {
|
|
95
128
|
const blocks = amble.queryAll(["w:p", "w:sectPr"])
|
|
96
|
-
blocks.forEach(
|
|
129
|
+
blocks.forEach(block => {
|
|
97
130
|
const text = block.textContent
|
|
98
131
|
tags.forEach(tag => {
|
|
99
132
|
const tagString = tag.title
|
|
100
133
|
if (text.includes(`{${tagString}}`)) {
|
|
101
|
-
usedTags.push(Object.assign({block}, tag))
|
|
134
|
+
usedTags.push(Object.assign({block}, tag) as TagData)
|
|
102
135
|
}
|
|
103
136
|
})
|
|
104
137
|
})
|
|
105
138
|
})
|
|
106
|
-
usedTags.forEach(tag => this.inlineRender(tag))
|
|
139
|
+
usedTags.forEach(tag => this.inlineRender(tag as unknown as TagData))
|
|
107
140
|
}
|
|
108
141
|
|
|
109
142
|
assemble(): void {
|
|
110
|
-
const text = this.fileXML
|
|
111
|
-
Array.from(this.preamble
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.bodyParts.forEach((bodyPart
|
|
115
|
-
const children = bodyPart.children
|
|
116
|
-
|
|
143
|
+
const text = this.fileXML!.query("w:body") as XMLElement
|
|
144
|
+
Array.from(this.preamble!.children)
|
|
145
|
+
.filter((node): node is XMLElement => node instanceof XMLElement)
|
|
146
|
+
.forEach(node => text.appendChild(node))
|
|
147
|
+
this.bodyParts.forEach((bodyPart, index) => {
|
|
148
|
+
const children = bodyPart.children
|
|
149
|
+
.slice()
|
|
150
|
+
.filter((node): node is XMLElement => node instanceof XMLElement)
|
|
151
|
+
children.forEach(node => {
|
|
117
152
|
text.appendChild(node)
|
|
118
153
|
})
|
|
119
154
|
if (index < this.bodyParts.length - 1) {
|
|
@@ -135,8 +170,8 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
|
135
170
|
)
|
|
136
171
|
}
|
|
137
172
|
})
|
|
138
|
-
Array.from(this.postamble
|
|
139
|
-
|
|
140
|
-
|
|
173
|
+
Array.from(this.postamble!.children)
|
|
174
|
+
.filter((node): node is XMLElement => node instanceof XMLElement)
|
|
175
|
+
.forEach(node => text.appendChild(node))
|
|
141
176
|
}
|
|
142
177
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import type {Schema} from "prosemirror-model"
|
|
6
6
|
import {HTMLExporterConvert} from "@fiduswriter/document/exporter/html/convert"
|
|
7
|
+
import type {HTMLExportMetadata} from "@fiduswriter/document/exporter/html/convert"
|
|
7
8
|
import {htmlExportTemplate} from "@fiduswriter/document/exporter/html/templates"
|
|
8
9
|
import type {ProgressCallback} from "@fiduswriter/document/exporter/tools/progress"
|
|
9
10
|
import {removeHidden} from "@fiduswriter/document/exporter/tools/doc_content"
|
|
@@ -12,7 +13,8 @@ import {ZipFileCreator} from "fwtoolkit/file/zip"
|
|
|
12
13
|
import {gettext, get, staticUrl} from "fwtoolkit"
|
|
13
14
|
import pretty from "pretty"
|
|
14
15
|
|
|
15
|
-
import type {Book, BookStyles, CSL, DocumentListEntry, User} from "../../types.js"
|
|
16
|
+
import type {Book, BookCoverImage, BookStyles, CSL, DocumentListEntry, User} from "../../types.js"
|
|
17
|
+
import type {FidusNode} from "@fiduswriter/document"
|
|
16
18
|
import {getMissingChapterData} from "../tools.js"
|
|
17
19
|
import {
|
|
18
20
|
containerTemplate,
|
|
@@ -64,7 +66,7 @@ interface ChapterOutput {
|
|
|
64
66
|
part: string
|
|
65
67
|
title: string
|
|
66
68
|
docNum: number
|
|
67
|
-
metaData:
|
|
69
|
+
metaData: HTMLExportMetadata
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
export class EpubBookExporter {
|
|
@@ -179,7 +181,7 @@ export class EpubBookExporter {
|
|
|
179
181
|
contents: pretty(
|
|
180
182
|
epubBookCoverTemplate({
|
|
181
183
|
book: this.book,
|
|
182
|
-
coverImage: coverImage as
|
|
184
|
+
coverImage: coverImage as BookCoverImage & {image: string},
|
|
183
185
|
shortLang: this.book.settings.language.split("-")[0]
|
|
184
186
|
})
|
|
185
187
|
)
|
|
@@ -209,7 +211,7 @@ export class EpubBookExporter {
|
|
|
209
211
|
return false
|
|
210
212
|
}
|
|
211
213
|
|
|
212
|
-
const docContent = removeHidden(doc.content
|
|
214
|
+
const docContent = removeHidden(doc.content) as FidusNode
|
|
213
215
|
|
|
214
216
|
const converter = new HTMLExporterConvert(
|
|
215
217
|
doc.title,
|
|
@@ -246,7 +248,7 @@ export class EpubBookExporter {
|
|
|
246
248
|
})
|
|
247
249
|
|
|
248
250
|
await Promise.all(
|
|
249
|
-
extraStyleSheets.map(
|
|
251
|
+
(extraStyleSheets as StyleSheet[]).map(
|
|
250
252
|
async (sheet: StyleSheet) => this.loadStyle(sheet)
|
|
251
253
|
)
|
|
252
254
|
)
|
|
@@ -326,19 +328,19 @@ export class EpubBookExporter {
|
|
|
326
328
|
10
|
|
327
329
|
),
|
|
328
330
|
modified: getTimestamp(new Date(this.updated * 1000)),
|
|
329
|
-
styleSheets: this.styleSheets as
|
|
331
|
+
styleSheets: this.styleSheets as Array<{filename: string}>,
|
|
330
332
|
math: this.math,
|
|
331
333
|
images: this.images.map(image => ({
|
|
332
334
|
...image,
|
|
333
|
-
mimeType: getImageMimeType(image.filename)
|
|
334
|
-
}))
|
|
335
|
+
mimeType: getImageMimeType(image.filename) || undefined
|
|
336
|
+
})),
|
|
335
337
|
fontFiles: this.fontFiles.map(font => ({
|
|
336
338
|
...font,
|
|
337
|
-
mimeType: getFontMimeType(font.filename)
|
|
338
|
-
}))
|
|
339
|
-
chapters: this.chapters
|
|
340
|
-
user: this.user
|
|
341
|
-
}
|
|
339
|
+
mimeType: getFontMimeType(font.filename) || undefined
|
|
340
|
+
})),
|
|
341
|
+
chapters: this.chapters,
|
|
342
|
+
user: {name: this.user.name || ""}
|
|
343
|
+
})
|
|
342
344
|
)
|
|
343
345
|
},
|
|
344
346
|
{
|
|
@@ -349,8 +351,12 @@ export class EpubBookExporter {
|
|
|
349
351
|
title: this.book.title,
|
|
350
352
|
idType: "fidus",
|
|
351
353
|
id: this.book.id,
|
|
352
|
-
toc: toc as
|
|
353
|
-
|
|
354
|
+
toc: toc as Array<{
|
|
355
|
+
link: string
|
|
356
|
+
title: string
|
|
357
|
+
children?: Array<{link: string; title: string}>
|
|
358
|
+
}>
|
|
359
|
+
})
|
|
354
360
|
)
|
|
355
361
|
},
|
|
356
362
|
{
|
|
@@ -358,9 +364,13 @@ export class EpubBookExporter {
|
|
|
358
364
|
contents: pretty(
|
|
359
365
|
navTemplate({
|
|
360
366
|
shortLang: this.book.settings.language.split("-")[0],
|
|
361
|
-
toc: toc as
|
|
362
|
-
|
|
363
|
-
|
|
367
|
+
toc: toc as Array<{
|
|
368
|
+
link: string
|
|
369
|
+
title: string
|
|
370
|
+
children?: Array<{link: string; title: string}>
|
|
371
|
+
}>,
|
|
372
|
+
styleSheets: this.styleSheets as Array<{filename: string}>
|
|
373
|
+
})
|
|
364
374
|
)
|
|
365
375
|
}
|
|
366
376
|
])
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import type {Schema} from "prosemirror-model"
|
|
6
6
|
import type {CSL, User} from "@fiduswriter/document"
|
|
7
|
+
import type {HTMLExportMetadata} from "@fiduswriter/document/exporter/html/convert"
|
|
7
8
|
import type {ProgressCallback} from "@fiduswriter/document/exporter/tools/progress"
|
|
8
9
|
import {HTMLExporter} from "@fiduswriter/document/exporter/html/index"
|
|
9
10
|
import {createSlug} from "@fiduswriter/document/exporter/tools/file"
|
|
@@ -33,7 +34,7 @@ interface StyleSheet {
|
|
|
33
34
|
|
|
34
35
|
interface TextFile {
|
|
35
36
|
filename: string
|
|
36
|
-
contents
|
|
37
|
+
contents?: string
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
interface HttpFile {
|
|
@@ -50,7 +51,7 @@ interface ChapterInfo {
|
|
|
50
51
|
number: number
|
|
51
52
|
part: string
|
|
52
53
|
doc: DocumentListEntry
|
|
53
|
-
metaData:
|
|
54
|
+
metaData: HTMLExportMetadata
|
|
54
55
|
toc: Array<Record<string, unknown>>
|
|
55
56
|
}
|
|
56
57
|
|
|
@@ -61,7 +62,7 @@ export class HTMLBookExporter {
|
|
|
61
62
|
book: Book
|
|
62
63
|
user: User
|
|
63
64
|
docList: DocumentListEntry[]
|
|
64
|
-
updated:
|
|
65
|
+
updated: number
|
|
65
66
|
multiDoc: boolean
|
|
66
67
|
relativeUrls: boolean
|
|
67
68
|
chapters: ChapterInfo[]
|
|
@@ -70,10 +71,10 @@ export class HTMLBookExporter {
|
|
|
70
71
|
httpFiles: HttpFile[]
|
|
71
72
|
math: boolean
|
|
72
73
|
bibCSS: string
|
|
73
|
-
chapterTemplate: (
|
|
74
|
-
indexTemplate: (
|
|
75
|
-
singleFileHTMLBookTemplate: (
|
|
76
|
-
singleFileHTMLBookCSSTemplate: (
|
|
74
|
+
chapterTemplate: (args: Record<string, unknown>) => string
|
|
75
|
+
indexTemplate: (args: Record<string, unknown>) => string
|
|
76
|
+
singleFileHTMLBookTemplate: (args: Record<string, unknown>) => string
|
|
77
|
+
singleFileHTMLBookCSSTemplate: (args: Record<string, unknown>) => string
|
|
77
78
|
styleSheets: StyleSheet[]
|
|
78
79
|
progressCallback?: ProgressCallback
|
|
79
80
|
|
|
@@ -84,7 +85,7 @@ export class HTMLBookExporter {
|
|
|
84
85
|
book: Book,
|
|
85
86
|
user: User,
|
|
86
87
|
docList: DocumentListEntry[],
|
|
87
|
-
updated:
|
|
88
|
+
updated: number,
|
|
88
89
|
multiDoc = true,
|
|
89
90
|
{relativeUrls = true} = {}
|
|
90
91
|
) {
|
|
@@ -103,12 +104,12 @@ export class HTMLBookExporter {
|
|
|
103
104
|
this.httpFiles = []
|
|
104
105
|
this.math = false
|
|
105
106
|
this.bibCSS = ""
|
|
106
|
-
this.chapterTemplate = multiDoc
|
|
107
|
+
this.chapterTemplate = (multiDoc
|
|
107
108
|
? htmlBookExportTemplate
|
|
108
|
-
:
|
|
109
|
-
this.indexTemplate = multiDoc
|
|
109
|
+
: singleFileHTMLBookChapterTemplate) as unknown as (args: Record<string, unknown>) => string
|
|
110
|
+
this.indexTemplate = (multiDoc
|
|
110
111
|
? htmlBookIndexTemplate
|
|
111
|
-
: htmlBookIndexBodyTemplate
|
|
112
|
+
: htmlBookIndexBodyTemplate) as unknown as (args: Record<string, unknown>) => string
|
|
112
113
|
this.singleFileHTMLBookTemplate = singleFileHTMLBookTemplate
|
|
113
114
|
this.singleFileHTMLBookCSSTemplate = singleFileHTMLBookCSSTemplate
|
|
114
115
|
this.styleSheets = [{url: staticUrl("css/book.css")}]
|
|
@@ -197,19 +198,19 @@ export class HTMLBookExporter {
|
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
const documentHTMLExporter = new HTMLExporter(
|
|
200
|
-
doc
|
|
201
|
-
bibDB
|
|
202
|
-
imageDB
|
|
201
|
+
doc,
|
|
202
|
+
bibDB,
|
|
203
|
+
imageDB,
|
|
203
204
|
this.csl,
|
|
204
|
-
this.updated,
|
|
205
|
+
new Date(this.updated * 1000),
|
|
205
206
|
[],
|
|
206
207
|
options,
|
|
207
|
-
htmlBookChapterTemplate as
|
|
208
|
+
htmlBookChapterTemplate as unknown as typeof HTMLExporter.prototype.htmlExportTemplate
|
|
208
209
|
)
|
|
209
210
|
|
|
210
211
|
await documentHTMLExporter.process()
|
|
211
212
|
const {metaData, converter, textFiles, httpFiles} =
|
|
212
|
-
documentHTMLExporter.getProcessedFiles()
|
|
213
|
+
documentHTMLExporter.getProcessedFiles()
|
|
213
214
|
|
|
214
215
|
const contents = textFiles.find(
|
|
215
216
|
(textFile: TextFile) => textFile.filename === "document.html"
|
|
@@ -431,7 +432,10 @@ export class HTMLBookExporter {
|
|
|
431
432
|
|
|
432
433
|
async createZip(): Promise<Blob | void> {
|
|
433
434
|
const zipper = new ZipFileCreator(
|
|
434
|
-
this.textFiles.concat(this.styleSheets as
|
|
435
|
+
this.textFiles.concat(this.styleSheets as TextFile[]) as Array<{
|
|
436
|
+
filename: string
|
|
437
|
+
contents: string
|
|
438
|
+
}>,
|
|
435
439
|
this.httpFiles,
|
|
436
440
|
this.includeZips,
|
|
437
441
|
"application/zip",
|