From 53804571b26abb1d020a4fc6a05be546c787b30a Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 4 Feb 2016 08:20:54 +0000 Subject: Handle missing paragraph styles in the source document --- lib/docx/body-reader.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') 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) -- cgit v1.2.3