{-# LANGUAGE CPP                 #-}
{-# LANGUAGE LambdaCase          #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections       #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE FlexibleContexts    #-}
{- |
   Module      : Text.Pandoc.App.CommandLineOptions
   Copyright   : Copyright (C) 2006-2021 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
          , options
          , engines
          , lookupHighlightStyle
          , setVariable
          ) where
import Control.Monad
import Control.Monad.Trans
import Control.Monad.Except (throwError)
import Control.Monad.State.Strict
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
#if MIN_VERSION_base(4,12,0)
import Data.List (isPrefixOf)
#endif
#endif
import Data.Maybe (fromMaybe, isJust)
import Data.Text (Text)
import Safe (tailDef)
import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme)
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)
import Text.Pandoc.Filter (Filter (..))
import Text.Pandoc.Highlighting (highlightingStyles)
import Text.Pandoc.Shared (ordNub, elemText, safeStrRead, defaultUserDataDir)
import Text.Printf

#ifdef EMBED_DATA_FILES
import Text.Pandoc.Data (dataFiles)
#else
import Paths_pandoc (getDataDir)
import System.Directory (getDirectoryContents)
#endif

import qualified Control.Exception as E
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 -> IO Opt)] -> Opt -> IO Opt
parseOptions :: [OptDescr (Opt -> IO Opt)] -> Opt -> IO Opt
parseOptions [OptDescr (Opt -> 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]
getArgs
  String
prg <- IO String
getProgName
  [OptDescr (Opt -> IO Opt)] -> Opt -> String -> [String] -> IO Opt
parseOptionsFromArgs [OptDescr (Opt -> IO Opt)]
options' Opt
defaults String
prg [String]
rawArgs

parseOptionsFromArgs
  :: [OptDescr (Opt -> IO Opt)] -> Opt -> String -> [String] -> IO Opt
parseOptionsFromArgs :: [OptDescr (Opt -> IO Opt)] -> Opt -> String -> [String] -> IO Opt
parseOptionsFromArgs [OptDescr (Opt -> IO Opt)]
options' Opt
defaults String
prg [String]
rawArgs = do
  let ([Opt -> IO Opt]
actions, [String]
args, [String]
unrecognizedOpts, [String]
errors) =
           ArgOrder (Opt -> IO Opt)
-> [OptDescr (Opt -> IO Opt)]
-> [String]
-> ([Opt -> IO Opt], [String], [String], [String])
forall a.
ArgOrder a
-> [OptDescr a] -> [String] -> ([a], [String], [String], [String])
getOpt' ArgOrder (Opt -> IO Opt)
forall a. ArgOrder a
Permute [OptDescr (Opt -> 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 (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

  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
errors Bool -> Bool -> Bool
&& [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
unknownOptionErrors) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
     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
$ 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.")

  -- thread option data structure through all supplied option actions
  Opt
opts <- (IO Opt -> (Opt -> IO Opt) -> IO Opt)
-> IO Opt -> [Opt -> IO Opt] -> IO Opt
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' IO Opt -> (Opt -> IO Opt) -> IO Opt
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
(>>=) (Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
defaults) [Opt -> IO Opt]
actions
  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
  Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return (Opt -> IO Opt) -> Opt -> IO Opt
forall a b. (a -> b) -> a -> b
$ 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 (t :: * -> *) a. Foldable t => t a -> Bool
null (Opt -> [String]
optIncludeInHeader Opt
opts)) Bool -> Bool -> Bool
||
                     Bool -> Bool
not ([String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Opt -> [String]
optIncludeBeforeBody Opt
opts)) Bool -> Bool -> Bool
||
                     Bool -> Bool
not ([String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Opt -> [String]
optIncludeAfterBody Opt
opts)) }

latexEngines :: [String]
latexEngines :: [String]
latexEngines  = [String
"pdflatex", String
"lualatex", String
"xelatex", String
"latexmk", String
"tectonic"]

htmlEngines :: [String]
htmlEngines :: [String]
htmlEngines  = [String
"wkhtmltopdf", String
"weasyprint", 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
"context", String
"context")
          ]

pdfEngines :: [String]
pdfEngines :: [String]
pdfEngines = [String] -> [String]
forall a. Ord a => [a] -> [a]
ordNub ([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 -> IO Opt)]
options :: [OptDescr (Opt -> IO Opt)]
options =
    [ String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"fr" [String
"from",String
"read"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> Text
T.toLower (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
arg) })
                  String
"FORMAT")
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"tw" [String
"to",String
"write"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"o" [String
"output"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"data-dir"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"M" [String
"metadata"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"metadata-file"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"d" [String
"defaults"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> PandocIO Opt -> IO Opt
forall a. PandocIO a -> IO a
runIOorExplode (PandocIO Opt -> IO Opt) -> PandocIO Opt -> IO Opt
forall a b. (a -> b) -> a -> b
$ do
                     let defsState :: DefaultsState
defsState = DefaultsState :: Maybe String -> [[String]] -> DefaultsState
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
                  )
                  String
"FILE")
                String
""

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"file-scope"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"sandbox"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optSandbox :: Bool
optSandbox = Bool
True }))
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"s" [String
"standalone"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"template"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                     Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"V" [String
"variable"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"wrap"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    case String
arg of
                      String
"auto" -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optWrap :: WrapOption
optWrap = WrapOption
WrapAuto }
                      String
"none" -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optWrap :: WrapOption
optWrap = WrapOption
WrapNone }
                      String
