From: schwarze Date: Mon, 17 Apr 2017 12:52:00 +0000 (+0000) Subject: Fix handling of trailing punctuation in .Lk. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=96aebfb38c1b18db069e4ba1e2145623b1e36e53;p=openbsd 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). --- diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index 0f44d76a661..43760c4082b 100644 --- a/usr.bin/mandoc/mdoc_html.c +++ b/usr.bin/mandoc/mdoc_html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_html.c,v 1.153 2017/03/17 12:06:02 schwarze Exp $ */ +/* $OpenBSD: mdoc_html.c,v 1.154 2017/04/17 12:52:00 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze @@ -1344,19 +1344,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/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c index af3f159e4f4..34dc72a0e72 100644 --- a/usr.bin/mandoc/mdoc_macro.c +++ b/usr.bin/mandoc/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_macro.c,v 1.174 2017/02/16 09:47:10 schwarze Exp $ */ +/* $OpenBSD: mdoc_macro.c,v 1.175 2017/04/17 12:52:00 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010, 2012-2017 Ingo Schwarze @@ -901,8 +901,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 @@ -922,6 +924,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/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c index 59690aa9df5..0c3e097269d 100644 --- a/usr.bin/mandoc/mdoc_man.c +++ b/usr.bin/mandoc/mdoc_man.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_man.c,v 1.104 2017/04/14 18:24:15 schwarze Exp $ */ +/* $OpenBSD: mdoc_man.c,v 1.105 2017/04/17 12:52:00 schwarze Exp $ */ /* * Copyright (c) 2011-2017 Ingo Schwarze * @@ -1463,12 +1463,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; } @@ -1476,9 +1477,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/usr.bin/mandoc/mdoc_markdown.c b/usr.bin/mandoc/mdoc_markdown.c index 74b261befad..f30186e1fb9 100644 --- a/usr.bin/mandoc/mdoc_markdown.c +++ b/usr.bin/mandoc/mdoc_markdown.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_markdown.c,v 1.15 2017/03/11 12:35:40 schwarze Exp $ */ +/* $OpenBSD: mdoc_markdown.c,v 1.16 2017/04/17 12:52:00 schwarze Exp $ */ /* * Copyright (c) 2017 Ingo Schwarze * @@ -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/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index 13f450dd40e..a025a232314 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_term.c,v 1.247 2017/04/14 19:34:54 schwarze Exp $ */ +/* $OpenBSD: mdoc_term.c,v 1.248 2017/04/17 12:52:00 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2017 Ingo Schwarze @@ -1993,12 +1993,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; } @@ -2007,19 +2008,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; }