{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE CPP                 #-}
{-# LANGUAGE DeriveGeneric       #-}
{-# LANGUAGE TemplateHaskell     #-}
{-# LANGUAGE FlexibleInstances   #-}
{-# LANGUAGE FlexibleContexts    #-}
{- |
   Module      : Text.Pandoc.App.Opt
   Copyright   : Copyright (C) 2006-2021 John MacFarlane
   License     : GNU GPL, version 2 or above

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

Options for pandoc when used as an app.
-}
module Text.Pandoc.App.Opt (
            Opt(..)
          , LineEnding (..)
          , IpynbOutput (..)
          , DefaultsState (..)
          , defaultOpts
          , applyDefaults
          , fullDefaultsPath
          ) where
import Control.Monad.Except (MonadIO, liftIO, throwError, (>=>), foldM)
import Control.Monad.State.Strict (StateT, modify, gets)
import System.FilePath ( addExtension, (</>), takeExtension, takeDirectory )
import System.Directory ( canonicalizePath )
import Data.Char (isLower, toLower)
import Data.Maybe (fromMaybe)
import GHC.Generics hiding (Meta)
import Text.Pandoc.Filter (Filter (..))
import Text.Pandoc.Logging (Verbosity (WARNING), LogMessage(..))
import Text.Pandoc.Options (TopLevelDivision (TopLevelDefault),
                            TrackChanges (AcceptChanges),
                            WrapOption (WrapAuto), HTMLMathMethod (PlainMath),
                            ReferenceLocation (EndOfDocument),
                            ObfuscationMethod (NoObfuscation),
                            CiteMethod (Citeproc))
import Text.Pandoc.Class (readFileLazy, fileExists, setVerbosity, report,
                          PandocMonad(lookupEnv), getUserDataDir)
import Text.Pandoc.Error (PandocError (PandocParseError, PandocSomeError))
import Text.Pandoc.Shared (camelCaseStrToHyphenated, defaultUserDataDir,
                           findM, ordNub)
import qualified Text.Pandoc.Parsing as P
import Text.Pandoc.Readers.Metadata (yamlMap)
import Text.Pandoc.Class.PandocPure
import Text.DocTemplates (Context(..))
import Data.Text (Text, unpack)
import Data.Default (def)
import qualified Data.Text as T
import qualified Data.Map as M
import Text.Pandoc.Definition (Meta(..), MetaValue(..))
import Data.Aeson (defaultOptions, Options(..))
import Data.Aeson.TH (deriveJSON)
import Control.Applicative ((<|>))
import Data.YAML

-- | The type of line-endings to be used when writing plain-text.
data LineEnding = LF | CRLF | Native deriving (Int -> LineEnding -> ShowS
[LineEnding] -> ShowS
LineEnding -> String
(Int -> LineEnding -> ShowS)
-> (LineEnding -> String)
-> ([LineEnding] -> ShowS)
-> Show LineEnding
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LineEnding] -> ShowS
$cshowList :: [LineEnding] -> ShowS
show :: LineEnding -> String
$cshow :: LineEnding -> String
showsPrec :: Int -> LineEnding -> ShowS
$cshowsPrec :: Int -> LineEnding -> ShowS
Show, (forall x. LineEnding -> Rep LineEnding x)
-> (forall x. Rep LineEnding x -> LineEnding) -> Generic LineEnding
forall x. Rep LineEnding x -> LineEnding
forall x. LineEnding -> Rep LineEnding x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LineEnding x -> LineEnding
$cfrom :: forall x. LineEnding -> Rep LineEnding x
Generic)

instance FromYAML LineEnding where
  parseYAML :: Node Pos -> Parser LineEnding
parseYAML = String
-> (Text -> Parser LineEnding) -> Node Pos -> Parser LineEnding
forall a. String -> (Text -> Parser a) -> Node Pos -> Parser a
withStr String
"LineEnding" ((Text -> Parser LineEnding) -> Node Pos -> Parser LineEnding)
-> (Text -> Parser LineEnding) -> Node Pos -> Parser LineEnding
forall a b. (a -> b) -> a -> b
$ \Text
t ->
    case Text -> Text
T.toLower Text
t of
      Text
"lf"     -> LineEnding -> Parser LineEnding
forall (m :: * -> *) a. Monad m => a -> m a
return LineEnding
LF
      Text
"crlf"   -> LineEnding -> Parser LineEnding
forall (m :: * -> *) a. Monad m => a -> m a
return LineEnding
CRLF
      Text
"native" -> LineEnding -> Parser LineEnding
forall (m :: * -> *) a. Monad m => a -> m a
return LineEnding
Native
      Text
_        -> String -> Parser LineEnding
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser LineEnding) -> String -> Parser LineEnding
forall a b. (a -> b) -> a -> b
$ String
"Unknown line ending type " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
t

-- | How to handle output blocks in ipynb.
data IpynbOutput =
    IpynbOutputAll
  | IpynbOutputNone
  | IpynbOutputBest
  deriving (Int -> IpynbOutput -> ShowS
[IpynbOutput] -> ShowS
IpynbOutput -> String
(Int -> IpynbOutput -> ShowS)
-> (IpynbOutput -> String)
-> ([IpynbOutput] -> ShowS)
-> Show IpynbOutput
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IpynbOutput] -> ShowS
$cshowList :: [IpynbOutput] -> ShowS
show :: IpynbOutput -> String
$cshow :: IpynbOutput -> String
showsPrec :: Int -> IpynbOutput -> ShowS
$cshowsPrec :: Int -> IpynbOutput -> ShowS
Show, (forall x. IpynbOutput -> Rep IpynbOutput x)
-> (forall x. Rep IpynbOutput x -> IpynbOutput)
-> Generic IpynbOutput
forall x. Rep IpynbOutput x -> IpynbOutput
forall x. IpynbOutput -> Rep IpynbOutput x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IpynbOutput x -> IpynbOutput
$cfrom :: forall x. IpynbOutput -> Rep IpynbOutput x
Generic)

instance FromYAML IpynbOutput where
  parseYAML :: Node Pos -> Parser IpynbOutput
parseYAML = String
-> (Text -> Parser IpynbOutput) -> Node Pos -> Parser IpynbOutput
forall a. String -> (Text -> Parser a) -> Node Pos -> Parser a
withStr String
"LineEnding" ((Text -> Parser IpynbOutput) -> Node Pos -> Parser IpynbOutput)
-> (Text -> Parser IpynbOutput) -> Node Pos -> Parser IpynbOutput
forall a b. (a -> b) -> a -> b
$ \Text
t ->
    case Text
t of
      Text
"none"  -> IpynbOutput -> Parser IpynbOutput
forall (m :: * -> *) a. Monad m => a -> m a
return IpynbOutput
IpynbOutputNone
      Text
"all"   -> IpynbOutput -> Parser IpynbOutput
forall (m :: * -> *) a. Monad m => a -> m a
return IpynbOutput
IpynbOutputAll
      Text
"best"  -> IpynbOutput -> Parser IpynbOutput
forall (m :: * -> *) a. Monad m => a -> m a
return IpynbOutput
IpynbOutputBest
      Text
_       -> String -> Parser IpynbOutput
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser IpynbOutput) -> String -> Parser IpynbOutput
forall a b. (a -> b) -> a -> b
$ String
"Unknown ipynb output type " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
t

-- | Data structure for command line options.
data Opt = Opt
    { Opt -> Int
optTabStop               :: Int     -- ^ Number of spaces per tab
    , Opt -> Bool
optPreserveTabs          :: Bool    -- ^ Preserve tabs instead of converting to spaces
    , Opt -> Bool
optStandalone            :: Bool    -- ^ Include header, footer
    , Opt -> Maybe Text
optFrom                  :: Maybe Text  -- ^ Reader format
    , Opt -> Maybe Text
optTo                    :: Maybe Text  -- ^ Writer format
    , Opt -> Bool
optTableOfContents       :: Bool    -- ^ Include table of contents
    , Opt -> Int
optShiftHeadingLevelBy   :: Int     -- ^ Shift heading level by
    , Opt -> Maybe String
optTemplate              :: Maybe FilePath  -- ^ Custom template
    , Opt -> Context Text
optVariables             :: Context Text    -- ^ Template variables to set
    , Opt -> Meta
optMetadata              :: Meta -- ^ Metadata fields to set
    , Opt -> [String]
optMetadataFiles         :: [FilePath]  -- ^ Name of YAML metadata files
    , Opt -> Maybe String
optOutputFile            :: Maybe FilePath  -- ^ Name of output file
    , Opt -> Maybe [String]
optInputFiles            :: Maybe [FilePath] -- ^ Names of input files
    , Opt -> Bool
optNumberSections        :: Bool    -- ^ Number sections in LaTeX
    , Opt -> [Int]
optNumberOffset          :: [Int]   -- ^ Starting number for sections
    , Opt -> Bool
optSectionDivs           :: Bool    -- ^ Put sections in div tags in HTML
    , Opt -> Bool
optIncremental           :: Bool    -- ^ Use incremental lists in Slidy/Slideous/S5
    , Opt -> Bool
optSelfContained         :: Bool    -- ^ Make HTML accessible offline
    , Opt -> Bool
optHtmlQTags             :: Bool    -- ^ Use <q> tags in HTML
    , Opt -> Maybe Text
optHighlightStyle        :: Maybe Text -- ^ Style to use for highlighted code
    , Opt -> [String]
optSyntaxDefinitions     :: [FilePath]  -- ^ xml syntax defs to load
    , Opt -> TopLevelDivision
optTopLevelDivision      :: TopLevelDivision -- ^ Type of the top-level divisions
    , Opt -> HTMLMathMethod
optHTMLMathMethod        :: HTMLMathMethod -- ^ Method to print HTML math
    , Opt -> Maybe String
optAbbreviations         :: Maybe FilePath -- ^ Path to abbrevs file
    , Opt -> Maybe String
optReferenceDoc          :: Maybe FilePath -- ^ Path of reference doc
    , Opt -> String
optEpubSubdirectory      :: String -- ^ EPUB subdir in OCF container
    , Opt -> Maybe String
optEpubMetadata          :: Maybe FilePath   -- ^ EPUB metadata
    , Opt -> [String]
optEpubFonts             :: [FilePath] -- ^ EPUB fonts to embed
    , Opt -> Int
optEpubChapterLevel      :: Int     -- ^ Header level at which to split chapters
    , Opt -> Maybe String
optEpubCoverImage        :: Maybe FilePath -- ^ Cover image for epub
    , Opt -> Int
optTOCDepth              :: Int     -- ^ Number of levels to include in TOC
    , Opt -> Bool
optDumpArgs              :: Bool    -- ^ Output command-line arguments
    , Opt -> Bool
optIgnoreArgs            :: Bool    -- ^ Ignore command-line arguments
    , Opt -> Verbosity
optVerbosity             :: Verbosity  -- ^ Verbosity of diagnostic output
    , Opt -> Bool
optTrace                 :: Bool  -- ^ Enable tracing
    , Opt -> Maybe String
optLogFile               :: Maybe FilePath -- ^ File to write JSON log output
    , Opt -> Bool
optFailIfWarnings        :: Bool    -- ^ Fail on warnings
    , Opt -> Bool
optReferenceLinks        :: Bool    -- ^ Use reference links in writing markdown, rst
    , Opt -> ReferenceLocation
optReferenceLocation     :: ReferenceLocation -- ^ location for footnotes and link references in markdown output
    , Opt -> Int
optDpi                   :: Int     -- ^ Dpi
    , Opt -> WrapOption
optWrap                  :: WrapOption  -- ^ Options for wrapping text
    , Opt -> Int
optColumns               :: Int     -- ^ Line length in characters
    , Opt -> [Filter]
optFilters               :: [Filter] -- ^ Filters to apply
    , Opt -> ObfuscationMethod
optEmailObfuscation      :: ObfuscationMethod
    , Opt -> Text
optIdentifierPrefix      :: Text
    , Opt -> Bool
optStripEmptyParagraphs  :: Bool -- ^ Strip empty paragraphs
    , Opt -> [Text]
optIndentedCodeClasses   :: [Text] -- ^ Default classes for indented code blocks
    , Opt -> Maybe String
optDataDir               :: Maybe FilePath
    , Opt -> CiteMethod
optCiteMethod            :: CiteMethod -- ^ Method to output cites
    , Opt -> Bool
optListings              :: Bool       -- ^ Use listings package for code blocks
    , Opt -> Maybe String
optPdfEngine             :: Maybe String -- ^ Program to use for latex/html -> pdf
    , Opt -> [String]
optPdfEngineOpts         :: [String]   -- ^ Flags to pass to the engine
    , Opt -> Maybe Int
optSlideLevel            :: Maybe Int  -- ^ Header level that creates slides
    , Opt -> Bool
optSetextHeaders         :: Bool       -- ^ Use atx headers for markdown level 1-2
    , Opt -> Bool
optAscii                 :: Bool       -- ^ Prefer ascii output
    , Opt -> Text
optDefaultImageExtension :: Text       -- ^ Default image extension
    , Opt -> Maybe String
optExtractMedia          :: Maybe FilePath -- ^ Path to extract embedded media
    , Opt -> TrackChanges
optTrackChanges          :: TrackChanges -- ^ Accept or reject MS Word track-changes.
    , Opt -> Bool
optFileScope             :: Bool         -- ^ Parse input files before combining
    , Opt -> Maybe Text
optTitlePrefix           :: Maybe Text     -- ^ Prefix for title
    , Opt -> [String]
optCss                   :: [FilePath]       -- ^ CSS files to link to
    , Opt -> IpynbOutput
optIpynbOutput           :: IpynbOutput      -- ^ How to treat ipynb output blocks
    , Opt -> [String]
optIncludeBeforeBody     :: [FilePath]       -- ^ Files to include before
    , Opt -> [String]
optIncludeAfterBody      :: [FilePath]       -- ^ Files to include after body
    , Opt -> [String]
optIncludeInHeader       :: [FilePath]       -- ^ Files to include in header
    , Opt -> [String]
optResourcePath          :: [FilePath] -- ^ Path to search for images etc
    , Opt -> [(Text, Text)]
optRequestHeaders        :: [(Text, Text)] -- ^ Headers for HTTP requests
    , Opt -> Bool
optNoCheckCertificate    :: Bool       -- ^ Disable certificate validation
    , Opt -> LineEnding
optEol                   :: LineEnding -- ^ Style of line-endings to use
    , Opt -> Bool
optStripComments         :: Bool       -- ^ Skip HTML comments
    , Opt -> Maybe String
optCSL                   :: Maybe FilePath -- ^ CSL stylesheet
    , Opt -> [String]
optBibliography          :: [FilePath]  -- ^ Bibliography files
    , Opt -> Maybe String
optCitationAbbreviations :: Maybe FilePath -- ^ Citation abbreviations
    } deriving ((forall x. Opt -> Rep Opt x)
-> (forall x. Rep Opt x -> Opt) -> Generic Opt
forall x. Rep Opt x -> Opt
forall x. Opt -> Rep Opt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Opt x -> Opt
$cfrom :: forall x. Opt -> Rep Opt x
Generic, Int -> Opt -> ShowS
[Opt] -> ShowS
Opt -> String
(Int -> Opt -> ShowS)
-> (Opt -> String) -> ([Opt] -> ShowS) -> Show Opt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Opt] -> ShowS
$cshowList :: [Opt] -> ShowS
show :: Opt -> String
$cshow :: Opt -> String
showsPrec :: Int -> Opt -> ShowS
$cshowsPrec :: Int -> Opt -> ShowS
Show)

