=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.84 retrieving revision 1.89 diff -u -p -r1.84 -r1.89 --- mandoc/html.c 2009/11/12 08:21:05 1.84 +++ mandoc/html.c 2009/11/15 06:45:31 1.89 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.84 2009/11/12 08:21:05 kristaps Exp $ */ +/* $Id: html.c,v 1.89 2009/11/15 06:45:31 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -91,7 +91,8 @@ extern int getsubopt(char **, char * const *, char 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 * @@ -221,13 +222,47 @@ print_res(struct html *h, const char *p, size_t 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,6 +292,15 @@ 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; } @@ -264,8 +308,10 @@ print_encode(struct html *h, const char *p) p += len - 1; if (DECO_NOSPACE == deco && '\0' == *(p + 1)) - h->flags |= HTML_NOSPACE; + nospace = 1; } + + return(nospace); } @@ -296,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); } @@ -319,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; + } } @@ -368,12 +407,10 @@ print_text(struct html *h, const char *p) if ( ! (h->flags & HTML_NOSPACE)) putchar(' '); - h->flags &= ~HTML_NOSPACE; - h->flags &= ~HTML_NEWLINE; + assert(p); + if ( ! print_encode(h, p, 0)) + h->flags &= ~HTML_NOSPACE; - if (p) - print_encode(h, p); - if (*p && 0 == *(p + 1)) switch (*p) { case('('): @@ -395,6 +432,8 @@ print_tagq(struct html *h, const struct tag *until) struct tag *tag; while ((tag = h->tags.head) != NULL) { + if (tag == h->metaf) + h->metaf = NULL; print_ctag(h, tag->tag); h->tags.head = tag->next; free(tag); @@ -412,6 +451,8 @@ print_stagq(struct html *h, const struct tag *suntil) while ((tag = h->tags.head) != NULL) { if (suntil && tag == suntil) return; + if (tag == h->metaf) + h->metaf = NULL; print_ctag(h, tag->tag); h->tags.head = tag->next; free(tag);