diff options
author | Jesse Rosenthal <jrosenthal@jhu.edu> | 2016-11-26 08:46:28 -0500 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-01-25 17:07:39 +0100 |
commit | 04487779b26458597fb751325b24c576b5088662 (patch) | |
tree | 0ee34da90dcfaee63b821ac68f8e0a40267d616a /pandoc.hs | |
parent | b19f79f672c49322328584fa339215e4234d98af (diff) |
Convert all writers to use PandocMonad.
Since PandocMonad is an instance of MonadError, this will allow us, in a
future commit, to change all invocations of `error` to `throwError`,
which will be preferable for the pure versions. At the moment, we're
disabling the lua custom writers (this is temporary).
This requires changing the type of the Writer in Text.Pandoc. Right now,
we run `runIOorExplode` in pandoc.hs, to make the conversion easier. We
can switch it to the safer `runIO` in the future.
Note that this required a change to Text.Pandoc.PDF as well. Since
running an external program is necessarily IO, we can be clearer about
using PandocIO.
Diffstat (limited to 'pandoc.hs')
-rw-r--r-- | pandoc.hs | 39 |
1 files changed, 21 insertions, 18 deletions
@@ -77,6 +77,7 @@ import Text.Printf (printf) import System.Posix.Terminal (queryTerminal) import System.Posix.IO (stdOutput) #endif +import Text.Pandoc.Class (runIOorExplode, PandocIO) type Transform = Pandoc -> Pandoc @@ -914,7 +915,7 @@ options = let allopts = unwords (concatMap optnames options) UTF8.hPutStrLn stdout $ printf tpl allopts (unwords (map fst readers)) - (unwords (map fst writers)) + (unwords (map fst (writers' :: [(String, Writer' PandocIO)]))) (unwords $ map fst highlightingStyles) ddir exitSuccess )) @@ -931,7 +932,7 @@ options = , Option "" ["list-output-formats"] (NoArg (\_ -> do - let writers'names = sort (map fst writers) + let writers'names = sort (map fst (writers' :: [(String, Writer' PandocIO)])) mapM_ (UTF8.hPutStrLn stdout) writers'names exitSuccess )) "" @@ -1268,10 +1269,12 @@ convertWithOpts opts args = do let laTeXInput = "latex" `isPrefixOf` readerName' || "beamer" `isPrefixOf` readerName' + + -- disabling the custom writer for now writer <- if ".lua" `isSuffixOf` format -- note: use non-lowercased version writerName - then return $ IOStringWriter $ writeCustom writerName - else case getWriter writerName' of + then error "custom writers disabled for now" + else case getWriter' writerName' of Left e -> err 9 $ if format == "pdf" then e ++ @@ -1477,9 +1480,9 @@ convertWithOpts opts args = do writerFn f = UTF8.writeFile f case writer of - IOStringWriter f -> f writerOptions doc' >>= writerFn outputFile - IOByteStringWriter f -> f writerOptions doc' >>= writeFnBinary outputFile - PureStringWriter f + -- StringWriter f -> f writerOptions doc' >>= writerFn outputFile + ByteStringWriter' f -> (runIOorExplode $ f writerOptions doc') >>= writeFnBinary outputFile + StringWriter' f | pdfOutput -> do -- make sure writer is latex or beamer or context or html5 unless (laTeXOutput || conTeXtOutput || html5Output) $ @@ -1503,14 +1506,14 @@ convertWithOpts opts args = do B.hPutStr stderr err' B.hPut stderr $ B.pack [10] err 43 "Error producing PDF" - | otherwise -> selfcontain (f writerOptions doc' ++ - ['\n' | not standalone']) - >>= writerFn outputFile . handleEntities - where htmlFormat = format `elem` - ["html","html5","s5","slidy","slideous","dzslides","revealjs"] - selfcontain = if selfContained && htmlFormat - then makeSelfContained writerOptions - else return - handleEntities = if htmlFormat && ascii - then toEntities - else id + | otherwise -> do + let htmlFormat = format `elem` + ["html","html5","s5","slidy","slideous","dzslides","revealjs"] + selfcontain = if selfContained && htmlFormat + then makeSelfContained writerOptions + else return + handleEntities = if htmlFormat && ascii + then toEntities + else id + output <- runIOorExplode $ f writerOptions doc' + selfcontain (output ++ ['\n' | not standalone']) >>= writerFn outputFile . handleEntities |