Ghost/core/server/lib/mobiledoc/cards/image.js
2018-08-31 11:05:47 +01:00

41 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-card 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;
}
};