@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,193 @@
|
|
|
1
|
+
// manages the .rels files. Need to initialize one for each of document.xml and footnotes.xml
|
|
2
|
+
import {escapeText} from "../../common/index.js"
|
|
3
|
+
|
|
4
|
+
const DEFAULT_XML = `<?xml version="1.0" encoding="UTF-8"?>
|
|
5
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>`
|
|
6
|
+
|
|
7
|
+
const DEFAULT_HYPERLINK_STYLE = `<w:style w:type="character" w:styleId="InternetLink">
|
|
8
|
+
<w:name w:val="Hyperlink"/>
|
|
9
|
+
<w:rPr>
|
|
10
|
+
<w:color w:val="000080"/>
|
|
11
|
+
<w:u w:val="single"/>
|
|
12
|
+
</w:rPr>
|
|
13
|
+
</w:style>`
|
|
14
|
+
|
|
15
|
+
export class DOCXExporterRels {
|
|
16
|
+
constructor(xml, docName) {
|
|
17
|
+
this.xml = xml
|
|
18
|
+
this.docName = docName
|
|
19
|
+
this.relsXML = false
|
|
20
|
+
this.ctXML = false
|
|
21
|
+
this.relIdCounter = -1
|
|
22
|
+
this.filePath = `word/_rels/${this.docName}.xml.rels`
|
|
23
|
+
this.ctFilePath = "[Content_Types].xml"
|
|
24
|
+
this.styleXML = false
|
|
25
|
+
this.styleFilePath = "word/styles.xml"
|
|
26
|
+
this.hyperLinkStyle = false
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
init() {
|
|
30
|
+
return Promise.all([
|
|
31
|
+
this.initCt()
|
|
32
|
+
.then(() => {
|
|
33
|
+
return this.xml.getXml(this.filePath, DEFAULT_XML)
|
|
34
|
+
})
|
|
35
|
+
.then(xml => {
|
|
36
|
+
this.relsXML = xml
|
|
37
|
+
this.findMaxRelId()
|
|
38
|
+
}),
|
|
39
|
+
this.xml.getXml(this.styleFilePath).then(styleXML => {
|
|
40
|
+
this.styleXML = styleXML
|
|
41
|
+
return Promise.resolve()
|
|
42
|
+
})
|
|
43
|
+
])
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
initCt() {
|
|
47
|
+
return this.xml.getXml(this.ctFilePath).then(ctXML => {
|
|
48
|
+
this.ctXML = ctXML
|
|
49
|
+
this.addRelsToCt()
|
|
50
|
+
return Promise.resolve()
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Go through a rels xml file and file all the listed relations
|
|
55
|
+
findMaxRelId() {
|
|
56
|
+
const rels = this.relsXML.queryAll("Relationship")
|
|
57
|
+
|
|
58
|
+
rels.forEach(rel => {
|
|
59
|
+
const id = Number.parseInt(
|
|
60
|
+
rel.getAttribute("Id").replace(/\D/g, "")
|
|
61
|
+
)
|
|
62
|
+
if (id > this.relIdCounter) {
|
|
63
|
+
this.relIdCounter = id
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
addRelsToCt() {
|
|
69
|
+
const override = this.ctXML.query("Overrid", {
|
|
70
|
+
PartName: `/${this.filePath}`
|
|
71
|
+
})
|
|
72
|
+
if (!override) {
|
|
73
|
+
const types = this.ctXML.query("Types")
|
|
74
|
+
types.appendXML(
|
|
75
|
+
`<Override PartName="/${this.filePath}" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>`
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Add a relationship for a link
|
|
81
|
+
addLinkRel(link) {
|
|
82
|
+
const rels = this.relsXML.query("Relationships")
|
|
83
|
+
const rId = ++this.relIdCounter
|
|
84
|
+
const string = `<Relationship Id="rId${rId}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="${escapeText(link)}" TargetMode="External"/>`
|
|
85
|
+
rels.appendXML(string)
|
|
86
|
+
return rId
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
addLinkStyle() {
|
|
90
|
+
if (this.hyperLinkStyle) {
|
|
91
|
+
// already added
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
const hyperLinkEl = this.styleXML.query("w:name", {
|
|
95
|
+
"w:val": "Hyperlink"
|
|
96
|
+
})
|
|
97
|
+
if (hyperLinkEl) {
|
|
98
|
+
this.hyperLinkStyle =
|
|
99
|
+
hyperLinkEl.parentElement.getAttribute("w:styleId")
|
|
100
|
+
} else {
|
|
101
|
+
const stylesEl = this.styleXML.query("w:styles")
|
|
102
|
+
stylesEl.appendXML(DEFAULT_HYPERLINK_STYLE)
|
|
103
|
+
this.hyperLinkStyle = "InternetLink"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// add a relationship for an image
|
|
108
|
+
addImageRel(imgFileName) {
|
|
109
|
+
const rels = this.relsXML.query("Relationships")
|
|
110
|
+
const rId = ++this.relIdCounter
|
|
111
|
+
const string = `<Relationship Id="rId${rId}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/${escapeText(imgFileName)}"/>`
|
|
112
|
+
rels.appendXML(string)
|
|
113
|
+
return rId
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
addFootnoteRel() {
|
|
117
|
+
const footnotesRel = this.relsXML.query("Relationship", {
|
|
118
|
+
Target: "footnotes.xml"
|
|
119
|
+
})
|
|
120
|
+
if (footnotesRel) {
|
|
121
|
+
// Rel exists already
|
|
122
|
+
const fnRId = Number.parseInt(
|
|
123
|
+
footnotesRel.getAttribute("Id").replace(/\D/g, "")
|
|
124
|
+
)
|
|
125
|
+
return fnRId
|
|
126
|
+
}
|
|
127
|
+
const rels = this.relsXML.query("Relationships")
|
|
128
|
+
const rId = ++this.relIdCounter
|
|
129
|
+
const string = `<Relationship Id="rId${rId}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" Target="footnotes.xml"/>`
|
|
130
|
+
rels.appendXML(string)
|
|
131
|
+
return rId
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
addNumberingRel() {
|
|
135
|
+
const numberingRel = this.relsXML.query("Relationship", {
|
|
136
|
+
Target: "numbering.xml"
|
|
137
|
+
})
|
|
138
|
+
if (numberingRel) {
|
|
139
|
+
// Rel exists already
|
|
140
|
+
const nuRId = Number.parseInt(
|
|
141
|
+
numberingRel.getAttribute("Id").replace(/\D/g, "")
|
|
142
|
+
)
|
|
143
|
+
return nuRId
|
|
144
|
+
}
|
|
145
|
+
const rels = this.relsXML.query("Relationships")
|
|
146
|
+
const rId = ++this.relIdCounter
|
|
147
|
+
const string = `<Relationship Id="rId${rId}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>`
|
|
148
|
+
rels.appendXML(string)
|
|
149
|
+
return rId
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
addCommentsRel() {
|
|
153
|
+
const commentsRel = this.relsXML.query("Relationship", {
|
|
154
|
+
Target: "comments.xml"
|
|
155
|
+
})
|
|
156
|
+
if (commentsRel) {
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
const rels = this.relsXML.query("Relationships")
|
|
160
|
+
const string = `<Relationship Id="rId${++this.relIdCounter}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" Target="comments.xml"/>`
|
|
161
|
+
rels.appendXML(string)
|
|
162
|
+
const override = this.ctXML.query("Override", {
|
|
163
|
+
PartName: "/word/comments.xml"
|
|
164
|
+
})
|
|
165
|
+
if (!override) {
|
|
166
|
+
const types = this.ctXML.query("Types")
|
|
167
|
+
types.appendXML(
|
|
168
|
+
'<Override PartName="/word/comments.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"/>'
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
addCommentsExtendedRel() {
|
|
174
|
+
const commentsExtendedRel = this.relsXML.query("Relationship", {
|
|
175
|
+
Target: "commentsExtended.xml"
|
|
176
|
+
})
|
|
177
|
+
if (commentsExtendedRel) {
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
const rels = this.relsXML.query("Relationships")
|
|
181
|
+
const string = `<Relationship Id="rId${++this.relIdCounter}" Type="http://schemas.microsoft.com/office/2011/relationships/commentsExtended" Target="commentsExtended.xml"/>`
|
|
182
|
+
rels.appendXML(string)
|
|
183
|
+
const override = this.ctXML.query("Override", {
|
|
184
|
+
PartName: "/word/commentsExtended.xml"
|
|
185
|
+
})
|
|
186
|
+
if (!override) {
|
|
187
|
+
const types = this.ctXML.query("Types")
|
|
188
|
+
types.appendXML(
|
|
189
|
+
'<Override PartName="/word/commentsExtended.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml"/>'
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|