Skip to content

Commit

Permalink
Simplify code normalization, in line with spec change.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgm committed Aug 26, 2018
1 parent 15a76de commit 14ae4f3
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] == ' ');
}
}

Expand Down

0 comments on commit 14ae4f3

Please sign in to comment.