mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
refs https://github.com/TryGhost/Ghost/issues/9724 - `<img>` elements can have both `alt ` and `title` attributes, ensure we render both of them
40 lines
1.1 KiB
JavaScript
40 lines
1.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);
|
|
}
|
|
if (payload.title) {
|
|
img.setAttribute('title', payload.title);
|
|
}
|
|
|
|
figure.appendChild(img);
|
|
|
|
if (payload.caption) {
|
|
let figcaption = dom.createElement('figcaption');
|
|
figcaption.appendChild(dom.createRawHTMLSection(payload.caption));
|
|
figure.appendChild(figcaption);
|
|
}
|
|
|
|
return figure;
|
|
}
|
|
};
|