instance FromYAML (Opt -> Opt) where
  parseYAML :: Node Pos -> Parser (Opt -> Opt)
parseYAML (Mapping Pos
_ Tag
_ Mapping Pos
m) = ((Node Pos, Node Pos) -> Parser (Opt -> Opt))
-> [(Node Pos, Node Pos)] -> Parser (Opt -> Opt)
forall (m :: * -> *) a b.
Monad m =>
(a -> m (b -> b)) -> [a] -> m (b -> b)
chain (Node Pos, Node Pos) -> Parser (Opt -> Opt)
doOpt (Mapping Pos -> [(Node Pos, Node Pos)]
forall k a. Map k a -> [(k, a)]
M.toList Mapping Pos
m)
  parseYAML Node Pos
n = Node Pos -> String -> Parser (Opt -> Opt)
forall a. Node Pos -> String -> Parser a
failAtNode Node Pos
n String
"Expected a mapping"

data DefaultsState = DefaultsState
    {
      DefaultsState -> Maybe String
curDefaults      :: Maybe FilePath -- currently parsed file
    , DefaultsState -> [[String]]
inheritanceGraph :: [[FilePath]]   -- defaults file inheritance graph
    } deriving (Int -> DefaultsState -> ShowS
[DefaultsState] -> ShowS
DefaultsState -> String
(Int -> DefaultsState -> ShowS)
-> (DefaultsState -> String)
-> ([DefaultsState] -> ShowS)
-> Show DefaultsState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DefaultsState] -> ShowS
$cshowList :: [DefaultsState] -> ShowS
show :: DefaultsState -> String
$cshow :: DefaultsState -> String
showsPrec :: Int -> DefaultsState -> ShowS
$cshowsPrec :: Int -> DefaultsState -> ShowS
Show)

instance (PandocMonad m, MonadIO m)
      => FromYAML (Opt -> StateT DefaultsState m Opt) where
  parseYAML :: Node Pos -> Parser (Opt -> StateT DefaultsState m Opt)
parseYAML (Mapping Pos
_ Tag
_ Mapping Pos
m) = do
    let opts :: Map Text (Node Pos)
opts = (Node Pos -> Text) -> Mapping Pos -> Map Text (Node Pos)
forall k2 k1 a. Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a
M.mapKeys Node Pos -> Text
forall loc. Node loc -> Text
toText Mapping Pos
m
    Maybe String
dataDir <- case Text -> Map Text (Node Pos) -> Maybe (Node Pos)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
"data-dir" Map Text (Node Pos)
opts of
      Maybe (Node Pos)
