version 1.11, 2008/12/05 22:54:44 |
version 1.22, 2008/12/10 12:05:33 |
|
|
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "libmdocml.h" |
#include "html.h" |
#include "private.h" |
|
#include "ml.h" |
#include "ml.h" |
|
|
|
|
/* TODO: allow head/tail-less invocations (just "div" start). */ |
/* TODO: allow head/tail-less invocations (just "div" start). */ |
|
|
struct htmlnode { |
struct htmlnode { |
Line 42 struct htmlnode { |
|
Line 40 struct htmlnode { |
|
struct htmlnode *parent; |
struct htmlnode *parent; |
}; |
}; |
|
|
|
|
struct htmlq { |
struct htmlq { |
struct htmlnode *last; |
struct htmlnode *last; |
}; |
}; |
|
|
|
|
static int html_loadcss(struct md_mbuf *, const char *); |
static int html_loadcss(struct md_mbuf *, |
|
const char *); |
static int html_alloc(void **); |
static int html_alloc(void **); |
static void html_free(void *); |
static void html_free(void *); |
static ssize_t html_endtag(struct md_mbuf *, void *, |
static ssize_t html_endtag(struct md_mbuf *, void *, |
const struct md_args *, |
const struct md_args *, |
enum md_ns, int); |
enum md_ns, int); |
|
static ssize_t html_beginstring(struct md_mbuf *, |
|
const struct md_args *, |
|
const char *, size_t); |
|
static ssize_t html_beginhttp(struct md_mbuf *, |
|
const struct md_args *, |
|
const char *, size_t); |
|
static ssize_t html_endstring(struct md_mbuf *, |
|
const struct md_args *, |
|
const char *, size_t); |
|
static ssize_t html_endhttp(struct md_mbuf *, |
|
const struct md_args *, |
|
const char *, size_t); |
static ssize_t html_begintag(struct md_mbuf *, void *, |
static ssize_t html_begintag(struct md_mbuf *, void *, |
const struct md_args *, |
const struct md_args *, |
enum md_ns, int, |
enum md_ns, int, |
Line 63 static int html_begin(struct md_mbuf *, |
|
Line 72 static int html_begin(struct md_mbuf *, |
|
const struct md_args *, |
const struct md_args *, |
const struct tm *, |
const struct tm *, |
const char *, const char *, |
const char *, const char *, |
const char *, const char *); |
enum roffmsec, enum roffvol); |
static int html_printargs(struct md_mbuf *, int, |
static int html_printargs(struct md_mbuf *, int, |
const char *, const int *, |
const char *, const int *, |
const char **, size_t *); |
const char **, size_t *); |
static int html_end(struct md_mbuf *, |
static int html_end(struct md_mbuf *, |
const struct md_args *); |
const struct md_args *, |
|
const struct tm *, |
|
const char *, const char *, |
|
enum roffmsec, enum roffvol); |
static int html_blocktagname(struct md_mbuf *, |
static int html_blocktagname(struct md_mbuf *, |
const struct md_args *, int, |
const struct md_args *, int, |
struct htmlq *, const int *, |
struct htmlq *, const int *, |
Line 83 static int html_headtagname(struct md_mbuf *, |
|
Line 95 static int html_headtagname(struct md_mbuf *, |
|
static int html_headtagargs(struct md_mbuf *, |
static int html_headtagargs(struct md_mbuf *, |
const struct md_args *, int, |
const struct md_args *, int, |
const int *, const char **, size_t *); |
const int *, const char **, size_t *); |
static int html_blockbodytagname(struct md_mbuf *, |
static int html_bodytagname(struct md_mbuf *, |
const struct md_args *, |
const struct md_args *, |
int, struct htmlq *, const int *, |
int, struct htmlq *, const int *, |
const char **, size_t *); |
const char **, size_t *); |
static int html_blockbodytagargs(struct md_mbuf *, |
static int html_bodytagargs(struct md_mbuf *, |
const struct md_args *, int, |
const struct md_args *, int, |
const int *, const char **, size_t *); |
const int *, const char **, size_t *); |
static int html_inlinetagname(struct md_mbuf *, |
static int html_inlinetagname(struct md_mbuf *, |
Line 107 static int html_It_headtagname(struct md_mbuf *, |
|
Line 119 static int html_It_headtagname(struct md_mbuf *, |
|
static int html_It_bodytagname(struct md_mbuf *, |
static int html_It_bodytagname(struct md_mbuf *, |
struct htmlq *, const int *, |
struct htmlq *, const int *, |
const char **, size_t *); |
const char **, size_t *); |
|
static int html_tputln(struct md_mbuf *, |
|
enum ml_scope, int, enum html_tag); |
|
static int html_aputln(struct md_mbuf *, enum ml_scope, |
|
int, enum html_tag, |
|
int, const struct html_pair *); |
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
Line 122 html_It_headtagname(struct md_mbuf *mbuf, struct htmlq |
|
Line 139 html_It_headtagname(struct md_mbuf *mbuf, struct htmlq |
|
break; |
break; |
|
|
assert(n); |
assert(n); |
|
|
|
/* LINTED */ |
for (i = 0; ROFF_ARGMAX != n->argc[i] && |
for (i = 0; ROFF_ARGMAX != n->argc[i] && |
i < ROFF_MAXLINEARG; i++) { |
i < ROFF_MAXLINEARG; i++) { |
switch (n->argc[i]) { |
switch (n->argc[i]) { |
|
case (ROFF_Ohang): |
|
return(html_stput(mbuf, HTML_TAG_DIV, res)); |
case (ROFF_Tag): |
case (ROFF_Tag): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ROFF_Column): |
case (ROFF_Column): |
return(ml_nputs(mbuf, "td", 2, res)); |
return(html_stput(mbuf, HTML_TAG_TD, res)); |
default: |
default: |
break; |
break; |
} |
} |
} |
} |
|
|
assert(i != ROFF_MAXLINEARG); |
return(0); |
abort(); |
|
/* NOTREACHED */ |
|
|
|
return(1); |
|
} |
} |
|
|
|
|
Line 155 html_It_bodytagname(struct md_mbuf *mbuf, struct htmlq |
|
Line 172 html_It_bodytagname(struct md_mbuf *mbuf, struct htmlq |
|
break; |
break; |
|
|
assert(n); |
assert(n); |
|
|
|
/* LINTED */ |
for (i = 0; ROFF_ARGMAX != n->argc[i] && |
for (i = 0; ROFF_ARGMAX != n->argc[i] && |
i < ROFF_MAXLINEARG; i++) { |
i < ROFF_MAXLINEARG; i++) { |
switch (n->argc[i]) { |
switch (n->argc[i]) { |
Line 175 html_It_bodytagname(struct md_mbuf *mbuf, struct htmlq |
|
Line 194 html_It_bodytagname(struct md_mbuf *mbuf, struct htmlq |
|
case (ROFF_Ohang): |
case (ROFF_Ohang): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ROFF_Inset): |
case (ROFF_Inset): |
return(ml_nputs(mbuf, "div", 3, res)); |
return(html_stput(mbuf, HTML_TAG_DIV, res)); |
case (ROFF_Tag): |
case (ROFF_Tag): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ROFF_Column): |
case (ROFF_Column): |
return(ml_nputs(mbuf, "td", 2, res)); |
return(html_stput(mbuf, HTML_TAG_TD, res)); |
default: |
default: |
break; |
break; |
} |
} |
} |
} |
|
|
assert(i != ROFF_MAXLINEARG); |
assert(i != ROFF_MAXLINEARG); |
abort(); |
return(0); |
/* NOTREACHED */ |
|
|
|
return(1); |
|
} |
} |
|
|
|
|
Line 204 html_Bl_bodytagname(struct md_mbuf *mbuf, struct htmlq |
|
Line 220 html_Bl_bodytagname(struct md_mbuf *mbuf, struct htmlq |
|
&& i < ROFF_MAXLINEARG; i++) { |
&& i < ROFF_MAXLINEARG; i++) { |
switch (argc[i]) { |
switch (argc[i]) { |
case (ROFF_Enum): |
case (ROFF_Enum): |
return(ml_nputs(mbuf, "ol", 2, res)); |
return(html_stput(mbuf, HTML_TAG_OL, res)); |
case (ROFF_Bullet): |
case (ROFF_Bullet): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ROFF_Dash): |
case (ROFF_Dash): |
Line 220 html_Bl_bodytagname(struct md_mbuf *mbuf, struct htmlq |
|
Line 236 html_Bl_bodytagname(struct md_mbuf *mbuf, struct htmlq |
|
case (ROFF_Ohang): |
case (ROFF_Ohang): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ROFF_Inset): |
case (ROFF_Inset): |
return(ml_nputs(mbuf, "ul", 2, res)); |
return(html_stput(mbuf, HTML_TAG_UL, res)); |
case (ROFF_Tag): |
case (ROFF_Tag): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ROFF_Column): |
case (ROFF_Column): |
return(ml_nputs(mbuf, "table", 5, res)); |
return(html_stput(mbuf, HTML_TAG_TABLE, res)); |
default: |
default: |
break; |
break; |
} |
} |
} |
} |
|
|
assert(i != ROFF_MAXLINEARG); |
assert(i != ROFF_MAXLINEARG); |
abort(); |
return(0); |
/* NOTREACHED */ |
|
} |
} |
|
|
|
|
Line 249 html_It_blocktagname(struct md_mbuf *mbuf, struct html |
|
Line 264 html_It_blocktagname(struct md_mbuf *mbuf, struct html |
|
break; |
break; |
|
|
assert(n); |
assert(n); |
|
|
|
/* LINTED */ |
for (i = 0; ROFF_ARGMAX != n->argc[i] && |
for (i = 0; ROFF_ARGMAX != n->argc[i] && |
i < ROFF_MAXLINEARG; i++) { |
i < ROFF_MAXLINEARG; i++) { |
switch (n->argc[i]) { |
switch (n->argc[i]) { |
Line 269 html_It_blocktagname(struct md_mbuf *mbuf, struct html |
|
Line 286 html_It_blocktagname(struct md_mbuf *mbuf, struct html |
|
case (ROFF_Ohang): |
case (ROFF_Ohang): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ROFF_Inset): |
case (ROFF_Inset): |
return(ml_nputs(mbuf, "li", 2, res)); |
return(html_stput(mbuf, HTML_TAG_LI, res)); |
case (ROFF_Tag): |
case (ROFF_Tag): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ROFF_Column): |
case (ROFF_Column): |
return(ml_nputs(mbuf, "tr", 2, res)); |
return(html_stput(mbuf, HTML_TAG_TR, res)); |
default: |
default: |
break; |
break; |
} |
} |
} |
} |
|
|
assert(i != ROFF_MAXLINEARG); |
assert(i != ROFF_MAXLINEARG); |
abort(); |
return(0); |
/* NOTREACHED */ |
|
} |
} |
|
|
|
|
|
|
} |
} |
|
|
|
|
|
static int |
|
html_tputln(struct md_mbuf *mbuf, enum ml_scope scope, |
|
int i, enum html_tag tag) |
|
{ |
|
|
|
if ( ! ml_putchars(mbuf, ' ', INDENT(i) * INDENT_SZ, NULL)) |
|
return(0); |
|
if ( ! html_tput(mbuf, scope, tag, NULL)) |
|
return(0); |
|
return(ml_nputs(mbuf, "\n", 1, NULL)); |
|
} |
|
|
|
|
|
static int |
|
html_aputln(struct md_mbuf *mbuf, enum ml_scope scope, int i, |
|
enum html_tag tag, int sz, const struct html_pair *p) |
|
{ |
|
|
|
if ( ! ml_putchars(mbuf, ' ', INDENT(i) * INDENT_SZ, NULL)) |
|
return(0); |
|
if ( ! html_aput(mbuf, scope, tag, NULL, sz, p)) |
|
return(0); |
|
return(ml_nputs(mbuf, "\n", 1, NULL)); |
|
} |
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static int |
static int |
html_begin(struct md_mbuf *mbuf, const struct md_args *args, |
html_begin(struct md_mbuf *mbuf, const struct md_args *args, |
const struct tm *tm, const char *os, |
const struct tm *tm, const char *os, |
const char *title, const char *section, |
const char *name, enum roffmsec msec, enum roffvol vol) |
const char *vol) |
|
{ |
{ |
const char *preamble, *css, *trail; |
enum roffvol bvol; |
char buf[512]; |
struct html_pair attr[4]; |
size_t res; |
char ts[32], title[64]; |
|
int i; |
|
|
preamble = |
(void)snprintf(ts, sizeof(ts), "%s(%s)", |
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n" |
name, roff_msecname(msec)); |
" \"http://www.w3.org/TR/html4/strict.dtd\">\n" |
|
"<html>\n" |
|
"<head>\n" |
|
" <meta http-equiv=\"Content-Type\"\n" |
|
" content=\"text/html;charset=utf-8\">\n" |
|
" <meta name=\"resource-type\" content=\"document\">\n" |
|
" <title>Manual Page for %s(%s)</title>\n"; |
|
|
|
css = |
if (vol >= ROFF_ARCH_START) { |
" <link rel=\"stylesheet\" type=\"text/css\"\n" |
switch (msec) { |
" href=\"%s\">\n"; |
case(ROFF_MSEC_1): |
trail = |
/* FALLTHROUGH */ |
"</head>\n" |
case(ROFF_MSEC_6): |
"<body>\n" |
/* FALLTHROUGH */ |
"<div class=\"mdoc\">"; |
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 */ |
|
} |
|
|
res = 0; |
(void)snprintf(title, sizeof(title), "%s (%s)", |
|
roff_volname(bvol), roff_volname(vol)); |
|
} else |
|
(void)snprintf(title, sizeof(title), "%s", roff_volname(vol)); |
|
|
(void)snprintf(buf, sizeof(buf) - 1, |
|
preamble, title, section); |
|
|
|
if ( ! ml_puts(mbuf, buf, &res)) |
i = 0; |
|
|
|
if ( ! html_typeput(mbuf, HTML_TYPE_4_01_STRICT, NULL)) |
return(0); |
return(0); |
|
if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_HTML)) |
|
return(0); |
|
if ( ! html_tputln(mbuf, ML_OPEN, i++, HTML_TAG_HEAD)) |
|
return(0); |
|
|
assert(args->params.html.css); |
attr[0].attr = HTML_ATTR_HTTP_EQUIV; |
|
attr[0].val = "content-type"; |
|
attr[1].attr = HTML_ATTR_CONTENT; |
|
attr[1].val = "text/html;charset=utf-8"; |
|
|
|
if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_META, 2, attr)) |
|
return(0); |
|
|
|
attr[0].attr = HTML_ATTR_NAME; |
|
attr[0].val = "resource-type"; |
|
attr[1].attr = HTML_ATTR_CONTENT; |
|
attr[1].val = "document"; |
|
|
|
if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_META, 2, attr)) |
|
return(0); |
|
|
|
if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_TITLE)) |
|
return(0); |
|
if ( ! ml_putstring(mbuf, ts, NULL)) |
|
return(0); |
|
if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TITLE)) |
|
return(0); |
|
|
if (HTML_CSS_EMBED & args->params.html.flags) { |
if (HTML_CSS_EMBED & args->params.html.flags) { |
if ( ! ml_puts(mbuf, " <style type=\"text/css\"><!--\n", &res)) |
attr[0].attr = HTML_ATTR_TYPE; |
|
attr[0].val = "text/css"; |
|
|
|
if ( ! html_aputln(mbuf, ML_OPEN, i, |
|
HTML_TAG_STYLE, 1, attr)) |
return(0); |
return(0); |
|
if ( ! html_commentput(mbuf, ML_OPEN, NULL)) |
|
return(0); |
|
|
if ( ! html_loadcss(mbuf, args->params.html.css)) |
if ( ! html_loadcss(mbuf, args->params.html.css)) |
return(0); |
return(0); |
if ( ! ml_puts(mbuf, " --!></style>\n", &res)) |
|
|
if ( ! html_commentput(mbuf, ML_CLOSE, NULL)) |
return(0); |
return(0); |
|
if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_STYLE)) |
|
return(0); |
} else { |
} else { |
(void)snprintf(buf, sizeof(buf) - 1, css, |
attr[0].attr = HTML_ATTR_REL; |
args->params.html.css); |
attr[0].val = "stylesheet"; |
if ( ! ml_puts(mbuf, buf, &res)) |
attr[1].attr = HTML_ATTR_TYPE; |
|
attr[1].val = "text/css"; |
|
attr[2].attr = HTML_ATTR_HREF; |
|
attr[2].val = args->params.html.css; |
|
|
|
if ( ! html_aputln(mbuf, ML_OPEN, i, |
|
HTML_TAG_LINK, 3, attr)) |
return(0); |
return(0); |
} |
} |
|
|
if ( ! ml_puts(mbuf, trail, &res)) |
if ( ! html_tputln(mbuf, ML_CLOSE, --i, HTML_TAG_HEAD)) |
return(0); |
return(0); |
|
if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_BODY)) |
|
return(0); |
|
|
return(1); |
attr[0].attr = HTML_ATTR_CLASS; |
|
attr[0].val = "mdoc"; |
|
|
|
if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_DIV, 1, attr)) |
|
return(0); |
|
|
|
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, 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 = "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); |
|
|
|
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); |
|
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, 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); |
|
return(html_tputln(mbuf, ML_CLOSE, --i, HTML_TAG_TABLE)); |
} |
} |
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static int |
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]; |
|
|
return(ml_puts(mbuf, "</div></body>\n</html>", NULL)); |
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)) |
|
return(0); |
|
return(html_tputln(mbuf, ML_CLOSE, 0, HTML_TAG_HTML)); |
} |
} |
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static int |
static int |
html_blockbodytagname(struct md_mbuf *mbuf, |
html_bodytagname(struct md_mbuf *mbuf, |
const struct md_args *args, int tok, struct htmlq *q, |
const struct md_args *args, int tok, struct htmlq *q, |
const int *argc, const char **argv, size_t *res) |
const int *argc, const char **argv, size_t *res) |
{ |
{ |
Line 417 html_blockbodytagname(struct md_mbuf *mbuf, |
|
Line 638 html_blockbodytagname(struct md_mbuf *mbuf, |
|
switch (tok) { |
switch (tok) { |
case (ROFF_Bl): |
case (ROFF_Bl): |
return(html_Bl_bodytagname(mbuf, q, argc, argv, res)); |
return(html_Bl_bodytagname(mbuf, q, argc, argv, res)); |
|
case (ROFF_Fo): |
|
return(html_stput(mbuf, HTML_TAG_SPAN, res)); |
case (ROFF_It): |
case (ROFF_It): |
return(html_It_bodytagname(mbuf, q, argc, argv, res)); |
return(html_It_bodytagname(mbuf, q, argc, argv, res)); |
|
case (ROFF_Oo): |
|
return(html_stput(mbuf, HTML_TAG_SPAN, res)); |
default: |
default: |
break; |
break; |
} |
} |
|
|
return(ml_puts(mbuf, "div", res)); |
return(html_stput(mbuf, HTML_TAG_DIV, res)); |
} |
} |
|
|
|
|
Line 437 html_headtagname(struct md_mbuf *mbuf, |
|
Line 662 html_headtagname(struct md_mbuf *mbuf, |
|
switch (tok) { |
switch (tok) { |
case (ROFF_It): |
case (ROFF_It): |
return(html_It_headtagname(mbuf, q, argc, argv, res)); |
return(html_It_headtagname(mbuf, q, argc, argv, res)); |
|
case (ROFF_Fo): |
|
/* FALLTHROUGH */ |
|
case (ROFF_Oo): |
|
return(html_stput(mbuf, HTML_TAG_SPAN, res)); |
case (ROFF_Sh): |
case (ROFF_Sh): |
return(ml_puts(mbuf, "h1", res)); |
return(html_stput(mbuf, HTML_TAG_H1, res)); |
case (ROFF_Ss): |
case (ROFF_Ss): |
return(ml_puts(mbuf, "h2", res)); |
return(html_stput(mbuf, HTML_TAG_H2, res)); |
default: |
default: |
break; |
break; |
} |
} |
|
|
return(ml_puts(mbuf, "div", res)); |
return(html_stput(mbuf, HTML_TAG_DIV, res)); |
} |
} |
|
|
|
|
Line 457 html_blocktagname(struct md_mbuf *mbuf, const struct m |
|
Line 686 html_blocktagname(struct md_mbuf *mbuf, const struct m |
|
{ |
{ |
|
|
switch (tok) { |
switch (tok) { |
|
case (ROFF_Fo): |
|
/* FALLTHROUGH */ |
|
case (ROFF_Oo): |
|
return(html_stput(mbuf, HTML_TAG_SPAN, res)); |
case (ROFF_It): |
case (ROFF_It): |
return(html_It_blocktagname(mbuf, q, argc, argv, res)); |
return(html_It_blocktagname(mbuf, q, argc, argv, res)); |
default: |
default: |
break; |
break; |
} |
} |
|
|
return(ml_puts(mbuf, "div", res)); |
return(html_stput(mbuf, HTML_TAG_DIV, res)); |
} |
} |
|
|
|
|
Line 473 html_printargs(struct md_mbuf *mbuf, int tok, const ch |
|
Line 706 html_printargs(struct md_mbuf *mbuf, int tok, const ch |
|
const int *argc, const char **argv, size_t *res) |
const int *argc, const char **argv, size_t *res) |
{ |
{ |
|
|
|
/* FIXME: use API in ml.h. */ |
|
|
if ( ! ml_puts(mbuf, " class=\"", res)) |
if ( ! ml_puts(mbuf, " class=\"", res)) |
return(0); |
return(0); |
if ( ! ml_puts(mbuf, ns, res)) |
if ( ! ml_puts(mbuf, ns, res)) |
Line 498 html_headtagargs(struct md_mbuf *mbuf, |
|
Line 733 html_headtagargs(struct md_mbuf *mbuf, |
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static int |
static int |
html_blockbodytagargs(struct md_mbuf *mbuf, |
html_bodytagargs(struct md_mbuf *mbuf, |
const struct md_args *args, int tok, |
const struct md_args *args, int tok, |
const int *argc, const char **argv, size_t *res) |
const int *argc, const char **argv, size_t *res) |
{ |
{ |
Line 525 html_inlinetagargs(struct md_mbuf *mbuf, |
|
Line 760 html_inlinetagargs(struct md_mbuf *mbuf, |
|
const int *argc, const char **argv, size_t *res) |
const int *argc, const char **argv, size_t *res) |
{ |
{ |
|
|
return(html_printargs(mbuf, tok, "inline", argc, argv, res)); |
if ( ! html_printargs(mbuf, tok, "inline", argc, argv, res)) |
|
return(0); |
|
|
|
switch (tok) { |
|
case (ROFF_Sx): |
|
|
|
/* FIXME: use API in ml.h. */ |
|
|
|
assert(*argv); |
|
if ( ! ml_nputs(mbuf, " href=\"#", 8, res)) |
|
return(0); |
|
if ( ! ml_putstring(mbuf, *argv, res)) |
|
return(0); |
|
if ( ! ml_nputs(mbuf, "\"", 1, res)) |
|
return(0); |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
return(1); |
} |
} |
|
|
|
|
Line 537 html_inlinetagname(struct md_mbuf *mbuf, |
|
Line 792 html_inlinetagname(struct md_mbuf *mbuf, |
|
|
|
switch (tok) { |
switch (tok) { |
case (ROFF_Pp): |
case (ROFF_Pp): |
return(ml_puts(mbuf, "div", res)); |
return(html_stput(mbuf, HTML_TAG_DIV, res)); |
|
case (ROFF_Sx): |
|
return(html_stput(mbuf, HTML_TAG_A, res)); |
default: |
default: |
break; |
break; |
} |
} |
|
|
return(ml_puts(mbuf, "span", res)); |
return(html_stput(mbuf, HTML_TAG_SPAN, res)); |
} |
} |
|
|
|
|
Line 575 html_begintag(struct md_mbuf *mbuf, void *data, |
|
Line 832 html_begintag(struct md_mbuf *mbuf, void *data, |
|
/* TODO: argv. */ |
/* TODO: argv. */ |
|
|
assert(argv); |
assert(argv); |
|
/* LINTED */ |
for (i = 0; ROFF_ARGMAX != argc[i] |
for (i = 0; ROFF_ARGMAX != argc[i] |
&& i < ROFF_MAXLINEARG; i++) |
&& i < ROFF_MAXLINEARG; i++) |
node->argc[i] = argc[i]; |
node->argc[i] = argc[i]; |
assert(i != ROFF_MAXLINEARG); |
assert(i != ROFF_MAXLINEARG); |
} else |
} |
assert(NULL == argv); |
|
|
|
|
|
q->last = node; |
q->last = node; |
Line 595 html_begintag(struct md_mbuf *mbuf, void *data, |
|
Line 852 html_begintag(struct md_mbuf *mbuf, void *data, |
|
return(-1); |
return(-1); |
break; |
break; |
case (MD_NS_BODY): |
case (MD_NS_BODY): |
if ( ! html_blockbodytagname(mbuf, args, tok, |
if ( ! html_bodytagname(mbuf, args, tok, |
q, argc, argv, &res)) |
q, argc, argv, &res)) |
return(-1); |
return(-1); |
if ( ! html_blockbodytagargs(mbuf, args, tok, |
if ( ! html_bodytagargs(mbuf, args, tok, |
argc, argv, &res)) |
argc, argv, &res)) |
return(-1); |
return(-1); |
break; |
break; |
Line 646 html_endtag(struct md_mbuf *mbuf, void *data, |
|
Line 903 html_endtag(struct md_mbuf *mbuf, void *data, |
|
return(-1); |
return(-1); |
break; |
break; |
case (MD_NS_BODY): |
case (MD_NS_BODY): |
if ( ! html_blockbodytagname(mbuf, args, tok, |
if ( ! html_bodytagname(mbuf, args, tok, |
q, node->argc, |
q, node->argc, |
(const char **)node->argv, &res)) |
(const char **)node->argv, &res)) |
return(-1); |
return(-1); |
Line 692 html_free(void *p) |
|
Line 949 html_free(void *p) |
|
assert(p); |
assert(p); |
q = (struct htmlq *)p; |
q = (struct htmlq *)p; |
|
|
|
/* LINTED */ |
while ((n = q->last)) { |
while ((n = q->last)) { |
q->last = n->parent; |
q->last = n->parent; |
free(n); |
free(n); |
Line 701 html_free(void *p) |
|
Line 959 html_free(void *p) |
|
} |
} |
|
|
|
|
|
static ssize_t |
|
html_beginhttp(struct md_mbuf *mbuf, |
|
const struct md_args *args, |
|
const char *buf, size_t sz) |
|
{ |
|
size_t res; |
|
struct html_pair pair; |
|
|
|
res = 0; |
|
pair.attr = HTML_ATTR_HREF; |
|
pair.val = (char *)buf; |
|
|
|
if ( ! html_aput(mbuf, ML_OPEN, HTML_TAG_A, &res, 1, &pair)) |
|
return(-1); |
|
return((ssize_t)res); |
|
} |
|
|
|
|
|
static ssize_t |
|
html_endhttp(struct md_mbuf *mbuf, |
|
const struct md_args *args, |
|
const char *buf, size_t sz) |
|
{ |
|
size_t res; |
|
|
|
res = 0; |
|
if ( ! html_tput(mbuf, ML_CLOSE, HTML_TAG_A, &res)) |
|
return(-1); |
|
return((ssize_t)res); |
|
} |
|
|
|
|
|
/* ARGSUSED */ |
|
static ssize_t |
|
html_beginstring(struct md_mbuf *mbuf, |
|
const struct md_args *args, |
|
const char *buf, size_t sz) |
|
{ |
|
|
|
if (0 == strncmp(buf, "http://", 7)) |
|
return(html_beginhttp(mbuf, args, buf, sz)); |
|
|
|
return(0); |
|
} |
|
|
|
|
|
/* ARGSUSED */ |
|
static ssize_t |
|
html_endstring(struct md_mbuf *mbuf, |
|
const struct md_args *args, |
|
const char *buf, size_t sz) |
|
{ |
|
|
|
if (0 == strncmp(buf, "http://", 7)) |
|
return(html_endhttp(mbuf, args, buf, sz)); |
|
|
|
return(0); |
|
} |
|
|
|
|
int |
int |
md_line_html(void *data, char *buf) |
md_line_html(void *data, char *buf) |
{ |
{ |
Line 729 md_init_html(const struct md_args *args, |
|
Line 1047 md_init_html(const struct md_args *args, |
|
cbs.ml_endtag = html_endtag; |
cbs.ml_endtag = html_endtag; |
cbs.ml_begin = html_begin; |
cbs.ml_begin = html_begin; |
cbs.ml_end = html_end; |
cbs.ml_end = html_end; |
|
cbs.ml_beginstring = html_beginstring; |
|
cbs.ml_endstring = html_endstring; |
|
|
return(mlg_alloc(args, rbuf, mbuf, &cbs)); |
return(mlg_alloc(args, rbuf, mbuf, &cbs)); |
} |
} |
|
|