From 99bb066bb925134b506d39c8d6694fe81337d9c1 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 8 Aug 2013 15:15:58 -0700 Subject: Pass writename as argument to filters. This way filters can figure out what the target format is and react appropriately. Example: #!/usr/bin/env runghc import Text.Pandoc.JSON import Data.Char main = toJSONFilter cap where cap (Just "html") (Str xs) = Str $ map toUpper xs cap _ x = x This capitalizes text only for html output. --- src/Text/Pandoc.hs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc.hs b/src/Text/Pandoc.hs index 27aa02a75..703bb876a 100644 --- a/src/Text/Pandoc.hs +++ b/src/Text/Pandoc.hs @@ -309,11 +309,8 @@ class ToJSONFilter a => ToJsonFilter a toJsonFilter = toJSONFilter readJSON :: ReaderOptions -> String -> Pandoc -readJSON _ = checkJSON . eitherDecode' . UTF8.fromStringLazy +readJSON _ = either error id . eitherDecode' . UTF8.fromStringLazy writeJSON :: WriterOptions -> Pandoc -> String writeJSON _ = UTF8.toStringLazy . encode -checkJSON :: Either String a -> a -checkJSON (Right x) = x -checkJSON (Left e) = error e -- cgit v1.2.3