diff --git a/xs_html.h b/xs_html.h
index 297b989..1184583 100644
--- a/xs_html.h
+++ b/xs_html.h
@@ -42,10 +42,8 @@ typedef enum {
struct xs_html {
xs_html_type type;
xs_str *content;
- xs_html *f_attr;
- xs_html *l_attr;
- xs_html *f_tag;
- xs_html *l_tag;
+ xs_html *attrs;
+ xs_html *tags;
xs_html *next;
};
@@ -140,25 +138,14 @@ xs_html *_xs_html_add(xs_html *tag, xs_html *var[])
while (*var) {
xs_html *data = *var++;
- xs_html **first;
- xs_html **last;
-
if (data->type == XS_HTML_ATTR) {
- first = &tag->f_attr;
- last = &tag->l_attr;
+ data->next = tag->attrs;
+ tag->attrs = data;
}
else {
- first = &tag->f_tag;
- last = &tag->l_tag;
+ data->next = tag->tags;
+ tag->tags = data;
}
-
- if (*first == NULL)
- *first = data;
-
- if (*last != NULL)
- (*last)->next = data;
-
- *last = data;
}
return tag;
@@ -206,17 +193,20 @@ void xs_html_render_f(xs_html *h, FILE *f)
if (h == NULL)
return;
+ /* follow the chain */
+ xs_html_render_f(h->next, f);
+
switch (h->type) {
case XS_HTML_TAG:
fprintf(f, "<%s", h->content);
/* attributes */
- xs_html_render_f(h->f_attr, f);
+ xs_html_render_f(h->attrs, f);
fprintf(f, ">");
/* sub-tags */
- xs_html_render_f(h->f_tag, f);
+ xs_html_render_f(h->tags, f);
fprintf(f, "%s>", h->content);
break;
@@ -225,14 +215,14 @@ void xs_html_render_f(xs_html *h, FILE *f)
fprintf(f, "<%s", h->content);
/* attributes */
- xs_html_render_f(h->f_attr, f);
+ xs_html_render_f(h->attrs, f);
fprintf(f, "/>");
break;
case XS_HTML_CONTAINER:
/* sub-tags */
- xs_html_render_f(h->f_tag, f);
+ xs_html_render_f(h->tags, f);
break;
case XS_HTML_ATTR:
@@ -244,9 +234,6 @@ void xs_html_render_f(xs_html *h, FILE *f)
break;
}
- /* follow the chain */
- xs_html_render_f(h->next, f);
-
xs_free(h->content);
xs_free(h);
}
diff --git a/xs_version.h b/xs_version.h
index 0e90e31..f25a017 100644
--- a/xs_version.h
+++ b/xs_version.h
@@ -1 +1 @@
-/* 1b21549513460489504a2caa4127607c914a10da 2023-12-03T23:45:32+01:00 */
+/* 3582ff265e19407df1d532eb1d90c372fe22ca62 2023-12-08T06:10:40+01:00 */