🐛 Koenig - Fixed missing `alt` text on images

refs https://github.com/TryGhost/Ghost/issues/9724
- render `alt` attribute if the image card payload has an `alt` property
This commit is contained in:
Kevin Ansfield 2018-07-30 10:10:11 +01:00
parent a1723a687c
commit 5b80ec44ab
2 changed files with 17 additions and 0 deletions

View File

@ -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);

View File

@ -31,6 +31,20 @@ describe('Image card', function () {
serializer.serialize(card.render(opts)).should.eql('<figure class="kg-image-card"><img src="https://www.ghost.org/image.png" class="kg-image"><figcaption>Test caption</figcaption></figure>');
});
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('<figure class="kg-image-card"><img src="https://www.ghost.org/image.png" class="kg-image" alt="example image"></figure>');
});
it('renders nothing with no src', function () {
let opts = {
env: {