"); + escape_string (html->file, s, " ", "\n"); + break; - assert (s->class == &tab_table_class ) ; + case TEXT_ITEM_LOG: + print_title_tag (html->file, "PRE", s); /* should be
"); + fprintf (html->file, "
*/
+ break;
- switch (s->type)
+ case TEXT_ITEM_EJECT_PAGE:
+ /* Nothing to do. */
+ break;
+ }
+ }
+ else if (is_message_item (output_item))
{
- case SOM_TABLE:
- output_tab_table ( this, (struct tab_table *) s->ext);
- break;
- case SOM_CHART:
- link_image (x->file, ((struct chart *)s->ext)->file_name);
- break;
- default:
- NOT_REACHED ();
+ const struct message_item *message_item = to_message_item (output_item);
+ char *s = msg_to_string (message_item_get_msg (message_item));
+ print_title_tag (html->file, "P", s);
+ free (s);
}
}
-/* Write LENGTH characters in TEXT to file F, escaping characters
- as necessary for HTML. Spaces are replaced by SPACE, which
- should be " " or " ". */
+/* Write TEXT to file F, escaping characters as necessary for HTML. Spaces are
+ replaced by SPACE, which should be " " or " " New-lines are replaced by
+ NEWLINE, which might be "
" or "\n" or something else appropriate. */
static void
-escape_string (FILE *file,
- const char *text, size_t length,
- const char *space)
+escape_string (FILE *file, const char *text,
+ const char *space, const char *newline)
{
- while (length-- > 0)
+ for (;;)
{
char c = *text++;
switch (c)
{
+ case 0:
+ return;
+ case '\n':
+ fputs (newline, file);
+ break;
case '&':
fputs ("&", file);
break;
@@ -240,6 +325,9 @@ escape_string (FILE *file,
case ' ':
fputs (space, file);
break;
+ case '"':
+ fputs (""", file);
+ break;
default:
putc (c, file);
break;
@@ -247,172 +335,286 @@ escape_string (FILE *file,
}
}
-/* Outputs content for a cell with options OPTS and contents
- TEXT. */
-void
-html_put_cell_contents (struct outp_driver *this,
- unsigned int opts, const struct substring text)
+static void
+escape_tag (FILE *file, const char *tag,
+ const char *text, const char *space, const char *newline)
{
- struct html_driver_ext *x = this->ext;
+ if (!text || !*text)
+ return;
- if (!(opts & TAB_EMPTY))
- {
- if (opts & TAB_EMPH)
- fputs ("", x->file);
- if (opts & TAB_FIX)
- {
- fputs ("", x->file);
- escape_string (x->file, ss_data (text), ss_length (text), " ");
- fputs ("", x->file);
- }
- else
- {
- size_t initial_spaces = ss_span (text, ss_cstr (CC_SPACES));
- escape_string (x->file,
- ss_data (text) + initial_spaces,
- ss_length (text) - initial_spaces,
- " ");
- }
- if (opts & TAB_EMPH)
- fputs ("", x->file);
- }
+ fprintf (file, "<%s>", tag);
+ escape_string (file, text, space, newline);
+ fprintf (file, "%s>", tag);
}
-/* Write table T to THIS output driver. */
-static void
-output_tab_table (struct outp_driver *this, struct tab_table *t)
+static const char *
+border_to_css (int border)
{
- struct html_driver_ext *x = this->ext;
-
- if (t->nr == 1 && t->nc == 1)
+ switch (border)
{
- fputs ("
", x->file); - html_put_cell_contents (this, t->ct[0], *t->cc); - fputs ("
\n", x->file); + case TABLE_STROKE_NONE: + return NULL; - return; + case TABLE_STROKE_SOLID: + return "solid"; + + case TABLE_STROKE_DASHED: + return "dashed"; + + case TABLE_STROKE_THICK: + return "thick solid"; + + case TABLE_STROKE_THIN: + return "thin solid"; + + case TABLE_STROKE_DOUBLE: + return "double"; + + default: + return NULL; } - fputs ("or | tag. */ - tag = (r < t->t || r >= t->nr - t->b - || c < t->l || c >= t->nc - t->r) ? "TH" : "TD"; - fprintf (x->file, " <%s ALIGN=%s", - tag, - (*ct & TAB_ALIGN_MASK) == TAB_LEFT ? "LEFT" - : (*ct & TAB_ALIGN_MASK) == TAB_RIGHT ? "RIGHT" - : "CENTER"); - if (*ct & TAB_JOIN) - { - if (j->x2 - j->x1 > 1) - fprintf (x->file, " COLSPAN=%d", j->x2 - j->x1); - if (j->y2 - j->y1 > 1) - fprintf (x->file, " ROWSPAN=%d", j->y2 - j->y1); - } - putc ('>', x->file); - - /* Output cell contents. */ - html_put_cell_contents (this, *ct, *cc); - - /* Output | or . */ - fprintf (x->file, "%s>\n", tag); - } - fputs ("
---|
or | tag. */
+ 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);
+
+ enum table_halign halign = table_halign_interpret (
+ cell.style->cell_style.halign, cell.options & TAB_NUMERIC);
+ if (halign != TABLE_HALIGN_LEFT)
+ {
+ fprintf (html->file, " ALIGN=\"%s\"",
+ (halign == TABLE_HALIGN_RIGHT ? "RIGHT"
+ : halign == TABLE_HALIGN_CENTER ? "CENTER"
+ : "CHAR"));
+ if (cell.style->cell_style.decimal_char)
+ fprintf (html->file, " CHAR=\"%c\"",
+ cell.style->cell_style.decimal_char);
+ }
+
+ if (cell.style->cell_style.valign != TABLE_VALIGN_TOP)
+ fprintf (html->file, " VALIGN=\"%s\"",
+ (cell.style->cell_style.valign == TABLE_VALIGN_BOTTOM
+ ? "BOTTOM" : "MIDDLE"));
+
+ colspan = table_cell_colspan (&cell);
+ if (colspan > 1)
+ fprintf (html->file, " COLSPAN=\"%d\"", colspan);
+
+ rowspan = table_cell_rowspan (&cell);
+ if (rowspan > 1)
+ fprintf (html->file, " ROWSPAN=\"%d\"", rowspan);
+
+ if (html->borders)
+ {
+ /* Cell borders. */
+ int n_borders = 0;
+
+ struct cell_color color;
+ top = table_get_rule (t, TABLE_VERT, x, y, &color);
+ put_border (html->file, &n_borders, top, "top");
+
+ if (y + rowspan == table_nr (t))
+ {
+ bottom = table_get_rule (t, TABLE_VERT, x, y + rowspan,
+ &color);
+ put_border (html->file, &n_borders, bottom, "bottom");
+ }
+
+ left = table_get_rule (t, TABLE_HORZ, x, y, &color);
+ put_border (html->file, &n_borders, left, "left");
+
+ if (x + colspan == table_nc (t))
+ {
+ right = table_get_rule (t, TABLE_HORZ, x + colspan, y,
+ &color);
+ put_border (html->file, &n_borders, right, "right");
+ }
+
+ if (n_borders > 0)
+ fputs ("\"", html->file);
+ }
+
+ putc ('>', html->file);
+
+ /* Output cell contents. */
+ const char *s = cell.text;
+ if (cell.options & TAB_FIX)
+ escape_tag (html->file, "TT", s, " ", " "); + else + { + s += strspn (s, CC_SPACES); + escape_string (html->file, s, " ", " "); + } + + if (cell.n_subscripts) + { + fputs ("", html->file); + for (size_t i = 0; i < cell.n_subscripts; i++) + { + if (i) + putc (',', html->file); + escape_string (html->file, cell.subscripts[i], + " ", " "); + } + fputs ("", html->file); + } + if (cell.superscript) + escape_tag (html->file, "SUP", cell.superscript, " ", " "); + html_put_footnote_markers (html, cell.footnotes, cell.n_footnotes); + + /* Output | or . */
+ fprintf (html->file, "%s>\n", tag);
+
+ next_1:
+ x = cell.d[TABLE_HORZ][1];
+ }
+ fputs ("
---|