pandoc/app/pandoc.hs

32 lines
1 KiB
Haskell
Raw Normal View History

{- |
Module : Main
2022-01-01 20:02:31 +01:00
Copyright : Copyright (C) 2006-2022 John MacFarlane
License : GNU GPL, version 2 or above
Maintainer : John MacFarlane <jgm@berkeley@edu>
Stability : alpha
Portability : portable
Parses command-line options and calls the appropriate readers and
writers.
-}
module Main where
import qualified Control.Exception as E
2017-06-01 15:09:38 +02:00
import Text.Pandoc.App (convertWithOpts, defaultOpts, options, parseOptions)
2017-10-28 05:39:20 +02:00
import Text.Pandoc.Error (handleError)
import Text.Pandoc.Server (ServerOpts(..), parseServerOpts, app)
import System.Environment (getProgName)
import qualified Network.Wai.Handler.CGI as CGI
import qualified Network.Wai.Handler.Warp as Warp
import Network.Wai.Middleware.Timeout (timeout)
2015-02-18 20:57:30 +01:00
main :: IO ()
main = E.handle (handleError . Left) $ do
prg <- getProgName
case prg of
"pandoc-server.cgi" -> CGI.run (timeout 2 app)
"pandoc-server" -> do
sopts <- parseServerOpts
Warp.run (serverPort sopts) (timeout (serverTimeout sopts) app)
_ -> parseOptions options defaultOpts >>= convertWithOpts