Nothing -> Maybe String -> Parser (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
forall a. Maybe a
Nothing
      Just Node Pos
v -> String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String)
-> (Text -> String) -> Text -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
unpack (Text -> Maybe String) -> Parser Text -> Parser (Maybe String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v
    Opt -> StateT DefaultsState m Opt
f <- [(Node Pos, Node Pos)]
-> Parser (Opt -> StateT DefaultsState m Opt)
forall (m :: * -> *).
Monad m =>
[(Node Pos, Node Pos)]
-> Parser (Opt -> StateT DefaultsState m Opt)
parseOptions (Mapping Pos -> [(Node Pos, Node Pos)]
forall k a. Map k a -> [(k, a)]
M.toList Mapping Pos
m)
    case Text -> Map Text (Node Pos) -> Maybe (Node Pos)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
"defaults" Map Text (Node Pos)
opts of
      Just Node Pos
v -> do
        Opt -> StateT DefaultsState m Opt
g <- Node Pos
-> Maybe String -> Parser (Opt -> StateT DefaultsState m Opt)
forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
Node Pos
-> Maybe String -> Parser (Opt -> StateT DefaultsState m Opt)
parseDefaults Node Pos
v Maybe String
dataDir
        (Opt -> StateT DefaultsState m Opt)
-> Parser (Opt -> StateT DefaultsState m Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return  ((Opt -> StateT DefaultsState m Opt)
 -> Parser (Opt -> StateT DefaultsState m Opt))
-> (Opt -> StateT DefaultsState m Opt)
-> Parser (Opt -> StateT DefaultsState m Opt)
forall a b. (a -> b) -> a -> b
$ Opt -> StateT DefaultsState m Opt
g (Opt -> StateT DefaultsState m Opt)
-> (Opt -> StateT DefaultsState m Opt)
-> Opt
-> StateT DefaultsState m Opt
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Opt -> StateT DefaultsState m Opt
f (Opt -> StateT DefaultsState m Opt)
-> (Opt -> StateT DefaultsState m Opt)
-> Opt
-> StateT DefaultsState m Opt
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Opt -> StateT DefaultsState m Opt
forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
Opt -> StateT DefaultsState m Opt
resolveVarsInOpt
      Maybe (Node Pos)
Nothing -> (Opt -> StateT DefaultsState m Opt)
-> Parser (Opt -> StateT DefaultsState m Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Opt -> StateT DefaultsState m Opt)
 -> Parser (Opt -> StateT DefaultsState m Opt))
-> (Opt -> StateT DefaultsState m Opt)
-> Parser (Opt -> StateT DefaultsState m Opt)
forall a b. (a -> b) -> a -> b
$ Opt -> StateT DefaultsState m Opt
f (Opt -> StateT DefaultsState m Opt)
-> (Opt -> StateT DefaultsState m Opt)
-> Opt
-> StateT DefaultsState m Opt
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Opt -> StateT DefaultsState m Opt
forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
Opt -> StateT DefaultsState m Opt
resolveVarsInOpt
    where
      toText :: Node loc -> Text
toText (Scalar loc
_ (SStr Text
s)) = Text
s
      toText Node loc
_ = Text
""
  parseYAML Node Pos
n = Node Pos -> String -> Parser (Opt -> StateT DefaultsState m Opt)
forall a. Node Pos -> String -> Parser a
failAtNode Node Pos
n String
"Expected a mapping"

resolveVarsInOpt :: forall m. (PandocMonad m, MonadIO m)
                 => Opt -> StateT DefaultsState m Opt
resolveVarsInOpt :: Opt -> StateT DefaultsState m Opt
resolveVarsInOpt
    opt :: Opt
opt@Opt
    { optTemplate :: Opt -> Maybe String
optTemplate              = Maybe String
oTemplate
    , optMetadataFiles :: Opt -> [String]
optMetadataFiles         = [String]
oMetadataFiles
    , optOutputFile :: Opt -> Maybe String
optOutputFile            = Maybe String
oOutputFile
    , optInputFiles :: Opt -> Maybe [String]
optInputFiles            = Maybe [String]
oInputFiles
    , optSyntaxDefinitions :: Opt -> [String]
optSyntaxDefinitions     = [String]
oSyntaxDefinitions
    , optAbbreviations :: Opt -> Maybe String
optAbbreviations         = Maybe String
oAbbreviations
    , optReferenceDoc :: Opt -> Maybe String
optReferenceDoc          = Maybe String
oReferenceDoc
    , optEpubMetadata :: Opt -> Maybe String
optEpubMetadata          = Maybe String
oEpubMetadata
    , optEpubFonts :: Opt -> [String]
optEpubFonts             = [String]
oEpubFonts
    , optEpubCoverImage :: Opt -> Maybe String
optEpubCoverImage        = Maybe String
oEpubCoverImage
    , optLogFile :: Opt -> Maybe String
optLogFile               = Maybe String
oLogFile
    , optFilters :: Opt -> [Filter]
optFilters               = [Filter]
oFilters
    , optDataDir :: Opt -> Maybe String
optDataDir               = Maybe String
oDataDir
    , optExtractMedia :: Opt -> Maybe String
optExtractMedia          = Maybe String
oExtractMedia
    , optCss :: Opt -> [String]
optCss                   = [String]
oCss
    , optIncludeBeforeBody :: Opt -> [String]
optIncludeBeforeBody     = [String]
oIncludeBeforeBody
    , optIncludeAfterBody :: Opt -> [String]
optIncludeAfterBody      = [String]
oIncludeAfterBody
    , optIncludeInHeader :: Opt -> [String]
optIncludeInHeader       = [String]
oIncludeInHeader
    , optResourcePath :: Opt -> [String]
optResourcePath          = [String]
oResourcePath
    , optCSL :: Opt -> Maybe String
optCSL                   = Maybe String
oCSL
    , optBibliography :: Opt -> [String]
optBibliography          = [String]
oBibliography
    , optCitationAbbreviations :: Opt -> Maybe String
optCitationAbbreviations = Maybe String
oCitationAbbreviations
    }
  = do
      Maybe String
oTemplate' <- (String -> StateT DefaultsState m String)
-> Maybe String -> StateT DefaultsState m (Maybe String)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars Maybe String
oTemplate
      [String]
oMetadataFiles' <- (String -> StateT DefaultsState m String)
-> [String] -> StateT DefaultsState m [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars [String]
oMetadataFiles
      Maybe String
oOutputFile' <- (String -> StateT DefaultsState m String)
-> Maybe String -> StateT DefaultsState m (Maybe String)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars Maybe String
oOutputFile
      Maybe [String]
oInputFiles' <- ([String] -> StateT DefaultsState m [String])
-> Maybe [String] -> StateT DefaultsState m (Maybe [String])
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((String -> StateT DefaultsState m String)
-> [String] -> StateT DefaultsState m [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars) Maybe [String]
oInputFiles
      [String]
oSyntaxDefinitions' <- (String -> StateT DefaultsState m String)
-> [String] -> StateT DefaultsState m [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars [String]
oSyntaxDefinitions
      Maybe String
oAbbreviations' <- (String -> StateT DefaultsState m String)
-> Maybe String -> StateT DefaultsState m (Maybe String)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars Maybe String
oAbbreviations
      Maybe String
oReferenceDoc' <- (String -> StateT DefaultsState m String)
-> Maybe String -> StateT DefaultsState m (Maybe String)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars Maybe String
oReferenceDoc
      Maybe String
oEpubMetadata' <- (String -> StateT DefaultsState m String)
-> Maybe String -> StateT DefaultsState m (Maybe String)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars Maybe String
oEpubMetadata
      [String]
oEpubFonts' <- (String -> StateT DefaultsState m String)
-> [String] -> StateT DefaultsState m [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars [String]
oEpubFonts
      Maybe String
oEpubCoverImage' <- (String -> StateT DefaultsState m String)
-> Maybe String -> StateT DefaultsState m (Maybe String)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars Maybe String
oEpubCoverImage
      Maybe String
oLogFile' <- (String -> StateT DefaultsState m String)
-> Maybe String -> StateT DefaultsState m (Maybe String)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars Maybe String
oLogFile
      [Filter]
oFilters' <- (Filter -> StateT DefaultsState m Filter)
-> [Filter] -> StateT DefaultsState m [Filter]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Filter -> StateT DefaultsState m Filter
resolveVarsInFilter [Filter]
oFilters
      Maybe String
oDataDir' <- (String -> StateT DefaultsState m String)
-> Maybe String -> StateT DefaultsState m (Maybe String)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars Maybe String
oDataDir
      Maybe String
oExtractMedia' <- (String -> StateT DefaultsState m String)
-> Maybe String -> StateT DefaultsState m (Maybe String)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars Maybe String
oExtractMedia
      [String]
oCss' <- (String -> StateT DefaultsState m String)
-> [String] -> StateT DefaultsState m [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars [String]
oCss
      [String]
oIncludeBeforeBody' <- (String -> StateT DefaultsState m String)
-> [String] -> StateT DefaultsState m [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars [String]
oIncludeBeforeBody
      [String]
oIncludeAfterBody' <- (String -> StateT DefaultsState m String)
-> [String] -> StateT DefaultsState m [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars [String]
oIncludeAfterBody
      [String]
oIncludeInHeader' <- (String -> StateT DefaultsState m String)
-> [String] -> StateT DefaultsState m [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars [String]
oIncludeInHeader
      [String]
oResourcePath' <- (String -> StateT DefaultsState m String)
-> [String] -> StateT DefaultsState m [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars [String]
oResourcePath
      Maybe String
oCSL' <- (String -> StateT DefaultsState m String)
-> Maybe String -> StateT DefaultsState m (Maybe String)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars Maybe String
oCSL
      [String]
oBibliography' <- (String -> StateT DefaultsState m String)
-> [String] -> StateT DefaultsState m [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars [String]
oBibliography
      Maybe String
oCitationAbbreviations' <- (String -> StateT DefaultsState m String)
-> Maybe String -> StateT DefaultsState m (Maybe String)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars Maybe String
oCitationAbbreviations
      Opt -> StateT DefaultsState m Opt
forall (m :: * -> *) a. Monad m => a -> m a
return Opt
opt{ optTemplate :: Maybe String
optTemplate              = Maybe String
oTemplate'
                , optMetadataFiles :: [String]
optMetadataFiles         = [String]
oMetadataFiles'
                , optOutputFile :: Maybe String
optOutputFile            = Maybe String
oOutputFile'
                , optInputFiles :: Maybe [String]
optInputFiles            = Maybe [String]
oInputFiles'
                , optSyntaxDefinitions :: [String]
optSyntaxDefinitions     = [String]
oSyntaxDefinitions'
                , optAbbreviations :: Maybe String
optAbbreviations         = Maybe String
oAbbreviations'
                , optReferenceDoc :: Maybe String
optReferenceDoc          = Maybe String
oReferenceDoc'
                , optEpubMetadata :: Maybe String
optEpubMetadata          = Maybe String
oEpubMetadata'
                , optEpubFonts :: [String]
optEpubFonts             = [String]
oEpubFonts'
                , optEpubCoverImage :: Maybe String
optEpubCoverImage        = Maybe String
oEpubCoverImage'
                , optLogFile :: Maybe String
optLogFile               = Maybe String
oLogFile'
                , optFilters :: [Filter]
optFilters               = [Filter]
oFilters'
                , optDataDir :: Maybe String
optDataDir               = Maybe String
oDataDir'
                , optExtractMedia :: Maybe String
optExtractMedia          = Maybe String
oExtractMedia'
                , optCss :: [String]
optCss                   = [String]
oCss'
                , optIncludeBeforeBody :: [String]
optIncludeBeforeBody     = [String]
oIncludeBeforeBody'
                , optIncludeAfterBody :: [String]
optIncludeAfterBody      = [String]
oIncludeAfterBody'
                , optIncludeInHeader :: [String]
optIncludeInHeader       = [String]
oIncludeInHeader'
                , optResourcePath :: [String]
optResourcePath          = [String]
oResourcePath'
                , optCSL :: Maybe String
optCSL                   = Maybe String
oCSL'
                , optBibliography :: [String]
optBibliography          = [String]
oBibliography'
                , optCitationAbbreviations :: Maybe String
optCitationAbbreviations = Maybe String
oCitationAbbreviations'
                }

 where
  resolveVars :: FilePath -> StateT DefaultsState m FilePath
  resolveVars :: String -> StateT DefaultsState m String
resolveVars [] = String -> StateT DefaultsState m String
forall (m :: * -> *) a. Monad m => a -> m a
return []
  resolveVars (Char
'$':Char
'{':String
xs) =
    let (String
ys, String
zs) = (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'}') String
xs
     in if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
zs
           then String -> StateT DefaultsState m String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> StateT DefaultsState m String)
-> String -> StateT DefaultsState m String
forall a b. (a -> b) -> a -> b
$ Char
'$'Char -> ShowS
forall a. a -> [a] -> [a]
:Char
'{'Char -> ShowS
forall a. a -> [a] -> [a]
:String
xs
           else do
             String
val <- String -> StateT DefaultsState m String
lookupEnv' String
ys
             (String
val String -> ShowS
forall a. [a] -> [a] -> [a]
++) ShowS
-> StateT DefaultsState m String -> StateT DefaultsState m String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> StateT DefaultsState m String
resolveVars (Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
1 String
zs)
  resolveVars (Char
c:String
cs) = (Char
cChar -> ShowS
forall a. a -> [a] -> [a]
:) ShowS
-> StateT DefaultsState m String -> StateT DefaultsState m String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> StateT DefaultsState m String
resolveVars String
cs
  lookupEnv' :: String -> StateT DefaultsState m String
  lookupEnv' :: String -> StateT DefaultsState m String
lookupEnv' String
"." = do
    Maybe String
mbCurDefaults <- (DefaultsState -> Maybe String)
-> StateT DefaultsState m (Maybe String)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DefaultsState -> Maybe String
curDefaults
    StateT DefaultsState m String
-> (String -> StateT DefaultsState m String)
-> Maybe String
-> StateT DefaultsState m String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> StateT DefaultsState m String
forall (m :: * -> *) a. Monad m => a -> m a
return String
"")
          (ShowS
-> StateT DefaultsState m String -> StateT DefaultsState m String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ShowS
takeDirectory (StateT DefaultsState m String -> StateT DefaultsState m String)
-> (String -> StateT DefaultsState m String)
-> String
-> StateT DefaultsState m String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO String -> StateT DefaultsState m String
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO String -> StateT DefaultsState m String)
-> (String -> IO String) -> String -> StateT DefaultsState m String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO String
canonicalizePath)
          Maybe String
mbCurDefaults
  lookupEnv' String
"USERDATA" = do
    Maybe String
mbodatadir <- (String -> StateT DefaultsState m String)
-> Maybe String -> StateT DefaultsState m (Maybe String)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> StateT DefaultsState m String
resolveVars Maybe String
oDataDir
    Maybe String
mbdatadir  <- StateT DefaultsState m (Maybe String)
forall (m :: * -> *). PandocMonad m => m (Maybe String)
getUserDataDir
    String
defdatadir <- IO String -> StateT DefaultsState m String
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO String
defaultUserDataDir
    String -> StateT DefaultsState m String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> StateT DefaultsState m String)
-> String -> StateT DefaultsState m String
forall a b. (a -> b) -> a -> b
$ String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe String
defdatadir (Maybe String
mbodatadir Maybe String -> Maybe String -> Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe String
mbdatadir)
  lookupEnv' String
v = do
    Maybe String
mbval <- (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> String
T.unpack (Maybe Text -> Maybe String)
-> StateT DefaultsState m (Maybe Text)
-> StateT DefaultsState m (Maybe String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> StateT DefaultsState m (Maybe Text)
forall (m :: * -> *). PandocMonad m => Text -> m (Maybe Text)
lookupEnv (String -> Text
T.pack String
v)
    case Maybe String
mbval of
      Maybe String
Nothing -> do
        LogMessage -> StateT DefaultsState m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> StateT DefaultsState m ())
-> LogMessage -> StateT DefaultsState m ()
forall a b. (a -> b) -> a -> b
$ Text -> LogMessage
EnvironmentVariableUndefined (String -> Text
T.pack String
v)
        String -> StateT DefaultsState m String
forall (m :: * -> *) a. Monad m => a -> m a
return String
forall a. Monoid a => a
mempty
      Just String
x  -> String -> StateT DefaultsState m String
forall (m :: * -> *) a. Monad m => a -> m a
return String
x
  resolveVarsInFilter :: Filter -> StateT DefaultsState m Filter
resolveVarsInFilter (JSONFilter String
fp) =
    String -> Filter
JSONFilter (String -> Filter)
-> StateT DefaultsState m String -> StateT DefaultsState m Filter
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> StateT DefaultsState m String
resolveVars String
fp
  resolveVarsInFilter (LuaFilter String
fp) =
    String -> Filter
LuaFilter (String -> Filter)
-> StateT DefaultsState m String -> StateT DefaultsState m Filter
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> StateT DefaultsState m String
resolveVars String
fp
  resolveVarsInFilter Filter
CiteprocFilter = Filter -> StateT DefaultsState m Filter
forall (m :: * -> *) a. Monad m => a -> m a
return Filter
CiteprocFilter



parseDefaults :: (PandocMonad m, MonadIO m)
              => Node Pos
              -> Maybe FilePath
              -> Parser (Opt -> StateT DefaultsState m Opt)
parseDefaults :: Node Pos
-> Maybe String -> Parser (Opt -> StateT DefaultsState m Opt)
parseDefaults Node Pos
n Maybe String
dataDir = Node Pos -> Parser [String]
parseDefsNames Node Pos
n Parser [String]
-> ([String] -> Parser (Opt -> StateT DefaultsState m Opt))
-> Parser (Opt -> StateT DefaultsState m Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[String]
ds -> (Opt -> StateT DefaultsState m Opt)
-> Parser (Opt -> StateT DefaultsState m Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Opt -> StateT DefaultsState m Opt)
 -> Parser (Opt -> StateT DefaultsState m Opt))
-> (Opt -> StateT DefaultsState m Opt)
-> Parser (Opt -> StateT DefaultsState m Opt)
forall a b. (a -> b) -> a -> b
$ \Opt
o -> do
  -- get parent defaults:
  String
defsParent <- (DefaultsState -> String) -> StateT DefaultsState m String
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((DefaultsState -> String) -> StateT DefaultsState m String)
-> (DefaultsState -> String) -> StateT DefaultsState m String
forall a b. (a -> b) -> a -> b
$ String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe String
"" (Maybe String -> String)
-> (DefaultsState -> Maybe String) -> DefaultsState -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DefaultsState -> Maybe String
curDefaults
  -- get child defaults:
  [String]
defsChildren <- (String -> StateT DefaultsState m String)
-> [String] -> StateT DefaultsState m [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Maybe String -> String -> StateT DefaultsState m String
forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
Maybe String -> String -> m String
fullDefaultsPath Maybe String
dataDir) [String]
ds
  -- expand parent in defaults inheritance graph by children:
  [[String]]
defsGraph <- (DefaultsState -> [[String]]) -> StateT DefaultsState m [[String]]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DefaultsState -> [[String]]
inheritanceGraph
  let defsGraphExp :: [[String]]
defsGraphExp = [[String]] -> [String] -> String -> [[String]]
forall a. Ord a => [[a]] -> [a] -> a -> [[a]]
expand [[String]]
defsGraph [String]
defsChildren String
defsParent
  (DefaultsState -> DefaultsState) -> StateT DefaultsState m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((DefaultsState -> DefaultsState) -> StateT DefaultsState m ())
-> (DefaultsState -> DefaultsState) -> StateT DefaultsState m ()
forall a b. (a -> b) -> a -> b
$ \DefaultsState
defsState -> DefaultsState
defsState{ inheritanceGraph :: [[String]]
inheritanceGraph = [[String]]
defsGraphExp }
  -- check for cyclic inheritance:
  if [[String]] -> Bool
forall a. Ord a => [[a]] -> Bool
cyclic [[String]]
defsGraphExp
    then PandocError -> StateT DefaultsState m Opt
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (PandocError -> StateT DefaultsState m Opt)
-> PandocError -> StateT DefaultsState m Opt
forall a b. (a -> b) -> a -> b
$
      Text -> PandocError
PandocSomeError (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
"Error: Circular defaults file reference in " String -> ShowS
forall a. [a] -> [a] -> [a]
++
        String
"'" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
defsParent String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"'"
    else (Opt -> String -> StateT DefaultsState m Opt)
-> Opt -> [String] -> StateT DefaultsState m Opt
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM Opt -> String -> StateT DefaultsState m Opt
forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
Opt -> String -> StateT DefaultsState m Opt
applyDefaults Opt
o [String]
defsChildren
  where parseDefsNames :: Node Pos -> Parser [String]
parseDefsNames Node Pos
x = (Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
x Parser [Text] -> ([Text] -> Parser [String]) -> Parser [String]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
xs -> [String] -> Parser [String]
forall (m :: * -> *) a. Monad m => a -> m a
return ([String] -> Parser [String]) -> [String] -> Parser [String]
forall a b. (a -> b) -> a -> b
$ (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
xs)
                       Parser [String] -> Parser [String] -> Parser [String]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
x Parser Text -> (Text -> Parser [String]) -> Parser [String]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x' -> [String] -> Parser [String]
forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> String
unpack Text
x'])

parseOptions :: Monad m
             => [(Node Pos, Node Pos)]
             -> Parser (Opt -> StateT DefaultsState m Opt)
parseOptions :: [(Node Pos, Node Pos)]
-> Parser (Opt -> StateT DefaultsState m Opt)
parseOptions [(Node Pos, Node Pos)]
ns = do
  Opt -> Opt
f <- ((Node Pos, Node Pos) -> Parser (Opt -> Opt))
-> [(Node Pos, Node Pos)] -> Parser (Opt -> Opt)
forall (m :: * -> *) a b.
Monad m =>
(a -> m (b -> b)) -> [a] -> m (b -> b)
chain (Node Pos, Node Pos) -> Parser (Opt -> Opt)
doOpt' [(Node Pos, Node Pos)]
ns
  (Opt -> StateT DefaultsState m Opt)
-> Parser (Opt -> StateT DefaultsState m Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Opt -> StateT DefaultsState m Opt)
 -> Parser (Opt -> StateT DefaultsState m Opt))
-> (Opt -> StateT DefaultsState m Opt)
-> Parser (Opt -> StateT DefaultsState m Opt)
forall a b. (a -> b) -> a -> b
$ Opt -> StateT DefaultsState m Opt
forall (m :: * -> *) a. Monad m => a -> m a
return (Opt -> StateT DefaultsState m Opt)
-> (Opt -> Opt) -> Opt -> StateT DefaultsState m Opt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Opt -> Opt
f

chain :: Monad m => (a -> m (b -> b)) -> [a] -> m (b -> b)
chain :: (a -> m (b -> b)) -> [a] -> m (b -> b)
chain a -> m (b -> b)
f = ((b -> b) -> a -> m (b -> b)) -> (b -> b) -> [a] -> m (b -> b)
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM (b -> b) -> a -> m (b -> b)
forall a. (a -> b) -> a -> m (a -> b)
g b -> b
forall a. a -> a
id
  where g :: (a -> b) -> a -> m (a -> b)
g a -> b
o a
n = a -> m (b -> b)
f a
n m (b -> b) -> ((b -> b) -> m (a -> b)) -> m (a -> b)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \b -> b
o' -> (a -> b) -> m (a -> b)
forall (m :: * -> *) a. Monad m => a -> m a
return ((a -> b) -> m (a -> b)) -> (a -> b) -> m (a -> b)
forall a b. (a -> b) -> a -> b
$ b -> b
o' (b -> b) -> (a -> b) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
o

doOpt' :: (Node Pos, Node Pos) -> Parser (Opt -> Opt)
doOpt' :: (Node Pos, Node Pos) -> Parser (Opt -> Opt)
doOpt' (Node Pos
k',Node Pos
v) = do
  Text
k <- Node Pos -> Parser Text
parseStringKey Node Pos
k'
  case Text
k of
    Text
"defaults" -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return Opt -> Opt
forall a. a -> a
id
    Text
_ -> (Node Pos, Node Pos) -> Parser (Opt -> Opt)
doOpt (Node Pos
k',Node Pos
v)

doOpt :: (Node Pos, Node Pos) -> Parser (Opt -> Opt)
doOpt :: (Node Pos, Node Pos) -> Parser (Opt -> Opt)
doOpt (Node Pos
k',Node Pos
v) = do
  Text
k <- Node Pos -> Parser Text
parseStringKey Node Pos
k'
  case Text
k of
    Text
"tab-stop" ->
      Node Pos -> Parser Int
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Int -> (Int -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optTabStop :: Int
optTabStop = Int
x })
    Text
"preserve-tabs" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optPreserveTabs :: Bool
optPreserveTabs = Bool
x })
    Text
"standalone" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optStandalone :: Bool
optStandalone = Bool
x })
    Text
"table-of-contents" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optTableOfContents :: Bool
optTableOfContents = Bool
x })
    Text
"toc" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optTableOfContents :: Bool
optTableOfContents = Bool
x })
    Text
