чување 8ef69743332bafd4477786447e63d5736b683852
родитељ c810f6b8c7911042f05a3d472cbb3cb11335e089
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Fri, 26 Nov 2021 12:57:24 +0100
Add inline-stylesheet YAML variable
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | slweb.1.in | | | 17 | +++++++++++++++-- |
| M | slweb.c | | | 44 | ++++++++++++++++++++++++++++++++++++++++---- |
измењених датотека: 2, додавања: 55(+), брисања: 6(-)
diff --git a/slweb.1.in b/slweb.1.in
@@ -515,9 +515,11 @@ passed to
The KaTeX stylesheet is not included, and needs to be included separately
through the
.B stylesheet
+or
+.B inline-stylesheet
.SM YAML
-variable (see
-.BR stylesheet ).
+variables (see
+.BR stylesheet ", " inline-stylesheet ).
.
.SS Directives
.
@@ -819,6 +821,17 @@ actual file path to pass to the
command. Otherwise, \fCsrc\fP is appended to \[lq].\[rq].
.
.IP \[bu]
+.BR inline-stylesheet .
+The contents of this variable will be treated as a
+.SM CSS
+file name to be included inline in the header using the \fC<style>\fP tag. You
+can add more than one
+.I inline-stylesheet
+declaration per
+.I .slw
+file.
+.
+.IP \[bu]
.BR lang .
Contents of this variable will be used for the \fClang\fP attribute of the
\fC<html>\fP tag.
diff --git a/slweb.c b/slweb.c
@@ -546,6 +546,38 @@ process_git_log(FILE* output)
return result ? warning(result, (u8*)"git-log: Cannot run git") : 0;
}
+int
+process_inline_stylesheet(FILE* output, const u8* css_filename)
+{
+ FILE* css = NULL;
+ u8* bufline = NULL;
+
+ if (!css_filename)
+ exit(error(EINVAL,
+ (u8*)"process_inline_stylesheet: Invalid argument"));
+
+ if (!(css = fopen((const char*)css_filename, "rt")))
+ exit(error(ENOENT,
+ (u8*)"process_inline_stylesheet: No such file: %s",
+ css_filename));
+
+ CALLOC(bufline, u8, BUFSIZE);
+
+ print_output(output, "<style type=\"text/css\">\n");
+ while (!feof(css))
+ {
+ if (!fgets((char*)bufline, BUFSIZE, css))
+ break;
+ print_output(output, "%s", bufline);
+ }
+ print_output(output, "</style>\n");
+
+ fclose(css);
+ free(bufline);
+
+ return 0;
+}
+
#define PRINTTSVIF(format, arg) \
do \
{ \
@@ -1639,7 +1671,7 @@ process_incdir(FILE* output, const u8* token, const u8* link_prefix,
pnamelist = namelist;
names_output = 0;
- while (names_output < MIN(names_total,num))
+ while (names_output < MIN(names_total, num))
{
process_incdir_subdir(output, (*pnamelist)->d_name, link_prefix,
details_open, macro_body);
@@ -2398,6 +2430,11 @@ add_css(FILE* output)
pvars->value);
output_firstcol = TRUE;
}
+ else if (!strcmp((char*)pvars->key, "inline-stylesheet"))
+ {
+ process_inline_stylesheet(output, pvars->value);
+ output_firstcol = TRUE;
+ }
pvars++;
}
return 0;
@@ -4386,9 +4423,8 @@ do_line:
break;
case '&':
- if (ANY(state, ST_CODE | ST_KBD | ST_PRE)
- || !*(pline+1)
- || isspace(*(pline+1)))
+ if (ANY(state, ST_CODE | ST_KBD | ST_PRE) || !*(pline + 1)
+ || isspace(*(pline + 1)))
{
size_t quot_len = strlen("&");
*ptoken = 0;