]> git.cameronkatri.com Git - mandoc.git/blobdiff - mdoc_html.c
When rendering the \h (horizontal motion) low-level roff(7) escape
[mandoc.git] / mdoc_html.c
index 8ae8703f7b486e536fd46d3a0594b3af4fdce775..c0a0a6a5697876c5197a357fc834be7f245cd0b7 100644 (file)
@@ -1,6 +1,6 @@
-/* $Id: mdoc_html.c,v 1.336 2020/03/13 15:32:28 schwarze Exp $ */
+/* $Id: mdoc_html.c,v 1.342 2021/03/30 19:26:20 schwarze Exp $ */
 /*
- * Copyright (c) 2014-2020 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014-2021 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -349,12 +349,11 @@ print_mdoc_node(MDOC_ARGS)
        if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT)
                return;
 
-       if (n->flags & NODE_NOFILL) {
-               html_fillmode(h, ROFF_nf);
-               if (n->flags & NODE_LINE)
-                       print_endline(h);
-       } else
+       if ((n->flags & NODE_NOFILL) == 0)
                html_fillmode(h, ROFF_fi);
+       else if (html_fillmode(h, ROFF_nf) == ROFF_nf &&
+           n->tok != ROFF_fi && n->flags & NODE_LINE)
+               print_endline(h);
 
        child = 1;
        n->flags &= ~NODE_ENDED;
@@ -377,10 +376,13 @@ print_mdoc_node(MDOC_ARGS)
                }
                t = h->tag;
                t->refcnt++;
-               if (NODE_DELIMC & n->flags)
+               if (n->flags & NODE_DELIMC)
                        h->flags |= HTML_NOSPACE;
-               print_text(h, n->string);
-               if (NODE_DELIMO & n->flags)
+               if (n->flags & NODE_HREF)
+                       print_tagged_text(h, n->string, n);
+               else
+                       print_text(h, n->string);
+               if (n->flags & NODE_DELIMO)
                        h->flags |= HTML_NOSPACE;
                break;
        case ROFFT_EQN:
@@ -569,7 +571,6 @@ mdoc_sh_pre(MDOC_ARGS)
                print_otag(h, TAG_SECTION, "c", "Sh");
                break;
        case ROFFT_HEAD:
-               n->flags |= NODE_ID;
                print_otag_id(h, TAG_H1, "Sh", n);
                break;
        case ROFFT_BODY:
@@ -591,7 +592,6 @@ mdoc_ss_pre(MDOC_ARGS)
                print_otag(h, TAG_SECTION, "c", "Ss");
                break;
        case ROFFT_HEAD:
-               n->flags |= NODE_ID;
                print_otag_id(h, TAG_H2, "Ss", n);
                break;
        case ROFFT_BODY:
@@ -694,8 +694,10 @@ mdoc_tg_pre(MDOC_ARGS)
 {
        char    *id;
 
-       if ((id = html_make_id(n, 1)) != NULL)
+       if ((id = html_make_id(n, 1)) != NULL) {
                print_tagq(h, print_otag(h, TAG_MARK, "i", id));
+               free(id);
+       }
        return 0;
 }
 
@@ -743,7 +745,7 @@ mdoc_it_pre(MDOC_ARGS)
                case ROFFT_HEAD:
                        return 0;
                case ROFFT_BODY:
-                       print_otag(h, TAG_LI, "");
+                       print_otag_id(h, TAG_LI, NULL, n);
                        break;
                default:
                        break;
@@ -755,7 +757,7 @@ mdoc_it_pre(MDOC_ARGS)
        case LIST_ohang:
                switch (n->type) {
                case ROFFT_HEAD:
-                       print_otag(h, TAG_DT, "");
+                       print_otag_id(h, TAG_DT, NULL, n);
                        break;
                case ROFFT_BODY:
                        print_otag(h, TAG_DD, "");
@@ -767,7 +769,7 @@ mdoc_it_pre(MDOC_ARGS)
        case LIST_tag:
                switch (n->type) {
                case ROFFT_HEAD:
-                       print_otag(h, TAG_DT, "");
+                       print_otag_id(h, TAG_DT, NULL, n);
                        break;
                case ROFFT_BODY:
                        if (n->child == NULL) {
@@ -788,7 +790,7 @@ mdoc_it_pre(MDOC_ARGS)
                        print_otag(h, TAG_TD, "");
                        break;
                default:
-                       print_otag(h, TAG_TR, "");
+                       print_otag_id(h, TAG_TR, NULL, n);
                }
        default:
                break;
@@ -854,8 +856,8 @@ mdoc_bl_pre(MDOC_ARGS)
        case LIST_tag:
                if (bl->offs)
                        print_otag(h, TAG_DIV, "c", "Bd-indent");
-               print_otag(h, TAG_DL, "c", bl->comp ?
-                   "Bl-tag Bl-compact" : "Bl-tag");
+               print_otag_id(h, TAG_DL,
+                   bl->comp ? "Bl-tag Bl-compact" : "Bl-tag", n->body);
                return 1;
        case LIST_column:
                elemtype = TAG_TABLE;
@@ -868,7 +870,7 @@ mdoc_bl_pre(MDOC_ARGS)
                (void)strlcat(cattr, " Bd-indent", sizeof(cattr));
        if (bl->comp)
                (void)strlcat(cattr, " Bl-compact", sizeof(cattr));
-       print_otag(h, elemtype, "c", cattr);
+       print_otag_id(h, elemtype, cattr, n->body);
        return 1;
 }
 
@@ -900,15 +902,15 @@ mdoc_d1_pre(MDOC_ARGS)
        switch (n->type) {
        case ROFFT_BLOCK:
                html_close_paragraph(h);
-               break;
+               return 1;
        case ROFFT_HEAD:
                return 0;
        case ROFFT_BODY:
-               return 1;
+               break;
        default:
                abort();
        }
-       print_otag(h, TAG_DIV, "c", "Bd Bd-indent");
+       print_otag_id(h, TAG_DIV, "Bd Bd-indent", n);
        if (n->tok == MDOC_Dl)
                print_otag(h, TAG_CODE, "c", "Li");
        return 1;
@@ -928,7 +930,7 @@ mdoc_sx_pre(MDOC_ARGS)
 static int
 mdoc_bd_pre(MDOC_ARGS)
 {
-       char                     buf[16];
+       char                     buf[20];
        struct roff_node        *nn;
        int                      comp;
 
@@ -965,7 +967,10 @@ mdoc_bd_pre(MDOC_ARGS)
            strcmp(n->norm->Bd.offs, "left") != 0)
                (void)strlcat(buf, " Bd-indent", sizeof(buf));
 
-       print_otag(h, TAG_DIV, "c", buf);
+       if (n->norm->Bd.type == DISP_literal)
+               (void)strlcat(buf, " Li", sizeof(buf));
+
+       print_otag_id(h, TAG_DIV, buf, n);
        return 1;
 }
 
@@ -1210,13 +1215,21 @@ mdoc_skip_pre(MDOC_ARGS)
 static int
 mdoc_pp_pre(MDOC_ARGS)
 {
+       char    *id;
+
        if (n->flags & NODE_NOFILL) {
                print_endline(h);
-               h->col = 1;
-               print_endline(h);
+               if (n->flags & NODE_ID)
+                       mdoc_tg_pre(meta, n, h);
+               else {
+                       h->col = 1;
+                       print_endline(h);
+               }
        } else {
                html_close_paragraph(h);
-               print_otag(h, TAG_P, "c", "Pp");
+               id = n->flags & NODE_ID ? html_make_id(n, 1) : NULL;
+               print_otag(h, TAG_P, "ci", "Pp", id);
+               free(id);
        }
        return 0;
 }