From cb9be671cf6346f9dd06b4901b4a89e2f6c67934 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Mon, 17 Apr 2017 12:53:29 +0000 Subject: Fix handling of trailing punctuation in .Lk. This macro is unusual in so far as trailing punction needs to remain inside the scope because it must be inside, not after the display of long URIs in terminal output mode. Improves formatting of fw_update(1), help(1), less(1), sendbug(1), acx(4), inet6(4), ipsec(4), oce(4), isakmpd.conf(5), afterboot(8), release(8), traceroute(8). --- mdoc_html.c | 22 ++++++++++++++-------- mdoc_macro.c | 6 +++++- mdoc_man.c | 14 +++++++++++--- mdoc_markdown.c | 17 ++++++++++++++--- mdoc_term.c | 16 +++++++++++----- 5 files changed, 55 insertions(+), 20 deletions(-) diff --git a/mdoc_html.c b/mdoc_html.c index 6987525c..61395d9b 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -1346,19 +1346,25 @@ mdoc_sp_pre(MDOC_ARGS) static int mdoc_lk_pre(MDOC_ARGS) { - if (NULL == (n = n->child)) - return 0; - - assert(n->type == ROFFT_TEXT); + struct tag *t; - print_otag(h, TAG_A, "cTh", "Lk", n->string); + if ((n = n->child) == NULL) + return 0; - if (NULL == n->next) + /* Link target and link text. */ + t = print_otag(h, TAG_A, "cTh", "Lk", n->string); + if (n->next == NULL || n->next->flags & NODE_DELIMC) print_text(h, n->string); - - for (n = n->next; n; n = n->next) + for (n = n->next; n != NULL && !(n->flags & NODE_DELIMC); n = n->next) print_text(h, n->string); + print_tagq(h, t); + /* Trailing punctuation. */ + while (n != NULL) { + h->flags |= HTML_NOSPACE; + print_text(h, n->string); + n = n->next; + } return 0; } diff --git a/mdoc_macro.c b/mdoc_macro.c index f6634b62..73d0ad79 100644 --- a/mdoc_macro.c +++ b/mdoc_macro.c @@ -903,8 +903,10 @@ in_line(MACRO_PROT_ARGS) } } - if (scope) + if (scope && tok != MDOC_Lk) { rew_elem(mdoc, tok); + scope = 0; + } /* * If no elements have been collected and we're allowed to have @@ -924,6 +926,8 @@ in_line(MACRO_PROT_ARGS) } if (nl) append_delims(mdoc, line, pos, buf); + if (scope) + rew_elem(mdoc, tok); } static void diff --git a/mdoc_man.c b/mdoc_man.c index e9705a18..c94f633c 100644 --- a/mdoc_man.c +++ b/mdoc_man.c @@ -1465,12 +1465,13 @@ pre_lk(DECL_ARGS) { const struct roff_node *link, *descr; - if (NULL == (link = n->child)) + if ((link = n->child) == NULL) return 0; - if (NULL != (descr = link->next)) { + /* Link text. */ + if ((descr = link->next) != NULL && !(descr->flags & NODE_DELIMC)) { font_push('I'); - while (NULL != descr) { + while (descr != NULL && !(descr->flags & NODE_DELIMC)) { print_word(descr->string); descr = descr->next; } @@ -1478,9 +1479,16 @@ pre_lk(DECL_ARGS) print_word(":"); } + /* Link target. */ font_push('B'); print_word(link->string); font_pop(); + + /* Trailing punctuation. */ + while (descr != NULL) { + print_word(descr->string); + descr = descr->next; + } return 0; } diff --git a/mdoc_markdown.c b/mdoc_markdown.c index 84e75a12..a9fba790 100644 --- a/mdoc_markdown.c +++ b/mdoc_markdown.c @@ -1304,18 +1304,29 @@ md_pre_Lk(struct roff_node *n) if ((link = n->child) == NULL) return 0; - descr = link->next == NULL ? link : link->next; + /* Link text. */ + descr = link->next; + if (descr == NULL || descr->flags & NODE_DELIMC) + descr = link; /* no text */ md_rawword("["); outflags &= ~MD_spc; do { md_word(descr->string); - descr = link->next == NULL ? NULL : descr->next; - } while (descr != NULL); + descr = descr->next; + } while (descr != NULL && !(descr->flags & NODE_DELIMC)); outflags &= ~MD_spc; + + /* Link target. */ md_rawword("]("); md_uri(link->string); outflags &= ~MD_spc; md_rawword(")"); + + /* Trailing punctuation. */ + while (descr != NULL) { + md_word(descr->string); + descr = descr->next; + } return 0; } diff --git a/mdoc_term.c b/mdoc_term.c index fa6301ed..61a3a17f 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1995,12 +1995,13 @@ termp_lk_pre(DECL_ARGS) const struct roff_node *link, *descr; int display; - if (NULL == (link = n->child)) + if ((link = n->child) == NULL) return 0; - if (NULL != (descr = link->next)) { + /* Link text. */ + if ((descr = link->next) != NULL && !(descr->flags & NODE_DELIMC)) { term_fontpush(p, TERMFONT_UNDER); - while (NULL != descr) { + while (descr != NULL && !(descr->flags & NODE_DELIMC)) { term_word(p, descr->string); descr = descr->next; } @@ -2009,19 +2010,24 @@ termp_lk_pre(DECL_ARGS) term_word(p, ":"); } + /* Link target. */ display = term_strlen(p, link->string) >= 26; if (display) { term_newln(p); p->offset += term_len(p, p->defindent + 1); } - term_fontpush(p, TERMFONT_BOLD); term_word(p, link->string); term_fontpop(p); + /* Trailing punctuation. */ + while (descr != NULL) { + p->flags |= TERMP_NOSPACE; + term_word(p, descr->string); + descr = descr->next; + } if (display) term_newln(p); - return 0; } -- cgit