@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
|
@@ -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, ExportDoc, FidusNode, ImageDB} from "@fiduswriter/document"
|
|
16
17
|
import {getMissingChapterData} from "../tools.js"
|
|
17
18
|
import {bookTexTemplate} from "./templates.js"
|
|
18
19
|
|
|
@@ -28,10 +29,11 @@ interface HttpFile {
|
|
|
28
29
|
|
|
29
30
|
export class LatexBookExporter {
|
|
30
31
|
schema: Schema
|
|
32
|
+
doc!: ExportDoc
|
|
31
33
|
book: Book
|
|
32
34
|
user: User
|
|
33
35
|
docList: DocumentListEntry[]
|
|
34
|
-
updated:
|
|
36
|
+
updated: number
|
|
35
37
|
textFiles: TextFile[]
|
|
36
38
|
httpFiles: HttpFile[]
|
|
37
39
|
zipFileName: string
|
|
@@ -42,7 +44,7 @@ export class LatexBookExporter {
|
|
|
42
44
|
book: Book,
|
|
43
45
|
user: User,
|
|
44
46
|
docList: DocumentListEntry[],
|
|
45
|
-
updated:
|
|
47
|
+
updated: number
|
|
46
48
|
) {
|
|
47
49
|
this.schema = schema
|
|
48
50
|
this.book = book
|
|
@@ -80,13 +82,14 @@ export class LatexBookExporter {
|
|
|
80
82
|
if (!doc) {
|
|
81
83
|
return
|
|
82
84
|
}
|
|
85
|
+
this.doc = doc
|
|
83
86
|
const converter = new LatexExporterConvert(
|
|
84
|
-
this
|
|
87
|
+
this,
|
|
85
88
|
{db: doc.images || {}},
|
|
86
89
|
{db: doc.bibliography || {}},
|
|
87
90
|
doc.settings
|
|
88
91
|
)
|
|
89
|
-
const chapterContent = removeHidden(doc.content as
|
|
92
|
+
const chapterContent = removeHidden(doc.content) as FidusNode
|
|
90
93
|
const convertedDoc = converter.init(chapterContent)
|
|
91
94
|
this.textFiles.push({
|
|
92
95
|
filename: `chapter-${index + 1}.tex`,
|
|
@@ -96,7 +99,7 @@ export class LatexBookExporter {
|
|
|
96
99
|
...new Set(bibIds.concat(Object.keys(convertedDoc.usedBibDB)))
|
|
97
100
|
]
|
|
98
101
|
imageIds = [...new Set(imageIds.concat(convertedDoc.imageIds))]
|
|
99
|
-
Object.assign(features, converter.features
|
|
102
|
+
Object.assign(features, converter.features)
|
|
100
103
|
Object.keys(convertedDoc.usedBibDB).forEach(
|
|
101
104
|
bibId =>
|
|
102
105
|
(combinedBibliography[bibId] = doc.bibliography?.[bibId])
|
|
@@ -110,12 +113,12 @@ export class LatexBookExporter {
|
|
|
110
113
|
})
|
|
111
114
|
if (bibIds.length > 0) {
|
|
112
115
|
const bibExport = new BibLatexExporter(
|
|
113
|
-
combinedBibliography as
|
|
116
|
+
combinedBibliography as unknown as ConstructorParameters<typeof BibLatexExporter>[0],
|
|
114
117
|
bibIds
|
|
115
118
|
)
|
|
116
119
|
this.textFiles.push({
|
|
117
120
|
filename: "bibliography.bib",
|
|
118
|
-
contents: (bibExport as
|
|
121
|
+
contents: (bibExport as unknown as {output: string}).output
|
|
119
122
|
})
|
|
120
123
|
}
|
|
121
124
|
imageIds.forEach(id => {
|
|
@@ -128,10 +131,13 @@ export class LatexBookExporter {
|
|
|
128
131
|
}
|
|
129
132
|
})
|
|
130
133
|
const bookConverter = new LatexExporterConvert(
|
|
131
|
-
this
|
|
132
|
-
{db: combinedImages as
|
|
133
|
-
{db: combinedBibliography as
|
|
134
|
-
{
|
|
134
|
+
this,
|
|
135
|
+
{db: combinedImages as unknown as ImageDB["db"]},
|
|
136
|
+
{db: combinedBibliography as unknown as BibDB["db"]},
|
|
137
|
+
{
|
|
138
|
+
language: this.book.settings.language,
|
|
139
|
+
bibliography_header: {} as FidusNode
|
|
140
|
+
}
|
|
135
141
|
)
|
|
136
142
|
bookConverter.features = features
|
|
137
143
|
const preamble = bookConverter.assemblePreamble()
|
|
@@ -155,7 +161,7 @@ export class LatexBookExporter {
|
|
|
155
161
|
this.httpFiles,
|
|
156
162
|
undefined,
|
|
157
163
|
undefined,
|
|
158
|
-
this.updated
|
|
164
|
+
new Date(this.updated * 1000)
|
|
159
165
|
)
|
|
160
166
|
|
|
161
167
|
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
|
})
|
|
@@ -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,
|
|
@@ -33,7 +33,7 @@ export class ODTBookExporter {
|
|
|
33
33
|
user: User
|
|
34
34
|
docList: DocumentListEntry[]
|
|
35
35
|
templateUrl: string
|
|
36
|
-
updated:
|
|
36
|
+
updated: number
|
|
37
37
|
textFiles: Array<Record<string, unknown>>
|
|
38
38
|
httpFiles: Array<Record<string, unknown>>
|
|
39
39
|
mimeType: string
|
|
@@ -45,7 +45,7 @@ export class ODTBookExporter {
|
|
|
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
|
|
@@ -83,14 +83,15 @@ export class ODTBookExporter {
|
|
|
83
83
|
this.progressCallback?.(gettext("Preparing ODT book..."), 10)
|
|
84
84
|
this.book.chapters.sort((a, b) => (a.number > b.number ? 1 : -1))
|
|
85
85
|
const xml = new XmlZip(this.templateUrl, this.mimeType)
|
|
86
|
-
const styles = new ODTExporterStyles(xml
|
|
87
|
-
const math = new ODTExporterMath(xml
|
|
88
|
-
const tracks = new ODTExporterTracks(xml
|
|
89
|
-
const render = new ODTBookExporterRender(xml
|
|
86
|
+
const styles = new ODTExporterStyles(xml)
|
|
87
|
+
const math = new ODTExporterMath(xml)
|
|
88
|
+
const tracks = new ODTExporterTracks(xml)
|
|
89
|
+
const render = new ODTBookExporterRender(xml, styles)
|
|
90
90
|
const metadata = new ODTExporterMetadata(
|
|
91
|
-
xml
|
|
91
|
+
xml,
|
|
92
92
|
styles,
|
|
93
|
-
this.getBaseMetadata()
|
|
93
|
+
this.getBaseMetadata(),
|
|
94
|
+
this.csl
|
|
94
95
|
)
|
|
95
96
|
|
|
96
97
|
return xml
|
|
@@ -100,7 +101,7 @@ export class ODTBookExporter {
|
|
|
100
101
|
.then(() => render.init())
|
|
101
102
|
.then(() => metadata.init())
|
|
102
103
|
.then(() => math.init())
|
|
103
|
-
.then(() => this.exportChapters(xml
|
|
104
|
+
.then(() => this.exportChapters(xml, render, styles, math, tracks))
|
|
104
105
|
.then(() => {
|
|
105
106
|
this.progressCallback?.(gettext("Finalizing ODT book..."), 90)
|
|
106
107
|
return xml.prepareBlob()
|
|
@@ -115,11 +116,11 @@ export class ODTBookExporter {
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
exportChapters(
|
|
118
|
-
xml:
|
|
119
|
+
xml: XmlZip,
|
|
119
120
|
render: ODTBookExporterRender,
|
|
120
|
-
styles:
|
|
121
|
-
math:
|
|
122
|
-
tracks:
|
|
121
|
+
styles: ODTExporterStyles,
|
|
122
|
+
math: ODTExporterMath,
|
|
123
|
+
tracks: ODTExporterTracks
|
|
123
124
|
): Promise<void> {
|
|
124
125
|
return this.book.chapters
|
|
125
126
|
.map((chapter, chapterIndex) => {
|
|
@@ -129,10 +130,12 @@ export class ODTBookExporter {
|
|
|
129
130
|
return Promise.resolve()
|
|
130
131
|
}
|
|
131
132
|
const docContent = fixTables(
|
|
132
|
-
removeHidden(
|
|
133
|
-
|
|
133
|
+
removeHidden(
|
|
134
|
+
doc.rawContent as unknown as FidusNode
|
|
135
|
+
) as FidusNode
|
|
136
|
+
)
|
|
134
137
|
const citations = new ODTExporterCitations(
|
|
135
|
-
docContent
|
|
138
|
+
docContent,
|
|
136
139
|
doc.settings,
|
|
137
140
|
styles,
|
|
138
141
|
{db: doc.bibliography || {}},
|
|
@@ -169,7 +172,7 @@ export class ODTBookExporter {
|
|
|
169
172
|
.then(() => {
|
|
170
173
|
const pmBib = footnotes.pmBib || citations.pmBib
|
|
171
174
|
render.render(
|
|
172
|
-
docContent
|
|
175
|
+
docContent,
|
|
173
176
|
pmBib,
|
|
174
177
|
doc.settings,
|
|
175
178
|
richtext,
|
|
@@ -199,7 +202,7 @@ export class ODTBookExporter {
|
|
|
199
202
|
.then(() => render.assemble())
|
|
200
203
|
}
|
|
201
204
|
|
|
202
|
-
getBaseMetadata():
|
|
205
|
+
getBaseMetadata(): ExportMetadata {
|
|
203
206
|
const authors = this.book.metadata.author?.length
|
|
204
207
|
? [{institution: this.book.metadata.author}]
|
|
205
208
|
: []
|
|
@@ -210,6 +213,7 @@ export class ODTBookExporter {
|
|
|
210
213
|
: []
|
|
211
214
|
return {
|
|
212
215
|
authors,
|
|
216
|
+
contributors: [],
|
|
213
217
|
keywords,
|
|
214
218
|
title: this.book.title,
|
|
215
219
|
language: this.book.settings.language
|
|
@@ -1,14 +1,26 @@
|
|
|
1
|
+
import type {DocSettings, FidusNode} from "@fiduswriter/document"
|
|
2
|
+
import {XMLElement} from "@fiduswriter/document/exporter/tools/xml"
|
|
3
|
+
import type {XmlZip} from "@fiduswriter/document/exporter/tools/xml_zip"
|
|
4
|
+
import {ODTExporterCitations} from "@fiduswriter/document/exporter/odt/citations"
|
|
1
5
|
import {ODTExporterRender} from "@fiduswriter/document/exporter/odt/render"
|
|
6
|
+
import {ODTExporterRichtext} from "@fiduswriter/document/exporter/odt/richtext"
|
|
7
|
+
import type {ODTExporterStyles} from "@fiduswriter/document/exporter/odt/styles"
|
|
8
|
+
|
|
9
|
+
interface Tag {
|
|
10
|
+
title: string
|
|
11
|
+
content?: unknown[]
|
|
12
|
+
block: XMLElement
|
|
13
|
+
}
|
|
2
14
|
|
|
3
15
|
export class ODTBookExporterRender extends ODTExporterRender {
|
|
4
|
-
styles:
|
|
5
|
-
preamble:
|
|
6
|
-
bodyTemplate:
|
|
7
|
-
postamble:
|
|
8
|
-
bodyParts:
|
|
9
|
-
fileXml:
|
|
16
|
+
styles: ODTExporterStyles
|
|
17
|
+
preamble: XMLElement | null
|
|
18
|
+
bodyTemplate: XMLElement | null
|
|
19
|
+
postamble: XMLElement | null
|
|
20
|
+
bodyParts: XMLElement[]
|
|
21
|
+
fileXml: XMLElement | null
|
|
10
22
|
|
|
11
|
-
constructor(xml:
|
|
23
|
+
constructor(xml: XmlZip, styles: ODTExporterStyles) {
|
|
12
24
|
super(xml)
|
|
13
25
|
|
|
14
26
|
this.styles = styles
|
|
@@ -22,16 +34,18 @@ export class ODTBookExporterRender extends ODTExporterRender {
|
|
|
22
34
|
}
|
|
23
35
|
|
|
24
36
|
init(): Promise<void> {
|
|
25
|
-
return this.xml.getXml(this.filePath).then(
|
|
37
|
+
return this.xml.getXml(this.filePath).then(xml => {
|
|
26
38
|
this.fileXml = xml
|
|
27
|
-
const text = xml.query("office:text")
|
|
39
|
+
const text = xml.query("office:text") as XMLElement
|
|
28
40
|
this.preamble = text.cloneNode(false)
|
|
29
41
|
this.bodyTemplate = text.cloneNode(false)
|
|
30
42
|
this.postamble = text.cloneNode(false)
|
|
31
|
-
let currentSection:
|
|
32
|
-
const textChildren = Array.from(text.children)
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
let currentSection: XMLElement | null = null
|
|
44
|
+
const textChildren = Array.from(text.children).filter(
|
|
45
|
+
(node): node is XMLElement => node instanceof XMLElement
|
|
46
|
+
)
|
|
47
|
+
textChildren.forEach(node => {
|
|
48
|
+
if (node.tagName && ["text:p", "text:h"].includes(node.tagName)) {
|
|
35
49
|
const bookmark = node.query("text:bookmark")
|
|
36
50
|
if (bookmark) {
|
|
37
51
|
const sectionName = String(
|
|
@@ -58,10 +72,17 @@ export class ODTBookExporterRender extends ODTExporterRender {
|
|
|
58
72
|
})
|
|
59
73
|
}
|
|
60
74
|
|
|
61
|
-
render(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
75
|
+
render(
|
|
76
|
+
docContent: FidusNode,
|
|
77
|
+
pmBib: unknown,
|
|
78
|
+
settings: DocSettings,
|
|
79
|
+
richtext: ODTExporterRichtext,
|
|
80
|
+
citations: ODTExporterCitations,
|
|
81
|
+
chapterIndex = 0
|
|
82
|
+
): void {
|
|
83
|
+
this.text = this.bodyTemplate!.cloneNode(true)
|
|
84
|
+
const textEl = this.text as XMLElement
|
|
85
|
+
const bodyBookmark = textEl.query("text:bookmark", {
|
|
65
86
|
"text:name": "body"
|
|
66
87
|
})
|
|
67
88
|
if (bodyBookmark) {
|
|
@@ -70,7 +91,13 @@ export class ODTBookExporterRender extends ODTExporterRender {
|
|
|
70
91
|
`chapter ${chapterIndex + 1}`
|
|
71
92
|
)
|
|
72
93
|
}
|
|
73
|
-
super.render(
|
|
94
|
+
super.render(
|
|
95
|
+
docContent,
|
|
96
|
+
pmBib as false | FidusNode,
|
|
97
|
+
settings,
|
|
98
|
+
richtext,
|
|
99
|
+
citations
|
|
100
|
+
)
|
|
74
101
|
this.bodyParts.push(this.text)
|
|
75
102
|
}
|
|
76
103
|
|
|
@@ -104,43 +131,51 @@ export class ODTBookExporterRender extends ODTExporterRender {
|
|
|
104
131
|
{title: "book.series_title", content: series_title},
|
|
105
132
|
{title: "book.series_position", content: series_position}
|
|
106
133
|
]
|
|
107
|
-
const usedTags:
|
|
108
|
-
|
|
134
|
+
const usedTags: Array<{
|
|
135
|
+
title: string
|
|
136
|
+
content?: unknown[]
|
|
137
|
+
block: XMLElement
|
|
138
|
+
}> = []
|
|
139
|
+
const ambles = [this.preamble, this.postamble].filter(
|
|
140
|
+
(amble): amble is XMLElement => amble !== null
|
|
141
|
+
)
|
|
109
142
|
ambles.forEach(amble => {
|
|
110
143
|
const blocks = amble.queryAll(["text:p", "text:h"])
|
|
111
|
-
blocks.forEach(
|
|
112
|
-
if (block.parentElement
|
|
144
|
+
blocks.forEach(block => {
|
|
145
|
+
if (block.parentElement?.tagName === "text:deletion") {
|
|
113
146
|
return
|
|
114
147
|
}
|
|
115
148
|
const text = block.textContent
|
|
116
149
|
tags.forEach(tag => {
|
|
117
150
|
const tagString = tag.title
|
|
118
151
|
if (text.includes(`{${tagString}}`)) {
|
|
119
|
-
usedTags.push(Object.assign({block}, tag))
|
|
152
|
+
usedTags.push(Object.assign({block}, tag) as Tag)
|
|
120
153
|
}
|
|
121
154
|
})
|
|
122
155
|
})
|
|
123
156
|
})
|
|
124
|
-
usedTags.forEach(tag => this.inlineRender(tag))
|
|
157
|
+
usedTags.forEach(tag => this.inlineRender(tag as unknown as Tag))
|
|
125
158
|
}
|
|
126
159
|
|
|
127
160
|
assemble(): void {
|
|
128
161
|
this.styles.addPageBreakStyle()
|
|
129
|
-
const text = this.fileXml
|
|
130
|
-
Array.from(this.preamble
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.bodyParts.forEach((bodyPart
|
|
134
|
-
const children = bodyPart.children
|
|
135
|
-
|
|
162
|
+
const text = this.fileXml!.query("office:text") as XMLElement
|
|
163
|
+
Array.from(this.preamble!.children)
|
|
164
|
+
.filter((node): node is XMLElement => node instanceof XMLElement)
|
|
165
|
+
.forEach(node => text.appendChild(node))
|
|
166
|
+
this.bodyParts.forEach((bodyPart, index) => {
|
|
167
|
+
const children = bodyPart.children
|
|
168
|
+
.slice()
|
|
169
|
+
.filter((node): node is XMLElement => node instanceof XMLElement)
|
|
170
|
+
children.forEach(node => {
|
|
136
171
|
text.appendChild(node)
|
|
137
172
|
})
|
|
138
173
|
if (index < this.bodyParts.length - 1) {
|
|
139
174
|
text.appendXML('<text:p text:style-name="PageBreak"/>')
|
|
140
175
|
}
|
|
141
176
|
})
|
|
142
|
-
Array.from(this.postamble
|
|
143
|
-
|
|
144
|
-
|
|
177
|
+
Array.from(this.postamble!.children)
|
|
178
|
+
.filter((node): node is XMLElement => node instanceof XMLElement)
|
|
179
|
+
.forEach(node => text.appendChild(node))
|
|
145
180
|
}
|
|
146
181
|
}
|
|
@@ -54,7 +54,9 @@ export class PrintBookExporter extends HTMLBookExporter {
|
|
|
54
54
|
if (!htmlDoc) {
|
|
55
55
|
return
|
|
56
56
|
}
|
|
57
|
-
const config:
|
|
57
|
+
const config: {title: string; printCallback?: (iframeWin: Window) => void} = {
|
|
58
|
+
title: this.book.title
|
|
59
|
+
}
|
|
58
60
|
|
|
59
61
|
if (navigator.userAgent.includes("Gecko/")) {
|
|
60
62
|
config.printCallback = (iframeWin: Window) => {
|
package/src/exporter/tools.ts
CHANGED
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
* decrypt end-to-end encrypted chapters.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type {Schema} from "prosemirror-model"
|
|
10
|
+
import type {Node, Schema} from "prosemirror-model"
|
|
11
11
|
import {getSettings} from "@fiduswriter/document/schema/convert"
|
|
12
12
|
import {acceptAllNoInsertions} from "@fiduswriter/document/transform"
|
|
13
13
|
import {gettext} from "fwtoolkit"
|
|
14
14
|
import type {ProgressCallback} from "@fiduswriter/document/exporter/tools/progress"
|
|
15
|
+
import type {FidusDoc} from "@fiduswriter/document"
|
|
15
16
|
|
|
16
17
|
import type {
|
|
17
18
|
ChapterLoader,
|
|
@@ -172,13 +173,13 @@ async function decryptE2EEChapters(
|
|
|
172
173
|
// Parse ProseMirror content.
|
|
173
174
|
if (rawContent) {
|
|
174
175
|
doc.rawContent = JSON.parse(
|
|
175
|
-
JSON.stringify(schema.nodeFromJSON(decryptedContent as Record<string, unknown>).toJSON())
|
|
176
|
+
JSON.stringify(schema.nodeFromJSON(decryptedContent as unknown as Record<string, unknown>).toJSON())
|
|
176
177
|
)
|
|
177
178
|
}
|
|
178
179
|
doc.content = acceptAllNoInsertions(
|
|
179
|
-
schema.nodeFromJSON(decryptedContent as Record<string, unknown>)
|
|
180
|
+
schema.nodeFromJSON(decryptedContent as unknown as Record<string, unknown>) as Node
|
|
180
181
|
).toJSON()
|
|
181
|
-
doc.settings = getSettings(doc.content)
|
|
182
|
+
doc.settings = getSettings(doc.content as unknown as FidusDoc)
|
|
182
183
|
|
|
183
184
|
// Decrypt encrypted images.
|
|
184
185
|
const encryptedImageEntries = Object.entries(doc.images || {}).filter(
|
|
@@ -167,7 +167,7 @@ export class NativeBookImporter {
|
|
|
167
167
|
|
|
168
168
|
const bookData = JSON.parse(
|
|
169
169
|
textFiles.find(f => f.filename === "book.json")?.content || "{}"
|
|
170
|
-
) as Record<string,
|
|
170
|
+
) as Record<string, unknown>
|
|
171
171
|
|
|
172
172
|
const sortedChapters = [...(bookData.chapters as Array<{chapter_index: number; number: number; part?: string}>)].sort(
|
|
173
173
|
(a, b) => a.chapter_index - b.chapter_index
|
|
@@ -197,9 +197,9 @@ export class NativeBookImporter {
|
|
|
197
197
|
throw new Error(`Missing chapter data for index ${ci}`)
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
const docJson = JSON.parse(docFile.content) as Record<string,
|
|
201
|
-
const imagesJson = JSON.parse(imagesFile.content) as Record<string,
|
|
202
|
-
const bibJson = JSON.parse(bibFile.content) as Record<string,
|
|
200
|
+
const docJson = JSON.parse(docFile.content) as Record<string, unknown>
|
|
201
|
+
const imagesJson = JSON.parse(imagesFile.content) as Record<string, unknown>
|
|
202
|
+
const bibJson = JSON.parse(bibFile.content) as Record<string, unknown>
|
|
203
203
|
|
|
204
204
|
const chapterPrefix = `chapters/${ci}/images/`
|
|
205
205
|
const chapterOtherFiles = binaryFiles
|
|
@@ -220,7 +220,7 @@ export class NativeBookImporter {
|
|
|
220
220
|
const importer = new NativeImporter(
|
|
221
221
|
docJson,
|
|
222
222
|
bibJson,
|
|
223
|
-
{db: imagesJson},
|
|
223
|
+
{db: imagesJson as unknown as import("@fiduswriter/document").ImageDB["db"]},
|
|
224
224
|
chapterOtherFiles,
|
|
225
225
|
this.user,
|
|
226
226
|
this.nativeBackend,
|
|
@@ -256,7 +256,7 @@ export class NativeBookImporter {
|
|
|
256
256
|
part: chapter.part || ""
|
|
257
257
|
}))
|
|
258
258
|
|
|
259
|
-
const book = await this.bookBackend.createBook(bookData
|
|
259
|
+
const book = await this.bookBackend.createBook(bookData, chapters, false)
|
|
260
260
|
this.bookId = book.id || null
|
|
261
261
|
this.ok = true
|
|
262
262
|
this.statusText = `"${bookData.title}" ${gettext("successfully imported.")}`
|