"preserve" -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optWrap :: WrapOption
optWrap = WrapOption
WrapPreserve }
                      String
_      -> PandocError -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"ascii"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optAscii :: Bool
optAscii = Bool
True }))
                 String
""  -- "Prefer ASCII output"

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"toc", String
"table-of-contents"]
                ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                 (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"toc-depth"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optTOCDepth :: Int
optTOCDepth = Int
t }
                           Maybe Int
_ -> PandocError -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"N" [String
"number-sections"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optNumberSections :: Bool
optNumberSections = Bool
True }))
                 String
"" -- "Number sections"

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"number-offset"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optNumberOffset :: [Int]
optNumberOffset = [Int]
ns,
                                                   optNumberSections :: Bool
optNumberSections = Bool
True }
                           Maybe [Int]
_      -> PandocError -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"top-level-division"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                      case String
arg of
                        String
"section" -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optTopLevelDivision :: TopLevelDivision
optTopLevelDivision =
                                        TopLevelDivision
TopLevelSection }
                        String
"chapter" -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optTopLevelDivision :: TopLevelDivision
optTopLevelDivision =
                                        TopLevelDivision
TopLevelChapter }
                        String
"part"    -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optTopLevelDivision :: TopLevelDivision
optTopLevelDivision =
                                        TopLevelDivision
TopLevelPart }
                        String
"default" -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optTopLevelDivision :: TopLevelDivision
optTopLevelDivision =
                                        TopLevelDivision
TopLevelDefault }
                        String
_ -> PandocError -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"extract-media"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"resource-path"]
                ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"H" [String
"include-in-header"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"B" [String
"include-before-body"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"A" [String
"include-after-body"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"no-highlight"]
                ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                 (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"highlight-style"]
                ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                 (\String
arg Opt
opt ->
                     Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"syntax-definition"]
                ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                 (\String
arg Opt
opt ->
                   Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"dpi"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optDpi :: Int
optDpi = Int
t }
                         Maybe Int
_              -> PandocError -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"eol"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optEol :: LineEnding
optEol = LineEnding
CRLF }
                      String
"lf"     -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optEol :: LineEnding
optEol = LineEnding
LF }
                      String
"native" -> Opt -> IO Opt
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 -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"columns"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optColumns :: Int
optColumns = Int
t }
                           Maybe Int
_              -> PandocError -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"p" [String
"preserve-tabs"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"tab-stop"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optTabStop :: Int
optTabStop = Int
t }
                           Maybe Int
_              -> PandocError -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"pdf-engine"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
pdfEngines
                        then Opt -> IO Opt
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 -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"pdf-engine-opt"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"reference-doc"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"self-contained"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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"

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"request-header"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"no-check-certificate"]
                ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                 (\Opt
opt -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optNoCheckCertificate :: Bool
optNoCheckCertificate = Bool
True }))
                String
"" -- "Disable certificate validation"

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"abbreviations"]
                ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                 (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"indented-code-classes"]
                  ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                   (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"default-image-extension"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"F" [String
"filter"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"L" [String
"lua-filter"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"shift-heading-level-by"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optShiftHeadingLevelBy :: Int
optShiftHeadingLevelBy = Int
t }
                           Maybe Int
_              -> PandocError -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"base-header-level"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                      String -> String -> 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 -> IO Opt
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 -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"strip-empty-paragraphs"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> do
                      String -> String -> IO ()
deprecatedOption String
"--strip-empty-paragraphs"
                        String
"Use +empty_paragraphs extension."
                      Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optStripEmptyParagraphs :: Bool
optStripEmptyParagraphs = Bool
True }))
                 String
"" -- "Strip empty paragraphs"

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"track-changes"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     TrackChanges
action <- case String
arg of
                            String
