From a897b826c16c68c395af4416fdd1413aa9585849 Mon Sep 17 00:00:00 2001 From: Ivan Kovmir Date: Thu, 26 Sep 2024 09:47:03 +0200 Subject: [PATCH] Remove all `#` characters from the page titles --- swege.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/swege.c b/swege.c index 2e1be18..4652c59 100644 --- a/swege.c +++ b/swege.c @@ -298,6 +298,7 @@ char * get_title(FILE * in) { char *line = NULL; + int n_hashes; size_t linecap = 0; getline(&line, &linecap, in); @@ -321,8 +322,11 @@ get_title(FILE * in) } } } else if (strlen(line) >= 3 && line[0] == '#') { - /* Copy line without the # */ - strncpy(ret, line + 2, (TITLE_SIZE + 1)); + /* Count the amount of '#' characters. */ + for (n_hashes = 1; line[n_hashes] == '#'; n_hashes++) + ; + /* Copy line without the '#' and ' ' immediately after it. */ + strncpy(ret, line + n_hashes + 1, (TITLE_SIZE + 1)); ret[TITLE_SIZE] = '\0'; /* Ensure termination */ rewind(in); /* Leave H1 in place for rendering */