    {-# LANGUAGE OverloadedStrings #-}
    {- |
       Module      : Text.Pandoc.Readers.Org.ExportSettings
       Copyright   : © 2016-2024 Albert Krewinkel
       License     : GNU GPL, version 2 or above

       Maintainer  : Albert Krewinkel <albert+pandoc@tarleb.com>

    Parsers for Org-mode export options.
    -}
    module Text.Pandoc.Readers.Org.ExportSettings
      ( exportSettings
      ) where

    import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
    import Text.Pandoc.Logging (LogMessage (UnknownOrgExportOption))
    import Text.Pandoc.Readers.Org.ParserState
    import Text.Pandoc.Readers.Org.Parsing

    import Control.Monad (mzero, void)
    import Data.Char (toLower)
    import Data.Maybe (listToMaybe)
    import Data.Text (Text, unpack)

    -- | Read and handle space separated org-mode export settings.
    exportSettings :: PandocMonad m => OrgParser m ()
    exportSettings :: forall (m :: * -> *). PandocMonad m => OrgParser m ()
    exportSettings = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [()]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [()]
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [()]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a b. (a -> b) -> a -> b
    $ ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [()]
    forall s (m :: * -> *) t u a sep.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
    sepBy ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m ()
    skipSpaces ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). PandocMonad m => OrgParser m ()
    exportSetting

    -- | Setter function for export settings.
    type ExportSettingSetter a = a -> ExportSettings -> ExportSettings

    -- | Read and process a single org-mode export option.
    exportSetting :: PandocMonad m => OrgParser m ()
    exportSetting :: forall (m :: * -> *). PandocMonad m => OrgParser m ()
    exportSetting = [ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice
      [ Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "^" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportSubSuperscripts = val })
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "'" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportSmartQuotes = val })
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "*" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportEmphasizedText = val })
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "-" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportSpecialStrings = val })
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    ":"
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    "<"
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "\\n" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportPreserveBreaks = val })
      , Text
    -> ExportSettingSetter ArchivedTreesOption
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter ArchivedTreesOption -> OrgParser m ()
    archivedTreeSetting Text
    "arch" (\ArchivedTreesOption
    val ExportSettings
    es -> ExportSettings
    es { exportArchivedTrees = val })
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "author" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportWithAuthor = val })
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    "c"
      -- org-mode allows the special value `comment` for creator, which we'll
      -- interpret as true as it doesn't make sense in the context of Pandoc.
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "creator" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportWithCreator = val })
      , Text
    -> ExportSettingSetter (Either [Text] [Text])
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text
    -> ExportSettingSetter (Either [Text] [Text]) -> OrgParser m ()
    complementableListSetting Text
    "d" (\Either [Text] [Text]
    val ExportSettings
    es -> ExportSettings
    es { exportDrawers = val })
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    "date"
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "e" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportWithEntities = val })
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "email" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportWithEmail = val })
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "f" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportWithFootnotes = val })
      , Text
    -> ExportSettingSetter Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Int -> OrgParser m ()
    integerSetting Text
    "H" (\Int
    val ExportSettings
    es -> ExportSettings
    es { exportHeadlineLevels = val })
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    "inline"
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    "num"
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "p" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportWithPlanning = val })
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    "pri"
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    "prop"
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    "stat"
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "tags" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportWithTags = val })
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    "tasks"
      , Text
    -> ExportSettingSetter TeXExport
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter TeXExport -> OrgParser m ()
    texSetting     Text
    "tex" (\TeXExport
    val ExportSettings
    es -> ExportSettings
    es { exportWithLatex = val })
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    "timestamp"
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    "title"
      , Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    "toc"
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "todo" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportWithTodoKeywords = val })
      , Text
    -> ExportSettingSetter Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting Text
    "|" (\Bool
    val ExportSettings
    es -> ExportSettings
    es { exportWithTables = val })
      , ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). PandocMonad m => OrgParser m ()
    ignoreAndWarn
      ] ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> String -> ParsecT s u m a
    <?> String
    "export setting"

    -- | Generic handler for export settings. Takes a parser which converts
    -- the plain option text into a data structure.
    genericExportSetting :: Monad m
                         => OrgParser m a
                         -> Text
                         -> ExportSettingSetter a
                         -> OrgParser m ()
    genericExportSetting :: forall (m :: * -> *) a.
    Monad m =>
    OrgParser m a -> Text -> ExportSettingSetter a -> OrgParser m ()
    genericExportSetting OrgParser m a
    optionParser Text
    settingIdentifier ExportSettingSetter a
    setter = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a b. (a -> b) -> a -> b
    $ do
      _     <- Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) u.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s u m Text
    textStr Text
    settingIdentifier ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    ':'
      value <- optionParser
      updateState $ modifyExportSettings value
     where
       modifyExportSettings :: a -> OrgParserState -> OrgParserState
    modifyExportSettings a
    val OrgParserState
    st =
         OrgParserState
    st { orgStateExportSettings = setter val . orgStateExportSettings $ st }

    -- | A boolean option, either nil (False) or non-nil (True).
    booleanSetting :: Monad m => Text ->  ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting :: forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Bool -> OrgParser m ()
    booleanSetting = OrgParser m Bool
    -> Text -> ExportSettingSetter Bool -> OrgParser m ()
    forall (m :: * -> *) a.
    Monad m =>
    OrgParser m a -> Text -> ExportSettingSetter a -> OrgParser m ()
    genericExportSetting OrgParser m Bool
    forall (m :: * -> *). Monad m => OrgParser m Bool
    elispBoolean

    -- | An integer-valued option.
    integerSetting :: Monad m => Text -> ExportSettingSetter Int -> OrgParser m ()
    integerSetting :: forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter Int -> OrgParser m ()
    integerSetting = OrgParser m Int
    -> Text -> ExportSettingSetter Int -> OrgParser m ()
    forall (m :: * -> *) a.
    Monad m =>
    OrgParser m a -> Text -> ExportSettingSetter a -> OrgParser m ()
    genericExportSetting OrgParser m Int
    forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) Int
    parseInt
     where
       parseInt :: ParsecT Sources u (ReaderT OrgParserLocal m) Int
    parseInt = ParsecT Sources u (ReaderT OrgParserLocal m) Int
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Int
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources u (ReaderT OrgParserLocal m) Int
     -> ParsecT Sources u (ReaderT OrgParserLocal m) Int)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Int
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Int
    forall a b. (a -> b) -> a -> b
    $
         ParsecT Sources u (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources u (ReaderT OrgParserLocal m) String
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Sources u (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    digit ParsecT Sources u (ReaderT OrgParserLocal m) String
    -> (String -> ParsecT Sources u (ReaderT OrgParserLocal m) Int)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Int
    forall a b.
    ParsecT Sources u (ReaderT OrgParserLocal m) a
    -> (a -> ParsecT Sources u (ReaderT OrgParserLocal m) b)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= ParsecT Sources u (ReaderT OrgParserLocal m) Int
    -> ((Int, String)
        -> ParsecT Sources u (ReaderT OrgParserLocal m) Int)
    -> Maybe (Int, String)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Int
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe ParsecT Sources u (ReaderT OrgParserLocal m) Int
    forall a. ParsecT Sources u (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero (Int -> ParsecT Sources u (ReaderT OrgParserLocal m) Int
    forall a. a -> ParsecT Sources u (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Int -> ParsecT Sources u (ReaderT OrgParserLocal m) Int)
    -> ((Int, String) -> Int)
    -> (Int, String)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Int, String) -> Int
    forall a b. (a, b) -> a
    fst) (Maybe (Int, String)
     -> ParsecT Sources u (ReaderT OrgParserLocal m) Int)
    -> (String -> Maybe (Int, String))
    -> String
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [(Int, String)] -> Maybe (Int, String)
    forall a. [a] -> Maybe a
    listToMaybe ([(Int, String)] -> Maybe (Int, String))
    -> (String -> [(Int, String)]) -> String -> Maybe (Int, String)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> [(Int, String)]
    forall a. Read a => ReadS a
    reads

    -- | Either the string "headline" or an elisp boolean and treated as an
    -- @ArchivedTreesOption@.
    archivedTreeSetting :: Monad m
                        => Text
                        -> ExportSettingSetter ArchivedTreesOption
                        -> OrgParser m ()
    archivedTreeSetting :: forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter ArchivedTreesOption -> OrgParser m ()
    archivedTreeSetting =
      OrgParser m ArchivedTreesOption
    -> Text
    -> ExportSettingSetter ArchivedTreesOption
    -> OrgParser m ()
    forall (m :: * -> *) a.
    Monad m =>
    OrgParser m a -> Text -> ExportSettingSetter a -> OrgParser m ()
    genericExportSetting (OrgParser m ArchivedTreesOption
     -> Text
     -> ExportSettingSetter ArchivedTreesOption
     -> OrgParser m ())
    -> OrgParser m ArchivedTreesOption
    -> Text
    -> ExportSettingSetter ArchivedTreesOption
    -> OrgParser m ()
    forall a b. (a -> b) -> a -> b
    $ OrgParser m ArchivedTreesOption
    archivedTreesHeadlineSetting OrgParser m ArchivedTreesOption
    -> OrgParser m ArchivedTreesOption
    -> OrgParser m ArchivedTreesOption
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> OrgParser m ArchivedTreesOption
    archivedTreesBoolean
     where
       archivedTreesHeadlineSetting :: OrgParser m ArchivedTreesOption
    archivedTreesHeadlineSetting =
         ArchivedTreesOption
    ArchivedTreesHeadlineOnly ArchivedTreesOption
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> OrgParser m ArchivedTreesOption
    forall a b.
    a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => Text -> OrgParser m Text
    optionString Text
    "headline"

       archivedTreesBoolean :: OrgParser m ArchivedTreesOption
    archivedTreesBoolean = OrgParser m ArchivedTreesOption -> OrgParser m ArchivedTreesOption
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (OrgParser m ArchivedTreesOption
     -> OrgParser m ArchivedTreesOption)
    -> OrgParser m ArchivedTreesOption
    -> OrgParser m ArchivedTreesOption
    forall a b. (a -> b) -> a -> b
    $ do
         exportBool <- OrgParser m Bool
    forall (m :: * -> *). Monad m => OrgParser m Bool
    elispBoolean
         return $
           if exportBool
           then ArchivedTreesExport
           else ArchivedTreesNoExport

    -- | A list or a complement list (i.e. a list starting with `not`).
    complementableListSetting :: Monad m
                              => Text
                              -> ExportSettingSetter (Either [Text] [Text])
                              -> OrgParser m ()
    complementableListSetting :: forall (m :: * -> *).
    Monad m =>
    Text
    -> ExportSettingSetter (Either [Text] [Text]) -> OrgParser m ()
    complementableListSetting = OrgParser m (Either [Text] [Text])
    -> Text
    -> ExportSettingSetter (Either [Text] [Text])
    -> OrgParser m ()
    forall (m :: * -> *) a.
    Monad m =>
    OrgParser m a -> Text -> ExportSettingSetter a -> OrgParser m ()
    genericExportSetting (OrgParser m (Either [Text] [Text])
     -> Text
     -> ExportSettingSetter (Either [Text] [Text])
     -> OrgParser m ())
    -> OrgParser m (Either [Text] [Text])
    -> Text
    -> ExportSettingSetter (Either [Text] [Text])
    -> OrgParser m ()
    forall a b. (a -> b) -> a -> b
    $ [OrgParser m (Either [Text] [Text])]
    -> OrgParser m (Either [Text] [Text])
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice
      [ [Text] -> Either [Text] [Text]
    forall a b. a -> Either a b
    Left  ([Text] -> Either [Text] [Text])
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> OrgParser m (Either [Text] [Text])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall (m :: * -> *). Monad m => OrgParser m [Text]
    complementTextList
      , [Text] -> Either [Text] [Text]
    forall a b. b -> Either a b
    Right ([Text] -> Either [Text] [Text])
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> OrgParser m (Either [Text] [Text])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall (m :: * -> *). Monad m => OrgParser m [Text]
    stringList
      , (\Bool
    b -> if Bool
    b then [Text] -> Either [Text] [Text]
    forall a b. a -> Either a b
    Left [] else [Text] -> Either [Text] [Text]
    forall a b. b -> Either a b
    Right []) (Bool -> Either [Text] [Text])
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Bool
    -> OrgParser m (Either [Text] [Text])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Bool
    forall (m :: * -> *). Monad m => OrgParser m Bool
    elispBoolean
      ]
     where
       -- Read a plain list of strings.
       stringList :: Monad m => OrgParser m [Text]
       stringList :: forall (m :: * -> *). Monad m => OrgParser m [Text]
    stringList = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) [Text])
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall a b. (a -> b) -> a -> b
    $
         Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '('
           ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall s (m :: * -> *) t u a sep.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
    sepBy ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    elispText ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m ()
    spaces
           ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    ')'

       -- Read an emacs lisp list specifying a complement set.
       complementTextList :: Monad m => OrgParser m [Text]
       complementTextList :: forall (m :: * -> *). Monad m => OrgParser m [Text]
    complementTextList = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) [Text])
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall a b. (a -> b) -> a -> b
    $
         String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    String -> ParsecT s u m String
    string String
    "(not "
           ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall s (m :: * -> *) t u a sep.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
    sepBy ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    elispText ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m ()
    spaces
           ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    ')'

       elispText :: Monad m => OrgParser m Text
       elispText :: forall (m :: * -> *). Monad m => OrgParser m Text
    elispText = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall a b. (a -> b) -> a -> b
    $
         Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '"'
           ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) t st a.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
    manyTillChar ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    alphaNum (Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '"')

    -- | Parses either @t@, @nil@, or @verbatim@ into a 'TeXExport' value.
    texSetting :: Monad m
               => Text
               -> ExportSettingSetter TeXExport
               -> OrgParser m ()
    texSetting :: forall (m :: * -> *).
    Monad m =>
    Text -> ExportSettingSetter TeXExport -> OrgParser m ()
    texSetting = OrgParser m TeXExport
    -> Text -> ExportSettingSetter TeXExport -> OrgParser m ()
    forall (m :: * -> *) a.
    Monad m =>
    OrgParser m a -> Text -> ExportSettingSetter a -> OrgParser m ()
    genericExportSetting (OrgParser m TeXExport
     -> Text -> ExportSettingSetter TeXExport -> OrgParser m ())
    -> OrgParser m TeXExport
    -> Text
    -> ExportSettingSetter TeXExport
    -> OrgParser m ()
    forall a b. (a -> b) -> a -> b
    $ OrgParser m TeXExport
    texVerbatim OrgParser m TeXExport
    -> OrgParser m TeXExport -> OrgParser m TeXExport
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> OrgParser m TeXExport
    texBoolean
     where
       texVerbatim :: OrgParser m TeXExport
    texVerbatim = TeXExport
    TeXVerbatim TeXExport
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> OrgParser m TeXExport
    forall a b.
    a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => Text -> OrgParser m Text
    optionString Text
    "verbatim"

       texBoolean :: OrgParser m TeXExport
    texBoolean = OrgParser m TeXExport -> OrgParser m TeXExport
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (OrgParser m TeXExport -> OrgParser m TeXExport)
    -> OrgParser m TeXExport -> OrgParser m TeXExport
    forall a b. (a -> b) -> a -> b
    $ do
         exportBool <- OrgParser m Bool
    forall (m :: * -> *). Monad m => OrgParser m Bool
    elispBoolean
         return $
           if exportBool
           then TeXExport
           else TeXIgnore

    -- | Read but ignore the export setting.
    ignoredSetting :: Monad m => Text -> OrgParser m ()
    ignoredSetting :: forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    ignoredSetting Text
    s = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (() ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a b.
    a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) u.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s u m Text
    textStr Text
    s ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    ':' ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    nonspaceChar)

    -- | Read any setting string, but ignore it and emit a warning.
    ignoreAndWarn :: PandocMonad m => OrgParser m ()
    ignoreAndWarn :: forall (m :: * -> *). PandocMonad m => OrgParser m ()
    ignoreAndWarn = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a b. (a -> b) -> a -> b
    $ do
      opt <- ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m Text
    many1Char ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    nonspaceChar
      report (UnknownOrgExportOption opt)
      return ()

    -- | Read an elisp boolean.  Only NIL is treated as false, non-NIL values are
    -- interpreted as true.
    elispBoolean :: Monad m => OrgParser m Bool
    elispBoolean :: forall (m :: * -> *). Monad m => OrgParser m Bool
    elispBoolean = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Bool
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Bool
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Bool)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Bool
    forall a b. (a -> b) -> a -> b
    $ do
      value <- ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    nonspaceChar
      return $ case map toLower value of
                 String
    "nil" -> Bool
    False
                 String
    "{}"  -> Bool
    False
                 String
    "()"  -> Bool
    False
                 String
    _     -> Bool
    True

    -- | Try to parse a literal string as the option value. Returns the
    -- string on success.
    optionString :: Monad m => Text -> OrgParser m Text
    optionString :: forall (m :: * -> *). Monad m => Text -> OrgParser m Text
    optionString Text
    s = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall a b. (a -> b) -> a -> b
    $ do
      _ <- String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    String -> ParsecT s u m String
    string (Text -> String
    unpack Text
    s)
      lookAhead (newline <|> spaceChar)
      return s