mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
refs https://github.com/TryGhost/Ghost/issues/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
37 lines
1 KiB
JavaScript
37 lines
1 KiB
JavaScript
module.exports = {
|
|
name: 'image',
|
|
type: 'dom',
|
|
render(opts) {
|
|
let payload = opts.payload;
|
|
// let version = opts.options.version;
|
|
let dom = opts.env.dom;
|
|
|
|
if (!payload.src) {
|
|
return '';
|
|
}
|
|
|
|
let figure = dom.createElement('figure');
|
|
let figureClass = 'kg-image-card';
|
|
if (payload.cardWidth) {
|
|
figureClass = `${figureClass} kg-width-${payload.cardWidth}`;
|
|
}
|
|
figure.setAttribute('class', figureClass);
|
|
|
|
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);
|
|
|
|
if (payload.caption) {
|
|
let figcaption = dom.createElement('figcaption');
|
|
figcaption.appendChild(dom.createRawHTMLSection(payload.caption));
|
|
figure.appendChild(figcaption);
|
|
}
|
|
|
|
return figure;
|
|
}
|
|
};
|