mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
990ecec873
* Added caption support to code card renderer refs https://github.com/TryGhost/Ghost-Admin/pull/1181 - when a caption for a code card is provided, render the contents inside a `<figure>` element with a `<figcaption class="kg-card kg-code-card">` to match other caption-enabled cards
38 lines
1 KiB
JavaScript
38 lines
1 KiB
JavaScript
const createCard = require('../create-card');
|
|
|
|
module.exports = createCard({
|
|
name: 'code',
|
|
type: 'dom',
|
|
render(opts) {
|
|
let payload = opts.payload;
|
|
let dom = opts.env.dom;
|
|
|
|
if (!payload.code) {
|
|
return '';
|
|
}
|
|
|
|
let pre = dom.createElement('pre');
|
|
let code = dom.createElement('code');
|
|
|
|
if (payload.language) {
|
|
code.setAttribute('class', `language-${payload.language}`);
|
|
}
|
|
|
|
code.appendChild(dom.createTextNode(payload.code));
|
|
pre.appendChild(code);
|
|
|
|
if (payload.caption) {
|
|
let figure = dom.createElement('figure');
|
|
figure.setAttribute('class', 'kg-card kg-code-card');
|
|
figure.appendChild(pre);
|
|
|
|
let figcaption = dom.createElement('figcaption');
|
|
figcaption.appendChild(dom.createRawHTMLSection(payload.caption));
|
|
figure.appendChild(figcaption);
|
|
|
|
return figure;
|
|
} else {
|
|
return pre;
|
|
}
|
|
}
|
|
});
|