commit 5f047d4
default
·
2023-12-03 16:26:50 +0000 UTC
parent a658e5d
Backport from xs.
3 files changed,
+28,
-13
M
html.c
+1,
-1
1@@ -1000,7 +1000,7 @@ static xs_html *html_button(char *clss, char *label, char *hint)
2 xs *c = xs_fmt("snac-btn-%s", clss);
3
4 /* use an NULL tag to separate non-css-classed buttons from one another */
5- return xs_html_tag(NULL,
6+ return xs_html_container(
7 xs_html_sctag("input",
8 xs_html_attr("type", "submit"),
9 xs_html_attr("name", "action"),
+26,
-11
1@@ -21,6 +21,9 @@ xs_html *_xs_html_tag(char *tag, xs_html *var[]);
2 xs_html *_xs_html_sctag(char *tag, xs_html *var[]);
3 #define xs_html_sctag(tag, ...) _xs_html_sctag(tag, (xs_html *[]) { __VA_ARGS__, NULL })
4
5+xs_html *_xs_html_container(xs_html *var[]);
6+#define xs_html_container(...) _xs_html_container((xs_html *[]) { __VA_ARGS__, NULL })
7+
8 void xs_html_render_f(xs_html *h, FILE *f);
9 xs_str *xs_html_render_s(xs_html *tag, char *prefix);
10 #define xs_html_render(tag) xs_html_render_s(tag, NULL)
11@@ -31,6 +34,7 @@ xs_str *xs_html_render_s(xs_html *tag, char *prefix);
12 typedef enum {
13 XS_HTML_TAG,
14 XS_HTML_SCTAG,
15+ XS_HTML_CONTAINER,
16 XS_HTML_ATTR,
17 XS_HTML_TEXT
18 } xs_html_type;
19@@ -75,9 +79,7 @@ xs_str *xs_html_encode(char *str)
20
21 /* insert the escaped char */
22 char tmp[8];
23- snprintf(tmp, sizeof(tmp), "&#%d;", *q);
24-
25- z = strlen(tmp);
26+ z = snprintf(tmp, sizeof(tmp), "&#%d;", *q);
27 s = xs_insert_m(s, o, tmp, z);
28 o += z;
29
30@@ -192,6 +194,12 @@ xs_html *_xs_html_sctag(char *tag, xs_html *var[])
31 }
32
33
34+xs_html *_xs_html_container(xs_html *var[])
35+{
36+ return _xs_html_tag_t(XS_HTML_CONTAINER, NULL, var);
37+}
38+
39+
40 void xs_html_render_f(xs_html *h, FILE *f)
41 /* renders the tag and its subtags into a file */
42 {
43@@ -200,8 +208,7 @@ void xs_html_render_f(xs_html *h, FILE *f)
44 switch (h->type) {
45 case XS_HTML_TAG:
46 case XS_HTML_SCTAG:
47- if (h->content)
48- fprintf(f, "<%s", h->content);
49+ fprintf(f, "<%s", h->content);
50
51 /* render the attributes */
52 st = h->f_attr;
53@@ -213,12 +220,10 @@ void xs_html_render_f(xs_html *h, FILE *f)
54
55 if (h->type == XS_HTML_SCTAG) {
56 /* self-closing tags should not have subtags */
57- if (h->content)
58- fprintf(f, "/>");
59+ fprintf(f, "/>");
60 }
61 else {
62- if (h->content)
63- fprintf(f, ">");
64+ fprintf(f, ">");
65
66 /* render the subtags */
67 st = h->f_tag;
68@@ -228,8 +233,18 @@ void xs_html_render_f(xs_html *h, FILE *f)
69 st = nst;
70 }
71
72- if (h->content)
73- fprintf(f, "</%s>", h->content);
74+ fprintf(f, "</%s>", h->content);
75+ }
76+
77+ break;
78+
79+ case XS_HTML_CONTAINER:
80+ /* render the subtags and nothing more */
81+ st = h->f_tag;
82+ while (st) {
83+ xs_html *nst = st->next;
84+ xs_html_render_f(st, f);
85+ st = nst;
86 }
87
88 break;
+1,
-1
1@@ -1 +1 @@
2-/* b26300d01136fad22ee774d20a7da5b299f30d13 2023-12-03T11:38:09+01:00 */
3+/* f27e092c79ca6e2e96f83e0d4c3dbc73d737ffaa 2023-12-03T17:12:47+01:00 */