+ }
+ fputs ("</sup>", html->file);
+ }
+
+ /* output </th> or </td>. */
+ fprintf (html->file, "</%s>\n", tag);
+}
+
+static void
+html_output_table_layer (struct html_driver *html, const struct pivot_table *pt,
+ const size_t *layer_indexes)
+{
+ struct table *title, *layers, *body, *caption, *footnotes;
+ pivot_output (pt, layer_indexes, true, &title, &layers, &body,
+ &caption, &footnotes, NULL, NULL);
+
+ fputs ("<table", html->file);
+ if (pt->notes)
+ {
+ fputs (" title=\"", html->file);
+ escape_string (html->file, pt->notes, " ", "\n");
+ putc ('"', html->file);
+ }
+ fputs (">\n", html->file);
+
+ if (title)
+ {
+ struct table_cell cell;
+ table_get_cell (title, 0, 0, &cell);
+ html_put_table_cell (html, pt, &cell, "caption", NULL);
+ }
+
+ if (layers)
+ {
+ fputs ("<thead>\n", html->file);
+ for (size_t y = 0; y < layers->n[V]; y++)
+ {
+ fputs ("<tr>\n", html->file);
+
+ struct table_cell cell;
+ table_get_cell (layers, 0, y, &cell);
+ cell.d[H][1] = body->n[H];
+ html_put_table_cell (html, pt, &cell, "td", NULL);
+
+ 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])