+ put_style (&style, "font-family", "\"");
+ escape_string (html->file, fs->typeface, " ", "\n");
+ putc ('"', html->file);
+ }
+ if (fs->bold)
+ put_style (&style, "font-weight", "bold");
+ if (fs->italic)
+ put_style (&style, "font-style", "italic");
+ if (fs->underline)
+ put_style (&style, "text-decoration", "underline");
+ if (fs->size)
+ {
+ char buf[32];
+ snprintf (buf, sizeof buf, "%dpt", fs->size);
+ put_style (&style, "font-size", buf);
+ }
+
+ if (t && html->borders)
+ {
+ put_border (t, cell, &style, V, 0, 0, "top");
+ put_border (t, cell, &style, H, 0, 0, "left");
+
+ if (cell->d[V][1] == t->n[V])
+ put_border (t, cell, &style, V, 0, 1, "bottom");
+ if (cell->d[H][1] == t->n[H])
+ put_border (t, cell, &style, H, 1, 0, "right");
+ }
+ style_end (&style);
+
+ int colspan = table_cell_colspan (cell);
+ if (colspan > 1)
+ fprintf (html->file, " colspan=\"%d\"", colspan);
+
+ int rowspan = table_cell_rowspan (cell);
+ if (rowspan > 1)
+ fprintf (html->file, " rowspan=\"%d\"", rowspan);
+
+ putc ('>', html->file);
+
+ const char *s = ds_cstr (&body);
+ s += strspn (s, CC_SPACES);
+ escape_string (html->file, s, " ", "<br>");
+ ds_destroy (&body);
+
+ const struct pivot_value_ex *ex = pivot_value_ex (cell->value);
+ if (ex->n_subscripts)
+ {
+ fputs ("<sub>", html->file);
+ for (size_t i = 0; i < ex->n_subscripts; i++)
+ {
+ if (i)
+ putc (',', html->file);
+ escape_string (html->file, ex->subscripts[i], " ", "<br>");
+ }
+ fputs ("</sub>", html->file);
+ }
+ if (ex->n_footnotes > 0)
+ {
+ fputs ("<sup>", html->file);
+ size_t n_footnotes = 0;
+ for (size_t i = 0; i < ex->n_footnotes; i++)
+ {
+ const struct pivot_footnote *f
+ = pt->footnotes[ex->footnote_indexes[i]];
+ if (f->show)
+ {
+ if (n_footnotes++ > 0)
+ putc (',', html->file);
+
+ char *marker = pivot_footnote_marker_string (f, pt);
+ escape_string (html->file, marker, " ", "<br>");
+ free (marker);
+ }
+ }
+ 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]; )