From 73e1ff454a70373121de513df898421409e5a0a2 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Tue, 19 Jan 2021 21:27:23 -0500 Subject: Map tags to IDs using only [[:alnum:]-._] --- bin/htagml.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/bin/htagml.c b/bin/htagml.c index 4df40d13..3d555dc8 100644 --- a/bin/htagml.c +++ b/bin/htagml.c @@ -14,6 +14,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -51,6 +52,16 @@ static size_t escape(bool esc, const char *ptr, size_t len) { return len; } +static void id(const char *tag) { + for (const char *ch = tag; *ch; ++ch) { + if (isalnum(*ch) || strchr("-._", *ch)) { + putchar(*ch); + } else { + putchar('_'); + } + } +} + static char *hstrstr(const char *haystack, const char *needle) { while (haystack) { char *elem = strchr(haystack, '<'); @@ -152,7 +163,7 @@ int main(int argc, char *argv[]) { if (index) { if (!tag) continue; printf("
  • tag, strlen(tag->tag)); + id(tag->tag); printf("\">"); escape(true, tag->tag, strlen(tag->tag)); printf("
  • \n"); @@ -181,9 +192,9 @@ int main(int argc, char *argv[]) { } escape(!pipe, buf, match - buf); printf("tag, strlen(tag->tag)); + id(tag->tag); printf("\" href=\"#"); - escape(true, tag->tag, strlen(tag->tag)); + id(tag->tag); printf("\">"); match += escape(!pipe, match, mlen); printf(""); -- cgit 1.4.1 9f4fa4d6965595aee645c0a8'/>