{-# LANGUAGE CPP                 #-}
{-# LANGUAGE LambdaCase          #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections       #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE FlexibleContexts    #-}
{- |
   Module      : Text.Pandoc.App.CommandLineOptions
   Copyright   : Copyright (C) 2006-2023 John MacFarlane
   License     : GNU GPL, version 2 or above

   Maintainer  : John MacFarlane <jgm@berkeley@edu>
   Stability   : alpha
   Portability : portable

Does a pandoc conversion based on command-line options.
-}
module Text.Pandoc.App.CommandLineOptions (
            parseOptions
          , parseOptionsFromArgs
          , handleOptInfo
          , options
          , engines
          , setVariable
          ) where
import Control.Monad.Trans
import Control.Monad.State.Strict
import Data.Containers.ListUtils (nubOrd)
import Data.Aeson.Encode.Pretty (encodePretty', Config(..), keyOrder,
         defConfig, Indent(..), NumberFormat(..))
import Data.Bifunctor (second)
import Data.Char (toLower)
import Data.List (intercalate, sort, foldl')
#ifdef _WINDOWS
import Data.List (isPrefixOf)
#endif
import Data.Maybe (fromMaybe, isJust)
import Data.Text (Text)
import Safe (tailDef)
import Skylighting (Syntax (..), defaultSyntaxMap)
import System.Console.GetOpt
import System.Environment (getArgs, getProgName)
import System.Exit (exitSuccess)
import System.FilePath
import System.IO (stdout)
import Text.DocTemplates (Context (..), ToContext (toVal), Val (..))
import Text.Pandoc
import Text.Pandoc.Builder (setMeta)
import Text.Pandoc.App.Opt (Opt (..), LineEnding (..), IpynbOutput (..),
                            DefaultsState (..), applyDefaults,
                            fullDefaultsPath, OptInfo(..))
import Text.Pandoc.Filter (Filter (..))
import Text.Pandoc.Highlighting (highlightingStyles, lookupHighlightingStyle)
import Text.Pandoc.Scripting (ScriptingEngine (..), customTemplate)
import Text.Pandoc.Shared (safeStrRead)
import Text.Printf
import qualified Control.Exception as E
import Control.Monad.Except (ExceptT(..), runExceptT, throwError)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as B
import qualified Data.Map as M
import qualified Data.Text as T
import qualified Text.Pandoc.UTF8 as UTF8

parseOptions :: [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
             -> Opt -> IO (Either OptInfo Opt)
parseOptions :: [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
-> Opt -> IO (Either OptInfo Opt)
parseOptions [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
options' Opt
defaults = do
  [String]
rawArgs <- (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map String -> String
UTF8.decodeArg ([String] -> [String]) -> IO [String] -> IO [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO [String] -> IO [String]
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO [String]
getArgs
  String
prg <- IO String -> IO String
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO String
getProgName
  [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
-> Opt -> String -> [String] -> IO (Either OptInfo Opt)
parseOptionsFromArgs [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
options' Opt
defaults String
prg [String]
rawArgs

parseOptionsFromArgs
  :: [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
  -> Opt -> String -> [String] -> IO (Either OptInfo Opt)
parseOptionsFromArgs :: [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
-> Opt -> String -> [String] -> IO (Either OptInfo Opt)
parseOptionsFromArgs [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
options' Opt
defaults String
prg [String]
rawArgs = do
  let ([Opt -> ExceptT OptInfo IO Opt]
actions, [String]
args, [String]
unrecognizedOpts, [String]
errors) =
           ArgOrder (Opt -> ExceptT OptInfo IO Opt)
-> [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
-> [String]
-> ([Opt -> ExceptT OptInfo IO Opt], [String], [String], [String])
forall a.
ArgOrder a
-> [OptDescr a] -> [String] -> ([a], [String], [String], [String])
getOpt' ArgOrder (Opt -> ExceptT OptInfo IO Opt)
forall a. ArgOrder a
Permute [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
options' ((String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map String -> String
UTF8.decodeArg [String]
rawArgs)

  let unknownOptionErrors :: [String]
unknownOptionErrors =
       (String -> [String] -> [String])
-> [String] -> [String] -> [String]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (String -> [String] -> [String]
handleUnrecognizedOption (String -> [String] -> [String])
-> (String -> String) -> String -> [String] -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'=')) []
       [String]
unrecognizedOpts

  let mbArgs :: Maybe [String]
mbArgs = case [String]
args of
                 [] -> Maybe [String]
forall a. Maybe a
Nothing
                 [String]
xs -> [String] -> Maybe [String]
forall a. a -> Maybe a
Just [String]
xs

  let adjustOpts :: Opt -> Opt
adjustOpts Opt
opts =
           Opt
opts{ optInputFiles :: Maybe [String]
optInputFiles =
                   (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map String -> String
normalizePath ([String] -> [String]) -> Maybe [String] -> Maybe [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Opt -> Maybe [String]
optInputFiles Opt
opts Maybe [String] -> Maybe [String] -> Maybe [String]
forall a. Semigroup a => a -> a -> a
<> Maybe [String]
mbArgs)
               , optStandalone :: Bool
optStandalone = -- certain other options imply standalone
                   Opt -> Bool
optStandalone Opt
opts Bool -> Bool -> Bool
||
                     Maybe String -> Bool
forall a. Maybe a -> Bool
isJust (Opt -> Maybe String
optTemplate Opt
opts) Bool -> Bool -> Bool
||
                     Opt -> Bool
optSelfContained Opt
opts Bool -> Bool -> Bool
||
                     Bool -> Bool
not ([String] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Opt -> [String]
optIncludeInHeader Opt
opts)) Bool -> Bool -> Bool
||
                     Bool -> Bool
not ([String] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Opt -> [String]
optIncludeBeforeBody Opt
opts)) Bool -> Bool -> Bool
||
                     Bool -> Bool
not ([String] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Opt -> [String]
optIncludeAfterBody Opt
opts)) }

  if ([String] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
errors Bool -> Bool -> Bool
&& [String] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
unknownOptionErrors)
     then -- thread option data structure through all supplied option actions
       ExceptT OptInfo IO Opt -> IO (Either OptInfo Opt)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT (ExceptT OptInfo IO Opt -> IO (Either OptInfo Opt))
-> ExceptT OptInfo IO Opt -> IO (Either OptInfo Opt)
forall a b. (a -> b) -> a -> b
$ Opt -> Opt
adjustOpts (Opt -> Opt) -> ExceptT OptInfo IO Opt -> ExceptT OptInfo IO Opt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((ExceptT OptInfo IO Opt
 -> (Opt -> ExceptT OptInfo IO Opt) -> ExceptT OptInfo IO Opt)
-> ExceptT OptInfo IO Opt
-> [Opt -> ExceptT OptInfo IO Opt]
-> ExceptT OptInfo IO Opt
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' ExceptT OptInfo IO Opt
-> (Opt -> ExceptT OptInfo IO Opt) -> ExceptT OptInfo IO Opt
forall a b.
ExceptT OptInfo IO a
-> (a -> ExceptT OptInfo IO b) -> ExceptT OptInfo IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
(>>=) (Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
defaults) [Opt -> ExceptT OptInfo IO Opt]
actions)
     else Either OptInfo Opt -> IO (Either OptInfo Opt)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either OptInfo Opt -> IO (Either OptInfo Opt))
-> Either OptInfo Opt -> IO (Either OptInfo Opt)
forall a b. (a -> b) -> a -> b
$ OptInfo -> Either OptInfo Opt
forall a b. a -> Either a b
Left (OptInfo -> Either OptInfo Opt) -> OptInfo -> Either OptInfo Opt
forall a b. (a -> b) -> a -> b
$ PandocError -> OptInfo
OptError (PandocError -> OptInfo) -> PandocError -> OptInfo
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError (Text -> PandocError) -> Text -> PandocError
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$
             [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String]
errors String -> String -> String
forall a. [a] -> [a] -> [a]
++ [String] -> String
unlines [String]
unknownOptionErrors String -> String -> String
forall a. [a] -> [a] -> [a]
++
             (String
"Try " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
prg String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" --help for more information.")

-- | React to an 'OptInfo' by printing the requested information
-- and exiting or (if there was a parsing error) raising an error.
handleOptInfo :: ScriptingEngine -> OptInfo -> IO ()
handleOptInfo :: ScriptingEngine -> OptInfo -> IO ()
handleOptInfo ScriptingEngine
engine OptInfo
info = (PandocError -> IO ()) -> IO () -> IO ()
forall e a. Exception e => (e -> IO a) -> IO a -> IO a
E.handle (Either PandocError () -> IO ()
forall a. Either PandocError a -> IO a
handleError (Either PandocError () -> IO ())
-> (PandocError -> Either PandocError ()) -> PandocError -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PandocError -> Either PandocError ()
forall a b. a -> Either a b
Left) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
  case OptInfo
info of
    OptInfo
BashCompletion -> do
      [String]
datafiles <- IO [String]
getDataFileNames
      String
tpl <- PandocIO String -> IO String
forall a. PandocIO a -> IO a
runIOorExplode (PandocIO String -> IO String) -> PandocIO String -> IO String
forall a b. (a -> b) -> a -> b
$
               ByteString -> String
UTF8.toString (ByteString -> String) -> PandocIO ByteString -> PandocIO String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                 String -> PandocIO ByteString
forall (m :: * -> *). PandocMonad m => String -> m ByteString
readDefaultDataFile String
"bash_completion.tpl"
      let optnames :: OptDescr a -> [String]
optnames (Option String
shorts [String]
longs ArgDescr a
_ String
_) =
            (Char -> String) -> String -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (\Char
c -> [Char
'-',Char
c]) String
shorts [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++
            (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String
"--" String -> String -> String
forall a. [a] -> [a] -> [a]
++) [String]
longs
      let allopts :: String
allopts = [String] -> String
unwords ((OptDescr (Opt -> ExceptT OptInfo IO Opt) -> [String])
-> [OptDescr (Opt -> ExceptT OptInfo IO Opt)] -> [String]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap OptDescr (Opt -> ExceptT OptInfo IO Opt) -> [String]
forall {a}. OptDescr a -> [String]
optnames [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
options)
      Handle -> Text -> IO ()
UTF8.hPutStrLn Handle
stdout (Text -> IO ()) -> Text -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ String -> String -> String -> String -> String -> String -> String
forall r. PrintfType r => String -> r
printf String
tpl String
allopts
          (Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
T.unwords [Text]
readersNames)
          (Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
T.unwords [Text]
writersNames)
          (Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
T.unwords ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ ((Text, Style) -> Text) -> [(Text, Style)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text, Style) -> Text
forall a b. (a, b) -> a
fst [(Text, Style)]
highlightingStyles)
          ([String] -> String
unwords [String]
datafiles)
    OptInfo
ListInputFormats -> (Text -> IO ()) -> [Text] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Handle -> Text -> IO ()
UTF8.hPutStrLn Handle
stdout) [Text]
readersNames
    OptInfo
ListOutputFormats -> (Text -> IO ()) -> [Text] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Handle -> Text -> IO ()
UTF8.hPutStrLn Handle
stdout) [Text]
writersNames
    ListExtensions Maybe Text
mbfmt -> do
      let formatName :: Text
formatName = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"markdown" Maybe Text
mbfmt
      let allExts :: Extensions
allExts = Text -> Extensions
getAllExtensions Text
formatName
      if Text
formatName Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem`
          (((Text, Reader PandocPure) -> Text)
-> [(Text, Reader PandocPure)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text, Reader PandocPure) -> Text
forall a b. (a, b) -> a
fst ([(Text, Reader PandocPure)]
forall (m :: * -> *). PandocMonad m => [(Text, Reader m)]
readers :: [(Text, Reader PandocPure)]) [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++
           ((Text, Writer PandocPure) -> Text)
-> [(Text, Writer PandocPure)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text, Writer PandocPure) -> Text
forall a b. (a, b) -> a
fst ([(Text, Writer PandocPure)]
forall (m :: * -> *). PandocMonad m => [(Text, Writer m)]
writers :: [(Text, Writer PandocPure)]))
         then PandocError -> IO ()
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO ()) -> PandocError -> IO ()
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError (Text -> PandocError) -> Text -> PandocError
forall a b. (a -> b) -> a -> b
$ Text
formatName Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                Text
" is not a recognized reader or writer format"
         else do
           let defExts :: Extensions
defExts = Text -> Extensions
getDefaultExtensions Text
formatName
           let showExt :: Extension -> String
showExt Extension
x =
                (if Extension -> Extensions -> Bool
extensionEnabled Extension
x Extensions
defExts
                    then Char
'+'
                    else if Extension -> Extensions -> Bool
extensionEnabled Extension
x Extensions
allExts
                            then Char
'-'
                            else Char
' ') Char -> String -> String
forall a. a -> [a] -> [a]
: Int -> String -> String
forall a. Int -> [a] -> [a]
drop Int
4 (Extension -> String
forall a. Show a => a -> String
show Extension
x)
           (Extension -> IO ()) -> [Extension] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Handle -> Text -> IO ()
UTF8.hPutStrLn Handle
stdout (Text -> IO ()) -> (Extension -> Text) -> Extension -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text) -> (Extension -> String) -> Extension -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Extension -> String
showExt)
              (Extensions -> [Extension]
extensionsToList Extensions
allExts)
    OptInfo
ListHighlightLanguages -> do
      let langs :: [String]
langs = [ Text -> String
T.unpack (Text -> Text
T.toLower (Syntax -> Text
sShortname Syntax
s))
                  | Syntax
s <- Map Text Syntax -> [Syntax]
forall k a. Map k a -> [a]
M.elems Map Text Syntax
defaultSyntaxMap
                  , Syntax -> Text
sShortname Syntax
s Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem`
                     [String -> Text
T.pack String
"Alert", String -> Text
T.pack String
"Alert_indent"]
                  ]
      (String -> IO ()) -> [String] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Handle -> Text -> IO ()
UTF8.hPutStrLn Handle
stdout (Text -> IO ()) -> (String -> Text) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack) ([String] -> [String]
forall a. Ord a => [a] -> [a]
sort [String]
langs)
    OptInfo
ListHighlightStyles -> do
      ((Text, Style) -> IO ()) -> [(Text, Style)] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Handle -> Text -> IO ()
UTF8.hPutStrLn Handle
stdout (Text -> IO ())
-> ((Text, Style) -> Text) -> (Text, Style) -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text, Style) -> Text
forall a b. (a, b) -> a
fst) [(Text, Style)]
highlightingStyles
    PrintDefaultTemplate Maybe String
mbout Text
fmt -> do
      let write :: Text -> IO ()
write = (Text -> IO ())
-> (String -> Text -> IO ()) -> Maybe String -> Text -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Handle -> Text -> IO ()
UTF8.hPutStr Handle
stdout) (String -> Text -> IO ()
UTF8.writeFile) Maybe String
mbout

      Either PandocError Text
templ <- PandocIO Text -> IO (Either PandocError Text)
forall a. PandocIO a -> IO (Either PandocError a)
runIO (PandocIO Text -> IO (Either PandocError Text))
-> PandocIO Text -> IO (Either PandocError Text)
forall a b. (a -> b) -> a -> b
$
               case String -> (String, String)
splitExtension (Text -> String
T.unpack Text
fmt) of
                    (String
_, String
"") -> do
                      -- built-in format
                      Maybe String -> PandocIO ()
forall (m :: * -> *). PandocMonad m => Maybe String -> m ()
setUserDataDir Maybe String
forall a. Maybe a
Nothing
                      Text -> PandocIO Text
forall (m :: * -> *). PandocMonad m => Text -> m Text
getDefaultTemplate Text
fmt
                    (String, String)
_ -> do
                      -- format looks like a filepath => custom writer
                      CustomComponents PandocIO
components <- ScriptingEngine
-> forall (m :: * -> *).
   (PandocMonad m, MonadIO m) =>
   String -> m (CustomComponents m)
engineLoadCustom ScriptingEngine
engine (Text -> String
T.unpack Text
fmt)
                      case CustomComponents PandocIO -> Maybe Text
forall (m :: * -> *). CustomComponents m -> Maybe Text
customTemplate CustomComponents PandocIO
components of
                        Just Text
t  -> Text -> PandocIO Text
forall a. a -> PandocIO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
t
                        Maybe Text
Nothing -> PandocError -> PandocIO Text
forall a e. Exception e => e -> a
E.throw (PandocError -> PandocIO Text) -> PandocError -> PandocIO Text
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocNoTemplateError Text
fmt
      case Either PandocError Text
templ of
           Right Text
t
             | Text -> Bool
T.null Text
t -> -- e.g. for docx, odt, json:
                 PandocError -> IO ()
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO ()) -> PandocError -> IO ()
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocCouldNotFindDataFileError (Text -> PandocError) -> Text -> PandocError
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack
                   (String
"templates/default." String -> String -> String
forall a. [a] -> [a] -> [a]
++ Text -> String
T.unpack Text
fmt)
             | Bool
otherwise -> Text -> IO ()
write Text
t
           Left PandocError
e  -> PandocError -> IO ()
forall e a. Exception e => e -> IO a
E.throwIO PandocError
e
    PrintDefaultDataFile Maybe String
mbout Text
f -> do
      let write :: ByteString -> IO ()
write = (ByteString -> IO ())
-> (String -> ByteString -> IO ())
-> Maybe String
-> ByteString
-> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ByteString -> IO ()
BS.putStr String -> ByteString -> IO ()
BS.writeFile Maybe String
mbout
      PandocIO () -> IO ()
forall a. PandocIO a -> IO a
runIOorExplode (PandocIO () -> IO ()) -> PandocIO () -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> PandocIO ByteString
forall (m :: * -> *). PandocMonad m => String -> m ByteString
readDefaultDataFile (Text -> String
T.unpack Text
f) PandocIO ByteString -> (ByteString -> PandocIO ()) -> PandocIO ()
forall a b. PandocIO a -> (a -> PandocIO b) -> PandocIO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IO () -> PandocIO ()
forall a. IO a -> PandocIO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> PandocIO ())
-> (ByteString -> IO ()) -> ByteString -> PandocIO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> IO ()
write
    PrintHighlightStyle Maybe String
mbout Text
styleName -> do
       let write :: ByteString -> IO ()
write = (ByteString -> IO ())
-> (String -> ByteString -> IO ())
-> Maybe String
-> ByteString
-> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ByteString -> IO ()
B.putStr String -> ByteString -> IO ()
B.writeFile Maybe String
mbout
       Style
sty <- PandocIO Style -> IO Style
forall a. PandocIO a -> IO a
runIOorExplode (PandocIO Style -> IO Style) -> PandocIO Style -> IO Style
forall a b. (a -> b) -> a -> b
$ String -> PandocIO Style
forall (m :: * -> *). PandocMonad m => String -> m Style
lookupHighlightingStyle (Text -> String
T.unpack Text
styleName)
       ByteString -> IO ()
write (ByteString -> IO ()) -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ Config -> Style -> ByteString
forall a. ToJSON a => Config -> a -> ByteString
encodePretty'
         Config
defConfig{confIndent :: Indent
confIndent = Int -> Indent
Spaces Int
4
                  ,confCompare :: Text -> Text -> Ordering
confCompare = [Text] -> Text -> Text -> Ordering
keyOrder
                    ((String -> Text) -> [String] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map String -> Text
T.pack
                     [String
"text-color"
                     ,String
"background-color"
                     ,String
"line-number-color"
                     ,String
"line-number-background-color"
                     ,String
"bold"
                     ,String
"italic"
                     ,String
"underline"
                     ,String
"text-styles"])
                  ,confNumFormat :: NumberFormat
confNumFormat = NumberFormat
Generic
                  ,confTrailingNewline :: Bool
confTrailingNewline = Bool
True} Style
sty
    OptInfo
VersionInfo -> do
      String
prg <- IO String
getProgName
      String
defaultDatadir <- IO String
defaultUserDataDir
      Handle -> Text -> IO ()
UTF8.hPutStrLn Handle
stdout
       (Text -> IO ()) -> Text -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack
       (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ String
prg String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Text -> String
T.unpack Text
pandocVersionText String -> String -> String
forall a. [a] -> [a] -> [a]
++
         String
compileInfo String -> String -> String
forall a. [a] -> [a] -> [a]
++
         String
"\nUser data directory: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
defaultDatadir String -> String -> String
forall a. [a] -> [a] -> [a]
++
         (Char
'\n'Char -> String -> String
forall a. a -> [a] -> [a]
:String
copyrightMessage)
    OptInfo
Help -> do
      String
prg <- IO String
getProgName
      Handle -> Text -> IO ()
UTF8.hPutStr Handle
stdout (String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ String -> [OptDescr (Opt -> ExceptT OptInfo IO Opt)] -> String
usageMessage String
prg [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
options)
    OptError PandocError
e -> PandocError -> IO ()
forall e a. Exception e => e -> IO a
E.throwIO PandocError
e
  IO ()
forall a. IO a
exitSuccess

-- | Supported LaTeX engines; the first item is used as default engine
-- when going through LaTeX.
latexEngines :: [String]
latexEngines :: [String]
latexEngines  = [String
"pdflatex", String
"lualatex", String
"xelatex", String
"latexmk", String
"tectonic"]

-- | Supported HTML PDF engines; the first item is used as default
-- engine when going through HTML.
htmlEngines :: [String]
htmlEngines :: [String]
htmlEngines  = [String
"wkhtmltopdf", String
"weasyprint", String
"pagedjs-cli", String
"prince"]

engines :: [(Text, String)]
engines :: [(Text, String)]
engines = (String -> (Text, String)) -> [String] -> [(Text, String)]
forall a b. (a -> b) -> [a] -> [b]
map (Text
"html",) [String]
htmlEngines [(Text, String)] -> [(Text, String)] -> [(Text, String)]
forall a. [a] -> [a] -> [a]
++
          (String -> (Text, String)) -> [String] -> [(Text, String)]
forall a b. (a -> b) -> [a] -> [b]
map (Text
"html5",) [String]
htmlEngines [(Text, String)] -> [(Text, String)] -> [(Text, String)]
forall a. [a] -> [a] -> [a]
++
          (String -> (Text, String)) -> [String] -> [(Text, String)]
forall a b. (a -> b) -> [a] -> [b]
map (Text
"latex",) [String]
latexEngines [(Text, String)] -> [(Text, String)] -> [(Text, String)]
forall a. [a] -> [a] -> [a]
++
          (String -> (Text, String)) -> [String] -> [(Text, String)]
forall a b. (a -> b) -> [a] -> [b]
map (Text
"beamer",) [String]
latexEngines [(Text, String)] -> [(Text, String)] -> [(Text, String)]
forall a. [a] -> [a] -> [a]
++
          [ (Text
"ms", String
"pdfroff")
          , (Text
"typst", String
"typst")
          , (Text
"context", String
"context")
          ]

pdfEngines :: [String]
pdfEngines :: [String]
pdfEngines = [String] -> [String]
forall a. Ord a => [a] -> [a]
nubOrd ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ ((Text, String) -> String) -> [(Text, String)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (Text, String) -> String
forall a b. (a, b) -> b
snd [(Text, String)]
engines

-- | A list of functions, each transforming the options data structure
--   in response to a command-line option.
options :: [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
options :: [OptDescr (Opt -> ExceptT OptInfo IO Opt)]
options =
    [ String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"fr" [String
"from",String
"read"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optFrom :: Maybe Text
optFrom = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
arg })
                  String
"FORMAT")
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"tw" [String
"to",String
"write"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optTo :: Maybe Text
optTo = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
arg })
                  String
"FORMAT")
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"o" [String
"output"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optOutputFile :: Maybe String
optOutputFile =
                                             String -> Maybe String
forall a. a -> Maybe a
Just (String -> String
normalizePath String
arg) })
                  String
"FILE")
                 String
"" -- "Name of output file"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"data-dir"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optDataDir :: Maybe String
optDataDir =
                                  String -> Maybe String
forall a. a -> Maybe a
Just (String -> String
normalizePath String
arg) })
                 String
