@@ -59,6 +59,7 @@ module Text.Pandoc.Pretty (
5959 , hsep
6060 , vcat
6161 , vsep
62+ , chomp
6263 , inside
6364 , braces
6465 , brackets
@@ -164,6 +165,17 @@ vcat = foldr ($$) empty
164165vsep :: [Doc] -> Doc
165166vsep = foldr ($+$) empty
166167
168+-- | Chomps trailing blank space off of a 'Doc'.
169+chomp :: Doc -> Doc
170+chomp d = Doc (fromList dl')
171+ where dl = toList (unDoc d)
172+ dl' = reverse $ dropWhile removeable $ reverse dl
173+ removeable BreakingSpace = True
174+ removeable CarriageReturn = True
175+ removeable NewLine = True
176+ removeable BlankLine = True
177+ removeable _ = False
178+
167179outp :: (IsString a, Monoid a)
168180 => Int -> String -> DocState a
169181outp off s | off <= 0 = do
@@ -427,3 +439,4 @@ quotes = inside (char '\'') (char '\'')
427439-- | Wraps a 'Doc' in double quotes.
428440doubleQuotes :: Doc -> Doc
429441doubleQuotes = inside (char '"') (char '"')
442+