]> git.cameronkatri.com Git - mandoc.git/blobdiff - html.c
simplify a few accesses to fields of structs, using auxiliary pointer
[mandoc.git] / html.c
diff --git a/html.c b/html.c
index 6e18fac291f0f8ff3f712dbfe434b2646fe132ae..71c9c711e825851b2b52bec5a6d58d5904dcde11 100644 (file)
--- a/html.c
+++ b/html.c
@@ -1,7 +1,7 @@
-/* $Id: html.c,v 1.269 2020/04/19 15:16:56 schwarze Exp $ */
+/* $Id: html.c,v 1.275 2021/09/09 14:47:24 schwarze Exp $ */
 /*
- * Copyright (c) 2011-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2011-2015, 2017-2021 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -81,7 +81,7 @@ static        const struct htmldata htmltags[TAG_MAX] = {
        {"h1",          HTML_TOPHRASE | HTML_NLAROUND},
        {"h2",          HTML_TOPHRASE | HTML_NLAROUND},
        {"p",           HTML_TOPHRASE | HTML_NLAROUND | HTML_INDENT},
-       {"pre",         HTML_TOPHRASE | HTML_NLALL | HTML_NOINDENT},
+       {"pre",         HTML_TOPHRASE | HTML_NLAROUND | HTML_NOINDENT},
        {"a",           HTML_INPHRASE | HTML_TOPHRASE},
        {"b",           HTML_INPHRASE | HTML_TOPHRASE},
        {"cite",        HTML_INPHRASE | HTML_TOPHRASE},
@@ -91,6 +91,7 @@ static        const struct htmldata htmltags[TAG_MAX] = {
        {"span",        HTML_INPHRASE | HTML_TOPHRASE},
        {"var",         HTML_INPHRASE | HTML_TOPHRASE},
        {"br",          HTML_INPHRASE | HTML_NOSTACK | HTML_NLALL},
+       {"hr",          HTML_INPHRASE | HTML_NOSTACK},
        {"mark",        HTML_INPHRASE },
        {"math",        HTML_INPHRASE | HTML_NLALL | HTML_INDENT},
        {"mrow",        0},
@@ -140,6 +141,7 @@ html_alloc(const struct manoutput *outopts)
        h = mandoc_calloc(1, sizeof(struct html));
 
        h->tag = NULL;
+       h->metac = h->metal = ESCAPE_FONTROMAN;
        h->style = outopts->style;
        if ((h->base_man1 = outopts->man) == NULL)
                h->base_man2 = NULL;
@@ -195,6 +197,8 @@ print_gen_head(struct html *h)
        struct tag      *t;
 
        print_otag(h, TAG_META, "?", "charset", "utf-8");
+       print_otag(h, TAG_META, "??", "name", "viewport",
+           "content", "width=device-width, initial-scale=1.0");
        if (h->style != NULL) {
                print_otag(h, TAG_LINK, "?h??", "rel", "stylesheet",
                    h->style, "type", "text/css", "media", "all");
@@ -237,8 +241,10 @@ html_setfont(struct html *h, enum mandoc_esc font)
        case ESCAPE_FONTITALIC:
        case ESCAPE_FONTBOLD:
        case ESCAPE_FONTBI:
-       case ESCAPE_FONTCW:
        case ESCAPE_FONTROMAN:
+       case ESCAPE_FONTCR:
+       case ESCAPE_FONTCB:
+       case ESCAPE_FONTCI:
                break;
        case ESCAPE_FONT:
                font = ESCAPE_FONTROMAN;
@@ -269,9 +275,17 @@ print_metaf(struct html *h)
                h->metaf = print_otag(h, TAG_B, "");
                print_otag(h, TAG_I, "");
                break;
-       case ESCAPE_FONTCW:
+       case ESCAPE_FONTCR:
                h->metaf = print_otag(h, TAG_SPAN, "c", "Li");
                break;
+       case ESCAPE_FONTCB:
+               h->metaf = print_otag(h, TAG_SPAN, "c", "Li");
+               print_otag(h, TAG_B, "");
+               break;
+       case ESCAPE_FONTCI:
+               h->metaf = print_otag(h, TAG_SPAN, "c", "Li");
+               print_otag(h, TAG_I, "");
+               break;
        default:
                break;
        }
@@ -383,11 +397,12 @@ html_make_id(const struct roff_node *n, int unique)
         * permitted in URL-fragment strings according to the
         * explicit list at:
         * https://url.spec.whatwg.org/#url-fragment-string
+        * In addition, reserve '~' for ordinal suffixes.
         */
 
        for (cp = buf; *cp != '\0'; cp++)
                if (isalnum((unsigned char)*cp) == 0 &&
-                   strchr("!$&'()*+,-./:;=?@_~", *cp) == NULL)
+                   strchr("!$&'()*+,-./:;=?@_", *cp) == NULL)
                        *cp = '_';
 
        if (unique == 0)
@@ -407,7 +422,7 @@ html_make_id(const struct roff_node *n, int unique)
 
        if (entry->ord > 1) {
                cp = buf;
-               mandoc_asprintf(&buf, "%s_%d", cp, entry->ord);
+               mandoc_asprintf(&buf, "%s~%d", cp, entry->ord);
                free(cp);
        }
        return buf;
@@ -499,8 +514,10 @@ print_encode(struct html *h, const char *p, const char *pend, int norecurse)
                case ESCAPE_FONTBOLD:
                case ESCAPE_FONTITALIC:
                case ESCAPE_FONTBI:
-               case ESCAPE_FONTCW:
                case ESCAPE_FONTROMAN:
+               case ESCAPE_FONTCR:
+               case ESCAPE_FONTCB:
+               case ESCAPE_FONTCI:
                        if (0 == norecurse) {
                                h->flags |= HTML_NOSPACE;
                                if (html_setfont(h, esc))