fix a big in highlighter
This commit is contained in:
@@ -23,29 +23,29 @@ const findBlockNodes = (doc: ProsemirrorNode) => {
|
|||||||
return nodes
|
return nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseNodes(nodes: any[], className: string[] = []): any {
|
||||||
|
return nodes.map(node => {
|
||||||
|
|
||||||
|
const classes = [
|
||||||
|
...className,
|
||||||
|
...node.properties ? node.properties.className : [],
|
||||||
|
]
|
||||||
|
|
||||||
|
if (node.children) {
|
||||||
|
return parseNodes(node.children, classes)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
text: node.value,
|
||||||
|
classes,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function getDecorations({ doc, name }: { doc: ProsemirrorNode, name: string}) {
|
function getDecorations({ doc, name }: { doc: ProsemirrorNode, name: string}) {
|
||||||
const decorations: Decoration[] = []
|
const decorations: Decoration[] = []
|
||||||
const blocks = findBlockNodes(doc).filter(block => block.node.type.name === name)
|
const blocks = findBlockNodes(doc).filter(block => block.node.type.name === name)
|
||||||
|
|
||||||
function parseNodes(nodes: any[], className: string[] = []): any {
|
|
||||||
return nodes.map(node => {
|
|
||||||
|
|
||||||
const classes = [
|
|
||||||
...className,
|
|
||||||
...node.properties ? node.properties.className : [],
|
|
||||||
]
|
|
||||||
|
|
||||||
if (node.children) {
|
|
||||||
return parseNodes(node.children, classes)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
text: node.value,
|
|
||||||
classes,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
blocks.forEach(block => {
|
blocks.forEach(block => {
|
||||||
let startPos = block.pos + 1
|
let startPos = block.pos + 1
|
||||||
const { language } = block.node.attrs
|
const { language } = block.node.attrs
|
||||||
@@ -57,7 +57,7 @@ function getDecorations({ doc, name }: { doc: ProsemirrorNode, name: string}) {
|
|||||||
: low.highlightAuto(block.node.textContent).value
|
: low.highlightAuto(block.node.textContent).value
|
||||||
|
|
||||||
parseNodes(nodes)
|
parseNodes(nodes)
|
||||||
.flat()
|
.flat(Infinity)
|
||||||
.map((node: any) => {
|
.map((node: any) => {
|
||||||
const from = startPos
|
const from = startPos
|
||||||
const to = from + node.text.length
|
const to = from + node.text.length
|
||||||
|
|||||||
Reference in New Issue
Block a user