diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-06-11 14:30:32 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-06-11 14:30:32 +0100 |
| commit | 48108d291a5b158ca6e4f4d830e832c116fd997e (patch) | |
| tree | bf00c0eb8dd3d95998979b8f6bfb1a64043174be | |
| parent | 1b34a534ed15dab39e6805f29526a01f0394eea4 (diff) | |
Ignore footnote separators
| -rw-r--r-- | lib/docx/footnotes-reader.js | 9 | ||||
| -rw-r--r-- | tests/docx/footnotes-reader.tests.js | 16 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/docx/footnotes-reader.js b/lib/docx/footnotes-reader.js index a653b8a..33bca14 100644 --- a/lib/docx/footnotes-reader.js +++ b/lib/docx/footnotes-reader.js @@ -3,7 +3,14 @@ exports.readFootnotesXml = readFootnotesXml; var Footnotes = require("../documents").Footnotes; function readFootnotesXml(xml) { - return xml.root.getElementsByTagName("w:footnote").map(readFootnoteElement); + return xml.root.getElementsByTagName("w:footnote") + .filter(isFootnoteElement) + .map(readFootnoteElement); +} + +function isFootnoteElement(element) { + var type = element.attributes["w:type"]; + return type !== "continuationSeparator" && type !== "separator"; } function readFootnoteElement(footnoteElement) { diff --git a/tests/docx/footnotes-reader.tests.js b/tests/docx/footnotes-reader.tests.js index 512f477..529937d 100644 --- a/tests/docx/footnotes-reader.tests.js +++ b/tests/docx/footnotes-reader.tests.js @@ -20,3 +20,19 @@ describe('readFootnotesXml', function() { assert.deepEqual(footnotes[0].id, "1"); }); }); + +footnoteTypeIsIgnored('continuationSeparator'); +footnoteTypeIsIgnored('separator'); + +function footnoteTypeIsIgnored(type) { + describe('footnotes of type ' + type + ' are ignored', function() { + test('ID and body of footnote are read', function() { + var footnotes = readFootnotesXml({ + root: new XmlElement("w:footnotes", {}, [ + new XmlElement("w:footnote", {"w:id": "1", "w:type": type}, []) + ]) + }); + assert.equal(footnotes.length, 0); + }); + }); +} |
