From 465281a1633cf6c631bf9ea7e3e5b3032d0b05ea Mon Sep 17 00:00:00 2001 From: Matteo Bini Date: Fri, 16 Aug 2024 19:23:19 +0200 Subject: [PATCH] figcaption tag --- srohtml.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/srohtml.c b/srohtml.c index 79c56c8..6a1b165 100644 --- a/srohtml.c +++ b/srohtml.c @@ -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, "")) { + len = strlen(body.str); + if (len >= FIGCAPTION_TAG_LEN + indentation) + line = body.str + len - FIGCAPTION_TAG_LEN; + if (line != NULL && !strcmp(line, "
")) { + *(line - indentation) = '\0'; + } else { + figcaption_presence = 1; + string_cat(&body, "
\n"); + } + indent_str(&ind, --indentation); + string_cat(&body, ind); + free(ind); + } if ((!strcmp(tag_closure, "") || !strcmp(tag_closure, "") || @@ -404,10 +426,18 @@ cmd_fi(const char *line) indent_str(&ind, indentation); string_cat(&body, ind); - string_cat(&body, "
\n"); + indent_str(&ind, ++indentation); + string_cat(&body, ind); + string_cat(&body, "\"\"
"); - imgs_presence = 1; + string_cat(&body, "\" alt=\"\">\n"); + img_presence = 1; + + string_cat(&body, ind); + string_cat(&body, "
"); + + strcpy(tag_closure, ""); 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" \