git.iko.soy/typeable/pandoc
on master help sign in
Changed types of writeJSON and readJSON.
90f5dd8John MacFarlane
src/Text/Pandoc/Readers.hs+7−8
@@ -106,7 +106,6 @@ import Text.Pandoc.Readers.TWiki
106import Text.Pandoc.Readers.Txt2Tags
106import Text.Pandoc.Readers.Txt2Tags
107import Text.Pandoc.Readers.Vimwiki
107import Text.Pandoc.Readers.Vimwiki
108import Text.Pandoc.Readers.Man
108import Text.Pandoc.Readers.Man
109−import Text.Pandoc.Shared (mapLeft)
110import qualified Text.Pandoc.UTF8 as UTF8
109import qualified Text.Pandoc.UTF8 as UTF8
111import Text.Parsec.Error
110import Text.Parsec.Error
112
111
@@ -116,10 +115,7 @@ data Reader m = TextReader (ReaderOptions -> Text -> m Pandoc)
116-- | Association list of formats and readers.
115-- | Association list of formats and readers.
117readers :: PandocMonad m => [(String, Reader m)]
116readers :: PandocMonad m => [(String, Reader m)]
118readers = [ ("native" , TextReader readNative)
117readers = [ ("native" , TextReader readNative)
119− ,("json" , TextReader $ \o s ->
118+ ,("json" , TextReader readJSON)
120− case readJSON o s of
121− Right doc -> return doc
122− Left _ -> throwError $ PandocParseError "JSON parse error")
123 ,("markdown" , TextReader readMarkdown)
119 ,("markdown" , TextReader readMarkdown)
124 ,("markdown_strict" , TextReader readMarkdown)
120 ,("markdown_strict" , TextReader readMarkdown)
125 ,("markdown_phpextra" , TextReader readMarkdown)
121 ,("markdown_phpextra" , TextReader readMarkdown)
@@ -162,6 +158,9 @@ getReader s =
162 getDefaultExtensions readerName)
158 getDefaultExtensions readerName)
163
159
164-- | Read pandoc document from JSON format.
160-- | Read pandoc document from JSON format.
161+readJSON :: PandocMonad m
165−readJSON :: ReaderOptions -> Text -> Either PandocError Pandoc
162+ => ReaderOptions -> Text -> m Pandoc
166−readJSON _ =
163+readJSON _ t =
167− mapLeft PandocParseError . eitherDecode' . BL.fromStrict . UTF8.fromText
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)
132writers :: PandocMonad m => [ ( String, Writer m) ]
132writers :: PandocMonad m => [ ( String, Writer m) ]
133writers = [
133writers = [
134 ("native" , TextWriter writeNative)
134 ("native" , TextWriter writeNative)
135− ,("json" , TextWriter $ \o d -> return $ writeJSON o d)
135+ ,("json" , TextWriter $ \o d -> writeJSON o d)
136 ,("docx" , ByteStringWriter writeDocx)
136 ,("docx" , ByteStringWriter writeDocx)
137 ,("odt" , ByteStringWriter writeODT)
137 ,("odt" , ByteStringWriter writeODT)
138 ,("pptx" , ByteStringWriter writePowerpoint)
138 ,("pptx" , ByteStringWriter writePowerpoint)
@@ -193,5 +193,5 @@ getWriter s
193 Just r -> Right (r, setExts $
193 Just r -> Right (r, setExts $
194 getDefaultExtensions writerName)
194 getDefaultExtensions writerName)
195
195
196−writeJSON :: WriterOptions -> Pandoc -> Text
196+writeJSON :: PandocMonad m => WriterOptions -> Pandoc -> m Text
197−writeJSON _ = UTF8.toText . BL.toStrict . encode
197+writeJSON _ = return . UTF8.toText . BL.toStrict . encode