From 14ae4f33c47b015ff41a2b4d88b215841ce5eb57 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 26 Aug 2018 10:50:54 -0700 Subject: Simplify code normalization, in line with spec change. --- src/inlines.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/inlines.c b/src/inlines.c index 0dc7864..bbda78f 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -324,27 +324,22 @@ static bufsize_t scan_to_closing_backticks(subject *subj, } // Destructively modify string, converting newlines to -// spaces or removing them if they're adjacent to spaces, -// then removing a single leading + trailing space. +// spaces, then removing a single leading + trailing space. static void S_normalize_code(cmark_strbuf *s) { - bool last_char_was_space = false; bufsize_t r, w; for (r = 0, w = 0; r < s->size; ++r) { switch (s->ptr[r]) { case '\r': + if (s->ptr[r + 1] != '\n') { + s->ptr[w++] = ' '; + } break; case '\n': - if (!last_char_was_space && !cmark_isspace(s->ptr[r + 1])) { - s->ptr[w++] = ' '; - last_char_was_space = true; - } else { - last_char_was_space = false; - } + s->ptr[w++] = ' '; break; default: s->ptr[w++] = s->ptr[r]; - last_char_was_space = (s->ptr[r] == ' '); } } -- cgit v1.2.3