diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-04-02 17:14:31 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-04-02 17:14:31 +0100 |
| commit | 6a4cc9231f219c0047272c56081f881eab800d74 (patch) | |
| tree | a9631dfa47eb3db6a7060255e8b3042f3255756f /README.md | |
| parent | 3afd698984f9ec3fcb9b16e5d6c12ea4a23dfb53 (diff) | |
Rename images.inline to images.imgElement
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 24 |
1 files changed, 13 insertions, 11 deletions
@@ -212,10 +212,10 @@ For instance, the following would replicate the default behaviour: ```javascript var options = { - convertImage: mammoth.images.inline(function(element) { - return element.read("base64").then(function(imageBuffer) { + convertImage: mammoth.images.imgElement(function(image) { + return image.read("base64").then(function(imageBuffer) { return { - src: "data:" + element.contentType + ";base64," + imageBuffer + src: "data:" + image.contentType + ";base64," + imageBuffer }; }); }) @@ -459,9 +459,9 @@ Each message has the following properties: #### Image converters -An inline image converter can be created by calling `mammoth.images.inline(func)`. -This creates an inline `<img>` element for each image in the original docx. -`func` should be a function that has one argument called `element`. +An image converter can be created by calling `mammoth.images.imgElement(func)`. +This creates an `<img>` element for each image in the original docx. +`func` should be a function that has one argument `image`. This argument is the image element being converted, and has the following properties: @@ -470,16 +470,18 @@ and has the following properties: * `contentType`: the content type of the image, such as `image/png`. -`func` should return an object (or a promise containing an object) with a `src` property, -which will be used as the `src` attribute on the `<img>` element. +`func` should return an object (or a promise of an object) of attributes for the `<img>` element. +At a minimum, this should include the `src` attribute. +If any alt text is found for the image, +this will be automatically added to the element's attributes. For instance, the following replicates the default image conversion: ```javascript -mammoth.images.inline(function(element) { - return element.read("base64").then(function(imageBuffer) { +mammoth.images.imgElement(function(image) { + return image.read("base64").then(function(imageBuffer) { return { - src: "data:" + element.contentType + ";base64," + imageBuffer + src: "data:" + image.contentType + ";base64," + imageBuffer }; }); }) |
