diff options
author | John MacFarlane <[email protected]> | 2014-12-13 14:13:58 -0800 |
---|---|---|
committer | John MacFarlane <[email protected]> | 2014-12-13 19:40:21 -0800 |
commit | a3030f985a973b3b835645313fdad1a8a72ff432 (patch) | |
tree | e1b1b43b16102b106bc43f4dd5eee32bb11b2a73 /src/html.c | |
parent | 8d6efe632aaeb1831c86b27e120a344c5e3ee7d4 (diff) |
Added iterator interface to API, removed cmark_walk.
* Added `iterator.c`, `iterator.h`.
* Removed `cmark_walk`.
* Replaced `cmark_walk` with iterator in HTML renderer.
* Replaced API test for `cmark_walk` with simple iterator test.
Diffstat (limited to 'src/html.c')
-rw-r--r-- | src/html.c | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -271,12 +271,18 @@ char *cmark_render_html(cmark_node *root) { char *result; strbuf html = GH_BUF_INIT; + cmark_event_type ev_type; + cmark_node *cur; struct render_state state = { &html, NULL }; - if (cmark_walk(root, S_render_node, &state)) { - result = (char *)strbuf_detach(&html); - strbuf_free(&html); - return result; - } else { - return NULL; + cmark_iter *iter = cmark_iter_new(root); + + while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { + cur = cmark_iter_get_node(iter); + S_render_node(cur, ev_type, &state); } + result = (char *)strbuf_detach(&html); + + cmark_iter_free(iter); + strbuf_free(&html); + return result; } |