=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.20 retrieving revision 1.24 diff -u -p -r1.20 -r1.24 --- mandoc/html.c 2008/12/10 00:58:15 1.20 +++ mandoc/html.c 2008/12/10 13:41:58 1.24 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.20 2008/12/10 00:58:15 kristaps Exp $ */ +/* $Id: html.c,v 1.24 2008/12/10 13:41:58 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -72,12 +72,15 @@ static int html_begin(struct md_mbuf *, const struct md_args *, const struct tm *, const char *, const char *, - enum roffmsec, const char *); + enum roffmsec, enum roffvol); static int html_printargs(struct md_mbuf *, int, const char *, const int *, const char **, size_t *); -static int html_end(struct md_mbuf *, - const struct md_args *); +static int html_end(struct md_mbuf *, + const struct md_args *, + const struct tm *, + const char *, const char *, + enum roffmsec, enum roffvol); static int html_blocktagname(struct md_mbuf *, const struct md_args *, int, struct htmlq *, const int *, @@ -382,15 +385,60 @@ html_aputln(struct md_mbuf *mbuf, enum ml_scope scope, static int html_begin(struct md_mbuf *mbuf, const struct md_args *args, const struct tm *tm, const char *os, - const char *name, enum roffmsec msec, const char *vol) + const char *name, enum roffmsec msec, enum roffvol vol) { + enum roffvol bvol; struct html_pair attr[4]; - char ts[32]; + char ts[32], title[64]; int i; (void)snprintf(ts, sizeof(ts), "%s(%s)", name, roff_msecname(msec)); + if (vol >= ROFF_ARCH_START) { + switch (msec) { + case(ROFF_MSEC_1): + /* FALLTHROUGH */ + case(ROFF_MSEC_6): + /* FALLTHROUGH */ + case(ROFF_MSEC_7): + bvol = ROFF_VOL_URM; + break; + case(ROFF_MSEC_2): + /* FALLTHROUGH */ + case(ROFF_MSEC_3): + /* FALLTHROUGH */ + case(ROFF_MSEC_3p): + /* FALLTHROUGH */ + case(ROFF_MSEC_4): + /* FALLTHROUGH */ + case(ROFF_MSEC_5): + bvol = ROFF_VOL_PRM; + break; + case(ROFF_MSEC_8): + bvol = ROFF_VOL_PRM; + break; + case(ROFF_MSEC_9): + bvol = ROFF_VOL_KM; + break; + case(ROFF_MSEC_UNASS): + /* FALLTHROUGH */ + case(ROFF_MSEC_DRAFT): + /* FALLTHROUGH */ + case(ROFF_MSEC_PAPER): + bvol = ROFF_VOL_NONE; + break; + default: + abort(); + /* NOTREACHED */ + } + + (void)snprintf(title, sizeof(title), "%s (%s)", + roff_volname(bvol), roff_volname(vol)); + } else + (void)snprintf(title, sizeof(title), "%s", roff_volname(vol)); + + i = 0; if ( ! html_typeput(mbuf, HTML_TYPE_4_01_STRICT, NULL)) @@ -431,13 +479,13 @@ html_begin(struct md_mbuf *mbuf, const struct md_args HTML_TAG_STYLE, 1, attr)) return(0); if ( ! html_commentput(mbuf, ML_OPEN, NULL)) - return(NULL); + return(0); if ( ! html_loadcss(mbuf, args->params.html.css)) return(0); if ( ! html_commentput(mbuf, ML_CLOSE, NULL)) - return(NULL); + return(0); if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_STYLE)) return(0); } else { @@ -466,29 +514,44 @@ html_begin(struct md_mbuf *mbuf, const struct md_args attr[0].attr = HTML_ATTR_WIDTH; attr[0].val = "100%"; + attr[1].attr = HTML_ATTR_CLASS; + attr[1].val = "header-table"; - if ( ! html_aputln(mbuf, ML_OPEN, i++, HTML_TAG_TABLE, 1, attr)) + if ( ! html_aputln(mbuf, ML_OPEN, i++, HTML_TAG_TABLE, 2, attr)) return(0); if ( ! html_tputln(mbuf, ML_OPEN, i++, HTML_TAG_TR)) return(0); - if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_TD)) + attr[0].attr = HTML_ATTR_ALIGN; + attr[0].val = "left"; + attr[1].attr = HTML_ATTR_CLASS; + attr[1].val = "header-section"; + + if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) return(0); if ( ! ml_putstring(mbuf, ts, NULL)) return(0); if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TD)) return(0); - if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_TD)) + attr[0].attr = HTML_ATTR_ALIGN; + attr[0].val = "center"; + attr[1].attr = HTML_ATTR_CLASS; + attr[1].val = "header-volume"; + + if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) return(0); - /* TODO: middle. */ + if ( ! ml_putstring(mbuf, title, NULL)) + return(0); if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TD)) return(0); attr[0].attr = HTML_ATTR_ALIGN; attr[0].val = "right"; + attr[1].attr = HTML_ATTR_CLASS; + attr[1].val = "header-section"; - if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_TD, 1, attr)) + if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) return(0); if ( ! ml_putstring(mbuf, ts, NULL)) return(0); @@ -503,9 +566,60 @@ html_begin(struct md_mbuf *mbuf, const struct md_args /* ARGSUSED */ static int -html_end(struct md_mbuf *mbuf, const struct md_args *args) +html_end(struct md_mbuf *mbuf, const struct md_args *args, + const struct tm *tm, const char *os, + const char *name, enum roffmsec msec, enum roffvol vol) { + struct html_pair attr[4]; + int i; + char ts[64]; + if (0 == strftime(ts, sizeof(ts), "%B %d, %Y", tm)) { + warn("strftime"); + return(0); + } + + i = 0; + + attr[0].attr = HTML_ATTR_WIDTH; + attr[0].val = "100%"; + attr[1].attr = HTML_ATTR_CLASS; + attr[1].val = "header-footer"; + + if ( ! html_aputln(mbuf, ML_OPEN, i++, HTML_TAG_TABLE, 2, attr)) + return(0); + if ( ! html_tputln(mbuf, ML_OPEN, i++, HTML_TAG_TR)) + return(0); + + attr[0].attr = HTML_ATTR_ALIGN; + attr[0].val = "left"; + attr[1].attr = HTML_ATTR_CLASS; + attr[1].val = "footer-os"; + + if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) + return(0); + if ( ! ml_putstring(mbuf, os, NULL)) + return(0); + if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TD)) + return(0); + + attr[0].attr = HTML_ATTR_ALIGN; + attr[0].val = "right"; + attr[1].attr = HTML_ATTR_CLASS; + attr[1].val = "footer-date"; + + if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) + return(0); + if ( ! ml_putstring(mbuf, ts, NULL)) + return(0); + if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TD)) + return(0); + + if ( ! html_tputln(mbuf, ML_CLOSE, --i, HTML_TAG_TR)) + return(0); + if ( ! html_tputln(mbuf, ML_CLOSE, --i, HTML_TAG_TABLE)) + return(0); + if ( ! html_tputln(mbuf, ML_CLOSE, 0, HTML_TAG_DIV)) return(0); if ( ! html_tputln(mbuf, ML_CLOSE, 0, HTML_TAG_BODY)) @@ -650,6 +764,25 @@ html_inlinetagargs(struct md_mbuf *mbuf, return(0); switch (tok) { + case (ROFF_Sh): + + /* FIXME: use API in ml.h. */ + + assert(*argv); + if ( ! ml_nputs(mbuf, " name=\"", 7, res)) + return(0); + if ( ! ml_putstring(mbuf, *argv++, res)) + return(0); + while (*argv) { + if ( ! ml_putstring(mbuf, "_", res)) + return(0); + if ( ! ml_putstring(mbuf, *argv++, res)) + return(0); + } + if ( ! ml_nputs(mbuf, "\"", 1, res)) + return(0); + break; + case (ROFF_Sx): /* FIXME: use API in ml.h. */ @@ -657,10 +790,17 @@ html_inlinetagargs(struct md_mbuf *mbuf, assert(*argv); if ( ! ml_nputs(mbuf, " href=\"#", 8, res)) return(0); - if ( ! ml_putstring(mbuf, *argv, res)) + if ( ! ml_putstring(mbuf, *argv++, res)) return(0); + while (*argv) { + if ( ! ml_putstring(mbuf, "_", res)) + return(0); + if ( ! ml_putstring(mbuf, *argv++, res)) + return(0); + } if ( ! ml_nputs(mbuf, "\"", 1, res)) return(0); + break; default: break; @@ -677,6 +817,8 @@ html_inlinetagname(struct md_mbuf *mbuf, { switch (tok) { + case (ROFF_Sh): + return(html_stput(mbuf, HTML_TAG_A, res)); case (ROFF_Pp): return(html_stput(mbuf, HTML_TAG_DIV, res)); case (ROFF_Sx): @@ -845,6 +987,7 @@ html_free(void *p) } +/* ARGSUSED */ static ssize_t html_beginhttp(struct md_mbuf *mbuf, const struct md_args *args, @@ -863,6 +1006,7 @@ html_beginhttp(struct md_mbuf *mbuf, } +/* ARGSUSED */ static ssize_t html_endhttp(struct md_mbuf *mbuf, const struct md_args *args,