summaryrefslogtreecommitdiff
path: root/src/render.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/render.c')
-rw-r--r--src/render.c51
1 files changed, 16 insertions, 35 deletions
diff --git a/src/render.c b/src/render.c
index 0fec3c4..f4c56ac 100644
--- a/src/render.c
+++ b/src/render.c
@@ -5,36 +5,6 @@
#include "utf8.h"
#include "render.h"
-static inline
-cmark_render_state
-cmark_initialize_render_state(int options, int width,
- void (*outc)(cmark_render_state*,
- cmark_escaping,
- int32_t,
- unsigned char))
-{
- cmark_strbuf *pref = (cmark_strbuf*)malloc(sizeof(cmark_strbuf));
- cmark_strbuf *buf = (cmark_strbuf*)malloc(sizeof(cmark_strbuf));
- cmark_strbuf_init(pref, 16);
- cmark_strbuf_init(buf, 1024);
- cmark_render_state state = { options, buf, pref, 0, width,
- 0, 0, 0, true, false, false, outc };
- return state;
-}
-
-static inline
-char *
-cmark_finalize_render_state(cmark_render_state *state)
-{
- char * result;
- result = (char *)cmark_strbuf_detach(state->buffer);
- cmark_strbuf_free(state->prefix);
- cmark_strbuf_free(state->buffer);
- free(state->prefix);
- free(state->buffer);
- return result;
-}
-
void cr(cmark_render_state *state)
{
if (state->need_cr < 1) {
@@ -162,14 +132,21 @@ cmark_render(cmark_node *root,
cmark_event_type ev_type,
cmark_render_state *state))
{
- if (CMARK_OPT_HARDBREAKS & options) {
- width = 0;
- }
- cmark_render_state state = cmark_initialize_render_state(options, width, outc);
+ cmark_strbuf pref = GH_BUF_INIT;
+ cmark_strbuf buf = GH_BUF_INIT;
cmark_node *cur;
cmark_event_type ev_type;
+ char *result;
cmark_iter *iter = cmark_iter_new(root);
+
+ if (CMARK_OPT_HARDBREAKS & options) {
+ width = 0;
+ }
+
+ cmark_render_state state = { options, &buf, &pref, 0, width,
+ 0, 0, 0, true, false, false, outc };
+
while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
cur = cmark_iter_get_node(iter);
if (!render_node(cur, ev_type, &state)) {
@@ -180,7 +157,11 @@ cmark_render(cmark_node *root,
}
}
+ result = (char *)cmark_strbuf_detach(state.buffer);
+
cmark_iter_free(iter);
+ cmark_strbuf_free(state.prefix);
+ cmark_strbuf_free(state.buffer);
- return cmark_finalize_render_state(&state);
+ return result;
}