cmark

My personal build of CMark ✏️

Commit
393c9507b033e3115c57887e8863f40d45f1a999
Parent
4b21fe65b6f774193ce25b6f0ebee5cf88b88200
Author
John MacFarlane <jgm@berkeley.edu>
Date

CommonMark renderer: don't wrap headers.

Diffstat

1 file changed, 7 insertions, 2 deletions

Status File Name N° Changes Insertions Deletions
Modified src/commonmark.c 9 7 2
diff --git 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);