@@ -47,6 +47,8 @@ module Text.Pandoc.Shared (
4747 wrapIfNeeded,
4848 wrappedTeX,
4949 wrapTeXIfNeeded,
50+ BlockWrapper (..),
51+ wrappedBlocksToDoc,
5052 -- * Parsing
5153 (>>~),
5254 anyLine,
@@ -101,7 +103,7 @@ module Text.Pandoc.Shared (
101103
102104import Text.Pandoc.Definition
103105import Text.ParserCombinators.Parsec
104−import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty )
106+import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text )
105107import qualified Text.PrettyPrint.HughesPJ as PP
106108import Text.Pandoc.CharacterReferences ( characterReference )
107109import Data.Char ( toLower, toUpper, ord, isLower, isUpper )
@@ -262,6 +264,16 @@ wrapTeXIfNeeded opts includePercent = if writerWrapText opts
262264 then wrappedTeX includePercent
263265 else ($)
264266
267+-- | Indicates whether block should be surrounded by blank lines (@Pad@) or not (@Reg@).
268+data BlockWrapper = Pad Doc | Reg Doc
269+
270+-- | Converts a list of wrapped blocks to a Doc, with appropriate spaces around blocks.
271+wrappedBlocksToDoc :: [BlockWrapper] -> Doc
272+wrappedBlocksToDoc = foldr addBlock empty
273+ where addBlock (Pad d) accum | isEmpty accum = d
274+ addBlock (Pad d) accum = d $$ text "" $$ accum
275+ addBlock (Reg d) accum = d $$ accum
276+
265277--
266278-- Parsing
267279--