aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2012-11-16 17:16:55 +0000
committerIngo Schwarze <schwarze@openbsd.org>2012-11-16 17:16:55 +0000
commitccb2b6c5e221f64660f6481251aaaf2dbd12679a (patch)
treecc6a0d77c99954bf2a563f9d3a06945037359ce9
parented556a16a0d0d619b59f20de7ff6e61eb00b0fde (diff)
downloadmandoc-ccb2b6c5e221f64660f6481251aaaf2dbd12679a.tar.gz
mandoc-ccb2b6c5e221f64660f6481251aaaf2dbd12679a.tar.zst
mandoc-ccb2b6c5e221f64660f6481251aaaf2dbd12679a.zip
Improve formatting of badly nested font blocks.
The basic idea is to already pop the font at the end marker instead of allowing it to linger until the final end of the block. This requires a few preliminaries: * For each block, save a pointer to the previous font to be used in case the block breaks another and gets extended. * That requires making node information writable during rendering. * Now fonts may get popped in the wrong order; hence, after the stack has already been rewound further by some block that began earlier, ignore popping a font that was put on the stack later. * To be able to exploit all this for font blocks, tie processing to their body, not their block, which is more logical anyway. Triggered by florian@ reporting vaguely similar issues with list blocks.
-rw-r--r--mdoc.h3
-rw-r--r--mdoc_term.c14
-rw-r--r--term.c4
3 files changed, 11 insertions, 10 deletions
diff --git a/mdoc.h b/mdoc.h
index 55536777..cc807d77 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -1,4 +1,4 @@
-/* $Id: mdoc.h,v 1.123 2012/07/10 14:38:51 schwarze Exp $ */
+/* $Id: mdoc.h,v 1.124 2012/11/16 17:16:55 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -363,6 +363,7 @@ struct mdoc_node {
enum mdoc_type type; /* AST node type */
enum mdoc_sec sec; /* current named section */
union mdoc_data *norm; /* normalised args */
+ const void *prev_font; /* before entering this node */
/* FIXME: these can be union'd to shave a few bytes. */
struct mdoc_arg *args; /* BLOCK/ELEM */
struct mdoc_node *pending; /* BLOCK */
diff --git a/mdoc_term.c b/mdoc_term.c
index 49bd6d82..45fd4192 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.243 2012/07/11 16:57:43 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.244 2012/11/16 17:16:55 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012 Ingo Schwarze <schwarze@openbsd.org>
@@ -42,7 +42,7 @@ struct termpair {
#define DECL_ARGS struct termp *p, \
struct termpair *pair, \
const struct mdoc_meta *m, \
- const struct mdoc_node *n
+ struct mdoc_node *n
struct termact {
int (*pre)(DECL_ARGS);
@@ -293,14 +293,13 @@ static void
print_mdoc_node(DECL_ARGS)
{
int chld;
- const void *font;
struct termpair npair;
size_t offset, rmargin;
chld = 1;
offset = p->offset;
rmargin = p->rmargin;
- font = term_fontq(p);
+ n->prev_font = term_fontq(p);
memset(&npair, 0, sizeof(struct termpair));
npair.ppair = pair;
@@ -366,7 +365,8 @@ print_mdoc_node(DECL_ARGS)
if (chld && n->child)
print_mdoc_nodelist(p, &npair, m, n->child);
- term_fontpopq(p, font);
+ term_fontpopq(p,
+ (ENDBODY_NOT == n->end ? n : n->pending)->prev_font);
switch (n->type) {
case (MDOC_TEXT):
@@ -1606,7 +1606,7 @@ static int
termp_bd_pre(DECL_ARGS)
{
size_t tabwidth, rm, rmax;
- const struct mdoc_node *nn;
+ struct mdoc_node *nn;
if (MDOC_BLOCK == n->type) {
print_bvspace(p, n, n);
@@ -2075,7 +2075,7 @@ termp_bf_pre(DECL_ARGS)
if (MDOC_HEAD == n->type)
return(0);
- else if (MDOC_BLOCK != n->type)
+ else if (MDOC_BODY != n->type)
return(1);
if (FONT_Em == n->norm->Bf.font)
diff --git a/term.c b/term.c
index 15f8812f..62290312 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.205 2012/07/16 21:30:42 schwarze Exp $ */
+/* $Id: term.c,v 1.206 2012/11/16 17:16:55 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
@@ -376,7 +376,7 @@ void
term_fontpopq(struct termp *p, const void *key)
{
- while (p->fonti >= 0 && key != &p->fontq[p->fonti])
+ while (p->fonti >= 0 && key < (void *)(p->fontq + p->fonti))
p->fonti--;
assert(p->fonti >= 0);
}