@fiduswriter/document 0.1.0-alpha.1
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/LICENSE +661 -0
- package/README.md +16 -0
- package/jest.config.js +23 -0
- package/package.json +59 -0
- package/schema.json +1 -0
- package/scripts/export-schema.js +16 -0
- package/src/bibliography/common.js +92 -0
- package/src/bibliography/csl_bib.js +139 -0
- package/src/citations/citeproc_sys.js +42 -0
- package/src/citations/format.js +194 -0
- package/src/common/blob.js +10 -0
- package/src/common/file.js +25 -0
- package/src/common/index.js +12 -0
- package/src/common/network.js +79 -0
- package/src/common/text.js +44 -0
- package/src/editor/e2ee/encryptor.js +228 -0
- package/src/exporter/docx/citations.js +177 -0
- package/src/exporter/docx/comments.js +165 -0
- package/src/exporter/docx/footnotes.js +240 -0
- package/src/exporter/docx/images.js +101 -0
- package/src/exporter/docx/index.js +185 -0
- package/src/exporter/docx/lists.js +260 -0
- package/src/exporter/docx/math.js +46 -0
- package/src/exporter/docx/metadata.js +289 -0
- package/src/exporter/docx/rels.js +193 -0
- package/src/exporter/docx/render.js +941 -0
- package/src/exporter/docx/richtext.js +1182 -0
- package/src/exporter/docx/tables.js +112 -0
- package/src/exporter/docx/tools.js +50 -0
- package/src/exporter/epub/index.js +142 -0
- package/src/exporter/epub/templates.js +140 -0
- package/src/exporter/epub/tools.js +96 -0
- package/src/exporter/html/citations.js +121 -0
- package/src/exporter/html/convert.js +813 -0
- package/src/exporter/html/index.js +192 -0
- package/src/exporter/html/templates.js +34 -0
- package/src/exporter/html/tools.js +50 -0
- package/src/exporter/jats/bibliography.js +183 -0
- package/src/exporter/jats/citations.js +109 -0
- package/src/exporter/jats/convert.js +871 -0
- package/src/exporter/jats/index.js +92 -0
- package/src/exporter/jats/templates.js +35 -0
- package/src/exporter/jats/text.js +72 -0
- package/src/exporter/latex/convert.js +934 -0
- package/src/exporter/latex/escape_latex.js +21 -0
- package/src/exporter/latex/index.js +74 -0
- package/src/exporter/latex/readme.js +22 -0
- package/src/exporter/native/shrink.js +132 -0
- package/src/exporter/odt/citations.js +101 -0
- package/src/exporter/odt/footnotes.js +147 -0
- package/src/exporter/odt/images.js +115 -0
- package/src/exporter/odt/index.js +156 -0
- package/src/exporter/odt/math.js +57 -0
- package/src/exporter/odt/metadata.js +251 -0
- package/src/exporter/odt/render.js +806 -0
- package/src/exporter/odt/richtext.js +865 -0
- package/src/exporter/odt/styles.js +387 -0
- package/src/exporter/odt/track.js +68 -0
- package/src/exporter/pandoc/citations.js +98 -0
- package/src/exporter/pandoc/convert.js +1017 -0
- package/src/exporter/pandoc/index.js +92 -0
- package/src/exporter/pandoc/readme.js +8 -0
- package/src/exporter/pandoc/tools.js +51 -0
- package/src/exporter/print/index.js +177 -0
- package/src/exporter/tools/doc_content.js +144 -0
- package/src/exporter/tools/file.js +9 -0
- package/src/exporter/tools/json.js +73 -0
- package/src/exporter/tools/svg.js +29 -0
- package/src/exporter/tools/xml.js +531 -0
- package/src/exporter/tools/xml_zip.js +95 -0
- package/src/exporter/tools/zip.js +90 -0
- package/src/exporter/tools/zotero_csl.js +93 -0
- package/src/importer/citations.js +129 -0
- package/src/importer/docx/citations.js +123 -0
- package/src/importer/docx/convert.js +1427 -0
- package/src/importer/docx/helpers.js +9 -0
- package/src/importer/docx/omml2mathml.js +1448 -0
- package/src/importer/docx/parse.js +735 -0
- package/src/importer/native/get_images.js +76 -0
- package/src/importer/native/update.js +29 -0
- package/src/importer/odt/citations.js +87 -0
- package/src/importer/odt/convert.js +1855 -0
- package/src/importer/pandoc/convert.js +884 -0
- package/src/importer/pandoc/helpers.js +84 -0
- package/src/importer/zip_analyzer.js +102 -0
- package/src/index.js +1 -0
- package/src/mathlive/opf_includes.js +24 -0
- package/src/schema/common/annotate.js +76 -0
- package/src/schema/common/base.js +118 -0
- package/src/schema/common/citation.js +62 -0
- package/src/schema/common/equation.js +31 -0
- package/src/schema/common/figure.js +190 -0
- package/src/schema/common/heading.js +43 -0
- package/src/schema/common/index.js +40 -0
- package/src/schema/common/list.js +95 -0
- package/src/schema/common/reference.js +100 -0
- package/src/schema/common/table.js +103 -0
- package/src/schema/common/track.js +190 -0
- package/src/schema/const.js +58 -0
- package/src/schema/convert.js +1272 -0
- package/src/schema/document/content.js +187 -0
- package/src/schema/document/index.js +117 -0
- package/src/schema/document/structure.js +452 -0
- package/src/schema/export.js +21 -0
- package/src/schema/footnotes.js +126 -0
- package/src/schema/footnotes_convert.js +31 -0
- package/src/schema/i18n.js +595 -0
- package/src/schema/index.js +5 -0
- package/src/schema/mini_json.js +61 -0
- package/src/schema/text.js +22 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import download from "downloadjs"
|
|
2
|
+
import pretty from "pretty"
|
|
3
|
+
|
|
4
|
+
import {shortFileTitle} from "../../common/index.js"
|
|
5
|
+
import {createSlug} from "../tools/file.js"
|
|
6
|
+
import {ZipFileCreator} from "../tools/zip.js"
|
|
7
|
+
import {JATSExporterConverter} from "./convert.js"
|
|
8
|
+
import {
|
|
9
|
+
articleTemplate,
|
|
10
|
+
bookPartWrapperTemplate,
|
|
11
|
+
darManifest
|
|
12
|
+
} from "./templates.js"
|
|
13
|
+
/*
|
|
14
|
+
Exporter to JATS
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export class JATSExporter {
|
|
18
|
+
constructor(doc, bibDB, imageDB, csl, updated, type) {
|
|
19
|
+
this.doc = doc
|
|
20
|
+
this.docTitle = shortFileTitle(this.doc.title, this.doc.path)
|
|
21
|
+
this.bibDB = bibDB
|
|
22
|
+
this.imageDB = imageDB
|
|
23
|
+
this.csl = csl
|
|
24
|
+
this.updated = updated
|
|
25
|
+
this.type = type // "article", "book-part-wrapper" (for documents) or "book" (for document collections)
|
|
26
|
+
|
|
27
|
+
this.zipFileName = false
|
|
28
|
+
this.textFiles = []
|
|
29
|
+
this.httpFiles = []
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
init() {
|
|
33
|
+
const fileFormat = this.type === "article" ? "jats" : "bits"
|
|
34
|
+
this.zipFileName = `${createSlug(this.docTitle)}.${fileFormat}.zip`
|
|
35
|
+
this.converter = new JATSExporterConverter(
|
|
36
|
+
this.type,
|
|
37
|
+
this.doc,
|
|
38
|
+
this.csl,
|
|
39
|
+
this.imageDB,
|
|
40
|
+
this.bibDB
|
|
41
|
+
)
|
|
42
|
+
return this.converter.init().then(({front, body, back, imageIds}) => {
|
|
43
|
+
const jats =
|
|
44
|
+
this.type === "article"
|
|
45
|
+
? articleTemplate({front, body, back})
|
|
46
|
+
: bookPartWrapperTemplate({front, body, back})
|
|
47
|
+
this.textFiles.push({
|
|
48
|
+
filename: "manuscript.xml",
|
|
49
|
+
contents: pretty(jats, {ocd: true})
|
|
50
|
+
})
|
|
51
|
+
const images = imageIds.map(id => {
|
|
52
|
+
const imageEntry = this.imageDB.db[id]
|
|
53
|
+
return {
|
|
54
|
+
title: imageEntry.title,
|
|
55
|
+
filename: imageEntry.image.split("/").pop(),
|
|
56
|
+
url: imageEntry.image
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
this.textFiles.push({
|
|
60
|
+
filename: "manifest.xml",
|
|
61
|
+
contents: pretty(
|
|
62
|
+
darManifest({
|
|
63
|
+
title: this.docTitle,
|
|
64
|
+
type: this.type,
|
|
65
|
+
images
|
|
66
|
+
}),
|
|
67
|
+
{ocd: true}
|
|
68
|
+
)
|
|
69
|
+
})
|
|
70
|
+
images.forEach(image => {
|
|
71
|
+
this.httpFiles.push({filename: image.filename, url: image.url})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
return this.createZip()
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
createZip() {
|
|
79
|
+
const zipper = new ZipFileCreator(
|
|
80
|
+
this.textFiles,
|
|
81
|
+
this.httpFiles,
|
|
82
|
+
undefined,
|
|
83
|
+
undefined,
|
|
84
|
+
this.updated
|
|
85
|
+
)
|
|
86
|
+
return zipper.init().then(blob => this.download(blob))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
download(blob) {
|
|
90
|
+
return download(blob, this.zipFileName, "application/zip")
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {escapeText, noSpaceTmp} from "../../common/index.js"
|
|
2
|
+
|
|
3
|
+
export const articleTemplate = ({front, body, back}) =>
|
|
4
|
+
`<?xml version="1.0" encoding="UTF-8"?>
|
|
5
|
+
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.3 20210610//EN" "https://jats.nlm.nih.gov/archiving/1.3/JATS-archivearticle1-3.dtd">
|
|
6
|
+
<article 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}</article>`
|
|
7
|
+
|
|
8
|
+
export const bookPartWrapperTemplate = ({front, body, back}) =>
|
|
9
|
+
`<?xml version="1.0" encoding="UTF-8"?>
|
|
10
|
+
<!DOCTYPE book-part-wrapper PUBLIC "-//NLM//DTD BITS Book Interchange DTD v2.1 20220202//EN" "https://jats.nlm.nih.gov/extensions/bits/2.1/BITS-book2-1.dtd">
|
|
11
|
+
<book-part-wrapper dtd-version="2.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ali="http://www.niso.org/schemas/ali/1.0/">
|
|
12
|
+
<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>
|
|
13
|
+
</book-part-wrapper>`
|
|
14
|
+
|
|
15
|
+
export const darManifest = ({images, title, type}) =>
|
|
16
|
+
noSpaceTmp`<?xml version="1.0" encoding="UTF-8"?>
|
|
17
|
+
<!DOCTYPE manifest PUBLIC "DarManifest 0.1.0" "http://darformat.org/DarManifest-0.1.0.dtd">
|
|
18
|
+
<dar>
|
|
19
|
+
<!-- Generated by Fidus Writer -->
|
|
20
|
+
<documents>
|
|
21
|
+
<document id="manuscript" name="${escapeText(title)}" type="${type}" path="manuscript.xml" />
|
|
22
|
+
</documents>
|
|
23
|
+
<assets>${images
|
|
24
|
+
.map(
|
|
25
|
+
image =>
|
|
26
|
+
`<asset id="${image.filename.split(".")[0]}" mime-type="image/${
|
|
27
|
+
image.filename.split(".")[1] === "png"
|
|
28
|
+
? "png"
|
|
29
|
+
: image.filename.split(".")[1] === "svg"
|
|
30
|
+
? "svg+xml"
|
|
31
|
+
: "jpeg"
|
|
32
|
+
}" name="${image.title}" path="${image.filename}"/>`
|
|
33
|
+
)
|
|
34
|
+
.join("")}</assets>
|
|
35
|
+
</dar>`
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {escapeText} from "../../common/index.js"
|
|
2
|
+
|
|
3
|
+
export function convertTexts(nodeList) {
|
|
4
|
+
return nodeList.map(node => convertText(node)).join("")
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function convertText(node) {
|
|
8
|
+
let start = ""
|
|
9
|
+
let end = ""
|
|
10
|
+
let strong, em, underline, hyperlink, anchor, sup, sub, code
|
|
11
|
+
// Check for hyperlink, bold/strong, italic/em and underline
|
|
12
|
+
if (node.marks) {
|
|
13
|
+
strong = node.marks.find(mark => mark.type === "strong")
|
|
14
|
+
em = node.marks.find(mark => mark.type === "em")
|
|
15
|
+
underline = node.marks.find(mark => mark.type === "underline")
|
|
16
|
+
hyperlink = node.marks.find(mark => mark.type === "link")
|
|
17
|
+
anchor = node.marks.find(mark => mark.type === "anchor")
|
|
18
|
+
sup = node.marks.find(mark => mark.type === "sup")
|
|
19
|
+
sub = node.marks.find(mark => mark.type === "sub")
|
|
20
|
+
code = node.marks.find(mark => mark.type === "code")
|
|
21
|
+
}
|
|
22
|
+
let attrs = anchor ? ` id="${anchor.attrs.id}"` : ""
|
|
23
|
+
if (em) {
|
|
24
|
+
start += `<italic${attrs}>`
|
|
25
|
+
end = "</italic>" + end
|
|
26
|
+
attrs = ""
|
|
27
|
+
}
|
|
28
|
+
if (strong) {
|
|
29
|
+
start += `<bold${attrs}>`
|
|
30
|
+
end = "</bold>" + end
|
|
31
|
+
attrs = ""
|
|
32
|
+
}
|
|
33
|
+
if (underline) {
|
|
34
|
+
start += `<underline${attrs}>`
|
|
35
|
+
end = "</underline>" + end
|
|
36
|
+
attrs = ""
|
|
37
|
+
}
|
|
38
|
+
if (sup) {
|
|
39
|
+
start += `<sup${attrs}>`
|
|
40
|
+
end = "</sup>" + end
|
|
41
|
+
attrs = ""
|
|
42
|
+
}
|
|
43
|
+
if (sub) {
|
|
44
|
+
start += `<sub${attrs}>`
|
|
45
|
+
end = "</sub>" + end
|
|
46
|
+
attrs = ""
|
|
47
|
+
}
|
|
48
|
+
if (code) {
|
|
49
|
+
start += `<monospace${attrs}>`
|
|
50
|
+
end = "</monospace>" + end
|
|
51
|
+
attrs = ""
|
|
52
|
+
}
|
|
53
|
+
if (hyperlink) {
|
|
54
|
+
const href = hyperlink.attrs.href
|
|
55
|
+
if (href[0] === "#") {
|
|
56
|
+
// Internal link
|
|
57
|
+
start += `<xref rid="${href.substring(1)}"${attrs}>`
|
|
58
|
+
end = "</xref>" + end
|
|
59
|
+
} else {
|
|
60
|
+
// External link
|
|
61
|
+
start += `<ext-link xlink:href="${escapeText(href)}" ext-link-type="uri" xlink:title="${escapeText(hyperlink.attrs.title)}"${attrs}>`
|
|
62
|
+
end = "</ext-link>" + end
|
|
63
|
+
}
|
|
64
|
+
attrs = ""
|
|
65
|
+
}
|
|
66
|
+
if (attrs) {
|
|
67
|
+
start += `<named-content${attrs}>`
|
|
68
|
+
end = "</named-content>" + end
|
|
69
|
+
attrs = ""
|
|
70
|
+
}
|
|
71
|
+
return start + escapeText(node.text) + end
|
|
72
|
+
}
|