Custom index heading with optional id

This commit is contained in:
Matteo Bini 2024-08-12 22:38:06 +02:00
parent f79292d9f3
commit ca9017342b
1 changed files with 35 additions and 5 deletions

View File

@ -75,7 +75,7 @@ static void cmd_fi(const char *line);
static void cmd_h(const char *line);
static void cmd_hr(void);
static void cmd_i(const char *line);
static void cmd_in();
static void cmd_in(const char *line);
static void cmd_la(const char *line);
static void cmd_le(void);
static void cmd_ls(void);
@ -115,6 +115,8 @@ string head;
size_t heading_position = 0;
int imgs_presence = 0;
int indentation = 2;
char *index_heading = NULL;
char *index_heading_id = NULL;
size_t index_position = 0;
char *language = NULL;
int licence_container = 0;
@ -225,7 +227,7 @@ cmd(char *line)
else if (!strncmp(line, "I", cmdlen))
cmd_i(line);
else if (!strncmp(line, "IN", cmdlen))
cmd_in();
cmd_in(line);
else if (!strncmp(line, "LA", cmdlen))
cmd_la(line);
else if (!strncmp(line, "LE", cmdlen))
@ -407,6 +409,7 @@ cmd_fi(const char *line)
string_cat(&body, "\" alt=\"\"></figure>");
imgs_presence = 1;
free(ind);
free(src);
}
@ -462,8 +465,23 @@ cmd_i(const char *line)
}
void
cmd_in(void)
cmd_in(const char *line)
{
/* move past "IN" */
line += 2;
/* move past arguments, once found them */
line += stread_param(line, &index_heading);
line += stread_param(line, &index_heading_id);
if (!strcmp(index_heading, "")) {
free(index_heading);
index_heading = NULL;
}
if (!strcmp(index_heading_id, "")) {
free(index_heading_id);
index_heading_id = NULL;
}
index_position = strlen(body.str);
}
@ -1019,8 +1037,20 @@ nav_index(FILE *f)
fputs("<nav>\n", f);
findent(ind, f);
fputs("<hr>\n", f);
if (index_heading != NULL) {
findent(ind, f);
fputs("<h3 id=\"indice\">Indice</h3>\n", f);
fputs("<h3", f);
if (index_heading_id != NULL) {
fputs(" id=\"", f);
fputs_html(index_heading_id, f, tag_attribute);
fputs("\"", f);
free(index_heading_id);
}
fputs(">", f);
fputs_html(index_heading, f, tag_content);
fputs("</h3>\n", f);
free(index_heading);
}
for (i = 0; i < page_index.index; i++) {
title = page_index.titles + i;
next_title = i == page_index.index - 1 ? NULL : title + 1;