aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-04 08:28:03 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-04 13:34:16 +0000
commit8408269bfec3cd2f92e02075cb05ef1a4772402d (patch)
tree9697ff393175d9f966932a68c9cdf10e44faeb45 /lib
parent53804571b26abb1d020a4fc6a05be546c787b30a (diff)
Handle missing run styles in the source document
Diffstat (limited to 'lib')
-rw-r--r--lib/docx/body-reader.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js
index ecf3e12..3837d4a 100644
--- a/lib/docx/body-reader.js
+++ b/lib/docx/body-reader.js
@@ -37,8 +37,9 @@ function BodyReader(options) {
var properties = {
type: "runProperties"
};
+ var messages = [];
- readRunStyle(properties, element);
+ readRunStyle(properties, element, messages);
var verticalAlignmentElement = element.first("w:vertAlign");
if (verticalAlignmentElement) {
@@ -50,17 +51,21 @@ function BodyReader(options) {
properties.isItalic = !!element.first("w:i");
properties.isStrikethrough = !!element.first("w:strike");
- return elementResult(properties);
+ return elementResultWithMessages(properties, messages);
}
- function readRunStyle(properties, element) {
+ function readRunStyle(properties, element, messages) {
var styleElement = element.first("w:rStyle");
if (styleElement) {
var styleId = styleElement.attributes["w:val"];
properties.styleId = styleId;
if (styleId) {
var style = styles.findCharacterStyleById(styleId);
- properties.styleName = style.name;
+ if (style) {
+ properties.styleName = style.name;
+ } else {
+ messages.push(undefinedStyleWarning("Run", styleId));
+ }
}
}
}
@@ -106,8 +111,7 @@ function BodyReader(options) {
if (style) {
properties.styleName = style.name;
} else {
- messages.push(warning(
- "Style with ID " + styleId + " was referenced but not defined in the document"));
+ messages.push(undefinedStyleWarning("Paragraph", styleId));
}
}
}
@@ -269,6 +273,11 @@ function BodyReader(options) {
[] : warning("Image of type " + contentType + " is unlikely to display in web browsers");
return elementResultWithMessages(image, warnings);
}
+
+ function undefinedStyleWarning(type, styleId) {
+ return warning(
+ type + " style with ID " + styleId + " was referenced but not defined in the document");
+ }
}
var supportedImageTypes = {