cmark

My personal build of CMark ✏️

Commit
050fb343307b8fe40e3f7541093b75eb276c547a
Parent
ba58d983c6c5e9be72c51210e5ae1aad00f229bb
Author
John MacFarlane <jgm@berkeley.edu>
Date

Made CommonMark renderer sensitive to CMARK_OPT_HARDBREAKS.

Note that width is automatically set to 0 if CMARK_OPT_HARDBREAKS is specified.

Diffstat

1 file changed, 8 insertions, 4 deletions

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