Skip to content

Commit 66fb095

Browse files
committed
Koenig - Render image title attribute if present
refs #9724 - `<img>` elements can have both `alt ` and `title` attributes, ensure we render both of them
1 parent cfd9ff3 commit 66fb095

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

core/server/lib/mobiledoc/cards/image.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ module.exports = {
2323
if (payload.alt) {
2424
img.setAttribute('alt', payload.alt);
2525
}
26+
if (payload.title) {
27+
img.setAttribute('title', payload.title);
28+
}
2629

2730
figure.appendChild(img);
2831

core/test/unit/lib/mobiledoc/cards/image_spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ describe('Image card', function () {
4545
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>');
4646
});
4747

48+
it('renders an image with title attribute', function () {
49+
let opts = {
50+
env: {
51+
dom: new SimpleDom.Document()
52+
},
53+
payload: {
54+
src: 'https://www.ghost.org/image.png',
55+
title: 'example image'
56+
}
57+
};
58+
59+
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>');
60+
});
61+
4862
it('renders nothing with no src', function () {
4963
let opts = {
5064
env: {

0 commit comments

Comments
 (0)