diff options
| author | 2023-12-03 23:47:25 +0100 | |
|---|---|---|
| committer | 2023-12-03 23:47:25 +0100 | |
| commit | b17aa7d5229c90724ca1b8c87f4ed62f46b6cb3f (patch) | |
| tree | eb8b0e311ca739286a5749ddaab6b102a7a2c9e3 /xs_html.h | |
| parent | Backport from xs. (diff) | |
| download | penes-snac2-b17aa7d5229c90724ca1b8c87f4ed62f46b6cb3f.tar.gz penes-snac2-b17aa7d5229c90724ca1b8c87f4ed62f46b6cb3f.tar.xz penes-snac2-b17aa7d5229c90724ca1b8c87f4ed62f46b6cb3f.zip | |
Backport from xs.
Diffstat (limited to 'xs_html.h')
| -rw-r--r-- | xs_html.h | 57 |
1 files changed, 23 insertions, 34 deletions
| @@ -203,61 +203,50 @@ xs_html *_xs_html_container(xs_html *var[]) | |||
| 203 | void xs_html_render_f(xs_html *h, FILE *f) | 203 | void xs_html_render_f(xs_html *h, FILE *f) |
| 204 | /* renders the tag and its subtags into a file */ | 204 | /* renders the tag and its subtags into a file */ |
| 205 | { | 205 | { |
| 206 | xs_html *st; | 206 | if (h == NULL) |
| 207 | return; | ||
| 207 | 208 | ||
| 208 | switch (h->type) { | 209 | switch (h->type) { |
| 209 | case XS_HTML_TAG: | 210 | case XS_HTML_TAG: |
| 210 | case XS_HTML_SCTAG: | ||
| 211 | fprintf(f, "<%s", h->content); | 211 | fprintf(f, "<%s", h->content); |
| 212 | 212 | ||
| 213 | /* render the attributes */ | 213 | /* attributes */ |
| 214 | st = h->f_attr; | 214 | xs_html_render_f(h->f_attr, f); |
| 215 | while (st) { | ||
| 216 | xs_html *nst = st->next; | ||
| 217 | xs_html_render_f(st, f); | ||
| 218 | st = nst; | ||
| 219 | } | ||
| 220 | 215 | ||
| 221 | if (h->type == XS_HTML_SCTAG) { | 216 | fprintf(f, ">"); |
| 222 | /* self-closing tags should not have subtags */ | ||
| 223 | fprintf(f, "/>"); | ||
| 224 | } | ||
| 225 | else { | ||
| 226 | fprintf(f, ">"); | ||
| 227 | 217 | ||
| 228 | /* render the subtags */ | 218 | /* sub-tags */ |
| 229 | st = h->f_tag; | 219 | xs_html_render_f(h->f_tag, f); |
| 230 | while (st) { | ||
| 231 | xs_html *nst = st->next; | ||
| 232 | xs_html_render_f(st, f); | ||
| 233 | st = nst; | ||
| 234 | } | ||
| 235 | 220 | ||
| 236 | fprintf(f, "</%s>", h->content); | 221 | fprintf(f, "</%s>", h->content); |
| 237 | } | 222 | break; |
| 223 | |||
| 224 | case XS_HTML_SCTAG: | ||
| 225 | fprintf(f, "<%s", h->content); | ||
| 238 | 226 | ||
| 227 | /* attributes */ | ||
| 228 | xs_html_render_f(h->f_attr, f); | ||
| 229 | |||
| 230 | fprintf(f, "/>"); | ||
| 239 | break; | 231 | break; |
| 240 | 232 | ||
| 241 | case XS_HTML_CONTAINER: | 233 | case XS_HTML_CONTAINER: |
| 242 | /* render the subtags and nothing more */ | 234 | /* sub-tags */ |
| 243 | st = h->f_tag; | 235 | xs_html_render_f(h->f_tag, f); |
| 244 | while (st) { | ||
| 245 | xs_html *nst = st->next; | ||
| 246 | xs_html_render_f(st, f); | ||
| 247 | st = nst; | ||
| 248 | } | ||
| 249 | |||
| 250 | break; | 236 | break; |
| 251 | 237 | ||
| 252 | case XS_HTML_ATTR: | 238 | case XS_HTML_ATTR: |
| 253 | fprintf(f, " %s", h->content); | 239 | fprintf(f, " "); |
| 254 | break; | 240 | /* fallthrough */ |
| 255 | 241 | ||
| 256 | case XS_HTML_TEXT: | 242 | case XS_HTML_TEXT: |
| 257 | fprintf(f, "%s", h->content); | 243 | fprintf(f, "%s", h->content); |
| 258 | break; | 244 | break; |
| 259 | } | 245 | } |
| 260 | 246 | ||
| 247 | /* follow the chain */ | ||
| 248 | xs_html_render_f(h->next, f); | ||
| 249 | |||
| 261 | xs_free(h->content); | 250 | xs_free(h->content); |
| 262 | xs_free(h); | 251 | xs_free(h); |
| 263 | } | 252 | } |