From f79347e128be11860ee54109d8d333b436426b45 Mon Sep 17 00:00:00 2001 From: MO <9125255+fengzilong@users.noreply.github.com> Date: Fri, 1 Oct 2021 03:34:20 +0800 Subject: [PATCH] fix: compatibility with lowlight v2 (#1939) --- .../extension-code-block-lowlight/src/lowlight-plugin.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/extension-code-block-lowlight/src/lowlight-plugin.ts b/packages/extension-code-block-lowlight/src/lowlight-plugin.ts index f0aa9b26..6f873557 100644 --- a/packages/extension-code-block-lowlight/src/lowlight-plugin.ts +++ b/packages/extension-code-block-lowlight/src/lowlight-plugin.ts @@ -34,8 +34,8 @@ function getDecorations({ doc, name, lowlight }: { doc: ProsemirrorNode, name: s const { language } = block.node.attrs const languages = lowlight.listLanguages() const nodes = language && languages.includes(language) - ? lowlight.highlight(language, block.node.textContent).value - : lowlight.highlightAuto(block.node.textContent).value + ? getHighlightNodes(lowlight.highlight(language, block.node.textContent)) + : getHighlightNodes(lowlight.highlightAuto(block.node.textContent)) parseNodes(nodes).forEach(node => { const to = from + node.text.length @@ -51,6 +51,11 @@ function getDecorations({ doc, name, lowlight }: { doc: ProsemirrorNode, name: s from = to }) }) + + function getHighlightNodes(result) { + // `.value` for lowlight v1, `.children` for lowlight v2 + return result.value || result.children || [] + } return DecorationSet.create(doc, decorations) }