From 86de41d87cc78feee9c4f4cdb22af1d72bcf4339 Mon Sep 17 00:00:00 2001 From: Matteo Bini Date: Tue, 23 Jul 2024 13:05:22 +0200 Subject: [PATCH] br, em and i tags. Partial img/figure support --- srohtml.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/srohtml.c b/srohtml.c index 698ad44..b68839a 100644 --- a/srohtml.c +++ b/srohtml.c @@ -38,9 +38,13 @@ static void cmd(char *line); static void cmd_close(void); static void cmd_a(const char *line); static void cmd_au_de_ti(char **str, const char *line); +static void cmd_br(void); static void cmd_dt(const char *line); +static void cmd_em(const char *line); +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_la(const char *line); static void cmd_le(void); static void cmd_ls(void); @@ -68,6 +72,7 @@ static void string_enlarge(string *old, const size_t size); static int string_putc(string *dst, const char c); /* variables */ +int imgs_presence = 0; char *author = NULL; char closure[CLS_MAX]; char *description = NULL; @@ -116,10 +121,16 @@ cmd(char *line) cmd_a(line); else if (!strncmp(line, "AU", cmdlen)) cmd_au_de_ti(&author, line); + else if (!strncmp(line, "BR", cmdlen)) + cmd_br(); else if (!strncmp(line, "DE", cmdlen)) cmd_au_de_ti(&description, line); else if (!strncmp(line, "DT", cmdlen)) cmd_dt(line); + else if (!strncmp(line, "EM", cmdlen)) + cmd_em(line); + else if (!strncmp(line, "FI", cmdlen)) + cmd_fi(line); else if (!strncmp(line, "H1", cmdlen)) cmd_h(line); else if (!strncmp(line, "H2", cmdlen)) @@ -134,6 +145,8 @@ cmd(char *line) cmd_h(line); else if (!strncmp(line, "HR", cmdlen)) cmd_hr(); + else if (!strncmp(line, "I", cmdlen)) + cmd_i(line); else if (!strncmp(line, "LA", cmdlen)) cmd_la(line); else if (!strncmp(line, "LE", cmdlen)) @@ -214,6 +227,13 @@ cmd_au_de_ti(char **str, const char *line) strcpy(*str, line); } +void +cmd_br(void) +{ + string_cat(&body, "
"); + space = 0; +} + void cmd_close(void) { @@ -252,6 +272,46 @@ cmd_dt(const char *line) free(in); } +void +cmd_em(const char *line) +{ + /* move past "EM" */ + line += 2; + /* move past ' ', if present */ + if (line[0] == ' ') + line++; + + if (space) + string_cat(&body, " "); + string_cat(&body, ""); + string_cat(&body, line); + string_cat(&body, ""); +} + +void +cmd_fi(const char *line) +{ + char *ind, *src; + + ind = NULL; + src = NULL; + + /* move past "FI" */ + line += 2; + /* move past argument, once found it */ + line += stread_param(line, &src); + + indent_str(&ind); + + string_cat(&body, ind); + string_cat(&body, "
\"\"
"); + imgs_presence = 1; + + free(src); +} + void cmd_h(const char *line) { @@ -275,6 +335,22 @@ cmd_hr(void) string_cat(&body, "\t\t
"); } +void +cmd_i(const char *line) +{ + /* move past "I" */ + line += 1; + /* move past ' ', if present */ + if (line[0] == ' ') + line++; + + if (space) + string_cat(&body, " "); + string_cat(&body, ""); + string_cat(&body, line); + string_cat(&body, ""); +} + void cmd_la(const char *line) { @@ -379,6 +455,7 @@ cmd_p(void) ind = NULL; indent_str(&ind); + string_cat(&body, ind); string_cat(&body, "

"); strcpy(closure, "

"); @@ -797,6 +874,21 @@ page_head(void) " }\n" ); + if (imgs_presence) { + string_cat(&head, "\n" \ +" figure {\n" \ +" margin-left: 0;\n" \ +" margin-right: 0;\n" \ +" text-align: center;\n" \ +" }\n" \ +"\n" \ +" img {\n" \ +" max-width: 100%;\n" \ +" width: 7em;\n" \ +" }\n" + ); + } + if (licence_container) { string_cat(&head, "\n" \ " .contenitore-licenza {\n" \