summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmark.h5
-rw-r--r--src/node.c9
2 files changed, 14 insertions, 0 deletions
diff --git a/src/cmark.h b/src/cmark.h
index 5f9f294..6b5c385 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -387,6 +387,11 @@ CMARK_EXPORT int cmark_node_insert_before(cmark_node *node,
*/
CMARK_EXPORT int cmark_node_insert_after(cmark_node *node, cmark_node *sibling);
+/** Replaces 'oldnode' with 'newnode' and frees the memory used by 'oldnode'.
+ * Returns 1 on success, 0 on failure.
+ */
+CMARK_EXPORT int cmark_node_replace(cmark_node *oldnode, cmark_node *newnode);
+
/** Adds 'child' to the beginning of the children of 'node'.
* Returns 1 on success, 0 on failure.
*/
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;