mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-11 11:45:15 +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 { language } = block.node.attrs
|
||||||
const languages = lowlight.listLanguages()
|
const languages = lowlight.listLanguages()
|
||||||
const nodes = language && languages.includes(language)
|
const nodes = language && languages.includes(language)
|
||||||
? lowlight.highlight(language, block.node.textContent).value
|
? getHighlightNodes(lowlight.highlight(language, block.node.textContent))
|
||||||
: lowlight.highlightAuto(block.node.textContent).value
|
: getHighlightNodes(lowlight.highlightAuto(block.node.textContent))
|
||||||
|
|
||||||
parseNodes(nodes).forEach(node => {
|
parseNodes(nodes).forEach(node => {
|
||||||
const to = from + node.text.length
|
const to = from + node.text.length
|
||||||
@ -51,6 +51,11 @@ function getDecorations({ doc, name, lowlight }: { doc: ProsemirrorNode, name: s
|
|||||||
from = to
|
from = to
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function getHighlightNodes(result) {
|
||||||
|
// `.value` for lowlight v1, `.children` for lowlight v2
|
||||||
|
return result.value || result.children || []
|
||||||
|
}
|
||||||
|
|
||||||
return DecorationSet.create(doc, decorations)
|
return DecorationSet.create(doc, decorations)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user