2006-12-20 07:50:14 +01:00
|
|
|
{- |
|
|
|
|
Module : Main
|
2022-01-01 20:02:31 +01:00
|
|
|
Copyright : Copyright (C) 2006-2022 John MacFarlane
|
2008-08-10 19:33:20 +02:00
|
|
|
License : GNU GPL, version 2 or above
|
2006-12-20 07:50:14 +01:00
|
|
|
|
2007-07-08 00:51:55 +02:00
|
|
|
Maintainer : John MacFarlane <jgm@berkeley@edu>
|
2008-08-10 19:33:20 +02:00
|
|
|
Stability : alpha
|
2006-12-20 07:50:14 +01:00
|
|
|
Portability : portable
|
|
|
|
|
|
|
|
Parses command-line options and calls the appropriate readers and
|
|
|
|
writers.
|
|
|
|
-}
|
2006-10-17 16:22:29 +02:00
|
|
|
module Main where
|
2017-04-02 23:02:55 +02:00
|
|
|
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)
|
2022-08-17 01:27:31 +02:00
|
|
|
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
|
|
|
|
2016-12-10 12:36:09 +01:00
|
|
|
main :: IO ()
|
2022-08-17 01:27:31 +02:00
|
|
|
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
|