@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.
Files changed (110) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +16 -0
  3. package/jest.config.js +23 -0
  4. package/package.json +59 -0
  5. package/schema.json +1 -0
  6. package/scripts/export-schema.js +16 -0
  7. package/src/bibliography/common.js +92 -0
  8. package/src/bibliography/csl_bib.js +139 -0
  9. package/src/citations/citeproc_sys.js +42 -0
  10. package/src/citations/format.js +194 -0
  11. package/src/common/blob.js +10 -0
  12. package/src/common/file.js +25 -0
  13. package/src/common/index.js +12 -0
  14. package/src/common/network.js +79 -0
  15. package/src/common/text.js +44 -0
  16. package/src/editor/e2ee/encryptor.js +228 -0
  17. package/src/exporter/docx/citations.js +177 -0
  18. package/src/exporter/docx/comments.js +165 -0
  19. package/src/exporter/docx/footnotes.js +240 -0
  20. package/src/exporter/docx/images.js +101 -0
  21. package/src/exporter/docx/index.js +185 -0
  22. package/src/exporter/docx/lists.js +260 -0
  23. package/src/exporter/docx/math.js +46 -0
  24. package/src/exporter/docx/metadata.js +289 -0
  25. package/src/exporter/docx/rels.js +193 -0
  26. package/src/exporter/docx/render.js +941 -0
  27. package/src/exporter/docx/richtext.js +1182 -0
  28. package/src/exporter/docx/tables.js +112 -0
  29. package/src/exporter/docx/tools.js +50 -0
  30. package/src/exporter/epub/index.js +142 -0
  31. package/src/exporter/epub/templates.js +140 -0
  32. package/src/exporter/epub/tools.js +96 -0
  33. package/src/exporter/html/citations.js +121 -0
  34. package/src/exporter/html/convert.js +813 -0
  35. package/src/exporter/html/index.js +192 -0
  36. package/src/exporter/html/templates.js +34 -0
  37. package/src/exporter/html/tools.js +50 -0
  38. package/src/exporter/jats/bibliography.js +183 -0
  39. package/src/exporter/jats/citations.js +109 -0
  40. package/src/exporter/jats/convert.js +871 -0
  41. package/src/exporter/jats/index.js +92 -0
  42. package/src/exporter/jats/templates.js +35 -0
  43. package/src/exporter/jats/text.js +72 -0
  44. package/src/exporter/latex/convert.js +934 -0
  45. package/src/exporter/latex/escape_latex.js +21 -0
  46. package/src/exporter/latex/index.js +74 -0
  47. package/src/exporter/latex/readme.js +22 -0
  48. package/src/exporter/native/shrink.js +132 -0
  49. package/src/exporter/odt/citations.js +101 -0
  50. package/src/exporter/odt/footnotes.js +147 -0
  51. package/src/exporter/odt/images.js +115 -0
  52. package/src/exporter/odt/index.js +156 -0
  53. package/src/exporter/odt/math.js +57 -0
  54. package/src/exporter/odt/metadata.js +251 -0
  55. package/src/exporter/odt/render.js +806 -0
  56. package/src/exporter/odt/richtext.js +865 -0
  57. package/src/exporter/odt/styles.js +387 -0
  58. package/src/exporter/odt/track.js +68 -0
  59. package/src/exporter/pandoc/citations.js +98 -0
  60. package/src/exporter/pandoc/convert.js +1017 -0
  61. package/src/exporter/pandoc/index.js +92 -0
  62. package/src/exporter/pandoc/readme.js +8 -0
  63. package/src/exporter/pandoc/tools.js +51 -0
  64. package/src/exporter/print/index.js +177 -0
  65. package/src/exporter/tools/doc_content.js +144 -0
  66. package/src/exporter/tools/file.js +9 -0
  67. package/src/exporter/tools/json.js +73 -0
  68. package/src/exporter/tools/svg.js +29 -0
  69. package/src/exporter/tools/xml.js +531 -0
  70. package/src/exporter/tools/xml_zip.js +95 -0
  71. package/src/exporter/tools/zip.js +90 -0
  72. package/src/exporter/tools/zotero_csl.js +93 -0
  73. package/src/importer/citations.js +129 -0
  74. package/src/importer/docx/citations.js +123 -0
  75. package/src/importer/docx/convert.js +1427 -0
  76. package/src/importer/docx/helpers.js +9 -0
  77. package/src/importer/docx/omml2mathml.js +1448 -0
  78. package/src/importer/docx/parse.js +735 -0
  79. package/src/importer/native/get_images.js +76 -0
  80. package/src/importer/native/update.js +29 -0
  81. package/src/importer/odt/citations.js +87 -0
  82. package/src/importer/odt/convert.js +1855 -0
  83. package/src/importer/pandoc/convert.js +884 -0
  84. package/src/importer/pandoc/helpers.js +84 -0
  85. package/src/importer/zip_analyzer.js +102 -0
  86. package/src/index.js +1 -0
  87. package/src/mathlive/opf_includes.js +24 -0
  88. package/src/schema/common/annotate.js +76 -0
  89. package/src/schema/common/base.js +118 -0
  90. package/src/schema/common/citation.js +62 -0
  91. package/src/schema/common/equation.js +31 -0
  92. package/src/schema/common/figure.js +190 -0
  93. package/src/schema/common/heading.js +43 -0
  94. package/src/schema/common/index.js +40 -0
  95. package/src/schema/common/list.js +95 -0
  96. package/src/schema/common/reference.js +100 -0
  97. package/src/schema/common/table.js +103 -0
  98. package/src/schema/common/track.js +190 -0
  99. package/src/schema/const.js +58 -0
  100. package/src/schema/convert.js +1272 -0
  101. package/src/schema/document/content.js +187 -0
  102. package/src/schema/document/index.js +117 -0
  103. package/src/schema/document/structure.js +452 -0
  104. package/src/schema/export.js +21 -0
  105. package/src/schema/footnotes.js +126 -0
  106. package/src/schema/footnotes_convert.js +31 -0
  107. package/src/schema/i18n.js +595 -0
  108. package/src/schema/index.js +5 -0
  109. package/src/schema/mini_json.js +61 -0
  110. 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
+ }