"DIRECTORY") -- "Directory containing pandoc data files."
                String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"M" [String
"metadata"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     let (String
key, String
val) = String -> (String, String)
splitField String
arg
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optMetadata :: Meta
optMetadata = String -> String -> Meta -> Meta
addMeta String
key String
val (Meta -> Meta) -> Meta -> Meta
forall a b. (a -> b) -> a -> b
$
                                                 Opt -> Meta
optMetadata Opt
opt })
                  String
"KEY[:VALUE]")
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"metadata-file"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optMetadataFiles :: [String]
optMetadataFiles =
                      Opt -> [String]
optMetadataFiles Opt
opt [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String -> String
normalizePath String
arg] })
                  String
"FILE")
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"d" [String
"defaults"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     Either PandocError Opt
res <- IO (Either PandocError Opt)
-> ExceptT OptInfo IO (Either PandocError Opt)
forall a. IO a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either PandocError Opt)
 -> ExceptT OptInfo IO (Either PandocError Opt))
-> IO (Either PandocError Opt)
-> ExceptT OptInfo IO (Either PandocError Opt)
forall a b. (a -> b) -> a -> b
$ PandocIO Opt -> IO (Either PandocError Opt)
forall a. PandocIO a -> IO (Either PandocError a)
runIO (PandocIO Opt -> IO (Either PandocError Opt))
-> PandocIO Opt -> IO (Either PandocError Opt)
forall a b. (a -> b) -> a -> b
$ do
                       let defsState :: DefaultsState
