diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docx/document-xml-reader.js | 2 | ||||
| -rw-r--r-- | lib/xmlreader.js | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/docx/document-xml-reader.js b/lib/docx/document-xml-reader.js index a23aa5f..15a2dae 100644 --- a/lib/docx/document-xml-reader.js +++ b/lib/docx/document-xml-reader.js @@ -104,7 +104,7 @@ function DocumentXmlReader(relationships, contentTypes, docxFile, numbering) { return new Result(properties); }, "w:t": function(element) { - return new Result(new documents.Text(element.children[0].value)); + return new Result(new documents.Text(element.text())); }, "w:tab": function(element) { return new Result(new documents.Tab()); diff --git a/lib/xmlreader.js b/lib/xmlreader.js index 51f24a7..f219d2b 100644 --- a/lib/xmlreader.js +++ b/lib/xmlreader.js @@ -105,6 +105,15 @@ Element.prototype.getElementsByTagName = function(name) { return toElementList(elements); }; +Element.prototype.text = function() { + if (this.children.length === 0) { + return ""; + } else if (this.children.length !== 1 || this.children[0].type !== "text") { + throw new Error("Not implemented"); + } + return this.children[0].value; +}; + var elementListPrototype = { getElementsByTagName: function(name) { return toElementList(_.flatten(this.map(function(element) { |
