fix a big in highlighter

This commit is contained in:
Philipp Kühn
2021-04-02 23:02:05 +02:00
parent 74bd678e8b
commit c94264894b

View File

@@ -23,11 +23,7 @@ const findBlockNodes = (doc: ProsemirrorNode) => {
return nodes
}
function getDecorations({ doc, name }: { doc: ProsemirrorNode, name: string}) {
const decorations: Decoration[] = []
const blocks = findBlockNodes(doc).filter(block => block.node.type.name === name)
function parseNodes(nodes: any[], className: string[] = []): any {
function parseNodes(nodes: any[], className: string[] = []): any {
return nodes.map(node => {
const classes = [
@@ -44,7 +40,11 @@ function getDecorations({ doc, name }: { doc: ProsemirrorNode, name: string}) {
classes,
}
})
}
}
function getDecorations({ doc, name }: { doc: ProsemirrorNode, name: string}) {
const decorations: Decoration[] = []
const blocks = findBlockNodes(doc).filter(block => block.node.type.name === name)
blocks.forEach(block => {
let startPos = block.pos + 1
@@ -57,7 +57,7 @@ function getDecorations({ doc, name }: { doc: ProsemirrorNode, name: string}) {
: low.highlightAuto(block.node.textContent).value
parseNodes(nodes)
.flat()
.flat(Infinity)
.map((node: any) => {
const from = startPos
const to = from + node.text.length