defsState =
                             DefaultsState { curDefaults :: Maybe String
curDefaults = Maybe String
forall a. Maybe a
Nothing,
                                             inheritanceGraph :: [[String]]
inheritanceGraph = [] }
                       String
fp <- Maybe String -> String -> PandocIO String
forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
Maybe String -> String -> m String
fullDefaultsPath (Opt -> Maybe String
optDataDir Opt
opt) String
arg
                       StateT DefaultsState PandocIO Opt -> DefaultsState -> PandocIO Opt
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT (Opt -> String -> StateT DefaultsState PandocIO Opt
forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
Opt -> String -> StateT DefaultsState m Opt
applyDefaults Opt
opt String
fp) DefaultsState
defsState
                     case Either PandocError Opt
res of
                       Left PandocError
e -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError PandocError
e
                       Right Opt
x -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
x
                  )
                  String
"FILE")
                String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"file-scope"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optFileScope :: Bool
optFileScope = Bool
True }))
                 String
"" -- "Parse input files before combining"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"sandbox"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optSandbox :: Bool
optSandbox = Bool
True }))
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"s" [String
"standalone"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optStandalone :: Bool
optStandalone = Bool
True }))
                 String
"" -- "Include needed header and footer on output"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"template"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optTemplate :: Maybe String
optTemplate = String -> Maybe String
forall a. a -> Maybe a
Just (String -> String
normalizePath String
arg) })
                  String
