diff options
author | John MacFarlane <jgm@berkeley.edu> | 2013-08-08 15:15:58 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2013-08-08 15:15:58 -0700 |
commit | 99bb066bb925134b506d39c8d6694fe81337d9c1 (patch) | |
tree | 51beae592444e1da080c774aac4e747744c4231f /src | |
parent | 83f263110f364e87d8c0908b4a52be801aa77802 (diff) | |
download | pandoc-99bb066bb925134b506d39c8d6694fe81337d9c1.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc.hs | 5 |
1 files changed, 1 insertions, 4 deletions
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 |