feat: Add alias condition to code-block-lowlight (#3155)

This commit is contained in:
Molly
2022-09-14 09:06:01 +09:00
committed by GitHub
parent fa96749ce2
commit b01ccff7b2

View File

@@ -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))