"from" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optFrom :: Maybe Text
optFrom = Maybe Text
x })
    Text
"reader" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optFrom :: Maybe Text
optFrom = Maybe Text
x })
    Text
"to" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optTo :: Maybe Text
optTo = Maybe Text
x })
    Text
"writer" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optTo :: Maybe Text
optTo = Maybe Text
x })
    Text
"shift-heading-level-by" ->
      Node Pos -> Parser Int
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Int -> (Int -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optShiftHeadingLevelBy :: Int
optShiftHeadingLevelBy = Int
x })
    Text
"template" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optTemplate :: Maybe String
optTemplate = Text -> String
unpack (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x })
    Text
"variables" ->
      Node Pos -> Parser (Context Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Context Text)
-> (Context Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Context Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optVariables :: Context Text
optVariables =
                                               Context Text
x Context Text -> Context Text -> Context Text
forall a. Semigroup a => a -> a -> a
<> Opt -> Context Text
optVariables Opt
o })
      -- Note: x comes first because <> for Context is left-biased union
      -- and we want to favor later default files. See #5988.
    Text
"metadata" ->
      Node Pos -> Parser Meta
yamlToMeta Node Pos
v Parser Meta -> (Meta -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Meta
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optMetadata :: Meta
optMetadata = Opt -> Meta
optMetadata Opt
o Meta -> Meta -> Meta
forall a. Semigroup a => a -> a -> a
<> Meta
x })
    Text
