From 13e443d7cc77aaf52712ebf2acbedb12090ef094 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Fri, 19 Oct 2018 23:01:02 -0700
Subject: [PATCH] Man writer: avoid unnecessary `.RS`/`.RE` pair in defn lists.

When the definition is just one paragraph, we don't need
the `.RS\n.RE`.
---
 src/Text/Pandoc/Writers/Man.hs |  4 +++-
 test/writer.man                | 38 ----------------------------------
 2 files changed, 3 insertions(+), 39 deletions(-)

diff --git a/src/Text/Pandoc/Writers/Man.hs b/src/Text/Pandoc/Writers/Man.hs
index d2803f06f..645476b77 100644
--- a/src/Text/Pandoc/Writers/Man.hs
+++ b/src/Text/Pandoc/Writers/Man.hs
@@ -253,7 +253,9 @@ definitionListItemToMan opts (label, defs) = do
                             rest' <- liftM vcat $ mapM
                                         (\item -> blockToMan opts item) xs
                             return $ first' $$
-                                     text ".RS" $$ rest' $$ text ".RE"
+                                     if null xs
+                                        then empty
+                                        else text ".RS" $$ rest' $$ text ".RE"
                           [] -> return empty
   return $ text ".TP" $$ nowrap (text ".B " <> labelText) $$ contents
 
diff --git a/test/writer.man b/test/writer.man
index ce9f3a23f..33cb576ff 100644
--- a/test/writer.man
+++ b/test/writer.man
@@ -320,52 +320,34 @@ Tight using spaces:
 .TP
 .B apple
 red fruit
-.RS
-.RE
 .TP
 .B orange
 orange fruit
-.RS
-.RE
 .TP
 .B banana
 yellow fruit
-.RS
-.RE
 .PP
 Tight using tabs:
 .TP
 .B apple
 red fruit
-.RS
-.RE
 .TP
 .B orange
 orange fruit
-.RS
-.RE
 .TP
 .B banana
 yellow fruit
-.RS
-.RE
 .PP
 Loose:
 .TP
 .B apple
 red fruit
-.RS
-.RE
 .TP
 .B orange
 orange fruit
-.RS
-.RE
 .TP
 .B banana
 yellow fruit
-.RS
-.RE
 .PP
 Multiple blocks with italics:
 .TP
@@ -395,47 +377,27 @@ Multiple definitions, tight:
 .TP
 .B apple
 red fruit
-.RS
-.RE
 computer
-.RS
-.RE
 .TP
 .B orange
 orange fruit
-.RS
-.RE
 bank
-.RS
-.RE
 .PP
 Multiple definitions, loose:
 .TP
 .B apple
 red fruit
-.RS
-.RE
 computer
-.RS
-.RE
 .TP
 .B orange
 orange fruit
-.RS
-.RE
 bank
-.RS
-.RE
 .PP
 Blank line after term, indented marker, alternate markers:
 .TP
 .B apple
 red fruit
-.RS
-.RE
 computer
-.RS
-.RE
 .TP
 .B orange
 orange fruit