ul, li tags and generalise p and license tags

This commit is contained in:
Matteo Bini 2024-09-01 15:36:15 +02:00
parent 9b7cfa66ce
commit ca8d6d7161
1 changed files with 96 additions and 56 deletions

152
srohtml.c
View File

@ -75,13 +75,13 @@ static void cmd_hr(void);
static void cmd_i(const char *line);
static void cmd_index(const char *line);
static void cmd_lang(const char *line);
static void cmd_license_end(void);
static void cmd_license_start(void);
static void cmd_line_tag(const char *tag);
static void cmd_note(const char *line);
static void cmd_p(void);
static void cmd_publication_date(const char *line);
static void cmd_q(const char *line);
static void cmd_strong(const char *line);
static void cmd_tag_end(const char *tag);
static void cmd_tag_start(const char *tag, const char *id, const char *class);
static void cmd_time(const char *line);
static void cmd_url(const char *line);
static void findent(const int ind, FILE *f);
@ -115,7 +115,9 @@ char *index_heading = NULL;
char *index_heading_id = NULL;
size_t index_position = 0;
char *language = NULL;
int li_presence = 0;
int licence_container = 0;
int nav_presence = 0;
char *publication_date = NULL;
array sitography;
int space = 0;
@ -238,14 +240,23 @@ cmd(char *line)
cmd_index(line);
else if (!strncmp(line, "LANG", cmdlen))
cmd_lang(line);
else if (!strncmp(line, "LICENSE_END", cmdlen))
cmd_license_end();
else if (!strncmp(line, "LICENSE_START", cmdlen))
cmd_license_start();
else if (!strncmp(line, "NOTE", cmdlen))
else if (!strncmp(line, "LI", cmdlen)) {
cmd_line_tag("li");
li_presence = 1;
} else if (!strncmp(line, "LICENSE_END", cmdlen))
cmd_tag_end("div");
else if (!strncmp(line, "LICENSE_START", cmdlen)) {
cmd_tag_start("div", "", "contenitore-licenza");
cmd_hr();
} else if (!strncmp(line, "NAV_END", cmdlen))
cmd_tag_end("nav");
else if (!strncmp(line, "NAV_START", cmdlen)) {
cmd_tag_start("nav", "", "");
nav_presence = 1;
} else if (!strncmp(line, "NOTE", cmdlen))
cmd_note(line);
else if (!strncmp(line, "P", cmdlen))
cmd_p();
cmd_line_tag("p");
else if (!strncmp(line, "PUBLICATION_DATE", cmdlen))
cmd_publication_date(line);
else if (!strncmp(line, "Q", cmdlen))
@ -254,6 +265,10 @@ cmd(char *line)
cmd_strong(line);
else if (!strncmp(line, "TITLE", cmdlen))
cmd_au_de_ti(&title, line);
else if (!strncmp(line, "UL_END", cmdlen))
cmd_tag_end("ul");
else if (!strncmp(line, "UL_START", cmdlen))
cmd_tag_start("ul", "", "");
else if (!strncmp(line, "URL", cmdlen))
cmd_url(line);
}
@ -489,13 +504,16 @@ void
cmd_h(const char *line)
{
const char *id;
char h[2];
char h[2], *ind;
h[0] = line[1];
h[1] = '\0';
id = NULL;
id = NULL;
ind = NULL;
array_strcat(&body, "\t\t<h");
indent_str(&ind, indentation);
array_strcat(&body, ind);
array_strcat(&body, "<h");
array_strcat(&body, h);
if (strlen(line) > 4 && line[2] == ' ' && line[3] != '\0') {
id = line + 3;
@ -513,12 +531,22 @@ cmd_h(const char *line)
if (id != NULL && index_position != 0)
add_h_to_index(line[1], id);
free(ind);
}
void
cmd_hr(void)
{
array_strcat(&body, "\t\t<hr>");
char *ind;
ind = NULL;
indent_str(&ind, indentation);
array_strcat(&body, ind);
array_strcat(&body, "<hr>\n");
free(ind);
}
void
@ -581,42 +609,25 @@ cmd_lang(const char *line)
}
void
cmd_license_end(void)
cmd_line_tag(const char *tag)
{
char *ind;
ind = NULL;
indentation--;
indent_str(&ind, indentation);
array_strcat(&body, ind);
array_strcat(&body, "</div>\n");
array_strcat(&body, "<");
array_strcat(&body, tag);
array_strcat(&body, ">");
strcpy(tag_closure, "</");
strcat(tag_closure, tag);
strcat(tag_closure, ">");
free(ind);
}
void
cmd_license_start(void)
{
char *ind;
ind = NULL;
licence_container = 1;
indent_str(&ind, indentation);
array_strcat(&body, ind);
array_strcat(&body, "<div class=\"contenitore-licenza\">\n");
indentation++;
free(ind);
ind = NULL;
indent_str(&ind, indentation);
array_strcat(&body, ind);
array_strcat(&body, "<hr>\n");
free(ind);
}
void
cmd_nav_end(const char *line)
{
@ -671,22 +682,6 @@ cmd_note(const char *line)
free(title);
}
void
cmd_p(void)
{
char *ind;
ind = NULL;
indent_str(&ind, indentation);
array_strcat(&body, ind);
array_strcat(&body, "<p>");
strcpy(tag_closure, "</p>");
free(ind);
}
void
cmd_publication_date(const char *line)
{
@ -755,6 +750,51 @@ cmd_strong(const char *line)
array_strcat(&body, "</strong>");
}
void
cmd_tag_end(const char *tag)
{
char *ind;
ind = NULL;
indentation--;
indent_str(&ind, indentation);
array_strcat(&body, ind);
array_strcat(&body, "</");
array_strcat(&body, tag);
array_strcat(&body, ">\n");
free(ind);
}
void
cmd_tag_start(const char *tag, const char *id, const char *class)
{
char *ind;
ind = NULL;
licence_container = 1;
indent_str(&ind, indentation);
array_strcat(&body, ind);
array_strcat(&body, "<");
array_strcat(&body, tag);
if (strcmp(id, "")) {
array_strcat(&body, " id=\"");
array_strcat_html(&body, id, tag_attribute);
array_strcat(&body, "\"");
}
if (strcmp(class, "")) {
array_strcat(&body, " class=\"");
array_strcat_html(&body, class, tag_attribute);
array_strcat(&body, "\"");
}
array_strcat(&body, ">\n");
indentation++;
free(ind);
}
void
cmd_time(const char *line)
{
@ -1259,7 +1299,7 @@ page_head(void)
"\n" \
" p"
);
if (index_position)
if (index_position || li_presence)
array_strcat(&head, ",\n\t\t\tli");
if (figcaption_presence)
array_strcat(&head, ",\n\t\t\tfigcaption");
@ -1374,7 +1414,7 @@ page_head(void)
" }\n"
);
if (index_position) {
if (index_position || nav_presence) {
array_strcat(&head, "\n" \
" nav {\n" \
" display: none;\n" \