@fiduswriter/books-document 0.1.6 → 0.1.8
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.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 +6 -6
- package/dist/exporter/html/index.d.ts.map +1 -1
- package/dist/exporter/html/index.js +4 -4
- package/dist/exporter/html/index.js.map +1 -1
- package/dist/exporter/latex/index.d.ts +2 -2
- package/dist/exporter/latex/index.d.ts.map +1 -1
- package/dist/exporter/latex/index.js +1 -1
- 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 +10 -2
- package/src/exporter/bits/index.ts +3 -3
- package/src/exporter/docx/index.ts +26 -22
- package/src/exporter/docx/render.ts +51 -29
- package/src/exporter/epub/index.ts +25 -16
- package/src/exporter/html/index.ts +28 -16
- package/src/exporter/latex/index.ts +12 -11
- package/src/exporter/native/index.ts +5 -4
- package/src/exporter/odt/index.ts +23 -19
- package/src/exporter/odt/render.ts +54 -31
- package/src/exporter/print/index.ts +3 -1
- package/src/exporter/tools.ts +5 -4
- package/src/importer/native/index.ts +6 -6
|
@@ -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,18 @@
|
|
|
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"
|
|
2
7
|
|
|
3
8
|
export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
4
|
-
preamble:
|
|
5
|
-
bodyTemplate:
|
|
6
|
-
postamble:
|
|
7
|
-
fileXML:
|
|
8
|
-
bodyParts:
|
|
9
|
+
preamble: XMLElement | null
|
|
10
|
+
bodyTemplate: XMLElement | null
|
|
11
|
+
postamble: XMLElement | null
|
|
12
|
+
fileXML: XMLElement | null
|
|
13
|
+
bodyParts: XMLElement[]
|
|
9
14
|
|
|
10
|
-
constructor(xml:
|
|
15
|
+
constructor(xml: XmlZip) {
|
|
11
16
|
super(xml)
|
|
12
17
|
|
|
13
18
|
this.preamble = null
|
|
@@ -19,14 +24,16 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
|
19
24
|
|
|
20
25
|
init(): Promise<void> {
|
|
21
26
|
return super.init().then(() => {
|
|
22
|
-
this.fileXML = this.text
|
|
23
|
-
const text = this.fileXML.query("w:body")
|
|
27
|
+
this.fileXML = this.text as XMLElement
|
|
28
|
+
const text = this.fileXML.query("w:body") as XMLElement
|
|
24
29
|
this.preamble = text.cloneNode(false)
|
|
25
30
|
this.bodyTemplate = text.cloneNode(false)
|
|
26
31
|
this.postamble = text.cloneNode(false)
|
|
27
|
-
let currentSection = this.bodyTemplate
|
|
28
|
-
const textChildren = Array.from(text.children)
|
|
29
|
-
|
|
32
|
+
let currentSection: XMLElement | null = this.bodyTemplate
|
|
33
|
+
const textChildren = Array.from(text.children).filter(
|
|
34
|
+
(node): node is XMLElement => node instanceof XMLElement
|
|
35
|
+
)
|
|
36
|
+
textChildren.forEach(node => {
|
|
30
37
|
const bookmarkStart = node.query("w:bookmarkStart")
|
|
31
38
|
if (bookmarkStart) {
|
|
32
39
|
const bookmarkName = String(
|
|
@@ -40,16 +47,23 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
|
40
47
|
currentSection = this.postamble
|
|
41
48
|
}
|
|
42
49
|
}
|
|
43
|
-
currentSection
|
|
50
|
+
currentSection!.appendChild(node)
|
|
44
51
|
})
|
|
45
52
|
return Promise.resolve()
|
|
46
53
|
})
|
|
47
54
|
}
|
|
48
55
|
|
|
49
|
-
render(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
render(
|
|
57
|
+
docContent: FidusNode,
|
|
58
|
+
pmBib: unknown,
|
|
59
|
+
settings: DocSettings,
|
|
60
|
+
richtext: DOCXExporterRichtext,
|
|
61
|
+
citations: DOCXExporterCitations,
|
|
62
|
+
chapterIndex = 0
|
|
63
|
+
): void {
|
|
64
|
+
this.text = this.bodyTemplate!.cloneNode(true)
|
|
65
|
+
const textEl = this.text as XMLElement
|
|
66
|
+
const bodyBookmark = textEl.query("w:bookmarkStart", {
|
|
53
67
|
"w:name": "body"
|
|
54
68
|
})
|
|
55
69
|
if (bodyBookmark) {
|
|
@@ -89,11 +103,17 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
|
89
103
|
{title: "book.series_title", content: series_title},
|
|
90
104
|
{title: "book.series_position", content: series_position}
|
|
91
105
|
]
|
|
92
|
-
const usedTags:
|
|
93
|
-
|
|
106
|
+
const usedTags: Array<{
|
|
107
|
+
title: string
|
|
108
|
+
content?: unknown
|
|
109
|
+
block: XMLElement
|
|
110
|
+
}> = []
|
|
111
|
+
const ambles = [this.preamble, this.postamble].filter(
|
|
112
|
+
(amble): amble is XMLElement => amble !== null
|
|
113
|
+
)
|
|
94
114
|
ambles.forEach(amble => {
|
|
95
115
|
const blocks = amble.queryAll(["w:p", "w:sectPr"])
|
|
96
|
-
blocks.forEach(
|
|
116
|
+
blocks.forEach(block => {
|
|
97
117
|
const text = block.textContent
|
|
98
118
|
tags.forEach(tag => {
|
|
99
119
|
const tagString = tag.title
|
|
@@ -107,13 +127,15 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
|
107
127
|
}
|
|
108
128
|
|
|
109
129
|
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
|
-
|
|
130
|
+
const text = this.fileXML!.query("w:body") as XMLElement
|
|
131
|
+
Array.from(this.preamble!.children)
|
|
132
|
+
.filter((node): node is XMLElement => node instanceof XMLElement)
|
|
133
|
+
.forEach(node => text.appendChild(node))
|
|
134
|
+
this.bodyParts.forEach((bodyPart, index) => {
|
|
135
|
+
const children = bodyPart.children
|
|
136
|
+
.slice()
|
|
137
|
+
.filter((node): node is XMLElement => node instanceof XMLElement)
|
|
138
|
+
children.forEach(node => {
|
|
117
139
|
text.appendChild(node)
|
|
118
140
|
})
|
|
119
141
|
if (index < this.bodyParts.length - 1) {
|
|
@@ -135,8 +157,8 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
|
135
157
|
)
|
|
136
158
|
}
|
|
137
159
|
})
|
|
138
|
-
Array.from(this.postamble
|
|
139
|
-
|
|
140
|
-
|
|
160
|
+
Array.from(this.postamble!.children)
|
|
161
|
+
.filter((node): node is XMLElement => node instanceof XMLElement)
|
|
162
|
+
.forEach(node => text.appendChild(node))
|
|
141
163
|
}
|
|
142
164
|
}
|
|
@@ -12,7 +12,8 @@ import {ZipFileCreator} from "fwtoolkit/file/zip"
|
|
|
12
12
|
import {gettext, get, staticUrl} from "fwtoolkit"
|
|
13
13
|
import pretty from "pretty"
|
|
14
14
|
|
|
15
|
-
import type {Book, BookStyles, CSL, DocumentListEntry, User} from "../../types.js"
|
|
15
|
+
import type {Book, BookCoverImage, BookStyles, CSL, DocumentListEntry, User} from "../../types.js"
|
|
16
|
+
import type {FidusNode} from "@fiduswriter/document"
|
|
16
17
|
import {getMissingChapterData} from "../tools.js"
|
|
17
18
|
import {
|
|
18
19
|
containerTemplate,
|
|
@@ -179,7 +180,7 @@ export class EpubBookExporter {
|
|
|
179
180
|
contents: pretty(
|
|
180
181
|
epubBookCoverTemplate({
|
|
181
182
|
book: this.book,
|
|
182
|
-
coverImage: coverImage as
|
|
183
|
+
coverImage: coverImage as BookCoverImage & {image: string},
|
|
183
184
|
shortLang: this.book.settings.language.split("-")[0]
|
|
184
185
|
})
|
|
185
186
|
)
|
|
@@ -209,7 +210,7 @@ export class EpubBookExporter {
|
|
|
209
210
|
return false
|
|
210
211
|
}
|
|
211
212
|
|
|
212
|
-
const docContent = removeHidden(doc.content
|
|
213
|
+
const docContent = removeHidden(doc.content) as FidusNode
|
|
213
214
|
|
|
214
215
|
const converter = new HTMLExporterConvert(
|
|
215
216
|
doc.title,
|
|
@@ -326,19 +327,19 @@ export class EpubBookExporter {
|
|
|
326
327
|
10
|
|
327
328
|
),
|
|
328
329
|
modified: getTimestamp(new Date(this.updated * 1000)),
|
|
329
|
-
styleSheets: this.styleSheets as
|
|
330
|
+
styleSheets: this.styleSheets as Array<{filename: string}>,
|
|
330
331
|
math: this.math,
|
|
331
332
|
images: this.images.map(image => ({
|
|
332
333
|
...image,
|
|
333
|
-
mimeType: getImageMimeType(image.filename)
|
|
334
|
-
}))
|
|
334
|
+
mimeType: getImageMimeType(image.filename) || undefined
|
|
335
|
+
})),
|
|
335
336
|
fontFiles: this.fontFiles.map(font => ({
|
|
336
337
|
...font,
|
|
337
|
-
mimeType: getFontMimeType(font.filename)
|
|
338
|
-
}))
|
|
339
|
-
chapters: this.chapters
|
|
340
|
-
user: this.user
|
|
341
|
-
}
|
|
338
|
+
mimeType: getFontMimeType(font.filename) || undefined
|
|
339
|
+
})),
|
|
340
|
+
chapters: this.chapters,
|
|
341
|
+
user: {name: this.user.name || ""}
|
|
342
|
+
})
|
|
342
343
|
)
|
|
343
344
|
},
|
|
344
345
|
{
|
|
@@ -349,8 +350,12 @@ export class EpubBookExporter {
|
|
|
349
350
|
title: this.book.title,
|
|
350
351
|
idType: "fidus",
|
|
351
352
|
id: this.book.id,
|
|
352
|
-
toc: toc as
|
|
353
|
-
|
|
353
|
+
toc: toc as Array<{
|
|
354
|
+
link: string
|
|
355
|
+
title: string
|
|
356
|
+
children?: Array<{link: string; title: string}>
|
|
357
|
+
}>
|
|
358
|
+
})
|
|
354
359
|
)
|
|
355
360
|
},
|
|
356
361
|
{
|
|
@@ -358,9 +363,13 @@ export class EpubBookExporter {
|
|
|
358
363
|
contents: pretty(
|
|
359
364
|
navTemplate({
|
|
360
365
|
shortLang: this.book.settings.language.split("-")[0],
|
|
361
|
-
toc: toc as
|
|
362
|
-
|
|
363
|
-
|
|
366
|
+
toc: toc as Array<{
|
|
367
|
+
link: string
|
|
368
|
+
title: string
|
|
369
|
+
children?: Array<{link: string; title: string}>
|
|
370
|
+
}>,
|
|
371
|
+
styleSheets: this.styleSheets as Array<{filename: string}>
|
|
372
|
+
})
|
|
364
373
|
)
|
|
365
374
|
}
|
|
366
375
|
])
|
|
@@ -61,7 +61,7 @@ export class HTMLBookExporter {
|
|
|
61
61
|
book: Book
|
|
62
62
|
user: User
|
|
63
63
|
docList: DocumentListEntry[]
|
|
64
|
-
updated:
|
|
64
|
+
updated: number
|
|
65
65
|
multiDoc: boolean
|
|
66
66
|
relativeUrls: boolean
|
|
67
67
|
chapters: ChapterInfo[]
|
|
@@ -70,10 +70,10 @@ export class HTMLBookExporter {
|
|
|
70
70
|
httpFiles: HttpFile[]
|
|
71
71
|
math: boolean
|
|
72
72
|
bibCSS: string
|
|
73
|
-
chapterTemplate: (
|
|
74
|
-
indexTemplate: (
|
|
75
|
-
singleFileHTMLBookTemplate: (
|
|
76
|
-
singleFileHTMLBookCSSTemplate: (
|
|
73
|
+
chapterTemplate: (args: Record<string, unknown>) => string
|
|
74
|
+
indexTemplate: (args: Record<string, unknown>) => string
|
|
75
|
+
singleFileHTMLBookTemplate: (args: Record<string, unknown>) => string
|
|
76
|
+
singleFileHTMLBookCSSTemplate: (args: Record<string, unknown>) => string
|
|
77
77
|
styleSheets: StyleSheet[]
|
|
78
78
|
progressCallback?: ProgressCallback
|
|
79
79
|
|
|
@@ -84,7 +84,7 @@ export class HTMLBookExporter {
|
|
|
84
84
|
book: Book,
|
|
85
85
|
user: User,
|
|
86
86
|
docList: DocumentListEntry[],
|
|
87
|
-
updated:
|
|
87
|
+
updated: number,
|
|
88
88
|
multiDoc = true,
|
|
89
89
|
{relativeUrls = true} = {}
|
|
90
90
|
) {
|
|
@@ -103,12 +103,12 @@ export class HTMLBookExporter {
|
|
|
103
103
|
this.httpFiles = []
|
|
104
104
|
this.math = false
|
|
105
105
|
this.bibCSS = ""
|
|
106
|
-
this.chapterTemplate = multiDoc
|
|
106
|
+
this.chapterTemplate = (multiDoc
|
|
107
107
|
? htmlBookExportTemplate
|
|
108
|
-
:
|
|
109
|
-
this.indexTemplate = multiDoc
|
|
108
|
+
: singleFileHTMLBookChapterTemplate) as unknown as (args: Record<string, unknown>) => string
|
|
109
|
+
this.indexTemplate = (multiDoc
|
|
110
110
|
? htmlBookIndexTemplate
|
|
111
|
-
: htmlBookIndexBodyTemplate
|
|
111
|
+
: htmlBookIndexBodyTemplate) as unknown as (args: Record<string, unknown>) => string
|
|
112
112
|
this.singleFileHTMLBookTemplate = singleFileHTMLBookTemplate
|
|
113
113
|
this.singleFileHTMLBookCSSTemplate = singleFileHTMLBookCSSTemplate
|
|
114
114
|
this.styleSheets = [{url: staticUrl("css/book.css")}]
|
|
@@ -197,19 +197,31 @@ export class HTMLBookExporter {
|
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
const documentHTMLExporter = new HTMLExporter(
|
|
200
|
-
doc
|
|
201
|
-
bibDB
|
|
202
|
-
imageDB
|
|
200
|
+
doc,
|
|
201
|
+
bibDB,
|
|
202
|
+
imageDB,
|
|
203
203
|
this.csl,
|
|
204
204
|
this.updated,
|
|
205
205
|
[],
|
|
206
206
|
options,
|
|
207
|
-
htmlBookChapterTemplate as
|
|
207
|
+
htmlBookChapterTemplate as unknown as typeof HTMLExporter.prototype.htmlExportTemplate
|
|
208
208
|
)
|
|
209
209
|
|
|
210
210
|
await documentHTMLExporter.process()
|
|
211
211
|
const {metaData, converter, textFiles, httpFiles} =
|
|
212
|
-
documentHTMLExporter.getProcessedFiles() as
|
|
212
|
+
documentHTMLExporter.getProcessedFiles() as {
|
|
213
|
+
metaData: Record<string, unknown>
|
|
214
|
+
converter: {
|
|
215
|
+
fnCounter: number
|
|
216
|
+
affCounter: number
|
|
217
|
+
categoryCounter: Record<string, number>
|
|
218
|
+
features: {math: boolean}
|
|
219
|
+
citations: {bibCSS: string}
|
|
220
|
+
metaData: {toc: Array<Record<string, unknown>>}
|
|
221
|
+
}
|
|
222
|
+
textFiles: TextFile[]
|
|
223
|
+
httpFiles: HttpFile[]
|
|
224
|
+
}
|
|
213
225
|
|
|
214
226
|
const contents = textFiles.find(
|
|
215
227
|
(textFile: TextFile) => textFile.filename === "document.html"
|
|
@@ -431,7 +443,7 @@ export class HTMLBookExporter {
|
|
|
431
443
|
|
|
432
444
|
async createZip(): Promise<Blob | void> {
|
|
433
445
|
const zipper = new ZipFileCreator(
|
|
434
|
-
this.textFiles.concat(this.styleSheets as
|
|
446
|
+
this.textFiles.concat(this.styleSheets as TextFile[]),
|
|
435
447
|
this.httpFiles,
|
|
436
448
|
this.includeZips,
|
|
437
449
|
"application/zip",
|
|
@@ -13,6 +13,7 @@ import {ZipFileCreator} from "fwtoolkit/file/zip"
|
|
|
13
13
|
import {gettext} from "fwtoolkit"
|
|
14
14
|
|
|
15
15
|
import type {Book, DocumentListEntry} from "../../types.js"
|
|
16
|
+
import type {BibDB, ImageDB} from "@fiduswriter/document"
|
|
16
17
|
import {getMissingChapterData} from "../tools.js"
|
|
17
18
|
import {bookTexTemplate} from "./templates.js"
|
|
18
19
|
|
|
@@ -31,7 +32,7 @@ export class LatexBookExporter {
|
|
|
31
32
|
book: Book
|
|
32
33
|
user: User
|
|
33
34
|
docList: DocumentListEntry[]
|
|
34
|
-
updated:
|
|
35
|
+
updated: number
|
|
35
36
|
textFiles: TextFile[]
|
|
36
37
|
httpFiles: HttpFile[]
|
|
37
38
|
zipFileName: string
|
|
@@ -42,7 +43,7 @@ export class LatexBookExporter {
|
|
|
42
43
|
book: Book,
|
|
43
44
|
user: User,
|
|
44
45
|
docList: DocumentListEntry[],
|
|
45
|
-
updated:
|
|
46
|
+
updated: number
|
|
46
47
|
) {
|
|
47
48
|
this.schema = schema
|
|
48
49
|
this.book = book
|
|
@@ -81,12 +82,12 @@ export class LatexBookExporter {
|
|
|
81
82
|
return
|
|
82
83
|
}
|
|
83
84
|
const converter = new LatexExporterConvert(
|
|
84
|
-
this
|
|
85
|
+
this,
|
|
85
86
|
{db: doc.images || {}},
|
|
86
87
|
{db: doc.bibliography || {}},
|
|
87
88
|
doc.settings
|
|
88
89
|
)
|
|
89
|
-
const chapterContent = removeHidden(doc.content
|
|
90
|
+
const chapterContent = removeHidden(doc.content)
|
|
90
91
|
const convertedDoc = converter.init(chapterContent)
|
|
91
92
|
this.textFiles.push({
|
|
92
93
|
filename: `chapter-${index + 1}.tex`,
|
|
@@ -96,7 +97,7 @@ export class LatexBookExporter {
|
|
|
96
97
|
...new Set(bibIds.concat(Object.keys(convertedDoc.usedBibDB)))
|
|
97
98
|
]
|
|
98
99
|
imageIds = [...new Set(imageIds.concat(convertedDoc.imageIds))]
|
|
99
|
-
Object.assign(features, converter.features
|
|
100
|
+
Object.assign(features, converter.features)
|
|
100
101
|
Object.keys(convertedDoc.usedBibDB).forEach(
|
|
101
102
|
bibId =>
|
|
102
103
|
(combinedBibliography[bibId] = doc.bibliography?.[bibId])
|
|
@@ -110,12 +111,12 @@ export class LatexBookExporter {
|
|
|
110
111
|
})
|
|
111
112
|
if (bibIds.length > 0) {
|
|
112
113
|
const bibExport = new BibLatexExporter(
|
|
113
|
-
combinedBibliography as
|
|
114
|
+
combinedBibliography as unknown as ConstructorParameters<typeof BibLatexExporter>[0],
|
|
114
115
|
bibIds
|
|
115
116
|
)
|
|
116
117
|
this.textFiles.push({
|
|
117
118
|
filename: "bibliography.bib",
|
|
118
|
-
contents: (bibExport as
|
|
119
|
+
contents: (bibExport as unknown as {output: string}).output
|
|
119
120
|
})
|
|
120
121
|
}
|
|
121
122
|
imageIds.forEach(id => {
|
|
@@ -128,9 +129,9 @@ export class LatexBookExporter {
|
|
|
128
129
|
}
|
|
129
130
|
})
|
|
130
131
|
const bookConverter = new LatexExporterConvert(
|
|
131
|
-
this
|
|
132
|
-
{db: combinedImages as
|
|
133
|
-
{db: combinedBibliography as
|
|
132
|
+
this,
|
|
133
|
+
{db: combinedImages as unknown as ImageDB["db"]},
|
|
134
|
+
{db: combinedBibliography as unknown as BibDB["db"]},
|
|
134
135
|
{language: this.book.settings.language, bibliography_header: {}}
|
|
135
136
|
)
|
|
136
137
|
bookConverter.features = features
|
|
@@ -155,7 +156,7 @@ export class LatexBookExporter {
|
|
|
155
156
|
this.httpFiles,
|
|
156
157
|
undefined,
|
|
157
158
|
undefined,
|
|
158
|
-
this.updated
|
|
159
|
+
new Date(this.updated * 1000)
|
|
159
160
|
)
|
|
160
161
|
|
|
161
162
|
return zipper.init().then(blob => {
|
|
@@ -12,6 +12,7 @@ import {FIDUSBOOK_VERSION} from "../../schema/index.js"
|
|
|
12
12
|
import type {Book, DocumentListEntry, User} from "../../types.js"
|
|
13
13
|
import {getMissingChapterData} from "../tools.js"
|
|
14
14
|
import type {ProgressCallback} from "@fiduswriter/document/exporter/native/shrink"
|
|
15
|
+
import type {FidusNode} from "@fiduswriter/document"
|
|
15
16
|
|
|
16
17
|
interface FileInclude {
|
|
17
18
|
url: string
|
|
@@ -30,7 +31,7 @@ export class NativeBookExporter {
|
|
|
30
31
|
book: Book
|
|
31
32
|
user: User
|
|
32
33
|
documentList: DocumentListEntry[]
|
|
33
|
-
updated:
|
|
34
|
+
updated: number
|
|
34
35
|
|
|
35
36
|
progressCallback?: ProgressCallback
|
|
36
37
|
|
|
@@ -39,7 +40,7 @@ export class NativeBookExporter {
|
|
|
39
40
|
book: Book,
|
|
40
41
|
user: User,
|
|
41
42
|
documentList: DocumentListEntry[],
|
|
42
|
-
updated:
|
|
43
|
+
updated: number,
|
|
43
44
|
progressCallback?: ProgressCallback
|
|
44
45
|
) {
|
|
45
46
|
this.schema = schema
|
|
@@ -134,7 +135,7 @@ export class NativeBookExporter {
|
|
|
134
135
|
)
|
|
135
136
|
|
|
136
137
|
const shrinker = new ShrinkFidus(
|
|
137
|
-
doc as
|
|
138
|
+
doc as unknown as {content: FidusNode; [key: string]: unknown},
|
|
138
139
|
{db: doc.images || {}},
|
|
139
140
|
{db: doc.bibliography || {}},
|
|
140
141
|
this.progressCallback
|
|
@@ -189,7 +190,7 @@ export class NativeBookExporter {
|
|
|
189
190
|
httpFiles,
|
|
190
191
|
[],
|
|
191
192
|
"application/fidusbook+zip",
|
|
192
|
-
this.updated
|
|
193
|
+
new Date(this.updated * 1000)
|
|
193
194
|
)
|
|
194
195
|
return zipper.init().then(blob => this.download(blob))
|
|
195
196
|
})
|