cmark

My personal build of CMark ✏️

Commit
f2ac8b6aa69a4765e44f815a031b7aa574d44b57
Parent
a4f61e832fa9f99e04d05ab4b4768538ba076c84
Author
John MacFarlane <jgm@berkeley.edu>
Date

Improved cmark_strbuf_normalize_whitespace.

Now all characters that satisfy cmark_isspace are recognized as whitespace. Previously CR and TAB (and others) weren't included.

Partially addresses #73.

Diffstat

1 file changed, 6 insertions, 11 deletions

Status File Name N° Changes Insertions Deletions
Modified src/buffer.c 17 6 11
diff --git a/src/buffer.c b/src/buffer.c
@@ -282,17 +282,12 @@ void cmark_strbuf_normalize_whitespace(cmark_strbuf *s) {
   bufsize_t r, w;
 
   for (r = 0, w = 0; r < s->size; ++r) {
-    switch (s->ptr[r]) {
-    case ' ':
-    case '\n':
-      if (last_char_was_space)
-        break;
-
-      s->ptr[w++] = ' ';
-      last_char_was_space = true;
-      break;
-
-    default:
+    if (cmark_isspace(s->ptr[r])) {
+      if (!last_char_was_space) {
+        s->ptr[w++] = ' ';
+        last_char_was_space = true;
+      }
+    } else {
       s->ptr[w++] = s->ptr[r];
       last_char_was_space = false;
     }