diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2020-04-07 22:56:02 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2020-04-07 22:56:02 +0000 |
commit | f4c07cc80595b2276a99fd6e5c95c734187feaab (patch) | |
tree | 23f120c67a8a3f6a33615c3d4d9f8115ed9ac08d /html.c | |
parent | 70b71d1de24478a8fcc7413f1cb42c83db416bc3 (diff) | |
download | mandoc-f4c07cc80595b2276a99fd6e5c95c734187feaab.tar.gz mandoc-f4c07cc80595b2276a99fd6e5c95c734187feaab.tar.zst mandoc-f4c07cc80595b2276a99fd6e5c95c734187feaab.zip |
Separate the place to put the <a href> permalink (now marked
with NODE_HREF) from the target element of the link (still marked
with NODE_ID). In many cases, use this to move the target to the
beginning of the paragraph, such that readers don't get dropped
into the middle of a sentence.
Diffstat (limited to 'html.c')
-rw-r--r-- | html.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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 <schwarze@openbsd.org> * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> @@ -779,18 +779,20 @@ print_otag_id(struct html *h, enum htmltag elemtype, const char *cattr, { 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, const char *cattr, 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; } |