"accept" -> TrackChanges -> IO TrackChanges
forall (m :: * -> *) a. Monad m => a -> m a
return TrackChanges
AcceptChanges
                            String
"reject" -> TrackChanges -> IO TrackChanges
forall (m :: * -> *) a. Monad m => a -> m a
return TrackChanges
RejectChanges
                            String
"all"    -> TrackChanges -> IO TrackChanges
forall (m :: * -> *) a. Monad m => a -> m a
return TrackChanges
AllChanges
                            String
_        -> PandocError -> IO TrackChanges
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO TrackChanges) -> PandocError -> 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 -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"strip-comments"]
                ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                 (\Opt
opt -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optStripComments :: Bool
optStripComments = Bool
True }))
               String
"" -- "Strip HTML comments"

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"reference-links"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"reference-location"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     ReferenceLocation
action <- case String
arg of
                            String
"block"    -> ReferenceLocation -> IO ReferenceLocation
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceLocation
EndOfBlock
                            String
"section"  -> ReferenceLocation -> IO ReferenceLocation
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceLocation
EndOfSection
                            String
"document" -> ReferenceLocation -> IO ReferenceLocation
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceLocation
EndOfDocument
                            String
_        -> PandocError -> IO ReferenceLocation
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO ReferenceLocation)
-> PandocError -> 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 -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"atx-headers"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> do
                    String -> String -> IO ()
deprecatedOption String
"--atx-headers"
                      String
"Use --markdown-headings=atx instead."
                    Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optSetextHeaders :: Bool
optSetextHeaders = Bool
False } ))
                 String
"" -- "Use atx-style headers for markdown"

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"markdown-headings"]
                  ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                    (\String
arg Opt
opt -> do
                      Bool
headingFormat <- case String
arg of
                        String
"setext" -> Bool -> IO Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
                        String
"atx" -> Bool -> IO Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False
                        String
_ -> PandocError -> IO Bool
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Bool) -> PandocError -> 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 -> IO Opt
forall (f :: * -> *) a. Applicative f => a -> f a
pure Opt
opt { optSetextHeaders :: Bool
optSetextHeaders = Bool
headingFormat }
                    )
                  String
"setext|atx")
                  String
""

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"listings"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"i" [String
"incremental"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"slide-level"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
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 -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"section-divs"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"html-q-tags"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt ->
                     Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"email-obfuscation"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     ObfuscationMethod
method <- case String
arg of
                            String
"references" -> ObfuscationMethod -> IO ObfuscationMethod
forall (m :: * -> *) a. Monad m => a -> m a
return ObfuscationMethod
ReferenceObfuscation
                            String
"javascript" -> ObfuscationMethod -> IO ObfuscationMethod
forall (m :: * -> *) a. Monad m => a -> m a
return ObfuscationMethod
JavascriptObfuscation
                            String
"none"       -> ObfuscationMethod -> IO ObfuscationMethod
forall (m :: * -> *) a. Monad m => a -> m a
return ObfuscationMethod
NoObfuscation
                            String
_            -> PandocError -> IO ObfuscationMethod
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO ObfuscationMethod)
-> PandocError -> 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 -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"id-prefix"]
                  ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                   (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"T" [String
"title-prefix"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"c" [String
"css"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"epub-subdirectory"]
             ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                     Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"epub-cover-image"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                     Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"epub-metadata"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"epub-embed-font"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                     Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"epub-chapter-level"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> 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 -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optEpubChapterLevel :: Int
optEpubChapterLevel = Int
t }
                           Maybe Int
_      -> PandocError -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> IO Opt
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocOptionError
                                    Text
"chapter level must be a number between 1 and 6")
                 String
"NUMBER")
                 String
"" -- "Header level at which to split chapters in EPUB"

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"ipynb-output"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                    case String
arg of
                      String
"all" -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optIpynbOutput :: IpynbOutput
optIpynbOutput = IpynbOutput
IpynbOutputAll }
                      String
"best" -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optIpynbOutput :: IpynbOutput
optIpynbOutput = IpynbOutput
IpynbOutputBest }
                      String
"none" -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optIpynbOutput :: IpynbOutput
optIpynbOutput = IpynbOutput
IpynbOutputNone }
                      String
