Changed type of 'readers' in Text.Pandoc, so all readers are in IO.

Users who want pure readers can still get them; this just affects
the function getReader that looks up a reader based on the format
name.

The point of this change is to make it possible to print warnings
from the parser.
This commit is contained in:
John MacFarlane
2013-01-03 22:55:55 -08:00
parent 7ef07ea3fc
commit 3bea3635d6
2 changed files with 15 additions and 14 deletions
+3 -2
View File
@@ -1016,8 +1016,9 @@ main = do
then handleIncludes
else return
doc <- (reader readerOpts) `fmap` (readSources sources >>=
handleIncludes' . convertTabs . intercalate "\n")
doc <- readSources sources >>=
handleIncludes' . convertTabs . intercalate "\n" >>=
reader readerOpts
let doc0 = foldr ($) doc transforms
+12 -12
View File
@@ -176,17 +176,17 @@ parseFormatSpec = parse formatSpec ""
_ -> Set.insert ext
-- | Association list of formats and readers.
readers :: [(String, ReaderOptions -> String -> Pandoc)]
readers = [("native" , \_ -> readNative)
,("json" , \_ -> decodeJSON)
,("markdown_strict" , readMarkdown)
,("markdown" , readMarkdown)
,("rst" , readRST)
,("mediawiki" , readMediaWiki)
,("docbook" , readDocBook)
,("textile" , readTextile) -- TODO : textile+lhs
,("html" , readHtml)
,("latex" , readLaTeX)
readers :: [(String, ReaderOptions -> String -> IO Pandoc)]
readers = [("native" , \_ s -> return $ readNative s)
,("json" , \_ s -> return $ decodeJSON s)
,("markdown_strict" , \o s -> return $ readMarkdown o s)
,("markdown" , \o s -> return $ readMarkdown o s)
,("rst" , \o s -> return $ readRST o s)
,("mediawiki" , \o s -> return $ readMediaWiki o s)
,("docbook" , \o s -> return $ readDocBook o 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)
]
data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
@@ -240,7 +240,7 @@ getDefaultExtensions "markdown_strict" = strictExtensions
getDefaultExtensions _ = pandocExtensions
-- | Retrieve reader based on formatSpec (format+extensions).
getReader :: String -> Either String (ReaderOptions -> String -> Pandoc)
getReader :: String -> Either String (ReaderOptions -> String -> IO Pandoc)
getReader s =
case parseFormatSpec s of
Left e -> Left $ intercalate "\n" $ [m | Message m <- errorMessages e]