@depup/mammoth 1.12.0-depup.54

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 (118) hide show
  1. package/.eslintrc.json +75 -0
  2. package/.github/ISSUE_TEMPLATE.md +12 -0
  3. package/.github/pull_request_template.md +3 -0
  4. package/.github/workflows/tests.yml +26 -0
  5. package/LICENSE +22 -0
  6. package/NEWS +530 -0
  7. package/README.md +37 -0
  8. package/bin/mammoth +38 -0
  9. package/browser/docx/files.js +14 -0
  10. package/browser/unzip.js +12 -0
  11. package/changes.json +34 -0
  12. package/lib/document-to-html.js +469 -0
  13. package/lib/documents.js +254 -0
  14. package/lib/docx/body-reader.js +798 -0
  15. package/lib/docx/comments-reader.js +31 -0
  16. package/lib/docx/content-types-reader.js +58 -0
  17. package/lib/docx/document-xml-reader.js +30 -0
  18. package/lib/docx/docx-reader.js +226 -0
  19. package/lib/docx/files.js +80 -0
  20. package/lib/docx/notes-reader.js +28 -0
  21. package/lib/docx/numbering-xml.js +111 -0
  22. package/lib/docx/office-xml-reader.js +73 -0
  23. package/lib/docx/relationships-reader.js +43 -0
  24. package/lib/docx/style-map.js +75 -0
  25. package/lib/docx/styles-reader.js +90 -0
  26. package/lib/docx/uris.js +21 -0
  27. package/lib/html/ast.js +51 -0
  28. package/lib/html/index.js +41 -0
  29. package/lib/html/simplify.js +88 -0
  30. package/lib/images.js +31 -0
  31. package/lib/index.d.ts +86 -0
  32. package/lib/index.js +111 -0
  33. package/lib/main.js +63 -0
  34. package/lib/options-reader.js +107 -0
  35. package/lib/promises.js +42 -0
  36. package/lib/raw-text.js +14 -0
  37. package/lib/results.js +72 -0
  38. package/lib/style-reader.js +365 -0
  39. package/lib/styles/document-matchers.js +100 -0
  40. package/lib/styles/html-paths.js +75 -0
  41. package/lib/styles/parser/tokeniser.js +30 -0
  42. package/lib/transforms.js +62 -0
  43. package/lib/underline.js +11 -0
  44. package/lib/unzip.js +20 -0
  45. package/lib/writers/html-writer.js +159 -0
  46. package/lib/writers/index.js +14 -0
  47. package/lib/writers/markdown-writer.js +163 -0
  48. package/lib/xml/index.js +8 -0
  49. package/lib/xml/nodes.js +70 -0
  50. package/lib/xml/reader.js +69 -0
  51. package/lib/xml/writer.js +61 -0
  52. package/lib/xml/xmldom.js +23 -0
  53. package/lib/zipfile.js +72 -0
  54. package/mammoth.browser.js +22096 -0
  55. package/mammoth.browser.min.js +20 -0
  56. package/package.json +106 -0
  57. package/test/.eslintrc.json +7 -0
  58. package/test/document-to-html.tests.js +892 -0
  59. package/test/docx/body-reader.tests.js +2037 -0
  60. package/test/docx/comments-reader.tests.js +53 -0
  61. package/test/docx/content-types-reader.tests.js +45 -0
  62. package/test/docx/document-matchers.js +42 -0
  63. package/test/docx/document-xml-reader.tests.js +41 -0
  64. package/test/docx/docx-reader.tests.js +179 -0
  65. package/test/docx/files.tests.js +107 -0
  66. package/test/docx/notes-reader.tests.js +36 -0
  67. package/test/docx/numbering-xml.tests.js +183 -0
  68. package/test/docx/office-xml-reader.tests.js +41 -0
  69. package/test/docx/relationships-reader.tests.js +65 -0
  70. package/test/docx/style-map.tests.js +113 -0
  71. package/test/docx/styles-reader.tests.js +143 -0
  72. package/test/docx/testing.js +12 -0
  73. package/test/docx/uris.tests.js +22 -0
  74. package/test/html/simplify.tests.js +141 -0
  75. package/test/html/write.tests.js +42 -0
  76. package/test/images.tests.js +112 -0
  77. package/test/main.tests.js +89 -0
  78. package/test/mammoth.tests.js +523 -0
  79. package/test/mocha.opts +1 -0
  80. package/test/options-reader.tests.js +63 -0
  81. package/test/raw-text.tests.js +61 -0
  82. package/test/results.tests.js +15 -0
  83. package/test/style-reader.tests.js +291 -0
  84. package/test/styles/document-matchers.tests.js +91 -0
  85. package/test/styles/html-paths.tests.js +20 -0
  86. package/test/styles/parser/tokeniser.tests.js +104 -0
  87. package/test/test-data/comments.docx +0 -0
  88. package/test/test-data/embedded-style-map.docx +0 -0
  89. package/test/test-data/empty.docx +0 -0
  90. package/test/test-data/empty.zip +0 -0
  91. package/test/test-data/endnotes.docx +0 -0
  92. package/test/test-data/external-picture.docx +0 -0
  93. package/test/test-data/footnote-hyperlink.docx +0 -0
  94. package/test/test-data/footnotes.docx +0 -0
  95. package/test/test-data/hello.zip +0 -0
  96. package/test/test-data/hyperlinks/word/_rels/document.xml.rels +10 -0
  97. package/test/test-data/hyperlinks/word/document.xml +18 -0
  98. package/test/test-data/simple/word/document.xml +18 -0
  99. package/test/test-data/simple-list.docx +0 -0
  100. package/test/test-data/single-paragraph.docx +0 -0
  101. package/test/test-data/strict-format.docx +0 -0
  102. package/test/test-data/strikethrough.docx +0 -0
  103. package/test/test-data/tables.docx +0 -0
  104. package/test/test-data/text-box.docx +0 -0
  105. package/test/test-data/tiny-picture-target-base-relative.docx +0 -0
  106. package/test/test-data/tiny-picture.docx +0 -0
  107. package/test/test-data/tiny-picture.png +0 -0
  108. package/test/test-data/underline.docx +0 -0
  109. package/test/test-data/utf8-bom.docx +0 -0
  110. package/test/test.js +11 -0
  111. package/test/testing.js +55 -0
  112. package/test/transforms.tests.js +125 -0
  113. package/test/unzip.tests.js +38 -0
  114. package/test/writers/html-writer.tests.js +133 -0
  115. package/test/writers/markdown-writer.tests.js +304 -0
  116. package/test/xml/reader.tests.js +85 -0
  117. package/test/xml/writer.tests.js +81 -0
  118. package/test/zipfile.tests.js +61 -0
