diff options
-rw-r--r-- | html.c | 13 | ||||
-rw-r--r-- | html.h | 3 | ||||
-rw-r--r-- | man_html.c | 18 | ||||
-rw-r--r-- | mdoc_html.c | 22 | ||||
-rw-r--r-- | tbl_html.c | 105 |
5 files changed, 112 insertions, 49 deletions
@@ -90,6 +90,7 @@ static const char *const htmlattrs[ATTR_MAX] = { "id", /* ATTR_ID */ "summary", /* ATTR_SUMMARY */ "align", /* ATTR_ALIGN */ + "colspan", /* ATTR_COLSPAN */ }; static void print_spec(struct html *, enum roffdeco, @@ -581,8 +582,14 @@ print_tagq(struct html *h, const struct tag *until) struct tag *tag; while ((tag = h->tags.head) != NULL) { + /* + * Remember to close out and nullify the current + * meta-font and table, if applicable. + */ if (tag == h->metaf) h->metaf = NULL; + if (tag == h->tblt) + h->tblt = NULL; print_ctag(h, tag->tag); h->tags.head = tag->next; free(tag); @@ -600,8 +607,14 @@ print_stagq(struct html *h, const struct tag *suntil) while ((tag = h->tags.head) != NULL) { if (suntil && tag == suntil) return; + /* + * Remember to close out and nullify the current + * meta-font and table, if applicable. + */ if (tag == h->metaf) h->metaf = NULL; + if (tag == h->tblt) + h->tblt = NULL; print_ctag(h, tag->tag); h->tags.head = tag->next; free(tag); @@ -67,6 +67,7 @@ enum htmlattr { ATTR_ID, ATTR_SUMMARY, ATTR_ALIGN, + ATTR_COLSPAN, ATTR_MAX }; @@ -117,6 +118,7 @@ struct html { #define HTML_NONOSPACE (1 << 4) struct tagq tags; /* stack of open tags */ struct rofftbl tbl; /* current table */ + struct tag *tblt; /* current open table scope */ void *symtab; /* character-escapes */ char *base_man; /* base for manpage href */ char *base_includes; /* base for include href */ @@ -136,6 +138,7 @@ struct tag *print_otag(struct html *, enum htmltag, void print_tagq(struct html *, const struct tag *); void print_stagq(struct html *, const struct tag *); void print_text(struct html *, const char *); +void print_tblclose(struct html *); void print_tbl(struct html *, const struct tbl_span *); void bufcat_su(struct html *, const char *, @@ -216,18 +216,32 @@ print_man_node(MAN_ARGS) print_otag(h, TAG_BR, 0, NULL); return; case (MAN_TBL): + /* + * This will take care of initialising all of the table + * state data for the first table, then tearing it down + * for the last one. + */ print_tbl(h, n->span); return; default: /* * Close out scope of font prior to opening a macro - * scope. Assert that the metafont is on the top of the - * stack (it's never nested). + * scope. */ if (HTMLFONT_NONE != h->metac) { h->metal = h->metac; h->metac = HTMLFONT_NONE; } + + /* + * Close out the current table, if it's open, and unset + * the "meta" table state. This will be reopened on the + * next table element. + */ + if (h->tblt) { + print_tblclose(h); + t = h->tags.head; + } if (mans[n->tok].pre) child = (*mans[n->tok].pre)(m, n, mh, h); break; diff --git a/mdoc_html.c b/mdoc_html.c index a3708728..1697ac32 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -420,14 +420,32 @@ print_mdoc_node(MDOC_ARGS) child = mdoc_root_pre(m, n, h); break; case (MDOC_TEXT): + /* No tables in this mode... */ + assert(NULL == h->tblt); if (' ' == *n->string && MDOC_LINE & n->flags) print_otag(h, TAG_BR, 0, NULL); print_text(h, n->string); return; case (MDOC_TBL): + /* + * This will take care of initialising all of the table + * state data for the first table, then tearing it down + * for the last one. + */ print_tbl(h, n->span); - break; + return; default: + /* + * Close out the current table, if it's open, and unset + * the "meta" table state. This will be reopened on the + * next table element. + */ + if (h->tblt) { + print_tblclose(h); + t = h->tags.head; + } + + assert(NULL == h->tblt); if (mdocs[n->tok].pre && ENDBODY_NOT == n->end) child = (*mdocs[n->tok].pre)(m, n, h); break; @@ -455,8 +473,6 @@ print_mdoc_node(MDOC_ARGS) case (MDOC_ROOT): mdoc_root_post(m, n, h); break; - case (MDOC_TBL): - break; default: if (mdocs[n->tok].post && ENDBODY_NOT == n->end) (*mdocs[n->tok].post)(m, n, h); @@ -27,6 +27,7 @@ #include "out.h" #include "html.h" +static void html_tblopen(struct html *, const struct tbl_span *); static size_t html_tbl_len(size_t, void *); static size_t html_tbl_strlen(const char *, void *); @@ -46,89 +47,105 @@ html_tbl_strlen(const char *p, void *arg) return(strlen(p)); } +static void +html_tblopen(struct html *h, const struct tbl_span *sp) +{ + const struct tbl_head *hp; + struct htmlpair tag; + struct roffsu su; + struct roffcol *col; + + if (TBL_SPAN_FIRST & sp->flags) { + h->tbl.len = html_tbl_len; + h->tbl.slen = html_tbl_strlen; + tblcalc(&h->tbl, sp); + } + + assert(NULL == h->tblt); + PAIR_CLASS_INIT(&tag, "tbl"); + h->tblt = print_otag(h, TAG_TABLE, 1, &tag); + + for (hp = sp->head; hp; hp = hp->next) { + bufinit(h); + col = &h->tbl.cols[hp->ident]; + SCALE_HS_INIT(&su, col->width); + bufcat_su(h, "width", &su); + PAIR_STYLE_INIT(&tag, h); + print_otag(h, TAG_COL, 1, &tag); + } + + print_otag(h, TAG_TBODY, 0, NULL); +} + +void +print_tblclose(struct html *h) +{ + + assert(h->tblt); + print_tagq(h, h->tblt); + h->tblt = NULL; +} + void print_tbl(struct html *h, const struct tbl_span *sp) { const struct tbl_head *hp; const struct tbl_dat *dp; - struct tag *tt; struct htmlpair tag; - struct roffsu su; - struct roffcol *col; + struct tag *tt; /* Inhibit printing of spaces: we do padding ourselves. */ + if (NULL == h->tblt) + html_tblopen(h, sp); + + assert(h->tblt); + h->flags |= HTML_NONOSPACE; h->flags |= HTML_NOSPACE; - /* First pass: calculate widths. */ - - if (TBL_SPAN_FIRST & sp->flags) { - h->tbl.len = html_tbl_len; - h->tbl.slen = html_tbl_strlen; - tblcalc(&h->tbl, sp); - } + tt = print_otag(h, TAG_TR, 0, NULL); switch (sp->pos) { case (TBL_SPAN_HORIZ): /* FALLTHROUGH */ case (TBL_SPAN_DHORIZ): + PAIR_INIT(&tag, ATTR_COLSPAN, "0"); + print_otag(h, TAG_TD, 1, &tag); break; default: - PAIR_CLASS_INIT(&tag, "tbl"); - print_otag(h, TAG_TABLE, 1, &tag); - print_otag(h, TAG_TR, 0, NULL); - - /* Iterate over template headers. */ - dp = sp->first; for (hp = sp->head; hp; hp = hp->next) { + print_stagq(h, tt); + print_otag(h, TAG_TD, 0, NULL); + switch (hp->pos) { case (TBL_HEAD_VERT): /* FALLTHROUGH */ case (TBL_HEAD_DVERT): continue; case (TBL_HEAD_DATA): - break; - } - - /* - * For the time being, use the simplest possible - * table styling: setting the widths of data - * columns. - */ - - col = &h->tbl.cols[hp->ident]; - SCALE_HS_INIT(&su, col->width); - bufcat_su(h, "width", &su); - PAIR_STYLE_INIT(&tag, h); - tt = print_otag(h, TAG_TD, 1, &tag); - - if (dp) { - switch (dp->layout->pos) { - case (TBL_CELL_DOWN): - break; - default: - if (NULL == dp->string) - break; - print_text(h, dp->string); + if (NULL == dp) break; - } + if (TBL_CELL_DOWN != dp->layout->pos) + if (dp->string) + print_text(h, dp->string); dp = dp->next; + break; } - - print_tagq(h, tt); } break; } - h->flags &= ~HTML_NONOSPACE; + print_tagq(h, tt); - /* Close out column specifiers on the last span. */ + h->flags &= ~HTML_NONOSPACE; if (TBL_SPAN_LAST & sp->flags) { assert(h->tbl.cols); free(h->tbl.cols); h->tbl.cols = NULL; + print_tblclose(h); } + } |