diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-01-26 21:55:45 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-01-26 21:55:45 +0000 |
| commit | c4a3d3abcf89fcba9fda9b4bad4dcc666d205c34 (patch) | |
| tree | 09894f512008fddfbe50b82b489b374446731a86 /lib/docx/document-xml-reader.js | |
| parent | b688edfa6fa6c3407e70dd9723fbeb495d11ee8e (diff) | |
Warn on unsupported image types
Diffstat (limited to 'lib/docx/document-xml-reader.js')
| -rw-r--r-- | lib/docx/document-xml-reader.js | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/lib/docx/document-xml-reader.js b/lib/docx/document-xml-reader.js index 12016b0..e290792 100644 --- a/lib/docx/document-xml-reader.js +++ b/lib/docx/document-xml-reader.js @@ -215,23 +215,34 @@ function DocumentXmlReader(options) { .getElementsByTagName("pic:blipFill") .getElementsByTagName("a:blip"); - var results = blips.map(function(blip) { - var relationshipId = blip.attributes["r:embed"]; - var imagePath = joinZipPath("word", relationships[relationshipId].target); - var readImage = docxFile.read.bind(docxFile, imagePath); - var altText = element.first("wp:docPr").attributes.descr; - - var image = documents.Image({ - readImage: readImage, - altText: altText, - contentType: contentTypes.findContentType(imagePath) - }); - return new Result(image); - }); + return Result.combine(blips.map(readBlip.bind(null, element))); + } + + function readBlip(element, blip) { + var relationshipId = blip.attributes["r:embed"]; + var imagePath = joinZipPath("word", relationships[relationshipId].target); + var readImage = docxFile.read.bind(docxFile, imagePath); + var altText = element.first("wp:docPr").attributes.descr; + var contentType = contentTypes.findContentType(imagePath); - return Result.combine(results); + var image = documents.Image({ + readImage: readImage, + altText: altText, + contentType: contentType + }); + var warnings = supportedImageTypes[contentType] ? + [] : warning("Image of type " + contentType + " is unlikely to display in web browsers"); + return new Result(image, warnings); } } + +var supportedImageTypes = { + "image/png": true, + "image/gif": true, + "image/jpeg": true, + "image/svg+xml": true, + "image/tiff": true +}; var ignoreElements = { "w:bookmarkStart": true, |
