mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
5189f5e640
no issue - the begin/end comments are only really useful when wrapping free-form content cards such as html and markdown, the rest all have specific elements and classes that can be used in parsers - made the comment wrappers optional in the `render()` function created by the `createCard()` factory - opted into comment wrappers for the html and markdown cards
32 lines
941 B
JavaScript
32 lines
941 B
JavaScript
module.exports = function createCard(card) {
|
|
const {name, type, config = {}} = card;
|
|
|
|
return {
|
|
name,
|
|
type,
|
|
render({env, payload, options}) {
|
|
const {dom} = env;
|
|
const cleanName = name.replace(/^card-/, '');
|
|
|
|
const cardOutput = card.render({env, payload, options});
|
|
|
|
if (!cardOutput) {
|
|
return cardOutput;
|
|
}
|
|
|
|
if (config.commentWrapper) {
|
|
const beginComment = dom.createComment(`kg-card-begin: ${cleanName}`);
|
|
const endComment = dom.createComment(`kg-card-end: ${cleanName}`);
|
|
const fragment = dom.createDocumentFragment();
|
|
|
|
fragment.appendChild(beginComment);
|
|
fragment.appendChild(cardOutput);
|
|
fragment.appendChild(endComment);
|
|
|
|
return fragment;
|
|
}
|
|
|
|
return cardOutput;
|
|
}
|
|
};
|
|
};
|