Skip to content

Commit 4bb756a

Browse files
committed
Update code span normalization...
to conform with spec change.
1 parent cffc51b commit 4bb756a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/inlines.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,11 @@ static bufsize_t scan_to_closing_backticks(subject *subj,
324324
}
325325

326326
// Destructively modify string, converting newlines to
327-
// spaces, then removing a single leading + trailing space.
327+
// spaces, then removing a single leading + trailing space,
328+
// unless the code span consists entirely of space characters.
328329
static void S_normalize_code(cmark_strbuf *s) {
329330
bufsize_t r, w;
331+
bool contains_nonspace = false;
330332

331333
for (r = 0, w = 0; r < s->size; ++r) {
332334
switch (s->ptr[r]) {
@@ -341,10 +343,14 @@ static void S_normalize_code(cmark_strbuf *s) {
341343
default:
342344
s->ptr[w++] = s->ptr[r];
343345
}
346+
if (s->ptr[r] != ' ') {
347+
contains_nonspace = true;
348+
}
344349
}
345350

346351
// begins and ends with space?
347-
if (s->ptr[0] == ' ' && s->ptr[w - 1] == ' ') {
352+
if (contains_nonspace &&
353+
s->ptr[0] == ' ' && s->ptr[w - 1] == ' ') {
348354
cmark_strbuf_drop(s, 1);
349355
cmark_strbuf_truncate(s, w - 2);
350356
} else {

0 commit comments

Comments
 (0)