summaryrefslogtreecommitdiff
path: root/xs_html.h
diff options
context:
space:
mode:
Diffstat (limited to 'xs_html.h')
-rw-r--r--xs_html.h57
1 files changed, 23 insertions, 34 deletions
diff --git a/xs_html.h b/xs_html.h
index 58a50b6..297b989 100644
--- a/xs_html.h
+++ b/xs_html.h
@@ -203,61 +203,50 @@ xs_html *_xs_html_container(xs_html *var[])
203void xs_html_render_f(xs_html *h, FILE *f) 203void 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}