summaryrefslogtreecommitdiffstats
path: root/html.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2020-04-06 10:16:17 +0000
committerIngo Schwarze <schwarze@openbsd.org>2020-04-06 10:16:17 +0000
commitb19e09dbeb7e957bca580776d8b3a4651016c904 (patch)
tree9decba67ceddc230203a9a25445f231797d73b56 /html.c
parent9c50b3f3dd65454028a85113ebc01c5f1f8dabf5 (diff)
downloadmandoc-b19e09dbeb7e957bca580776d8b3a4651016c904.tar.gz
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 'html.c')
-rw-r--r--html.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/html.c b/html.c
index 4fc0ecd4..3b5f2405 100644
--- a/html.c
+++ b/html.c
@@ -362,7 +362,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;
@@ -769,13 +769,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;
@@ -788,8 +790,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;
}