=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/html.c,v retrieving revision 1.136 retrieving revision 1.137 diff -u -r1.136 -r1.137 --- src/usr.bin/mandoc/html.c 2020/04/06 09:55:49 1.136 +++ src/usr.bin/mandoc/html.c 2020/04/07 22:45:37 1.137 @@ -1,4 +1,4 @@ -/* $OpenBSD: html.c,v 1.136 2020/04/06 09:55:49 schwarze Exp $ */ +/* $OpenBSD: html.c,v 1.137 2020/04/07 22:45:37 schwarze Exp $ */ /* * Copyright (c) 2011-2015, 2017-2020 Ingo Schwarze * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons @@ -777,18 +777,20 @@ { 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) @@ -797,9 +799,11 @@ 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; }