diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-12-19 09:44:48 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-12-19 09:44:48 -0800 |
commit | 8a71de7d058592b05c7f74424d2a2efbeab8ddc2 (patch) | |
tree | 01618bab0ec2162b5d480893a9eab10f7a7d0362 /src | |
parent | 68c3a91166347a32a57fb81223750a63cfd92105 (diff) |
Improve rendering of commonmark code spans with spaces.
Closes #316.
Diffstat (limited to 'src')
-rw-r--r-- | src/commonmark.c | 10 |
1 files changed, 9 insertions, 1 deletions
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("`"); } |