version 1.8, 2008/12/05 17:43:14 |
version 1.9, 2008/12/05 19:45:15 |
|
|
|
|
|
|
/* TODO: allow head/tail-less invocations (just "div" start). */ |
/* TODO: allow head/tail-less invocations (just "div" start). */ |
/* FIXME: free htmlq. */ |
|
|
|
struct htmlnode { |
struct htmlnode { |
int tok; |
int tok; |
|
|
}; |
}; |
|
|
|
|
static void htmlnode_free(struct htmlnode *); |
|
static void htmlnode_free(struct htmlnode *); |
|
|
|
static int html_loadcss(struct md_mbuf *, const char *); |
static int html_loadcss(struct md_mbuf *, const char *); |
|
|
|
static int html_alloc(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); |
Line 210 html_begin(struct md_mbuf *mbuf, const struct md_args |
|
Line 208 html_begin(struct md_mbuf *mbuf, const struct md_args |
|
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) |
{ |
{ |
size_t res; |
|
|
|
res = 0; |
return(ml_puts(mbuf, "</div></body>\n</html>", NULL)); |
if ( ! ml_puts(mbuf, "</div></body>\n</html>", &res)) |
|
return(0); |
|
|
|
return(1); |
|
} |
} |
|
|
|
|
Line 230 html_blockbodytagname(struct md_mbuf *mbuf, |
|
Line 223 html_blockbodytagname(struct md_mbuf *mbuf, |
|
} |
} |
|
|
|
|
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static int |
static int |
html_blockheadtagname(struct md_mbuf *mbuf, |
html_blockheadtagname(struct md_mbuf *mbuf, |
Line 252 html_blocktagname(struct md_mbuf *mbuf, |
|
Line 243 html_blocktagname(struct md_mbuf *mbuf, |
|
} |
} |
|
|
|
|
|
/* ARGSUSED */ |
static int |
static int |
html_printargs(struct md_mbuf *mbuf, int tok, const char *ns, |
html_printargs(struct md_mbuf *mbuf, int tok, const char *ns, |
const int *argc, const char **argv, size_t *res) |
const int *argc, const char **argv, size_t *res) |
{ |
{ |
int i, c; |
|
|
|
if ( ! ml_puts(mbuf, " class=\"", res)) |
if ( ! ml_puts(mbuf, " class=\"", res)) |
return(0); |
return(0); |
Line 266 html_printargs(struct md_mbuf *mbuf, int tok, const ch |
|
Line 257 html_printargs(struct md_mbuf *mbuf, int tok, const ch |
|
return(0); |
return(0); |
if ( ! ml_puts(mbuf, toknames[tok], res)) |
if ( ! ml_puts(mbuf, toknames[tok], res)) |
return(0); |
return(0); |
if ( ! ml_puts(mbuf, "\"", res)) |
return(ml_puts(mbuf, "\"", res)); |
return(0); |
|
|
|
if (NULL == argv || NULL == argc) |
|
return(1); |
|
assert(argv && argc); |
|
|
|
/* FIXME: ignores values. */ |
|
|
|
for (i = 0; ROFF_ARGMAX != (c = argc[i]); i++) { |
|
if (argv[i]) |
|
continue; |
|
if ( ! ml_puts(mbuf, " class=\"", res)) |
|
return(0); |
|
if ( ! ml_puts(mbuf, ns, res)) |
|
return(0); |
|
if ( ! ml_puts(mbuf, "-", res)) |
|
return(0); |
|
if ( ! ml_puts(mbuf, toknames[tok], res)) |
|
return(0); |
|
if ( ! ml_puts(mbuf, "-", res)) |
|
return(0); |
|
if ( ! ml_puts(mbuf, tokargnames[c], res)) |
|
return(0); |
|
if ( ! ml_puts(mbuf, "\"", res)) |
|
return(0); |
|
} |
|
|
|
return(1); |
|
} |
} |
|
|
|
|
Line 352 html_inlinetagname(struct md_mbuf *mbuf, |
|
Line 315 html_inlinetagname(struct md_mbuf *mbuf, |
|
case (ROFF_Pp): |
case (ROFF_Pp): |
return(ml_puts(mbuf, "div", res)); |
return(ml_puts(mbuf, "div", res)); |
default: |
default: |
return(ml_puts(mbuf, "span", res)); |
break; |
} |
} |
return(1); |
|
|
return(ml_puts(mbuf, "span", res)); |
} |
} |
|
|
|
|
Line 455 html_endtag(struct md_mbuf *mbuf, void *data, |
|
Line 419 html_endtag(struct md_mbuf *mbuf, void *data, |
|
node = q->last; |
node = q->last; |
q->last = node->parent; |
q->last = node->parent; |
|
|
htmlnode_free(node); |
free(node); |
|
|
return((ssize_t)res); |
return((ssize_t)res); |
} |
} |
|
|
|
|
|
static int |
|
html_alloc(void **p) |
|
{ |
|
|
|
if (NULL == (*p = calloc(1, sizeof(struct htmlq)))) { |
|
warn("calloc"); |
|
return(0); |
|
} |
|
return(1); |
|
} |
|
|
|
|
|
static void |
|
html_free(void *p) |
|
{ |
|
struct htmlq *q; |
|
struct htmlnode *n; |
|
|
|
assert(p); |
|
q = (struct htmlq *)p; |
|
|
|
while ((n = q->last)) { |
|
q->last = n->parent; |
|
free(n); |
|
} |
|
|
|
free(q); |
|
} |
|
|
|
|
int |
int |
md_line_html(void *data, char *buf) |
md_line_html(void *data, char *buf) |
{ |
{ |
|
|
md_init_html(const struct md_args *args, |
md_init_html(const struct md_args *args, |
struct md_mbuf *mbuf, const struct md_rbuf *rbuf) |
struct md_mbuf *mbuf, const struct md_rbuf *rbuf) |
{ |
{ |
struct htmlq *q; |
struct ml_cbs cbs; |
|
|
if (NULL == (q = calloc(1, sizeof(struct htmlq)))) { |
cbs.ml_alloc = html_alloc; |
warn("calloc"); |
cbs.ml_free = html_free; |
return(NULL); |
cbs.ml_begintag = html_begintag; |
} |
cbs.ml_endtag = html_endtag; |
|
cbs.ml_begin = html_begin; |
|
cbs.ml_end = html_end; |
|
|
return(mlg_alloc(args, q, rbuf, mbuf, html_begintag, |
return(mlg_alloc(args, rbuf, mbuf, &cbs)); |
html_endtag, html_begin, html_end)); |
|
} |
} |
|
|