"metadata-files" ->
      Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x ->
                        (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optMetadataFiles :: [String]
optMetadataFiles =
                                           Opt -> [String]
optMetadataFiles Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<>
                                           (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x })
    Text
"metadata-file" -> -- allow either a list or a single value
      (Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optMetadataFiles :: [String]
optMetadataFiles =
                                                Opt -> [String]
optMetadataFiles Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<>
                                                (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x }))
      Parser (Opt -> Opt) -> Parser (Opt -> Opt) -> Parser (Opt -> Opt)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
      (Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Text -> (Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x ->
                        (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optMetadataFiles :: [String]
optMetadataFiles =
                                           Opt -> [String]
optMetadataFiles Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<>[Text -> String
unpack Text
x] }))
    Text
"output-file" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optOutputFile :: Maybe String
optOutputFile = Text -> String
unpack (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x })
    Text
"input-files" ->
      Node Pos -> Parser (Maybe [Text])
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe [Text])
-> (Maybe [Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe [Text]
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optInputFiles :: Maybe [String]
optInputFiles =
                                              Opt -> Maybe [String]
optInputFiles Opt
o Maybe [String] -> Maybe [String] -> Maybe [String]
forall a. Semigroup a => a -> a -> a
<>
                                                ((Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack ([Text] -> [String]) -> Maybe [Text] -> Maybe [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe [Text]
x) })
    Text
"input-file" -> -- allow either a list or a single value
      (Node Pos -> Parser (Maybe [Text])
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe [Text])
-> (Maybe [Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe [Text]
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optInputFiles :: Maybe [String]
optInputFiles =
                                                Opt -> Maybe [String]
optInputFiles Opt
o Maybe [String] -> Maybe [String] -> Maybe [String]
forall a. Semigroup a => a -> a -> a
<>
                                                  ((Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack ([Text] -> [String]) -> Maybe [Text] -> Maybe [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe [Text]
x) }))
      Parser (Opt -> Opt) -> Parser (Opt -> Opt) -> Parser (Opt -> Opt)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
      (Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optInputFiles :: Maybe [String]
optInputFiles =
                                                Opt -> Maybe [String]
optInputFiles Opt
o Maybe [String] -> Maybe [String] -> Maybe [String]
forall a. Semigroup a => a -> a -> a
<>
                                                ((\Text
z -> [Text -> String
unpack Text
z]) (Text -> [String]) -> Maybe Text -> Maybe [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x)
                                            }))
    Text
"number-sections" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optNumberSections :: Bool
optNumberSections = Bool
x })
    Text
"number-offset" ->
      Node Pos -> Parser [Int]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Int]
-> ([Int] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Int]
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optNumberOffset :: [Int]
optNumberOffset = [Int]
x })
    Text
"section-divs" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optSectionDivs :: Bool
optSectionDivs = Bool
x })
    Text
"incremental" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optIncremental :: Bool
optIncremental = Bool
x })
    Text
"self-contained" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optSelfContained :: Bool
optSelfContained = Bool
x })
    Text
"html-q-tags" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optHtmlQTags :: Bool
optHtmlQTags = Bool
x })
    Text
"highlight-style" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optHighlightStyle :: Maybe Text
optHighlightStyle = Maybe Text
x })
    Text
"syntax-definition" ->
      (Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x ->
                (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optSyntaxDefinitions :: [String]
optSyntaxDefinitions =
                                   Opt -> [String]
optSyntaxDefinitions Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<> (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x }))
      Parser (Opt -> Opt) -> Parser (Opt -> Opt) -> Parser (Opt -> Opt)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
      (Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Text -> (Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optSyntaxDefinitions :: [String]
optSyntaxDefinitions =
                                 Opt -> [String]
optSyntaxDefinitions Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<> [Text -> String
unpack Text
x] }))
    Text
"syntax-definitions" ->
      Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optSyntaxDefinitions :: [String]
optSyntaxDefinitions =
                                Opt -> [String]
optSyntaxDefinitions Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<> (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x })
    Text
"top-level-division" ->
      Node Pos -> Parser TopLevelDivision
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser TopLevelDivision
-> (TopLevelDivision -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \TopLevelDivision
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optTopLevelDivision :: TopLevelDivision
optTopLevelDivision = TopLevelDivision
x })
    Text
"html-math-method" ->
      Node Pos -> Parser HTMLMathMethod
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser HTMLMathMethod
-> (HTMLMathMethod -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \HTMLMathMethod
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optHTMLMathMethod :: HTMLMathMethod
optHTMLMathMethod = HTMLMathMethod
x })
    Text
