diff --git a/packages/extension-code-block-lowlight/src/lowlight-plugin.ts b/packages/extension-code-block-lowlight/src/lowlight-plugin.ts index 8ca5db00562..6c0ec1c268d 100644 --- a/packages/extension-code-block-lowlight/src/lowlight-plugin.ts +++ b/packages/extension-code-block-lowlight/src/lowlight-plugin.ts @@ -1,4 +1,6 @@ import { findChildren } from '@tiptap/core' +// @ts-ignore +import highlight from 'highlight.js/lib/core' import { Node as ProsemirrorNode } from 'prosemirror-model' import { Plugin, PluginKey } from 'prosemirror-state' import { Decoration, DecorationSet } from 'prosemirror-view' @@ -30,6 +32,10 @@ function getHighlightNodes(result: any) { return result.value || result.children || [] } +function registered(aliasOrLanguage: string) { + return Boolean(highlight.getLanguage(aliasOrLanguage)) +} + function getDecorations({ doc, name, @@ -43,7 +49,8 @@ function getDecorations({ let from = block.pos + 1 const language = block.node.attrs.language || defaultLanguage const languages = lowlight.listLanguages() - const nodes = language && languages.includes(language) + + const nodes = language && (languages.includes(language) || registered(language)) ? getHighlightNodes(lowlight.highlight(language, block.node.textContent)) : getHighlightNodes(lowlight.highlightAuto(block.node.textContent))