aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_macro.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2019-01-01 07:42:04 +0000
committerIngo Schwarze <schwarze@openbsd.org>2019-01-01 07:42:04 +0000
commit2fd178dd414bc5241e3bfcc62b303d84f58bb147 (patch)
tree4187ab4a60894ec5219556473df4b1e2af8d690c /mdoc_macro.c
parente622f2f088e1e43491b5e037c6d38b5cdece150e (diff)
downloadmandoc-2fd178dd414bc5241e3bfcc62b303d84f58bb147.tar.gz
mandoc-2fd178dd414bc5241e3bfcc62b303d84f58bb147.tar.zst
mandoc-2fd178dd414bc5241e3bfcc62b303d84f58bb147.zip
Correctly set the ROFF_NOFILL parser flag for .Bd .Ed .Sh, such
that children and later siblings get correct NODE_NOFILL assignments. This doesn't change rendering yet but prepares for future rendering improvements.
Diffstat (limited to 'mdoc_macro.c')
-rw-r--r--mdoc_macro.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/mdoc_macro.c b/mdoc_macro.c
index 11ca85c7..aed0221d 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -1,7 +1,7 @@
-/* $Id: mdoc_macro.c,v 1.230 2018/12/31 04:55:46 schwarze Exp $ */
+/* $Id: mdoc_macro.c,v 1.231 2019/01/01 07:42:04 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2012-2019 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -696,6 +696,19 @@ blk_exp_close(MACRO_PROT_ARGS)
"%s %s", roff_name[tok], buf + *pos);
if (endbody == NULL && n != NULL)
rew_pending(mdoc, n);
+
+ /*
+ * Restore the fill mode that was set before the display.
+ * This needs to be done here rather than during validation
+ * such that subsequent nodes get the right flags.
+ */
+
+ if (tok == MDOC_Ed && body != NULL) {
+ if (body->flags & NODE_NOFILL)
+ mdoc->flags |= ROFF_NOFILL;
+ else
+ mdoc->flags &= ~ROFF_NOFILL;
+ }
return;
}
@@ -936,14 +949,15 @@ in_line(MACRO_PROT_ARGS)
static void
blk_full(MACRO_PROT_ARGS)
{
- int done, la, nl, parsed;
struct mdoc_arg *arg;
struct roff_node *blk; /* Our own or a broken block. */
struct roff_node *head; /* Our own head. */
struct roff_node *body; /* Our own body. */
struct roff_node *n;
- enum margserr ac, lac;
char *p;
+ size_t iarg;
+ int done, la, nl, parsed;
+ enum margserr ac, lac;
nl = MDOC_NEWLINE & mdoc->flags;
@@ -1039,6 +1053,9 @@ blk_full(MACRO_PROT_ARGS)
* regular child nodes.
*/
+ if (tok == MDOC_Sh)
+ mdoc->flags &= ~ROFF_NOFILL;
+
mdoc_argv(mdoc, line, tok, &arg, pos, buf);
blk = mdoc_block_alloc(mdoc, line, ppos, tok, arg);
head = body = NULL;
@@ -1180,6 +1197,31 @@ blk_full(MACRO_PROT_ARGS)
rew_last(mdoc, head);
body = roff_body_alloc(mdoc, line, ppos, tok);
+
+ /*
+ * Set up fill mode for display blocks.
+ * This needs to be done here up front rather than during
+ * validation such that child nodes get the right flags.
+ */
+
+ if (tok == MDOC_Bd && arg != NULL) {
+ for (iarg = 0; iarg < arg->argc; iarg++) {
+ switch (arg->argv[iarg].arg) {
+ case MDOC_Unfilled:
+ case MDOC_Literal:
+ mdoc->flags |= ROFF_NOFILL;
+ break;
+ case MDOC_Filled:
+ case MDOC_Ragged:
+ case MDOC_Centred:
+ mdoc->flags &= ~ROFF_NOFILL;
+ break;
+ default:
+ continue;
+ }
+ break;
+ }
+ }
out:
if (mdoc->flags & MDOC_FREECOL) {
rew_last(mdoc, body);