mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 02:44:33 +03:00
f54db75ed1
refs https://github.com/TryGhost/Ghost/issues/9623 - add support for `code` card that renders into `<pre><code>...</code></pre>` - render language class if one is provided
25 lines
532 B
JavaScript
25 lines
532 B
JavaScript
module.exports = {
|
|
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);
|
|
|
|
return pre;
|
|
}
|
|
};
|