- for (r = 0; r < t->nr; r++)
- {
- int c;
-
- fputs (" <TR>\n", x->file.file);
- for (c = 0; c < t->nc; c++, ct++)
- {
- struct fixed_string *cc;
- int tag;
- char header[128];
- char *cp;
- struct tab_joined_cell *j = NULL;
-
- cc = t->cc + c + r * t->nc;
- if (*ct & TAB_JOIN)
- {
- j = (struct tab_joined_cell *) ls_c_str (cc);
- cc = &j->contents;
- if (j->x1 != c || j->y1 != r)
- continue;
- }
-
- if (r < t->t || r >= t->nr - t->b
- || c < t->l || c >= t->nc - t->r)
- tag = 'H';
- else
- tag = 'D';
- cp = stpcpy (header, " <T");
- *cp++ = tag;
-
- switch (*ct & TAB_ALIGN_MASK)
- {
- case TAB_RIGHT:
- cp = stpcpy (cp, " ALIGN=RIGHT");
- break;
- case TAB_LEFT:
- break;
- case TAB_CENTER:
- cp = stpcpy (cp, " ALIGN=CENTER");
- break;
- default:
- assert (0);
- }
-
- if (*ct & TAB_JOIN)
- {
- if (j->x2 - j->x1 > 1)
- cp = spprintf (cp, " COLSPAN=%d", j->x2 - j->x1);
- if (j->y2 - j->y1 > 1)
- cp = spprintf (cp, " ROWSPAN=%d", j->y2 - j->y1);
-
- cc = &j->contents;
- }
-
- strcpy (cp, ">");
- fputs (header, x->file.file);
-
- if ( ! (*ct & TAB_EMPTY) )
- {
- char *s = ls_c_str (cc);
- size_t l = ls_length (cc);
-
- while (l && isspace ((unsigned char) *s))
- {
- l--;
- s++;
- }
-
- escape_string (x->file.file, s, l);
- }
-
- fprintf (x->file.file, "</T%c>\n", tag);
- }
- fputs (" </TR>\n", x->file.file);
- }
- }
-
- fputs ("</TABLE>\n\n", x->file.file);
+ 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);