From 42bf2c72d14bba2a852d97de53916afef4f57269 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Wed, 3 Dec 2008 21:27:56 +0000 Subject: Initial html outputs working. --- html.c | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ mlg.c | 7 +-- xml.c | 12 +++-- 3 files changed, 176 insertions(+), 25 deletions(-) diff --git a/html.c b/html.c index a0ef241c..16ed07e1 100644 --- a/html.c +++ b/html.c @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.2 2008/12/03 19:21:58 kristaps Exp $ */ +/* $Id: html.c,v 1.3 2008/12/03 21:27:56 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -41,6 +41,16 @@ static ssize_t html_blocktagname(struct md_mbuf *, static ssize_t 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 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 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 *, @@ -48,6 +58,7 @@ static ssize_t html_inlinetagargs(struct md_mbuf *, const int *, const char **); +/* ARGSUSED */ static int html_begin(struct md_mbuf *mbuf, const struct md_args *args) { @@ -80,6 +91,7 @@ html_begin(struct md_mbuf *mbuf, const struct md_args *args) } +/* ARGSUSED */ static int html_end(struct md_mbuf *mbuf, const struct md_args *args) { @@ -93,8 +105,9 @@ html_end(struct md_mbuf *mbuf, const struct md_args *args) } +/* ARGSUSED */ static ssize_t -html_blocktagname(struct md_mbuf *mbuf, +html_blockbodytagname(struct md_mbuf *mbuf, const struct md_args *args, int tok) { size_t res; @@ -106,6 +119,56 @@ html_blocktagname(struct md_mbuf *mbuf, if ( ! ml_puts(mbuf, "blockquote", &res)) return(-1); break; + default: + if ( ! ml_puts(mbuf, "div", &res)) + return(-1); + break; + } + + return((ssize_t)res); +} + + + + +/* ARGSUSED */ +static ssize_t +html_blockheadtagname(struct md_mbuf *mbuf, + const struct md_args *args, int tok) +{ + size_t res; + + res = 0; + + switch (tok) { + case (ROFF_Sh): + if ( ! ml_puts(mbuf, "h1", &res)) + return(-1); + break; + case (ROFF_Ss): + if ( ! ml_puts(mbuf, "h2", &res)) + return(-1); + break; + default: + if ( ! ml_puts(mbuf, "div", &res)) + return(-1); + break; + } + + return((ssize_t)res); +} + + +/* ARGSUSED */ +static ssize_t +html_blocktagname(struct md_mbuf *mbuf, + const struct md_args *args, int tok) +{ + size_t res; + + res = 0; + + switch (tok) { case (ROFF_Bd): if ( ! ml_puts(mbuf, "pre", &res)) return(-1); @@ -124,40 +187,112 @@ html_blocktagname(struct md_mbuf *mbuf, break; } - return((size_t)res); + return((ssize_t)res); } /* ARGSUSED */ static ssize_t -html_blocktagargs(struct md_mbuf *mbuf, const struct md_args *args, +html_blockheadtagargs(struct md_mbuf *mbuf, const struct md_args *args, int tok, const int *argc, const char **argv) { + size_t res; + + res = 0; + + if ( ! ml_puts(mbuf, " class=\"head:", &res)) + return(0); + if ( ! ml_puts(mbuf, toknames[tok], &res)) + return(0); + if ( ! ml_puts(mbuf, "\"", &res)) + return(0); switch (tok) { default: + break; + } + + return(0); +} + + +/* ARGSUSED */ +static ssize_t +html_blockbodytagargs(struct md_mbuf *mbuf, const struct md_args *args, + int tok, const int *argc, const char **argv) +{ + size_t res; + + res = 0; + + if ( ! ml_puts(mbuf, " class=\"body:", &res)) return(0); + if ( ! ml_puts(mbuf, toknames[tok], &res)) + return(0); + if ( ! ml_puts(mbuf, "\"", &res)) + return(0); + + switch (tok) { + default: + break; } - return(-1); + return(res); } /* ARGSUSED */ static ssize_t -html_inlinetagargs(struct md_mbuf *mbuf, const struct md_args *args, +html_blocktagargs(struct md_mbuf *mbuf, const struct md_args *args, int tok, const int *argc, const char **argv) { + size_t res; + + res = 0; + + if ( ! ml_puts(mbuf, " class=\"block:", &res)) + return(0); + if ( ! ml_puts(mbuf, toknames[tok], &res)) + return(0); + if ( ! ml_puts(mbuf, "\"", &res)) + return(0); switch (tok) { default: + break; + } + + return(0); +} + + +/* ARGSUSED */ +static ssize_t +html_inlinetagargs(struct md_mbuf *mbuf, const struct md_args *args, + int tok, const int *argc, const char **argv) +{ + size_t res; + + res = 0; + + if ( ! ml_puts(mbuf, " class=\"inline:", &res)) return(0); + if ( ! ml_puts(mbuf, toknames[tok], &res)) + return(0); + if ( ! ml_puts(mbuf, "\"", &res)) + return(0); + + + switch (tok) { + default: + break; } - return(-1); + return(0); } +/* ARGSUSED */ static ssize_t html_inlinetagname(struct md_mbuf *mbuf, const struct md_args *args, int tok) @@ -167,14 +302,6 @@ html_inlinetagname(struct md_mbuf *mbuf, res = 0; switch (tok) { - case (ROFF_Sh): - if ( ! ml_puts(mbuf, "h1", &res)) - return(-1); - break; - case (ROFF_Ss): - if ( ! ml_puts(mbuf, "h2", &res)) - return(-1); - break; default: if ( ! ml_puts(mbuf, "span", &res)) return(-1); @@ -192,11 +319,24 @@ html_begintag(struct md_mbuf *mbuf, const struct md_args *args, { assert(ns != MD_NS_DEFAULT); - if (MD_NS_BLOCK == ns) { + switch (ns) { + case (MD_NS_BLOCK): if ( ! html_blocktagname(mbuf, args, tok)) return(0); return(html_blocktagargs(mbuf, args, tok, argc, argv)); + case (MD_NS_BODY): + if ( ! html_blockbodytagname(mbuf, args, tok)) + return(0); + return(html_blockbodytagargs(mbuf, args, + tok, argc, argv)); + case (MD_NS_HEAD): + if ( ! html_blockheadtagname(mbuf, args, tok)) + return(0); + return(html_blockheadtagargs(mbuf, args, + tok, argc, argv)); + default: + break; } if ( ! html_inlinetagname(mbuf, args, tok)) @@ -211,8 +351,16 @@ html_endtag(struct md_mbuf *mbuf, const struct md_args *args, { assert(ns != MD_NS_DEFAULT); - if (MD_NS_BLOCK == ns) + switch (ns) { + case (MD_NS_BLOCK): return(html_blocktagname(mbuf, args, tok)); + case (MD_NS_BODY): + return(html_blockbodytagname(mbuf, args, tok)); + case (MD_NS_HEAD): + return(html_blockheadtagname(mbuf, args, tok)); + default: + break; + } return(html_inlinetagname(mbuf, args, tok)); } diff --git a/mlg.c b/mlg.c index a7c211db..17ef1efd 100644 --- a/mlg.c +++ b/mlg.c @@ -1,4 +1,4 @@ -/* $Id: mlg.c,v 1.2 2008/12/03 19:21:58 kristaps Exp $ */ +/* $Id: mlg.c,v 1.3 2008/12/03 21:27:56 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -189,7 +189,7 @@ mlg_indent(struct md_mlg *p) { size_t count; - count = p->indent > MAXINDENT ? MAXINDENT : p->indent; + count = p->indent > MAXINDENT ? (size_t)MAXINDENT : p->indent; count *= INDENT; assert(0 == p->pos); @@ -212,6 +212,7 @@ mlg_newline(struct md_mlg *p) static void mlg_mode(struct md_mlg *p, enum md_tok ns) { + p->flags &= ~ML_OVERRIDE_ONE; p->last = ns; } @@ -252,7 +253,7 @@ mlg_data(struct md_mlg *p, int space, char *buf) if ( ! ml_nputstring(p->mbuf, bufp, sz, &p->pos)) return(0); - if (p->indent * MAXINDENT + sz >= COLUMNS) + if (p->indent * INDENT + sz >= COLUMNS) if ( ! mlg_newline(p)) return(0); if ( ! (ML_OVERRIDE_ALL & p->flags)) diff --git a/xml.c b/xml.c index 95c743bb..854c42b8 100644 --- a/xml.c +++ b/xml.c @@ -1,4 +1,4 @@ -/* $Id: xml.c,v 1.11 2008/12/03 19:21:58 kristaps Exp $ */ +/* $Id: xml.c,v 1.12 2008/12/03 21:27:56 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -37,6 +37,7 @@ static int xml_end(struct md_mbuf *, const struct md_args *); +/* ARGSUSED */ static int xml_begin(struct md_mbuf *mbuf, const struct md_args *args) { @@ -54,6 +55,7 @@ xml_begin(struct md_mbuf *mbuf, const struct md_args *args) } +/* ARGSUSED */ static int xml_end(struct md_mbuf *mbuf, const struct md_args *args) { @@ -67,6 +69,7 @@ xml_end(struct md_mbuf *mbuf, const struct md_args *args) } +/* ARGSUSED */ static ssize_t xml_begintag(struct md_mbuf *mbuf, const struct md_args *args, enum md_ns ns, int tok, @@ -97,14 +100,14 @@ xml_begintag(struct md_mbuf *mbuf, const struct md_args *args, break; } - if ( ! ml_nputs(mbuf, toknames[tok], - strlen(toknames[tok]), &res)) + if ( ! ml_puts(mbuf, toknames[tok], &res)) return(-1); return((ssize_t)res); } +/* ARGSUSED */ static ssize_t xml_endtag(struct md_mbuf *mbuf, const struct md_args *args, enum md_ns ns, int tok) @@ -134,8 +137,7 @@ xml_endtag(struct md_mbuf *mbuf, const struct md_args *args, break; } - if ( ! ml_nputs(mbuf, toknames[tok], - strlen(toknames[tok]), &res)) + if ( ! ml_puts(mbuf, toknames[tok], &res)) return(-1); return((ssize_t)res); -- cgit v1.2.3-56-ge451