feat: add support for checking for attributes in extendMarkRange

This commit is contained in:
Philipp Kühn
2021-05-17 13:00:54 +02:00
parent 5b8808a899
commit ff7dd9b919
7 changed files with 391 additions and 14 deletions

View File

@@ -0,0 +1,31 @@
import { Node as ProseMirrorNode } from 'prosemirror-model'
/**
* Returns a node tree with node positions.
*/
export default function getDebugJSON(node: ProseMirrorNode) {
const debug = (startNode: ProseMirrorNode, startOffset = 0) => {
const nodes: any[] = []
startNode.forEach((n, offset) => {
const from = startOffset + offset
const to = from + n.nodeSize
nodes.push({
type: n.type.name,
attrs: { ...n.attrs },
from,
to,
marks: n.marks.map(mark => ({
type: mark.type.name,
attrs: { ...mark.attrs },
})),
content: debug(n, from + 1),
})
})
return nodes
}
return debug(node)
}