Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
&& singleChild
&& matchesString
) {
const to = Number(node.textContent.match(/.*to=([0-9]+)/)[1]);
const from = Number(node.textContent.match(/.*from=([0-9]+)/)[1]);
const newNodeData = getHighlightContent(from, to);
// let exact = '';
// primaryEditorState.doc.slice(from, to).content.forEach((sliceNode)=>{ exact += sliceNode.textContent; });
// let prefix = '';
// primaryEditorState.doc.slice(Math.max(0, from - 10), Math.max(0, from)).content.forEach((sliceNode)=>{ prefix += sliceNode.textContent; });
// let suffix = '';
// primaryEditorState.doc.slice(Math.min(primaryEditorState.doc.nodeSize - 2, to), Math.min(primaryEditorState.doc.nodeSize - 2, to + 10)).content.forEach((sliceNode)=>{ suffix += sliceNode.textContent; });
// console.log(to, from, exact, prefix, suffix);
const newNode = node.type.schema.nodes.highlightQuote.create(newNodeData);
/* TODO: this doesn't paste correctly inline */
return new Slice(Fragment.fromArray([newNode, node.type.schema.nodes.paragraph.create()]), slice.openStart, slice.openEnd);
}
return slice;
},
},
// console.log(props.getHighlightContent, singleChild)
if (props.getHighlightContent && singleChild && matchesString) {
const to = Number(node.textContent.match(/.*to=([0-9]+)/)[1]);
const from = Number(node.textContent.match(/.*from=([0-9]+)/)[1]);
const newNodeData = props.getHighlightContent(from, to);
// let exact = '';
// primaryEditorState.doc.slice(from, to).content.forEach((sliceNode)=>{ exact += sliceNode.textContent; });
// let prefix = '';
// primaryEditorState.doc.slice(Math.max(0, from - 10), Math.max(0, from)).content.forEach((sliceNode)=>{ prefix += sliceNode.textContent; });
// let suffix = '';
// primaryEditorState.doc.slice(Math.min(primaryEditorState.doc.nodeSize - 2, to), Math.min(primaryEditorState.doc.nodeSize - 2, to + 10)).content.forEach((sliceNode)=>{ suffix += sliceNode.textContent; });
// console.log(to, from, exact, prefix, suffix);
const newNode = node.type.schema.nodes.highlightQuote.create(newNodeData);
/* TODO: this doesn't paste correctly inline */
return new Slice(
Fragment.fromArray([newNode, node.type.schema.nodes.paragraph.create()]),
slice.openStart,
slice.openEnd,
);
}
return slice;
},
},
.addToSet(child.marks)))
pos = end
}
}
// adding rest of text to nodes
if (pos < text.length) {
nodes.push(child.cut(pos))
}
} else {
nodes.push(child.copy(handler(child.content)))
}
})
return Fragment.fromArray(nodes)
}
child.cut(start, end).mark(link.create(attrs).addToSet(child.marks))
)
}
pos = end
})
// copy over whatever is left
if (pos < text.length) {
linkified.push(child.cut(pos))
}
} else {
linkified.push(child.copy(linkify(child.content)))
}
})
return Fragment.fromArray(linkified)
}
function mapFragment(fragment, f, parent) {
let mapped = []
for (let i = 0; i < fragment.childCount; i++) {
let child = fragment.child(i)
if (child.content.size) child = child.copy(mapFragment(child.content, f, child))
if (child.isInline) child = f(child, parent, i)
mapped.push(child)
}
return Fragment.fromArray(mapped)
}
.mark(type.create(attrs)
.addToSet(child.marks)))
pos = end
}
} while (match)
if (pos < text.length) {
nodes.push(child.cut(pos))
}
} else {
nodes.push(child.copy(handler(child.content)))
}
})
return Fragment.fromArray(nodes)
}
for (let i = 0, size = content.childCount; i < size; i++) {
const node = content.child(i)
const transformed = node.isLeaf
? callback(node, parent, i)
: callback(node.copy(mapFragment(node.content, callback, node)), parent, i)
if (transformed) {
if (transformed instanceof Fragment) {
children.push(...getFragmentBackingArray(transformed))
} else if (Array.isArray(transformed)) {
children.push(...transformed)
} else {
children.push(transformed)
}
}
}
return Fragment.fromArray(children)
}