"FILE")
                 String
"" -- "Use custom template"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"V" [String
"variable"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     let (String
key, String
val) = String -> (String, String)
splitField String
arg
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optVariables :: Context Text
optVariables =
                                  Text -> Text -> Context Text -> Context Text
setVariable (String -> Text
T.pack String
key) (String -> Text
T.pack String
val) (Context Text -> Context Text) -> Context Text -> Context Text
forall a b. (a -> b) -> a -> b
$
                                    Opt -> Context Text
optVariables Opt
opt })
                  String
"KEY[:VALUE]")
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"wrap"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    case String
arg of
                      String
"auto" -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optWrap :: WrapOption
optWrap = WrapOption
WrapAuto }
                      String
"none" -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optWrap :: WrapOption
optWrap = WrapOption
WrapNone }
                      String
"preserve" -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optWrap :: WrapOption
optWrap = WrapOption
WrapPreserve }
                      String
_      -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                 Text
"--wrap must be auto, none, or preserve")
                 String
"auto|none|preserve")
                 String
"" -- "Option for wrapping text in output"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"ascii"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optAscii :: Bool
optAscii = Bool
True }))
                 String
""  -- "Prefer ASCII output"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"toc", String
"table-of-contents"]
                ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                 (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optTableOfContents :: Bool
optTableOfContents = Bool
True }))
               String
"" -- "Include table of contents"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"toc-depth"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                      case String -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => String -> m a
safeStrRead String
arg of
                           Just Int
t | Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
1 Bool -> Bool -> Bool
&& Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
6 ->
                                    Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optTOCDepth :: Int
optTOCDepth = Int
t }
                           Maybe Int
_ -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                Text
"TOC level must be a number 1-6")
                 String
"NUMBER")
                 String
"" -- "Number of levels to include in TOC"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"N" [String
"number-sections"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optNumberSections :: Bool
optNumberSections = Bool
True }))
                 String
"" -- "Number sections"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"number-offset"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                      case String -> Maybe [Int]
forall (m :: * -> *) a. (MonadPlus m, Read a) => String -> m a
safeStrRead (String
"[" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
arg String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"]") of
                           Just [Int]
ns -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optNumberOffset :: [Int]
optNumberOffset = [Int]
ns,
                                                   optNumberSections :: Bool
optNumberSections = Bool
True }
                           Maybe [Int]
_      -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                       Text
"could not parse number-offset")
                 String
"NUMBERS")
                 String
"" -- "Starting number for sections, subsections, etc."

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"top-level-division"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                      case String
arg of
                        String
"section" -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optTopLevelDivision :: TopLevelDivision
optTopLevelDivision =
                                        TopLevelDivision
TopLevelSection }
                        String
"chapter" -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optTopLevelDivision :: TopLevelDivision
optTopLevelDivision =
                                        TopLevelDivision
TopLevelChapter }
                        String
"part"    -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optTopLevelDivision :: TopLevelDivision
optTopLevelDivision =
                                        TopLevelDivision
TopLevelPart }
                        String
"default" -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optTopLevelDivision :: TopLevelDivision
optTopLevelDivision =
                                        TopLevelDivision
TopLevelDefault }
                        String
_ -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError (Text -> PandocError) -> Text -> PandocError
forall a b. (a -> b) -> a -> b
$
                                Text
"Top-level division must be " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                                Text
"section,  chapter, part, or default" )
                   String
"section|chapter|part")
                 String
"" -- "Use top-level division type in LaTeX, ConTeXt, DocBook"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"extract-media"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optExtractMedia :: Maybe String
optExtractMedia =
                                  String -> Maybe String
forall a. a -> Maybe a
Just (String -> String
normalizePath String
arg) })
                  String
"PATH")
                 String
"" -- "Directory to which to extract embedded media"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"resource-path"]
                ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optResourcePath :: [String]
optResourcePath =
                                   String -> [String]
splitSearchPath String
arg [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++
                                    Opt -> [String]
optResourcePath Opt
opt })
                   String
"SEARCHPATH")
                  String
"" -- "Paths to search for images and other resources"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"H" [String
"include-in-header"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optIncludeInHeader :: [String]
optIncludeInHeader =
                                             Opt -> [String]
optIncludeInHeader Opt
opt [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++
                                             [String -> String
normalizePath String
arg] })
                  String
"FILE")
                 String
"" -- "File to include at end of header (implies -s)"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"B" [String
"include-before-body"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optIncludeBeforeBody :: [String]
optIncludeBeforeBody =
                                            Opt -> [String]
optIncludeBeforeBody Opt
opt [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++
                                            [String -> String
normalizePath String
arg] })
                  String
"FILE")
                 String
"" -- "File to include before document body"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"A" [String
"include-after-body"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optIncludeAfterBody :: [String]
optIncludeAfterBody =
                                            Opt -> [String]
optIncludeAfterBody Opt
opt [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++
                                            [String -> String
normalizePath String
arg] })
                  String
"FILE")
                 String
"" -- "File to include after document body"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"no-highlight"]
                ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                 (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optHighlightStyle :: Maybe Text
optHighlightStyle = Maybe Text
forall a. Maybe a
Nothing }))
                 String
"" -- "Don't highlight source code"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"highlight-style"]
                ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                 (\String
arg Opt
opt ->
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optHighlightStyle :: Maybe Text
optHighlightStyle = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$
                                 String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ String -> String
normalizePath String
arg })
                 String
"STYLE|FILE")
                 String
"" -- "Style for highlighted code"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"syntax-definition"]
                ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                 (\String
arg Opt
opt ->
                   Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optSyntaxDefinitions :: [String]
optSyntaxDefinitions = String -> String
normalizePath String
arg String -> [String] -> [String]
forall a. a -> [a] -> [a]
:
                                Opt -> [String]
optSyntaxDefinitions Opt
opt })
                 String
"FILE")
                String
"" -- "Syntax definition (xml) file"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"dpi"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    case String -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => String -> m a
safeStrRead String
arg of
                         Just Int
t | Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optDpi :: Int
optDpi = Int
t }
                         Maybe Int
_              -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                        Text
"dpi must be a number greater than 0")
                  String
"NUMBER")
                 String
"" -- "Dpi (default 96)"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"eol"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    case Char -> Char
toLower (Char -> Char) -> String -> String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String
arg of
                      String
"crlf"   -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optEol :: LineEnding
optEol = LineEnding
CRLF }
                      String
"lf"     -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optEol :: LineEnding
optEol = LineEnding
LF }
                      String
"native" -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optEol :: LineEnding
optEol = LineEnding
Native }
                      -- mac-syntax (cr) is not supported in ghc-base.
                      String
_      -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                Text
"--eol must be crlf, lf, or native")
                  String
"crlf|lf|native")
                 String
"" -- "EOL (default OS-dependent)"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"columns"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                      case String -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => String -> m a
safeStrRead String
arg of
                           Just Int
t | Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optColumns :: Int
optColumns = Int
t }
                           Maybe Int
_              -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                   Text
"columns must be a number greater than 0")
                 String
"NUMBER")
                 String
"" -- "Length of line in characters"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"p" [String
"preserve-tabs"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optPreserveTabs :: Bool
optPreserveTabs = Bool
True }))
                 String
"" -- "Preserve tabs instead of converting to spaces"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"tab-stop"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                      case String -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => String -> m a
safeStrRead String
arg of
                           Just Int
t | Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optTabStop :: Int
optTabStop = Int
t }
                           Maybe Int
_              -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                  Text
"tab-stop must be a number greater than 0")
                  String
"NUMBER")
                 String
"" -- "Tab stop (default 4)"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"pdf-engine"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     let b :: String
b = String -> String
takeBaseName String
arg
                     if String
b String -> [String] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
pdfEngines
                        then Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optPdfEngine :: Maybe String
optPdfEngine = String -> Maybe String
forall a. a -> Maybe a
Just String
arg }
                        else PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$
                              Text -> PandocError
PandocOptionError (Text -> PandocError) -> Text -> PandocError
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$
                              String
"pdf-engine must be one of "
                               String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
", " [String]
pdfEngines)
                  String
"PROGRAM")
                 String
"" -- "Name of program to use in generating PDF"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"pdf-engine-opt"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                      let oldArgs :: [String]
oldArgs = Opt -> [String]
optPdfEngineOpts Opt
opt
                      Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optPdfEngineOpts :: [String]
optPdfEngineOpts = [String]
oldArgs [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String
arg]})
                  String
"STRING")
                 String
"" -- "Flags to pass to the PDF-engine, all instances of this option are accumulated and used"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"reference-doc"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optReferenceDoc :: Maybe String
optReferenceDoc = String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String) -> String -> Maybe String
forall a b. (a -> b) -> a -> b
$ String -> String
normalizePath String
arg })
                  String
"FILE")
                 String
"" -- "Path of custom reference doc"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"self-contained"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> do
                    String -> String -> ExceptT OptInfo IO ()
deprecatedOption String
"--self-contained" String
"use --embed-resources --standalone"
                    Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optSelfContained :: Bool
optSelfContained = Bool
True }))
                 String
"" -- "Make slide shows include all the needed js and css (deprecated)"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"embed-resources"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optEmbedResources :: Bool
optEmbedResources = Bool
True }))
                 String
"" -- "Make slide shows include all the needed js and css"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"request-header"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     let (String
key, String
val) = String -> (String, String)
splitField String
arg
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optRequestHeaders :: [(Text, Text)]
optRequestHeaders =
                       (String -> Text
T.pack String
key, String -> Text
T.pack String
val) (Text, Text) -> [(Text, Text)] -> [(Text, Text)]
forall a. a -> [a] -> [a]
: Opt -> [(Text, Text)]
optRequestHeaders Opt
opt })
                  String
"NAME:VALUE")
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"no-check-certificate"]
                ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                 (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optNoCheckCertificate :: Bool
optNoCheckCertificate = Bool
True }))
                String
"" -- "Disable certificate validation"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"abbreviations"]
                ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                 (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optAbbreviations :: Maybe String
optAbbreviations =
                                            String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String) -> String -> Maybe String
forall a b. (a -> b) -> a -> b
$ String -> String
normalizePath String
arg })
                String
"FILE")
                String
"" -- "Specify file for custom abbreviations"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"indented-code-classes"]
                  ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                   (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optIndentedCodeClasses :: [Text]
optIndentedCodeClasses = Text -> [Text]
T.words (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$
                                             (Char -> Char) -> Text -> Text
T.map (\Char
c -> if Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
',' then Char
' ' else Char
c) (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$
                                             String -> Text
T.pack String
arg })
                   String
"STRING")
                  String
"" -- "Classes (whitespace- or comma-separated) to use for indented code-blocks"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"default-image-extension"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optDefaultImageExtension :: Text
optDefaultImageExtension = String -> Text
T.pack String
arg })
                   String
"extension")
                  String
"" -- "Default extension for extensionless images"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"F" [String
"filter"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optFilters :: [Filter]
optFilters =
                      Opt -> [Filter]
optFilters Opt
opt [Filter] -> [Filter] -> [Filter]
forall a. [a] -> [a] -> [a]
++ [String -> Filter
JSONFilter (String -> String
normalizePath String
arg)] })
                  String
"PROGRAM")
                 String
"" -- "External JSON filter"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"L" [String
"lua-filter"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optFilters :: [Filter]
optFilters =
                      Opt -> [Filter]
optFilters Opt
opt [Filter] -> [Filter] -> [Filter]
forall a. [a] -> [a] -> [a]
++ [String -> Filter
LuaFilter (String -> String
normalizePath String
arg)] })
                  String
"SCRIPTPATH")
                 String
"" -- "Lua filter"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"shift-heading-level-by"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                      case String -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => String -> m a
safeStrRead String
arg of
                           Just Int
t ->
                               Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optShiftHeadingLevelBy :: Int
optShiftHeadingLevelBy = Int
t }
                           Maybe Int
_              -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                               Text
"shift-heading-level-by takes an integer argument")
                  String
"NUMBER")
                 String
"" -- "Shift heading level"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"base-header-level"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                      String -> String -> ExceptT OptInfo IO ()
deprecatedOption String
"--base-header-level"
                        String
"Use --shift-heading-level-by instead."
                      case String -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => String -> m a
safeStrRead String
arg of
                           Just Int
t | Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 Bool -> Bool -> Bool
&& Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
6 ->
                               Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optShiftHeadingLevelBy :: Int
optShiftHeadingLevelBy = Int
t Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 }
                           Maybe Int
_              -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                               Text
"base-header-level must be 1-5")
                  String
"NUMBER")
                 String
"" -- "Headers base level"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"track-changes"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     TrackChanges
action <- case String
arg of
                            String
"accept" -> TrackChanges -> ExceptT OptInfo IO TrackChanges
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return TrackChanges
AcceptChanges
                            String
"reject" -> TrackChanges -> ExceptT OptInfo IO TrackChanges
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return TrackChanges
RejectChanges
                            String
"all"    -> TrackChanges -> ExceptT OptInfo IO TrackChanges
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return TrackChanges
AllChanges
                            String
_        -> PandocError -> ExceptT OptInfo IO TrackChanges
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO TrackChanges)
-> PandocError -> ExceptT OptInfo IO TrackChanges
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError (Text -> PandocError) -> Text -> PandocError
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack
                               (String
"Unknown option for track-changes: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
arg)
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optTrackChanges :: TrackChanges
optTrackChanges = TrackChanges
action })
                  String
"accept|reject|all")
                 String
"" -- "Accepting or reject MS Word track-changes.""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"strip-comments"]
                ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                 (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optStripComments :: Bool
optStripComments = Bool
True }))
               String
"" -- "Strip HTML comments"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"reference-links"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optReferenceLinks :: Bool
optReferenceLinks = Bool
True } ))
                 String
"" -- "Use reference links in parsing HTML"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"reference-location"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     ReferenceLocation
action <- case String
arg of
                            String
"block"    -> ReferenceLocation -> ExceptT OptInfo IO ReferenceLocation
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceLocation
EndOfBlock
                            String
"section"  -> ReferenceLocation -> ExceptT OptInfo IO ReferenceLocation
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceLocation
EndOfSection
                            String
"document" -> ReferenceLocation -> ExceptT OptInfo IO ReferenceLocation
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceLocation
EndOfDocument
                            String
_        -> PandocError -> ExceptT OptInfo IO ReferenceLocation
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO ReferenceLocation)
-> PandocError -> ExceptT OptInfo IO ReferenceLocation
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError (Text -> PandocError) -> Text -> PandocError
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack
                               (String
"Unknown option for reference-location: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
arg)
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optReferenceLocation :: ReferenceLocation
optReferenceLocation = ReferenceLocation
action })
                  String
"block|section|document")
                 String
"" -- "Accepting or reject MS Word track-changes.""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"markdown-headings"]
                  ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                    (\String
arg Opt
opt -> do
                      Bool
headingFormat <- case String
arg of
                        String
"setext" -> Bool -> ExceptT OptInfo IO Bool
forall a. a -> ExceptT OptInfo IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
                        String
"atx" -> Bool -> ExceptT OptInfo IO Bool
forall a. a -> ExceptT OptInfo IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False
                        String
_ -> PandocError -> ExceptT OptInfo IO Bool
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Bool)
-> PandocError -> ExceptT OptInfo IO Bool
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError (Text -> PandocError) -> Text -> PandocError
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack
                          (String
"Unknown markdown heading format: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
arg String -> String -> String
forall a. [a] -> [a] -> [a]
++
                            String
". Expecting atx or setext")
                      Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Opt
opt { optSetextHeaders :: Bool
optSetextHeaders = Bool
headingFormat }
                    )
                  String
"setext|atx")
                  String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"list-tables"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> do
                    Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optListTables :: Bool
optListTables = Bool
True } ))
                 String
"" -- "Use list tables for RST"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"listings"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optListings :: Bool
optListings = Bool
True }))
                 String
"" -- "Use listings package for LaTeX code blocks"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"i" [String
"incremental"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optIncremental :: Bool
optIncremental = Bool
True }))
                 String
"" -- "Make list items display incrementally in Slidy/Slideous/S5"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"slide-level"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                      case String -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => String -> m a
safeStrRead String
arg of
                           Just Int
t | Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
6 ->
                                    Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optSlideLevel :: Maybe Int
optSlideLevel = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
t }
                           Maybe Int
_      -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                    Text
"slide level must be a number between 0 and 6")
                 String
"NUMBER")
                 String
"" -- "Force header level for slides"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"section-divs"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optSectionDivs :: Bool
optSectionDivs = Bool
True }))
                 String
"" -- "Put sections in div tags in HTML"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"html-q-tags"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt ->
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optHtmlQTags :: Bool
optHtmlQTags = Bool
True }))
                 String
"" -- "Use <q> tags for quotes in HTML"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"email-obfuscation"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     ObfuscationMethod
method <- case String
arg of
                            String
"references" -> ObfuscationMethod -> ExceptT OptInfo IO ObfuscationMethod
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ObfuscationMethod
ReferenceObfuscation
                            String
"javascript" -> ObfuscationMethod -> ExceptT OptInfo IO ObfuscationMethod
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ObfuscationMethod
JavascriptObfuscation
                            String
"none"       -> ObfuscationMethod -> ExceptT OptInfo IO ObfuscationMethod
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ObfuscationMethod
NoObfuscation
                            String
_            -> PandocError -> ExceptT OptInfo IO ObfuscationMethod
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO ObfuscationMethod)
-> PandocError -> ExceptT OptInfo IO ObfuscationMethod
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError (Text -> PandocError) -> Text -> PandocError
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack
                               (String
"Unknown obfuscation method: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
arg)
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optEmailObfuscation :: ObfuscationMethod
optEmailObfuscation = ObfuscationMethod
method })
                  String
"none|javascript|references")
                 String
"" -- "Method for obfuscating email in HTML"

     , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"id-prefix"]
                  ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                   (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optIdentifierPrefix :: Text
optIdentifierPrefix = String -> Text
T.pack String
arg })
                   String