_ -> PandocError -> IO Opt
forall e a. Exception e => e -> IO a
E.throwIO (PandocError -> IO Opt) -> PandocError -> 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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"C" [String
"citeproc"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"bibliography"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"csl"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                     Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"citation-abbreviations"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt ->
                     Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"natbib"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"biblatex"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"mathml"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt ->
                      Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"webtex"]
                 ((Maybe String -> Opt -> IO Opt)
-> String -> ArgDescr (Opt -> 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 -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"mathjax"]
                 ((Maybe String -> Opt -> IO Opt)
-> String -> ArgDescr (Opt -> 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 -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"katex"]
                 ((Maybe String -> Opt -> IO Opt)
-> String -> ArgDescr (Opt -> IO Opt)
forall a. (Maybe String -> a) -> String -> ArgDescr a
OptArg
                  (\Maybe String
arg Opt
opt ->
                      Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"gladtex"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt ->
                      Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"trace"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"dump-args"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"ignore-args"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"verbose"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt { optVerbosity :: Verbosity
optVerbosity = Verbosity
INFO }))
                 String
"" -- "Verbose diagnostic output."

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

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"fail-if-warnings"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"log"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> Opt -> IO Opt
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 -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"bash-completion"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
_ -> 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 -> IO Opt) -> [String])
-> [OptDescr (Opt -> IO Opt)] -> [String]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap OptDescr (Opt -> IO Opt) -> [String]
forall a. OptDescr a -> [String]
optnames [OptDescr (Opt -> 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)
                     IO Opt
forall a. IO a
exitSuccess ))
                 String
"" -- "Print bash completion script"

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"list-input-formats"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
_ -> do
                     (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
                     IO Opt
forall a. IO a
exitSuccess ))
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"list-output-formats"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
_ -> do
                     (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
                     IO Opt
forall a. IO a
exitSuccess ))
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"list-extensions"]
                 ((Maybe String -> Opt -> IO Opt)
-> String -> ArgDescr (Opt -> IO Opt)
forall a. (Maybe String -> a) -> String -> ArgDescr a
OptArg
                  (\Maybe String
arg Opt
_ -> do
                     let extList :: [Extension]
                         extList :: [Extension]
extList = [Extension
forall a. Bounded a => a
minBound..Extension
forall a. Bounded a => a
maxBound]
                     let allExts :: Extensions
allExts =
                           case Maybe String
arg of
                             Maybe String
Nothing  -> [Extension] -> Extensions
extensionsFromList [Extension]
extList
                             Just String
fmt -> Text -> Extensions
getAllExtensions (Text -> Extensions) -> Text -> Extensions
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
fmt
                     let defExts :: Extensions
defExts =
                           case Maybe String
arg of
                             Maybe String
Nothing   -> Text -> Extensions
getDefaultExtensions
                                           Text
"markdown"
                             Just String
fmt  -> Text -> Extensions
getDefaultExtensions (Text -> Extensions) -> Text -> Extensions
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
fmt
                     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)
                       [Extension
ex | Extension
ex <- [Extension]
extList, Extension -> Extensions -> Bool
extensionEnabled Extension
ex Extensions
allExts]
                     IO Opt
forall a. IO a
exitSuccess )
                  String
"FORMAT")
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"list-highlight-languages"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
_ -> 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)
                     IO Opt
forall a. IO a
exitSuccess ))
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"list-highlight-styles"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
_ -> 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
                     IO Opt
forall a. IO a
exitSuccess ))
                 String
""

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"D" [String
"print-default-template"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     let write :: Text -> IO ()
write = case Opt -> Maybe String
optOutputFile Opt
opt of
                                        Just String
f  -> String -> Text -> IO ()
UTF8.writeFile String
f
                                        Maybe String
Nothing -> Handle -> Text -> IO ()
UTF8.hPutStr Handle
stdout
                     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
$ do
                                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 (String -> Text
T.pack String
arg)
                     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]
++ String
arg)
                            | Bool
otherwise -> Text -> IO ()
write Text
t
                          Left PandocError
e  -> PandocError -> IO ()
forall e a. Exception e => e -> IO a
E.throwIO PandocError
e
                     IO Opt
forall a. IO a
exitSuccess)
                  String
"FORMAT")
                 String
"" -- "Print default template for FORMAT"

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"print-default-data-file"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> do
                     let write :: ByteString -> IO ()
write = case Opt -> Maybe String
optOutputFile Opt
opt of
                                        Just String
f  -> String -> ByteString -> IO ()
BS.writeFile String
f
                                        Maybe String
Nothing -> Handle -> ByteString -> IO ()
BS.hPutStr Handle
stdout
                     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 String
arg PandocIO ByteString -> (ByteString -> PandocIO ()) -> PandocIO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IO () -> PandocIO ()
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
                     IO Opt
forall a. IO a
exitSuccess)
                  String
"FILE")
                  String
