=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.206 retrieving revision 1.215 diff -u -p -r1.206 -r1.215 --- mandoc/html.c 2017/02/05 19:29:19 1.206 +++ mandoc/html.c 2017/06/23 02:32:12 1.215 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.206 2017/02/05 19:29:19 schwarze Exp $ */ +/* $Id: html.c,v 1.215 2017/06/23 02:32:12 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons * Copyright (c) 2011-2015, 2017 Ingo Schwarze @@ -28,8 +28,9 @@ #include #include -#include "mandoc.h" #include "mandoc_aux.h" +#include "mandoc.h" +#include "roff.h" #include "out.h" #include "html.h" #include "manconf.h" @@ -76,6 +77,7 @@ static const struct htmldata htmltags[TAG_MAX] = { {"dt", HTML_NLAROUND}, {"dd", HTML_NLAROUND | HTML_INDENT}, {"pre", HTML_NLALL | HTML_NOINDENT}, + {"var", 0}, {"cite", 0}, {"b", 0}, {"i", 0}, @@ -85,6 +87,7 @@ static const struct htmldata htmltags[TAG_MAX] = { {"math", HTML_NLALL | HTML_INDENT}, {"mrow", 0}, {"mi", 0}, + {"mn", 0}, {"mo", 0}, {"msup", 0}, {"msub", 0}, @@ -235,6 +238,28 @@ print_metaf(struct html *h, enum mandoc_esc deco) } } +char * +html_make_id(const struct roff_node *n) +{ + const struct roff_node *nch; + char *buf, *cp; + + for (nch = n->child; nch != NULL; nch = nch->next) + if (nch->type != ROFFT_TEXT) + return NULL; + + buf = NULL; + deroff(&buf, n); + + /* http://www.w3.org/TR/html5/dom.html#the-id-attribute */ + + for (cp = buf; *cp != '\0'; cp++) + if (*cp == ' ') + *cp = '_'; + + return buf; +} + int html_strlen(const char *cp) { @@ -321,16 +346,18 @@ static int print_encode(struct html *h, const char *p, const char *pend, int norecurse) { char numbuf[16]; - size_t sz; - int c, len, nospace; + struct tag *t; const char *seq; + size_t sz; + int c, len, breakline, nospace; enum mandoc_esc esc; - static const char rejs[9] = { '\\', '<', '>', '&', '"', + static const char rejs[10] = { ' ', '\\', '<', '>', '&', '"', ASCII_NBRSP, ASCII_HYPH, ASCII_BREAK, '\0' }; if (pend == NULL) pend = strchr(p, '\0'); + breakline = 0; nospace = 0; while (p < pend) { @@ -341,14 +368,28 @@ print_encode(struct html *h, const char *p, const char } for (sz = strcspn(p, rejs); sz-- && p < pend; p++) - if (*p == ' ') - print_endword(h); - else - print_byte(h, *p); + print_byte(h, *p); + if (breakline && + (p >= pend || *p == ' ' || *p == ASCII_NBRSP)) { + t = print_otag(h, TAG_DIV, ""); + print_text(h, "\\~"); + print_tagq(h, t); + breakline = 0; + while (p < pend && (*p == ' ' || *p == ASCII_NBRSP)) + p++; + continue; + } + if (p >= pend) break; + if (*p == ' ') { + print_endword(h); + p++; + continue; + } + if (print_escape(h, *p++)) continue; @@ -393,6 +434,9 @@ print_encode(struct html *h, const char *p, const char if (c <= 0) continue; break; + case ESCAPE_BREAK: + breakline = 1; + continue; case ESCAPE_NOSPACE: if ('\0' == *p) nospace = 1; @@ -533,18 +577,25 @@ print_otag(struct html *h, enum htmltag tag, const cha print_byte(h, '='); print_byte(h, '"'); switch (*fmt) { - case 'M': - print_href(h, arg1, arg2, 1); - fmt++; - break; case 'I': print_href(h, arg1, NULL, 0); fmt++; break; + case 'M': + print_href(h, arg1, arg2, 1); + fmt++; + break; case 'R': print_byte(h, '#'); + print_encode(h, arg1, NULL, 1); fmt++; - /* FALLTHROUGH */ + break; + case 'T': + print_encode(h, arg1, NULL, 1); + print_word(h, "\" title=\""); + print_encode(h, arg1, NULL, 1); + fmt++; + break; default: print_encode(h, arg1, NULL, 1); break; @@ -578,13 +629,21 @@ print_otag(struct html *h, enum htmltag tag, const cha SCALE_VS_INIT(su, i); break; case 'w': - case 'W': if ((arg2 = va_arg(ap, char *)) == NULL) break; su = &mysu; a2width(arg2, su); - if (fmt[-1] == 'W') + if (*fmt == '+') { + /* Increase to make even bold text fit. */ + su->scale *= 1.2; + /* Add padding. */ + su->scale += 3.0; + fmt++; + } + if (*fmt == '-') { su->scale *= -1.0; + fmt++; + } break; default: abort(); @@ -911,7 +970,10 @@ print_word(struct html *h, const char *cp) static void a2width(const char *p, struct roffsu *su) { - if (a2roffsu(p, su, SCALE_MAX) < 2) { + const char *end; + + end = a2roffsu(p, su, SCALE_MAX); + if (end == NULL || *end != '\0') { su->unit = SCALE_EN; su->scale = html_strlen(p); } else if (su->scale < 0.0)