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]
This commit is contained in:
parent
5c9ddaac2c
commit
90f5dd88a4
2 changed files with 10 additions and 11 deletions
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue