diff options
| author | 2023-11-20 20:28:20 +0100 | |
|---|---|---|
| committer | 2023-11-20 20:28:20 +0100 | |
| commit | 1ad4a936496868e770b709f33390c5abce0487da (patch) | |
| tree | f30b51eace2de2e68e8dd2bfc3efd3c1b052f9d9 /xs_html.h | |
| parent | html_actor_icon() returns an xs_str instead of adding to another one. (diff) | |
| download | penes-snac2-1ad4a936496868e770b709f33390c5abce0487da.tar.gz penes-snac2-1ad4a936496868e770b709f33390c5abce0487da.tar.xz penes-snac2-1ad4a936496868e770b709f33390c5abce0487da.zip | |
html_actor_icon() uses xs_html.
Diffstat (limited to 'xs_html.h')
| -rw-r--r-- | xs_html.h | 44 |
1 files changed, 25 insertions, 19 deletions
| @@ -12,12 +12,15 @@ xs_html *xs_html_attr(char *key, char *value); | |||
| 12 | xs_html *xs_html_text(char *content); | 12 | xs_html *xs_html_text(char *content); |
| 13 | xs_html *xs_html_raw(char *content); | 13 | xs_html *xs_html_raw(char *content); |
| 14 | 14 | ||
| 15 | xs_html *xs_html_add(xs_html *tag, xs_html *data); | 15 | xs_html *_xs_html_add(xs_html *tag, xs_html *var[]); |
| 16 | #define xs_html_add(tag, ...) _xs_html_add(tag, (xs_html *[]) { __VA_ARGS__, NULL }) | ||
| 16 | 17 | ||
| 17 | xs_html *_xs_html_tag(char *tag, xs_html *var[]); | 18 | xs_html *_xs_html_tag(char *tag, xs_html *var[]); |
| 18 | #define xs_html_tag(tag, ...) _xs_html_tag(tag, (xs_html *[]) { __VA_ARGS__, NULL }) | 19 | #define xs_html_tag(tag, ...) _xs_html_tag(tag, (xs_html *[]) { __VA_ARGS__, NULL }) |
| 20 | |||
| 19 | xs_html *_xs_html_sctag(char *tag, xs_html *var[]); | 21 | xs_html *_xs_html_sctag(char *tag, xs_html *var[]); |
| 20 | #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 | |||
| 21 | xs_str *_xs_html_render(xs_html *h, xs_str *s); | 24 | xs_str *_xs_html_render(xs_html *h, xs_str *s); |
| 22 | #define xs_html_render(h) _xs_html_render(h, xs_str_new(NULL)) | 25 | #define xs_html_render(h) _xs_html_render(h, xs_str_new(NULL)) |
| 23 | 26 | ||
| @@ -127,28 +130,32 @@ xs_html *xs_html_raw(char *content) | |||
| 127 | } | 130 | } |
| 128 | 131 | ||
| 129 | 132 | ||
| 130 | xs_html *xs_html_add(xs_html *tag, xs_html *data) | 133 | xs_html *_xs_html_add(xs_html *tag, xs_html *var[]) |
| 131 | /* add data (attrs, tags or text) to a tag */ | 134 | /* add data (attrs, tags or text) to a tag */ |
| 132 | { | 135 | { |
| 133 | xs_html **first; | 136 | while (*var) { |
| 134 | xs_html **last; | 137 | xs_html *data = *var++; |
| 135 | 138 | ||
| 136 | if (data->type == XS_HTML_ATTR) { | 139 | xs_html **first; |
| 137 | first = &tag->f_attr; | 140 | xs_html **last; |
| 138 | last = &tag->l_attr; | ||
| 139 | } | ||
| 140 | else { | ||
| 141 | first = &tag->f_tag; | ||
| 142 | last = &tag->l_tag; | ||
| 143 | } | ||
| 144 | 141 | ||
| 145 | if (*first == NULL) | 142 | if (data->type == XS_HTML_ATTR) { |
| 146 | *first = data; | 143 | first = &tag->f_attr; |
| 144 | last = &tag->l_attr; | ||
| 145 | } | ||
| 146 | else { | ||
| 147 | first = &tag->f_tag; | ||
| 148 | last = &tag->l_tag; | ||
| 149 | } | ||
| 147 | 150 | ||
| 148 | if (*last != NULL) | 151 | if (*first == NULL) |
| 149 | (*last)->next = data; | 152 | *first = data; |
| 150 | 153 | ||
| 151 | *last = data; | 154 | if (*last != NULL) |
| 155 | (*last)->next = data; | ||
| 156 | |||
| 157 | *last = data; | ||
| 158 | } | ||
| 152 | 159 | ||
| 153 | return tag; | 160 | return tag; |
| 154 | } | 161 | } |
| @@ -162,8 +169,7 @@ static xs_html *_xs_html_tag_t(xs_html_type type, char *tag, xs_html *var[]) | |||
| 162 | a->type = type; | 169 | a->type = type; |
| 163 | a->content = xs_dup(tag); | 170 | a->content = xs_dup(tag); |
| 164 | 171 | ||
| 165 | while (*var) | 172 | _xs_html_add(a, var); |
| 166 | xs_html_add(a, *var++); | ||
| 167 | 173 | ||
| 168 | return a; | 174 | return a; |
| 169 | } | 175 | } |