From 9120514998cabb9d53379acb289fa71ed55b3880 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 19 Dec 2010 12:39:49 -0800 Subject: Pretty: Added enclosed, parens. --- src/Text/Pandoc/Pretty.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Pretty.hs b/src/Text/Pandoc/Pretty.hs index 950d9a406..3ba5c4b2c 100644 --- a/src/Text/Pandoc/Pretty.hs +++ b/src/Text/Pandoc/Pretty.hs @@ -59,8 +59,10 @@ module Text.Pandoc.Pretty ( , hsep , vcat , vsep + , enclosed , braces , brackets + , parens ) where @@ -395,10 +397,19 @@ chop n cs = case break (=='\n') cs of else take n xs : chop n (drop n xs ++ ys) where len = length xs +-- | Encloses a 'Doc' inside a start and end 'Doc'. +enclosed :: Doc -> Doc -> Doc -> Doc +enclosed start end contents = + start <> contents <> end + -- | Puts a 'Doc' in curly braces. braces :: Doc -> Doc -braces d = char '{' <> d <> char '}' +braces = enclosed (char '{') (char '}') -- | Puts a 'Doc' in square brackets. brackets :: Doc -> Doc -brackets d = char '[' <> d <> char ']' +brackets = enclosed (char '[') (char ']') + +-- | Puts a 'Doc' in parentheses. +parens :: Doc -> Doc +parens = enclosed (char '[') (char ']') -- cgit v1.2.3