Ghost/core/server/lib/mobiledoc/cards/code.js
Kevin Ansfield f54db75ed1 Koenig - Code card server-side rendering
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
2018-05-15 16:27:34 +01:00

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