"abbreviations" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optAbbreviations :: Maybe String
optAbbreviations = Text -> String
unpack (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x })
    Text
"reference-doc" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optReferenceDoc :: Maybe String
optReferenceDoc = Text -> String
unpack (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x })
    Text
"epub-subdirectory" ->
      Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Text -> (Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optEpubSubdirectory :: String
optEpubSubdirectory = Text -> String
unpack Text
x })
    Text
"epub-metadata" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optEpubMetadata :: Maybe String
optEpubMetadata = Text -> String
unpack (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x })
    Text
"epub-fonts" ->
      Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optEpubFonts :: [String]
optEpubFonts = Opt -> [String]
optEpubFonts Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<>
                                               (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x })
    Text
"epub-chapter-level" ->
      Node Pos -> Parser Int
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Int -> (Int -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optEpubChapterLevel :: Int
optEpubChapterLevel = Int
x })
    Text
"epub-cover-image" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optEpubCoverImage :: Maybe String
optEpubCoverImage = Text -> String
unpack (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x })
    Text
"toc-depth" ->
      Node Pos -> Parser Int
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Int -> (Int -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optTOCDepth :: Int
optTOCDepth = Int
x })
    Text
"dump-args" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optDumpArgs :: Bool
optDumpArgs = Bool
x })
    Text
"ignore-args" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optIgnoreArgs :: Bool
optIgnoreArgs = Bool
x })
    Text
"verbosity" ->
      Node Pos -> Parser Verbosity
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Verbosity
-> (Verbosity -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Verbosity
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optVerbosity :: Verbosity
optVerbosity = Verbosity
x })
    Text
"trace" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optTrace :: Bool
optTrace = Bool
x })
    Text
"log-file" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optLogFile :: Maybe String
optLogFile = Text -> String
unpack (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x })
    Text
"fail-if-warnings" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optFailIfWarnings :: Bool
optFailIfWarnings = Bool
x })
    Text
"reference-links" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optReferenceLinks :: Bool
optReferenceLinks = Bool
x })
    Text
"reference-location" ->
      Node Pos -> Parser ReferenceLocation
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser ReferenceLocation
-> (ReferenceLocation -> Parser (Opt -> Opt))
-> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ReferenceLocation
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optReferenceLocation :: ReferenceLocation
optReferenceLocation = ReferenceLocation
x })
    Text
"dpi" ->
      Node Pos -> Parser Int
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Int -> (Int -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optDpi :: Int
optDpi = Int
x })
    Text
"wrap" ->
      Node Pos -> Parser WrapOption
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser WrapOption
-> (WrapOption -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \WrapOption
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optWrap :: WrapOption
optWrap = WrapOption
x })
    Text
"columns" ->
      Node Pos -> Parser Int
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Int -> (Int -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optColumns :: Int
optColumns = Int
x })
    Text
"filters" ->
      Node Pos -> Parser [Filter]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Filter]
-> ([Filter] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Filter]
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optFilters :: [Filter]
optFilters = Opt -> [Filter]
optFilters Opt
o [Filter] -> [Filter] -> [Filter]
forall a. Semigroup a => a -> a -> a
<> [Filter]
x })
    Text
"citeproc" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x ->
        if Bool
x
           then (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optFilters :: [Filter]
optFilters = Filter
CiteprocFilter Filter -> [Filter] -> [Filter]
forall a. a -> [a] -> [a]
: Opt -> [Filter]
optFilters Opt
o })
           else (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return Opt -> Opt
forall a. a -> a
id
    Text
"email-obfuscation" ->
      Node Pos -> Parser ObfuscationMethod
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser ObfuscationMethod
-> (ObfuscationMethod -> Parser (Opt -> Opt))
-> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ObfuscationMethod
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optEmailObfuscation :: ObfuscationMethod
optEmailObfuscation = ObfuscationMethod
x })
    Text
"identifier-prefix" ->
      Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Text -> (Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optIdentifierPrefix :: Text
optIdentifierPrefix = Text
x })
    Text
"strip-empty-paragraphs" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optStripEmptyParagraphs :: Bool
optStripEmptyParagraphs = Bool
x })
    Text
"indented-code-classes" ->
      Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optIndentedCodeClasses :: [Text]
optIndentedCodeClasses = [Text]
x })
    Text
"data-dir" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optDataDir :: Maybe String
optDataDir = Text -> String
unpack (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x })
    Text
"cite-method" ->
      Node Pos -> Parser CiteMethod
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser CiteMethod
-> (CiteMethod -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CiteMethod
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optCiteMethod :: CiteMethod
optCiteMethod = CiteMethod
x })
    Text
"listings" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optListings :: Bool
optListings = Bool
x })
    Text
"pdf-engine" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optPdfEngine :: Maybe String
optPdfEngine = Text -> String
unpack (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x })
    Text
"pdf-engine-opts" ->
      Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optPdfEngineOpts :: [String]
optPdfEngineOpts = (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x })
    Text
"pdf-engine-opt" ->
      (Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optPdfEngineOpts :: [String]
optPdfEngineOpts = (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x }))
      Parser (Opt -> Opt) -> Parser (Opt -> Opt) -> Parser (Opt -> Opt)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
      (Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Text -> (Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optPdfEngineOpts :: [String]
optPdfEngineOpts = [Text -> String
unpack Text
x] }))
    Text
"slide-level" ->
      Node Pos -> Parser (Maybe Int)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Int)
-> (Maybe Int -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Int
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optSlideLevel :: Maybe Int
optSlideLevel = Maybe Int
x })
    Text
"atx-headers" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optSetextHeaders :: Bool
optSetextHeaders = Bool -> Bool
not Bool
x })
    Text
"markdown-headings" ->
      Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Text -> (Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o ->
        case Text -> Text
T.toLower Text
x of
          Text
"atx"    -> Opt
o{ optSetextHeaders :: Bool
optSetextHeaders = Bool
False }
          Text
"setext" -> Opt
o{ optSetextHeaders :: Bool
optSetextHeaders = Bool
True }
          Text
_        -> Opt
o)
    Text
"ascii" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optAscii :: Bool
optAscii = Bool
x })
    Text
"default-image-extension" ->
      Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Text -> (Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optDefaultImageExtension :: Text
optDefaultImageExtension = Text
x })
    Text
"extract-media" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optExtractMedia :: Maybe String
optExtractMedia = Text -> String
unpack (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x })
    Text
"track-changes" ->
      Node Pos -> Parser TrackChanges
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser TrackChanges
-> (TrackChanges -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \TrackChanges
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optTrackChanges :: TrackChanges
optTrackChanges = TrackChanges
x })
    Text
"file-scope" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optFileScope :: Bool
optFileScope = Bool
x })
    Text
"title-prefix" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optTitlePrefix :: Maybe Text
optTitlePrefix = Maybe Text
x,
                                             optStandalone :: Bool
optStandalone = Bool
True })
    Text
"css" ->
      (Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optCss :: [String]
optCss = Opt -> [String]
optCss Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<>
                                                 (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x }))
      Parser (Opt -> Opt) -> Parser (Opt -> Opt) -> Parser (Opt -> Opt)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
      (Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Text -> (Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optCss :: [String]
optCss = Opt -> [String]
optCss Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<>
                                                [Text -> String
unpack Text
x] }))
    Text
"bibliography" ->
      (Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o ->
                               Opt
o{ optBibliography :: [String]
optBibliography = Opt -> [String]
optBibliography Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<>
                                                      (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x }))
      Parser (Opt -> Opt) -> Parser (Opt -> Opt) -> Parser (Opt -> Opt)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
      (Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Text -> (Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o ->
                               Opt
o{ optBibliography :: [String]
optBibliography = Opt -> [String]
optBibliography Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<>
                                                       [Text -> String
unpack Text
x] }))
    Text
"csl" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optCSL :: Maybe String
optCSL = Text -> String
unpack (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x })
    Text
"citation-abbreviations" ->
      Node Pos -> Parser (Maybe Text)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser (Maybe Text)
-> (Maybe Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe Text
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optCitationAbbreviations :: Maybe String
optCitationAbbreviations =
                                                  Text -> String
unpack (Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
x })
    Text
"ipynb-output" ->
      Node Pos -> Parser IpynbOutput
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser IpynbOutput
-> (IpynbOutput -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \IpynbOutput
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optIpynbOutput :: IpynbOutput
optIpynbOutput = IpynbOutput
x })
    Text
"include-before-body" ->
      (Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optIncludeBeforeBody :: [String]
optIncludeBeforeBody =
                                Opt -> [String]
optIncludeBeforeBody Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<> (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x }))
      Parser (Opt -> Opt) -> Parser (Opt -> Opt) -> Parser (Opt -> Opt)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
      (Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Text -> (Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optIncludeBeforeBody :: [String]
optIncludeBeforeBody =
                                Opt -> [String]
optIncludeBeforeBody Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<> [Text -> String
unpack Text
x] }))
    Text
"include-after-body" ->
      (Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optIncludeAfterBody :: [String]
optIncludeAfterBody =
                                Opt -> [String]
optIncludeAfterBody Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<> (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x }))
      Parser (Opt -> Opt) -> Parser (Opt -> Opt) -> Parser (Opt -> Opt)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
      (Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Text -> (Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optIncludeAfterBody :: [String]
optIncludeAfterBody =
                                Opt -> [String]
optIncludeAfterBody Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<> [Text -> String
unpack Text
x] }))
    Text
"include-in-header" ->
      (Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optIncludeInHeader :: [String]
optIncludeInHeader =
                                Opt -> [String]
optIncludeInHeader Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<> (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x }))
      Parser (Opt -> Opt) -> Parser (Opt -> Opt) -> Parser (Opt -> Opt)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
      (Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Text -> (Text -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optIncludeInHeader :: [String]
optIncludeInHeader =
                                Opt -> [String]
optIncludeInHeader Opt
o [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<> [Text -> String
unpack Text
x] }))
    Text
"resource-path" ->
      Node Pos -> Parser [Text]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [Text]
