From 8a71de7d058592b05c7f74424d2a2efbeab8ddc2 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 19 Dec 2019 09:44:48 -0800 Subject: Improve rendering of commonmark code spans with spaces. Closes #316. --- src/commonmark.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/commonmark.c b/src/commonmark.c index 404c290..3440a91 100644 --- a/src/commonmark.c +++ b/src/commonmark.c @@ -182,6 +182,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node, char *emph_delim; bool first_in_list_item; bufsize_t marker_width; + bool has_nonspace; bool allow_wrap = renderer->width > 0 && !(CMARK_OPT_NOBREAKS & options) && !(CMARK_OPT_HARDBREAKS & options); @@ -371,9 +372,16 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node, code = cmark_node_get_literal(node); code_len = strlen(code); numticks = shortest_unused_backtick_sequence(code); + has_nonspace = false; + for (i=0; i < code_len; i++) { + if (code[i] != ' ') { + has_nonspace = true; + break; + } + } extra_spaces = code_len == 0 || code[0] == '`' || code[code_len - 1] == '`' || - code[0] == ' ' || code[code_len - 1] == ' '; + (has_nonspace && code[0] == ' ' && code[code_len - 1] == ' '); for (i = 0; i < numticks; i++) { LIT("`"); } -- cgit v1.2.3