Welcome to little lamb

Code » qmdoc » commit aff76a7

Fix entities being double-escaped in page's TOC

author Olivier Brunel
2023-01-01 21:47:48 UTC
committer Olivier Brunel
2023-01-04 15:09:27 UTC
parent 09d948d6ae4fdf952f8057dfe86f39ca7bf039e0

Fix entities being double-escaped in page's TOC

main.c +5 -4

diff --git a/main.c b/main.c
index dcf7b48..5cbfa48 100644
--- a/main.c
+++ b/main.c
@@ -182,13 +182,14 @@ anchor(struct ctx *ctx, const char *text, size_t size)
 }
 
 static int
-strip_tags(struct ctx *ctx, const char *text, size_t size)
+strip_tags(struct ctx *ctx, const char *text, size_t size, int no_escaping)
 {
+    int (*do_text) (struct ctx *, const char *, size_t) = (no_escaping) ? raw_text : escape_text;
     const char *s;
     for(;;) {
         s = memchr(text, '<', size);
         if (!s) break;
-        if (!escape_text(ctx, text, s - text))
+        if (!do_text(ctx, text, s - text))
             return 0;
         size -= ++s - text;
         text = s;
@@ -198,7 +199,7 @@ strip_tags(struct ctx *ctx, const char *text, size_t size)
             text = s;
         }
     }
-    return escape_text(ctx, text, size);
+    return do_text(ctx, text, size);
 }
 
 static int
@@ -606,7 +607,7 @@ leave_block(MD_BLOCKTYPE type, void *details, void *ctx_)
                 if (!raw_str(ctx, "<li><a href=\"#")
                         || !anchor(ctx, toc, l)
                         || !raw_str(ctx, "\">")
-                        || !strip_tags(ctx, toc, l)
+                        || !strip_tags(ctx, toc, l, 1)
                         || !raw_str(ctx, "</a>"))
                     return ERR_PARSER_TOC;
                 ctx->doc.flags &= ~DOC_BUFFERING;