summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2012-07-16 09:51:54 +0000
committerIngo Schwarze <schwarze@openbsd.org>2012-07-16 09:51:54 +0000
commit9cc2ea62b7433f3021b78293349ccddded36ce3c (patch)
treea0d5bc5eb6dec5a31c7a860c48546a0be56f158b
parent7d38f2b698595b8911b6d5954a9f59103ac33ff8 (diff)
downloadmandoc-9cc2ea62b7433f3021b78293349ccddded36ce3c.tar.gz
Several -mdoc parser improvements related to vertical spacing:
* So far, .Pp and .Lp were removed before paragraph type blocks. * Now also remove .br before paragraph type blocks. * Treat .Lp as a paragraph like .Pp, so remove .Pp, .Lp, .br before it. * Do not treat .sp as a paragraph, don't remove anything before it. * After .Sh, .Ss, .Pp, and .Lp, remove .Pp, .Lp, .sp, .br, and blank lines. * After .sp and .br, remove .br. OpenBSD rev. mdoc.c 1.89 and mdoc_validate.c 1.106
-rw-r--r--mdoc.c3
-rw-r--r--mdoc_man.c5
-rw-r--r--mdoc_validate.c42
3 files changed, 42 insertions, 8 deletions
diff --git a/mdoc.c b/mdoc.c
index b32614f3..90cc8169 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -801,7 +801,8 @@ mdoc_ptext(struct mdoc *m, int line, char *buf, int offs)
return(0);
m->next = MDOC_NEXT_SIBLING;
- return(1);
+
+ return(mdoc_valid_post(m));
}
if ( ! mdoc_word_alloc(m, line, offs, buf+offs))
diff --git a/mdoc_man.c b/mdoc_man.c
index 2673fe4a..8d7cd000 100644
--- a/mdoc_man.c
+++ b/mdoc_man.c
@@ -1342,7 +1342,10 @@ static int
pre_sp(DECL_ARGS)
{
- print_line(".sp", MMAN_nl);
+ if (MMAN_PP & outflags && MDOC_It != n->parent->tok)
+ print_line(".PP", 0);
+ else
+ print_line(".sp", 0);
return(1);
}
diff --git a/mdoc_validate.c b/mdoc_validate.c
index e8218d82..7f2a991e 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -107,6 +107,7 @@ static int post_lb(POST_ARGS);
static int post_nm(POST_ARGS);
static int post_ns(POST_ARGS);
static int post_os(POST_ARGS);
+static int post_par(POST_ARGS);
static int post_ignpar(POST_ARGS);
static int post_prol(POST_ARGS);
static int post_root(POST_ARGS);
@@ -152,9 +153,10 @@ static v_post posts_nm[] = { post_nm, NULL };
static v_post posts_notext[] = { ewarn_eq0, NULL };
static v_post posts_ns[] = { post_ns, NULL };
static v_post posts_os[] = { post_os, post_prol, NULL };
+static v_post posts_pp[] = { post_par, ewarn_eq0, NULL };
static v_post posts_rs[] = { post_rs, NULL };
static v_post posts_sh[] = { post_ignpar, hwarn_ge1, post_sh, NULL };
-static v_post posts_sp[] = { ewarn_le1, NULL };
+static v_post posts_sp[] = { post_par, ewarn_le1, NULL };
static v_post posts_ss[] = { post_ignpar, hwarn_ge1, NULL };
static v_post posts_st[] = { post_st, NULL };
static v_post posts_std[] = { post_std, NULL };
@@ -185,7 +187,7 @@ static const struct valids mdoc_valids[MDOC_MAX] = {
{ pres_os, posts_os }, /* Os */
{ pres_sh, posts_sh }, /* Sh */
{ pres_ss, posts_ss }, /* Ss */
- { pres_pp, posts_notext }, /* Pp */
+ { pres_pp, posts_pp }, /* Pp */
{ pres_d1, posts_wline }, /* D1 */
{ pres_dl, posts_dl }, /* Dl */
{ pres_bd, posts_bd }, /* Bd */
@@ -286,7 +288,7 @@ static const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, NULL }, /* Fr */
{ NULL, posts_eoln }, /* Ud */
{ NULL, posts_lb }, /* Lb */
- { NULL, posts_notext }, /* Lp */
+ { pres_pp, posts_pp }, /* Lp */
{ NULL, NULL }, /* Lk */
{ NULL, posts_defaults }, /* Mt */
{ NULL, NULL }, /* Brq */
@@ -297,8 +299,8 @@ static const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, NULL }, /* En */
{ NULL, NULL }, /* Dx */
{ NULL, posts_text }, /* %Q */
- { NULL, posts_notext }, /* br */
- { pres_pp, posts_sp }, /* sp */
+ { NULL, posts_pp }, /* br */
+ { NULL, posts_sp }, /* sp */
{ NULL, posts_text1 }, /* %U */
{ NULL, NULL }, /* Ta */
};
@@ -1979,7 +1981,9 @@ pre_par(PRE_ARGS)
* block: `Lp', `Pp', or non-compact `Bd' or `Bl'.
*/
- if (MDOC_Pp != mdoc->last->tok && MDOC_Lp != mdoc->last->tok)
+ if (MDOC_Pp != mdoc->last->tok &&
+ MDOC_Lp != mdoc->last->tok &&
+ MDOC_br != mdoc->last->tok)
return(1);
if (MDOC_Bl == n->tok && n->norm->Bl.comp)
return(1);
@@ -1994,6 +1998,32 @@ pre_par(PRE_ARGS)
}
static int
+post_par(POST_ARGS)
+{
+
+ if (MDOC_ELEM != mdoc->last->type &&
+ MDOC_BLOCK != mdoc->last->type)
+ return(1);
+
+ if (NULL == mdoc->last->prev) {
+ if (MDOC_Sh != mdoc->last->parent->tok &&
+ MDOC_Ss != mdoc->last->parent->tok)
+ return(1);
+ } else {
+ if (MDOC_Pp != mdoc->last->prev->tok &&
+ MDOC_Lp != mdoc->last->prev->tok &&
+ (MDOC_br != mdoc->last->tok ||
+ (MDOC_sp != mdoc->last->prev->tok &&
+ MDOC_br != mdoc->last->prev->tok)))
+ return(1);
+ }
+
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_IGNPAR);
+ mdoc_node_delete(mdoc, mdoc->last);
+ return(1);
+}
+
+static int
pre_literal(PRE_ARGS)
{