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:
parent
fb226ac956
commit
631edbe60a
1 changed files with 17 additions and 1 deletions
|
@ -42,9 +42,25 @@ export function hrToCard(node, builder, {addSection, nodeFinished}) {
|
||||||
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 [
|
export default [
|
||||||
brToSoftBreakAtom,
|
brToSoftBreakAtom,
|
||||||
removeLeadingNewline,
|
removeLeadingNewline,
|
||||||
imgToCard,
|
imgToCard,
|
||||||
hrToCard
|
hrToCard,
|
||||||
|
preCodeToCard
|
||||||
];
|
];
|
||||||
|
|
Loading…
Add table
Reference in a new issue