aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-04-22 11:25:58 +0100
committerMichael Williamson <mike@zwobble.org>2014-04-22 11:25:58 +0100
commit7cad7ca1dcdf48ac826c54e33629bb961c7380dd (patch)
treed0b4005d2f05f7fe74d3cc9abd380100de615a6c /lib
parentea1c98fb4fc0aee93c194e6a90cf9b71326705af (diff)
Read styles from styles.xml
Diffstat (limited to 'lib')
-rw-r--r--lib/docx/styles-reader.js25
1 files changed, 25 insertions, 0 deletions
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};
+}