    {-# LANGUAGE FlexibleContexts  #-}
    {-# LANGUAGE LambdaCase        #-}
    {-# LANGUAGE OverloadedStrings #-}
    {- |
       Module      : Text.Pandoc.Readers.Org.Meta
       Copyright   : Copyright (C) 2014-2024 Albert Krewinkel
       License     : GNU GPL, version 2 or above

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

    Parsers for Org-mode meta declarations.
    -}
    module Text.Pandoc.Readers.Org.Meta
      ( metaExport
      , metaKey
      , metaLine
      ) where

    import Text.Pandoc.Readers.Org.BlockStarts
    import Text.Pandoc.Readers.Org.ExportSettings (exportSettings)
    import Text.Pandoc.Readers.Org.Inlines
    import Text.Pandoc.Readers.Org.ParserState
    import Text.Pandoc.Readers.Org.Parsing

    import Text.Pandoc.Builder (Blocks, Inlines)
    import qualified Text.Pandoc.Builder as B
    import Text.Pandoc.Class.PandocMonad (PandocMonad)
    import Text.Pandoc.Definition
    import Text.Pandoc.Shared (blocksToInlines, safeRead)
    import Text.Pandoc.URI (urlEncode)

    import Control.Monad (mzero, void)
    import Data.List (intercalate, intersperse)
    import Data.Map (Map)
    import Data.Maybe (fromMaybe)
    import Data.Text (Text)
    import qualified Data.Map as Map
    import qualified Data.Set as Set
    import qualified Data.Text as T

    -- | Returns the current meta, respecting export options.
    metaExport :: Monad m => OrgParser m (F Meta)
    metaExport :: forall (m :: * -> *). Monad m => OrgParser m (F Meta)
    metaExport = do
      st <- ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      let settings = OrgParserState -> ExportSettings
    orgStateExportSettings OrgParserState
    st
      return $ (if exportWithAuthor  settings then id else removeMeta "author")
             . (if exportWithCreator settings then id else removeMeta "creator")
             . (if exportWithEmail   settings then id else removeMeta "email")
            <$> orgStateMeta st

    removeMeta :: Text -> Meta -> Meta
    removeMeta :: Text -> Meta -> Meta
    removeMeta Text
    key Meta
    meta' =
      let metaMap :: Map Text MetaValue
    metaMap = Meta -> Map Text MetaValue
    unMeta Meta
    meta'
      in Map Text MetaValue -> Meta
    Meta (Map Text MetaValue -> Meta) -> Map Text MetaValue -> Meta
    forall a b. (a -> b) -> a -> b
    $ Text -> Map Text MetaValue -> Map Text MetaValue
    forall k a. Ord k => k -> Map k a -> Map k a
    Map.delete Text
    key Map Text MetaValue
    metaMap

    -- | Parse and handle a single line containing meta information
    -- The order, in which blocks are tried, makes sure that we're not looking at
    -- the beginning of a block, so we don't need to check for it
    metaLine :: PandocMonad m => OrgParser m Blocks
    metaLine :: forall (m :: * -> *). PandocMonad m => OrgParser m Blocks
    metaLine = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) Blocks)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    forall a b. (a -> b) -> a -> b
    $ Blocks
    forall a. Monoid a => a
    mempty Blocks
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    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
    <$ ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    metaLineStart ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    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) ()
    forall (m :: * -> *). PandocMonad m => OrgParser m ()
    keywordLine

    keywordLine :: PandocMonad m => OrgParser m ()
    keywordLine :: forall (m :: * -> *). PandocMonad m => OrgParser m ()
    keywordLine = 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
      key   <- Text -> Text
    T.toLower (Text -> Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) 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
    metaKey
      case Map.lookup key keywordHandlers of
        Maybe
      (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    Nothing -> String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a.
    String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. MonadFail m => String -> m a
    fail (String
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a b. (a -> b) -> a -> b
    $ String
    "Unknown keyword: " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ Text -> String
    T.unpack Text
    key
        Just ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    hd -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    hd

    metaKey :: Monad m => OrgParser m Text
    metaKey :: forall (m :: * -> *). Monad m => OrgParser m Text
    metaKey = Text -> Text
    T.toLower (Text -> Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> 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 (String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    String -> ParsecT s u m Char
    noneOf String
    ": \n\r")
                        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
    ':'
                        ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> 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
    <*  ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m ()
    skipSpaces

    infix 0 ~~>
    (~~>) :: a -> b -> (a, b)
    a
    a ~~> :: forall a b. a -> b -> (a, b)
    ~~> b
    b = (a
    a, b
    b)

    keywordHandlers :: PandocMonad m => Map Text (OrgParser m ())
    keywordHandlers :: forall (m :: * -> *). PandocMonad m => Map Text (OrgParser m ())
    keywordHandlers = [(Text, OrgParser m ())] -> Map Text (OrgParser m ())
    forall k a. Ord k => [(k, a)] -> Map k a
    Map.fromList
      [ Text
    "author" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    lineOfInlines OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    collectLines Text
    "author"
      , Text
    "bibliography" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> (Text -> F Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Text)
    forall a b.
    (a -> b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Text -> F Text
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) (F Text)
    -> (Text -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Text -> Meta -> Meta
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    collectAsList Text
    "bibliography"
      , Text
    "creator" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> (Text -> F Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Text)
    forall a b.
    (a -> b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Text -> F Text
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) (F Text)
    -> (Text -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Text -> Meta -> Meta
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    B.setMeta Text
    "creator"
      , Text
    "date" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    lineOfInlines OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    B.setMeta Text
    "date"
      , Text
    "description" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    lineOfInlines OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    collectLines Text
    "description"
      , Text
    "email" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> (Text -> F Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Text)
    forall a b.
    (a -> b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Text -> F Text
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) (F Text)
    -> (Text -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Text -> Meta -> Meta
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    B.setMeta Text
    "email"
      , Text
    "exclude_tags" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m [Tag]
    forall (m :: * -> *). Monad m => OrgParser m [Tag]
    tagList OrgParser m [Tag] -> ([Tag] -> OrgParser m ()) -> OrgParser m ()
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> (a
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (OrgParserState -> OrgParserState) -> OrgParser m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
    -> ([Tag] -> OrgParserState -> OrgParserState)
    -> [Tag]
    -> OrgParser m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Tag] -> OrgParserState -> OrgParserState
    setExcludedTags
      , Text
    "header-includes" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~>
        OrgParser m (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    lineOfInlines OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    collectLines Text
    "header-includes"
      -- HTML-specifix export settings
      , Text
    "html_head" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~>
        Text -> OrgParser m (F Inlines)
    forall (m :: * -> *). Monad m => Text -> OrgParser m (F Inlines)
    metaExportSnippet Text
    "html" OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    collectAsList Text
    "header-includes"
      , Text
    "html_head_extra" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~>
        Text -> OrgParser m (F Inlines)
    forall (m :: * -> *). Monad m => Text -> OrgParser m (F Inlines)
    metaExportSnippet Text
    "html" OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    collectAsList Text
    "header-includes"
      , Text
    "institute" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    lineOfInlines OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    collectLines Text
    "institute"
      -- topic keywords
      , Text
    "keywords" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    lineOfInlines OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    collectLines Text
    "keywords"
      -- document language
      , Text
    "language" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> (Text -> F Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Text)
    forall a b.
    (a -> b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Text -> F Text
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) (F Text)
    -> (Text -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Text -> Meta -> Meta
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    B.setMeta Text
    "lang"
      -- LaTeX-specific export settings
      , Text
    "latex_class" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> (Text -> F Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Text)
    forall a b.
    (a -> b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Text -> F Text
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) (F Text)
    -> (Text -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Text -> Meta -> Meta
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    B.setMeta Text
    "documentclass"
      , Text
    "latex_class_options" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~>
          (Text -> F Text
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Text -> F Text) -> (Text -> Text) -> Text -> F Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Bool) -> Text -> Text
    T.filter (Char -> String -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `notElem` (String
    "[]" :: String)) (Text -> F Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F 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
    anyLine)
          ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) (F Text)
    -> (Text -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Text -> Meta -> Meta
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    B.setMeta Text
    "classoption"
      , Text
    "latex_header" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~>
          Text -> OrgParser m (F Inlines)
    forall (m :: * -> *). Monad m => Text -> OrgParser m (F Inlines)
    metaExportSnippet Text
    "latex" OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    collectAsList Text
    "header-includes"
      , Text
    "latex_header_extra" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~>
          Text -> OrgParser m (F Inlines)
    forall (m :: * -> *). Monad m => Text -> OrgParser m (F Inlines)
    metaExportSnippet Text
    "latex" OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    collectAsList Text
    "header-includes"
      -- link and macro
      , Text
    "link" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    addLinkFormatter
      , Text
    "macro" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m (Text, [Text] -> Text)
    forall (m :: * -> *). Monad m => OrgParser m (Text, [Text] -> Text)
    macroDefinition OrgParser m (Text, [Text] -> Text)
    -> ((Text, [Text] -> Text) -> OrgParser m ()) -> OrgParser m ()
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> (a
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (OrgParserState -> OrgParserState) -> OrgParser m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
    -> ((Text, [Text] -> Text) -> OrgParserState -> OrgParserState)
    -> (Text, [Text] -> Text)
    -> OrgParser m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text, [Text] -> Text) -> OrgParserState -> OrgParserState
    registerMacro
      -- pandoc-specific way to include references in the bibliography
      , Text
    "nocite" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    lineOfInlines OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    collectLines Text
    "nocite"
      -- compact way to set export settings
      , Text
    "options"  Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m ()
    forall (m :: * -> *). PandocMonad m => OrgParser m ()
    exportSettings
      -- pandoc-specific way to configure emphasis recognition
      , Text
    "pandoc-emphasis-post" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m (Maybe String)
    forall (m :: * -> *). Monad m => OrgParser m (Maybe String)
    emphChars OrgParser m (Maybe String)
    -> (Maybe String -> OrgParser m ()) -> OrgParser m ()
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> (a
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (OrgParserState -> OrgParserState) -> OrgParser m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
    -> (Maybe String -> OrgParserState -> OrgParserState)
    -> Maybe String
    -> OrgParser m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Maybe String -> OrgParserState -> OrgParserState
    setEmphasisPostChar
      , Text
    "pandoc-emphasis-pre" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m (Maybe String)
    forall (m :: * -> *). Monad m => OrgParser m (Maybe String)
    emphChars OrgParser m (Maybe String)
    -> (Maybe String -> OrgParser m ()) -> OrgParser m ()
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> (a
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (OrgParserState -> OrgParserState) -> OrgParser m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
    -> (Maybe String -> OrgParserState -> OrgParserState)
    -> Maybe String
    -> OrgParser m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Maybe String -> OrgParserState -> OrgParserState
    setEmphasisPreChar
      -- result markers (ignored)
      , Text
    "result" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> OrgParser m ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine
      , Text
    "select_tags" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m [Tag]
    forall (m :: * -> *). Monad m => OrgParser m [Tag]
    tagList OrgParser m [Tag] -> ([Tag] -> OrgParser m ()) -> OrgParser m ()
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> (a
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (OrgParserState -> OrgParserState) -> OrgParser m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
    -> ([Tag] -> OrgParserState -> OrgParserState)
    -> [Tag]
    -> OrgParser m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Tag] -> OrgParserState -> OrgParserState
    setSelectedTags
      , Text
    "seq_todo" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m TodoSequence
    forall (m :: * -> *). Monad m => OrgParser m TodoSequence
    todoSequence OrgParser m TodoSequence
    -> (TodoSequence -> OrgParser m ()) -> OrgParser m ()
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> (a
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (OrgParserState -> OrgParserState) -> OrgParser m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
    -> (TodoSequence -> OrgParserState -> OrgParserState)
    -> TodoSequence
    -> OrgParser m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . TodoSequence -> OrgParserState -> OrgParserState
    registerTodoSequence
      , Text
    "subtitle" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    lineOfInlines OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    collectLines Text
    "subtitle"
      , Text
    "title" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    lineOfInlines OrgParser m (F Inlines)
    -> (Inlines -> Meta -> Meta) -> OrgParser m ()
    forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    `parseThen` Text -> Inlines -> Meta -> Meta
    collectLines Text
    "title"
      , Text
    "todo" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m TodoSequence
    forall (m :: * -> *). Monad m => OrgParser m TodoSequence
    todoSequence OrgParser m TodoSequence
    -> (TodoSequence -> OrgParser m ()) -> OrgParser m ()
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> (a
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (OrgParserState -> OrgParserState) -> OrgParser m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
    -> (TodoSequence -> OrgParserState -> OrgParserState)
    -> TodoSequence
    -> OrgParser m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . TodoSequence -> OrgParserState -> OrgParserState
    registerTodoSequence
      , Text
    "typ_todo" Text -> OrgParser m () -> (Text, OrgParser m ())
    forall a b. a -> b -> (a, b)
    ~~> OrgParser m TodoSequence
    forall (m :: * -> *). Monad m => OrgParser m TodoSequence
    todoSequence OrgParser m TodoSequence
    -> (TodoSequence -> OrgParser m ()) -> OrgParser m ()
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> (a
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (OrgParserState -> OrgParserState) -> OrgParser m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
    -> (TodoSequence -> OrgParserState -> OrgParserState)
    -> TodoSequence
    -> OrgParser m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . TodoSequence -> OrgParserState -> OrgParserState
    registerTodoSequence
      ]

    parseThen :: PandocMonad m
              => OrgParser m (F a)
              -> (a -> Meta -> Meta)
              -> OrgParser m ()
    parseThen :: forall (m :: * -> *) a.
    PandocMonad m =>
    OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
    parseThen OrgParser m (F a)
    p a -> Meta -> Meta
    modMeta = do
      value <- OrgParser m (F a)
    p
      meta  <- orgStateMeta <$> getState
      updateState (\OrgParserState
    st -> OrgParserState
    st { orgStateMeta = modMeta <$> value <*> meta })

    collectLines :: Text -> Inlines -> Meta -> Meta
    collectLines :: Text -> Inlines -> Meta -> Meta
    collectLines Text
    key Inlines
    value Meta
    meta =
      let value' :: MetaValue
    value' = Meta -> [Inline] -> MetaValue
    appendValue Meta
    meta (Inlines -> [Inline]
    forall a. Many a -> [a]
    B.toList Inlines
    value)
      in Text -> MetaValue -> Meta -> Meta
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    B.setMeta Text
    key MetaValue
    value' Meta
    meta
     where
      appendValue :: Meta -> [Inline] -> MetaValue
      appendValue :: Meta -> [Inline] -> MetaValue
    appendValue Meta
    m [Inline]
    v = [Inline] -> MetaValue
    MetaInlines ([Inline] -> MetaValue) -> [Inline] -> MetaValue
    forall a b. (a -> b) -> a -> b
    $ Meta -> [Inline]
    curInlines Meta
    m [Inline] -> [Inline] -> [Inline]
    forall a. Semigroup a => a -> a -> a
    <> [Inline]
    v

      curInlines :: Meta -> [Inline]
    curInlines Meta
    m = case MetaValue -> [Inline]
    collectInlines (MetaValue -> [Inline]) -> Maybe MetaValue -> Maybe [Inline]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> Meta -> Maybe MetaValue
    lookupMeta Text
    key Meta
    m of
        Maybe [Inline]
    Nothing -> []
        Just [] -> []
        Just [Inline]
    xs -> [Inline]
    xs [Inline] -> [Inline] -> [Inline]
    forall a. Semigroup a => a -> a -> a
    <> [Inline
    B.SoftBreak]

      collectInlines :: MetaValue -> [Inline]
      collectInlines :: MetaValue -> [Inline]
    collectInlines = \case
        MetaInlines [Inline]
    inlns -> [Inline]
    inlns
        MetaList [MetaValue]
    ml       -> [Inline] -> [[Inline]] -> [Inline]
    forall a. [a] -> [[a]] -> [a]
    intercalate [Inline
    B.SoftBreak] ([[Inline]] -> [Inline]) -> [[Inline]] -> [Inline]
    forall a b. (a -> b) -> a -> b
    $ (MetaValue -> [Inline]) -> [MetaValue] -> [[Inline]]
    forall a b. (a -> b) -> [a] -> [b]
    map MetaValue -> [Inline]
    collectInlines [MetaValue]
    ml
        MetaString Text
    s      -> [Text -> Inline
    B.Str Text
    s]
        MetaBlocks [Block]
    blks   -> [Block] -> [Inline]
    blocksToInlines [Block]
    blks
        MetaMap Map Text MetaValue
    _map      -> []
        MetaBool Bool
    _bool    -> []

    -- | Accumulate the result as a MetaList under the given key.
    collectAsList :: B.ToMetaValue a => Text -> a -> Meta -> Meta
    collectAsList :: forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    collectAsList Text
    key a
    value Meta
    meta =
      let value' :: MetaValue
    value' = Meta -> MetaValue -> MetaValue
    metaListAppend Meta
    meta (a -> MetaValue
    forall a. ToMetaValue a => a -> MetaValue
    B.toMetaValue a
    value)
      in Text -> MetaValue -> Meta -> Meta
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    forall a. ToMetaValue a => Text -> a -> Meta -> Meta
    B.setMeta Text
    key MetaValue
    value' Meta
    meta
     where
      metaListAppend :: Meta -> MetaValue -> MetaValue
    metaListAppend Meta
    m MetaValue
    v = [MetaValue] -> MetaValue
    MetaList (Meta -> [MetaValue]
    curList Meta
    m [MetaValue] -> [MetaValue] -> [MetaValue]
    forall a. [a] -> [a] -> [a]
    ++ [MetaValue
    v])
      curList :: Meta -> [MetaValue]
    curList Meta
    m = case Text -> Meta -> Maybe MetaValue
    lookupMeta Text
    key Meta
    m of
                    Just (MetaList [MetaValue]
    ms) -> [MetaValue]
    ms
                    Just MetaValue
    x             -> [MetaValue
    x]
                    Maybe MetaValue
    _                  -> []

    -- | Read an format specific meta definition
    metaExportSnippet :: Monad m => Text -> OrgParser m (F Inlines)
    metaExportSnippet :: forall (m :: * -> *). Monad m => Text -> OrgParser m (F Inlines)
    metaExportSnippet Text
    format = Inlines -> F Inlines
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text -> Inlines
    B.rawInline Text
    format (Text -> F Inlines)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
    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
    anyLine

    -- | Parse a link type definition (like @wp https://en.wikipedia.org/wiki/@).
    addLinkFormatter :: Monad m => OrgParser m ()
    addLinkFormatter :: forall (m :: * -> *). Monad m => OrgParser m ()
    addLinkFormatter = 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
      linkType <- Char -> Text -> Text
    T.cons (Char -> Text -> Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> 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
    letter ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall a b.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) (a -> b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> 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
    manyChar (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 ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    String -> ParsecT s u m Char
    oneOf String
    "-_") ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> 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
    <* ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m ()
    skipSpaces
      formatter <- parseFormat
      updateState $ \OrgParserState
    s ->
        let fs :: OrgLinkFormatters
    fs = OrgParserState -> OrgLinkFormatters
    orgStateLinkFormatters OrgParserState
    s
        in OrgParserState
    s{ orgStateLinkFormatters = Map.insert linkType formatter fs }

    -- | An ad-hoc, single-argument-only implementation of a printf-style format
    -- parser.
    parseFormat :: Monad m => OrgParser m (Text -> Text)
    parseFormat :: forall (m :: * -> *). Monad m => OrgParser m (Text -> Text)
    parseFormat = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    forall a b. (a -> b) -> a -> b
    $ ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    forall {u}.
    ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    replacePlain ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    forall {u}.
    ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    replaceUrl ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    forall {u}.
    ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    justAppend
     where
       -- inefficient
       replacePlain :: ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    replacePlain = ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
     -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text))
    -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    forall a b. (a -> b) -> a -> b
    $ (\[Text]
    x -> [Text] -> Text
    T.concat ([Text] -> Text) -> (Text -> [Text]) -> Text -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text -> [Text] -> [Text]) -> [Text] -> Text -> [Text]
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    intersperse [Text]
    x)
                         ([Text] -> Text -> Text)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [ParsecT Sources u (ReaderT OrgParserLocal m) Text]
    -> ParsecT Sources u (ReaderT OrgParserLocal m) [Text]
    forall (t :: * -> *) (m :: * -> *) a.
    (Traversable t, Monad m) =>
    t (m a) -> m (t a)
    forall (m :: * -> *) a. Monad m => [m a] -> m [a]
    sequence [Char -> ParsecT Sources u (ReaderT OrgParserLocal m) Text
    forall {m :: * -> *} {s} {st}.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s st m Text
    tillSpecifier Char
    's', ParsecT Sources u (ReaderT OrgParserLocal m) Text
    forall {st}. ParsecT Sources st (ReaderT OrgParserLocal m) Text
    rest]
       replaceUrl :: ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    replaceUrl   = ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
     -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text))
    -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    forall a b. (a -> b) -> a -> b
    $ (\[Text]
    x -> [Text] -> Text
    T.concat ([Text] -> Text) -> (Text -> [Text]) -> Text -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text -> [Text] -> [Text]) -> [Text] -> Text -> [Text]
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    intersperse [Text]
    x (Text -> [Text]) -> (Text -> Text) -> Text -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    urlEncode)
                         ([Text] -> Text -> Text)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [ParsecT Sources u (ReaderT OrgParserLocal m) Text]
    -> ParsecT Sources u (ReaderT OrgParserLocal m) [Text]
    forall (t :: * -> *) (m :: * -> *) a.
    (Traversable t, Monad m) =>
    t (m a) -> m (t a)
    forall (m :: * -> *) a. Monad m => [m a] -> m [a]
    sequence [Char -> ParsecT Sources u (ReaderT OrgParserLocal m) Text
    forall {m :: * -> *} {s} {st}.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s st m Text
    tillSpecifier Char
    'h', ParsecT Sources u (ReaderT OrgParserLocal m) Text
    forall {st}. ParsecT Sources st (ReaderT OrgParserLocal m) Text
    rest]
       justAppend :: ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    justAppend   = ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
     -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text))
    -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    forall a b. (a -> b) -> a -> b
    $ Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    (<>) (Text -> Text -> Text)
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources u (ReaderT OrgParserLocal m) (Text -> Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources u (ReaderT OrgParserLocal m) Text
    forall {st}. ParsecT Sources st (ReaderT OrgParserLocal m) Text
    rest

       rest :: ParsecT Sources st (ReaderT OrgParserLocal m) Text
    rest            = ParsecT Sources st (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources st (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources st (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 st (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    anyChar         (ParsecT Sources st (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) t u.
    (Stream s m t, Show t) =>
    ParsecT s u m ()
    eof ParsecT Sources st (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources st (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources st (ReaderT OrgParserLocal m) ()
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> () ()
    -> ParsecT Sources st (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources st (ReaderT OrgParserLocal m) ()
    forall a b.
    a
    -> ParsecT Sources st (ReaderT OrgParserLocal m) b
    -> ParsecT Sources st (ReaderT OrgParserLocal m) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ String -> ParsecT Sources st (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    String -> ParsecT s u m Char
    oneOf String
    "\n\r")
       tillSpecifier :: Char -> ParsecT s st m Text
    tillSpecifier Char
    c = ParsecT s st m Char -> ParsecT s st m String -> ParsecT s st 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 (String -> ParsecT s st m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    String -> ParsecT s u m Char
    noneOf String
    "\n\r") (ParsecT s st m String -> ParsecT s st m String
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT s st m String -> ParsecT s st m String)
    -> ParsecT s st m String -> ParsecT s st m String
    forall a b. (a -> b) -> a -> b
    $ String -> ParsecT s st m String
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    String -> ParsecT s u m String
    string (Char
    '%'Char -> String -> String
    forall a. a -> [a] -> [a]
    :Char
    cChar -> String -> String
    forall a. a -> [a] -> [a]
    :String
    ""))

    tagList :: Monad m => OrgParser m [Tag]
    tagList :: forall (m :: * -> *). Monad m => OrgParser m [Tag]
    tagList = do
      ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m ()
    skipSpaces
      (Text -> Tag) -> [Text] -> [Tag]
    forall a b. (a -> b) -> [a] -> [b]
    map Text -> Tag
    Tag ([Text] -> [Tag])
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Tag]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> 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]
    many (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    orgTagWord ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> 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
    <* 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) [Tag]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Tag]
    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
    forall (m :: * -> *). Monad m => OrgParser m Char
    newline

    setExcludedTags :: [Tag] -> OrgParserState -> OrgParserState
    setExcludedTags :: [Tag] -> OrgParserState -> OrgParserState
    setExcludedTags [Tag]
    tags OrgParserState
    st =
      let finalSet :: Set Tag
    finalSet = if OrgParserState -> Bool
    orgStateExcludeTagsChanged OrgParserState
    st
                       then (Tag -> Set Tag -> Set Tag) -> Set Tag -> [Tag] -> Set Tag
    forall a b. (a -> b -> b) -> b -> [a] -> b
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr Tag -> Set Tag -> Set Tag
    forall a. Ord a => a -> Set a -> Set a
    Set.insert (OrgParserState -> Set Tag
    orgStateExcludeTags OrgParserState
    st) [Tag]
    tags
                       else [Tag] -> Set Tag
    forall a. Ord a => [a] -> Set a
    Set.fromList [Tag]
    tags
      in OrgParserState
    st { orgStateExcludeTags = finalSet, orgStateExcludeTagsChanged = True }

    setSelectedTags :: [Tag] -> OrgParserState -> OrgParserState
    setSelectedTags :: [Tag] -> OrgParserState -> OrgParserState
    setSelectedTags [Tag]
    tags OrgParserState
    st =
      let finalSet :: Set Tag
    finalSet = if OrgParserState -> Bool
    orgStateSelectTagsChanged OrgParserState
    st
                       then (Tag -> Set Tag -> Set Tag) -> Set Tag -> [Tag] -> Set Tag
    forall a b. (a -> b -> b) -> b -> [a] -> b
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr Tag -> Set Tag -> Set Tag
    forall a. Ord a => a -> Set a -> Set a
    Set.insert (OrgParserState -> Set Tag
    orgStateSelectTags OrgParserState
    st) [Tag]
    tags
                       else [Tag] -> Set Tag
    forall a. Ord a => [a] -> Set a
    Set.fromList [Tag]
    tags
      in OrgParserState
    st { orgStateSelectTags = finalSet, orgStateSelectTagsChanged = True }

    setEmphasisPreChar :: Maybe [Char] -> OrgParserState -> OrgParserState
    setEmphasisPreChar :: Maybe String -> OrgParserState -> OrgParserState
    setEmphasisPreChar Maybe String
    csMb OrgParserState
    st =
      let preChars :: String
    preChars = String -> Maybe String -> String
    forall a. a -> Maybe a -> a
    fromMaybe (OrgParserState -> String
    orgStateEmphasisPreChars OrgParserState
    defaultOrgParserState) Maybe String
    csMb
      in OrgParserState
    st { orgStateEmphasisPreChars = preChars }

    setEmphasisPostChar :: Maybe [Char] -> OrgParserState -> OrgParserState
    setEmphasisPostChar :: Maybe String -> OrgParserState -> OrgParserState
    setEmphasisPostChar Maybe String
    csMb OrgParserState
    st =
      let postChars :: String
    postChars = String -> Maybe String -> String
    forall a. a -> Maybe a -> a
    fromMaybe (OrgParserState -> String
    orgStateEmphasisPostChars OrgParserState
    defaultOrgParserState) Maybe String
    csMb
      in OrgParserState
    st { orgStateEmphasisPostChars = postChars }

    -- | Parses emphasis border character like @".,?!"@
    emphChars :: Monad m => OrgParser m (Maybe [Char])
    emphChars :: forall (m :: * -> *). Monad m => OrgParser m (Maybe String)
    emphChars = do
      ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m ()
    skipSpaces
      Text -> Maybe String
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead (Text -> Maybe String)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe String)
    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
    anyLine

    lineOfInlines :: PandocMonad m => OrgParser m (F Inlines)
    lineOfInlines :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    lineOfInlines = do
      OrgParser m ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    updateLastPreCharPos
      F Inlines -> F Inlines
    forall s. Future s Inlines -> Future s Inlines
    trimInlinesF (F Inlines -> F Inlines)
    -> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [F Inlines] -> F Inlines
    forall a. Monoid a => [a] -> a
    mconcat ([F Inlines] -> F Inlines)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
    forall s (m :: * -> *) t u a end.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
    manyTill ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    inline ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    newline

    -- | Parses ToDo sequences / keywords like @TODO DOING | DONE@.
    todoSequence :: Monad m => OrgParser m TodoSequence
    todoSequence :: forall (m :: * -> *). Monad m => OrgParser m TodoSequence
    todoSequence = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence
    forall a b. (a -> b) -> a -> b
    $ do
      todoKws <- OrgParser m [Text]
    forall (m :: * -> *). Monad m => OrgParser m [Text]
    todoKeywords
      doneKws <- optionMaybe $ todoDoneSep *> doneKeywords
      newline
      -- There must be at least one DONE keyword. The last TODO keyword is
      -- taken if necessary.
      case doneKws of
        Just [Text]
    done  -> TodoSequence
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (TodoSequence
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence)
    -> TodoSequence
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence
    forall a b. (a -> b) -> a -> b
    $ [Text] -> [Text] -> TodoSequence
    keywordsToSequence [Text]
    todoKws [Text]
    done
        Maybe [Text]
    Nothing    -> case [Text] -> [Text]
    forall a. [a] -> [a]
    reverse [Text]
    todoKws of
                        []     -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence
    forall a.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero  -- no keywords present
                        (Text
    x:[Text]
    xs) -> TodoSequence
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (TodoSequence
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence)
    -> TodoSequence
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) TodoSequence
    forall a b. (a -> b) -> a -> b
    $ [Text] -> [Text] -> TodoSequence
    keywordsToSequence ([Text] -> [Text]
    forall a. [a] -> [a]
    reverse [Text]
    xs) [Text
    x]

     where
       todoKeyword :: Monad m => OrgParser m Text
       todoKeyword :: forall (m :: * -> *). Monad m => OrgParser m Text
    todoKeyword = do
         keyword <- 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
         let cleanKeyword = (Char -> Bool) -> Text -> Text
    T.takeWhile (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /= Char
    '(') Text
    keyword
         skipSpaces
         return cleanKeyword

       todoKeywords :: Monad m => OrgParser m [Text]
       todoKeywords :: forall (m :: * -> *). Monad m => OrgParser m [Text]
    todoKeywords = 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
    $
         let endOfKeywords :: ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    endOfKeywords = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    todoDoneSep ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> 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 -> ParsecT s u m a
    <|> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    newline
         in 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 end.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
    manyTill ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    todoKeyword (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
    lookAhead ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    endOfKeywords)

       doneKeywords :: Monad m => OrgParser m [Text]
       doneKeywords :: forall (m :: * -> *). Monad m => OrgParser m [Text]
    doneKeywords = 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
    $
         ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall s (m :: * -> *) t u a end.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
    manyTill (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    todoKeyword ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> 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
    <* 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 ()
    optional ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    todoDoneSep) (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    newline)

       todoDoneSep :: Monad m => OrgParser m ()
       todoDoneSep :: forall (m :: * -> *). Monad m => OrgParser m ()
    todoDoneSep = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a b. (a -> b) -> a -> b
    $ 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) ()
    -> 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
    '|' ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> 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) a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    skipSpaces1

       keywordsToSequence :: [Text] -> [Text] -> TodoSequence
       keywordsToSequence :: [Text] -> [Text] -> TodoSequence
    keywordsToSequence [Text]
    todo [Text]
    done =
         let todoMarkers :: TodoSequence
    todoMarkers = (Text -> TodoMarker) -> [Text] -> TodoSequence
    forall a b. (a -> b) -> [a] -> [b]
    map (TodoState -> Text -> TodoMarker
    TodoMarker TodoState
    Todo) [Text]
    todo
             doneMarkers :: TodoSequence
    doneMarkers = (Text -> TodoMarker) -> [Text] -> TodoSequence
    forall a b. (a -> b) -> [a] -> [b]
    map (TodoState -> Text -> TodoMarker
    TodoMarker TodoState
    Done) [Text]
    done
         in TodoSequence
    todoMarkers TodoSequence -> TodoSequence -> TodoSequence
    forall a. [a] -> [a] -> [a]
    ++ TodoSequence
    doneMarkers

    macroDefinition :: Monad m => OrgParser m (Text, [Text] -> Text)
    macroDefinition :: forall (m :: * -> *). Monad m => OrgParser m (Text, [Text] -> Text)
    macroDefinition = ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Text, [Text] -> Text)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Text, [Text] -> Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources
       OrgParserState
       (ReaderT OrgParserLocal m)
       (Text, [Text] -> Text)
     -> ParsecT
          Sources
          OrgParserState
          (ReaderT OrgParserLocal m)
          (Text, [Text] -> Text))
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Text, [Text] -> Text)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Text, [Text] -> Text)
    forall a b. (a -> b) -> a -> b
    $ do
      macroName <- 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 ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> 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
    <* ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m ()
    skipSpaces
      firstPart <- expansionPart
      (elemOrder, parts) <- unzip <$> many ((,) <$> placeholder <*> expansionPart)
      let expander = [Text] -> Text
    forall a. Monoid a => [a] -> a
    mconcat ([Text] -> Text) -> ([Text] -> [Text]) -> [Text] -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Text] -> [Text] -> [Text]
    forall a. [a] -> [a] -> [a]
    alternate (Text
    firstPartText -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    :[Text]
    parts) ([Text] -> [Text]) -> ([Text] -> [Text]) -> [Text] -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Int] -> [Text] -> [Text]
    reorder [Int]
    elemOrder
      return (macroName, expander)
     where
      placeholder :: Monad m => OrgParser m Int
      placeholder :: forall (m :: * -> *). Monad m => OrgParser m Int
    placeholder = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int)
    -> (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text -> Int)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    forall a b.
    (a -> b)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (Int -> Maybe Int -> Int
    forall a. a -> Maybe a -> a
    fromMaybe Int
    1 (Maybe Int -> Int) -> (Text -> Maybe Int) -> Text -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Maybe Int
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead) (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    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) 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 (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    digit

      expansionPart :: Monad m => OrgParser m Text
      expansionPart :: forall (m :: * -> *). Monad m => OrgParser m Text
    expansionPart = 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
    $ 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
    manyChar (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    forall (m :: * -> *). Monad m => OrgParser m Int
    placeholder ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> 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
    *> String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    String -> ParsecT s u m Char
    noneOf String
    "\n\r")

      alternate :: [a] -> [a] -> [a]
      alternate :: forall a. [a] -> [a] -> [a]
    alternate []     [a]
    ys     = [a]
    ys
      alternate [a]
    xs     []     = [a]
    xs
      alternate (a
    x:[a]
    xs) (a
    y:[a]
    ys) = a
    x a -> [a] -> [a]
    forall a. a -> [a] -> [a]
    : a
    y a -> [a] -> [a]
    forall a. a -> [a] -> [a]
    : [a] -> [a] -> [a]
    forall a. [a] -> [a] -> [a]
    alternate [a]
    xs [a]
    ys

      reorder :: [Int] -> [Text] -> [Text]
      reorder :: [Int] -> [Text] -> [Text]
    reorder [Int]
    perm [Text]
    xs =
        let element :: Int -> [Text]
    element Int
    n = Int -> [Text] -> [Text]
    forall a. Int -> [a] -> [a]
    take Int
    1 ([Text] -> [Text]) -> [Text] -> [Text]
    forall a b. (a -> b) -> a -> b
    $ Int -> [Text] -> [Text]
    forall a. Int -> [a] -> [a]
    drop (Int
    n Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) [Text]
    xs
        in (Int -> [Text]) -> [Int] -> [Text]
    forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
    concatMap Int -> [Text]
    element [Int]
    perm