From 8d6efe632aaeb1831c86b27e120a344c5e3ee7d4 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 13 Dec 2014 12:08:19 -0800 Subject: API improvements: cmark_event_type parameter for walk handlers. Added cmark_event_type enum, which is used as the second parameter of the handler passed to cmark_walk. See #224. --- src/node.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/node.c') diff --git a/src/node.c b/src/node.c index a7083ca..72eb619 100644 --- a/src/node.c +++ b/src/node.c @@ -786,7 +786,7 @@ int S_is_leaf_node(cmark_node *current_node) int cmark_walk(cmark_node *root, cmark_node_handler handler, void *state) { - int begin = 1; + int ev_type = CMARK_EVENT_ENTER; cmark_node *current_node = root; int depth = 0; cmark_node *next, *parent, *first_child; @@ -796,14 +796,15 @@ int cmark_walk(cmark_node *root, cmark_node_handler handler, void *state) next = current_node->next; parent = current_node->parent; - if (!handler(current_node, begin, state)) { + if (!handler(current_node, ev_type, state)) { return 0; } - if (begin && !S_is_leaf_node(current_node)) { + if (ev_type == CMARK_EVENT_ENTER && + !S_is_leaf_node(current_node)) { first_child = current_node->first_child; if (first_child == NULL) { - begin = 0; // stay on this node + ev_type = CMARK_EVENT_EXIT; // stay on this node } else { depth += 1; current_node = first_child; @@ -816,13 +817,14 @@ int cmark_walk(cmark_node *root, cmark_node_handler handler, void *state) if (next) { // don't go past root: if (current_node == root) { + ev_type = CMARK_EVENT_DONE; return 1; } else { - begin = 1; + ev_type = CMARK_EVENT_ENTER; current_node = next; } } else { - begin = 0; + ev_type = CMARK_EVENT_EXIT; depth -= 1; current_node = parent; } -- cgit v1.2.3