From 7cad7ca1dcdf48ac826c54e33629bb961c7380dd Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 22 Apr 2014 11:25:58 +0100 Subject: Read styles from styles.xml --- lib/docx/styles-reader.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/docx/styles-reader.js (limited to 'lib') diff --git a/lib/docx/styles-reader.js b/lib/docx/styles-reader.js new file mode 100644 index 0000000..d896d3d --- /dev/null +++ b/lib/docx/styles-reader.js @@ -0,0 +1,25 @@ +exports.readStylesXml = readStylesXml; + +function Styles(paragraphStyles) { + return { + findParagraphStyleById: function(styleId) { + return paragraphStyles[styleId]; + } + }; +} + +function readStylesXml(xml) { + var paragraphStyles = []; + + xml.root.getElementsByTagName("w:style").forEach(function(styleElement) { + var style = readStyleElement(styleElement); + paragraphStyles[style.styleId] = style; + }); + + return new Styles(paragraphStyles); +} + +function readStyleElement(styleElement) { + var styleId = styleElement.attributes["w:styleId"]; + return {styleId: styleId}; +} -- cgit v1.2.3