From 631edbe60a0a16de00da3e542e43b3083e001da7 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 18 May 2018 14:06:35 +0100 Subject: [PATCH] Koenig - Convert
 to code card

refs https://github.com/TryGhost/Ghost/issues/9623
- add parser plugin to match a `
` with a nested `` as it's first child and transform it into a code card
---
 .../addon/options/parser-plugins.js            | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/ghost/admin/lib/koenig-editor/addon/options/parser-plugins.js b/ghost/admin/lib/koenig-editor/addon/options/parser-plugins.js
index 54156499d9..d0914cd166 100644
--- a/ghost/admin/lib/koenig-editor/addon/options/parser-plugins.js
+++ b/ghost/admin/lib/koenig-editor/addon/options/parser-plugins.js
@@ -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
 ];