diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-06-08 22:22:54 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-06-08 22:22:54 +0100 |
| commit | 3ddcb6b5aa1a4502ff60fecc0e38041efa41a20e (patch) | |
| tree | a27964927b79b8964af274e864b3400f4a336482 | |
| parent | aac54dca5f6b96788ae9c045cb64534ab7b598ad (diff) | |
Ignore styles that aren't paragraph or character
| -rw-r--r-- | lib/docx/styles-reader.js | 11 | ||||
| -rw-r--r-- | tests/docx/styles-reader.tests.js | 9 |
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/docx/styles-reader.js b/lib/docx/styles-reader.js index d38c510..dc90bc1 100644 --- a/lib/docx/styles-reader.js +++ b/lib/docx/styles-reader.js @@ -17,10 +17,17 @@ function readStylesXml(xml) { var paragraphStyles = {}; var characterStyles = {}; + var styles = { + "paragraph": paragraphStyles, + "character": characterStyles + }; + xml.root.getElementsByTagName("w:style").forEach(function(styleElement) { var style = readStyleElement(styleElement); - var styleSet = style.type === "paragraph" ? paragraphStyles : characterStyles; - styleSet[style.styleId] = style; + var styleSet = styles[style.type]; + if (styleSet) { + styleSet[style.styleId] = style; + } }); return new Styles(paragraphStyles, characterStyles); diff --git a/tests/docx/styles-reader.tests.js b/tests/docx/styles-reader.tests.js index 6dfdcd2..2c07913 100644 --- a/tests/docx/styles-reader.tests.js +++ b/tests/docx/styles-reader.tests.js @@ -44,6 +44,15 @@ describe('readStylesXml', function() { assert.equal(styles.findParagraphStyleById("Heading1Char"), null); }); + test('character and table styles are distinct', function() { + var styles = readStylesXml({ + root: new XmlElement("w:styles", {}, [ + styleElement("table", "Heading1", "Heading 1"), + ]) + }); + assert.equal(styles.findCharacterStyleById("Heading1"), null); + }); + test('styles include names', function() { var styles = readStylesXml({ root: new XmlElement("w:styles", {}, [ |
