From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (kristaps@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p0DEUE58026389 for ; Thu, 13 Jan 2011 09:30:15 -0500 (EST) Received: (from kristaps@localhost) by krisdoz.my.domain (8.14.3/8.14.3/Submit) id p0DEUDK5019024; Thu, 13 Jan 2011 09:30:13 -0500 (EST) Date: Thu, 13 Jan 2011 09:30:13 -0500 (EST) Message-Id: <201101131430.p0DEUDK5019024@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: kristaps@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Change how -Thtml behaves with tables: use multiple rows, with X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Change how -Thtml behaves with tables: use multiple rows, with widths set by COL, until an external macro is encountered. At this point in time, close out the table and process the macro. When the first table row is again re-encountered, re-start the table. This requires a bit of tracking added to "struct html", but the change is very small and follows the logic of meta-fonts. This all follows a bug-report by joerg@. Modified Files: -------------- mdocml: html.c html.h man_html.c mdoc_html.c tbl_html.c Revision Data ------------- Index: html.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/html.h,v retrieving revision 1.38 retrieving revision 1.39 diff -Lhtml.h -Lhtml.h -u -p -r1.38 -r1.39 --- html.h +++ html.h @@ -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 *, e 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 *, Index: man_html.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_html.c,v retrieving revision 1.65 retrieving revision 1.66 diff -Lman_html.c -Lman_html.c -u -p -r1.65 -r1.66 --- man_html.c +++ man_html.c @@ -216,17 +216,31 @@ 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); Index: html.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/html.c,v retrieving revision 1.124 retrieving revision 1.125 diff -Lhtml.c -Lhtml.c -u -p -r1.124 -r1.125 --- html.c +++ html.c @@ -90,6 +90,7 @@ static const char *const htmlattrs[ATTR_ "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 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 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); Index: mdoc_html.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_html.c,v retrieving revision 1.143 retrieving revision 1.144 diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.143 -r1.144 --- mdoc_html.c +++ 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; @@ -454,8 +472,6 @@ print_mdoc_node(MDOC_ARGS) switch (n->type) { case (MDOC_ROOT): mdoc_root_post(m, n, h); - break; - case (MDOC_TBL): break; default: if (mdocs[n->tok].post && ENDBODY_NOT == n->end) Index: tbl_html.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/tbl_html.c,v retrieving revision 1.6 retrieving revision 1.7 diff -Ltbl_html.c -Ltbl_html.c -u -p -r1.6 -r1.7 --- tbl_html.c +++ tbl_html.c @@ -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); } + } -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv