summaryrefslogtreecommitdiff
path: root/src/render.h
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-07-11 15:51:12 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-07-11 17:38:34 -0700
commit476f083fc0d4ac31da918f7e1110cabc10acf02f (patch)
tree0b3b43da0769e783f2234e2d9cb632ec357955a7 /src/render.h
parent4e3b2cf8af9872fb1bfc29bfa6b9d24b5c063ff1 (diff)
Factored out common bits of rendering into separate render module.
* Added render.c, render.h. * Moved common functions and definitions from latex.c and commonmark.c to render.c, render.h. * Added a wrapper, cmark_render, that creates a renderer given a character-escaper and a node renderer. Closes #63.
Diffstat (limited to 'src/render.h')
-rw-r--r--src/render.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/render.h b/src/render.h
new file mode 100644
index 0000000..6c268a1
--- /dev/null
+++ b/src/render.h
@@ -0,0 +1,67 @@
+#ifndef CMARK_RENDER_H
+#define CMARK_RENDER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdlib.h>
+#include "buffer.h"
+#include "chunk.h"
+
+typedef enum {
+ LITERAL,
+ NORMAL,
+ TITLE,
+ URL
+} cmark_escaping;
+
+struct cmark_render_state {
+ int options;
+ cmark_strbuf* buffer;
+ cmark_strbuf* prefix;
+ int column;
+ int width;
+ int need_cr;
+ bufsize_t last_breakable;
+ int enumlevel;
+ bool begin_line;
+ bool no_wrap;
+ bool in_tight_list_item;
+ void (*outc)(struct cmark_render_state*,
+ cmark_escaping,
+ int32_t,
+ unsigned char);
+};
+
+typedef struct cmark_render_state cmark_render_state;
+
+void cr(cmark_render_state *state);
+
+void blankline(cmark_render_state *state);
+
+void out(cmark_render_state *state,
+ cmark_chunk str,
+ bool wrap,
+ cmark_escaping escape);
+
+void lit(cmark_render_state *state, char *s, bool wrap);
+
+char*
+cmark_render(cmark_node *root,
+ int options,
+ int width,
+ void (*outc)(cmark_render_state*,
+ cmark_escaping,
+ int32_t,
+ unsigned char),
+ int (*render_node)(cmark_node *node,
+ cmark_event_type ev_type,
+ cmark_render_state *state));
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif