Koenig - Render image `title` attribute if present

refs https://github.com/TryGhost/Ghost/issues/9724
- `<img>` elements can have both `alt ` and `title` attributes, ensure we render both of them
This commit is contained in:
Kevin Ansfield 2018-08-13 09:48:04 +01:00
parent cfd9ff3993
commit 66fb0955a4
2 changed files with 17 additions and 0 deletions

View File

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

View File

@ -45,6 +45,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" alt="example image"></figure>');
});
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('<figure class="kg-image-card"><img src="https://www.ghost.org/image.png" class="kg-image" title="example image"></figure>');
});
it('renders nothing with no src', function () {
let opts = {
env: {