diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-11-29 12:56:06 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-11-29 12:56:06 -0800 |
commit | 90f5dd88a4f9a5378e430438fc3ef8ab1c3db9a4 (patch) | |
tree | b7abc2f5efca2d60abe6ec30e4410eecf5a24f2a /src/Text/Pandoc | |
parent | 5c9ddaac2c86242163b2f87f8d1cca6e1d1a49c8 (diff) | |
download | pandoc-90f5dd88a4f9a5378e430438fc3ef8ab1c3db9a4.tar.gz |
Changed types of writeJSON and readJSON.
Previously they were not monadic; we now have them run in an
instance of the Pandoc monad, like the other readers and writers.
[API change]
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers.hs | 15 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers.hs | 6 |
2 files changed, 10 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Readers.hs b/src/Text/Pandoc/Readers.hs index 76492b0aa..630b8b858 100644 --- a/src/Text/Pandoc/Readers.hs +++ b/src/Text/Pandoc/Readers.hs @@ -106,7 +106,6 @@ import Text.Pandoc.Readers.TWiki import Text.Pandoc.Readers.Txt2Tags import Text.Pandoc.Readers.Vimwiki import Text.Pandoc.Readers.Man -import Text.Pandoc.Shared (mapLeft) import qualified Text.Pandoc.UTF8 as UTF8 import Text.Parsec.Error @@ -116,10 +115,7 @@ data Reader m = TextReader (ReaderOptions -> Text -> m Pandoc) -- | Association list of formats and readers. readers :: PandocMonad m => [(String, Reader m)] readers = [ ("native" , TextReader readNative) - ,("json" , TextReader $ \o s -> - case readJSON o s of - Right doc -> return doc - Left _ -> throwError $ PandocParseError "JSON parse error") + ,("json" , TextReader readJSON) ,("markdown" , TextReader readMarkdown) ,("markdown_strict" , TextReader readMarkdown) ,("markdown_phpextra" , TextReader readMarkdown) @@ -162,6 +158,9 @@ getReader s = getDefaultExtensions readerName) -- | Read pandoc document from JSON format. -readJSON :: ReaderOptions -> Text -> Either PandocError Pandoc -readJSON _ = - mapLeft PandocParseError . eitherDecode' . BL.fromStrict . UTF8.fromText +readJSON :: PandocMonad m + => ReaderOptions -> Text -> m Pandoc +readJSON _ t = + case eitherDecode' . BL.fromStrict . UTF8.fromText $ t of + Right doc -> return doc + Left _ -> throwError $ PandocParseError "JSON parse error" diff --git a/src/Text/Pandoc/Writers.hs b/src/Text/Pandoc/Writers.hs index 5d4a9122a..b61404238 100644 --- a/src/Text/Pandoc/Writers.hs +++ b/src/Text/Pandoc/Writers.hs @@ -132,7 +132,7 @@ data Writer m = TextWriter (WriterOptions -> Pandoc -> m Text) writers :: PandocMonad m => [ ( String, Writer m) ] writers = [ ("native" , TextWriter writeNative) - ,("json" , TextWriter $ \o d -> return $ writeJSON o d) + ,("json" , TextWriter $ \o d -> writeJSON o d) ,("docx" , ByteStringWriter writeDocx) ,("odt" , ByteStringWriter writeODT) ,("pptx" , ByteStringWriter writePowerpoint) @@ -193,5 +193,5 @@ getWriter s Just r -> Right (r, setExts $ getDefaultExtensions writerName) -writeJSON :: WriterOptions -> Pandoc -> Text -writeJSON _ = UTF8.toText . BL.toStrict . encode +writeJSON :: PandocMonad m => WriterOptions -> Pandoc -> m Text +writeJSON _ = return . UTF8.toText . BL.toStrict . encode |