Skip to content

Commit

Permalink
feat: Add alias condition to code-block-lowlight (#3155)
Browse files Browse the repository at this point in the history
  • Loading branch information
dngwoodo committed Sep 14, 2022
1 parent fa96749 commit b01ccff
Showing 1 changed file with 8 additions and 1 deletion.
@@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -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))

Expand Down

0 comments on commit b01ccff

Please sign in to comment.