summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-03-21 20:11:38 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-03-21 20:11:38 -0700
commit393c9507b033e3115c57887e8863f40d45f1a999 (patch)
tree61345c0b936784c9891fe23f3030cd034ef1c90f
parent4b21fe65b6f774193ce25b6f0ebee5cf88b88200 (diff)
CommonMark renderer: don't wrap headers.
-rw-r--r--src/commonmark.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/commonmark.c b/src/commonmark.c
index 3ab9988..73c3d2d 100644
--- a/src/commonmark.c
+++ b/src/commonmark.c
@@ -20,6 +20,7 @@ struct render_state {
int need_cr;
int last_breakable;
bool begin_line;
+ bool no_wrap;
};
static inline void cr(struct render_state *state)
@@ -63,6 +64,8 @@ static inline void out(struct render_state *state,
cmark_chunk remainder = cmark_chunk_literal("");
int k = state->buffer->size - 1;
+ wrap = wrap && !state->no_wrap;
+
while (state->need_cr) {
if (k < 0 || state->buffer->ptr[k] == '\n') {
k -= 1;
@@ -209,8 +212,9 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
lit(state, "#", false);
}
lit(state, " ", false);
- // TODO set a "nowrap" variable in state, and refer to this in out()
+ state->no_wrap = true;
} else {
+ state->no_wrap = false;
blankline(state);
}
break;
@@ -321,7 +325,8 @@ char *cmark_render_commonmark(cmark_node *root, int options)
char *result;
cmark_strbuf commonmark = GH_BUF_INIT;
cmark_strbuf prefix = GH_BUF_INIT;
- struct render_state state = { &commonmark, &prefix, 0, 65, 0, 0, true };
+ struct render_state state =
+ { &commonmark, &prefix, 0, 65, 0, 0, true, false };
cmark_node *cur;
cmark_event_type ev_type;
cmark_iter *iter = cmark_iter_new(root);