@fiduswriter/books-document 0.1.2 → 0.1.4
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.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,17 +2,17 @@
|
|
|
2
2
|
* BITS (Book Interchange Tag Suite) book exporter.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {Schema} from "prosemirror-model"
|
|
6
6
|
import pretty from "pretty"
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
7
|
+
import {JATSExporterConverter} from "@fiduswriter/document/exporter/jats/convert"
|
|
8
|
+
import {darManifest} from "@fiduswriter/document/exporter/jats/templates"
|
|
9
|
+
import {createSlug} from "@fiduswriter/document/exporter/tools/file"
|
|
10
|
+
import {ZipFileCreator} from "@fiduswriter/document/exporter/tools/zip"
|
|
11
|
+
import {addAlert} from "fwtoolkit"
|
|
12
12
|
|
|
13
|
-
import type {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
13
|
+
import type {Book, CSL, DocumentListEntry, User} from "../../types.js"
|
|
14
|
+
import {getMissingChapterData} from "../tools.js"
|
|
15
|
+
import {bitsTemplate} from "./templates.js"
|
|
16
16
|
|
|
17
17
|
interface TextFile {
|
|
18
18
|
filename: string
|
|
@@ -73,39 +73,37 @@ export class BITSBookExporter {
|
|
|
73
73
|
export(): Promise<Blob> {
|
|
74
74
|
this.book.chapters.sort((a, b) => (a.number > b.number ? 1 : -1))
|
|
75
75
|
|
|
76
|
-
const imageDict: Record<string, {
|
|
76
|
+
const imageDict: Record<string, {image: string; title?: string}> = {}
|
|
77
77
|
return Promise.all(
|
|
78
78
|
this.book.chapters.map(chapter => {
|
|
79
79
|
const doc = this.docList.find(d => d.id === chapter.text)
|
|
80
80
|
if (!doc) {
|
|
81
|
-
return Promise.resolve({
|
|
81
|
+
return Promise.resolve({front: "", body: "", back: ""})
|
|
82
82
|
}
|
|
83
83
|
const converter = new JATSExporterConverter(
|
|
84
84
|
this.type,
|
|
85
85
|
doc,
|
|
86
86
|
this.csl,
|
|
87
|
-
{
|
|
88
|
-
{
|
|
87
|
+
{db: doc.images || {}},
|
|
88
|
+
{db: doc.bibliography || {}}
|
|
89
89
|
)
|
|
90
|
-
return converter
|
|
91
|
-
.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return { front, body, back }
|
|
101
|
-
})
|
|
90
|
+
return converter.init().then(({front, body, back, imageIds}) => {
|
|
91
|
+
imageIds.forEach(
|
|
92
|
+
(imageId: string | number) =>
|
|
93
|
+
(imageDict[imageId] = doc.images?.[imageId] as {
|
|
94
|
+
image: string
|
|
95
|
+
title?: string
|
|
96
|
+
})
|
|
97
|
+
)
|
|
98
|
+
return {front, body, back}
|
|
99
|
+
})
|
|
102
100
|
})
|
|
103
101
|
).then(chapters => this.createFiles(chapters, imageDict))
|
|
104
102
|
}
|
|
105
103
|
|
|
106
104
|
createFiles(
|
|
107
|
-
chapters: Array<{
|
|
108
|
-
imageDict: Record<string, {
|
|
105
|
+
chapters: Array<{front: string; body: string; back: string}>,
|
|
106
|
+
imageDict: Record<string, {image: string; title?: string}>
|
|
109
107
|
): Promise<Blob> {
|
|
110
108
|
const images = Object.values(imageDict).map(image => ({
|
|
111
109
|
filename: image.image.split("/").pop()?.split("?")[0] || "",
|
|
@@ -118,9 +116,7 @@ export class BITSBookExporter {
|
|
|
118
116
|
this.textFiles = [
|
|
119
117
|
{
|
|
120
118
|
filename: "manuscript.xml",
|
|
121
|
-
contents: pretty(bitsTemplate(this.book, chapters), {
|
|
122
|
-
ocd: true
|
|
123
|
-
})
|
|
119
|
+
contents: pretty(bitsTemplate(this.book, chapters), {ocd: true})
|
|
124
120
|
},
|
|
125
121
|
{
|
|
126
122
|
filename: "manifest.xml",
|
|
@@ -130,7 +126,7 @@ export class BITSBookExporter {
|
|
|
130
126
|
type: this.type,
|
|
131
127
|
images
|
|
132
128
|
}),
|
|
133
|
-
{
|
|
129
|
+
{ocd: true}
|
|
134
130
|
)
|
|
135
131
|
}
|
|
136
132
|
]
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {escapeText} from "fwtoolkit"
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {Book, BitsTemplateParams} from "../../types.js"
|
|
4
4
|
|
|
5
|
-
const bookPartTemplate = ({
|
|
5
|
+
const bookPartTemplate = ({front, body, back}: BitsTemplateParams) =>
|
|
6
6
|
`<book-part book-part-type="chapter" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ali="http://www.niso.org/schemas/ali/1.0/" xmlns:mml="http://www.w3.org/1998/Math/MathML">${front}${body}${back}</book-part>`
|
|
7
7
|
|
|
8
8
|
export const bitsTemplate = (
|
|
9
9
|
book: Book,
|
|
10
|
-
chapters: Array<{
|
|
10
|
+
chapters: Array<{front: string; body: string; back: string}>
|
|
11
11
|
) => {
|
|
12
12
|
const updated = new Date((book.updated || 0) * 1000)
|
|
13
13
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -2,31 +2,31 @@
|
|
|
2
2
|
* DOCX book exporter.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type {
|
|
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 {
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
import type {
|
|
28
|
-
import {
|
|
29
|
-
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
|
+
|
|
15
|
+
import {DOCXExporterCitations} from "@fiduswriter/document/exporter/docx/citations"
|
|
16
|
+
import {DOCXExporterComments} from "@fiduswriter/document/exporter/docx/comments"
|
|
17
|
+
import {DOCXExporterFootnotes} from "@fiduswriter/document/exporter/docx/footnotes"
|
|
18
|
+
import {DOCXExporterImages} from "@fiduswriter/document/exporter/docx/images"
|
|
19
|
+
import {DOCXExporterLists} from "@fiduswriter/document/exporter/docx/lists"
|
|
20
|
+
import {DOCXExporterMath} from "@fiduswriter/document/exporter/docx/math"
|
|
21
|
+
import {DOCXExporterMetadata} from "@fiduswriter/document/exporter/docx/metadata"
|
|
22
|
+
import {DOCXExporterRels} from "@fiduswriter/document/exporter/docx/rels"
|
|
23
|
+
import {DOCXExporterRichtext} from "@fiduswriter/document/exporter/docx/richtext"
|
|
24
|
+
import {DOCXExporterTables} from "@fiduswriter/document/exporter/docx/tables"
|
|
25
|
+
import {moveFootnoteComments} from "@fiduswriter/document/exporter/docx/tools"
|
|
26
|
+
|
|
27
|
+
import type {Book, DocumentListEntry} from "../../types.js"
|
|
28
|
+
import {getMissingChapterData} from "../tools.js"
|
|
29
|
+
import {DOCXBookExporterRender} from "./render.js"
|
|
30
30
|
|
|
31
31
|
export class DOCXBookExporter {
|
|
32
32
|
schema: Schema
|
|
@@ -70,9 +70,12 @@ export class DOCXBookExporter {
|
|
|
70
70
|
)
|
|
71
71
|
return false
|
|
72
72
|
}
|
|
73
|
-
return getMissingChapterData(
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
return getMissingChapterData(
|
|
74
|
+
this.book,
|
|
75
|
+
this.docList,
|
|
76
|
+
this.schema,
|
|
77
|
+
{rawContent: true}
|
|
78
|
+
).then(() => this.export())
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
export(): Promise<Blob> {
|
|
@@ -95,9 +98,7 @@ export class DOCXBookExporter {
|
|
|
95
98
|
.then(() => math.init())
|
|
96
99
|
.then(() => render.init())
|
|
97
100
|
.then(() => rels.init())
|
|
98
|
-
.then(() =>
|
|
99
|
-
this.exportChapters(xml as any, render, rels, math, tables)
|
|
100
|
-
)
|
|
101
|
+
.then(() => this.exportChapters(xml as any, render, rels, math, tables))
|
|
101
102
|
.then(() => xml.prepareBlob())
|
|
102
103
|
.then(blob => this.download(blob))
|
|
103
104
|
}
|
|
@@ -124,7 +125,7 @@ export class DOCXBookExporter {
|
|
|
124
125
|
|
|
125
126
|
const images = new DOCXExporterImages(
|
|
126
127
|
docContent as any,
|
|
127
|
-
{
|
|
128
|
+
{db: doc.images || {}},
|
|
128
129
|
xml,
|
|
129
130
|
rels
|
|
130
131
|
)
|
|
@@ -132,7 +133,7 @@ export class DOCXBookExporter {
|
|
|
132
133
|
const citations = new DOCXExporterCitations(
|
|
133
134
|
docContent,
|
|
134
135
|
doc.settings,
|
|
135
|
-
{
|
|
136
|
+
{db: doc.bibliography || {}},
|
|
136
137
|
this.csl,
|
|
137
138
|
xml
|
|
138
139
|
)
|
|
@@ -141,8 +142,8 @@ export class DOCXBookExporter {
|
|
|
141
142
|
doc as any,
|
|
142
143
|
docContent,
|
|
143
144
|
doc.settings,
|
|
144
|
-
{
|
|
145
|
-
{
|
|
145
|
+
{db: doc.images || {}},
|
|
146
|
+
{db: doc.bibliography || {}},
|
|
146
147
|
xml,
|
|
147
148
|
citations,
|
|
148
149
|
this.csl,
|
|
@@ -213,7 +214,7 @@ export class DOCXBookExporter {
|
|
|
213
214
|
|
|
214
215
|
getBaseMetadata(): Record<string, unknown> {
|
|
215
216
|
const authors = this.book.metadata.author?.length
|
|
216
|
-
? [{
|
|
217
|
+
? [{institution: this.book.metadata.author}]
|
|
217
218
|
: []
|
|
218
219
|
const keywords = this.book.metadata.keywords?.length
|
|
219
220
|
? this.book.metadata.keywords
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {DOCXExporterRender} from "@fiduswriter/document/exporter/docx/render"
|
|
2
2
|
|
|
3
3
|
export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
4
4
|
preamble: any
|
|
@@ -47,8 +47,7 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
render(...args: any[]): void {
|
|
50
|
-
const [docContent, pmBib, settings, richtext, citations, chapterIndex] =
|
|
51
|
-
args
|
|
50
|
+
const [docContent, pmBib, settings, richtext, citations, chapterIndex] = args
|
|
52
51
|
this.text = this.bodyTemplate.cloneNode(true)
|
|
53
52
|
const bodyBookmark = (this.text as any).query("w:bookmarkStart", {
|
|
54
53
|
"w:name": "body"
|
|
@@ -76,19 +75,19 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
|
76
75
|
series_position
|
|
77
76
|
}: Record<string, unknown>): void {
|
|
78
77
|
const tags = [
|
|
79
|
-
{
|
|
80
|
-
{
|
|
81
|
-
{
|
|
82
|
-
{
|
|
83
|
-
{
|
|
84
|
-
{
|
|
85
|
-
{
|
|
86
|
-
{
|
|
87
|
-
{
|
|
88
|
-
{
|
|
89
|
-
{
|
|
90
|
-
{
|
|
91
|
-
{
|
|
78
|
+
{title: "book.title", content: title},
|
|
79
|
+
{title: "book.subtitle", content: subtitle},
|
|
80
|
+
{title: "book.version", content: version},
|
|
81
|
+
{title: "book.publisher", content: publisher},
|
|
82
|
+
{title: "book.copyright", content: copyright},
|
|
83
|
+
{title: "book.author", content: author},
|
|
84
|
+
{title: "book.keywords", content: keywords},
|
|
85
|
+
{title: "book.language", content: language},
|
|
86
|
+
{title: "book.description", content: description},
|
|
87
|
+
{title: "book.isbn", content: isbn},
|
|
88
|
+
{title: "book.publication_date", content: publication_date},
|
|
89
|
+
{title: "book.series_title", content: series_title},
|
|
90
|
+
{title: "book.series_position", content: series_position}
|
|
92
91
|
]
|
|
93
92
|
const usedTags: any[] = []
|
|
94
93
|
const ambles = [this.preamble, this.postamble]
|
|
@@ -99,7 +98,7 @@ export class DOCXBookExporterRender extends DOCXExporterRender {
|
|
|
99
98
|
tags.forEach(tag => {
|
|
100
99
|
const tagString = tag.title
|
|
101
100
|
if (text.includes(`{${tagString}}`)) {
|
|
102
|
-
usedTags.push(Object.assign({
|
|
101
|
+
usedTags.push(Object.assign({block}, tag))
|
|
103
102
|
}
|
|
104
103
|
})
|
|
105
104
|
})
|
|
@@ -2,23 +2,17 @@
|
|
|
2
2
|
* EPUB book exporter.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
5
|
+
import type {Schema} from "prosemirror-model"
|
|
6
|
+
import {HTMLExporterConvert} from "@fiduswriter/document/exporter/html/convert"
|
|
7
|
+
import {htmlExportTemplate} from "@fiduswriter/document/exporter/html/templates"
|
|
8
|
+
import {removeHidden} from "@fiduswriter/document/exporter/tools/doc_content"
|
|
9
|
+
import {createSlug} from "@fiduswriter/document/exporter/tools/file"
|
|
10
|
+
import {ZipFileCreator} from "@fiduswriter/document/exporter/tools/zip"
|
|
11
|
+
import {addAlert, get, staticUrl} from "fwtoolkit"
|
|
12
12
|
import pretty from "pretty"
|
|
13
13
|
|
|
14
|
-
import type {
|
|
15
|
-
|
|
16
|
-
BookStyles,
|
|
17
|
-
CSL,
|
|
18
|
-
DocumentListEntry,
|
|
19
|
-
User
|
|
20
|
-
} from "../../types.js"
|
|
21
|
-
import { getMissingChapterData } from "../tools.js"
|
|
14
|
+
import type {Book, BookStyles, CSL, DocumentListEntry, User} from "../../types.js"
|
|
15
|
+
import {getMissingChapterData} from "../tools.js"
|
|
22
16
|
import {
|
|
23
17
|
containerTemplate,
|
|
24
18
|
epubBookCopyrightTemplate,
|
|
@@ -110,7 +104,7 @@ export class EpubBookExporter {
|
|
|
110
104
|
this.images = []
|
|
111
105
|
this.fontFiles = []
|
|
112
106
|
this.httpFiles = []
|
|
113
|
-
this.styleSheets = [{
|
|
107
|
+
this.styleSheets = [{url: staticUrl("css/book.css")}]
|
|
114
108
|
this.chapters = []
|
|
115
109
|
this.contentItems = []
|
|
116
110
|
this.includeZips = []
|
|
@@ -148,10 +142,7 @@ export class EpubBookExporter {
|
|
|
148
142
|
)
|
|
149
143
|
})
|
|
150
144
|
|
|
151
|
-
this.styleSheets.push({
|
|
152
|
-
contents,
|
|
153
|
-
filename: `css/${bookStyle.slug}.css`
|
|
154
|
-
})
|
|
145
|
+
this.styleSheets.push({contents, filename: `css/${bookStyle.slug}.css`})
|
|
155
146
|
this.fontFiles = this.fontFiles.concat(
|
|
156
147
|
bookStyle.bookstylefile_set.map(([url, filename]) => ({
|
|
157
148
|
filename: `css/media/${filename}`,
|
|
@@ -171,9 +162,7 @@ export class EpubBookExporter {
|
|
|
171
162
|
if (coverImage?.image) {
|
|
172
163
|
this.images.push({
|
|
173
164
|
url: coverImage.image.split("?")[0],
|
|
174
|
-
filename:
|
|
175
|
-
coverImage.image.split("/").pop()?.split("?")[0] ||
|
|
176
|
-
"cover",
|
|
165
|
+
filename: coverImage.image.split("/").pop()?.split("?")[0] || "cover",
|
|
177
166
|
coverImage: true
|
|
178
167
|
})
|
|
179
168
|
|
|
@@ -212,17 +201,15 @@ export class EpubBookExporter {
|
|
|
212
201
|
return false
|
|
213
202
|
}
|
|
214
203
|
|
|
215
|
-
const docContent = removeHidden(
|
|
216
|
-
doc.content as any
|
|
217
|
-
) as any
|
|
204
|
+
const docContent = removeHidden(doc.content as any) as any
|
|
218
205
|
|
|
219
206
|
const converter = new HTMLExporterConvert(
|
|
220
207
|
doc.title,
|
|
221
208
|
doc.settings,
|
|
222
209
|
docContent,
|
|
223
210
|
htmlExportTemplate,
|
|
224
|
-
{
|
|
225
|
-
{
|
|
211
|
+
{db: doc.images || {}},
|
|
212
|
+
{db: doc.bibliography || {}},
|
|
226
213
|
this.csl,
|
|
227
214
|
this.styleSheets,
|
|
228
215
|
{
|
|
@@ -233,7 +220,7 @@ export class EpubBookExporter {
|
|
|
233
220
|
idPrefix: `c-${chapter.number}-`
|
|
234
221
|
}
|
|
235
222
|
)
|
|
236
|
-
const {
|
|
223
|
+
const {html, imageIds, metaData, extraStyleSheets} =
|
|
237
224
|
await converter.init()
|
|
238
225
|
|
|
239
226
|
if (!html) {
|
|
@@ -242,10 +229,7 @@ export class EpubBookExporter {
|
|
|
242
229
|
|
|
243
230
|
imageIds.forEach((id: string | number) => {
|
|
244
231
|
const image = doc.images?.[id]
|
|
245
|
-
if (
|
|
246
|
-
image?.image &&
|
|
247
|
-
typeof image.image === "string"
|
|
248
|
-
) {
|
|
232
|
+
if (image?.image && typeof image.image === "string") {
|
|
249
233
|
this.images.push({
|
|
250
234
|
filename: `images/${image.image.split("/").pop()}`,
|
|
251
235
|
url: image.image
|
|
@@ -254,8 +238,8 @@ export class EpubBookExporter {
|
|
|
254
238
|
})
|
|
255
239
|
|
|
256
240
|
await Promise.all(
|
|
257
|
-
extraStyleSheets.map(
|
|
258
|
-
this.loadStyle(sheet)
|
|
241
|
+
extraStyleSheets.map(
|
|
242
|
+
async (sheet: StyleSheet) => this.loadStyle(sheet)
|
|
259
243
|
)
|
|
260
244
|
)
|
|
261
245
|
|
|
@@ -302,9 +286,7 @@ export class EpubBookExporter {
|
|
|
302
286
|
})
|
|
303
287
|
}
|
|
304
288
|
items = items.concat(
|
|
305
|
-
(
|
|
306
|
-
chapter.metaData.toc as Array<Record<string, unknown>>
|
|
307
|
-
).map(item => ({
|
|
289
|
+
(chapter.metaData.toc as Array<Record<string, unknown>>).map(item => ({
|
|
308
290
|
...item,
|
|
309
291
|
docNum: chapter.number,
|
|
310
292
|
link: `document-${chapter.number}.xhtml#c-${chapter.number}-${item.id}`
|
|
@@ -412,15 +394,13 @@ export class EpubBookExporter {
|
|
|
412
394
|
) {
|
|
413
395
|
return file
|
|
414
396
|
}
|
|
415
|
-
return Object.assign({}, file, {
|
|
416
|
-
filename: `EPUB/${file.filename}`
|
|
417
|
-
})
|
|
397
|
+
return Object.assign({}, file, {filename: `EPUB/${file.filename}`})
|
|
418
398
|
})
|
|
419
399
|
this.fontFiles = this.fontFiles.map(file =>
|
|
420
|
-
Object.assign({}, file, {
|
|
400
|
+
Object.assign({}, file, {filename: `EPUB/${file.filename}`})
|
|
421
401
|
)
|
|
422
402
|
this.includeZips = this.includeZips.map(file =>
|
|
423
|
-
Object.assign({}, file, {
|
|
403
|
+
Object.assign({}, file, {directory: `EPUB/${file.directory}`})
|
|
424
404
|
)
|
|
425
405
|
}
|
|
426
406
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import {LANGUAGES} from "@fiduswriter/document/schema/const"
|
|
2
|
+
import {escapeText, localizeDate} from "fwtoolkit"
|
|
3
|
+
import {mathliveOpfIncludes} from "@fiduswriter/document/mathlive/opf_includes"
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
5
|
+
import type {Book} from "../../types.js"
|
|
6
|
+
import {bookTerm} from "../../i18n.js"
|
|
7
7
|
|
|
8
8
|
export const containerTemplate = () => `<?xml version="1.0" encoding="UTF-8"?>
|
|
9
9
|
<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
|
|
@@ -184,11 +184,11 @@ export const epubBookOpfTemplate = ({
|
|
|
184
184
|
idType: string
|
|
185
185
|
date: string
|
|
186
186
|
modified: string
|
|
187
|
-
styleSheets: Array<{
|
|
187
|
+
styleSheets: Array<{filename: string}>
|
|
188
188
|
math: boolean
|
|
189
|
-
images: Array<{
|
|
190
|
-
fontFiles: Array<{
|
|
191
|
-
chapters: Array<{
|
|
189
|
+
images: Array<{coverImage?: boolean; filename: string; mimeType?: string}>
|
|
190
|
+
fontFiles: Array<{filename: string; mimeType?: string}>
|
|
191
|
+
chapters: Array<{number: number}>
|
|
192
192
|
user: Record<string, string>
|
|
193
193
|
}) => `<?xml version="1.0" encoding="UTF-8"?>
|
|
194
194
|
<package xmlns="http://www.idpf.org/2007/opf" version="3.0"
|
|
@@ -296,9 +296,7 @@ export const epubBookOpfTemplate = ({
|
|
|
296
296
|
${book.cover_image ? '<itemref idref="cover" linear="no"/>' : ""}
|
|
297
297
|
<itemref idref="titlepage" linear="yes"/>
|
|
298
298
|
${chapters
|
|
299
|
-
.map(
|
|
300
|
-
chapter => `<itemref idref="t${chapter.number}" linear="yes" />`
|
|
301
|
-
)
|
|
299
|
+
.map(chapter => `<itemref idref="t${chapter.number}" linear="yes" />`)
|
|
302
300
|
.join("")}
|
|
303
301
|
<itemref idref="copyright" linear="yes"/>
|
|
304
302
|
<itemref idref="nav" linear="no"/>
|
|
@@ -318,7 +316,7 @@ export const navTemplate = ({
|
|
|
318
316
|
}: {
|
|
319
317
|
shortLang: string
|
|
320
318
|
toc: TocItem[]
|
|
321
|
-
styleSheets: Array<{
|
|
319
|
+
styleSheets: Array<{filename: string}>
|
|
322
320
|
}) =>
|
|
323
321
|
`<?xml version="1.0" encoding="UTF-8"?>
|
|
324
322
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="${shortLang}"
|
|
@@ -386,7 +384,7 @@ export const ncxTemplate = ({
|
|
|
386
384
|
|
|
387
385
|
const renderNcxItems = (
|
|
388
386
|
items: TocItem[],
|
|
389
|
-
counter: {
|
|
387
|
+
counter: {count: number} = {count: 1}
|
|
390
388
|
): string =>
|
|
391
389
|
items
|
|
392
390
|
.map(
|
|
@@ -55,11 +55,9 @@ export function buildHierarchy(
|
|
|
55
55
|
parentLevel--
|
|
56
56
|
}
|
|
57
57
|
if (parent) {
|
|
58
|
-
;(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
>
|
|
62
|
-
).push(node)
|
|
58
|
+
;(idMap[parent.id as string | number].children as Array<
|
|
59
|
+
Record<string, unknown>
|
|
60
|
+
>).push(node)
|
|
63
61
|
} else {
|
|
64
62
|
root.push(node)
|
|
65
63
|
}
|