+ for (y = 0; y < table_nr (t); y++)
+ {
+ int x;
+
+ fputs ("<tr>\n", html->file);
+ for (x = 0; x < table_nc (t);)
+ {
+ struct table_cell cell;
+ const char *tag;
+
+ table_get_cell (t, x, y, &cell);
+ if (x != cell.d[TABLE_HORZ][0] || y != cell.d[TABLE_VERT][0])
+ goto next_1;
+
+ /* output <td> or <th> tag. */
+ bool is_header = (y < table_ht (t)
+ || y >= table_nr (t) - table_hb (t)
+ || x < table_hl (t)
+ || x >= table_nc (t) - table_hr (t));
+ tag = is_header ? "th" : "td";
+ fprintf (html->file, "<%s", tag);
+
+ struct css_style *style = style_start (html->file);
+ enum table_halign halign = table_halign_interpret (
+ cell.style->cell_style.halign, cell.options & TAB_NUMERIC);
+
+ switch (halign)
+ {
+ case TABLE_HALIGN_RIGHT:
+ put_style (style, "text-align", "right");
+ break;
+ case TABLE_HALIGN_CENTER:
+ put_style (style, "text-align", "center");
+ break;
+ default:
+ /* Do nothing */
+ break;
+ }
+
+ if (cell.style->cell_style.valign != TABLE_VALIGN_TOP)
+ {
+ put_style (style, "vertical-align",
+ (cell.style->cell_style.valign == TABLE_VALIGN_BOTTOM
+ ? "bottom" : "middle"));
+ }
+
+ int colspan = table_cell_colspan (&cell);
+ int rowspan = table_cell_rowspan (&cell);
+
+ if (html->borders)
+ {
+ /* Cell borders. */
+ struct cell_color color;
+
+ int top = table_get_rule (t, TABLE_VERT, x, y, &color);
+ put_border (style, top, "top");
+
+ if (y + rowspan == table_nr (t))
+ {
+ int bottom = table_get_rule (t, TABLE_VERT, x, y + rowspan,
+ &color);
+ put_border (style, bottom, "bottom");
+ }
+
+ int left = table_get_rule (t, TABLE_HORZ, x, y, &color);
+ put_border (style, left, "left");
+
+ if (x + colspan == table_nc (t))
+ {
+ int right = table_get_rule (t, TABLE_HORZ, x + colspan, y,
+ &color);
+ put_border (style, right, "right");
+ }
+ }
+ style_end (style);
+
+ if (colspan > 1)
+ fprintf (html->file, " colspan=\"%d\"", colspan);
+
+ if (rowspan > 1)
+ fprintf (html->file, " rowspan=\"%d\"", rowspan);
+
+ putc ('>', html->file);
+
+ /* Output cell contents. */
+ const char *s = cell.text;
+ if (cell.options & TAB_FIX)
+ escape_tag (html->file, "tt", s, " ", "<br>");
+ else
+ {
+ s += strspn (s, CC_SPACES);
+ escape_string (html->file, s, " ", "<br>");
+ }
+
+ if (cell.n_subscripts)
+ {
+ fputs ("<sub>", html->file);
+ for (size_t i = 0; i < cell.n_subscripts; i++)
+ {
+ if (i)
+ putc (',', html->file);
+ escape_string (html->file, cell.subscripts[i],
+ " ", "<br>");
+ }
+ fputs ("</sub>", html->file);
+ }
+ if (cell.superscript)
+ escape_tag (html->file, "sup", cell.superscript, " ", "<br>");
+ html_put_footnote_markers (html, cell.footnotes, cell.n_footnotes);
+
+ /* output </th> or </td>. */
+ fprintf (html->file, "</%s>\n", tag);
+
+ next_1:
+ x = cell.d[TABLE_HORZ][1];
+ }
+ fputs ("</tr>\n", html->file);
+ }