"STRING")
                  String
"" -- "Prefix to add to automatically generated HTML identifiers"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"T" [String
"title-prefix"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt {
                       optVariables :: Context Text
optVariables =
                         Text -> Text -> Context Text -> Context Text
setVariable Text
"title-prefix" (String -> Text
T.pack String
arg) (Context Text -> Context Text) -> Context Text -> Context Text
forall a b. (a -> b) -> a -> b
$
                           Opt -> Context Text
optVariables Opt
opt,
                       optStandalone :: Bool
optStandalone = Bool
True })
                  String
"STRING")
                 String
"" -- "String to prefix to HTML window title"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"c" [String
"css"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optCss :: [String]
optCss = Opt -> [String]
optCss Opt
opt [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String
arg] })
                  -- add new link to end, so it is included in proper order
                  String
"URL")
                 String
"" -- "Link to CSS style sheet"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"epub-subdirectory"]
             ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optEpubSubdirectory :: String
optEpubSubdirectory = String
arg })
                  String
"DIRNAME")
                 String
"" -- "Name of subdirectory for epub content in OCF container"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"epub-cover-image"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optVariables :: Context Text
optVariables =
                       Text -> Text -> Context Text -> Context Text
setVariable Text
"epub-cover-image"
                         (String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ String -> String
normalizePath String
arg) (Context Text -> Context Text) -> Context Text -> Context Text
forall a b. (a -> b) -> a -> b
$
                         Opt -> Context Text
optVariables Opt
opt })
                  String
"FILE")
                 String
"" -- "Path of epub cover image"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"epub-title-page"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    case String
arg of
                      String
"true" -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optEpubTitlePage :: Bool
optEpubTitlePage = Bool
True }
                      String
"false" -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optEpubTitlePage :: Bool
optEpubTitlePage = Bool
False }
                      String
_ -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError (Text -> PandocError) -> Text -> PandocError
forall a b. (a -> b) -> a -> b
$
                                Text
"Argument to --epub-title-page must be " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                                Text
"true or false" )
                 String
"true|false")
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"epub-metadata"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optEpubMetadata :: Maybe String
optEpubMetadata = String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String) -> String -> Maybe String
forall a b. (a -> b) -> a -> b
$
                                             String -> String
normalizePath String
arg })
                  String
"FILE")
                 String
"" -- "Path of epub metadata file"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"epub-embed-font"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optEpubFonts :: [String]
optEpubFonts = String -> String
normalizePath String
arg String -> [String] -> [String]
forall a. a -> [a] -> [a]
:
                                                Opt -> [String]
optEpubFonts Opt
opt })
                  String
"FILE")
                 String
"" -- "Directory of fonts to embed"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"split-level"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                      case String -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => String -> m a
safeStrRead String
arg of
                           Just Int
t | Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
1 Bool -> Bool -> Bool
&& Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
6 ->
                                    Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optSplitLevel :: Int
optSplitLevel = Int
t }
                           Maybe Int
_      -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                    Text
"split level must be a number between 1 and 6")
                 String
"NUMBER")
                 String
"" -- "Header level at which to split documents in chunked HTML or EPUB"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"chunk-template"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optChunkTemplate :: Maybe Text
optChunkTemplate = Text -> Maybe Text
forall a. a -> Maybe a
Just (String -> Text
T.pack String
arg) })
                 String
"PATHTEMPLATE")
                 String
"" -- "Template for file paths in chunkedhtml"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"epub-chapter-level"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                      String -> String -> ExceptT OptInfo IO ()
deprecatedOption String
"--epub-chapter-level"
                                       String
"use --split-level"
                      case String -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => String -> m a
safeStrRead String
arg of
                           Just Int
t | Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
1 Bool -> Bool -> Bool
&& Int
t Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
6 ->
                                    Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optSplitLevel :: Int
optSplitLevel = Int
t }
                           Maybe Int
_      -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                    Text
"split level must be a number between 1 and 6")
                 String
"NUMBER")
                 String
"" -- "Header level at which to split documents in chunked HTML or EPUB"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"ipynb-output"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    case String
arg of
                      String
"all" -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optIpynbOutput :: IpynbOutput
optIpynbOutput = IpynbOutput
IpynbOutputAll }
                      String
"best" -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optIpynbOutput :: IpynbOutput
optIpynbOutput = IpynbOutput
IpynbOutputBest }
                      String
"none" -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optIpynbOutput :: IpynbOutput
optIpynbOutput = IpynbOutput
IpynbOutputNone }
                      String
_ -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                             Text
"ipynb-output must be all, none, or best")
                 String
"all|none|best")
                 String
"" -- "Starting number for sections, subsections, etc."

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"C" [String
"citeproc"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optFilters :: [Filter]
optFilters =
                      Opt -> [Filter]
optFilters Opt
opt [Filter] -> [Filter] -> [Filter]
forall a. [a] -> [a] -> [a]
++ [Filter
CiteprocFilter] }))
                 String
"" -- "Process citations"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"bibliography"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optMetadata :: Meta
optMetadata =
                                            String -> String -> Meta -> Meta
addMeta String
"bibliography"
                                              (String -> String
normalizePath String
arg) (Meta -> Meta) -> Meta -> Meta
forall a b. (a -> b) -> a -> b
$
                                              Opt -> Meta
optMetadata Opt
opt })
                   String
"FILE")
                 String
""

     , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"csl"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                    case Text -> Meta -> Maybe MetaValue
lookupMeta (String -> Text
T.pack String
"csl") (Meta -> Maybe MetaValue) -> Meta -> Maybe MetaValue
forall a b. (a -> b) -> a -> b
$ Opt -> Meta
optMetadata Opt
opt of
                      Just MetaValue
_ -> PandocError -> ExceptT OptInfo IO Opt
forall a. PandocError -> ExceptT OptInfo IO a
optError (PandocError -> ExceptT OptInfo IO Opt)
-> PandocError -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                   Text
"Only one CSL file can be specified."
                      Maybe MetaValue
Nothing -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optMetadata :: Meta
optMetadata = String -> String -> Meta -> Meta
addMeta String
"csl" (String -> String
normalizePath String
arg) (Meta -> Meta) -> Meta -> Meta
forall a b. (a -> b) -> a -> b
$
                      Opt -> Meta
optMetadata Opt
opt })
                   String
"FILE")
                 String
""

     , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"citation-abbreviations"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                     Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optMetadata :: Meta
optMetadata =
                                  String -> String -> Meta -> Meta
addMeta String
"citation-abbreviations"
                                    (String -> String
normalizePath String
arg) (Meta -> Meta) -> Meta -> Meta
forall a b. (a -> b) -> a -> b
$ Opt -> Meta
optMetadata Opt
opt })
                   String
"FILE")
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"natbib"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optCiteMethod :: CiteMethod
optCiteMethod = CiteMethod
Natbib }))
                 String
"" -- "Use natbib cite commands in LaTeX output"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"biblatex"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optCiteMethod :: CiteMethod
optCiteMethod = CiteMethod
Biblatex }))
                 String
"" -- "Use biblatex cite commands in LaTeX output"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"mathml"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt ->
                      Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optHTMLMathMethod :: HTMLMathMethod
optHTMLMathMethod = HTMLMathMethod
MathML }))
                 String
"" -- "Use mathml for HTML math"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"webtex"]
                 ((Maybe String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (Maybe String -> a) -> String -> ArgDescr a
OptArg
                  (\Maybe String
arg Opt
opt -> do
                      let url' :: String
url' = String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe String
"https://latex.codecogs.com/png.latex?" Maybe String
arg
                      Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optHTMLMathMethod :: HTMLMathMethod
optHTMLMathMethod = Text -> HTMLMathMethod
WebTeX (Text -> HTMLMathMethod) -> Text -> HTMLMathMethod
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
url' })
                  String
"URL")
                 String
"" -- "Use web service for HTML math"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"mathjax"]
                 ((Maybe String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (Maybe String -> a) -> String -> ArgDescr a
OptArg
                  (\Maybe String
arg Opt
opt -> do
                      let url' :: Text
url' = Text -> (String -> Text) -> Maybe String -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
defaultMathJaxURL String -> Text
T.pack Maybe String
arg
                      Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optHTMLMathMethod :: HTMLMathMethod
optHTMLMathMethod = Text -> HTMLMathMethod
MathJax Text
url'})
                  String
"URL")
                 String
"" -- "Use MathJax for HTML math"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"katex"]
                 ((Maybe String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (Maybe String -> a) -> String -> ArgDescr a
OptArg
                  (\Maybe String
arg Opt
opt ->
                      Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt
                        { optHTMLMathMethod :: HTMLMathMethod
optHTMLMathMethod = Text -> HTMLMathMethod
KaTeX (Text -> HTMLMathMethod) -> Text -> HTMLMathMethod
forall a b. (a -> b) -> a -> b
$
                           Text -> (String -> Text) -> Maybe String -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
defaultKaTeXURL String -> Text
T.pack Maybe String
arg })
                  String
"URL")
                  String
"" -- Use KaTeX for HTML Math

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"gladtex"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt ->
                      Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optHTMLMathMethod :: HTMLMathMethod
optHTMLMathMethod = HTMLMathMethod
GladTeX }))
                 String
