As the title above. I want to replace a figure
tag with image
tag. I have tried replace()
、replaceWith()
、setNodeMarkup()
、prosemirror-utils::replaceSelectedNode()
methods etc.
function(tr, dispatch, node, nodeType, $pos, attrs){
// `node` is figure Node, `nodeType` and `$pos` is the corresponding NodeType and ResolvedPos.
let newNode = nodeType.create(attrs, null, null);
let pos = $pos.pos;
// attempt 1
tr.replace(pos, pos + node.nodeSize, new Slice(newNode, 0, 0));
// attempt 2
tr.replaceWith(pos, pos + node.nodeSize, newNode);
// attempt 3
tr.setNodeMarkup($pos.pos, nodeType, attrs);
// // attempt 4 in prosemirror-utils
replaceSelectedNode(newNode)(tr);
}