From 23c26bbc65dd719aa200897ae71bc7bea6c14aab Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 18 Nov 2011 13:10:45 -0800 Subject: Pretty: Added chomp combinator. --- src/Text/Pandoc/Pretty.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Pretty.hs b/src/Text/Pandoc/Pretty.hs index 54d65af6f..5c6eee27c 100644 --- a/src/Text/Pandoc/Pretty.hs +++ b/src/Text/Pandoc/Pretty.hs @@ -59,6 +59,7 @@ module Text.Pandoc.Pretty ( , hsep , vcat , vsep + , chomp , inside , braces , brackets @@ -164,6 +165,17 @@ vcat = foldr ($$) empty vsep :: [Doc] -> Doc vsep = foldr ($+$) empty +-- | Chomps trailing blank space off of a 'Doc'. +chomp :: Doc -> Doc +chomp d = Doc (fromList dl') + where dl = toList (unDoc d) + dl' = reverse $ dropWhile removeable $ reverse dl + removeable BreakingSpace = True + removeable CarriageReturn = True + removeable NewLine = True + removeable BlankLine = True + removeable _ = False + outp :: (IsString a, Monoid a) => Int -> String -> DocState a outp off s | off <= 0 = do @@ -427,3 +439,4 @@ quotes = inside (char '\'') (char '\'') -- | Wraps a 'Doc' in double quotes. doubleQuotes :: Doc -> Doc doubleQuotes = inside (char '"') (char '"') + -- cgit v1.2.3