"" -- "Use gladtex for HTML math"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"trace"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optTrace :: Bool
optTrace = Bool
True }))
                 String
"" -- "Turn on diagnostic tracing in readers."

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"dump-args"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optDumpArgs :: Bool
optDumpArgs = Bool
True }))
                 String
"" -- "Print output filename and arguments to stdout."

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"ignore-args"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optIgnoreArgs :: Bool
optIgnoreArgs = Bool
True }))
                 String
"" -- "Ignore command-line arguments."

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"verbose"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optVerbosity :: Verbosity
optVerbosity = Verbosity
INFO }))
                 String
"" -- "Verbose diagnostic output."

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"quiet"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optVerbosity :: Verbosity
optVerbosity = Verbosity
ERROR }))
                 String
"" -- "Suppress warnings."

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"fail-if-warnings"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optFailIfWarnings :: Bool
optFailIfWarnings = Bool
True }))
                 String
"" -- "Exit with error status if there were  warnings."

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"log"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> ExceptT OptInfo IO Opt
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optLogFile :: Maybe String
optLogFile = String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String) -> String -> Maybe String
forall a b. (a -> b) -> a -> b
$
                                            String -> String
normalizePath String
arg })
                String
"FILE")
                String
"" -- "Log messages in JSON format to this file."

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"bash-completion"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg (\Opt
_ -> OptInfo -> ExceptT OptInfo IO Opt
forall a. OptInfo -> ExceptT OptInfo IO a
optInfo OptInfo
BashCompletion))
                 String
"" -- "Print bash completion script"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"list-input-formats"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg (\Opt
_ -> OptInfo -> ExceptT OptInfo IO Opt
forall a. OptInfo -> ExceptT OptInfo IO a
optInfo OptInfo
ListInputFormats))
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"list-output-formats"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg (\Opt
_ -> OptInfo -> ExceptT OptInfo IO Opt
forall a. OptInfo -> ExceptT OptInfo IO a
optInfo OptInfo
ListOutputFormats))
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"list-extensions"]
                 ((Maybe String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (Maybe String -> a) -> String -> ArgDescr a
OptArg (\Maybe String
arg Opt
_ -> OptInfo -> ExceptT OptInfo IO Opt
forall a. OptInfo -> ExceptT OptInfo IO a
optInfo (OptInfo -> ExceptT OptInfo IO Opt)
-> OptInfo -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Maybe Text -> OptInfo
ListExtensions (Maybe Text -> OptInfo) -> Maybe Text -> OptInfo
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> Maybe String -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe String
arg)
                 String
"FORMAT")
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"list-highlight-languages"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg (\Opt
_ -> OptInfo -> ExceptT OptInfo IO Opt
forall a. OptInfo -> ExceptT OptInfo IO a
optInfo OptInfo
ListHighlightLanguages))
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"list-highlight-styles"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg (\Opt
_ -> OptInfo -> ExceptT OptInfo IO Opt
forall a. OptInfo -> ExceptT OptInfo IO a
optInfo OptInfo
ListHighlightStyles))
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"D" [String
"print-default-template"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opts -> OptInfo -> ExceptT OptInfo IO Opt
forall a. OptInfo -> ExceptT OptInfo IO a
optInfo (OptInfo -> ExceptT OptInfo IO Opt)
-> OptInfo -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$
                    Maybe String -> Text -> OptInfo
PrintDefaultTemplate (Opt -> Maybe String
optOutputFile Opt
opts) (String -> Text
T.pack String
arg))
                 String
"FORMAT")
                 String
"" -- "Print default template for FORMAT"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"print-default-data-file"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opts -> OptInfo -> ExceptT OptInfo IO Opt
forall a. OptInfo -> ExceptT OptInfo IO a
optInfo (OptInfo -> ExceptT OptInfo IO Opt)
-> OptInfo -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$
                    Maybe String -> Text -> OptInfo
PrintDefaultDataFile (Opt -> Maybe String
optOutputFile Opt
opts) (String -> Text
T.pack String
arg))
                 String
"FILE")
                  String
"" -- "Print default data file"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"print-highlight-style"]
                 ((String -> Opt -> ExceptT OptInfo IO Opt)
-> String -> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opts ->
                    OptInfo -> ExceptT OptInfo IO Opt
forall a. OptInfo -> ExceptT OptInfo IO a
optInfo (OptInfo -> ExceptT OptInfo IO Opt)
-> OptInfo -> ExceptT OptInfo IO Opt
forall a b. (a -> b) -> a -> b
$ Maybe String -> Text -> OptInfo
PrintHighlightStyle (Opt -> Maybe String
optOutputFile Opt
opts)
                               (String -> Text
T.pack String
arg))
                  String
"STYLE|FILE")
                 String
"" -- "Print default template for FORMAT"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"v" [String
"version"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg (\Opt
_ -> OptInfo -> ExceptT OptInfo IO Opt
forall a. OptInfo -> ExceptT OptInfo IO a
optInfo OptInfo
VersionInfo))
                 String
"" -- "Print version"

    , String
-> [String]
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
-> String
-> OptDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"h" [String
"help"]
                 ((Opt -> ExceptT OptInfo IO Opt)
-> ArgDescr (Opt -> ExceptT OptInfo IO Opt)
forall a. a -> ArgDescr a
NoArg (\Opt
_ -> OptInfo -> ExceptT OptInfo IO Opt
forall a. OptInfo -> ExceptT OptInfo IO a
optInfo OptInfo
Help))
                 String
"" -- "Show help"
    ]

optError :: PandocError -> ExceptT OptInfo IO a
optError :: forall a. PandocError -> ExceptT OptInfo IO a
optError = OptInfo -> ExceptT OptInfo IO a
forall a. OptInfo -> ExceptT OptInfo IO a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (OptInfo -> ExceptT OptInfo IO a)
-> (PandocError -> OptInfo) -> PandocError -> ExceptT OptInfo IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PandocError -> OptInfo
OptError

optInfo :: OptInfo -> ExceptT OptInfo IO a
optInfo :: forall a. OptInfo -> ExceptT OptInfo IO a
optInfo = OptInfo -> ExceptT OptInfo IO a
forall a. OptInfo -> ExceptT OptInfo IO a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError

-- Returns usage message
usageMessage :: String -> [OptDescr (Opt -> ExceptT OptInfo IO Opt)] -> String
usageMessage :: String -> [OptDescr (Opt -> ExceptT OptInfo IO Opt)] -> String
usageMessage String
programName = String -> [OptDescr (Opt -> ExceptT OptInfo IO Opt)] -> String
forall a. String -> [OptDescr a] -> String
usageInfo (String
programName String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" [OPTIONS] [FILES]")

copyrightMessage :: String
copyrightMessage :: String
copyrightMessage = String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"\n" [
 String
"Copyright (C) 2006-2023 John MacFarlane. Web:  https://pandoc.org",
 String
"This is free software; see the source for copying conditions. There is no",
 String
"warranty, not even for merchantability or fitness for a particular purpose." ]

compileInfo :: String
compileInfo :: String
compileInfo =
  String
"\nCompiled with pandoc-types " String -> String -> String
forall a. [a] -> [a] -> [a]
++ VERSION_pandoc_types ++
  String
", texmath " String -> String -> String
forall a. [a] -> [a] -> [a]
++ VERSION_texmath ++ ", skylighting " ++
  VERSION_skylighting ++ ",\nciteproc " ++ VERSION_citeproc ++
  ", ipynb " ++ VERSION_ipynb