-> ([Text] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Text]
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optResourcePath :: [String]
optResourcePath = (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
unpack [Text]
x [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<>
                                 Opt -> [String]
optResourcePath Opt
o })
    Text
"request-headers" ->
      Node Pos -> Parser [(Text, Text)]
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser [(Text, Text)]
-> ([(Text, Text)] -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[(Text, Text)]
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optRequestHeaders :: [(Text, Text)]
optRequestHeaders = [(Text, Text)]
x })
    Text
"no-check-certificate" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x ->
             (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optNoCheckCertificate :: Bool
optNoCheckCertificate = Bool
x })
    Text
"eol" ->
      Node Pos -> Parser LineEnding
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser LineEnding
-> (LineEnding -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \LineEnding
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o{ optEol :: LineEnding
optEol = LineEnding
x })
    Text
"strip-comments" ->
      Node Pos -> Parser Bool
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v Parser Bool -> (Bool -> Parser (Opt -> Opt)) -> Parser (Opt -> Opt)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
x -> (Opt -> Opt) -> Parser (Opt -> Opt)
forall (m :: * -> *) a. Monad m => a -> m a
return (\Opt
o -> Opt
o  { optStripComments :: Bool
optStripComments = Bool
x })
    Text
_ -> Node Pos -> String -> Parser (Opt -> Opt)
forall a. Node Pos -> String -> Parser a
failAtNode Node Pos
k' (String -> Parser (Opt -> Opt)) -> String -> Parser (Opt -> Opt)
forall a b. (a -> b) -> a -> b
$ String
"Unknown option " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
k

-- | Defaults for command-line options.
defaultOpts :: Opt
defaultOpts :: Opt
defaultOpts = Opt :: Int
-> Bool
-> Bool
-> Maybe Text
-> Maybe Text
-> Bool
-> Int
-> Maybe String
-> Context Text
-> Meta
-> [String]
-> Maybe String
-> Maybe [String]
-> Bool
-> [Int]
-> Bool
-> Bool
-> Bool
-> Bool
-> Maybe Text
-> [String]
-> TopLevelDivision
-> HTMLMathMethod
-> Maybe String
-> Maybe String
-> String
-> Maybe String
-> [String]
-> Int
-> Maybe String
-> Int
-> Bool
-> Bool
-> Verbosity
-> Bool
-> Maybe String
-> Bool
-> Bool
-> ReferenceLocation
-> Int
-> WrapOption
-> Int
-> [Filter]
-> ObfuscationMethod
-> Text
-> Bool
-> [Text]
-> Maybe String
-> CiteMethod
-> Bool
-> Maybe String
-> [String]
-> Maybe Int
-> Bool
-> Bool
-> Text
-> Maybe String
-> TrackChanges
-> Bool
-> Maybe Text
-> [String]
-> IpynbOutput
-> [String]
-> [String]
-> [String]
-> [String]
-> [(Text, Text)]
-> Bool
-> LineEnding
-> Bool
-> Maybe String
-> [String]
-> Maybe String
-> Opt
Opt
    { optTabStop :: Int
optTabStop               = Int
4
    , optPreserveTabs :: Bool
optPreserveTabs          = Bool
False
    , optStandalone :: Bool
optStandalone            = Bool
False
    , optFrom :: Maybe Text
optFrom                  = Maybe Text
forall a. Maybe a
Nothing
    , optTo :: Maybe Text
optTo                    = Maybe Text
forall a. Maybe a
Nothing
    , optTableOfContents :: Bool
optTableOfContents       = Bool
False
    , optShiftHeadingLevelBy :: Int
optShiftHeadingLevelBy   = Int
0
    , optTemplate :: Maybe String
optTemplate              = Maybe String
forall a. Maybe a
Nothing
    , optVariables :: Context Text
optVariables             = Context Text
forall a. Monoid a => a
mempty
    , optMetadata :: Meta
optMetadata              = Meta
forall a. Monoid a => a
mempty
    , optMetadataFiles :: [String]
optMetadataFiles         = []
    , optOutputFile :: Maybe String
optOutputFile            = Maybe String
forall a. Maybe a
Nothing
    , optInputFiles :: Maybe [String]
optInputFiles            = Maybe [String]
forall a. Maybe a
Nothing
    , optNumberSections :: Bool
optNumberSections        = Bool
False
    , optNumberOffset :: [Int]
optNumberOffset          = [Int
0,Int
0,Int
0,Int
0,Int
0,Int
0]
    , optSectionDivs :: Bool
optSectionDivs           = Bool
False
    , optIncremental :: Bool
optIncremental           = Bool
False
    , optSelfContained :: Bool
optSelfContained         = Bool
False
    , optHtmlQTags :: Bool
optHtmlQTags             = Bool
False
    , optHighlightStyle :: Maybe Text
optHighlightStyle        = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"pygments"
    , optSyntaxDefinitions :: [String]
optSyntaxDefinitions     = []
    , optTopLevelDivision :: TopLevelDivision
optTopLevelDivision      = TopLevelDivision
TopLevelDefault
    , optHTMLMathMethod :: HTMLMathMethod
optHTMLMathMethod        = HTMLMathMethod
PlainMath
    , optAbbreviations :: Maybe String
optAbbreviations         = Maybe String
forall a. Maybe a
Nothing
    , optReferenceDoc :: Maybe String
optReferenceDoc          = Maybe String
forall a. Maybe a
Nothing
    , optEpubSubdirectory :: String
optEpubSubdirectory      = String
"EPUB"
    , optEpubMetadata :: Maybe String
optEpubMetadata          = Maybe String
forall a. Maybe a
Nothing
    , optEpubFonts :: [String]
optEpubFonts             = []
    , optEpubChapterLevel :: Int
optEpubChapterLevel      = Int
1
    , optEpubCoverImage :: Maybe String
optEpubCoverImage        = Maybe String
forall a. Maybe a
Nothing
    , optTOCDepth :: Int
optTOCDepth              = Int
3
    , optDumpArgs :: Bool
optDumpArgs              = Bool
False
    , optIgnoreArgs :: Bool
optIgnoreArgs            = Bool
False
    , optVerbosity :: Verbosity
optVerbosity             = Verbosity
WARNING
    , optTrace :: Bool
optTrace                 = Bool
False
    , optLogFile :: Maybe String
optLogFile               = Maybe String
forall a. Maybe a
Nothing
    , optFailIfWarnings :: Bool
optFailIfWarnings        = Bool
False
    , optReferenceLinks :: Bool
optReferenceLinks        = Bool
False
    , optReferenceLocation :: ReferenceLocation
optReferenceLocation     = ReferenceLocation
EndOfDocument
    , optDpi :: Int
optDpi                   = Int
96
    , optWrap :: WrapOption
optWrap                  = WrapOption
WrapAuto
    , optColumns :: Int
optColumns               = Int
72
    , optFilters :: [Filter]
optFilters               = []
    , optEmailObfuscation :: ObfuscationMethod
optEmailObfuscation      = ObfuscationMethod
NoObfuscation
    , optIdentifierPrefix :: Text
optIdentifierPrefix      = Text
""
    , optStripEmptyParagraphs :: Bool
optStripEmptyParagraphs  = Bool
False
    , optIndentedCodeClasses :: [Text]
optIndentedCodeClasses   = []
    , optDataDir :: Maybe String
optDataDir               = Maybe String
forall a. Maybe a
Nothing
    , optCiteMethod :: CiteMethod
optCiteMethod            = CiteMethod
Citeproc
    , optListings :: Bool
optListings              = Bool
False
    , optPdfEngine :: Maybe String
optPdfEngine             = Maybe String
forall a. Maybe a
Nothing
    , optPdfEngineOpts :: [String]
optPdfEngineOpts         = []
    , optSlideLevel :: Maybe Int
optSlideLevel            = Maybe Int
forall a. Maybe a
Nothing
    , optSetextHeaders :: Bool
optSetextHeaders         = Bool
False
    , optAscii :: Bool
optAscii                 = Bool
False
    , optDefaultImageExtension :: Text
optDefaultImageExtension = Text
""
    , optExtractMedia :: Maybe String
optExtractMedia          = Maybe String
forall a. Maybe a
Nothing
    , optTrackChanges :: TrackChanges
optTrackChanges          = TrackChanges
AcceptChanges
    , optFileScope :: Bool
optFileScope             = Bool
False
    , optTitlePrefix :: Maybe Text
optTitlePrefix           = Maybe Text
forall a. Maybe a
Nothing
    , optCss :: [String]
optCss                   = []
    , optIpynbOutput :: IpynbOutput
optIpynbOutput           = IpynbOutput
IpynbOutputBest
    , optIncludeBeforeBody :: [String]
optIncludeBeforeBody     = []
    , optIncludeAfterBody :: [String]
optIncludeAfterBody      = []
    , optIncludeInHeader :: [String]
optIncludeInHeader       = []
    , optResourcePath :: [String]
optResourcePath          = [String
"."]
    , optRequestHeaders :: [(Text, Text)]
optRequestHeaders        = []
    , optNoCheckCertificate :: Bool
optNoCheckCertificate    = Bool
False
    , optEol :: LineEnding
optEol                   = LineEnding
Native
    , optStripComments :: Bool
optStripComments         = Bool
False
    , optCSL :: Maybe String
optCSL                   = Maybe String
forall a. Maybe a
Nothing
    , optBibliography :: [String]
optBibliography          = []
    , optCitationAbbreviations :: Maybe String
optCitationAbbreviations = Maybe String
forall a. Maybe a
Nothing
    }

parseStringKey ::  Node Pos -> Parser Text
parseStringKey :: Node Pos -> Parser Text
parseStringKey Node Pos
k = case Node Pos
k of
  Scalar Pos
_ (SStr Text
t) -> Text -> Parser Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
t
  Scalar Pos
_ Scalar
_ -> Node Pos -> String -> Parser Text
forall a. Node Pos -> String -> Parser a
failAtNode Node Pos
k String
"Non-string key"
  Node Pos
