0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Koenig - Convert <pre><code> to code card

refs https://github.com/TryGhost/Ghost/issues/9623
- add parser plugin to match a `<pre>` with a nested `<code>` as it's first child and transform it into a code card
This commit is contained in:
Kevin Ansfield 2018-05-18 14:06:35 +01:00
parent fb226ac956
commit 631edbe60a

View file

@ -42,9 +42,25 @@ export function hrToCard(node, builder, {addSection, nodeFinished}) {
nodeFinished();
}
export function preCodeToCard(node, builder, {addSection, nodeFinished}) {
if (node.nodeType !== 1 || node.tagName !== 'PRE') {
return;
}
let [codeElement] = node.children;
if (codeElement && codeElement.tagName === 'CODE') {
let payload = {code: codeElement.textContent};
let cardSection = builder.createCardSection('code', payload);
addSection(cardSection);
nodeFinished();
}
}
export default [
brToSoftBreakAtom,
removeLeadingNewline,
imgToCard,
hrToCard
hrToCard,
preCodeToCard
];