handleUnrecognizedOption :: String -> [String] -> [String]
handleUnrecognizedOption :: String -> [String] -> [String]
handleUnrecognizedOption String
"--smart" =
  ((String
"--smart/-S has been removed.  Use +smart or -smart extension instead.\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
    String
"For example: pandoc -f markdown+smart -t markdown-smart.") String -> [String] -> [String]
forall a. a -> [a] -> [a]
:)
handleUnrecognizedOption String
"--normalize" =
  (String
"--normalize has been removed.  Normalization is now automatic." String -> [String] -> [String]
forall a. a -> [a] -> [a]
:)
handleUnrecognizedOption String
"-S" = String -> [String] -> [String]
handleUnrecognizedOption String
"--smart"
handleUnrecognizedOption String
"--old-dashes" =
  (String
"--old-dashes has been removed.  Use +old_dashes extension instead." String -> [String] -> [String]
forall a. a -> [a] -> [a]
:)
handleUnrecognizedOption String
"--no-wrap" =
  (String
"--no-wrap has been removed.  Use --wrap=none instead." String -> [String] -> [String]
forall a. a -> [a] -> [a]
:)
handleUnrecognizedOption String
"--latex-engine" =
  (String
"--latex-engine has been removed.  Use --pdf-engine instead." String -> [String] -> [String]
forall a. a -> [a] -> [a]
:)
handleUnrecognizedOption String
"--latex-engine-opt" =
  (String
"--latex-engine-opt has been removed.  Use --pdf-engine-opt instead." String -> [String] -> [String]
forall a. a -> [a] -> [a]
:)
handleUnrecognizedOption String
"--chapters" =
  (String
"--chapters has been removed. Use --top-level-division=chapter instead." String -> [String] -> [String]
forall a. a -> [a] -> [a]
:)
handleUnrecognizedOption String
"--reference-docx" =
  (String
"--reference-docx has been removed. Use --reference-doc instead." String -> [String] -> [String]
forall a. a -> [a] -> [a]
:)
handleUnrecognizedOption String
"--reference-odt" =
  (String
"--reference-odt has been removed. Use --reference-doc instead." String -> [String] -> [String]
forall a. a -> [a] -> [a]
:)
handleUnrecognizedOption String
"--parse-raw" =
  (String
"--parse-raw/-R has been removed. Use +raw_html or +raw_tex extension.\n" String -> [String] -> [String]
forall a. a -> [a] -> [a]
:)
handleUnrecognizedOption String
"--epub-stylesheet" =
  (String
"--epub-stylesheet has been removed. Use --css instead.\n" String -> [String] -> [String]
forall a. a -> [a] -> [a]
:)
handleUnrecognizedOption String
"-R" = String -> [String] -> [String]
handleUnrecognizedOption String
"--parse-raw"
handleUnrecognizedOption String
x =
  ((String
"Unknown option " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
".") String -> [String] -> [String]
forall a. a -> [a] -> [a]
:)

readersNames :: [Text]
readersNames :: [Text]
readersNames = [Text] -> [Text]
forall a. Ord a => [a] -> [a]
sort (((Text, Reader PandocIO) -> Text)
-> [(Text, Reader PandocIO)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text, Reader PandocIO) -> Text
forall a b. (a, b) -> a
fst ([(Text, Reader PandocIO)]
forall (m :: * -> *). PandocMonad m => [(Text, Reader m)]
readers :: [(Text, Reader PandocIO)]))

writersNames :: [Text]
writersNames :: [Text]
writersNames = [Text] -> [Text]
forall a. Ord a => [a] -> [a]
sort
  (Text
"pdf" Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: ((Text, Writer PandocIO) -> Text)
-> [(Text, Writer PandocIO)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text, Writer PandocIO) -> Text
forall a b. (a, b) -> a
fst ([(Text, Writer PandocIO)]
forall (m :: * -> *). PandocMonad m => [(Text, Writer m)]
writers :: [(Text, Writer PandocIO)]))

splitField :: String -> (String, String)
splitField :: String -> (String, String)
splitField = (String -> String) -> (String, String) -> (String, String)
forall b c a. (b -> c) -> (a, b) -> (a, c)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second (String -> String -> String
forall a. [a] -> [a] -> [a]
tailDef String
"true") ((String, String) -> (String, String))
-> (String -> (String, String)) -> String -> (String, String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (\Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
':' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'=')

deprecatedOption :: String -> String -> ExceptT OptInfo IO ()
deprecatedOption :: String -> String -> ExceptT OptInfo IO ()
deprecatedOption String
o String
msg = do
  Either PandocError ()
res <- IO (Either PandocError ())
-> ExceptT OptInfo IO (Either PandocError ())
forall a. IO a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either PandocError ())
 -> ExceptT OptInfo IO (Either PandocError ()))
-> IO (Either PandocError ())
-> ExceptT OptInfo IO (Either PandocError ())
forall a b. (a -> b) -> a -> b
$ PandocIO () -> IO (Either PandocError ())
forall a. PandocIO a -> IO (Either PandocError a)
runIO (LogMessage -> PandocIO ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> PandocIO ()) -> LogMessage -> PandocIO ()
forall a b. (a -> b) -> a -> b
$ Text -> Text -> LogMessage
Deprecated (String -> Text
T.pack String
o) (String -> Text
T.pack String
msg))
  case Either PandocError ()
res of
       Right () -> () -> ExceptT OptInfo IO ()
forall a. a -> ExceptT OptInfo IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
       Left PandocError
e   -> PandocError -> ExceptT OptInfo IO ()
forall a. PandocError -> ExceptT OptInfo IO a
optError PandocError
e

-- | Set text value in text context.  Create list if it has a value already,
-- or add to a list value.
setVariable :: Text -> Text -> Context Text -> Context Text
setVariable :: Text -> Text -> Context Text -> Context Text
setVariable Text
key Text
val (Context Map Text (Val Text)
ctx) = Map Text (Val Text) -> Context Text
forall a. Map Text (Val a) -> Context a
Context (Map Text (Val Text) -> Context Text)
-> Map Text (Val Text) -> Context Text
forall a b. (a -> b) -> a -> b
$ (Maybe (Val Text) -> Maybe (Val Text))
-> Text -> Map Text (Val Text) -> Map Text (Val Text)
forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
M.alter Maybe (Val Text) -> Maybe (Val Text)
forall {a}. ToContext a Text => Maybe (Val a) -> Maybe (Val a)
go Text
key Map Text (Val Text)
ctx
  where go :: Maybe (Val a) -> Maybe (Val a)
go Maybe (Val a)
Nothing             = Val a -> Maybe (Val a)
forall a. a -> Maybe a
Just (Val a -> Maybe (Val a)) -> Val a -> Maybe (Val a)
forall a b. (a -> b) -> a -> b
$ Text -> Val a
forall a b. ToContext a b => b -> Val a
toVal Text
val
        go (Just (ListVal [Val a]
xs)) = Val a -> Maybe (Val a)
forall a. a -> Maybe a
Just (Val a -> Maybe (Val a)) -> Val a -> Maybe (Val a)
forall a b. (a -> b) -> a -> b
$ [Val a] -> Val a
forall a. [Val a] -> Val a
ListVal ([Val a] -> Val a) -> [Val a] -> Val a
forall a b. (a -> b) -> a -> b
$ [Val a]
xs [Val a] -> [Val a] -> [Val a]
forall a. [a] -> [a] -> [a]
++ [Text -> Val a
forall a b. ToContext a b => b -> Val a
toVal Text
val]
        go (Just Val a
x)            = Val a -> Maybe (Val a)
forall a. a -> Maybe a
Just (Val a -> Maybe (Val a)) -> Val a -> Maybe (Val a)
forall a b. (a -> b) -> a -> b
$ [Val a] -> Val a
forall a. [Val a] -> Val a
ListVal [Val a
x, Text -> Val a
forall a b. ToContext a b => b -> Val a
toVal Text
val]

addMeta :: String -> String -> Meta -> Meta
addMeta :: String -> String -> Meta -> Meta
addMeta String
k String
v Meta
meta =
  case Text -> Meta -> Maybe MetaValue
lookupMeta Text
k' Meta
meta of
       Maybe MetaValue
Nothing -> Text -> MetaValue -> Meta -> Meta
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
forall b. ToMetaValue b => Text -> b -> Meta -> Meta
setMeta Text
k' MetaValue
v' Meta
meta
       Just (MetaList [MetaValue]
xs) ->
                  Text -> MetaValue -> Meta -> Meta
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
forall b. ToMetaValue b => Text -> b -> Meta -> Meta
setMeta Text
k' ([MetaValue] -> MetaValue
MetaList ([MetaValue]
xs [MetaValue] -> [MetaValue] -> [MetaValue]
forall a. [a] -> [a] -> [a]
++ [MetaValue
v'])) Meta
meta
       Just MetaValue
x  -> Text -> MetaValue -> Meta -> Meta
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
forall b. ToMetaValue b => Text -> b -> Meta -> Meta
setMeta Text
k' ([MetaValue] -> MetaValue
MetaList [MetaValue
x, MetaValue
v']) Meta
meta
 where
  v' :: MetaValue
v' = String -> MetaValue
readMetaValue String
v
  k' :: Text
k' = String -> Text
T.pack String
k

readMetaValue :: String -> MetaValue
readMetaValue :: String -> MetaValue
readMetaValue String
s
  | String
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"true"  = Bool -> MetaValue
MetaBool Bool
True
  | String
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"True"  = Bool -> MetaValue
MetaBool Bool
True
  | String
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"TRUE"  = Bool -> MetaValue
MetaBool Bool
True
  | String
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"false" = Bool -> MetaValue
MetaBool Bool
False
  | String
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"False" = Bool -> MetaValue
MetaBool Bool
False
  | String
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"FALSE" = Bool -> MetaValue
MetaBool Bool
False
  | Bool
otherwise    = Text -> MetaValue
MetaString (Text -> MetaValue) -> Text -> MetaValue
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
s

-- On Windows with ghc 8.6+, we need to rewrite paths
-- beginning with \\ to \\?\UNC\. -- See #5127.
normalizePath :: FilePath -> FilePath
#ifdef _WINDOWS
normalizePath fp =
  if "\\\\" `isPrefixOf` fp && not ("\\\\?\\" `isPrefixOf` fp)
    then "\\\\?\\UNC\\" ++ drop 2 fp
    else fp
#else
normalizePath :: String -> String
normalizePath = String -> String
forall a. a -> a
id
#endif