mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
no issue - adds abolsute->relative and relative->absolute transformer methods to card definitions - allows for each card to tailor it's transformation to the specific needs of it's payload so that the `mobiledoc` field can be transformed successfully during API serialization/deserialization
48 lines
1.4 KiB
JavaScript
48 lines
1.4 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;
|
|
}
|
|
},
|
|
|
|
absoluteToRelative(urlUtils, payload, options) {
|
|
payload.caption = payload.caption && urlUtils.htmlAbsoluteToRelative(payload.caption, options);
|
|
return payload;
|
|
},
|
|
|
|
relativeToAbsolute(urlUtils, payload, options) {
|
|
payload.caption = payload.caption && urlUtils.htmlRelativeToAbsolute(payload.caption, options);
|
|
return payload;
|
|
}
|
|
});
|