aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-07-23 22:31:50 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-07-23 22:31:50 -0700
commit5592666ca44aa0d027cd95bf11cff09825896584 (patch)
tree60b63a739ea79030aa436b0e351ecb406b583a84 /src/Text/Pandoc.hs
parentaf5705308a4e4271602e7d356fa8602489e31d0e (diff)
downloadpandoc-5592666ca44aa0d027cd95bf11cff09825896584.tar.gz
Text.Pandoc: Added readJSON, writeJSON to the API.
Closes #817.
Diffstat (limited to 'src/Text/Pandoc.hs')
-rw-r--r--src/Text/Pandoc.hs26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/Text/Pandoc.hs b/src/Text/Pandoc.hs
index 86e78ce53..b5b698e09 100644
--- a/src/Text/Pandoc.hs
+++ b/src/Text/Pandoc.hs
@@ -72,9 +72,11 @@ module Text.Pandoc
, readOPML
, readHaddock
, readNative
+ , readJSON
-- * Writers: converting /from/ Pandoc format
, Writer (..)
, writeNative
+ , writeJSON
, writeMarkdown
, writePlain
, writeRST
@@ -190,9 +192,8 @@ markdown o s = do
-- | Association list of formats and readers.
readers :: [(String, ReaderOptions -> String -> IO Pandoc)]
-readers = [("native" , \_ s -> return $ readNative s)
- ,("json" , \_ s -> return $ checkJSON
- $ decode $ UTF8.fromStringLazy s)
+readers = [ ("native" , \_ s -> return $ readNative s)
+ ,("json" , \o s -> return $ readJSON o s)
,("markdown" , markdown)
,("markdown_strict" , markdown)
,("markdown_phpextra" , markdown)
@@ -205,8 +206,8 @@ readers = [("native" , \_ s -> return $ readNative s)
,("textile" , \o s -> return $ readTextile o s) -- TODO : textile+lhs
,("html" , \o s -> return $ readHtml o s)
,("latex" , \o s -> return $ readLaTeX o s)
- ,("haddock" , \o s -> return $ readHaddock o s)
- ]
+ ,("haddock" , \o s -> return $ readHaddock o s)
+ ]
data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
| IOStringWriter (WriterOptions -> Pandoc -> IO String)
@@ -216,12 +217,12 @@ data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
writers :: [ ( String, Writer ) ]
writers = [
("native" , PureStringWriter writeNative)
- ,("json" , PureStringWriter $ \_ -> UTF8.toStringLazy . encode)
+ ,("json" , PureStringWriter writeJSON)
,("docx" , IOByteStringWriter writeDocx)
- ,("odt" , IOByteStringWriter writeODT)
- ,("epub" , IOByteStringWriter $ \o ->
+ ,("odt" , IOByteStringWriter writeODT)
+ ,("epub" , IOByteStringWriter $ \o ->
writeEPUB o{ writerEpubVersion = Just EPUB2 })
- ,("epub3" , IOByteStringWriter $ \o ->
+ ,("epub3" , IOByteStringWriter $ \o ->
writeEPUB o{ writerEpubVersion = Just EPUB3 })
,("fb2" , IOStringWriter writeFB2)
,("html" , PureStringWriter writeHtmlString)
@@ -359,3 +360,10 @@ instance (Data a) => ToJsonFilter (a -> IO [a]) where
checkJSON :: Maybe a -> a
checkJSON Nothing = error "Error parsing JSON"
checkJSON (Just r) = r
+
+readJSON :: ReaderOptions -> String -> Pandoc
+readJSON _ = checkJSON . decode . UTF8.fromStringLazy
+
+writeJSON :: WriterOptions -> Pandoc -> String
+writeJSON _ = UTF8.toStringLazy . encode
+