@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,85 @@
1
+ var assert = require("assert");
2
+
3
+ var xmlreader = require("../../lib/xml/reader");
4
+ var test = require("../test")(module);
5
+
6
+
7
+ test('should read self-closing element', function() {
8
+ return xmlreader.readString("<body/>").then(function(result) {
9
+ assert.deepEqual({type: "element", name: "body", attributes: {}, children: []}, result);
10
+ });
11
+ });
12
+
13
+ test('should read empty element with separate closing tag', function() {
14
+ return xmlreader.readString("<body></body>").then(function(result) {
15
+ assert.deepEqual({type: "element", name: "body", attributes: {}, children: []}, result);
16
+ });
17
+ });
18
+
19
+ test('should read attributes of tags', function() {
20
+ return xmlreader.readString('<body name="bob"/>').then(function(result) {
21
+ assert.deepEqual({name: "bob"}, result.attributes);
22
+ });
23
+ });
24
+
25
+ test('can read text element', function() {
26
+ return xmlreader.readString('<body>Hello!</body>').then(function(result) {
27
+ assert.deepEqual({type: "text", value: "Hello!"}, result.children[0]);
28
+ });
29
+ });
30
+
31
+ test('should read element with children', function() {
32
+ return xmlreader.readString("<body><a/><b/></body>").then(function(root) {
33
+ assert.equal(2, root.children.length);
34
+ assert.equal("a", root.children[0].name);
35
+ assert.equal("b", root.children[1].name);
36
+ });
37
+ });
38
+
39
+ test('unmapped namespaces URIs are included in braces as prefix', function() {
40
+ return xmlreader.readString('<w:body xmlns:w="word"/>').then(function(result) {
41
+ assert.deepEqual(result.name, "{word}body");
42
+ });
43
+ });
44
+
45
+ test('mapped namespaces URIs are translated using map', function() {
46
+ var namespaceMap = {
47
+ "word": "x"
48
+ };
49
+
50
+ return xmlreader.readString('<w:body xmlns:w="word"/>', namespaceMap).then(function(result) {
51
+ assert.deepEqual(result.name, "x:body");
52
+ });
53
+ });
54
+
55
+ test('namespace of attributes is mapped to prefix', function() {
56
+ var namespaceMap = {
57
+ "word": "x"
58
+ };
59
+ var xmlString = '<w:body xmlns:w="word" w:val="Hello!"/>';
60
+ return xmlreader.readString(xmlString, namespaceMap).then(function(result) {
61
+ assert.deepEqual(result.attributes["x:val"], "Hello!");
62
+ });
63
+ });
64
+
65
+ test('can find first element with name', function() {
66
+ return xmlreader.readString('<body><a/><b index="1"/><b index="2"/></body>').then(function(result) {
67
+ var first = result.first("b");
68
+ assert.equal("1", first.attributes.index);
69
+ });
70
+ });
71
+
72
+ test('whitespace between xml declaration and root tag is ignored', function() {
73
+ return xmlreader.readString('<?xml version="1.0" ?>\n<body/>').then(function(result) {
74
+ assert.deepEqual("body", result.name);
75
+ });
76
+ });
77
+
78
+ test('error if XML is badly formed', function() {
79
+ return xmlreader.readString("<bo").then(function(result) {
80
+ throw new Error("Expected failure");
81
+ }, function(error) {
82
+ assert.ok(error);
83
+ return 1;
84
+ });
85
+ });
@@ -0,0 +1,81 @@
1
+ var assert = require("assert");
2
+
3
+ var xml = require("../../lib/xml");
4
+ var writer = require("../../lib/xml/writer");
5
+ var test = require("../test")(module);
6
+
7
+
8
+ test('writing empty root element writes out xml declaration and empty root element', function() {
9
+ assertXmlString(xml.element("root"), {}, '<root/>');
10
+ });
11
+
12
+ test('can write empty child elements', function() {
13
+ assertXmlString(xml.element("root", {}, [xml.element("album"), xml.element("single")]), {},
14
+ '<root><album/><single/></root>');
15
+ });
16
+
17
+ test('can write empty descendant elements', function() {
18
+ var element = xml.element("root", {}, [
19
+ xml.element("album", {}, [
20
+ xml.element("year"),
21
+ xml.element("song")
22
+ ])
23
+ ]);
24
+ assertXmlString(element, {},
25
+ '<root><album><year/><song/></album></root>');
26
+ });
27
+
28
+ test('can write element attributes', function() {
29
+ var element = xml.element("root", {}, [
30
+ xml.element("album", {"title": "Everything in Transit"})
31
+ ]);
32
+ assertXmlString(element, {},
33
+ '<root><album title="Everything in Transit"/></root>');
34
+ });
35
+
36
+ test('can write text nodes', function() {
37
+ var element = xml.element("root", {}, [
38
+ xml.element("album", {}, [
39
+ xml.text("Everything in Transit")
40
+ ])
41
+ ]);
42
+ assertXmlString(element, {},
43
+ '<root><album>Everything in Transit</album></root>');
44
+ });
45
+
46
+ test('can write root element with long-form prefix when URI is namespace', function() {
47
+ var element = xml.element("{music}root");
48
+ assertXmlString(element, {"m": "music"},
49
+ '<m:root xmlns:m="music"/>');
50
+ });
51
+
52
+ test('can write child elements with long-form prefix when URI is namespace', function() {
53
+ var element = xml.element("root", {}, [
54
+ xml.element("{music}album")
55
+ ]);
56
+ assertXmlString(element, {"m": "music"},
57
+ '<root xmlns:m="music"><m:album/></root>');
58
+ });
59
+
60
+ test('can write child elements with short-form prefix when URI is namespace', function() {
61
+ var element = xml.element("root", {}, [
62
+ xml.element("m:album")
63
+ ]);
64
+ assertXmlString(element, {"m": "music"},
65
+ '<root xmlns:m="music"><m:album/></root>');
66
+ });
67
+
68
+ test('default namespace has key of empty string', function() {
69
+ var element = xml.element("root", {}, [
70
+ xml.element("{music}album")
71
+ ]);
72
+ assertXmlString(element, {"": "music"},
73
+ '<root xmlns="music"><album/></root>');
74
+ });
75
+
76
+
77
+ function assertXmlString(element, namespaces, expectedString) {
78
+ assert.equal(writer.writeString(element, namespaces),
79
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
80
+ expectedString);
81
+ }
@@ -0,0 +1,61 @@
1
+ var assert = require("assert");
2
+
3
+ var JSZip = require("jszip");
4
+
5
+ var zipfile = require("../lib/zipfile");
6
+ var test = require("./test")(module);
7
+
8
+ test('file in zip can be read after being written', function() {
9
+ return emptyZipFile().then(function(zip) {
10
+ assert(!zip.exists("song/title"));
11
+
12
+ zip.write("song/title", "Dark Blue");
13
+
14
+ assert(zip.exists("song/title"));
15
+ return zip.read("song/title", "utf8").then(function(contents) {
16
+ assert.equal(contents, "Dark Blue");
17
+ });
18
+ });
19
+ });
20
+
21
+ function emptyZipFile() {
22
+ var zip = new JSZip();
23
+ return zip.generateAsync({type: "arraybuffer"}).then(function(arrayBuffer) {
24
+ return zipfile.openArrayBuffer(arrayBuffer);
25
+ });
26
+ }
27
+
28
+
29
+ test("splitPath splits zip paths on last forward slash", function() {
30
+ assert.deepEqual(zipfile.splitPath("a/b"), {dirname: "a", basename: "b"});
31
+ assert.deepEqual(zipfile.splitPath("a/b/c"), {dirname: "a/b", basename: "c"});
32
+ assert.deepEqual(zipfile.splitPath("/a/b/c"), {dirname: "/a/b", basename: "c"});
33
+ });
34
+
35
+
36
+ test("when path has no forward slashes then splitPath returns empty dirname", function() {
37
+ assert.deepEqual(zipfile.splitPath("name"), {dirname: "", basename: "name"});
38
+ });
39
+
40
+
41
+ test("joinPath joins arguments with forward slashes", function() {
42
+ assert.equal(zipfile.joinPath("a", "b"), "a/b");
43
+ assert.equal(zipfile.joinPath("a/b", "c"), "a/b/c");
44
+ assert.equal(zipfile.joinPath("a", "b/c"), "a/b/c");
45
+ assert.equal(zipfile.joinPath("/a/b", "c"), "/a/b/c");
46
+ });
47
+
48
+
49
+ test("empty parts are ignored when joining paths", function() {
50
+ assert.equal(zipfile.joinPath("a", ""), "a");
51
+ assert.equal(zipfile.joinPath("", "b"), "b");
52
+ assert.equal(zipfile.joinPath("a", "", "b"), "a/b");
53
+ });
54
+
55
+
56
+ test("when joining paths then absolute paths ignore earlier paths", function() {
57
+ assert.equal(zipfile.joinPath("a", "/b"), "/b");
58
+ assert.equal(zipfile.joinPath("a", "/b", "c"), "/b/c");
59
+ assert.equal(zipfile.joinPath("/a", "/b"), "/b");
60
+ assert.equal(zipfile.joinPath("/a"), "/a");
61
+ });