cmark

My personal build of CMark ✏️

Commit
e63be8475f241cde1f7001252a3039b5c66c3e0f
Parent
464b21b11b17009b09379e7edd6dac9c6479db98
Author
John MacFarlane <jgm@berkeley.edu>
Date

commonmark renderer: special case EMPH(EMPH(x)).

This needs to be rendered `*_x_*` rather than `**x**`.

Diffstat

1 file changed, 11 insertions, 2 deletions

Status File Name N° Changes Insertions Deletions
Modified src/commonmark.c 13 11 2
diff --git a/src/commonmark.c b/src/commonmark.c
@@ -254,6 +254,7 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
 	const char *info;
 	const char *title;
 	char listmarker[64];
+	char *emph_delim;
 	int marker_width;
 
 	state->in_tight_list_item =
@@ -434,10 +435,18 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
 		break;
 
 	case CMARK_NODE_EMPH:
+		// If we have EMPH(EMPH(x)), we need to use *_x_*
+		// because **x** is STRONG(x):
+		if (node->parent && node->parent->type == CMARK_NODE_EMPH &&
+		    node->next == NULL && node->prev == NULL) {
+			emph_delim = "_";
+		} else {
+			emph_delim = "*";
+		}
 		if (entering) {
-			lit(state, "*", false);
+			lit(state, emph_delim, false);
 		} else {
-			lit(state, "*", false);
+			lit(state, emph_delim, false);
 		}
 		break;