cmark

Unnamed repository; edit this file 'description' to name the repository.

commit e63be8475f241cde1f7001252a3039b5c66c3e0f
parent 464b21b11b17009b09379e7edd6dac9c6479db98
Author: John MacFarlane <jgm@berkeley.edu>
Date:   Sun, 29 Mar 2015 16:29:14 -0700

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

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

Diffstat:
Msrc/commonmark.c | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
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;