@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,76 @@
1
+ import {get} from "../../common/index.js"
2
+
3
+ export class GetImages {
4
+ constructor(images, entries) {
5
+ this.images = images
6
+ this.imageEntries = Object.values(this.images)
7
+ this.entries = entries
8
+ this.counter = 0
9
+ }
10
+
11
+ init() {
12
+ if (this.entries.length > 0) {
13
+ if (this.entries[0].hasOwnProperty("url")) {
14
+ return this.getImageUrlEntry()
15
+ } else {
16
+ return this.getImageZipEntry()
17
+ }
18
+ } else {
19
+ return Promise.resolve()
20
+ }
21
+ }
22
+
23
+ getImageZipEntry() {
24
+ if (this.counter < this.imageEntries.length) {
25
+ return new Promise(resolve => {
26
+ const f = this.entries.find(
27
+ entry =>
28
+ entry.filename === this.imageEntries[this.counter].image
29
+ )
30
+ if (!f) {
31
+ console.warn(
32
+ `Image ${this.imageEntries[this.counter].image} not found`,
33
+ this.imageEntries,
34
+ this.entries
35
+ )
36
+ this.counter++
37
+ return this.getImageZipEntry().then(() => {
38
+ resolve()
39
+ })
40
+ }
41
+ const fc = f.content
42
+ this.imageEntries[this.counter]["file"] = new window.Blob(
43
+ [fc],
44
+ {
45
+ type: this.imageEntries[this.counter].file_type
46
+ }
47
+ )
48
+ this.counter++
49
+ this.getImageZipEntry().then(() => {
50
+ resolve()
51
+ })
52
+ })
53
+ } else {
54
+ return Promise.resolve()
55
+ }
56
+ }
57
+
58
+ getImageUrlEntry() {
59
+ if (this.counter < this.imageEntries.length) {
60
+ const getUrl = this.entries.find(
61
+ entry =>
62
+ entry.filename ===
63
+ `images/${this.imageEntries[this.counter].image.split("/").pop()}`
64
+ ).url
65
+ return get(getUrl)
66
+ .then(response => response.blob())
67
+ .then(blob => {
68
+ this.imageEntries[this.counter]["file"] = blob
69
+ this.counter++
70
+ return this.getImageUrlEntry()
71
+ })
72
+ } else {
73
+ return Promise.resolve()
74
+ }
75
+ }
76
+ }
@@ -0,0 +1,29 @@
1
+ import {updateDoc} from "../../schema/convert.js"
2
+
3
+ export function updateFile(doc, filetypeVersion, bibliography, images) {
4
+ // update bibliography -- currently not needed
5
+ // bibliography = updateBib(bibliography)
6
+ if (filetypeVersion < 3.2) {
7
+ Object.values(images).forEach(
8
+ image =>
9
+ (image.copyright = {
10
+ holder: false,
11
+ year: false,
12
+ freeToRead: true,
13
+ licenses: []
14
+ })
15
+ )
16
+ }
17
+ if (filetypeVersion < 3.3) {
18
+ doc.content = doc.contents
19
+ delete doc.contents
20
+ }
21
+ if (filetypeVersion < 2.0) {
22
+ // Before 2.0, version numbers of the doc and of the file differed.
23
+ doc = updateDoc(doc, doc.settings["doc_version"], bibliography)
24
+ } else {
25
+ doc = updateDoc(doc, filetypeVersion, bibliography)
26
+ }
27
+
28
+ return {doc, bibliography, images}
29
+ }
@@ -0,0 +1,87 @@
1
+ import {OdtCitationsParser} from "biblatex-csl-converter"
2
+ import {citationResultToNode} from "../citations.js"
3
+
4
+ /**
5
+ * Check whether an ODT reference mark name belongs to a bibliography region
6
+ * (Zotero ZOTERO_BIBL, Mendeley CSL_BIBLIOGRAPHY).
7
+ * Uses OdtCitationsParser.referenceMarkBibliography().
8
+ *
9
+ * @param {string} markName - text:name attribute value
10
+ * @returns {boolean}
11
+ */
12
+ export function isOdtBibliographyReferenceMark(markName) {
13
+ if (!markName) {
14
+ return false
15
+ }
16
+ return OdtCitationsParser.referenceMarkBibliography(markName).isBibliography
17
+ }
18
+
19
+ /**
20
+ * Check whether a text:section name belongs to a bibliography region
21
+ * (Zotero, JabRef).
22
+ * Uses OdtCitationsParser.sectionBibliography().
23
+ *
24
+ * @param {string} sectionName - text:name attribute value
25
+ * @returns {boolean}
26
+ */
27
+ export function isOdtBibliographySection(sectionName) {
28
+ if (!sectionName) {
29
+ return false
30
+ }
31
+ return OdtCitationsParser.sectionBibliography(sectionName).isBibliography
32
+ }
33
+
34
+ /**
35
+ * Check whether an ODT reference mark name belongs to a citation.
36
+ * Uses OdtCitationsParser.referenceMarkCitation() with retrieve=false.
37
+ *
38
+ * @param {string} markName - text:name attribute value
39
+ * @returns {boolean}
40
+ */
41
+ export function isOdtCitationMark(markName) {
42
+ if (!markName) {
43
+ return false
44
+ }
45
+ return OdtCitationsParser.referenceMarkCitation(markName, false).isCitation
46
+ }
47
+
48
+ /**
49
+ * Parse a citation from an ODT reference mark name and add any new
50
+ * bibliography entries into `bibliography`.
51
+ *
52
+ * Handles Zotero, Mendeley Desktop (legacy), and JabRef reference marks.
53
+ *
54
+ * @param {string} markName - text:name attribute of the reference-mark-start
55
+ * @param {Object} bibliography - Fidus Writer bibliography (mutated in place)
56
+ * @returns {Object|null} ProseMirror citation node or null
57
+ */
58
+ export function parseOdtReferenceMark(markName, bibliography, bibDB) {
59
+ if (!markName) {
60
+ return null
61
+ }
62
+ const result = OdtCitationsParser.referenceMarkCitation(
63
+ markName,
64
+ true, // retrieve
65
+ true // retrieveMetadata
66
+ )
67
+ return citationResultToNode(result, bibliography, bibDB)
68
+ }
69
+
70
+ /**
71
+ * Parse a citation from a LibreOffice native <text:bibliography-mark> element
72
+ * and add any new bibliography entries into `bibliography`.
73
+ *
74
+ * @param {Object} bibMarkNode - The parsed text:bibliography-mark XMLElement
75
+ * @param {Object} bibliography - Fidus Writer bibliography (mutated in place)
76
+ * @returns {Object|null} ProseMirror citation node or null
77
+ */
78
+ export function parseOdtBibliographyMark(bibMarkNode, bibliography) {
79
+ if (!bibMarkNode) {
80
+ return null
81
+ }
82
+ const result = OdtCitationsParser.bibliographyMarkCitation(
83
+ bibMarkNode.outerXML,
84
+ true // retrieve
85
+ )
86
+ return citationResultToNode(result, bibliography)
87
+ }