Backport from xs.

This commit is contained in:
default 2023-12-08 06:13:08 +01:00
parent ce0e782c94
commit 8bdebf278a
2 changed files with 14 additions and 27 deletions

View File

@ -42,10 +42,8 @@ typedef enum {
struct xs_html { struct xs_html {
xs_html_type type; xs_html_type type;
xs_str *content; xs_str *content;
xs_html *f_attr; xs_html *attrs;
xs_html *l_attr; xs_html *tags;
xs_html *f_tag;
xs_html *l_tag;
xs_html *next; xs_html *next;
}; };
@ -140,25 +138,14 @@ xs_html *_xs_html_add(xs_html *tag, xs_html *var[])
while (*var) { while (*var) {
xs_html *data = *var++; xs_html *data = *var++;
xs_html **first;
xs_html **last;
if (data->type == XS_HTML_ATTR) { if (data->type == XS_HTML_ATTR) {
first = &tag->f_attr; data->next = tag->attrs;
last = &tag->l_attr; tag->attrs = data;
} }
else { else {
first = &tag->f_tag; data->next = tag->tags;
last = &tag->l_tag; tag->tags = data;
} }
if (*first == NULL)
*first = data;
if (*last != NULL)
(*last)->next = data;
*last = data;
} }
return tag; return tag;
@ -206,17 +193,20 @@ void xs_html_render_f(xs_html *h, FILE *f)
if (h == NULL) if (h == NULL)
return; return;
/* follow the chain */
xs_html_render_f(h->next, f);
switch (h->type) { switch (h->type) {
case XS_HTML_TAG: case XS_HTML_TAG:
fprintf(f, "<%s", h->content); fprintf(f, "<%s", h->content);
/* attributes */ /* attributes */
xs_html_render_f(h->f_attr, f); xs_html_render_f(h->attrs, f);
fprintf(f, ">"); fprintf(f, ">");
/* sub-tags */ /* sub-tags */
xs_html_render_f(h->f_tag, f); xs_html_render_f(h->tags, f);
fprintf(f, "</%s>", h->content); fprintf(f, "</%s>", h->content);
break; break;
@ -225,14 +215,14 @@ void xs_html_render_f(xs_html *h, FILE *f)
fprintf(f, "<%s", h->content); fprintf(f, "<%s", h->content);
/* attributes */ /* attributes */
xs_html_render_f(h->f_attr, f); xs_html_render_f(h->attrs, f);
fprintf(f, "/>"); fprintf(f, "/>");
break; break;
case XS_HTML_CONTAINER: case XS_HTML_CONTAINER:
/* sub-tags */ /* sub-tags */
xs_html_render_f(h->f_tag, f); xs_html_render_f(h->tags, f);
break; break;
case XS_HTML_ATTR: case XS_HTML_ATTR:
@ -244,9 +234,6 @@ void xs_html_render_f(xs_html *h, FILE *f)
break; break;
} }
/* follow the chain */
xs_html_render_f(h->next, f);
xs_free(h->content); xs_free(h->content);
xs_free(h); xs_free(h);
} }

View File

@ -1 +1 @@
/* 1b21549513460489504a2caa4127607c914a10da 2023-12-03T23:45:32+01:00 */ /* 3582ff265e19407df1d532eb1d90c372fe22ca62 2023-12-08T06:10:40+01:00 */