Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated mobiledoc renderer to insert begin/end HTML comments around c…
…ards 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
- Loading branch information
1 parent
23d5480
commit 4f9e687
Showing
17 changed files
with
91 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
// this card is just an alias of the `markdown` card which is necessary because | ||
// our markdown-only editor was using the `card-markdown` card name | ||
const markdownCard = require('./markdown'); | ||
const createCard = require('../create-card'); | ||
|
||
module.exports = Object.assign({}, markdownCard, {name: 'card-markdown'}); | ||
module.exports = createCard( | ||
Object.assign({}, markdownCard, {name: 'card-markdown'}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
module.exports = { | ||
const createCard = require('../create-card'); | ||
|
||
module.exports = createCard({ | ||
name: 'hr', | ||
type: 'dom', | ||
render(opts) { | ||
return opts.env.dom.createElement('hr'); | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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; | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters