Skip to content

Commit

Permalink
Support new IO-capable Writer API
Browse files Browse the repository at this point in the history
  • Loading branch information
samstokes committed Sep 22, 2016
1 parent e0bacf1 commit 73facaf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion OTL/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ module Main (

import Text.OTL
import Text.OTL.Pandoc
import qualified Text.Pandoc.UTF8 as UTF8

import Text.ParserCombinators.Parsec (ParseError)
import System.Exit (exitFailure)
import qualified Text.Pandoc as Pandoc
import System.Environment (getArgs)
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy as B


main :: IO ()
Expand All @@ -43,4 +45,9 @@ handleParse (Right outline) = do
let writer = fromMaybe (error $ "can't write " ++ outputFormat) $ lookup outputFormat Pandoc.writers
options <- defaultWriterOptions outputFormat
pandoc <- toPandoc outline
putStrLn $ writer options $ pandoc
let writeBinary :: B.ByteString -> IO ()
writeBinary = B.writeFile (UTF8.encodePath "-")
case writer of
Pandoc.PureStringWriter w -> UTF8.putStr $ w options pandoc
Pandoc.IOStringWriter w -> w options pandoc >>= UTF8.putStr
Pandoc.IOByteStringWriter w -> w options pandoc >>= writeBinary

0 comments on commit 73facaf

Please sign in to comment.