_ -> Node Pos -> String -> Parser Text
forall a. Node Pos -> String -> Parser a
failAtNode Node Pos
k String
"Non-scalar key"

yamlToMeta :: Node Pos -> Parser Meta
yamlToMeta :: Node Pos -> Parser Meta
yamlToMeta (Mapping Pos
_ Tag
_ Mapping Pos
m) =
    (PandocError -> Parser Meta)
-> (Meta -> Parser Meta) -> Either PandocError Meta -> Parser Meta
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Parser Meta
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Meta)
-> (PandocError -> String) -> PandocError -> Parser Meta
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PandocError -> String
forall a. Show a => a -> String
show) Meta -> Parser Meta
forall (m :: * -> *) a. Monad m => a -> m a
return (Either PandocError Meta -> Parser Meta)
-> Either PandocError Meta -> Parser Meta
forall a b. (a -> b) -> a -> b
$ ParserT
  Sources
  ParserState
  PandocPure
  (Future ParserState (Map Text MetaValue))
-> Either PandocError Meta
forall s.
Default s =>
ParserT
  Sources ParserState PandocPure (Future s (Map Text MetaValue))
-> Either PandocError Meta
runEverything (ParserT
  Sources ParserState PandocPure (Future ParserState MetaValue)
-> Mapping Pos
-> ParserT
     Sources
     ParserState
     PandocPure
     (Future ParserState (Map Text MetaValue))
forall (m :: * -> *) st.
(PandocMonad m, HasLastStrPosition st) =>
ParserT Sources st m (Future st MetaValue)
-> Mapping Pos
-> ParserT Sources st m (Future st (Map Text MetaValue))
yamlMap ParserT
  Sources ParserState PandocPure (Future ParserState MetaValue)
forall st.
ParsecT Sources st PandocPure (Future ParserState MetaValue)
pMetaString Mapping Pos
m)
  where
    pMetaString :: ParsecT Sources st PandocPure (Future ParserState MetaValue)
pMetaString = MetaValue -> Future ParserState MetaValue
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MetaValue -> Future ParserState MetaValue)
-> (Text -> MetaValue) -> Text -> Future ParserState MetaValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> MetaValue
MetaString (Text -> Future ParserState MetaValue)
-> ParsecT Sources st PandocPure Text
-> ParsecT Sources st PandocPure (Future ParserState MetaValue)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Sources st PandocPure Char
-> ParsecT Sources st PandocPure Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
P.manyChar ParserT Sources st PandocPure Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
P.anyChar
    runEverything :: ParserT
  Sources ParserState PandocPure (Future s (Map Text MetaValue))
-> Either PandocError Meta
runEverything ParserT
  Sources ParserState PandocPure (Future s (Map Text MetaValue))
p =
      PandocPure (Either PandocError (Future s (Map Text MetaValue)))
-> Either
     PandocError (Either PandocError (Future s (Map Text MetaValue)))
forall a. PandocPure a -> Either PandocError a
runPure (ParserT
  Sources ParserState PandocPure (Future s (Map Text MetaValue))
-> ParserState
-> Text
-> PandocPure (Either PandocError (Future s (Map Text MetaValue)))
forall (m :: * -> *) t st a.
(Monad m, ToSources t) =>
ParserT Sources st m a -> st -> t -> m (Either PandocError a)
P.readWithM ParserT
  Sources ParserState PandocPure (Future s (Map Text MetaValue))
p (ParserState
forall a. Default a => a
def :: P.ParserState) (Text
"" :: Text))
      Either
  PandocError (Either PandocError (Future s (Map Text MetaValue)))
-> (Either PandocError (Future s (Map Text MetaValue))
    -> Either PandocError Meta)
-> Either PandocError Meta
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Future s (Map Text MetaValue) -> Meta)
-> Either PandocError (Future s (Map Text MetaValue))
-> Either PandocError Meta
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Map Text MetaValue -> Meta
Meta (Map Text MetaValue -> Meta)
-> (Future s (Map Text MetaValue) -> Map Text MetaValue)
-> Future s (Map Text MetaValue)
-> Meta
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Future s (Map Text MetaValue) -> s -> Map Text MetaValue)
-> s -> Future s (Map Text MetaValue) -> Map Text MetaValue
forall a b c. (a -> b -> c) -> b -> a -> c
flip Future s (Map Text MetaValue) -> s -> Map Text MetaValue
forall s a. Future s a -> s -> a
P.runF s
forall a. Default a => a
def)
yamlToMeta Node Pos
_ = Meta -> Parser Meta
forall (m :: * -> *) a. Monad m => a -> m a
return Meta
forall a. Monoid a => a
mempty

-- | Apply defaults from --defaults file.
applyDefaults :: (PandocMonad m, MonadIO m)
              => Opt
              -> FilePath
              -> StateT DefaultsState m Opt
applyDefaults :: Opt -> String -> StateT DefaultsState m Opt
applyDefaults Opt
opt String
file = do
  Verbosity -> StateT DefaultsState m ()
forall (m :: * -> *). PandocMonad m => Verbosity -> m ()
setVerbosity (Verbosity -> StateT DefaultsState m ())
-> Verbosity -> StateT DefaultsState m ()
forall a b. (a -> b) -> a -> b
$ Opt -> Verbosity
optVerbosity Opt
opt
  (DefaultsState -> DefaultsState) -> StateT DefaultsState m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((DefaultsState -> DefaultsState) -> StateT DefaultsState m ())
-> (DefaultsState -> DefaultsState) -> StateT DefaultsState m ()
forall a b. (a -> b) -> a -> b
$ \DefaultsState
defsState -> DefaultsState
defsState{ curDefaults :: Maybe String
curDefaults = String -> Maybe String
forall a. a -> Maybe a
Just String
file }
  ByteString
inp <- String -> StateT DefaultsState m ByteString
forall (m :: * -> *). PandocMonad m => String -> m ByteString
readFileLazy String
file
  case ByteString
-> Either (Pos, String) (Opt -> StateT DefaultsState m Opt)
forall v. FromYAML v => ByteString -> Either (Pos, String) v
decode1 ByteString
inp of
      Right Opt -> StateT DefaultsState m Opt
f -> Opt -> StateT DefaultsState m Opt
f Opt
opt
      Left (Pos
errpos, String
errmsg)  -> PandocError -> StateT DefaultsState m Opt
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (PandocError -> StateT DefaultsState m Opt)
-> PandocError -> StateT DefaultsState m Opt
forall a b. (a -> b) -> a -> b
$
         Text -> PandocError
PandocParseError (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
"Error parsing " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
file String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" line " String -> ShowS
forall a. [a] -> [a] -> [a]
++
          Int -> String
forall a. Show a => a -> String
show (Pos -> Int
posLine Pos
errpos) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" column " String -> ShowS
forall a. [a] -> [a] -> [a]
++
          Int -> String
forall a. Show a => a -> String
show (Pos -> Int
posColumn Pos
errpos) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":\n" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
errmsg

fullDefaultsPath :: (PandocMonad m, MonadIO m)
                 => Maybe FilePath
                 -> FilePath
                 -> m FilePath
fullDefaultsPath :: Maybe String -> String -> m String
fullDefaultsPath Maybe String
dataDir String
file = do
  let fp :: String
fp = if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (ShowS
takeExtension String
file)
              then String -> ShowS
addExtension String
file String
"yaml"
              else String
file
  String
defaultDataDir <- IO String -> m String
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO String
defaultUserDataDir
  let defaultFp :: String
defaultFp = String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe String
defaultDataDir Maybe String
dataDir String -> ShowS
</> String
"defaults" String -> ShowS
</> String
fp
  String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe String
fp (Maybe String -> String) -> m (Maybe String) -> m String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> m Bool) -> [String] -> m (Maybe String)
forall (m :: * -> *) (t :: * -> *) a.
(Monad m, Foldable t) =>
(a -> m Bool) -> t a -> m (Maybe a)
findM String -> m Bool
forall (m :: * -> *). PandocMonad m => String -> m Bool
fileExists [String
fp, String
defaultFp]

-- | In a list of lists, append another list in front of every list which
-- starts with specific element.
expand :: Ord a => [[a]] -> [a] -> a -> [[a]]
expand :: [[a]] -> [a] -> a -> [[a]]
expand [] [a]
ns a
n = (a -> [a]) -> [a] -> [[a]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a
x -> a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a
n]) [a]
ns
expand [[a]]
ps [a]
ns a
n = ([a] -> [[a]]) -> [[a]] -> [[a]]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (a -> [a] -> [a] -> [[a]]
forall a. Eq a => a -> [a] -> [a] -> [[a]]
ext a
n [a]
ns) [[a]]
ps
  where
    ext :: a -> [a] -> [a] -> [[a]]
ext a
x [a]
xs [a]
p = case [a]
p of
      (a
l : [a]
_) | a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
l -> (a -> [a]) -> [a] -> [[a]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
p) [a]
xs
      [a]
_ -> [[a]
p]

cyclic :: Ord a => [[a]] -> Bool
cyclic :: [[a]] -> Bool
cyclic = ([a] -> Bool) -> [[a]] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any [a] -> Bool
forall a. Ord a => [a] -> Bool
hasDuplicate
  where
    hasDuplicate :: [a] -> Bool
hasDuplicate [a]
xs = [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([a] -> [a]
forall a. Ord a => [a] -> [a]
ordNub [a]
xs) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs

-- see https://github.com/jgm/pandoc/pull/4083
-- using generic deriving caused long compilation times
$(deriveJSON
   defaultOptions{ fieldLabelModifier = drop 11 . map toLower } ''IpynbOutput)
$(deriveJSON
   defaultOptions{ fieldLabelModifier = map toLower } ''LineEnding)
$(deriveJSON
   defaultOptions{ fieldLabelModifier =
                      camelCaseStrToHyphenated . dropWhile isLower
                 } ''Opt)