+ fputs ("</tr>\n", html->file);
+ }
+ fputs ("</thead>\n", html->file);
+ }
+
+ fputs ("<tbody>\n", html->file);
+ for (int y = 0; y < body->n[V]; y++)
+ {
+ fputs ("<tr>\n", html->file);
+ for (int x = 0; x < body->n[H]; )
+ {
+ struct table_cell cell;
+ table_get_cell (body, x, y, &cell);
+ if (x == cell.d[TABLE_HORZ][0] && y == cell.d[TABLE_VERT][0])
+ {
+ bool is_header = (y < body->h[V][0]
+ || y >= body->n[V] - body->h[V][1]
+ || x < body->h[H][0]
+ || x >= body->n[H] - body->h[H][1]);
+ const char *tag = is_header ? "th" : "td";
+ html_put_table_cell (html, pt, &cell, tag, body);
+ }
+
+ x = cell.d[TABLE_HORZ][1];
+ }
+ fputs ("</tr>\n", html->file);
+ }
+ fputs ("</tbody>\n", html->file);
+
+ if (caption || footnotes)
+ {
+ fprintf (html->file, "<tfoot>\n");
+
+ if (caption)
+ {
+ fputs ("<tr>\n", html->file);
+
+ struct table_cell cell;
+ table_get_cell (caption, 0, 0, &cell);
+ cell.d[H][1] = body->n[H];
+ html_put_table_cell (html, pt, &cell, "td", NULL);
+
+ fputs ("</tr>\n", html->file);
+ }
+
+ if (footnotes)
+ for (size_t y = 0; y < footnotes->n[V]; y++)
+ {
+ fputs ("<tr>\n", html->file);
+
+ struct table_cell cell;
+ table_get_cell (footnotes, 0, y, &cell);
+ cell.d[H][1] = body->n[H];
+ html_put_table_cell (html, pt, &cell, "td", NULL);