diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-03-30 22:26:18 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-03-30 22:26:18 +0000 |
| commit | 099c86ab5fabea429eb226fbff179f0317ec755c (patch) | |
| tree | 7d633240cc4c8de39da667bab1d9aaf6584a3701 /lib | |
| parent | c127f0d75175d2ab06682bac1bb22dcf31de2b81 (diff) | |
Read style names from paragraph properties
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docx-reader.js | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/docx-reader.js b/lib/docx-reader.js index 3078d2f..606c61b 100644 --- a/lib/docx-reader.js +++ b/lib/docx-reader.js @@ -53,7 +53,30 @@ function readXmlElement(element) { var xmlElementReaders = { "w:p": function(element) { var children = readXmlElements(element.children); - return new documents.Paragraph(children); + var properties; + var propertiesElement = _.find(children, isParagraphProperties); + if (propertiesElement) { + properties = propertiesElement.properties; + } + + return new documents.Paragraph( + children.filter(negate(isParagraphProperties)), + properties + ); + }, + "w:pPr": function(element) { + var properties = { + }; + + var styleElement = element.first("w:pStyle"); + if (styleElement) { + properties.styleName = styleElement.attributes["w:val"]; + } + + return { + type: "paragraphProperties", + properties: properties + }; }, "w:r": function(element) { var children = readXmlElements(element.children); @@ -72,3 +95,12 @@ function notNull(value) { return value !== null; } +function isParagraphProperties(element) { + return element.type === "paragraphProperties"; +} + +function negate(predicate) { + return function(value) { + return !predicate(value); + }; +} |
