From 6b9aa0d1e370d2f982ed85882181e735fa4431d2 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 28 Apr 2013 12:52:24 +0100 Subject: Allow custom image to HTML conversion --- tests/document-to-html.tests.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js index c7b7bcf..65ce341 100644 --- a/tests/document-to-html.tests.js +++ b/tests/document-to-html.tests.js @@ -206,6 +206,27 @@ describe('DocumentConverter', function() { assert.equal(htmlImageElement.attributes.alt, "It's a hat"); }); }); + + test('can add custom handler for images', function() { + var imageBuffer = new Buffer("Not an image at all!"); + var image = new documents.Image({ + readImage: function(encoding) { + return q.when(imageBuffer.toString(encoding)); + }, + contentType: "image/png" + }); + var converter = new DocumentConverter({ + convertImage: function(element, html, messages, callback) { + element.read("utf8").then(function(altText) {; + html.selfClosing(htmlPaths.element("img", {alt: altText})); + callback(); + }); + } + }); + return converter.convertToHtml(image).then(function(result) { + assert.equal(result.value, 'Not an image at all!'); + }); + }); }); function paragraphOfText(text, styleName) { -- cgit v1.2.3