From 4bb756a98c0982b8b39b4eee8091e1a5f60d7111 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 4 Apr 2019 22:05:12 -0700 Subject: Update code span normalization... to conform with spec change. --- src/inlines.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/inlines.c') diff --git a/src/inlines.c b/src/inlines.c index 458ab72..e6b491f 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -324,9 +324,11 @@ static bufsize_t scan_to_closing_backticks(subject *subj, } // Destructively modify string, converting newlines to -// spaces, then removing a single leading + trailing space. +// spaces, then removing a single leading + trailing space, +// unless the code span consists entirely of space characters. static void S_normalize_code(cmark_strbuf *s) { bufsize_t r, w; + bool contains_nonspace = false; for (r = 0, w = 0; r < s->size; ++r) { switch (s->ptr[r]) { @@ -341,10 +343,14 @@ static void S_normalize_code(cmark_strbuf *s) { default: s->ptr[w++] = s->ptr[r]; } + if (s->ptr[r] != ' ') { + contains_nonspace = true; + } } // begins and ends with space? - if (s->ptr[0] == ' ' && s->ptr[w - 1] == ' ') { + if (contains_nonspace && + s->ptr[0] == ' ' && s->ptr[w - 1] == ' ') { cmark_strbuf_drop(s, 1); cmark_strbuf_truncate(s, w - 2); } else { -- cgit v1.2.3