diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2011-02-06 22:25:37 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2011-02-06 22:25:37 +0000 |
commit | c12284a87f6464cb76f414396466c8d21b762e3d (patch) | |
tree | 80acc883b0c41900eaa91e68f5d9d704cfde713c | |
parent | f39b167a786f1221a985d195cfe02986edb66af4 (diff) |
Some pre-handlers produce output, so reorder the code to set up
keep flags before they are called.
Without this bugfix, .Bk was ineffective in some cases.
"looks reasonable" kristaps@
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Bk/break.in | 18 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Bk/break.out_ascii | 9 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_term.c | 39 |
3 files changed, 49 insertions, 17 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Bk/break.in b/regress/usr.bin/mandoc/mdoc/Bk/break.in index de2038436a2..32d79f03b30 100644 --- a/regress/usr.bin/mandoc/mdoc/Bk/break.in +++ b/regress/usr.bin/mandoc/mdoc/Bk/break.in @@ -5,6 +5,24 @@ .Nm Bk-break .Nd handling of word keeps .Sh DESCRIPTION +Even though it is called a word keep, +.Bk -words +it will not keep words together in free-form text. +.Ek +However, even the noop macro +.Bk -words +.No is sufficient to let the keep take effect . +.Ek +Even text generated in pre-handlers must be kept together with +the text following it: +.Bk -words +.Xr one 1 No and Xr two 2 +.Ek +should be on the same line. +.Pp +Including the whole output line into the keep is not required, +including just the macros to be kept together is sufficient: +.Pp .Nm .Ar x x x x x x x x .Ar x x x x x x x x diff --git a/regress/usr.bin/mandoc/mdoc/Bk/break.out_ascii b/regress/usr.bin/mandoc/mdoc/Bk/break.out_ascii index 04bafbcccdd..623e7a9bd1a 100644 --- a/regress/usr.bin/mandoc/mdoc/Bk/break.out_ascii +++ b/regress/usr.bin/mandoc/mdoc/Bk/break.out_ascii @@ -4,6 +4,15 @@ NNAAMMEE BBkk--bbrreeaakk - handling of word keeps DDEESSCCRRIIPPTTIIOONN + Even though it is called a word keep, it will not keep words together in + free-form text. However, even the noop macro + is sufficient to let the keep take effect. Even text generated in pre- + handlers must be kept together with the text following it: + one(1) and two(2) should be on the same line. + + Including the whole output line into the keep is not required, including + just the macros to be kept together is sufficient: + BBkk--bbrreeaakk _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x [o _a] diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index 572e93c45b0..88f238b543c 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.127 2011/02/06 17:33:20 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.128 2011/02/06 22:25:36 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> @@ -308,22 +308,6 @@ print_mdoc_node(DECL_ARGS) memset(&npair, 0, sizeof(struct termpair)); npair.ppair = pair; - - switch (n->type) { - case (MDOC_TEXT): - if (' ' == *n->string && MDOC_LINE & n->flags) - term_newln(p); - term_word(p, n->string); - break; - case (MDOC_TBL): - term_tbl(p, n->span); - break; - default: - if (termacts[n->tok].pre && ENDBODY_NOT == n->end) - chld = (*termacts[n->tok].pre) - (p, &npair, m, n); - break; - } /* * Keeps only work until the end of a line. If a keep was @@ -355,6 +339,27 @@ print_mdoc_node(DECL_ARGS) (n->parent && MDOC_SYNPRETTY & n->parent->flags))) p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP); + /* + * After the keep flags have been set up, we may now + * produce output. Note that some pre-handlers do so. + */ + + switch (n->type) { + case (MDOC_TEXT): + if (' ' == *n->string && MDOC_LINE & n->flags) + term_newln(p); + term_word(p, n->string); + break; + case (MDOC_TBL): + term_tbl(p, n->span); + break; + default: + if (termacts[n->tok].pre && ENDBODY_NOT == n->end) + chld = (*termacts[n->tok].pre) + (p, &npair, m, n); + break; + } + if (chld && n->child) print_mdoc_nodelist(p, &npair, m, n->child); |