@@ -60,6 +60,7 @@ module Text.Pandoc.Pretty (
6060 , hsep
6161 , vcat
6262 , vsep
63+ , nestle
6364 , chomp
6465 , inside
6566 , braces
@@ -72,7 +73,7 @@ module Text.Pandoc.Pretty (
7273 )
7374
7475where
75−import Data.Sequence (Seq, fromList, (<|), singleton, mapWithIndex)
76+import Data.Sequence (Seq, fromList, (<|), singleton, mapWithIndex, viewl, ViewL(..))
7677import Data.Foldable (toList)
7778import Data.List (intercalate)
7879import Data.Monoid
@@ -186,6 +187,14 @@ vcat = foldr ($$) empty
186187vsep :: [Doc] -> Doc
187188vsep = foldr ($+$) empty
188189
190+-- | Removes leading blank lines from a 'Doc'.
191+nestle :: Doc -> Doc
192+nestle (Doc d) = Doc $ go d
193+ where go x = case viewl x of
194+ (BlankLine :< rest) -> go rest
195+ (NewLine :< rest) -> go rest
196+ _ -> x
197+
189198-- | Chomps trailing blank space off of a 'Doc'.
190199chomp :: Doc -> Doc
191200chomp d = Doc (fromList dl')