=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.265 retrieving revision 1.266 diff -u -p -r1.265 -r1.266 --- mandoc/html.c 2020/04/06 10:16:17 1.265 +++ mandoc/html.c 2020/04/07 22:56:02 1.266 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.265 2020/04/06 10:16:17 schwarze Exp $ */ +/* $Id: html.c,v 1.266 2020/04/07 22:56:02 schwarze Exp $ */ /* * Copyright (c) 2011-2015, 2017-2020 Ingo Schwarze * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons @@ -779,18 +779,20 @@ print_otag_id(struct html *h, enum htmltag elemtype, c { struct roff_node *nch; struct tag *ret, *t; - const char *id; + char *id, *href; ret = NULL; - id = NULL; + id = href = NULL; if (n->flags & NODE_ID) id = html_make_id(n, 1); - if (id != NULL && htmltags[elemtype].flags & HTML_INPHRASE) - ret = print_otag(h, TAG_A, "chR", "permalink", id); + if (n->flags & NODE_HREF) + href = id == NULL ? html_make_id(n, 0) : id; + if (href != NULL && htmltags[elemtype].flags & HTML_INPHRASE) + ret = print_otag(h, TAG_A, "chR", "permalink", href); t = print_otag(h, elemtype, "ci", cattr, id); if (ret == NULL) { ret = t; - if (id != NULL && (nch = n->child) != NULL) { + if (href != NULL && (nch = n->child) != NULL) { /* man(7) is safe, it tags phrasing content only. */ if (n->tok > MDOC_MAX || htmltags[elemtype].flags & HTML_TOPHRASE) @@ -799,9 +801,11 @@ print_otag_id(struct html *h, enum htmltag elemtype, c while (nch != NULL && nch->type == ROFFT_TEXT) nch = nch->next; if (nch == NULL) - print_otag(h, TAG_A, "chR", "permalink", id); + print_otag(h, TAG_A, "chR", "permalink", href); } } + if (id == NULL) + free(href); return ret; }