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