Skip to content

Commit a86759c

Browse files
committed
Koenig - Added rich-text caption support
refs TryGhost/Ghost#9724 - captions can have HTML so we need to render as HTML rather than as a text node so special chars don't get escaped
1 parent 02f5606 commit a86759c

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

packages/kg-default-cards/lib/cards/embed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616

1717
if (payload.caption) {
1818
let figcaption = dom.createElement('figcaption');
19-
figcaption.appendChild(dom.createTextNode(payload.caption));
19+
figcaption.appendChild(dom.createRawHTMLSection(payload.caption));
2020
figure.appendChild(figcaption);
2121
}
2222

packages/kg-default-cards/lib/cards/image.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828

2929
if (payload.caption) {
3030
let figcaption = dom.createElement('figcaption');
31-
figcaption.appendChild(dom.createTextNode(payload.caption));
31+
figcaption.appendChild(dom.createRawHTMLSection(payload.caption));
3232
figure.appendChild(figcaption);
3333
}
3434

packages/kg-default-cards/test/cards/embed_spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ describe('Embed card', function () {
6363
},
6464
payload: {
6565
html: 'Testing',
66-
caption: 'Caption'
66+
caption: '<strong>Caption</strong>'
6767
}
6868
};
6969

70-
serializer.serialize(card.render(opts)).should.match('<figure class="kg-embed-card">Testing<figcaption>Caption</figcaption></figure>');
70+
serializer.serialize(card.render(opts)).should.match('<figure class="kg-embed-card">Testing<figcaption><strong>Caption</strong></figcaption></figure>');
7171
});
7272
});

packages/kg-default-cards/test/cards/image_spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ describe('Image card', function () {
2424
},
2525
payload: {
2626
src: 'https://www.ghost.org/image.png',
27-
caption: 'Test caption'
27+
caption: '<b>Test caption</b>'
2828
}
2929
};
3030

31-
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>');
31+
serializer.serialize(card.render(opts)).should.eql('<figure class="kg-image-card"><img src="https://www.ghost.org/image.png" class="kg-image"><figcaption><b>Test caption</b></figcaption></figure>');
3232
});
3333

3434
it('renders an image with alt text', function () {

0 commit comments

Comments
 (0)