Skip to content

Commit 14ae4f3

Browse files
committed
Simplify code normalization, in line with spec change.
1 parent 15a76de commit 14ae4f3

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/inlines.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,27 +324,22 @@ static bufsize_t scan_to_closing_backticks(subject *subj,
324324
}
325325

326326
// Destructively modify string, converting newlines to
327-
// spaces or removing them if they're adjacent to spaces,
328-
// then removing a single leading + trailing space.
327+
// spaces, then removing a single leading + trailing space.
329328
static void S_normalize_code(cmark_strbuf *s) {
330-
bool last_char_was_space = false;
331329
bufsize_t r, w;
332330

333331
for (r = 0, w = 0; r < s->size; ++r) {
334332
switch (s->ptr[r]) {
335333
case '\r':
334+
if (s->ptr[r + 1] != '\n') {
335+
s->ptr[w++] = ' ';
336+
}
336337
break;
337338
case '\n':
338-
if (!last_char_was_space && !cmark_isspace(s->ptr[r + 1])) {
339-
s->ptr[w++] = ' ';
340-
last_char_was_space = true;
341-
} else {
342-
last_char_was_space = false;
343-
}
339+
s->ptr[w++] = ' ';
344340
break;
345341
default:
346342
s->ptr[w++] = s->ptr[r];
347-
last_char_was_space = (s->ptr[r] == ' ');
348343
}
349344
}
350345

0 commit comments

Comments
 (0)