From faa0ef8bfa3a3b78990b07027c9db0b525e52785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 2 Apr 2021 22:21:17 +0200 Subject: [PATCH] check for language in highlighting --- .../extension-code-block-lowlight/src/lowlight-plugin.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/extension-code-block-lowlight/src/lowlight-plugin.ts b/packages/extension-code-block-lowlight/src/lowlight-plugin.ts index c8c47454..ef4dfeb0 100644 --- a/packages/extension-code-block-lowlight/src/lowlight-plugin.ts +++ b/packages/extension-code-block-lowlight/src/lowlight-plugin.ts @@ -48,7 +48,13 @@ function getDecorations({ doc, name }: { doc: ProsemirrorNode, name: string}) { blocks.forEach(block => { let startPos = block.pos + 1 - const nodes = low.highlightAuto(block.node.textContent).value + const { language } = block.node.attrs + // TODO: add missing type for `listLanguages` + // @ts-ignore + const languages = low.listLanguages() as string[] + const nodes = language && languages.includes(language) + ? low.highlight(language, block.node.textContent).value + : low.highlightAuto(block.node.textContent).value parseNodes(nodes) .flat()