=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/html.c,v retrieving revision 1.135 retrieving revision 1.136 diff -c -r1.135 -r1.136 *** src/usr.bin/mandoc/html.c 2020/03/13 00:31:04 1.135 --- src/usr.bin/mandoc/html.c 2020/04/06 09:55:49 1.136 *************** *** 1,4 **** ! /* $OpenBSD: html.c,v 1.135 2020/03/13 00:31:04 schwarze Exp $ */ /* * Copyright (c) 2011-2015, 2017-2020 Ingo Schwarze * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons --- 1,4 ---- ! /* $OpenBSD: html.c,v 1.136 2020/04/06 09:55:49 schwarze Exp $ */ /* * Copyright (c) 2011-2015, 2017-2020 Ingo Schwarze * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons *************** *** 360,366 **** return NULL; break; default: ! if (n->child->type != ROFFT_TEXT) return NULL; buf = mandoc_strdup(n->child->string); break; --- 360,366 ---- return NULL; break; default: ! if (n->child == NULL || n->child->type != ROFFT_TEXT) return NULL; buf = mandoc_strdup(n->child->string); break; *************** *** 767,779 **** /* * 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. */ struct tag * print_otag_id(struct html *h, enum htmltag elemtype, const char *cattr, struct roff_node *n) { struct tag *ret, *t; const char *id; --- 767,781 ---- /* * Print an element with an optional "id=" attribute. ! * 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,793 **** t = print_otag(h, elemtype, "ci", cattr, id); if (ret == NULL) { ret = t; ! if (id != NULL) ! print_otag(h, TAG_A, "chR", "permalink", id); } return ret; } --- 788,804 ---- t = print_otag(h, elemtype, "ci", cattr, id); if (ret == NULL) { ret = t; ! 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; }