aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2011-11-18 13:10:45 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2011-11-18 13:19:22 -0800
commit23c26bbc65dd719aa200897ae71bc7bea6c14aab (patch)
tree24ea2c070486faa8a01d340df9cd5b837369f473 /src/Text
parent823c0bcda90dc060afd7c5026d194ddc9dec9409 (diff)
downloadpandoc-23c26bbc65dd719aa200897ae71bc7bea6c14aab.tar.gz
Pretty: Added chomp combinator.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Pretty.hs13
1 files changed, 13 insertions, 0 deletions
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 '"')
+