From: schwarze Date: Tue, 30 May 2017 16:31:25 +0000 (+0000) Subject: fix formatting of intermediate punctuation in .Lk X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=eb4d0f3030a3b30bde6e6a8786cf32fc2af1a8fb;p=openbsd fix formatting of intermediate punctuation in .Lk --- diff --git a/regress/usr.bin/mandoc/mdoc/Lk/noarg.in b/regress/usr.bin/mandoc/mdoc/Lk/noarg.in index a0200ed1ed4..910f641cb86 100644 --- a/regress/usr.bin/mandoc/mdoc/Lk/noarg.in +++ b/regress/usr.bin/mandoc/mdoc/Lk/noarg.in @@ -7,7 +7,7 @@ .Sh DESCRIPTION multiple arguments .Lk http://www.bsd.lv/ the bsd.lv project , -.Lk http://www.gnu.org/software/groff/ GNU troff , +.Lk http://www.gnu.org/software/groff/ GNU troff "," two arguments .Lk http://mdocml.bsd.lv/ mandoc one argument diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index 2f81d5e9a2a..1fb8236c273 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.163 2017/05/17 17:53:48 schwarze Exp $ */ +/* $OpenBSD: mdoc_html.c,v 1.164 2017/05/30 16:31:25 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze @@ -1307,24 +1307,32 @@ mdoc_pp_pre(MDOC_ARGS) static int mdoc_lk_pre(MDOC_ARGS) { + const struct roff_node *link, *descr, *punct; struct tag *t; - if ((n = n->child) == NULL) + if ((link = n->child) == NULL) return 0; + /* Find beginning of trailing punctuation. */ + punct = n->last; + while (punct != link && punct->flags & NODE_DELIMC) + punct = punct->prev; + punct = punct->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 != NULL && !(n->flags & NODE_DELIMC); n = n->next) - print_text(h, n->string); + t = print_otag(h, TAG_A, "cTh", "Lk", link->string); + for (descr = link->next; descr != punct; descr = descr->next) { + if (descr->flags & (NODE_DELIMC | NODE_DELIMO)) + h->flags |= HTML_NOSPACE; + print_text(h, descr->string); + } print_tagq(h, t); /* Trailing punctuation. */ - while (n != NULL) { + while (punct != NULL) { h->flags |= HTML_NOSPACE; - print_text(h, n->string); - n = n->next; + print_text(h, punct->string); + punct = punct->next; } return 0; } diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c index 027af713485..0267d88a2f2 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.113 2017/05/08 15:33:43 schwarze Exp $ */ +/* $OpenBSD: mdoc_man.c,v 1.114 2017/05/30 16:31:25 schwarze Exp $ */ /* * Copyright (c) 2011-2017 Ingo Schwarze * @@ -1525,16 +1525,22 @@ post_lb(DECL_ARGS) static int pre_lk(DECL_ARGS) { - const struct roff_node *link, *descr; + const struct roff_node *link, *descr, *punct; int display; if ((link = n->child) == NULL) return 0; + /* Find beginning of trailing punctuation. */ + punct = n->last; + while (punct != link && punct->flags & NODE_DELIMC) + punct = punct->prev; + punct = punct->next; + /* Link text. */ - if ((descr = link->next) != NULL && !(descr->flags & NODE_DELIMC)) { + if ((descr = link->next) != NULL && descr != punct) { font_push('I'); - while (descr != NULL && !(descr->flags & NODE_DELIMC)) { + while (descr != punct) { print_word(descr->string); descr = descr->next; } @@ -1554,9 +1560,9 @@ pre_lk(DECL_ARGS) font_pop(); /* Trailing punctuation. */ - while (descr != NULL) { - print_word(descr->string); - descr = descr->next; + while (punct != NULL) { + print_word(punct->string); + punct = punct->next; } if (display) print_line(".RE", MMAN_nl); diff --git a/usr.bin/mandoc/mdoc_markdown.c b/usr.bin/mandoc/mdoc_markdown.c index 24a99df7e06..19d564a2dbd 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.21 2017/05/05 15:16:25 schwarze Exp $ */ +/* $OpenBSD: mdoc_markdown.c,v 1.22 2017/05/30 16:31:25 schwarze Exp $ */ /* * Copyright (c) 2017 Ingo Schwarze * @@ -1306,21 +1306,27 @@ md_uri(const char *s) static int md_pre_Lk(struct roff_node *n) { - const struct roff_node *link, *descr; + const struct roff_node *link, *descr, *punct; if ((link = n->child) == NULL) return 0; + /* Find beginning of trailing punctuation. */ + punct = n->last; + while (punct != link && punct->flags & NODE_DELIMC) + punct = punct->prev; + punct = punct->next; + /* Link text. */ descr = link->next; - if (descr == NULL || descr->flags & NODE_DELIMC) + if (descr == punct) descr = link; /* no text */ md_rawword("["); outflags &= ~MD_spc; do { md_word(descr->string); descr = descr->next; - } while (descr != NULL && !(descr->flags & NODE_DELIMC)); + } while (descr != punct); outflags &= ~MD_spc; /* Link target. */ @@ -1330,9 +1336,9 @@ md_pre_Lk(struct roff_node *n) md_rawword(")"); /* Trailing punctuation. */ - while (descr != NULL) { - md_word(descr->string); - descr = descr->next; + while (punct != NULL) { + md_word(punct->string); + punct = punct->next; } return 0; } diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index 82a46994f38..40cd82da914 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.256 2017/05/09 14:09:37 schwarze Exp $ */ +/* $OpenBSD: mdoc_term.c,v 1.257 2017/05/30 16:31:25 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2017 Ingo Schwarze @@ -1975,16 +1975,24 @@ termp_li_pre(DECL_ARGS) static int termp_lk_pre(DECL_ARGS) { - const struct roff_node *link, *descr; + const struct roff_node *link, *descr, *punct; int display; if ((link = n->child) == NULL) return 0; + /* Find beginning of trailing punctuation. */ + punct = n->last; + while (punct != link && punct->flags & NODE_DELIMC) + punct = punct->prev; + punct = punct->next; + /* Link text. */ - if ((descr = link->next) != NULL && !(descr->flags & NODE_DELIMC)) { + if ((descr = link->next) != NULL && descr != punct) { term_fontpush(p, TERMFONT_UNDER); - while (descr != NULL && !(descr->flags & NODE_DELIMC)) { + while (descr != punct) { + if (descr->flags & (NODE_DELIMC | NODE_DELIMO)) + p->flags |= TERMP_NOSPACE; term_word(p, descr->string); descr = descr->next; } @@ -2004,10 +2012,10 @@ termp_lk_pre(DECL_ARGS) term_fontpop(p); /* Trailing punctuation. */ - while (descr != NULL) { + while (punct != NULL) { p->flags |= TERMP_NOSPACE; - term_word(p, descr->string); - descr = descr->next; + term_word(p, punct->string); + punct = punct->next; } if (display) term_newln(p);