@hyperlex/mammoth 1.4.9-beta
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.
- package/.eslintrc.json +77 -0
- package/.github/ISSUE_TEMPLATE.md +12 -0
- package/.idea/mammoth.js.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.travis.yml +10 -0
- package/LICENSE +22 -0
- package/NEWS +373 -0
- package/README.md +883 -0
- package/bin/mammoth +38 -0
- package/browser/docx/files.js +14 -0
- package/browser/unzip.js +12 -0
- package/lib/document-to-html.js +453 -0
- package/lib/documents.js +238 -0
- package/lib/docx/body-reader.js +636 -0
- package/lib/docx/comments-reader.js +31 -0
- package/lib/docx/content-types-reader.js +58 -0
- package/lib/docx/document-xml-reader.js +26 -0
- package/lib/docx/docx-reader.js +222 -0
- package/lib/docx/files.js +67 -0
- package/lib/docx/notes-reader.js +28 -0
- package/lib/docx/numbering-xml.js +69 -0
- package/lib/docx/office-xml-reader.js +58 -0
- package/lib/docx/relationships-reader.js +43 -0
- package/lib/docx/style-map.js +75 -0
- package/lib/docx/styles-reader.js +70 -0
- package/lib/docx/uris.js +21 -0
- package/lib/html/ast.js +50 -0
- package/lib/html/index.js +41 -0
- package/lib/html/simplify.js +88 -0
- package/lib/images.js +29 -0
- package/lib/index.js +115 -0
- package/lib/main.js +63 -0
- package/lib/options-reader.js +98 -0
- package/lib/promises.js +42 -0
- package/lib/results.js +72 -0
- package/lib/style-reader.js +321 -0
- package/lib/styles/document-matchers.js +74 -0
- package/lib/styles/html-paths.js +81 -0
- package/lib/styles/parser/tokeniser.js +30 -0
- package/lib/transforms.js +61 -0
- package/lib/underline.js +11 -0
- package/lib/unzip.js +22 -0
- package/lib/writers/html-writer.js +160 -0
- package/lib/writers/index.js +14 -0
- package/lib/writers/markdown-writer.js +163 -0
- package/lib/xml/index.js +7 -0
- package/lib/xml/nodes.js +69 -0
- package/lib/xml/reader.js +83 -0
- package/lib/xml/writer.js +61 -0
- package/lib/zipfile.js +77 -0
- package/mammoth.browser.js +32950 -0
- package/mammoth.browser.min.js +18 -0
- package/package.json +65 -0
- package/test/.eslintrc.json +7 -0
- package/test/document-to-html.tests.js +834 -0
- package/test/docx/body-reader.tests.js +1342 -0
- package/test/docx/comments-reader.tests.js +52 -0
- package/test/docx/content-types-reader.tests.js +45 -0
- package/test/docx/document-matchers.js +37 -0
- package/test/docx/docx-reader.tests.js +179 -0
- package/test/docx/files.tests.js +94 -0
- package/test/docx/notes-reader.tests.js +35 -0
- package/test/docx/numbering-xml.tests.js +65 -0
- package/test/docx/office-xml-reader.tests.js +24 -0
- package/test/docx/relationships-reader.tests.js +65 -0
- package/test/docx/style-map.tests.js +112 -0
- package/test/docx/styles-reader.tests.js +133 -0
- package/test/docx/uris.tests.js +22 -0
- package/test/html/simplify.tests.js +134 -0
- package/test/html/write.tests.js +42 -0
- package/test/images.tests.js +34 -0
- package/test/main.tests.js +89 -0
- package/test/mammoth.tests.js +429 -0
- package/test/mocha.opts +1 -0
- package/test/options-reader.tests.js +63 -0
- package/test/results.tests.js +15 -0
- package/test/style-reader.tests.js +256 -0
- package/test/styles/document-matchers.tests.js +71 -0
- package/test/styles/html-paths.tests.js +20 -0
- package/test/styles/parser/tokeniser.tests.js +104 -0
- package/test/test-data/comments.docx +0 -0
- package/test/test-data/embedded-style-map.docx +0 -0
- package/test/test-data/empty.docx +0 -0
- package/test/test-data/empty.zip +0 -0
- package/test/test-data/endnotes.docx +0 -0
- package/test/test-data/external-picture.docx +0 -0
- package/test/test-data/footnote-hyperlink.docx +0 -0
- package/test/test-data/footnotes.docx +0 -0
- package/test/test-data/hello.zip +0 -0
- package/test/test-data/hyperlinks/word/_rels/document.xml.rels +10 -0
- package/test/test-data/hyperlinks/word/document.xml +18 -0
- package/test/test-data/simple/word/document.xml +18 -0
- package/test/test-data/simple-list.docx +0 -0
- package/test/test-data/single-paragraph.docx +0 -0
- package/test/test-data/strikethrough.docx +0 -0
- package/test/test-data/tables.docx +0 -0
- package/test/test-data/text-box.docx +0 -0
- package/test/test-data/tiny-picture-target-base-relative.docx +0 -0
- package/test/test-data/tiny-picture.docx +0 -0
- package/test/test-data/tiny-picture.png +0 -0
- package/test/test-data/underline.docx +0 -0
- package/test/test-data/utf8-bom.docx +0 -0
- package/test/test.js +11 -0
- package/test/testing.js +55 -0
- package/test/transforms.tests.js +125 -0
- package/test/unzip.tests.js +38 -0
- package/test/writers/html-writer.tests.js +133 -0
- package/test/writers/markdown-writer.tests.js +304 -0
- package/test/xml/reader.tests.js +85 -0
- package/test/xml/writer.tests.js +81 -0
- package/test/zipfile.tests.js +59 -0
package/lib/documents.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
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
|
+
hyperlink: "hyperlink",
|
|
10
|
+
noteReference: "noteReference",
|
|
11
|
+
image: "image",
|
|
12
|
+
note: "note",
|
|
13
|
+
commentReference: "commentReference",
|
|
14
|
+
comment: "comment",
|
|
15
|
+
table: "table",
|
|
16
|
+
tableRow: "tableRow",
|
|
17
|
+
tableCell: "tableCell",
|
|
18
|
+
"break": "break",
|
|
19
|
+
bookmarkStart: "bookmarkStart"
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function Document(children, options) {
|
|
23
|
+
options = options || {};
|
|
24
|
+
return {
|
|
25
|
+
type: types.document,
|
|
26
|
+
children: children,
|
|
27
|
+
notes: options.notes || new Notes({}),
|
|
28
|
+
comments: options.comments || []
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function Paragraph(children, properties) {
|
|
33
|
+
properties = properties || {};
|
|
34
|
+
var indent = properties.indent || {};
|
|
35
|
+
var spacing = properties.spacing || {};
|
|
36
|
+
var border = properties.border || {};
|
|
37
|
+
return {
|
|
38
|
+
type: types.paragraph,
|
|
39
|
+
children: children,
|
|
40
|
+
styleId: properties.styleId || null,
|
|
41
|
+
styleName: properties.styleName || null,
|
|
42
|
+
numbering: properties.numbering || null,
|
|
43
|
+
alignment: properties.alignment || null,
|
|
44
|
+
indent: {
|
|
45
|
+
start: indent.start || null,
|
|
46
|
+
end: indent.end || null,
|
|
47
|
+
firstLine: indent.firstLine || null,
|
|
48
|
+
hanging: indent.hanging || null
|
|
49
|
+
},
|
|
50
|
+
spacing: {
|
|
51
|
+
lineRule: spacing.lineRule || null,
|
|
52
|
+
line: spacing.line || null,
|
|
53
|
+
before: spacing.before || null,
|
|
54
|
+
after: spacing.after || null
|
|
55
|
+
},
|
|
56
|
+
border: {
|
|
57
|
+
top: border.top || null,
|
|
58
|
+
left: border.left || null,
|
|
59
|
+
bottom: border.bottom || null,
|
|
60
|
+
right: border.right || null
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function Run(children, properties) {
|
|
66
|
+
properties = properties || {};
|
|
67
|
+
return {
|
|
68
|
+
type: types.run,
|
|
69
|
+
children: children,
|
|
70
|
+
styleId: properties.styleId || null,
|
|
71
|
+
styleName: properties.styleName || null,
|
|
72
|
+
isBold: properties.isBold,
|
|
73
|
+
isUnderline: properties.isUnderline,
|
|
74
|
+
isItalic: properties.isItalic,
|
|
75
|
+
isStrikethrough: properties.isStrikethrough,
|
|
76
|
+
isSmallCaps: properties.isSmallCaps,
|
|
77
|
+
verticalAlignment: properties.verticalAlignment || verticalAlignment.baseline,
|
|
78
|
+
font: properties.font || null,
|
|
79
|
+
size: properties.size || null,
|
|
80
|
+
color: properties.color || null,
|
|
81
|
+
highlight: properties.highlight || null
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
var verticalAlignment = {
|
|
86
|
+
baseline: "baseline",
|
|
87
|
+
superscript: "superscript",
|
|
88
|
+
subscript: "subscript"
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
function Text(value) {
|
|
92
|
+
return {
|
|
93
|
+
type: types.text,
|
|
94
|
+
value: value
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function Tab() {
|
|
99
|
+
return {
|
|
100
|
+
type: types.tab
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function Hyperlink(children, options) {
|
|
105
|
+
return {
|
|
106
|
+
type: types.hyperlink,
|
|
107
|
+
children: children,
|
|
108
|
+
href: options.href,
|
|
109
|
+
anchor: options.anchor,
|
|
110
|
+
targetFrame: options.targetFrame
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function NoteReference(options) {
|
|
115
|
+
return {
|
|
116
|
+
type: types.noteReference,
|
|
117
|
+
noteType: options.noteType,
|
|
118
|
+
noteId: options.noteId
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function Notes(notes) {
|
|
123
|
+
this._notes = _.indexBy(notes, function(note) {
|
|
124
|
+
return noteKey(note.noteType, note.noteId);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
Notes.prototype.resolve = function(reference) {
|
|
129
|
+
return this.findNoteByKey(noteKey(reference.noteType, reference.noteId));
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
Notes.prototype.findNoteByKey = function(key) {
|
|
133
|
+
return this._notes[key] || null;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
function Note(options) {
|
|
137
|
+
return {
|
|
138
|
+
type: types.note,
|
|
139
|
+
noteType: options.noteType,
|
|
140
|
+
noteId: options.noteId,
|
|
141
|
+
body: options.body
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function commentReference(options) {
|
|
146
|
+
return {
|
|
147
|
+
type: types.commentReference,
|
|
148
|
+
commentId: options.commentId
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function comment(options) {
|
|
153
|
+
return {
|
|
154
|
+
type: types.comment,
|
|
155
|
+
commentId: options.commentId,
|
|
156
|
+
body: options.body,
|
|
157
|
+
authorName: options.authorName,
|
|
158
|
+
authorInitials: options.authorInitials
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function noteKey(noteType, id) {
|
|
163
|
+
return noteType + "-" + id;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function Image(options) {
|
|
167
|
+
return {
|
|
168
|
+
type: types.image,
|
|
169
|
+
read: options.readImage,
|
|
170
|
+
altText: options.altText,
|
|
171
|
+
contentType: options.contentType
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function Table(children, properties) {
|
|
176
|
+
properties = properties || {};
|
|
177
|
+
return {
|
|
178
|
+
type: types.table,
|
|
179
|
+
children: children,
|
|
180
|
+
styleId: properties.styleId || null,
|
|
181
|
+
styleName: properties.styleName || null
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function TableRow(children, options) {
|
|
186
|
+
options = options || {};
|
|
187
|
+
return {
|
|
188
|
+
type: types.tableRow,
|
|
189
|
+
children: children,
|
|
190
|
+
isHeader: options.isHeader || false
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function TableCell(children, options) {
|
|
195
|
+
options = options || {};
|
|
196
|
+
return {
|
|
197
|
+
type: types.tableCell,
|
|
198
|
+
children: children,
|
|
199
|
+
colSpan: options.colSpan == null ? 1 : options.colSpan,
|
|
200
|
+
rowSpan: options.rowSpan == null ? 1 : options.rowSpan
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function Break(breakType) {
|
|
205
|
+
return {
|
|
206
|
+
type: types["break"],
|
|
207
|
+
breakType: breakType
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function BookmarkStart(options) {
|
|
212
|
+
return {
|
|
213
|
+
type: types.bookmarkStart,
|
|
214
|
+
name: options.name
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
exports.document = exports.Document = Document;
|
|
219
|
+
exports.paragraph = exports.Paragraph = Paragraph;
|
|
220
|
+
exports.run = exports.Run = Run;
|
|
221
|
+
exports.Text = Text;
|
|
222
|
+
exports.tab = exports.Tab = Tab;
|
|
223
|
+
exports.Hyperlink = Hyperlink;
|
|
224
|
+
exports.noteReference = exports.NoteReference = NoteReference;
|
|
225
|
+
exports.Notes = Notes;
|
|
226
|
+
exports.Note = Note;
|
|
227
|
+
exports.commentReference = commentReference;
|
|
228
|
+
exports.comment = comment;
|
|
229
|
+
exports.Image = Image;
|
|
230
|
+
exports.Table = Table;
|
|
231
|
+
exports.TableRow = TableRow;
|
|
232
|
+
exports.TableCell = TableCell;
|
|
233
|
+
exports.lineBreak = Break("line");
|
|
234
|
+
exports.pageBreak = Break("page");
|
|
235
|
+
exports.columnBreak = Break("column");
|
|
236
|
+
exports.BookmarkStart = BookmarkStart;
|
|
237
|
+
|
|
238
|
+
exports.verticalAlignment = verticalAlignment;
|