From 78bf8cb3c86e47d614af8f2629bdc00e459cf758 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Tue, 7 Apr 2020 22:56:02 +0000 Subject: Separate the place to put the 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. --- html.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index 3b5f2405..79288939 100644 --- a/html.c +++ b/html.c @@ -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; } -- cgit