summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-01-19 21:27:23 -0500
committerJune McEnroe <june@causal.agency>2021-01-19 21:27:23 -0500
commit73e1ff454a70373121de513df898421409e5a0a2 (patch)
treee3ae5564f5e4d600dba73578ce8ce4ae66edd87f /bin
parentDon't use a pager if reading standard input (diff)
downloadsrc-73e1ff454a70373121de513df898421409e5a0a2.tar.gz
src-73e1ff454a70373121de513df898421409e5a0a2.zip
Map tags to IDs using only [[:alnum:]-._]
Diffstat (limited to 'bin')
-rw-r--r--bin/htagml.c17
1 files 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 <http://www.gnu.org/licenses/>.
  */
 
+#include <ctype.h>
 #include <err.h>
 #include <regex.h>
 #include <stdbool.h>
@@ -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("<li><a class=\"tag\" href=\"#");
-			escape(true, tag->tag, strlen(tag->tag));
+			id(tag->tag);
 			printf("\">");
 			escape(true, tag->tag, strlen(tag->tag));
 			printf("</a></li>\n");
@@ -181,9 +192,9 @@ int main(int argc, char *argv[]) {
 		}
 		escape(!pipe, buf, match - buf);
 		printf("<a class=\"tag\" id=\"");
-		escape(true, tag->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("</a>");
d Born SlippyJune McEnroe I watched Trainspotting last night. 2018-04-03Add I Can Tell You About PainJune McEnroe 2018-04-03Reverse new music orderJune McEnroe 2018-04-03Add FAUVE, CocoRosieJune McEnroe 2018-04-03Add House of LeavesJune McEnroe 2018-04-03Add ChromaticsJune McEnroe 2018-04-03Add those new Arcade Fire singlesJune McEnroe 2018-04-03Add SermonJune McEnroe 2018-04-03Add Pools of LightJune McEnroe 2018-04-03Add SteroidsJune McEnroe 2018-04-03Add A Common TruthJune McEnroe 2018-04-03Add new Colin Stetson albumJune McEnroe 2018-04-03Add ForgetJune McEnroe 2018-04-03Add ArcaJune McEnroe 2018-04-03Add new DMST and Joni VoidJune McEnroe 2018-04-03Add The Body LoversJune McEnroe 2018-04-03Add some albums from recentlyJune McEnroe 2018-04-03Add Saltland Light of MercyJune McEnroe 2018-04-03Add Jessica Moss GlaciersJune McEnroe 2018-04-03Add BNNY RBBTJune McEnroe 2018-04-03Add DepthsJune McEnroe 2018-04-03Add new Saltland previewJune McEnroe 2018-04-03Add BenjiJune McEnroe 2018-04-03Add Mouth MoodsJune McEnroe 2018-04-03Add Those Who Walk AwayJune McEnroe 2018-04-03Add Some TunesJune McEnroe 2018-04-03Add Pas pire popJune McEnroe 2018-04-03Add I Give You PowerJune McEnroe 2018-04-03Add Jenny GoGoJune McEnroe 2018-04-03Add KKB Fish BowlJune McEnroe 2018-04-03Add new Avec le soleil album previewJune McEnroe 2018-04-03Add Julien Baker as recent new musicJune McEnroe 2018-04-03Add recent new musicJune McEnroe