=================================================================== RCS file: /cvs/mandoc/mdoc_markdown.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -p -r1.21 -r1.22 --- mandoc/mdoc_markdown.c 2017/05/05 15:17:32 1.21 +++ mandoc/mdoc_markdown.c 2017/05/30 16:31:29 1.22 @@ -1,4 +1,4 @@ -/* $Id: mdoc_markdown.c,v 1.21 2017/05/05 15:17:32 schwarze Exp $ */ +/* $Id: mdoc_markdown.c,v 1.22 2017/05/30 16:31:29 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; }