source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Several -mdoc parser improvements related to vertical spacing: *
@ 2012-07-16  9:51 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2012-07-16  9:51 UTC (permalink / raw)
  To: source

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

Modified Files:
--------------
    mdocml:
        mdoc.c
        mdoc_man.c
        mdoc_validate.c

Revision Data
-------------
Index: mdoc_man.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_man.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -Lmdoc_man.c -Lmdoc_man.c -u -p -r1.39 -r1.40
--- mdoc_man.c
+++ 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);
 }
 
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.187
retrieving revision 1.188
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.187 -r1.188
--- mdoc_validate.c
+++ 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, N
 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[M
 	{ 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[M
 	{ 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[M
 	{ 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);
@@ -1987,6 +1991,32 @@ pre_par(PRE_ARGS)
 		return(1);
 	if (MDOC_It == n->tok && n->parent->norm->Bl.comp)
 		return(1);
+
+	mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_IGNPAR);
+	mdoc_node_delete(mdoc, mdoc->last);
+	return(1);
+}
+
+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);
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.198
retrieving revision 1.199
diff -Lmdoc.c -Lmdoc.c -u -p -r1.198 -r1.199
--- mdoc.c
+++ mdoc.c
@@ -801,7 +801,8 @@ mdoc_ptext(struct mdoc *m, int line, cha
 			return(0);
 
 		m->next = MDOC_NEXT_SIBLING;
-		return(1);
+
+		return(mdoc_valid_post(m));
 	}
 
 	if ( ! mdoc_word_alloc(m, line, offs, buf+offs))
--
 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:[~2012-07-16  9:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-16  9:51 mdocml: Several -mdoc parser improvements related to vertical spacing: * 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).