diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-02-04 08:20:54 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-02-04 13:34:16 +0000 |
| commit | 53804571b26abb1d020a4fc6a05be546c787b30a (patch) | |
| tree | 4b278eee9e4e5e03ec5f22e3f380c7acbf32041f /lib | |
| parent | b7c2373a32a64050986288a2eb68c4fd69f7e7eb (diff) | |
Handle missing paragraph styles in the source document
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docx/body-reader.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index 618474e..ecf3e12 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -95,6 +95,7 @@ function BodyReader(options) { var properties = { type: "paragraphProperties" }; + var messages = []; var styleElement = element.first("w:pStyle"); if (styleElement) { @@ -102,7 +103,12 @@ function BodyReader(options) { properties.styleId = styleId; if (styleId) { var style = styles.findParagraphStyleById(styleId); - properties.styleName = style.name; + if (style) { + properties.styleName = style.name; + } else { + messages.push(warning( + "Style with ID " + styleId + " was referenced but not defined in the document")); + } } } var alignElement = element.first("w:jc"); @@ -111,7 +117,7 @@ function BodyReader(options) { } properties.numbering = readNumberingProperties(element.firstOrEmpty("w:numPr")); - return elementResult(properties); + return elementResultWithMessages(properties, messages); }, "w:r": function(element) { return readXmlElements(element.children) |
