From 93843bd2fe8c91fe9e659c5b801f1a7d672dc223 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 10 Jan 2016 23:35:33 -0800 Subject: Added cmark_node_replace(oldnode, newnode). API change. I've found in using the API that this is very often wanted. --- src/node.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/node.c') diff --git a/src/node.c b/src/node.c index ce7f80c..0fd5573 100644 --- a/src/node.c +++ b/src/node.c @@ -730,6 +730,15 @@ int cmark_node_insert_after(cmark_node *node, cmark_node *sibling) { return 1; } +int cmark_node_replace(cmark_node *oldnode, cmark_node *newnode) { + if (!cmark_node_insert_before(oldnode, newnode)) { + return 0; + } + cmark_node_unlink(oldnode); + cmark_node_free(oldnode); + return 1; +} + int cmark_node_prepend_child(cmark_node *node, cmark_node *child) { if (!S_can_contain(node, child)) { return 0; -- cgit v1.2.3