commit b17aa7d
default
·
2023-12-03 22:47:25 +0000 UTC
parent 5f047d4
Backport from xs.
2 files changed,
+24,
-35
+23,
-34
1@@ -203,61 +203,50 @@ xs_html *_xs_html_container(xs_html *var[])
2 void xs_html_render_f(xs_html *h, FILE *f)
3 /* renders the tag and its subtags into a file */
4 {
5- xs_html *st;
6+ if (h == NULL)
7+ return;
8
9 switch (h->type) {
10 case XS_HTML_TAG:
11- case XS_HTML_SCTAG:
12 fprintf(f, "<%s", h->content);
13
14- /* render the attributes */
15- st = h->f_attr;
16- while (st) {
17- xs_html *nst = st->next;
18- xs_html_render_f(st, f);
19- st = nst;
20- }
21+ /* attributes */
22+ xs_html_render_f(h->f_attr, f);
23
24- if (h->type == XS_HTML_SCTAG) {
25- /* self-closing tags should not have subtags */
26- fprintf(f, "/>");
27- }
28- else {
29- fprintf(f, ">");
30+ fprintf(f, ">");
31
32- /* render the subtags */
33- st = h->f_tag;
34- while (st) {
35- xs_html *nst = st->next;
36- xs_html_render_f(st, f);
37- st = nst;
38- }
39+ /* sub-tags */
40+ xs_html_render_f(h->f_tag, f);
41
42- fprintf(f, "</%s>", h->content);
43- }
44+ fprintf(f, "</%s>", h->content);
45+ break;
46+
47+ case XS_HTML_SCTAG:
48+ fprintf(f, "<%s", h->content);
49
50+ /* attributes */
51+ xs_html_render_f(h->f_attr, f);
52+
53+ fprintf(f, "/>");
54 break;
55
56 case XS_HTML_CONTAINER:
57- /* render the subtags and nothing more */
58- st = h->f_tag;
59- while (st) {
60- xs_html *nst = st->next;
61- xs_html_render_f(st, f);
62- st = nst;
63- }
64-
65+ /* sub-tags */
66+ xs_html_render_f(h->f_tag, f);
67 break;
68
69 case XS_HTML_ATTR:
70- fprintf(f, " %s", h->content);
71- break;
72+ fprintf(f, " ");
73+ /* fallthrough */
74
75 case XS_HTML_TEXT:
76 fprintf(f, "%s", h->content);
77 break;
78 }
79
80+ /* follow the chain */
81+ xs_html_render_f(h->next, f);
82+
83 xs_free(h->content);
84 xs_free(h);
85 }
+1,
-1
1@@ -1 +1 @@
2-/* f27e092c79ca6e2e96f83e0d4c3dbc73d737ffaa 2023-12-03T17:12:47+01:00 */
3+/* 1b21549513460489504a2caa4127607c914a10da 2023-12-03T23:45:32+01:00 */