@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,452 @@
1
+ export const doc = {
2
+ content: "title part*",
3
+ selectable: false,
4
+ allowGapCursor: false,
5
+ attrs: {
6
+ documentstyle: {
7
+ default: ""
8
+ },
9
+ tracked: {
10
+ default: false
11
+ },
12
+ citationstyle: {
13
+ // Default citation style
14
+ default: "apa"
15
+ },
16
+ citationstyles: {
17
+ // Available citation styles
18
+ default: [
19
+ "american-anthropological-association",
20
+ "apa",
21
+ "chicago-author-date",
22
+ "chicago-note-bibliography",
23
+ "harvard-cite-them-right", // previously harvard1
24
+ "modern-language-association", // previously mla
25
+ "nature",
26
+ "oxford-university-press-humsoc"
27
+ ]
28
+ },
29
+ language: {
30
+ // Default language
31
+ default: "en-US"
32
+ },
33
+ languages: {
34
+ // Available languages
35
+ default: [
36
+ "af-ZA",
37
+ "sq-AL",
38
+ "ar",
39
+ "ast",
40
+ "be",
41
+ "br",
42
+ "bg",
43
+ "ca",
44
+ "ca-ES-Valencia",
45
+ "zh-CN",
46
+ "da",
47
+ "nl",
48
+ "en-AU",
49
+ "en-CA",
50
+ "en-NZ",
51
+ "en-ZA",
52
+ "en-GB",
53
+ "en-US",
54
+ "eo",
55
+ "fr",
56
+ "gl",
57
+ "de-DE",
58
+ "de-AU",
59
+ "de-CH",
60
+ "el",
61
+ "he",
62
+ "is",
63
+ "it",
64
+ "ja",
65
+ "km",
66
+ "lt",
67
+ "ml",
68
+ "nb-NO",
69
+ "nn-NO",
70
+ "fa",
71
+ "pl",
72
+ "pt-BR",
73
+ "pt-PT",
74
+ "ro",
75
+ "ru",
76
+ "tr",
77
+ "sr-SP-Cy",
78
+ "sr-SP-Lt",
79
+ "sk",
80
+ "sl",
81
+ "es",
82
+ "sv",
83
+ "ta",
84
+ "tl",
85
+ "uk"
86
+ ]
87
+ },
88
+ papersize: {
89
+ // Default paper size
90
+ default: "A4"
91
+ },
92
+ papersizes: {
93
+ // Available paper sizes
94
+ default: ["A4", "US Letter"]
95
+ },
96
+ footnote_marks: {
97
+ default: ["strong", "em", "link"]
98
+ },
99
+ footnote_elements: {
100
+ default: [
101
+ "paragraph",
102
+ "heading1",
103
+ "heading2",
104
+ "heading3",
105
+ "heading4",
106
+ "heading5",
107
+ "heading6",
108
+ "figure",
109
+ "ordered_list",
110
+ "bullet_list",
111
+ "horizontal_rule",
112
+ "equation",
113
+ "citation",
114
+ "cross_reference",
115
+ "blockquote",
116
+ "table"
117
+ ]
118
+ },
119
+ bibliography_header: {
120
+ default: {}
121
+ },
122
+ template: {
123
+ default: ""
124
+ },
125
+ import_id: {
126
+ default: ""
127
+ },
128
+ copyright: {
129
+ default: {
130
+ holder: false,
131
+ year: false,
132
+ freeToRead: true,
133
+ licenses: []
134
+ }
135
+ },
136
+ code_categories: {
137
+ default: {
138
+ listing: {
139
+ counter: 0,
140
+ enabled: true
141
+ },
142
+ example: {
143
+ counter: 0,
144
+ enabled: true
145
+ },
146
+ snippet: {
147
+ counter: 0,
148
+ enabled: false
149
+ },
150
+ tutorial: {
151
+ counter: 0,
152
+ enabled: false
153
+ },
154
+ exercise: {
155
+ counter: 0,
156
+ enabled: false
157
+ },
158
+ exercise_solution: {
159
+ counter: 0,
160
+ enabled: false
161
+ }
162
+ }
163
+ },
164
+ code_languages: {
165
+ default: [
166
+ "javascript",
167
+ "python",
168
+ "java",
169
+ "cpp",
170
+ "c",
171
+ "csharp",
172
+ "php",
173
+ "ruby",
174
+ "go",
175
+ "rust",
176
+ "swift",
177
+ "kotlin",
178
+ "typescript",
179
+ "html",
180
+ "css",
181
+ "sql",
182
+ "bash",
183
+ "shell",
184
+ "r",
185
+ "matlab",
186
+ "scala",
187
+ "perl",
188
+ "lua",
189
+ "haskell",
190
+ "xml",
191
+ "json",
192
+ "yaml",
193
+ "markdown"
194
+ ]
195
+ },
196
+ id_types: {
197
+ default: []
198
+ }
199
+ },
200
+ parseDOM: [
201
+ {
202
+ tag: "div.doc",
203
+ getAttrs(dom) {
204
+ return {
205
+ papersize: dom.dataset.papersize,
206
+ citationstyle: dom.dataset.citationstyle,
207
+ documentstyle: dom.dataset.documentstyle
208
+ }
209
+ }
210
+ }
211
+ ],
212
+ toDOM(node) {
213
+ return [
214
+ "div",
215
+ {
216
+ class: "doc",
217
+ "data-papersize": node.attrs.papersize,
218
+ "data-citationstyle": node.attrs.citationstyle,
219
+ "data-documentstyle": node.attrs.documentstyle
220
+ },
221
+ 0
222
+ ]
223
+ }
224
+ }
225
+
226
+ const partSpec = (type, content, attrs = {}) => ({
227
+ content,
228
+ group: "part",
229
+ marks: "annotation track",
230
+ isolating: true,
231
+ attrs: Object.assign(
232
+ {
233
+ title: {
234
+ default: ""
235
+ },
236
+ id: {
237
+ default: ""
238
+ },
239
+ locking: {
240
+ default: false
241
+ },
242
+ language: {
243
+ default: false
244
+ },
245
+ optional: {
246
+ default: false
247
+ },
248
+ hidden: {
249
+ default: false
250
+ },
251
+ help: {
252
+ default: false
253
+ },
254
+ initial: {
255
+ default: false
256
+ },
257
+ deleted: {
258
+ // used when a part is present in a document but not part of the document template due to template changes
259
+ default: false
260
+ }
261
+ },
262
+ attrs
263
+ ),
264
+ parseDOM: [
265
+ {
266
+ tag: `div.doc-${type}`,
267
+ getAttrs(dom) {
268
+ return {
269
+ hidden: dom.dataset.hidden === "true" ? true : false
270
+ }
271
+ }
272
+ }
273
+ ],
274
+ toDOM(node) {
275
+ const attrs = {
276
+ class: `doc-part doc-${type} ${node.attrs.id ? `doc-${node.attrs.id}` : "doc-no-id"}`
277
+ }
278
+ if (node.attrs.hidden) {
279
+ attrs["data-hidden"] = "true"
280
+ }
281
+ if (node.attrs.deleted) {
282
+ attrs.class += " doc-deleted"
283
+ }
284
+ return ["div", attrs, 0]
285
+ }
286
+ })
287
+
288
+ export const richtext_part = partSpec("richtext", "block+", {
289
+ elements: {
290
+ default: [
291
+ "paragraph",
292
+ "heading1",
293
+ "heading2",
294
+ "heading3",
295
+ "heading4",
296
+ "heading5",
297
+ "heading6",
298
+ "code_block",
299
+ "figure",
300
+ "ordered_list",
301
+ "bullet_list",
302
+ "horizontal_rule",
303
+ "equation",
304
+ "citation",
305
+ "cross_reference",
306
+ "blockquote",
307
+ "footnote",
308
+ "table"
309
+ ]
310
+ },
311
+ marks: {
312
+ default: ["strong", "em", "link", "anchor", "sup", "sub", "code"]
313
+ },
314
+ metadata: {
315
+ default: false
316
+ }
317
+ })
318
+ export const heading_part = partSpec("heading", "heading", {
319
+ elements: {
320
+ default: ["heading1"]
321
+ },
322
+ marks: {
323
+ default: ["strong", "em", "link", "anchor", "sup", "sub", "code"]
324
+ },
325
+ metadata: {
326
+ default: false
327
+ }
328
+ })
329
+ export const contributors_part = partSpec("contributors", "contributor*", {
330
+ item_title: {
331
+ default: "Contributor"
332
+ },
333
+ metadata: {
334
+ default: false
335
+ }
336
+ })
337
+ export const tags_part = partSpec("tags", "tag*", {
338
+ item_title: {
339
+ default: "Tag"
340
+ },
341
+ metadata: {
342
+ default: false
343
+ }
344
+ })
345
+ export const table_part = partSpec("table", "table", {
346
+ elements: {
347
+ default: [
348
+ "paragraph",
349
+ "heading1",
350
+ "heading2",
351
+ "heading3",
352
+ "heading4",
353
+ "heading5",
354
+ "heading6",
355
+ "code_block",
356
+ "figure",
357
+ "ordered_list",
358
+ "bullet_list",
359
+ "horizontal_rule",
360
+ "equation",
361
+ "citation",
362
+ "blockquote",
363
+ "footnote"
364
+ ]
365
+ },
366
+ marks: {
367
+ default: ["strong", "em", "link", "anchor", "sup", "sub", "code"]
368
+ }
369
+ })
370
+
371
+ export const table_of_contents = {
372
+ group: "part",
373
+ marks: "annotation track",
374
+ defining: true,
375
+ parseDOM: [
376
+ {
377
+ tag: "div.table-of-contents"
378
+ }
379
+ ],
380
+ attrs: {
381
+ title: {
382
+ default: "Table of Contents"
383
+ },
384
+ id: {
385
+ default: "toc"
386
+ },
387
+ optional: {
388
+ default: false
389
+ },
390
+ hidden: {
391
+ default: false
392
+ }
393
+ },
394
+ toDOM(node) {
395
+ const dom = document.createElement("div")
396
+ dom.classList.add("doc-part", "table-of-contents")
397
+ if (node.attrs.hidden) {
398
+ dom.dataset.hidden = "true"
399
+ }
400
+ dom.innerHTML = `<h1 class="toc">${node.attrs.title}</h1>`
401
+ return dom
402
+ }
403
+ }
404
+
405
+ export const separator_part = {
406
+ marks: "annotation track",
407
+ group: "part",
408
+ defining: true,
409
+ attrs: {
410
+ id: {
411
+ default: "separator"
412
+ }
413
+ },
414
+ parseDOM: [
415
+ {
416
+ tag: "hr.doc-separator_part"
417
+ }
418
+ ],
419
+ toDOM(node) {
420
+ const dom = document.createElement("hr")
421
+ dom.classList.add("doc-separator_part")
422
+ dom.classList.add(`doc-${node.attrs.id}`)
423
+ return dom
424
+ }
425
+ }
426
+
427
+ export const title = {
428
+ content: "text*",
429
+ marks: "annotation track",
430
+ group: "fixedpart",
431
+ defining: true,
432
+ isolating: true,
433
+ attrs: {
434
+ id: {
435
+ default: "title"
436
+ }
437
+ },
438
+ parseDOM: [
439
+ {
440
+ tag: "div.doc-title"
441
+ }
442
+ ],
443
+ toDOM(_node) {
444
+ return [
445
+ "div",
446
+ {
447
+ class: "doc-part doc-title"
448
+ },
449
+ 0
450
+ ]
451
+ }
452
+ }
@@ -0,0 +1,21 @@
1
+ import {docSchema} from "./document/index.js"
2
+
3
+ export class SchemaExport {
4
+ constructor() {
5
+ this.schema = docSchema
6
+ }
7
+
8
+ init() {
9
+ const spec = {
10
+ nodes: {},
11
+ marks: {}
12
+ }
13
+ this.schema.spec.nodes.forEach(
14
+ (key, value) => (spec.nodes[key] = value)
15
+ )
16
+ this.schema.spec.marks.forEach(
17
+ (key, value) => (spec.marks[key] = value)
18
+ )
19
+ return JSON.stringify(spec)
20
+ }
21
+ }
@@ -0,0 +1,126 @@
1
+ import OrderedMap from "orderedmap"
2
+ import {Schema} from "prosemirror-model"
3
+ import {marks, nodes} from "prosemirror-schema-basic"
4
+ import {tableNodes} from "prosemirror-tables"
5
+ import {
6
+ anchor,
7
+ annotation_tag,
8
+ blockquote,
9
+ bullet_list,
10
+ citation,
11
+ comment,
12
+ cross_reference,
13
+ deletion,
14
+ equation,
15
+ figure,
16
+ figure_caption,
17
+ figure_equation,
18
+ format_change,
19
+ heading1,
20
+ heading2,
21
+ heading3,
22
+ heading4,
23
+ heading5,
24
+ heading6,
25
+ horizontal_rule,
26
+ image,
27
+ insertion,
28
+ link,
29
+ list_item,
30
+ ordered_list,
31
+ paragraph,
32
+ underline
33
+ } from "./common/index.js"
34
+
35
+ const footnotecontainer = {
36
+ group: "part",
37
+ selectable: false,
38
+ content: "(block|table_block)+",
39
+ marks: "annotation",
40
+ parseDOM: [{tag: "div.footnote-container"}],
41
+ toDOM(_node) {
42
+ return ["div", {class: "footnote-container"}, 0]
43
+ }
44
+ }
45
+
46
+ const doc = {
47
+ content: "part*",
48
+ selectable: false
49
+ }
50
+
51
+ const spec = {
52
+ nodes: OrderedMap.from({
53
+ doc,
54
+ footnotecontainer,
55
+ paragraph,
56
+ heading1,
57
+ heading2,
58
+ heading3,
59
+ heading4,
60
+ heading5,
61
+ heading6,
62
+ blockquote,
63
+ horizontal_rule,
64
+ figure,
65
+ image,
66
+ figure_equation,
67
+ figure_caption,
68
+ text: nodes.text,
69
+ hard_break: nodes.hard_break,
70
+ citation,
71
+ equation,
72
+ cross_reference,
73
+ ordered_list,
74
+ bullet_list,
75
+ list_item
76
+ }),
77
+ marks: OrderedMap.from({
78
+ em: marks.em,
79
+ strong: marks.strong,
80
+ link,
81
+ underline,
82
+ anchor,
83
+ comment,
84
+ annotation_tag,
85
+ deletion,
86
+ insertion,
87
+ format_change
88
+ })
89
+ }
90
+
91
+ spec.nodes = spec.nodes.append(
92
+ tableNodes({
93
+ tableGroup: "table_block",
94
+ cellContent: "block+"
95
+ })
96
+ )
97
+
98
+ spec.nodes = spec.nodes.update(
99
+ "table",
100
+ Object.assign({}, spec.nodes.get("table"), {
101
+ attrs: {
102
+ track: {default: []}
103
+ },
104
+ parseDOM: [
105
+ {
106
+ tag: "table",
107
+ getAttrs(dom) {
108
+ return {
109
+ track: dom.dataset.track
110
+ ? JSON.parse(dom.dataset.track)
111
+ : []
112
+ }
113
+ }
114
+ }
115
+ ],
116
+ toDOM(node) {
117
+ const attrs = {}
118
+ if (node.attrs.track.length) {
119
+ attrs["data-track"] = JSON.stringify(node.attrs.track)
120
+ }
121
+ return ["table", attrs, ["tbody", 0]]
122
+ }
123
+ })
124
+ )
125
+
126
+ export const fnSchema = new Schema(spec)
@@ -0,0 +1,31 @@
1
+ import {DOMParser, DOMSerializer, Node} from "prosemirror-model"
2
+
3
+ import {fnSchema} from "./footnotes.js"
4
+
5
+ // Convert the footnote HTML stored with the marker to a PM node representation of the footnote.
6
+ export const htmlToFnNode = content => {
7
+ const footnoteDOM = document.createElement("div")
8
+ footnoteDOM.classList.add("footnote-container")
9
+ footnoteDOM.innerHTML = content
10
+ const node = DOMParser.fromSchema(fnSchema).parse(footnoteDOM, {
11
+ preserveWhitespace: true,
12
+ topNode: false
13
+ })
14
+ const json = node.firstChild.toJSON().content
15
+
16
+ return json
17
+ }
18
+
19
+ export const fnNodeToPmNode = fnContents => {
20
+ const footnote = {
21
+ type: "footnotecontainer",
22
+ content: fnContents
23
+ }
24
+ return Node.fromJSON(fnSchema, footnote)
25
+ }
26
+
27
+ export const fnNodeToHtml = jsonString => {
28
+ const pmNode = fnNodeToPmNode(jsonString),
29
+ serializer = DOMSerializer.fromSchema(fnSchema)
30
+ return serializer.serializeNode(pmNode).innerHTML
31
+ }