cmark

My personal build of CMark ✏️

Commit
4bb756a98c0982b8b39b4eee8091e1a5f60d7111
Parent
cffc51b19828d67b246cb367da3b8b45270e5a62
Author
John MacFarlane <jgm@berkeley.edu>
Date

Update code span normalization...

to conform with spec change.

Diffstat

1 file changed, 8 insertions, 2 deletions

Status File Name N° Changes Insertions Deletions
Modified src/inlines.c 10 8 2
diff --git 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 {