Welcome to little lamb

Code » qmdoc » commit 9371d20

Fix rendering of code blocks with a lang only

author Olivier Brunel
2022-12-31 21:16:13 UTC
committer Olivier Brunel
2022-12-31 21:16:13 UTC
parent 6f7f72c84c8b0a30796eff1146b5073f4262f8a3

Fix rendering of code blocks with a lang only

That is, when a lang was specified without any other argument (e.g. hl
or from=) we forgot to still turn buffering on, leading to invalid HTML.

main.c +28 -28

diff --git a/main.c b/main.c
index 641fd1e..a9672f9 100644
--- a/main.c
+++ b/main.c
@@ -450,34 +450,34 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_)
 
                     const char *s;
                     s = memchr(t, ' ', l);
-                    if (!s) break;
-
-                    ++s;
-                    l -= s - t;
-                    t = s;
-                    while (l > 0) {
-                        if ((ctx->code.flags & CODE_LINES)
-                                && l > 5 && !strncmp(t, "from=", 5)) {
-                            char *end = NULL;
-                            ctx->code.from = strtol(t + 5, &end, 10);
-                            if (!end || (*end != ' ' && *end != '\n'))
-                                return ERR_INVALID;
-                            l -= end - t;
-                            t = end;
-                        } else if (l >= 2 && !strncmp(t, "hl", 2)
-                                && (s[2] == ' ' || s[2] == '\n')) {
-                            ctx->code.flags |= CODE_HIGHLIGHT;
-                            l -= 2;
-                            t += 2;
-                        } else {
-                            s = memchr(t, ' ', l);
-                            if (!s) break;
-                            l -= s - t;
-                            t = s;
-                        }
-                        while (*t == ' ' && l > 0) {
-                            ++t;
-                            --l;
+                    if (s) {
+                        ++s;
+                        l -= s - t;
+                        t = s;
+                        while (l > 0) {
+                            if ((ctx->code.flags & CODE_LINES)
+                                    && l > 5 && !strncmp(t, "from=", 5)) {
+                                char *end = NULL;
+                                ctx->code.from = strtol(t + 5, &end, 10);
+                                if (!end || (*end != ' ' && *end != '\n'))
+                                    return ERR_INVALID;
+                                l -= end - t;
+                                t = end;
+                            } else if (l >= 2 && !strncmp(t, "hl", 2)
+                                    && (s[2] == ' ' || s[2] == '\n')) {
+                                ctx->code.flags |= CODE_HIGHLIGHT;
+                                l -= 2;
+                                t += 2;
+                            } else {
+                                s = memchr(t, ' ', l);
+                                if (!s) break;
+                                l -= s - t;
+                                t = s;
+                            }
+                            while (*t == ' ' && l > 0) {
+                                ++t;
+                                --l;
+                            }
                         }
                     }