summaryrefslogtreecommitdiff
path: root/xs_html.h
diff options
context:
space:
mode:
authorGravatar default2023-12-03 17:26:50 +0100
committerGravatar default2023-12-03 17:26:50 +0100
commit5f047d46c0ad2dd2f1cf83f359ac1ad779cb67f8 (patch)
tree2c072f1e54ebfcb08d05a3f5cc87a933f0ff06b0 /xs_html.h
parentDon't show polls as 'votable' from the public timeline. (diff)
downloadpenes-snac2-5f047d46c0ad2dd2f1cf83f359ac1ad779cb67f8.tar.gz
penes-snac2-5f047d46c0ad2dd2f1cf83f359ac1ad779cb67f8.tar.xz
penes-snac2-5f047d46c0ad2dd2f1cf83f359ac1ad779cb67f8.zip
Backport from xs.
Diffstat (limited to '')
-rw-r--r--xs_html.h37
1 files changed, 26 insertions, 11 deletions
diff --git a/xs_html.h b/xs_html.h
index f644b74..58a50b6 100644
--- a/xs_html.h
+++ b/xs_html.h
@@ -21,6 +21,9 @@ xs_html *_xs_html_tag(char *tag, xs_html *var[]);
21xs_html *_xs_html_sctag(char *tag, xs_html *var[]); 21xs_html *_xs_html_sctag(char *tag, xs_html *var[]);
22#define xs_html_sctag(tag, ...) _xs_html_sctag(tag, (xs_html *[]) { __VA_ARGS__, NULL }) 22#define xs_html_sctag(tag, ...) _xs_html_sctag(tag, (xs_html *[]) { __VA_ARGS__, NULL })
23 23
24xs_html *_xs_html_container(xs_html *var[]);
25#define xs_html_container(...) _xs_html_container((xs_html *[]) { __VA_ARGS__, NULL })
26
24void xs_html_render_f(xs_html *h, FILE *f); 27void xs_html_render_f(xs_html *h, FILE *f);
25xs_str *xs_html_render_s(xs_html *tag, char *prefix); 28xs_str *xs_html_render_s(xs_html *tag, char *prefix);
26#define xs_html_render(tag) xs_html_render_s(tag, NULL) 29#define xs_html_render(tag) xs_html_render_s(tag, NULL)
@@ -31,6 +34,7 @@ xs_str *xs_html_render_s(xs_html *tag, char *prefix);
31typedef enum { 34typedef enum {
32 XS_HTML_TAG, 35 XS_HTML_TAG,
33 XS_HTML_SCTAG, 36 XS_HTML_SCTAG,
37 XS_HTML_CONTAINER,
34 XS_HTML_ATTR, 38 XS_HTML_ATTR,
35 XS_HTML_TEXT 39 XS_HTML_TEXT
36} xs_html_type; 40} xs_html_type;
@@ -75,9 +79,7 @@ xs_str *xs_html_encode(char *str)
75 79
76 /* insert the escaped char */ 80 /* insert the escaped char */
77 char tmp[8]; 81 char tmp[8];
78 snprintf(tmp, sizeof(tmp), "&#%d;", *q); 82 z = snprintf(tmp, sizeof(tmp), "&#%d;", *q);
79
80 z = strlen(tmp);
81 s = xs_insert_m(s, o, tmp, z); 83 s = xs_insert_m(s, o, tmp, z);
82 o += z; 84 o += z;
83 85
@@ -192,6 +194,12 @@ xs_html *_xs_html_sctag(char *tag, xs_html *var[])
192} 194}
193 195
194 196
197xs_html *_xs_html_container(xs_html *var[])
198{
199 return _xs_html_tag_t(XS_HTML_CONTAINER, NULL, var);
200}
201
202
195void xs_html_render_f(xs_html *h, FILE *f) 203void xs_html_render_f(xs_html *h, FILE *f)
196/* renders the tag and its subtags into a file */ 204/* renders the tag and its subtags into a file */
197{ 205{
@@ -200,8 +208,7 @@ void xs_html_render_f(xs_html *h, FILE *f)
200 switch (h->type) { 208 switch (h->type) {
201 case XS_HTML_TAG: 209 case XS_HTML_TAG:
202 case XS_HTML_SCTAG: 210 case XS_HTML_SCTAG:
203 if (h->content) 211 fprintf(f, "<%s", h->content);
204 fprintf(f, "<%s", h->content);
205 212
206 /* render the attributes */ 213 /* render the attributes */
207 st = h->f_attr; 214 st = h->f_attr;
@@ -213,12 +220,10 @@ void xs_html_render_f(xs_html *h, FILE *f)
213 220
214 if (h->type == XS_HTML_SCTAG) { 221 if (h->type == XS_HTML_SCTAG) {
215 /* self-closing tags should not have subtags */ 222 /* self-closing tags should not have subtags */
216 if (h->content) 223 fprintf(f, "/>");
217 fprintf(f, "/>");
218 } 224 }
219 else { 225 else {
220 if (h->content) 226 fprintf(f, ">");
221 fprintf(f, ">");
222 227
223 /* render the subtags */ 228 /* render the subtags */
224 st = h->f_tag; 229 st = h->f_tag;
@@ -228,8 +233,18 @@ void xs_html_render_f(xs_html *h, FILE *f)
228 st = nst; 233 st = nst;
229 } 234 }
230 235
231 if (h->content) 236 fprintf(f, "</%s>", h->content);
232 fprintf(f, "</%s>", h->content); 237 }
238
239 break;
240
241 case XS_HTML_CONTAINER:
242 /* render the subtags and nothing more */
243 st = h->f_tag;
244 while (st) {
245 xs_html *nst = st->next;
246 xs_html_render_f(st, f);
247 st = nst;
233 } 248 }
234 249
235 break; 250 break;