"" -- "Print default data file"

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"" [String
"print-highlight-style"]
                 ((String -> Opt -> IO Opt) -> String -> ArgDescr (Opt -> IO Opt)
forall a. (String -> a) -> String -> ArgDescr a
ReqArg
                  (\String
arg Opt
opt -> 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 -> ByteString -> IO ())
-> Maybe String -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ Opt -> Maybe String
optOutputFile Opt
opt
                     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
lookupHighlightStyle String
arg
                     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
                     IO Opt
forall a. IO a
exitSuccess)
                  String
"STYLE|FILE")
                 String
"" -- "Print default template for FORMAT"


    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"v" [String
"version"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
_ -> 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
pandocVersion 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)
                     IO Opt
forall a. IO a
exitSuccess ))
                 String
"" -- "Print version"

    , String
-> [String]
-> ArgDescr (Opt -> IO Opt)
-> String
-> OptDescr (Opt -> IO Opt)
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"h" [String
"help"]
                 ((Opt -> IO Opt) -> ArgDescr (Opt -> IO Opt)
forall a. a -> ArgDescr a
NoArg
                  (\Opt
_ -> 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 -> IO Opt)] -> String
usageMessage String
prg [OptDescr (Opt -> IO Opt)]
options)
                     IO Opt
forall a. IO a
exitSuccess ))
                 String
"" -- "Show help"
    ]

getDataFileNames :: IO [FilePath]
getDataFileNames :: IO [String]
getDataFileNames = do
#ifdef EMBED_DATA_FILES
  let allDataFiles = map fst dataFiles
#else
  [String]
allDataFiles <- (String -> Bool) -> [String] -> [String]
forall a. (a -> Bool) -> [a] -> [a]
filter (\String
x -> String
x String -> String -> Bool
forall a. Eq a => a -> a -> Bool
/= String
"." Bool -> Bool -> Bool
&& String
x String -> String -> Bool
forall a. Eq a => a -> a -> Bool
/= String
"..") ([String] -> [String]) -> IO [String] -> IO [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                      (IO String
getDataDir IO String -> (String -> IO [String]) -> IO [String]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> IO [String]
getDirectoryContents)
#endif
  [String] -> IO [String]
forall (m :: * -> *) a. Monad m => a -> m a
return ([String] -> IO [String]) -> [String] -> IO [String]
forall a b. (a -> b) -> a -> b
$ String
"reference.docx" String -> [String] -> [String]
forall a. a -> [a] -> [a]
: String
"reference.odt" String -> [String] -> [String]
forall a. a -> [a] -> [a]
: String
"reference.pptx" String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
allDataFiles

-- Returns usage message
usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
usageMessage String
programName = String -> [OptDescr (Opt -> 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-2021 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 (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 -> Text -> Bool
`elemText` Text
":=")

lookupHighlightStyle :: PandocMonad m => String -> m Style
lookupHighlightStyle :: String -> m Style
lookupHighlightStyle String
s
  | String -> String
takeExtension String
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
".theme" = -- attempt to load KDE theme
    do ByteString
contents <- String -> m ByteString
forall (m :: * -> *). PandocMonad m => String -> m ByteString
readFileLazy String
s
       case ByteString -> Either String Style
parseTheme ByteString
contents of
            Left String
_    -> PandocError -> m Style
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (PandocError -> m Style) -> PandocError -> m Style
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
"Could not read highlighting theme " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s
            Right Style
sty -> Style -> m Style
forall (m :: * -> *) a. Monad m => a -> m a
return Style
sty
  | Bool
otherwise =
  case Text -> [(Text, Style)] -> Maybe Style
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup (Text -> Text
T.toLower (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
s) [(Text, Style)]
highlightingStyles of
       Just Style
sty -> Style -> m Style
forall (m :: * -> *) a. Monad m => a -> m a
return Style
sty
       Maybe Style
Nothing  -> PandocError -> m Style
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (PandocError -> m Style) -> PandocError -> m Style
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
"Unknown highlight-style " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s

deprecatedOption :: String -> String -> IO ()
deprecatedOption :: String -> String -> IO ()
deprecatedOption String
o String
msg =
  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)) IO (Either PandocError ())
-> (Either PandocError () -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
    \case
       Right () -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
       Left PandocError
e   -> PandocError -> IO ()
forall e a. Exception e => e -> IO a
E.throwIO PandocError
e

-- | Set text value in text context.
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
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
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
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
#if MIN_VERSION_base(4,12,0)
normalizePath fp =
  if "\\\\" `isPrefixOf` fp && not ("\\\\?\\" `isPrefixOf` fp)
    then "\\\\?\\UNC\\" ++ drop 2 fp
    else fp
#else
normalizePath = id
#endif
#else
normalizePath :: String -> String
normalizePath = String -> String
forall a. a -> a
id
#endif