summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmark.h14
-rw-r--r--src/iterator.c8
2 files changed, 22 insertions, 0 deletions
diff --git a/src/cmark.h b/src/cmark.h
index 45bc338..84a15c8 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -163,6 +163,11 @@ cmark_node_last_child(cmark_node *node);
*
* cmark_iter_free(iter);
* }
+ *
+ * Note that if you delete the current node, its first child, or its
+ * next sibling, the iterator may point to a nonexistent note.
+ * Use 'cmark_iter_reset' to set its pointer to the next node that
+ * should be traversed.
*/
/** Creates a new iterator starting at 'root'.
@@ -177,6 +182,15 @@ CMARK_EXPORT
void
cmark_iter_free(cmark_iter *iter);
+/** Resets the iterator so that the current node is 'current' and
+ the event type is 'event_type'. Use this to resume after destructively
+ modifying the tree structure.
+ */
+CMARK_EXPORT
+void
+cmark_iter_reset(cmark_iter *iter, cmark_node *current,
+ cmark_event_type event_type);
+
/** Returns the event type (`CMARK_EVENT_ENTER`, `CMARK_EVENT_EXIT`,
* or `CMARK_EVENT_DONE`) for the next node.
*/
diff --git a/src/iterator.c b/src/iterator.c
index b0ac9d2..2c15246 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -48,6 +48,14 @@ int S_is_leaf(cmark_node *node)
}
}
+void
+cmark_iter_reset(cmark_iter *iter, cmark_node *current,
+ cmark_event_type event_type)
+{
+ iter->event_type = event_type;
+ iter->current = current;
+}
+
cmark_node*
cmark_iter_get_node(cmark_iter *iter)
{