diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-03-23 13:22:08 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-03-23 13:22:08 -0700 |
commit | 050fb343307b8fe40e3f7541093b75eb276c547a (patch) | |
tree | ef4e89ee961c95450e962371fa50737bb561427b | |
parent | ba58d983c6c5e9be72c51210e5ae1aad00f229bb (diff) |
Made CommonMark renderer sensitive to CMARK_OPT_HARDBREAKS.
Note that width is automatically set to 0 if CMARK_OPT_HARDBREAKS
is specified.
-rw-r--r-- | src/commonmark.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/commonmark.c b/src/commonmark.c index 98fef5e..d11c449 100644 --- a/src/commonmark.c +++ b/src/commonmark.c @@ -13,6 +13,7 @@ // Functions to convert cmark_nodes to commonmark strings. struct render_state { + int options; cmark_strbuf* buffer; cmark_strbuf* prefix; int column; @@ -296,7 +297,9 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, break; case CMARK_NODE_LINEBREAK: - lit(state, "\\", false); + if (!(CMARK_OPT_HARDBREAKS & state->options)) { + lit(state, "\\", false); + } cr(state); break; @@ -386,14 +389,15 @@ char *cmark_render_commonmark(cmark_node *root, int options, int width) char *result; cmark_strbuf commonmark = GH_BUF_INIT; cmark_strbuf prefix = GH_BUF_INIT; + if (CMARK_OPT_HARDBREAKS & options) { + width = 0; + } struct render_state state = - { &commonmark, &prefix, 0, width, 0, 0, true, false }; + { options, &commonmark, &prefix, 0, width, 0, 0, true, false }; cmark_node *cur; cmark_event_type ev_type; cmark_iter *iter = cmark_iter_new(root); - if (options == 0) options = 0; // avoid warning about unused parameters - while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { cur = cmark_iter_get_node(iter); S_render_node(cur, ev_type, &state); |