source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Fix handling of trailing punctuation in .Lk.
@ 2017-04-17 12:53 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-04-17 12:53 UTC (permalink / raw)
  To: source

Log Message:
-----------
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).

Modified Files:
--------------
    mdocml:
        mdoc_html.c
        mdoc_macro.c
        mdoc_man.c
        mdoc_markdown.c
        mdoc_term.c

Revision Data
-------------
Index: mdoc_man.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_man.c,v
retrieving revision 1.106
retrieving revision 1.107
diff -Lmdoc_man.c -Lmdoc_man.c -u -p -r1.106 -r1.107
--- mdoc_man.c
+++ 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;
 }
 
Index: mdoc_markdown.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_markdown.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -Lmdoc_markdown.c -Lmdoc_markdown.c -u -p -r1.15 -r1.16
--- mdoc_markdown.c
+++ 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;
 }
 
Index: mdoc_html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_html.c,v
retrieving revision 1.278
retrieving revision 1.279
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.278 -r1.279
--- mdoc_html.c
+++ 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;
 }
 
Index: mdoc_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_term.c,v
retrieving revision 1.348
retrieving revision 1.349
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.348 -r1.349
--- mdoc_term.c
+++ 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;
 }
 
Index: mdoc_macro.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_macro.c,v
retrieving revision 1.217
retrieving revision 1.218
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.217 -r1.218
--- mdoc_macro.c
+++ 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
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-04-17 12:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-17 12:53 mdocml: Fix handling of trailing punctuation in .Lk schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).