=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.4 retrieving revision 1.11 diff -u -p -r1.4 -r1.11 --- mandoc/html.c 2008/12/04 11:25:29 1.4 +++ mandoc/html.c 2008/12/05 22:54:44 1.11 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.4 2008/12/04 11:25:29 kristaps Exp $ */ +/* $Id: html.c,v 1.11 2008/12/05 22:54:44 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -32,12 +32,30 @@ #include "ml.h" +/* TODO: allow head/tail-less invocations (just "div" start). */ + +struct htmlnode { + int tok; + enum md_ns ns; + int argc[ROFF_MAXLINEARG]; + char *argv[ROFF_MAXLINEARG]; + struct htmlnode *parent; +}; + + +struct htmlq { + struct htmlnode *last; +}; + + static int html_loadcss(struct md_mbuf *, const char *); -static ssize_t html_endtag(struct md_mbuf *, +static int html_alloc(void **); +static void html_free(void *); +static ssize_t html_endtag(struct md_mbuf *, void *, const struct md_args *, enum md_ns, int); -static ssize_t html_begintag(struct md_mbuf *, +static ssize_t html_begintag(struct md_mbuf *, void *, const struct md_args *, enum md_ns, int, const int *, const char **); @@ -46,31 +64,228 @@ static int html_begin(struct md_mbuf *, const struct tm *, const char *, const char *, const char *, const char *); +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 ssize_t html_blocktagname(struct md_mbuf *, - const struct md_args *, int); -static ssize_t html_blocktagargs(struct md_mbuf *, +static int html_blocktagname(struct md_mbuf *, + const struct md_args *, int, + struct htmlq *, const int *, + const char **, size_t *); +static int html_blocktagargs(struct md_mbuf *, const struct md_args *, int, - const int *, const char **); -static ssize_t html_blockheadtagname(struct md_mbuf *, - const struct md_args *, int); -static ssize_t html_blockheadtagargs(struct md_mbuf *, + const int *, const char **, size_t *); +static int html_headtagname(struct md_mbuf *, + const struct md_args *, int, + struct htmlq *, const int *, + const char **, size_t *); +static int html_headtagargs(struct md_mbuf *, const struct md_args *, int, - const int *, const char **); -static ssize_t html_blockbodytagname(struct md_mbuf *, - const struct md_args *, int); -static ssize_t html_blockbodytagargs(struct md_mbuf *, + const int *, const char **, size_t *); +static int html_blockbodytagname(struct md_mbuf *, + const struct md_args *, + int, struct htmlq *, const int *, + const char **, size_t *); +static int html_blockbodytagargs(struct md_mbuf *, const struct md_args *, int, - const int *, const char **); -static ssize_t html_inlinetagname(struct md_mbuf *, - const struct md_args *, int); -static ssize_t html_inlinetagargs(struct md_mbuf *, + const int *, const char **, size_t *); +static int html_inlinetagname(struct md_mbuf *, + const struct md_args *, int, size_t *); +static int html_inlinetagargs(struct md_mbuf *, const struct md_args *, int, - const int *, const char **); + const int *, const char **, size_t *); +static int html_Bl_bodytagname(struct md_mbuf *, + struct htmlq *, const int *, + const char **, size_t *); +static int html_It_blocktagname(struct md_mbuf *, + struct htmlq *, const int *, + const char **, size_t *); +static int html_It_headtagname(struct md_mbuf *, + struct htmlq *, const int *, + const char **, size_t *); +static int html_It_bodytagname(struct md_mbuf *, + struct htmlq *, const int *, + const char **, size_t *); +/* ARGSUSED */ static int +html_It_headtagname(struct md_mbuf *mbuf, struct htmlq *q, + const int *argc, const char **argv, size_t *res) +{ + struct htmlnode *n; + int i; + + for (n = q->last; n; n = n->parent) + if (n->tok == ROFF_Bl) + break; + + assert(n); + for (i = 0; ROFF_ARGMAX != n->argc[i] && + i < ROFF_MAXLINEARG; i++) { + switch (n->argc[i]) { + case (ROFF_Tag): + /* FALLTHROUGH */ + case (ROFF_Column): + return(ml_nputs(mbuf, "td", 2, res)); + default: + break; + } + } + + assert(i != ROFF_MAXLINEARG); + abort(); + /* NOTREACHED */ + + return(1); +} + + +/* ARGSUSED */ +static int +html_It_bodytagname(struct md_mbuf *mbuf, struct htmlq *q, + const int *argc, const char **argv, size_t *res) +{ + struct htmlnode *n; + int i; + + for (n = q->last; n; n = n->parent) + if (n->tok == ROFF_Bl) + break; + + assert(n); + for (i = 0; ROFF_ARGMAX != n->argc[i] && + i < ROFF_MAXLINEARG; i++) { + switch (n->argc[i]) { + case (ROFF_Enum): + /* FALLTHROUGH */ + case (ROFF_Bullet): + /* FALLTHROUGH */ + case (ROFF_Dash): + /* FALLTHROUGH */ + case (ROFF_Hyphen): + /* FALLTHROUGH */ + case (ROFF_Item): + /* FALLTHROUGH */ + case (ROFF_Diag): + /* FALLTHROUGH */ + case (ROFF_Hang): + /* FALLTHROUGH */ + case (ROFF_Ohang): + /* FALLTHROUGH */ + case (ROFF_Inset): + return(ml_nputs(mbuf, "div", 3, res)); + case (ROFF_Tag): + /* FALLTHROUGH */ + case (ROFF_Column): + return(ml_nputs(mbuf, "td", 2, res)); + default: + break; + } + } + + assert(i != ROFF_MAXLINEARG); + abort(); + /* NOTREACHED */ + + return(1); +} + + +/* ARGSUSED */ +static int +html_Bl_bodytagname(struct md_mbuf *mbuf, struct htmlq *q, + const int *argc, const char **argv, size_t *res) +{ + int i; + + for (i = 0; ROFF_ARGMAX != argc[i] + && i < ROFF_MAXLINEARG; i++) { + switch (argc[i]) { + case (ROFF_Enum): + return(ml_nputs(mbuf, "ol", 2, res)); + case (ROFF_Bullet): + /* FALLTHROUGH */ + case (ROFF_Dash): + /* FALLTHROUGH */ + case (ROFF_Hyphen): + /* FALLTHROUGH */ + case (ROFF_Item): + /* FALLTHROUGH */ + case (ROFF_Diag): + /* FALLTHROUGH */ + case (ROFF_Hang): + /* FALLTHROUGH */ + case (ROFF_Ohang): + /* FALLTHROUGH */ + case (ROFF_Inset): + return(ml_nputs(mbuf, "ul", 2, res)); + case (ROFF_Tag): + /* FALLTHROUGH */ + case (ROFF_Column): + return(ml_nputs(mbuf, "table", 5, res)); + default: + break; + } + } + + assert(i != ROFF_MAXLINEARG); + abort(); + /* NOTREACHED */ +} + + +/* ARGSUSED */ +static int +html_It_blocktagname(struct md_mbuf *mbuf, struct htmlq *q, + const int *argc, const char **argv, size_t *res) +{ + struct htmlnode *n; + int i; + + for (n = q->last; n; n = n->parent) + if (n->tok == ROFF_Bl) + break; + + assert(n); + for (i = 0; ROFF_ARGMAX != n->argc[i] && + i < ROFF_MAXLINEARG; i++) { + switch (n->argc[i]) { + case (ROFF_Enum): + /* FALLTHROUGH */ + case (ROFF_Bullet): + /* FALLTHROUGH */ + case (ROFF_Dash): + /* FALLTHROUGH */ + case (ROFF_Hyphen): + /* FALLTHROUGH */ + case (ROFF_Item): + /* FALLTHROUGH */ + case (ROFF_Diag): + /* FALLTHROUGH */ + case (ROFF_Hang): + /* FALLTHROUGH */ + case (ROFF_Ohang): + /* FALLTHROUGH */ + case (ROFF_Inset): + return(ml_nputs(mbuf, "li", 2, res)); + case (ROFF_Tag): + /* FALLTHROUGH */ + case (ROFF_Column): + return(ml_nputs(mbuf, "tr", 2, res)); + default: + break; + } + } + + assert(i != ROFF_MAXLINEARG); + abort(); + /* NOTREACHED */ +} + + +static int html_loadcss(struct md_mbuf *mbuf, const char *css) { size_t res, bufsz; @@ -151,7 +366,7 @@ html_begin(struct md_mbuf *mbuf, const struct md_args trail = "\n" "\n" - "
\n"; + "
"; res = 0; @@ -163,7 +378,7 @@ html_begin(struct md_mbuf *mbuf, const struct md_args assert(args->params.html.css); if (HTML_CSS_EMBED & args->params.html.flags) { - if ( ! ml_puts(mbuf, "