mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-21 15:28:09 +08:00
18 lines
450 B
TypeScript
18 lines
450 B
TypeScript
|
import { ResolvedPos } from 'prosemirror-model'
|
||
|
|
||
|
export const getTextContentFromNodes = ($from: ResolvedPos<any>, maxMatch = 500) => {
|
||
|
let textBefore = ''
|
||
|
|
||
|
$from.parent.nodesBetween(
|
||
|
Math.max(0, $from.parentOffset - maxMatch),
|
||
|
$from.parentOffset,
|
||
|
(node, pos, parent, index) => {
|
||
|
textBefore += node.type.spec.toText?.({
|
||
|
node, pos, parent, index,
|
||
|
}) || node.textContent || '%leaf%'
|
||
|
},
|
||
|
)
|
||
|
|
||
|
return textBefore
|
||
|
}
|