summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/html.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2020-04-06 09:55:51 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2020-04-06 09:55:51 +0000
commit8b440b4adf0207c9d0637b16817fda9700a8a0e9 (patch)
tree32ef9dde1ac1a79fc25501c9f0d7b80395e0a540 /usr.bin/mandoc/html.c
parentcd810fb4ab3cd85588a2f3e795b5c12ca43b1b28 (diff)
Support manual tagging of .Pp, .Bd, .D1, .Dl, .Bl, and .It.
In HTML output, improve the logic for writing inside permalinks: skip them when there is no child content or when there is a risk that the children might contain flow content.
Diffstat (limited to 'usr.bin/mandoc/html.c')
-rw-r--r--usr.bin/mandoc/html.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c
index c7c87c67a4e..e15c680b296 100644
--- a/usr.bin/mandoc/html.c
+++ b/usr.bin/mandoc/html.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: html.c,v 1.135 2020/03/13 00:31:04 schwarze Exp $ */
+/* $OpenBSD: html.c,v 1.136 2020/04/06 09:55:49 schwarze Exp $ */
/*
* Copyright (c) 2011-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -360,7 +360,7 @@ html_make_id(const struct roff_node *n, int unique)
return NULL;
break;
default:
- if (n->child->type != ROFFT_TEXT)
+ if (n->child == NULL || n->child->type != ROFFT_TEXT)
return NULL;
buf = mandoc_strdup(n->child->string);
break;
@@ -767,13 +767,15 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...)
/*
* Print an element with an optional "id=" attribute.
- * If there is an "id=" attribute, also add a permalink:
- * outside if it's a phrasing element, or inside otherwise.
+ * If the element has phrasing content and an "id=" attribute,
+ * also add a permalink: outside if it can be in phrasing context,
+ * inside otherwise.
*/
struct tag *
print_otag_id(struct html *h, enum htmltag elemtype, const char *cattr,
struct roff_node *n)
{
+ struct roff_node *nch;
struct tag *ret, *t;
const char *id;
@@ -786,8 +788,17 @@ print_otag_id(struct html *h, enum htmltag elemtype, const char *cattr,
t = print_otag(h, elemtype, "ci", cattr, id);
if (ret == NULL) {
ret = t;
- if (id != NULL)
- print_otag(h, TAG_A, "chR", "permalink", id);
+ if (id != NULL && (nch = n->child) != NULL) {
+ /* man(7) is safe, it tags phrasing content only. */
+ if (n->tok > MDOC_MAX ||
+ htmltags[elemtype].flags & HTML_TOPHRASE)
+ nch = NULL;
+ else /* For mdoc(7), beware of nested blocks. */
+ while (nch != NULL && nch->type == ROFFT_TEXT)
+ nch = nch->next;
+ if (nch == NULL)
+ print_otag(h, TAG_A, "chR", "permalink", id);
+ }
}
return ret;
}