git.iko.soy/typeable/pandoc
on master help sign in
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]

commit90f5dd88a4f9a5378e430438fc3ef8ab1c3db9a4 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 29 Nov 2018, 12:56 (8 years ago) parent5c9ddaa
2 files changed+10−11
src/Text/Pandoc/Readers.hs+7−8 src/Text/Pandoc/Writers.hs+3−3
src/Text/Pandoc/Readers.hs+7−8
@@ -106,7 +106,6 @@ import Text.Pandoc.Readers.TWiki
106106import Text.Pandoc.Readers.Txt2Tags
107107import Text.Pandoc.Readers.Vimwiki
108108import Text.Pandoc.Readers.Man
109−import Text.Pandoc.Shared (mapLeft)
110109import qualified Text.Pandoc.UTF8 as UTF8
111110import Text.Parsec.Error
112111
@@ -116,10 +115,7 @@ data Reader m = TextReader (ReaderOptions -> Text -> m Pandoc)
116115-- | Association list of formats and readers.
117116readers :: PandocMonad m => [(String, Reader m)]
118117readers = [ ("native" , TextReader readNative)
119− ,("json" , TextReader $ \o s ->
120− case readJSON o s of
121− Right doc -> return doc
122− Left _ -> throwError $ PandocParseError "JSON parse error")
118+ ,("json" , TextReader readJSON)
123119 ,("markdown" , TextReader readMarkdown)
124120 ,("markdown_strict" , TextReader readMarkdown)
125121 ,("markdown_phpextra" , TextReader readMarkdown)
@@ -162,6 +158,9 @@ getReader s =
162158 getDefaultExtensions readerName)
163159
164160-- | Read pandoc document from JSON format.
165−readJSON :: ReaderOptions -> Text -> Either PandocError Pandoc
166−readJSON _ =
167− mapLeft PandocParseError . eitherDecode' . BL.fromStrict . UTF8.fromText
161+readJSON :: PandocMonad m
162+ => ReaderOptions -> Text -> m Pandoc
163+readJSON _ t =
164+ case eitherDecode' . BL.fromStrict . UTF8.fromText $ t of
165+ Right doc -> return doc
166+ Left _ -> throwError $ PandocParseError "JSON parse error"
src/Text/Pandoc/Writers.hs+3−3
@@ -132,7 +132,7 @@ data Writer m = TextWriter (WriterOptions -> Pandoc -> m Text)
132132writers :: PandocMonad m => [ ( String, Writer m) ]
133133writers = [
134134 ("native" , TextWriter writeNative)
135− ,("json" , TextWriter $ \o d -> return $ writeJSON o d)
135+ ,("json" , TextWriter $ \o d -> writeJSON o d)
136136 ,("docx" , ByteStringWriter writeDocx)
137137 ,("odt" , ByteStringWriter writeODT)
138138 ,("pptx" , ByteStringWriter writePowerpoint)
@@ -193,5 +193,5 @@ getWriter s
193193 Just r -> Right (r, setExts $
194194 getDefaultExtensions writerName)
195195
196−writeJSON :: WriterOptions -> Pandoc -> Text
197−writeJSON _ = UTF8.toText . BL.toStrict . encode
196+writeJSON :: PandocMonad m => WriterOptions -> Pandoc -> m Text
197+writeJSON _ = return . UTF8.toText . BL.toStrict . encode