From 66fb0955a4134f7e6962a0a2ade831d9d56d676f Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 13 Aug 2018 09:48:04 +0100 Subject: [PATCH] Koenig - Render image `title` attribute if present refs https://github.com/TryGhost/Ghost/issues/9724 - `` elements can have both `alt ` and `title` attributes, ensure we render both of them --- 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 e8c3ecf5ee..316411f0ae 100644 --- a/core/server/lib/mobiledoc/cards/image.js +++ b/core/server/lib/mobiledoc/cards/image.js @@ -23,6 +23,9 @@ module.exports = { if (payload.alt) { img.setAttribute('alt', payload.alt); } + if (payload.title) { + img.setAttribute('title', payload.title); + } 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 627db0b3a0..3b9d08ba93 100644 --- a/core/test/unit/lib/mobiledoc/cards/image_spec.js +++ b/core/test/unit/lib/mobiledoc/cards/image_spec.js @@ -45,6 +45,20 @@ describe('Image card', function () { serializer.serialize(card.render(opts)).should.eql('
example image
'); }); + it('renders an image with title attribute', function () { + let opts = { + env: { + dom: new SimpleDom.Document() + }, + payload: { + src: 'https://www.ghost.org/image.png', + title: 'example image' + } + }; + + serializer.serialize(card.render(opts)).should.eql('
'); + }); + it('renders nothing with no src', function () { let opts = { env: {