mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-30 06:12:03 +03:00
4f9e687f62
no issue We're creating tooling to convert HTML to Ghost flavoured mobiledoc, however we have cards that allow arbitrary content without a wrapper element which means that we're unable to do a 1:1 mapping of mobiledoc->html->mobiledoc. To work around this problem we now output HTML comments before/after the output of each card so that our converter can extract card content correctly when parsing HTML. - added `createCard` method which wraps a card's `render()` method to add begin/end comments and updated all cards to use it - only takes affect for newly added or re-saved posts/pages
29 lines
813 B
JavaScript
29 lines
813 B
JavaScript
module.exports = function createCard(card) {
|
|
const {name, type} = 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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
};
|
|
};
|