figcaption tag

This commit is contained in:
Matteo Bini 2024-08-16 19:23:19 +02:00
parent ca9017342b
commit 465281a163
1 changed files with 53 additions and 10 deletions

View File

@ -9,6 +9,7 @@
#define CLS_MAX 16
#define DATE_LEN 10
#define FAVICON "data:image/gif;base64,R0lGODlhEAAQAKEAAAAAcP///wAAcAAAcCH5BAEKAAIALAAAAAAQABAAQAIwlBWZxxwAQWjtTQRvlZhTnGSfYT3eZ3WaE4mjGa1UasoH7c6tzYanfqmhJMKXglcAADs="
#define FIGCAPTION_TAG_LEN 12
#define INDEX_START 16
#define LANG_LEN 2
#define LINE_MAX 1000
@ -111,9 +112,10 @@ static int string_putc(string *dst, const char c);
char *author = NULL;
string body;
char *description = NULL;
int figcaption_presence = 0;
string head;
size_t heading_position = 0;
int imgs_presence = 0;
int img_presence = 0;
int indentation = 2;
char *index_heading = NULL;
char *index_heading_id = NULL;
@ -318,9 +320,29 @@ cmd_br(void)
void
cmd_close(void)
{
char *ind, *line;
index_title *title;
size_t len;
title = NULL;
ind = NULL;
len = 0;
line = NULL;
title = NULL;
if (!strcmp(tag_closure, "</figure>")) {
len = strlen(body.str);
if (len >= FIGCAPTION_TAG_LEN + indentation)
line = body.str + len - FIGCAPTION_TAG_LEN;
if (line != NULL && !strcmp(line, "<figcaption>")) {
*(line - indentation) = '\0';
} else {
figcaption_presence = 1;
string_cat(&body, "</figcaption>\n");
}
indent_str(&ind, --indentation);
string_cat(&body, ind);
free(ind);
}
if ((!strcmp(tag_closure, "</h3>") ||
!strcmp(tag_closure, "</h4>") ||
@ -404,10 +426,18 @@ cmd_fi(const char *line)
indent_str(&ind, indentation);
string_cat(&body, ind);
string_cat(&body, "<figure><img src=\"");
string_cat(&body, "<figure>\n");
indent_str(&ind, ++indentation);
string_cat(&body, ind);
string_cat(&body, "<img src=\"");
string_cat(&body, src);
string_cat(&body, "\" alt=\"\"></figure>");
imgs_presence = 1;
string_cat(&body, "\" alt=\"\">\n");
img_presence = 1;
string_cat(&body, ind);
string_cat(&body, "<figcaption>");
strcpy(tag_closure, "</figure>");
free(ind);
free(src);
@ -898,7 +928,11 @@ indent_str(char **str, const int ind)
{
int i;
*str = safe_malloc(sizeof(char) * (ind + 1));
if (*str == NULL || strlen(*str) <= ind) {
free(*str);
*str = safe_malloc(sizeof(char) * (ind + 1));
}
for (i = 0; i < ind; i++)
(*str)[i] = '\t';
(*str)[ind] = '\0';
@ -1160,9 +1194,10 @@ page_head(void)
" p"
);
if (index_position)
string_cat(&head, ",\n\t\t\tli {");
else
string_cat(&head, " {");
string_cat(&head, ",\n\t\t\tli");
if (figcaption_presence)
string_cat(&head, ",\n\t\t\tfigcaption");
string_cat(&head, " {");
string_cat(&head, "\n" \
" line-height: 1.5;\n" \
" }\n" \
@ -1173,7 +1208,7 @@ page_head(void)
" }\n"
);
if (imgs_presence) {
if (img_presence) {
string_cat(&head, "\n" \
" figure {\n" \
" margin-left: 0;\n" \
@ -1188,6 +1223,14 @@ page_head(void)
);
}
if (figcaption_presence) {
string_cat(&head, "\n" \
" figcaption {\n" \
" font-style: italic;\n" \
" }\n" \
);
}
if (licence_container) {
string_cat(&head, "\n" \
" .contenitore-licenza {\n" \