diff options
-rw-r--r-- | html.c | 180 | ||||
-rw-r--r-- | mlg.c | 5 | ||||
-rw-r--r-- | xml.c | 10 |
3 files changed, 173 insertions, 22 deletions
@@ -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)); } @@ -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)) @@ -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); |