=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.82 retrieving revision 1.88 diff -u -p -r1.82 -r1.88 --- mandoc/html.c 2009/11/09 05:11:46 1.82 +++ mandoc/html.c 2009/11/14 19:23:58 1.88 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.82 2009/11/09 05:11:46 kristaps Exp $ */ +/* $Id: html.c,v 1.88 2009/11/14 19:23:58 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -88,10 +88,11 @@ extern int getsubopt(char **, char * const *, char #endif -static void print_spec(struct html *, const char *, int); -static void print_res(struct html *, const char *, int); +static void print_spec(struct html *, const char *, size_t); +static void print_res(struct html *, const char *, size_t); static void print_ctag(struct html *, enum htmltag); -static void print_encode(struct html *, const char *); +static int print_encode(struct html *, const char *, int); +static void print_metaf(struct html *, enum roffdeco); void * @@ -193,12 +194,12 @@ print_gen_head(struct html *h) static void -print_spec(struct html *h, const char *p, int len) +print_spec(struct html *h, const char *p, size_t len) { const char *rhs; size_t sz; - rhs = chars_a2ascii(h->symtab, p, (size_t)len, &sz); + rhs = chars_a2ascii(h->symtab, p, len, &sz); if (NULL == rhs) return; @@ -207,12 +208,12 @@ print_spec(struct html *h, const char *p, int len) static void -print_res(struct html *h, const char *p, int len) +print_res(struct html *h, const char *p, size_t len) { const char *rhs; size_t sz; - rhs = chars_a2res(h->symtab, p, (size_t)len, &sz); + rhs = chars_a2res(h->symtab, p, len, &sz); if (NULL == rhs) return; @@ -221,13 +222,47 @@ print_res(struct html *h, const char *p, int len) static void -print_encode(struct html *h, const char *p) +print_metaf(struct html *h, enum roffdeco deco) { + const char *class; + struct htmlpair tag; + + switch (deco) { + case (DECO_BOLD): + class = "bold"; + break; + case (DECO_ITALIC): + class = "italic"; + break; + case (DECO_ROMAN): + class = "roman"; + break; + default: + abort(); + /* NOTREACHED */ + } + + if (h->metaf) { + assert(h->tags.head); + assert(h->metaf == h->tags.head); + print_tagq(h, h->metaf); + } + + PAIR_CLASS_INIT(&tag, class); + h->metaf = print_otag(h, TAG_SPAN, 1, &tag); +} + + +static int +print_encode(struct html *h, const char *p, int norecurse) +{ size_t sz; - int len; + int len, nospace; const char *seq; enum roffdeco deco; + nospace = 0; + for (; *p; p++) { sz = strcspn(p, "\\<>&"); @@ -257,12 +292,26 @@ print_encode(struct html *h, const char *p) case (DECO_SPECIAL): print_spec(h, seq, sz); break; + case (DECO_BOLD): + /* FALLTHROUGH */ + case (DECO_ITALIC): + /* FALLTHROUGH */ + case (DECO_ROMAN): + if (norecurse) + break; + print_metaf(h, deco); + break; default: break; } p += len - 1; + + if (DECO_NOSPACE == deco && '\0' == *(p + 1)) + nospace = 1; } + + return(nospace); } @@ -293,17 +342,12 @@ print_otag(struct html *h, enum htmltag tag, for (i = 0; i < sz; i++) { printf(" %s=\"", htmlattrs[p[i].key]); assert(p->val); - print_encode(h, p[i].val); + (void)print_encode(h, p[i].val, 1); putchar('\"'); } putchar('>'); h->flags |= HTML_NOSPACE; - if (HTML_CLRLINE & htmltags[tag].flags) - h->flags |= HTML_NEWLINE; - else - h->flags &= ~HTML_NEWLINE; - return(t); } @@ -316,10 +360,8 @@ print_ctag(struct html *h, enum htmltag tag) printf("", htmltags[tag].name); if (HTML_CLRLINE & htmltags[tag].flags) { h->flags |= HTML_NOSPACE; - h->flags |= HTML_NEWLINE; putchar('\n'); - } else - h->flags &= ~HTML_NEWLINE; + } } @@ -365,11 +407,9 @@ print_text(struct html *h, const char *p) if ( ! (h->flags & HTML_NOSPACE)) putchar(' '); - h->flags &= ~HTML_NOSPACE; - h->flags &= ~HTML_NEWLINE; - - if (p) - print_encode(h, p); + assert(p); + if ( ! print_encode(h, p, 0)) + h->flags &= ~HTML_NOSPACE; if (*p && 0 == *(p + 1)) switch (*p) {