From 5b80ec44ab11c8161866b3ef00402185dacd22a0 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 30 Jul 2018 10:10:11 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Koenig=20-=20Fixed=20missing=20`?= =?UTF-8?q?alt`=20text=20on=20images?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs https://github.com/TryGhost/Ghost/issues/9724 - render `alt` attribute if the image card payload has an `alt` property --- core/server/lib/mobiledoc/cards/image.js | 3 +++ core/test/unit/lib/mobiledoc/cards/image_spec.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+) 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: {