mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 17:43:49 +08:00
fix: compatibility with lowlight v2 (#1939)
This commit is contained in:
parent
dead826250
commit
f79347e128
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user