diff --git a/core/server/lib/mobiledoc/cards/image.js b/core/server/lib/mobiledoc/cards/image.js index ab931e8671..308fc7bcba 100644 --- a/core/server/lib/mobiledoc/cards/image.js +++ b/core/server/lib/mobiledoc/cards/image.js @@ -20,6 +20,9 @@ module.exports = { let img = dom.createElement('img'); img.setAttribute('src', payload.src); img.setAttribute('class', 'kg-image'); + if (payload.alt) { + img.setAttribute('alt', payload.alt); + } figure.appendChild(img); diff --git a/core/test/unit/lib/mobiledoc/cards/image_spec.js b/core/test/unit/lib/mobiledoc/cards/image_spec.js index fe59bf29b3..7bd3b6f6c0 100644 --- a/core/test/unit/lib/mobiledoc/cards/image_spec.js +++ b/core/test/unit/lib/mobiledoc/cards/image_spec.js @@ -31,6 +31,20 @@ describe('Image card', function () { serializer.serialize(card.render(opts)).should.eql('
Test caption
'); }); + it('renders an image with alt text', function () { + let opts = { + env: { + dom: new SimpleDom.Document() + }, + payload: { + src: 'https://www.ghost.org/image.png', + alt: 'example image' + } + }; + + serializer.serialize(card.render(opts)).should.eql('
example image
'); + }); + it('renders nothing with no src', function () { let opts = { env: {