@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,254 @@
1
+ var _ = require("underscore");
2
+
3
+ var types = exports.types = {
4
+ document: "document",
5
+ paragraph: "paragraph",
6
+ run: "run",
7
+ text: "text",
8
+ tab: "tab",
9
+ checkbox: "checkbox",
10
+ hyperlink: "hyperlink",
11
+ noteReference: "noteReference",
12
+ image: "image",
13
+ note: "note",
14
+ commentReference: "commentReference",
15
+ comment: "comment",
16
+ table: "table",
17
+ tableRow: "tableRow",
18
+ tableCell: "tableCell",
19
+ "break": "break",
20
+ bookmarkStart: "bookmarkStart"
21
+ };
22
+
23
+ function Document(children, options) {
24
+ options = options || {};
25
+ return {
26
+ type: types.document,
27
+ children: children,
28
+ notes: options.notes || new Notes({}),
29
+ comments: options.comments || []
30
+ };
31
+ }
32
+
33
+ function Paragraph(children, properties) {
34
+ properties = properties || {};
35
+ var indent = properties.indent || {};
36
+ return {
37
+ type: types.paragraph,
38
+ children: children,
39
+ styleId: properties.styleId || null,
40
+ styleName: properties.styleName || null,
41
+ numbering: properties.numbering || null,
42
+ alignment: properties.alignment || null,
43
+ indent: {
44
+ start: indent.start || null,
45
+ end: indent.end || null,
46
+ firstLine: indent.firstLine || null,
47
+ hanging: indent.hanging || null
48
+ }
49
+ };
50
+ }
51
+
52
+ function Run(children, properties) {
53
+ properties = properties || {};
54
+ return {
55
+ type: types.run,
56
+ children: children,
57
+ styleId: properties.styleId || null,
58
+ styleName: properties.styleName || null,
59
+ isBold: !!properties.isBold,
60
+ isUnderline: !!properties.isUnderline,
61
+ isItalic: !!properties.isItalic,
62
+ isStrikethrough: !!properties.isStrikethrough,
63
+ isAllCaps: !!properties.isAllCaps,
64
+ isSmallCaps: !!properties.isSmallCaps,
65
+ verticalAlignment: properties.verticalAlignment || verticalAlignment.baseline,
66
+ font: properties.font || null,
67
+ fontSize: properties.fontSize || null,
68
+ highlight: properties.highlight || null
69
+ };
70
+ }
71
+
72
+ var verticalAlignment = {
73
+ baseline: "baseline",
74
+ superscript: "superscript",
75
+ subscript: "subscript"
76
+ };
77
+
78
+ function Text(value) {
79
+ return {
80
+ type: types.text,
81
+ value: value
82
+ };
83
+ }
84
+
85
+ function Tab() {
86
+ return {
87
+ type: types.tab
88
+ };
89
+ }
90
+
91
+ function Checkbox(options) {
92
+ return {
93
+ type: types.checkbox,
94
+ checked: options.checked
95
+ };
96
+ }
97
+
98
+ function Hyperlink(children, options) {
99
+ return {
100
+ type: types.hyperlink,
101
+ children: children,
102
+ href: options.href,
103
+ anchor: options.anchor,
104
+ targetFrame: options.targetFrame
105
+ };
106
+ }
107
+
108
+ function NoteReference(options) {
109
+ return {
110
+ type: types.noteReference,
111
+ noteType: options.noteType,
112
+ noteId: options.noteId
113
+ };
114
+ }
115
+
116
+ function Notes(notes) {
117
+ this._notes = _.indexBy(notes, function(note) {
118
+ return noteKey(note.noteType, note.noteId);
119
+ });
120
+ }
121
+
122
+ Notes.prototype.resolve = function(reference) {
123
+ return this.findNoteByKey(noteKey(reference.noteType, reference.noteId));
124
+ };
125
+
126
+ Notes.prototype.findNoteByKey = function(key) {
127
+ return this._notes[key] || null;
128
+ };
129
+
130
+ function Note(options) {
131
+ return {
132
+ type: types.note,
133
+ noteType: options.noteType,
134
+ noteId: options.noteId,
135
+ body: options.body
136
+ };
137
+ }
138
+
139
+ function commentReference(options) {
140
+ return {
141
+ type: types.commentReference,
142
+ commentId: options.commentId
143
+ };
144
+ }
145
+
146
+ function comment(options) {
147
+ return {
148
+ type: types.comment,
149
+ commentId: options.commentId,
150
+ body: options.body,
151
+ authorName: options.authorName,
152
+ authorInitials: options.authorInitials
153
+ };
154
+ }
155
+
156
+ function noteKey(noteType, id) {
157
+ return noteType + "-" + id;
158
+ }
159
+
160
+ function Image(options) {
161
+ return {
162
+ type: types.image,
163
+ // `read` is retained for backwards compatibility, but other read
164
+ // methods should be preferred.
165
+ read: function(encoding) {
166
+ if (encoding) {
167
+ return options.readImage(encoding);
168
+ } else {
169
+ return options.readImage().then(function(arrayBuffer) {
170
+ return Buffer.from(arrayBuffer);
171
+ });
172
+ }
173
+ },
174
+ readAsArrayBuffer: function() {
175
+ return options.readImage();
176
+ },
177
+ readAsBase64String: function() {
178
+ return options.readImage("base64");
179
+ },
180
+ readAsBuffer: function() {
181
+ return options.readImage().then(function(arrayBuffer) {
182
+ return Buffer.from(arrayBuffer);
183
+ });
184
+ },
185
+ altText: options.altText,
186
+ contentType: options.contentType
187
+ };
188
+ }
189
+
190
+ function Table(children, properties) {
191
+ properties = properties || {};
192
+ return {
193
+ type: types.table,
194
+ children: children,
195
+ styleId: properties.styleId || null,
196
+ styleName: properties.styleName || null
197
+ };
198
+ }
199
+
200
+ function TableRow(children, options) {
201
+ options = options || {};
202
+ return {
203
+ type: types.tableRow,
204
+ children: children,
205
+ isHeader: options.isHeader || false
206
+ };
207
+ }
208
+
209
+ function TableCell(children, options) {
210
+ options = options || {};
211
+ return {
212
+ type: types.tableCell,
213
+ children: children,
214
+ colSpan: options.colSpan == null ? 1 : options.colSpan,
215
+ rowSpan: options.rowSpan == null ? 1 : options.rowSpan
216
+ };
217
+ }
218
+
219
+ function Break(breakType) {
220
+ return {
221
+ type: types["break"],
222
+ breakType: breakType
223
+ };
224
+ }
225
+
226
+ function BookmarkStart(options) {
227
+ return {
228
+ type: types.bookmarkStart,
229
+ name: options.name
230
+ };
231
+ }
232
+
233
+ exports.document = exports.Document = Document;
234
+ exports.paragraph = exports.Paragraph = Paragraph;
235
+ exports.run = exports.Run = Run;
236
+ exports.text = exports.Text = Text;
237
+ exports.tab = exports.Tab = Tab;
238
+ exports.checkbox = exports.Checkbox = Checkbox;
239
+ exports.Hyperlink = Hyperlink;
240
+ exports.noteReference = exports.NoteReference = NoteReference;
241
+ exports.Notes = Notes;
242
+ exports.Note = Note;
243
+ exports.commentReference = commentReference;
244
+ exports.comment = comment;
245
+ exports.Image = Image;
246
+ exports.Table = Table;
247
+ exports.TableRow = TableRow;
248
+ exports.TableCell = TableCell;
249
+ exports.lineBreak = Break("line");
250
+ exports.pageBreak = Break("page");
251
+ exports.columnBreak = Break("column");
252
+ exports.BookmarkStart = BookmarkStart;
253
+
254
+ exports.verticalAlignment = verticalAlignment;