diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-05-24 09:46:11 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-05-24 09:46:11 +0100 |
| commit | 963a9c2101a18803ddd8be195cecef70919cfa4d (patch) | |
| tree | 6f24df9c034d7713e70a516446bc3921faaa9ea2 | |
| parent | d0542bf7055343ff01fbe698ec25a117c4c5be36 (diff) | |
| parent | 60d6d9e584c44c3beae16110b6685a0a86bc38b4 (diff) | |
Merge remote-tracking branch 'jaceyshome/master'
| -rw-r--r-- | lib/docx/styles-reader.js | 7 | ||||
| -rw-r--r-- | tests/docx/styles-reader.tests.js | 16 |
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/docx/styles-reader.js b/lib/docx/styles-reader.js index dc90bc1..3419ac4 100644 --- a/lib/docx/styles-reader.js +++ b/lib/docx/styles-reader.js @@ -36,6 +36,11 @@ function readStylesXml(xml) { function readStyleElement(styleElement) { var type = styleElement.attributes["w:type"]; var styleId = styleElement.attributes["w:styleId"]; - var name = styleElement.first("w:name").attributes["w:val"]; + var name = styleName(styleElement); return {type: type, styleId: styleId, name: name}; } + +function styleName(styleElement) { + var nameElement = styleElement.first("w:name"); + return nameElement ? nameElement.attributes["w:val"] : null; +} diff --git a/tests/docx/styles-reader.tests.js b/tests/docx/styles-reader.tests.js index 7899b1b..73a9050 100644 --- a/tests/docx/styles-reader.tests.js +++ b/tests/docx/styles-reader.tests.js @@ -59,6 +59,18 @@ describe('readStylesXml', function() { }); assert.equal(styles.findParagraphStyleById("Heading1").name, "Heading 1"); }); + + test('style name is null if w:name element does not exist', function() { + var styles = readStylesXml({ + root: new XmlElement("w:styles", {}, [ + styleWithoutWNameElement("paragraph", "Heading1"), + styleWithoutWNameElement("character", "Heading1Char") + ]) + }); + assert.equal(styles.findParagraphStyleById("Heading1").name, null); + assert.equal(styles.findCharacterStyleById("Heading1Char").name, null); + }); + }); function paragraphStyleElement(id, name) { @@ -74,3 +86,7 @@ function styleElement(type, id, name) { new XmlElement("w:name", {"w:val": name}, []) ]); } + +function styleWithoutWNameElement(type, id) { + return new XmlElement("w:style", {"w:type": type, "w:styleId": id}, []); +} |