@@ -0,0 +1,61 @@
1
+ var _ = require("underscore");
2
+ var xmlbuilder = require("xmlbuilder");
3
+
4
+
5
+ exports.writeString = writeString;
6
+
7
+
8
+ function writeString(root, namespaces) {
9
+ var uriToPrefix = _.invert(namespaces);
10
+
11
+ var nodeWriters = {
12
+ element: writeElement,
13
+ text: writeTextNode
14
+ };
15
+
16
+ function writeNode(builder, node) {
17
+ return nodeWriters[node.type](builder, node);
18
+ }
19
+
20
+ function writeElement(builder, element) {
21
+ var elementBuilder = builder.element(mapElementName(element.name), element.attributes);
22
+ element.children.forEach(function(child) {
23
+ writeNode(elementBuilder, child);
24
+ });
25
+ }
26
+
27
+ function mapElementName(name) {
28
+ var longFormMatch = /^\{(.*)\}(.*)$/.exec(name);
29
+ if (longFormMatch) {
30
+ var prefix = uriToPrefix[longFormMatch[1]];
31
+ return prefix + (prefix === "" ? "" : ":") + longFormMatch[2];
32
+ } else {
33
+ return name;
34
+ }
35
+ }
36
+
37
+ function writeDocument(root) {
38
+ var builder = xmlbuilder
39
+ .create(mapElementName(root.name), {
40
+ version: '1.0',
41
+ encoding: 'UTF-8',
42
+ standalone: true
43
+ });
44
+
45
+ _.forEach(namespaces, function(uri, prefix) {
46
+ var key = "xmlns" + (prefix === "" ? "" : ":" + prefix);
47
+ builder.attribute(key, uri);
48
+ });
49
+
50
+ root.children.forEach(function(child) {
51
+ writeNode(builder, child);
52
+ });
53
+ return builder.end();
54
+ }
55
+
56
+ return writeDocument(root);
57
+ }
58
+
59
+ function writeTextNode(builder, node) {
60
+ builder.text(node.value);
61
+ }
@@ -0,0 +1,23 @@
1
+ var xmldom = require("@xmldom/xmldom");
2
+ var dom = require("@xmldom/xmldom/lib/dom");
3
+
4
+ function parseFromString(string) {
5
+ var error = null;
6
+
7
+ var domParser = new xmldom.DOMParser({
8
+ errorHandler: function(level, message) {
9
+ error = {level: level, message: message};
10
+ }
11
+ });
12
+
13
+ var document = domParser.parseFromString(string);
14
+
15
+ if (error === null) {
16
+ return document;
17
+ } else {
18
+ throw new Error(error.level + ": " + error.message);
19
+ }
20
+ }
21
+
22
+ exports.parseFromString = parseFromString;
23
+ exports.Node = dom.Node;
package/lib/zipfile.js ADDED
@@ -0,0 +1,72 @@
1
+ var base64js = require("base64-js");
2
+ var JSZip = require("jszip");
3
+
4
+ exports.openArrayBuffer = openArrayBuffer;
5
+ exports.splitPath = splitPath;
6
+ exports.joinPath = joinPath;
7
+
8
+ function openArrayBuffer(arrayBuffer) {
9
+ return JSZip.loadAsync(arrayBuffer).then(function(zipFile) {
10
+ function exists(name) {
11
+ return zipFile.file(name) !== null;
12
+ }
13
+
14
+ function read(name, encoding) {
15
+ return zipFile.file(name).async("uint8array").then(function(array) {
16
+ if (encoding === "base64") {
17
+ return base64js.fromByteArray(array);
18
+ } else if (encoding) {
19
+ var decoder = new TextDecoder(encoding);
20
+ return decoder.decode(array);
21
+ } else {
22
+ return array;
23
+ }
24
+ });
25
+ }
26
+
27
+ function write(name, contents) {
28
+ zipFile.file(name, contents);
29
+ }
30
+
31
+ function toArrayBuffer() {
32
+ return zipFile.generateAsync({type: "arraybuffer"});
33
+ }
34
+
35
+ return {
36
+ exists: exists,
37
+ read: read,
38
+ write: write,
39
+ toArrayBuffer: toArrayBuffer
40
+ };
41
+ });
42
+ }
43
+
44
+ function splitPath(path) {
45
+ var lastIndex = path.lastIndexOf("/");
46
+ if (lastIndex === -1) {
47
+ return {dirname: "", basename: path};
48
+ } else {
49
+ return {
50
+ dirname: path.substring(0, lastIndex),
51
+ basename: path.substring(lastIndex + 1)
52
+ };
53
+ }
54
+ }
55
+
56
+ function joinPath() {
57
+ var nonEmptyPaths = Array.prototype.filter.call(arguments, function(path) {
58
+ return path;
59
+ });
60
+
61
+ var relevantPaths = [];
62
+
63
+ nonEmptyPaths.forEach(function(path) {
64
+ if (/^\//.test(path)) {
65
+ relevantPaths = [path];
66
+ } else {
67
+ relevantPaths.push(path);
68
+ }
69
+ });
70
+
71
+ return relevantPaths.join("/");
72
+ }