    {-# LANGUAGE ScopedTypeVariables #-}
    {-# LANGUAGE FlexibleContexts  #-}
    {-# LANGUAGE LambdaCase        #-}
    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE RecordWildCards   #-}
    {- |
       Module      : Text.Pandoc.Readers.Org.Blocks
       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 block elements.
    -}
    module Text.Pandoc.Readers.Org.Blocks
      ( blockList
      , meta
      ) where

    import Text.Pandoc.Readers.Org.BlockStarts
    import Text.Pandoc.Readers.Org.DocumentTree (documentTree,
                                                 unprunedHeadlineToBlocks)
    import Text.Pandoc.Readers.Org.Inlines
    import Text.Pandoc.Readers.Org.Meta (metaExport, metaKey, metaLine)
    import Text.Pandoc.Readers.Org.ParserState
    import Text.Pandoc.Readers.Org.Parsing
    import Text.Pandoc.Readers.Org.Shared (cleanLinkText, isImageFilename,
                                           originalLang, translateLang, exportsCode)
    import Text.Pandoc.Readers.LaTeX.Math (inlineEnvironmentNames)
    import Text.Pandoc.Builder (Blocks, Inlines, Many(..))
    import Text.Pandoc.Class.PandocMonad (PandocMonad)
    import Text.Pandoc.Definition
    import Text.Pandoc.Options
    import Text.Pandoc.Shared (compactify, compactifyDL, safeRead)

    import Control.Monad (foldM, guard, mzero, void)
    import Data.Bifunctor (bimap)
    import Data.Char (isSpace)
    import Data.Default (Default)
    import Data.Functor (($>))
    import Data.List (find, foldl')
    import Data.Maybe (fromMaybe, isJust, isNothing)
    import Data.Text (Text)
    import Data.List.NonEmpty (nonEmpty)
    import System.FilePath
    import qualified Data.Foldable as F
    import qualified Data.Text as T
    import qualified Text.Pandoc.Builder as B
    import qualified Text.Pandoc.Walk as Walk
    import Text.Pandoc.Sources (ToSources(..))

    --
    -- parsing blocks
    --

    -- | Get a list of blocks.
    blockList :: PandocMonad m => OrgParser m [Block]
    blockList :: forall (m :: * -> *). PandocMonad m => OrgParser m [Block]
    blockList = do
      fHeadlineTree  <- OrgParser m (F Blocks)
    -> OrgParser m (F Inlines) -> OrgParser m (F Headline)
    forall (m :: * -> *).
    PandocMonad m =>
    OrgParser m (F Blocks)
    -> OrgParser m (F Inlines) -> OrgParser m (F Headline)
    documentTree OrgParser m (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    blocks OrgParser m (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    inline
      st             <- getState
      let headlineTree = F Headline -> OrgParserState -> Headline
    forall s a. Future s a -> s -> a
    runF F Headline
    fHeadlineTree OrgParserState
    st
      unprunedHeadlineToBlocks headlineTree st

    -- | Get the meta information saved in the state.
    meta :: Monad m => OrgParser m Meta
    meta :: forall (m :: * -> *). Monad m => OrgParser m Meta
    meta = do
      meta' <- OrgParser m (F Meta)
    forall (m :: * -> *). Monad m => OrgParser m (F Meta)
    metaExport
      runF meta' <$> getState

    blocks :: PandocMonad m => OrgParser m (F Blocks)
    blocks :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    blocks = [F Blocks] -> F Blocks
    forall a. Monoid a => [a] -> a
    mconcat ([F Blocks] -> F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [F Blocks]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [F Blocks]
    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 Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    block (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    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) Int
    forall (m :: * -> *). Monad m => OrgParser m Int
    headerStart) 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) ()
    forall s (m :: * -> *) t u.
    (Stream s m t, Show t) =>
    ParsecT s u m ()
    eof)

    block :: PandocMonad m => OrgParser m (F Blocks)
    block :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    block = [ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice [ F Blocks
    forall a. Monoid a => a
    mempty F Blocks
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F 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) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    blanklines
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    table
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    orgBlock
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    figure
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). Monad m => OrgParser m (F Blocks)
    example
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    genericDrawer
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    include
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    specialLine
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). Monad m => OrgParser m (F Blocks)
    horizontalRule
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    list
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    latexFragment
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    noteBlock
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    rawOrgLine
                   , ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    paraOrPlain
                   ] ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> String
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> String -> ParsecT s u m a
    <?> String
    "block"

    -- | Parse a horizontal rule into a block element
    horizontalRule :: Monad m => OrgParser m (F Blocks)
    horizontalRule :: forall (m :: * -> *). Monad m => OrgParser m (F Blocks)
    horizontalRule = Blocks -> F Blocks
    forall a. a -> Future OrgParserState a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Blocks
    B.horizontalRule F Blocks
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F 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) ()
    -> 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) ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    hline

    --
    -- Block Attributes
    --

    -- | Attributes that may be added to figures (like a name or caption).
    data BlockAttributes = BlockAttributes
      { BlockAttributes -> Maybe Text
    blockAttrName      :: Maybe Text
      , BlockAttributes -> Maybe (F Inlines)
    blockAttrCaption   :: Maybe (F Inlines)
      , BlockAttributes -> [(Text, Text)]
    blockAttrKeyValues :: [(Text, Text)]
      }

    -- | Convert BlockAttributes into pandoc Attr
    attrFromBlockAttributes :: BlockAttributes -> Attr
    attrFromBlockAttributes :: BlockAttributes -> Attr
    attrFromBlockAttributes BlockAttributes{[(Text, Text)]
    Maybe Text
    Maybe (F Inlines)
    blockAttrName :: BlockAttributes -> Maybe Text
    blockAttrCaption :: BlockAttributes -> Maybe (F Inlines)
    blockAttrKeyValues :: BlockAttributes -> [(Text, Text)]
    blockAttrName :: Maybe Text
    blockAttrCaption :: Maybe (F Inlines)
    blockAttrKeyValues :: [(Text, Text)]
    ..} =
      let
        ident :: Text
    ident   = Text -> Maybe Text -> Text
    forall a. a -> Maybe a -> a
    fromMaybe Text
    forall a. Monoid a => a
    mempty (Maybe Text -> Text) -> Maybe Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> [(Text, Text)] -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    "id" [(Text, Text)]
    blockAttrKeyValues
        classes :: [Text]
    classes = [Text] -> (Text -> [Text]) -> Maybe Text -> [Text]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] Text -> [Text]
    T.words (Maybe Text -> [Text]) -> Maybe Text -> [Text]
    forall a b. (a -> b) -> a -> b
    $ Text -> [(Text, Text)] -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    "class" [(Text, Text)]
    blockAttrKeyValues
        kv :: [(Text, Text)]
    kv      = ((Text, Text) -> Bool) -> [(Text, Text)] -> [(Text, Text)]
    forall a. (a -> Bool) -> [a] -> [a]
    filter ((Text -> [Text] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `notElem` [Text
    "id", Text
    "class"]) (Text -> Bool) -> ((Text, Text) -> Text) -> (Text, Text) -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text, Text) -> Text
    forall a b. (a, b) -> a
    fst) [(Text, Text)]
    blockAttrKeyValues
      in (Text
    ident, [Text]
    classes, [(Text, Text)]
    kv)

    stringyMetaAttribute :: Monad m => OrgParser m (Text, Text)
    stringyMetaAttribute :: forall (m :: * -> *). Monad m => OrgParser m (Text, Text)
    stringyMetaAttribute = 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
    $ do
      OrgParser m ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    metaLineStart
      attrName <- 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) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall end s (m :: * -> *) t st.
    (Show end, Stream s m t) =>
    ParsecT s st m Char -> ParsecT s st m end -> ParsecT s st m Text
    many1TillChar ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    nonspaceChar (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
    ':')
      skipSpaces
      attrValue <- anyLine <|> ("" <$ newline)
      return (attrName, attrValue)

    -- | Parse a set of block attributes. Block attributes are given through
    -- lines like @#+caption: block caption@ or @#+attr_html: :width 20@.
    -- Parsing will fail if any line contains an attribute different from
    -- those attributes known to work on blocks.
    blockAttributes :: PandocMonad m => OrgParser m BlockAttributes
    blockAttributes :: forall (m :: * -> *). PandocMonad m => OrgParser m BlockAttributes
    blockAttributes = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) BlockAttributes
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) BlockAttributes
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) BlockAttributes
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) BlockAttributes)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) BlockAttributes
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) BlockAttributes
    forall a b. (a -> b) -> a -> b
    $ do
      kv <- 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]
    many ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (Text, Text)
    forall (m :: * -> *). Monad m => OrgParser m (Text, Text)
    stringyMetaAttribute
      guard $ all (isBlockAttr . fst) kv
      let caption = (Maybe Text -> (Text, Text) -> Maybe Text)
    -> Maybe Text -> [(Text, Text)] -> Maybe Text
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl' (Text -> Maybe Text -> (Text, Text) -> Maybe Text
    appendValues Text
    "caption") Maybe Text
    forall a. Maybe a
    Nothing [(Text, Text)]
    kv
      let kvAttrs = (Maybe Text -> (Text, Text) -> Maybe Text)
    -> Maybe Text -> [(Text, Text)] -> Maybe Text
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl' (Text -> Maybe Text -> (Text, Text) -> Maybe Text
    appendValues Text
    "attr_html") Maybe Text
    forall a. Maybe a
    Nothing [(Text, Text)]
    kv
      let name    = (Text, Text) -> Text
    forall a b. (a, b) -> b
    snd ((Text, Text) -> Text) -> Maybe (Text, Text) -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ((Text, Text) -> Bool) -> [(Text, Text)] -> Maybe (Text, Text)
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
    find ((Text -> [Text] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [Text
    "name", Text
    "label"]) (Text -> Bool) -> ((Text, Text) -> Text) -> (Text, Text) -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text, Text) -> Text
    forall a b. (a, b) -> a
    fst) ([(Text, Text)] -> [(Text, Text)]
    forall a. [a] -> [a]
    reverse [(Text, Text)]
    kv)
      caption' <- traverse (parseFromString inlines . (<> "\n")) caption
      kvAttrs' <- parseFromString keyValues . (<> "\n") $ fromMaybe mempty kvAttrs
      return BlockAttributes
               { blockAttrName = name
               , blockAttrCaption = caption'
               , blockAttrKeyValues = kvAttrs'
               }
     where
       isBlockAttr :: Text -> Bool
       isBlockAttr :: Text -> Bool
    isBlockAttr = (Text -> [Text] -> Bool) -> [Text] -> Text -> Bool
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip Text -> [Text] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    elem
                     [ Text
    "name", Text
    "label", Text
    "caption"
                     , Text
    "attr_html", Text
    "attr_latex"
                     , Text
    "results"
                     ]

       appendValues :: Text -> Maybe Text -> (Text, Text) -> Maybe Text
       appendValues :: Text -> Maybe Text -> (Text, Text) -> Maybe Text
    appendValues Text
    attrName Maybe Text
    accValue (Text
    key, Text
    value) =
         if Text
    key Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    /= Text
    attrName
         then Maybe Text
    accValue
         else case Maybe Text
    accValue of
                Just Text
    acc -> Text -> Maybe Text
    forall a. a -> Maybe a
    Just (Text -> Maybe Text) -> Text -> Maybe Text
    forall a b. (a -> b) -> a -> b
    $ Text
    acc Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    " " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    value
                Maybe Text
    Nothing  -> Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    value

    -- | Parse key-value pairs for HTML attributes
    keyValues :: Monad m => OrgParser m [(Text, Text)]
    keyValues :: forall (m :: * -> *). Monad m => OrgParser m [(Text, Text)]
    keyValues = 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)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [(Text, 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 ((,) (Text -> Text -> (Text, Text))
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Text -> (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
    key ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Text -> (Text, Text))
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Text, 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) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    value) ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    newline
     where
       key :: Monad m => OrgParser m Text
       key :: forall (m :: * -> *). Monad m => OrgParser m Text
    key = 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) ()
    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) 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 s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    nonspaceChar

       value :: Monad m => OrgParser m Text
       value :: forall (m :: * -> *). Monad m => OrgParser m Text
    value = 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) 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) ()
    -> 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
    anyChar ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    endOfValue

       endOfValue :: Monad m => OrgParser m ()
       endOfValue :: forall (m :: * -> *). Monad m => OrgParser m ()
    endOfValue = 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) String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a b. (a -> b) -> a -> b
    $ ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    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) 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
    spaceChar ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    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) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    key))
                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) ()
    -> 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) ()
    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) ()
    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) 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)

    --
    -- Org Blocks (#+begin_... / #+end_...)
    --

    -- | Read an org-mode block delimited by #+begin_type and #+end_type.
    orgBlock :: PandocMonad m => OrgParser m (F Blocks)
    orgBlock :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    orgBlock = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      blockAttrs <- OrgParser m BlockAttributes
    forall (m :: * -> *). PandocMonad m => OrgParser m BlockAttributes
    blockAttributes
      blkType <- blockHeaderStart
      ($ blkType) $
        case T.toLower blkType of
          Text
    "export"    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). Monad m => Text -> OrgParser m (F Blocks)
    exportBlock
          Text
    "comment"   -> (Text -> F Blocks)
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    Monad m =>
    (Text -> F Blocks) -> Text -> OrgParser m (F Blocks)
    rawBlockLines (F Blocks -> Text -> F Blocks
    forall a b. a -> b -> a
    const F Blocks
    forall a. Monoid a => a
    mempty)
          Text
    "html"      -> (Text -> F Blocks)
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    Monad m =>
    (Text -> F Blocks) -> Text -> OrgParser m (F Blocks)
    rawBlockLines (Blocks -> F Blocks
    forall a. a -> Future OrgParserState a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> F Blocks) -> (Text -> Blocks) -> Text -> F Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text -> Blocks
    B.rawBlock (Text -> Text
    lowercase Text
    blkType))
          Text
    "latex"     -> (Text -> F Blocks)
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    Monad m =>
    (Text -> F Blocks) -> Text -> OrgParser m (F Blocks)
    rawBlockLines (Blocks -> F Blocks
    forall a. a -> Future OrgParserState a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> F Blocks) -> (Text -> Blocks) -> Text -> F Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text -> Blocks
    B.rawBlock (Text -> Text
    lowercase Text
    blkType))
          Text
    "ascii"     -> (Text -> F Blocks)
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    Monad m =>
    (Text -> F Blocks) -> Text -> OrgParser m (F Blocks)
    rawBlockLines (Blocks -> F Blocks
    forall a. a -> Future OrgParserState a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> F Blocks) -> (Text -> Blocks) -> Text -> F Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text -> Blocks
    B.rawBlock (Text -> Text
    lowercase Text
    blkType))
          Text
    "example"   -> BlockAttributes
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    BlockAttributes -> Text -> OrgParser m (F Blocks)
    exampleBlock BlockAttributes
    blockAttrs
          Text
    "quote"     -> (F Blocks -> F Blocks)
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    (F Blocks -> F Blocks) -> Text -> OrgParser m (F Blocks)
    parseBlockLines ((Blocks -> Blocks) -> F Blocks -> F Blocks
    forall a b.
    (a -> b) -> Future OrgParserState a -> Future OrgParserState b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Blocks -> Blocks
    B.blockQuote)
          Text
    "verse"     -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> OrgParser m (F Blocks)
    verseBlock
          Text
    "src"       -> BlockAttributes
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    BlockAttributes -> Text -> OrgParser m (F Blocks)
    codeBlock BlockAttributes
    blockAttrs
          Text
    "note"      -> Text
    -> BlockAttributes
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> BlockAttributes -> Text -> OrgParser m (F Blocks)
    admonitionBlock Text
    "note" BlockAttributes
    blockAttrs
          Text
    "warning"   -> Text
    -> BlockAttributes
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> BlockAttributes -> Text -> OrgParser m (F Blocks)
    admonitionBlock Text
    "warning" BlockAttributes
    blockAttrs
          Text
    "tip"       -> Text
    -> BlockAttributes
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> BlockAttributes -> Text -> OrgParser m (F Blocks)
    admonitionBlock Text
    "tip" BlockAttributes
    blockAttrs
          Text
    "caution"   -> Text
    -> BlockAttributes
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> BlockAttributes -> Text -> OrgParser m (F Blocks)
    admonitionBlock Text
    "caution" BlockAttributes
    blockAttrs
          Text
    "important" -> Text
    -> BlockAttributes
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> BlockAttributes -> Text -> OrgParser m (F Blocks)
    admonitionBlock Text
    "important" BlockAttributes
    blockAttrs
          Text
    _           ->
            -- case-sensitive checks
            case Text
    blkType of
              Text
    "abstract" -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> OrgParser m (F Blocks)
    metadataBlock
              Text
    _ -> (F Blocks -> F Blocks)
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    (F Blocks -> F Blocks) -> Text -> OrgParser m (F Blocks)
    parseBlockLines ((F Blocks -> F Blocks)
     -> Text
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> (F Blocks -> F Blocks)
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $
                       let (Text
    ident, [Text]
    classes, [(Text, Text)]
    kv) = BlockAttributes -> Attr
    attrFromBlockAttributes BlockAttributes
    blockAttrs
                       in (Blocks -> Blocks) -> F Blocks -> F Blocks
    forall a b.
    (a -> b) -> Future OrgParserState a -> Future OrgParserState b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap ((Blocks -> Blocks) -> F Blocks -> F Blocks)
    -> (Blocks -> Blocks) -> F Blocks -> F Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Blocks -> Blocks
    B.divWith (Text
    ident, [Text]
    classes [Text] -> [Text] -> [Text]
    forall a. [a] -> [a] -> [a]
    ++ [Text
    blkType], [(Text, Text)]
    kv)
     where
       blockHeaderStart :: Monad m => OrgParser m Text
       blockHeaderStart :: forall (m :: * -> *). Monad m => OrgParser m Text
    blockHeaderStart = 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) ()
    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) 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
    *> Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s st m Text
    stringAnyCase Text
    "#+begin_" ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) 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
    -> 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
    forall (m :: * -> *). Monad m => OrgParser m Text
    orgArgWord

       lowercase :: Text -> Text
       lowercase :: Text -> Text
    lowercase = Text -> Text
    T.toLower

    admonitionBlock :: PandocMonad m
                    => Text -> BlockAttributes -> Text -> OrgParser m (F Blocks)
    admonitionBlock :: forall (m :: * -> *).
    PandocMonad m =>
    Text -> BlockAttributes -> Text -> OrgParser m (F Blocks)
    admonitionBlock Text
    blockType BlockAttributes
    blockAttrs Text
    rawtext = do
      bls <- (F Blocks -> F Blocks) -> Text -> OrgParser m (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    (F Blocks -> F Blocks) -> Text -> OrgParser m (F Blocks)
    parseBlockLines F Blocks -> F Blocks
    forall a. a -> a
    id Text
    rawtext
      let id' = Text -> Maybe Text -> Text
    forall a. a -> Maybe a -> a
    fromMaybe Text
    forall a. Monoid a => a
    mempty (Maybe Text -> Text) -> Maybe Text -> Text
    forall a b. (a -> b) -> a -> b
    $ BlockAttributes -> Maybe Text
    blockAttrName BlockAttributes
    blockAttrs
      pure $ fmap
        (B.divWith (id', [blockType], []) .
         (B.divWith ("", ["title"], []) (B.para (B.str (T.toTitle blockType))) <>))
        bls

    exampleBlock :: PandocMonad m => BlockAttributes -> Text -> OrgParser m (F Blocks)
    exampleBlock :: forall (m :: * -> *).
    PandocMonad m =>
    BlockAttributes -> Text -> OrgParser m (F Blocks)
    exampleBlock BlockAttributes
    blockAttrs Text
    _label = do
      ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m ()
    skipSpaces
      (classes, kv) <- OrgParser m ([Text], [(Text, Text)])
    forall (m :: * -> *).
    Monad m =>
    OrgParser m ([Text], [(Text, Text)])
    switchesAsAttributes
      newline
      content <- rawBlockContent "example"
      let id' = Text -> Maybe Text -> Text
    forall a. a -> Maybe a -> a
    fromMaybe Text
    forall a. Monoid a => a
    mempty (Maybe Text -> Text) -> Maybe Text -> Text
    forall a b. (a -> b) -> a -> b
    $ BlockAttributes -> Maybe Text
    blockAttrName BlockAttributes
    blockAttrs
      let codeBlck = Attr -> Text -> Blocks
    B.codeBlockWith (Text
    id', Text
    "example"Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    :[Text]
    classes, [(Text, Text)]
    kv) Text
    content
      return . return $ codeBlck

    rawBlockLines :: Monad m => (Text   -> F Blocks) -> Text -> OrgParser m (F Blocks)
    rawBlockLines :: forall (m :: * -> *).
    Monad m =>
    (Text -> F Blocks) -> Text -> OrgParser m (F Blocks)
    rawBlockLines Text -> F Blocks
    f Text
    blockType = OrgParser m ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    ignHeaders OrgParser m ()
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    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
    *> (Text -> F Blocks
    f (Text -> F Blocks)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => Text -> OrgParser m Text
    rawBlockContent Text
    blockType)

    parseBlockLines :: PandocMonad m => (F Blocks -> F Blocks) -> Text -> OrgParser m (F Blocks)
    parseBlockLines :: forall (m :: * -> *).
    PandocMonad m =>
    (F Blocks -> F Blocks) -> Text -> OrgParser m (F Blocks)
    parseBlockLines F Blocks -> F Blocks
    f Text
    blockType = OrgParser m ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    ignHeaders OrgParser m ()
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    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
    *> (F Blocks -> F Blocks
    f (F Blocks -> F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    parsedBlockContent)
     where
       parsedBlockContent :: PandocMonad m => OrgParser m (F Blocks)
       parsedBlockContent :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    parsedBlockContent = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
         raw <- Text -> OrgParser m Text
    forall (m :: * -> *). Monad m => Text -> OrgParser m Text
    rawBlockContent Text
    blockType
         parseFromString blocks (raw <> "\n")

    -- | Read the raw string content of a block
    rawBlockContent :: Monad m => Text -> OrgParser m Text
    rawBlockContent :: forall (m :: * -> *). Monad m => Text -> OrgParser m Text
    rawBlockContent Text
    blockType = 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
      blkLines <- 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
    rawLine ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    blockEnder
      tabStop <- getOption readerTabStop
      trimP <- orgStateTrimLeadBlkIndent <$> getState
      -- split lines into indentation/contents tuples
      let splitLines = (Text -> (Text, Text)) -> [Text] -> [(Text, Text)]
    forall a b. (a -> b) -> [a] -> [b]
    map ((Char -> Bool) -> Text -> (Text, Text)
    T.span (\Char
    c -> Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Char
    ' ' Bool -> Bool -> Bool
    || Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Char
    '\t')) [Text]
    blkLines
      let countSpaces = (Char -> Int -> Int) -> Int -> Text -> Int
    forall a. (Char -> a -> a) -> a -> Text -> a
    T.foldr (\case {Char
    '\t' -> (Int
    tabStop Int -> Int -> Int
    forall a. Num a => a -> a -> a
    +); Char
    _ -> (Int
    1 Int -> Int -> Int
    forall a. Num a => a -> a -> a
    +)}) Int
    0
      let shortestIndent = ((Text, Text) -> Int -> Int) -> Int -> [(Text, Text)] -> Int
    forall a b. (a -> b -> b) -> b -> [a] -> b
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr (Int -> Int -> Int
    forall a. Ord a => a -> a -> a
    min (Int -> Int -> Int)
    -> ((Text, Text) -> Int) -> (Text, Text) -> Int -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Int
    countSpaces (Text -> Int) -> ((Text, Text) -> Text) -> (Text, Text) -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text, Text) -> Text
    forall a b. (a, b) -> a
    fst) Int
    forall a. Bounded a => a
    maxBound
                         ([(Text, Text)] -> Int)
    -> ([(Text, Text)] -> [(Text, Text)]) -> [(Text, Text)] -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((Text, Text) -> Bool) -> [(Text, Text)] -> [(Text, Text)]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (Bool -> Bool
    not (Bool -> Bool) -> ((Text, Text) -> Bool) -> (Text, Text) -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Bool
    T.null (Text -> Bool) -> ((Text, Text) -> Text) -> (Text, Text) -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text, Text) -> Text
    forall a b. (a, b) -> b
    snd) -- ignore empty lines
                         ([(Text, Text)] -> Int) -> [(Text, Text)] -> Int
    forall a b. (a -> b) -> a -> b
    $ [(Text, Text)]
    splitLines
      let tabsToSpaces = HasCallStack => Text -> Text -> Text -> Text
    Text -> Text -> Text -> Text
    T.replace Text
    "\t" (Int -> Text -> Text
    T.replicate Int
    tabStop Text
    " ")
      let reIndent = if Bool
    trimP
                     then (Int -> Text -> Text
    T.drop Int
    shortestIndent (Text -> Text) -> (Text -> Text) -> Text -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    tabsToSpaces)
                     else Text -> Text
    forall a. a -> a
    id

      T.unlines (map (uncurry T.append . bimap reIndent commaEscaped) splitLines)
       <$ updateState (\OrgParserState
    s -> OrgParserState
    s { orgStateTrimLeadBlkIndent = True })
     where
       rawLine :: Monad m => OrgParser m Text
       rawLine :: forall (m :: * -> *). Monad m => OrgParser m Text
    rawLine = 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
    $ (Text
    "" Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    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) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline) ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> 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 -> ParsecT s u m a
    <|> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine

       blockEnder :: Monad m => OrgParser m ()
       blockEnder :: forall (m :: * -> *). Monad m => OrgParser m ()
    blockEnder = 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
    $ 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) Text
    -> 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
    <* Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s st m Text
    stringAnyCase (Text
    "#+end_" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    blockType)

       commaEscaped :: Text -> Text
    commaEscaped Text
    suff = case Text -> Maybe (Char, Text)
    T.uncons Text
    suff of
         Just (Char
    ',', Text
    cs)
           | Text
    "*"  <- Int -> Text -> Text
    T.take Int
    1 Text
    cs -> Text
    cs
           | Text
    "#+" <- Int -> Text -> Text
    T.take Int
    2 Text
    cs -> Text
    cs
         Maybe (Char, Text)
    _                       -> Text
    suff

    -- | Read but ignore all remaining block headers.
    ignHeaders :: Monad m => OrgParser m ()
    ignHeaders :: forall (m :: * -> *). Monad m => OrgParser m ()
    ignHeaders = (() ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> 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
    <$ ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    newline) 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) 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
    <$ ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine)

    -- | Read a block containing code intended for export in specific backends
    -- only.
    exportBlock :: Monad m => Text -> OrgParser m (F Blocks)
    exportBlock :: forall (m :: * -> *). Monad m => Text -> OrgParser m (F Blocks)
    exportBlock Text
    blockType = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      exportType <- 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) 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
    forall (m :: * -> *). Monad m => OrgParser m Text
    orgArgWord 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 (m :: * -> *). Monad m => OrgParser m ()
    ignHeaders
      contents   <- rawBlockContent blockType
      returnF (B.rawBlock (T.toLower exportType) contents)

    verseBlock :: PandocMonad m => Text -> OrgParser m (F Blocks)
    verseBlock :: forall (m :: * -> *).
    PandocMonad m =>
    Text -> OrgParser m (F Blocks)
    verseBlock Text
    blockType = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      OrgParser m ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    ignHeaders
      content <- Text -> OrgParser m Text
    forall (m :: * -> *). Monad m => Text -> OrgParser m Text
    rawBlockContent Text
    blockType
      fmap B.lineBlock . sequence
        <$> mapM parseVerseLine (T.lines content)
     where
       -- replace initial spaces with nonbreaking spaces to preserve
       -- indentation, parse the rest as normal inline
       parseVerseLine :: PandocMonad m => Text -> OrgParser m (F Inlines)
       parseVerseLine :: forall (m :: * -> *).
    PandocMonad m =>
    Text -> OrgParser m (F Inlines)
    parseVerseLine Text
    cs = do
         let (Text
    initialSpaces, Text
    indentedLine) = (Char -> Bool) -> Text -> (Text, Text)
    T.span Char -> Bool
    isSpace Text
    cs
         let nbspIndent :: Inlines
    nbspIndent = if Text -> Bool
    T.null Text
    initialSpaces
                          then Inlines
    forall a. Monoid a => a
    mempty
                          else Text -> Inlines
    B.str (Text -> Inlines) -> Text -> Inlines
    forall a b. (a -> b) -> a -> b
    $ (Char -> Char) -> Text -> Text
    T.map (Char -> Char -> Char
    forall a b. a -> b -> a
    const Char
    '\160') Text
    initialSpaces
         line <- OrgParser m (F Inlines) -> Text -> OrgParser m (F Inlines)
    forall (m :: * -> *) a.
    Monad m =>
    OrgParser m a -> Text -> OrgParser m a
    parseFromString OrgParser m (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    inlines (Text
    indentedLine Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    "\n")
         return (trimInlinesF $ pure nbspIndent <> line)

    -- | Parses an environment of the given name and adds the result to the document
    -- metadata under a key of the same name.
    metadataBlock :: PandocMonad m => Text -> OrgParser m (F Blocks)
    metadataBlock :: forall (m :: * -> *).
    PandocMonad m =>
    Text -> OrgParser m (F Blocks)
    metadataBlock Text
    blockType = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      content <- (F Blocks -> F Blocks)
    -> Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    (F Blocks -> F Blocks) -> Text -> OrgParser m (F Blocks)
    parseBlockLines F Blocks -> F Blocks
    forall a. a -> a
    id Text
    blockType
      meta'   <- orgStateMeta <$> getState
      updateState $ \OrgParserState
    st ->
        OrgParserState
    st { orgStateMeta = B.setMeta blockType <$> content <*> meta' }
      return mempty

    -- | Read a code block and the associated results block if present.  Which of
    -- the blocks is included in the output is determined using the "exports"
    -- argument in the block header.
    codeBlock :: PandocMonad m => BlockAttributes -> Text -> OrgParser m (F Blocks)
    codeBlock :: forall (m :: * -> *).
    PandocMonad m =>
    BlockAttributes -> Text -> OrgParser m (F Blocks)
    codeBlock BlockAttributes
    blockAttrs Text
    blockType = do
      ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m ()
    skipSpaces
      (classes, kv)  <- OrgParser m ([Text], [(Text, Text)])
    forall (m :: * -> *).
    Monad m =>
    OrgParser m ([Text], [(Text, Text)])
    codeHeaderArgs OrgParser m ([Text], [(Text, Text)])
    -> OrgParser m ([Text], [(Text, Text)])
    -> OrgParser m ([Text], [(Text, Text)])
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> (([Text], [(Text, Text)])
    forall a. Monoid a => a
    mempty ([Text], [(Text, Text)])
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> OrgParser m ([Text], [(Text, Text)])
    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 ()
    ignHeaders)
      content        <- rawBlockContent blockType
      resultsContent <- option mempty babelResultsBlock
      let identifier = Text -> Maybe Text -> Text
    forall a. a -> Maybe a -> a
    fromMaybe Text
    forall a. Monoid a => a
    mempty (Maybe Text -> Text) -> Maybe Text -> Text
    forall a b. (a -> b) -> a -> b
    $ BlockAttributes -> Maybe Text
    blockAttrName BlockAttributes
    blockAttrs
      let classes'   = case [Text]
    classes of
                         Text
    c:[Text]
    cs | Just Text
    c' <- Text -> Text -> Maybe Text
    T.stripPrefix Text
    "jupyter-" Text
    c ->
                                Text
    c' Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    : Text
    "code" Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    : [Text]
    cs
                         [Text]
    _ -> [Text]
    classes
      let codeBlk    = Attr -> Text -> Blocks
    B.codeBlockWith (Text
    identifier, [Text]
    classes', [(Text, Text)]
    kv) Text
    content
      let wrap       = (Blocks -> F Blocks)
    -> (F Inlines -> Blocks -> F Blocks)
    -> Maybe (F Inlines)
    -> Blocks
    -> F Blocks
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Blocks -> F Blocks
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure F Inlines -> Blocks -> F Blocks
    addCaption (BlockAttributes -> Maybe (F Inlines)
    blockAttrCaption BlockAttributes
    blockAttrs)
      return $
        (if exportsCode kv    then wrap codeBlk   else mempty) <>
        (if exportsResults kv then resultsContent else mempty)
     where
       addCaption :: F Inlines -> Blocks -> F Blocks
       addCaption :: F Inlines -> Blocks -> F Blocks
    addCaption F Inlines
    caption Blocks
    blk = Attr -> Blocks -> Blocks
    B.divWith (Text
    "", [Text
    "captioned-content"], [])
                             (Blocks -> Blocks) -> F Blocks -> F Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (F Inlines -> F Blocks
    mkCaptionBlock F Inlines
    caption F Blocks -> F Blocks -> F Blocks
    forall a. Semigroup a => a -> a -> a
    <> Blocks -> F Blocks
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Blocks
    blk)

       mkCaptionBlock :: F Inlines -> F Blocks
       mkCaptionBlock :: F Inlines -> F Blocks
    mkCaptionBlock = (Inlines -> Blocks) -> F Inlines -> F Blocks
    forall a b.
    (a -> b) -> Future OrgParserState a -> Future OrgParserState b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (Attr -> Blocks -> Blocks
    B.divWith (Text
    "", [Text
    "caption"], []) (Blocks -> Blocks) -> (Inlines -> Blocks) -> Inlines -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Inlines -> Blocks
    B.plain)

       exportsResults :: [(Text, Text)] -> Bool
       exportsResults :: [(Text, Text)] -> Bool
    exportsResults = Bool -> (Text -> Bool) -> Maybe Text -> Bool
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Bool
    False (Text -> [Text] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [Text
    "results", Text
    "both"]) (Maybe Text -> Bool)
    -> ([(Text, Text)] -> Maybe Text) -> [(Text, Text)] -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> [(Text, Text)] -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    "exports"

    -- | Parse the result of an evaluated babel code block.
    babelResultsBlock :: PandocMonad m => OrgParser m (F Blocks)
    babelResultsBlock :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    babelResultsBlock = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      OrgParser m Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    blanklines
      ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) ()
    resultsMarker 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) ()
    -> 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) ()
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> (ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> (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) ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . 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) ())
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a b. (a -> b) -> a -> b
    $
          OrgParser 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) ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    metaLineStart ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> OrgParser m Text -> OrgParser 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
    *> OrgParser m Text
    forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
    anyLineNewline) ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) ()
    resultsMarker)
      ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    block
     where
      resultsMarker :: ParsecT Sources u (ReaderT OrgParserLocal m) ()
    resultsMarker = ParsecT Sources u (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources u (ReaderT OrgParserLocal m) ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources u (ReaderT OrgParserLocal m) ()
     -> ParsecT Sources u (ReaderT OrgParserLocal m) ())
    -> (ParsecT Sources u (ReaderT OrgParserLocal m) Char
        -> ParsecT Sources u (ReaderT OrgParserLocal m) ())
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources u (ReaderT OrgParserLocal m) ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ParsecT Sources u (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources u (ReaderT OrgParserLocal m) ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void (ParsecT Sources u (ReaderT OrgParserLocal m) Char
     -> ParsecT Sources u (ReaderT OrgParserLocal m) ())
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources u (ReaderT OrgParserLocal m) ()
    forall a b. (a -> b) -> a -> b
    $ Text -> ParsecT Sources u (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s st m Text
    stringAnyCase Text
    "#+RESULTS:" ParsecT Sources u (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Char
    forall a b.
    ParsecT Sources u (ReaderT OrgParserLocal m) a
    -> ParsecT Sources u (ReaderT OrgParserLocal m) b
    -> ParsecT Sources u (ReaderT OrgParserLocal m) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources u (ReaderT OrgParserLocal m) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline

    -- | Parse code block arguments
    codeHeaderArgs :: Monad m => OrgParser m ([Text], [(Text, Text)])
    codeHeaderArgs :: forall (m :: * -> *).
    Monad m =>
    OrgParser m ([Text], [(Text, Text)])
    codeHeaderArgs = 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
      language   <- 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) 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
    forall (m :: * -> *). Monad m => OrgParser m Text
    orgArgWord
      (switchClasses, switchKv) <- switchesAsAttributes
      parameters <- manyTill blockOption newline
      return ( translateLang language : switchClasses
             , originalLang language <> switchKv <> parameters
             )

    switchesAsAttributes :: Monad m => OrgParser m ([Text], [(Text, Text)])
    switchesAsAttributes :: forall (m :: * -> *).
    Monad m =>
    OrgParser m ([Text], [(Text, Text)])
    switchesAsAttributes = 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
      switches <- 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, Maybe Text, SwitchPolarity)]
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         [(Char, Maybe Text, SwitchPolarity)]
    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, Maybe Text, SwitchPolarity)]
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         [(Char, Maybe Text, SwitchPolarity)]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (OrgParser m (Char, Maybe Text, SwitchPolarity)
    forall (m :: * -> *).
    Monad m =>
    OrgParser m (Char, Maybe Text, SwitchPolarity)
    switch OrgParser m (Char, Maybe Text, SwitchPolarity)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         [(Char, Maybe Text, SwitchPolarity)]
    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]
    `sepBy` 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
    spaceChar)
      return $ foldr addToAttr ([], []) switches
     where
      addToAttr :: (Char, Maybe Text, SwitchPolarity)
                -> ([Text], [(Text, Text)])
                -> ([Text], [(Text, Text)])
      addToAttr :: (Char, Maybe Text, SwitchPolarity)
    -> ([Text], [(Text, Text)]) -> ([Text], [(Text, Text)])
    addToAttr (Char
    'n', Maybe Text
    lineNum, SwitchPolarity
    pol) ([Text]
    cls, [(Text, Text)]
    kv) =
        let kv' :: [(Text, Text)]
    kv' = case Maybe Text
    lineNum of
                    Just Text
    num -> (Text
    "startFrom", Text
    num)(Text, Text) -> [(Text, Text)] -> [(Text, Text)]
    forall a. a -> [a] -> [a]
    :[(Text, Text)]
    kv
                    Maybe Text
    Nothing  -> [(Text, Text)]
    kv
            cls' :: [Text]
    cls' = case SwitchPolarity
    pol of
                     SwitchPolarity
    SwitchPlus  -> Text
    "continuedSourceBlock"Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    :[Text]
    cls
                     SwitchPolarity
    SwitchMinus -> [Text]
    cls
        in (Text
    "numberLines"Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    :[Text]
    cls', [(Text, Text)]
    kv')
      addToAttr (Char, Maybe Text, SwitchPolarity)
    _ ([Text], [(Text, Text)])
    x = ([Text], [(Text, Text)])
    x

    -- | Whether a switch flag is specified with @+@ or @-@.
    data SwitchPolarity = SwitchPlus | SwitchMinus
      deriving (Int -> SwitchPolarity -> ShowS
    [SwitchPolarity] -> ShowS
    SwitchPolarity -> String
    (Int -> SwitchPolarity -> ShowS)
    -> (SwitchPolarity -> String)
    -> ([SwitchPolarity] -> ShowS)
    -> Show SwitchPolarity
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> SwitchPolarity -> ShowS
    showsPrec :: Int -> SwitchPolarity -> ShowS
    $cshow :: SwitchPolarity -> String
    show :: SwitchPolarity -> String
    $cshowList :: [SwitchPolarity] -> ShowS
    showList :: [SwitchPolarity] -> ShowS
    Show, SwitchPolarity -> SwitchPolarity -> Bool
    (SwitchPolarity -> SwitchPolarity -> Bool)
    -> (SwitchPolarity -> SwitchPolarity -> Bool) -> Eq SwitchPolarity
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: SwitchPolarity -> SwitchPolarity -> Bool
    == :: SwitchPolarity -> SwitchPolarity -> Bool
    $c/= :: SwitchPolarity -> SwitchPolarity -> Bool
    /= :: SwitchPolarity -> SwitchPolarity -> Bool
    Eq)

    -- | Parses a switch's polarity.
    switchPolarity :: Monad m => OrgParser m SwitchPolarity
    switchPolarity :: forall (m :: * -> *). Monad m => OrgParser m SwitchPolarity
    switchPolarity = (SwitchPolarity
    SwitchMinus SwitchPolarity
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) SwitchPolarity
    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
    <$ 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) SwitchPolarity
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) SwitchPolarity
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) SwitchPolarity
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> (SwitchPolarity
    SwitchPlus SwitchPolarity
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) SwitchPolarity
    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
    <$ 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 a source block switch option.
    switch :: Monad m => OrgParser m (Char, Maybe Text, SwitchPolarity)
    switch :: forall (m :: * -> *).
    Monad m =>
    OrgParser m (Char, Maybe Text, SwitchPolarity)
    switch = ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Char, Maybe Text, SwitchPolarity)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources
       OrgParserState
       (ReaderT OrgParserLocal m)
       (Char, Maybe Text, SwitchPolarity)
     -> ParsecT
          Sources
          OrgParserState
          (ReaderT OrgParserLocal m)
          (Char, Maybe Text, SwitchPolarity))
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    forall a b. (a -> b) -> a -> b
    $ ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Char, Maybe Text, SwitchPolarity)
    forall (m :: * -> *).
    Monad m =>
    OrgParser m (Char, Maybe Text, SwitchPolarity)
    lineNumberSwitch ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Char, Maybe Text, SwitchPolarity)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    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, Maybe Text, SwitchPolarity)
    labelSwitch
                   ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Char, Maybe Text, SwitchPolarity)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    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, Maybe Text, SwitchPolarity)
    forall (m :: * -> *).
    Monad m =>
    OrgParser m (Char, Maybe Text, SwitchPolarity)
    whitespaceSwitch ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Char, Maybe Text, SwitchPolarity)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    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, Maybe Text, SwitchPolarity)
    forall {a}.
    ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Char, Maybe a, SwitchPolarity)
    simpleSwitch
     where
       simpleSwitch :: ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Char, Maybe a, SwitchPolarity)
    simpleSwitch = (\SwitchPolarity
    pol Char
    c -> (Char
    c, Maybe a
    forall a. Maybe a
    Nothing, SwitchPolarity
    pol)) (SwitchPolarity -> Char -> (Char, Maybe a, SwitchPolarity))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) SwitchPolarity
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char -> (Char, Maybe a, SwitchPolarity))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) SwitchPolarity
    forall (m :: * -> *). Monad m => OrgParser m SwitchPolarity
    switchPolarity ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Char -> (Char, Maybe a, SwitchPolarity))
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe a, SwitchPolarity)
    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
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    letter
       labelSwitch :: ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Char, Maybe Text, SwitchPolarity)
    labelSwitch = Char
    -> OrgParser m Text
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    forall (m :: * -> *).
    Monad m =>
    Char
    -> OrgParser m Text
    -> OrgParser m (Char, Maybe Text, SwitchPolarity)
    genericSwitch Char
    'l' (OrgParser m Text
     -> ParsecT
          Sources
          OrgParserState
          (ReaderT OrgParserLocal m)
          (Char, Maybe Text, SwitchPolarity))
    -> OrgParser m Text
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    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
    -> OrgParser m Text -> OrgParser 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
    -> OrgParser m Text
    forall end s (m :: * -> *) t st.
    (Show end, Stream s m t) =>
    ParsecT s st m Char -> ParsecT s st m end -> ParsecT s st m Text
    many1TillChar ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    nonspaceChar (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
    '"')

    whitespaceSwitch :: Monad m => OrgParser m (Char, Maybe Text, SwitchPolarity)
    whitespaceSwitch :: forall (m :: * -> *).
    Monad m =>
    OrgParser m (Char, Maybe Text, SwitchPolarity)
    whitespaceSwitch = 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 String
    "-i"
      (OrgParserState -> OrgParserState)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((OrgParserState -> OrgParserState)
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> (OrgParserState -> OrgParserState)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a b. (a -> b) -> a -> b
    $ \OrgParserState
    s -> OrgParserState
    s { orgStateTrimLeadBlkIndent = False }
      (Char, Maybe Text, SwitchPolarity)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Char
    'i', Maybe Text
    forall a. Maybe a
    Nothing, SwitchPolarity
    SwitchMinus)

    -- | Generic source block switch-option parser.
    genericSwitch :: Monad m
                  => Char
                  -> OrgParser m Text
                  -> OrgParser m (Char, Maybe Text, SwitchPolarity)
    genericSwitch :: forall (m :: * -> *).
    Monad m =>
    Char
    -> OrgParser m Text
    -> OrgParser m (Char, Maybe Text, SwitchPolarity)
    genericSwitch Char
    c OrgParser m Text
    p = ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Char, Maybe Text, SwitchPolarity)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources
       OrgParserState
       (ReaderT OrgParserLocal m)
       (Char, Maybe Text, SwitchPolarity)
     -> ParsecT
          Sources
          OrgParserState
          (ReaderT OrgParserLocal m)
          (Char, Maybe Text, SwitchPolarity))
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Char, Maybe Text, SwitchPolarity)
    forall a b. (a -> b) -> a -> b
    $ do
      polarity <- OrgParser m SwitchPolarity
    forall (m :: * -> *). Monad m => OrgParser m SwitchPolarity
    switchPolarity OrgParser m SwitchPolarity
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> OrgParser m SwitchPolarity
    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
    c OrgParser m SwitchPolarity
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> OrgParser m SwitchPolarity
    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
      arg <- optionMaybe p
      return (c, arg, polarity)

    -- | Reads a line number switch option. The line number switch can be used with
    -- example and source blocks.
    lineNumberSwitch :: Monad m => OrgParser m (Char, Maybe Text, SwitchPolarity)
    lineNumberSwitch :: forall (m :: * -> *).
    Monad m =>
    OrgParser m (Char, Maybe Text, SwitchPolarity)
    lineNumberSwitch = Char
    -> OrgParser m Text
    -> OrgParser m (Char, Maybe Text, SwitchPolarity)
    forall (m :: * -> *).
    Monad m =>
    Char
    -> OrgParser m Text
    -> OrgParser m (Char, Maybe Text, SwitchPolarity)
    genericSwitch Char
    'n' (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> OrgParser 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
    digit)

    blockOption :: Monad m => OrgParser m (Text, Text)
    blockOption :: forall (m :: * -> *). Monad m => OrgParser m (Text, Text)
    blockOption = 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
    $ do
      argKey <- OrgParser m Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    orgArgKey
      paramValue <- option "yes" orgParamValue
      return (argKey, paramValue)

    orgParamValue :: Monad m => OrgParser m Text
    orgParamValue :: forall (m :: * -> *). Monad m => OrgParser m Text
    orgParamValue = 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 -> Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) 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 String -> Text
    T.pack (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    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) ()
    -> 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) 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) ()
    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) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    orgArgKey
        ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    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" ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    forall end s (m :: * -> *) t st a.
    (Show end, Stream s m t) =>
    ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
    `many1Till` ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    endOfValue
        ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    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
     where
      endOfValue :: ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    endOfValue = 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) ()
     -> 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) ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (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) ()
    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
    <* 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
    "\n\r")
                            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) ()
    -> 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) ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    skipSpaces1 ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> 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) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    orgArgKey)

    --
    -- Drawers
    --

    -- | A generic drawer which has no special meaning for org-mode.
    -- Whether or not this drawer is included in the output depends on the drawers
    -- export setting.
    genericDrawer :: PandocMonad m => OrgParser m (F Blocks)
    genericDrawer :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    genericDrawer = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      name    <- Text -> Text
    T.toUpper (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
    drawerStart
      content <- manyTill drawerLine (try drawerEnd)
      state   <- getState
      -- Include drawer if it is explicitly included in or not explicitly excluded
      -- from the list of drawers that should be exported.  PROPERTIES drawers are
      -- never exported.
      case exportDrawers . orgStateExportSettings $ state of
        Either [Text] [Text]
    _           | Text
    name Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == Text
    "PROPERTIES" -> F Blocks
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return F Blocks
    forall a. Monoid a => a
    mempty
        Left  [Text]
    names | Text
    name Text -> [Text] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem`    [Text]
    names -> F Blocks
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return F Blocks
    forall a. Monoid a => a
    mempty
        Right [Text]
    names | Text
    name Text -> [Text] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `notElem` [Text]
    names -> F Blocks
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return F Blocks
    forall a. Monoid a => a
    mempty
        Either [Text] [Text]
    _           -> Text -> F Blocks -> F Blocks
    drawerDiv Text
    name (F Blocks -> F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [Text]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    [Text] -> OrgParser m (F Blocks)
    parseLines [Text]
    content
     where
      parseLines :: PandocMonad m => [Text] -> OrgParser m (F Blocks)
      parseLines :: forall (m :: * -> *).
    PandocMonad m =>
    [Text] -> OrgParser m (F Blocks)
    parseLines = OrgParser m (F Blocks) -> Text -> OrgParser m (F Blocks)
    forall (m :: * -> *) a.
    Monad m =>
    OrgParser m a -> Text -> OrgParser m a
    parseFromString OrgParser m (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    blocks (Text -> OrgParser m (F Blocks))
    -> ([Text] -> Text) -> [Text] -> OrgParser m (F Blocks)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    "\n") (Text -> Text) -> ([Text] -> Text) -> [Text] -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Text] -> Text
    T.unlines

      drawerDiv :: Text -> F Blocks -> F Blocks
      drawerDiv :: Text -> F Blocks -> F Blocks
    drawerDiv Text
    drawerName = (Blocks -> Blocks) -> F Blocks -> F Blocks
    forall a b.
    (a -> b) -> Future OrgParserState a -> Future OrgParserState b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap ((Blocks -> Blocks) -> F Blocks -> F Blocks)
    -> (Blocks -> Blocks) -> F Blocks -> F Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Blocks -> Blocks
    B.divWith (Text
    forall a. Monoid a => a
    mempty, [Text
    drawerName, Text
    "drawer"], [(Text, Text)]
    forall a. Monoid a => a
    mempty)

    drawerLine :: Monad m => OrgParser m Text
    drawerLine :: forall (m :: * -> *). Monad m => OrgParser m Text
    drawerLine = OrgParser m Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine

    drawerEnd :: Monad m => OrgParser m Text
    drawerEnd :: forall (m :: * -> *). Monad m => OrgParser m Text
    drawerEnd = 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) ()
    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) 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
    *> Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s st m Text
    stringAnyCase Text
    ":END:" 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) 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
    <* ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    newline

    --
    -- Figures
    --

    -- | Figures or an image paragraph (i.e. an image on a line by itself). Only
    -- images with a caption attribute are interpreted as figures.
    figure :: PandocMonad m => OrgParser m (F Blocks)
    figure :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    figure = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      figAttrs <- OrgParser m BlockAttributes
    forall (m :: * -> *). PandocMonad m => OrgParser m BlockAttributes
    blockAttributes
      src <- skipSpaces *> selfTarget <* skipSpaces <* endOfParagraph
      case cleanLinkText src of
        Maybe Text
    Nothing     -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a.
    ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero
        Just Text
    imgSrc -> do
          Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Text -> Bool
    isImageFilename Text
    imgSrc)
          let isFigure :: Bool
    isFigure = Maybe (F Inlines) -> Bool
    forall a. Maybe a -> Bool
    isJust (Maybe (F Inlines) -> Bool) -> Maybe (F Inlines) -> Bool
    forall a b. (a -> b) -> a -> b
    $ BlockAttributes -> Maybe (F Inlines)
    blockAttrCaption BlockAttributes
    figAttrs
          F Blocks
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F Blocks
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> F Blocks
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ Bool -> BlockAttributes -> Text -> F Blocks
    imageBlock Bool
    isFigure BlockAttributes
    figAttrs Text
    imgSrc
     where
       selfTarget :: PandocMonad m => OrgParser m Text
       selfTarget :: forall (m :: * -> *). PandocMonad m => OrgParser m Text
    selfTarget = 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
    forall (m :: * -> *). PandocMonad m => OrgParser m Text
    linkTarget 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
    ']'

       imageBlock :: Bool -> BlockAttributes -> Text -> F Blocks
       imageBlock :: Bool -> BlockAttributes -> Text -> F Blocks
    imageBlock Bool
    isFigure BlockAttributes
    figAttrs Text
    imgSrc =
         let
           figName :: Text
    figName    = Text -> Maybe Text -> Text
    forall a. a -> Maybe a -> a
    fromMaybe Text
    forall a. Monoid a => a
    mempty (Maybe Text -> Text) -> Maybe Text -> Text
    forall a b. (a -> b) -> a -> b
    $ BlockAttributes -> Maybe Text
    blockAttrName BlockAttributes
    figAttrs
           figCaption :: F Inlines
    figCaption = F Inlines -> Maybe (F Inlines) -> F Inlines
    forall a. a -> Maybe a -> a
    fromMaybe F Inlines
    forall a. Monoid a => a
    mempty (Maybe (F Inlines) -> F Inlines) -> Maybe (F Inlines) -> F Inlines
    forall a b. (a -> b) -> a -> b
    $ BlockAttributes -> Maybe (F Inlines)
    blockAttrCaption BlockAttributes
    figAttrs
           figKeyVals :: [(Text, Text)]
    figKeyVals = BlockAttributes -> [(Text, Text)]
    blockAttrKeyValues BlockAttributes
    figAttrs
           attr :: Attr
    attr       = (Text
    figName, [Text]
    forall a. Monoid a => a
    mempty, [(Text, Text)]
    figKeyVals)
         in if Bool
    isFigure
               then (\Inlines
    c -> Attr -> Caption -> Blocks -> Blocks
    B.figureWith Attr
    attr (Blocks -> Caption
    B.simpleCaption (Inlines -> Blocks
    B.plain Inlines
    c))
                           (Inlines -> Blocks
    B.plain (Inlines -> Blocks) -> Inlines -> Blocks
    forall a b. (a -> b) -> a -> b
    $ Text -> Text -> Inlines -> Inlines
    B.image Text
    imgSrc Text
    "" Inlines
    forall a. Monoid a => a
    mempty))
                    (Inlines -> Blocks) -> F Inlines -> F Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> F Inlines
    figCaption
               else Inlines -> Blocks
    B.para (Inlines -> Blocks) -> (Inlines -> Inlines) -> Inlines -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Attr -> Text -> Text -> Inlines -> Inlines
    B.imageWith Attr
    attr Text
    imgSrc Text
    figName (Inlines -> Blocks) -> F Inlines -> F Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> F Inlines
    figCaption

    -- | Succeeds if looking at the end of the current paragraph
    endOfParagraph :: Monad m => OrgParser m ()
    endOfParagraph :: forall (m :: * -> *). Monad m => OrgParser m ()
    endOfParagraph = 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
    $ 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
    *> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    newline ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> 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) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    endOfBlock

    --
    -- Examples
    --

    -- | Example code marked up by a leading colon.
    example :: Monad m => OrgParser m (F Blocks)
    example :: forall (m :: * -> *). Monad m => OrgParser m (F Blocks)
    example = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ Blocks
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
    returnF (Blocks
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ([Text] -> Blocks)
    -> [Text]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Blocks
    exampleCode (Text -> Blocks) -> ([Text] -> Text) -> [Text] -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Text] -> Text
    T.unlines ([Text]
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m 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]
    many1 ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    exampleLine
     where
       exampleLine :: Monad m => OrgParser m Text
       exampleLine :: forall (m :: * -> *). Monad m => OrgParser m Text
    exampleLine = 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
    $ OrgParser m ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    exampleLineStart OrgParser m ()
    -> 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
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine

    exampleCode :: Text -> Blocks
    exampleCode :: Text -> Blocks
    exampleCode = Attr -> Text -> Blocks
    B.codeBlockWith (Text
    "", [Text
    "example"], [])

    --
    -- Comments, Options and Metadata
    --

    specialLine :: PandocMonad m => OrgParser m (F Blocks)
    specialLine :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    specialLine = (Blocks -> F Blocks)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    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 Blocks -> F Blocks
    forall a. a -> Future OrgParserState a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> (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) (F Blocks)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . 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) (F Blocks))
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $
      ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    forall (m :: * -> *). PandocMonad m => OrgParser m Blocks
    rawExportLine ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    -> 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 -> ParsecT s u m a
    <|> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    forall (m :: * -> *). PandocMonad m => OrgParser m Blocks
    printbibliographyLine ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    -> 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 -> ParsecT s u m a
    <|> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    forall (m :: * -> *). PandocMonad m => OrgParser m Blocks
    metaLine ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    -> 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 -> ParsecT s u m a
    <|> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    forall (m :: * -> *). Monad m => OrgParser m Blocks
    commentLine

    printbibliographyLine :: PandocMonad m => OrgParser m Blocks
    printbibliographyLine :: forall (m :: * -> *). PandocMonad m => OrgParser m Blocks
    printbibliographyLine = do
      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
    $ 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) 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
    <* 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
    "#+print_bibliography:" ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> 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) Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine
      Blocks
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) Blocks)
    -> Blocks
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Blocks -> Blocks
    B.divWith (Text
    "refs",[],[]) Blocks
    forall a. Monoid a => a
    mempty

    -- | Include the content of a file.
    include :: PandocMonad m => OrgParser m (F Blocks)
    include :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    include = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      OrgParser m ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    metaLineStart OrgParser m ()
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> OrgParser 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
    <* Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s st m Text
    stringAnyCase Text
    "include:" OrgParser m () -> OrgParser m () -> OrgParser 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
    <* OrgParser m ()
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m ()
    skipSpaces
      filename <- OrgParser m String
    forall (m :: * -> *). PandocMonad m => OrgParser m String
    includeTarget
      includeArgs <- many (try $ skipSpaces *> many1Char alphaNum)
      params <- keyValues
      blocksParser <- case includeArgs of
          (Text
    "example" : [Text]
    _) -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (ParsecT
            Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources
          OrgParserState
          (ReaderT OrgParserLocal m)
          (ParsecT
             Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (ParsecT
            Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    forall a b. (a -> b) -> a -> b
    $ Blocks -> F Blocks
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Blocks -> F Blocks) -> (Text -> Blocks) -> Text -> F Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Blocks
    B.codeBlock (Text -> F Blocks)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). PandocMonad m => OrgParser m Text
    parseRaw
          [Text
    "export"] -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (ParsecT
            Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources
          OrgParserState
          (ReaderT OrgParserLocal m)
          (ParsecT
             Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)))
    -> (Blocks
        -> ParsecT
             Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> Blocks
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (ParsecT
            Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Blocks
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
    returnF (Blocks
     -> ParsecT
          Sources
          OrgParserState
          (ReaderT OrgParserLocal m)
          (ParsecT
             Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)))
    -> Blocks
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (ParsecT
            Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    forall a b. (a -> b) -> a -> b
    $ [Block] -> Blocks
    forall a. [a] -> Many a
    B.fromList []
          [Text
    "export", Text
    format] -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (ParsecT
            Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources
          OrgParserState
          (ReaderT OrgParserLocal m)
          (ParsecT
             Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (ParsecT
            Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    forall a b. (a -> b) -> a -> b
    $ Blocks -> F Blocks
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Blocks -> F Blocks) -> (Text -> Blocks) -> Text -> F Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text -> Blocks
    B.rawBlock Text
    format (Text -> F Blocks)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). PandocMonad m => OrgParser m Text
    parseRaw
          (Text
    "src" : [Text]
    rest) -> do
            let attr :: Attr
    attr = case [Text]
    rest of
                         [Text
    lang] -> (Text
    forall a. Monoid a => a
    mempty, [Text
    lang], [(Text, Text)]
    forall a. Monoid a => a
    mempty)
                         [Text]
    _ -> Attr
    nullAttr
            ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (ParsecT
            Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources
          OrgParserState
          (ReaderT OrgParserLocal m)
          (ParsecT
             Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (ParsecT
            Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    forall a b. (a -> b) -> a -> b
    $ Blocks -> F Blocks
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Blocks -> F Blocks) -> (Text -> Blocks) -> Text -> F Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Attr -> Text -> Blocks
    B.codeBlockWith Attr
    attr (Text -> F Blocks)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). PandocMonad m => OrgParser m Text
    parseRaw
          [Text]
    _ -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (ParsecT
            Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    forall a.
    a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources
          OrgParserState
          (ReaderT OrgParserLocal m)
          (ParsecT
             Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (ParsecT
            Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    forall a b. (a -> b) -> a -> b
    $ Blocks -> F Blocks
    forall a. a -> Future OrgParserState a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> F Blocks) -> ([Block] -> Blocks) -> [Block] -> F Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Block] -> Blocks
    forall a. [a] -> Many a
    B.fromList ([Block] -> Blocks) -> ([Block] -> [Block]) -> [Block] -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [(Text, Text)] -> [Block] -> [Block]
    blockFilter [(Text, Text)]
    params ([Block] -> F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [Block]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Block]
    forall (m :: * -> *). PandocMonad m => OrgParser m [Block]
    blockList
      currentDir <- takeDirectory . sourceName <$> getPosition
      let (startLine, endLine) =
            case lookup "lines" params of
              Maybe Text
    Nothing -> (Maybe Int
    forall a. Maybe a
    Nothing, Maybe Int
    forall a. Maybe a
    Nothing)
              Just Text
    bounds -> let boundStr :: Text
    boundStr = Int -> Text -> Text
    T.drop Int
    1 (Int -> Text -> Text
    T.dropEnd Int
    1 Text
    bounds)
                                 begStr :: Text
    begStr = (Char -> Bool) -> Text -> Text
    T.takeWhile (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /= Char
    '-') Text
    boundStr
                                 endStr :: Text
    endStr = (Char -> Bool) -> Text -> Text
    T.takeWhileEnd (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /= Char
    '-') Text
    boundStr
                             in (Text -> Maybe Int
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead Text
    begStr, Int -> Int
    forall a. Enum a => a -> a
    pred (Int -> Int) -> Maybe Int -> Maybe Int
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> Maybe Int
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead Text
    endStr)
      insertIncludedFile blocksParser toSources
                         [currentDir] filename startLine endLine
     where
      includeTarget :: PandocMonad m => OrgParser m FilePath
      includeTarget :: forall (m :: * -> *). PandocMonad m => OrgParser m String
    includeTarget = do
        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) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    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 (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\t") (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
    '"')

      parseRaw :: PandocMonad m => OrgParser m Text
      parseRaw :: forall (m :: * -> *). PandocMonad m => OrgParser m Text
    parseRaw = 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
    anyChar

      blockFilter :: [(Text, Text)] -> [Block] -> [Block]
      blockFilter :: [(Text, Text)] -> [Block] -> [Block]
    blockFilter [(Text, Text)]
    params [Block]
    blks =
        let minlvl :: Maybe Text
    minlvl = Text -> [(Text, Text)] -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    "minlevel" [(Text, Text)]
    params
        in case (Maybe Text
    minlvl Maybe Text -> (Text -> Maybe Int) -> Maybe Int
    forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Text -> Maybe Int
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead :: Maybe Int) of
             Maybe Int
    Nothing -> [Block]
    blks
             Just Int
    lvl -> let levels :: [Int]
    levels = (Block -> [Int]) -> [Block] -> [Int]
    forall c. Monoid c => (Block -> c) -> [Block] -> c
    forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
    Walk.query Block -> [Int]
    headerLevel [Block]
    blks
                             curMin :: Int
    curMin = Int -> (NonEmpty Int -> Int) -> Maybe (NonEmpty Int) -> Int
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Int
    0 NonEmpty Int -> Int
    forall a. Ord a => NonEmpty a -> a
    forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
    minimum (Maybe (NonEmpty Int) -> Int) -> Maybe (NonEmpty Int) -> Int
    forall a b. (a -> b) -> a -> b
    $ [Int] -> Maybe (NonEmpty Int)
    forall a. [a] -> Maybe (NonEmpty a)
    nonEmpty [Int]
    levels
                         in (Block -> Block) -> [Block] -> [Block]
    forall a b. Walkable a b => (a -> a) -> b -> b
    Walk.walk (Int -> Block -> Block
    shiftHeader (Int
    curMin Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    lvl)) [Block]
    blks

      headerLevel :: Block -> [Int]
      headerLevel :: Block -> [Int]
    headerLevel (Header Int
    lvl Attr
    _attr [Inline]
    _content) = [Int
    lvl]
      headerLevel Block
    _ = []

      shiftHeader :: Int -> Block -> Block
      shiftHeader :: Int -> Block -> Block
    shiftHeader Int
    shift Block
    blk =
        case Block
    blk of
          (Header Int
    lvl Attr
    attr [Inline]
    content)
           | Int
    lvl Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    shift Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    0  -> Int -> Attr -> [Inline] -> Block
    Header (Int
    lvl Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    shift) Attr
    attr [Inline]
    content
           | Bool
    otherwise        -> [Inline] -> Block
    Para [Inline]
    content
          Block
    _ -> Block
    blk

    -- | Parses a meta line which defines a raw block. Currently recognized:
    -- @#+LATEX:@, @#+HTML:@, @#+TEXINFO:@, and @#+BEAMER@.
    rawExportLine :: PandocMonad m => OrgParser m Blocks
    rawExportLine :: forall (m :: * -> *). PandocMonad m => OrgParser m Blocks
    rawExportLine = 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
    $ do
      OrgParser m ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    metaLineStart
      key <- OrgParser m Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    metaKey
      if key `elem` ["latex", "html", "texinfo", "beamer"]
        then B.rawBlock key <$> anyLine
        else mzero

    -- | Parses any meta line, i.e., a line starting with @#+@, into a raw
    -- org block. This should be the last resort when trying to parse
    -- keywords. Leading spaces are discarded.
    rawOrgLine :: PandocMonad m => OrgParser m (F Blocks)
    rawOrgLine :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    rawOrgLine = do
      line <- OrgParser m ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    metaLineStart OrgParser m ()
    -> 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
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine
      returnF $ B.rawBlock "org" $ "#+" <> line

    commentLine :: Monad m => OrgParser m Blocks
    commentLine :: forall (m :: * -> *). Monad m => OrgParser m Blocks
    commentLine = OrgParser m ()
    forall (m :: * -> *). Monad m => OrgParser m ()
    commentLineStart OrgParser m ()
    -> 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
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> Blocks
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> Blocks
    forall a. Monoid a => a
    mempty

    --
    -- Tables
    --
    data ColumnProperty = ColumnProperty
      { ColumnProperty -> Maybe Alignment
    columnAlignment :: Maybe Alignment
      , ColumnProperty -> Maybe Int
    columnRelWidth  :: Maybe Int
      } deriving (Int -> ColumnProperty -> ShowS
    [ColumnProperty] -> ShowS
    ColumnProperty -> String
    (Int -> ColumnProperty -> ShowS)
    -> (ColumnProperty -> String)
    -> ([ColumnProperty] -> ShowS)
    -> Show ColumnProperty
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> ColumnProperty -> ShowS
    showsPrec :: Int -> ColumnProperty -> ShowS
    $cshow :: ColumnProperty -> String
    show :: ColumnProperty -> String
    $cshowList :: [ColumnProperty] -> ShowS
    showList :: [ColumnProperty] -> ShowS
    Show, ColumnProperty -> ColumnProperty -> Bool
    (ColumnProperty -> ColumnProperty -> Bool)
    -> (ColumnProperty -> ColumnProperty -> Bool) -> Eq ColumnProperty
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: ColumnProperty -> ColumnProperty -> Bool
    == :: ColumnProperty -> ColumnProperty -> Bool
    $c/= :: ColumnProperty -> ColumnProperty -> Bool
    /= :: ColumnProperty -> ColumnProperty -> Bool
    Eq)

    instance Default ColumnProperty where
      def :: ColumnProperty
    def = Maybe Alignment -> Maybe Int -> ColumnProperty
    ColumnProperty Maybe Alignment
    forall a. Maybe a
    Nothing Maybe Int
    forall a. Maybe a
    Nothing

    data OrgTableRow = OrgContentRow (F [Blocks])
                     | OrgAlignRow [ColumnProperty]
                     | OrgHlineRow

    -- OrgTable is strongly related to the pandoc table ADT.  Using the same
    -- (i.e. pandoc-global) ADT would mean that the reader would break if the
    -- global structure was to be changed, which would be bad.  The final table
    -- should be generated using a builder function.
    data OrgTable = OrgTable
      { OrgTable -> [ColumnProperty]
    orgTableColumnProperties :: [ColumnProperty]
      , OrgTable -> [Blocks]
    orgTableHeader           :: [Blocks]
      , OrgTable -> [[Blocks]]
    orgTableRows             :: [[Blocks]]
      }

    table :: PandocMonad m => OrgParser m (F Blocks)
    table :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    table = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      -- don't allow a table on the first line of a list item; org requires that
      -- tables start at first non-space character on the line
      let isFirstInListItem :: OrgParserState -> Bool
    isFirstInListItem OrgParserState
    st = OrgParserState -> ParserContext
    orgStateParserContext OrgParserState
    st ParserContext -> ParserContext -> Bool
    forall a. Eq a => a -> a -> Bool
    == ParserContext
    ListItemState Bool -> Bool -> Bool
    &&
                                 Maybe SourcePos -> Bool
    forall a. Maybe a -> Bool
    isNothing (OrgParserState -> Maybe SourcePos
    orgStateLastPreCharPos OrgParserState
    st)
      Bool
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Bool
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> (OrgParserState -> Bool)
    -> OrgParserState
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool -> Bool
    not (Bool -> Bool)
    -> (OrgParserState -> Bool) -> OrgParserState -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . OrgParserState -> Bool
    isFirstInListItem (OrgParserState
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      blockAttrs <- OrgParser m BlockAttributes
    forall (m :: * -> *). PandocMonad m => OrgParser m BlockAttributes
    blockAttributes
      let identMb = BlockAttributes -> Maybe Text
    blockAttrName BlockAttributes
    blockAttrs
      tbl <- gridTableWith blocks <|> orgTable
      withTables <- getExportSetting exportWithTables
      return $ if withTables
                  then do
                    xs <- unMany <$> tbl
                    case F.toList xs of
                      [Table Attr
    _ Caption
    _ [ColSpec]
    cs TableHead
    th [TableBody]
    tb TableFoot
    tf] -> do
                        capt <- case BlockAttributes -> Maybe (F Inlines)
    blockAttrCaption BlockAttributes
    blockAttrs of
                                  Maybe (F Inlines)
    Nothing -> Caption -> Future OrgParserState Caption
    forall a. a -> Future OrgParserState a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Caption -> Future OrgParserState Caption)
    -> Caption -> Future OrgParserState Caption
    forall a b. (a -> b) -> a -> b
    $ Maybe [Inline] -> [Block] -> Caption
    Caption Maybe [Inline]
    forall a. Maybe a
    Nothing []
                                  Just F Inlines
    ils -> do
                                    ils' <- F Inlines
    ils
                                    pure $ B.simpleCaption . B.plain $ ils'
                        let attr = (Text -> Maybe Text -> Text
    forall a. a -> Maybe a -> a
    fromMaybe Text
    forall a. Monoid a => a
    mempty Maybe Text
    identMb, [],
                                     BlockAttributes -> [(Text, Text)]
    blockAttrKeyValues BlockAttributes
    blockAttrs)
                        pure $ B.tableWith attr capt cs th tb tf
                      [Block]
    _ -> F Blocks
    tbl   -- should not happen
                  else mempty

    -- | A normal org table
    orgTable :: PandocMonad m => OrgParser m (F Blocks)
    orgTable :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    orgTable = do
      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
    tableStart
      rows <- OrgParser m [OrgTableRow]
    forall (m :: * -> *). PandocMonad m => OrgParser m [OrgTableRow]
    tableRows
      let orgTbl = OrgTable -> OrgTable
    normalizeTable (OrgTable -> OrgTable)
    -> Future OrgParserState OrgTable -> Future OrgParserState OrgTable
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [OrgTableRow] -> Future OrgParserState OrgTable
    rowsToTable [OrgTableRow]
    rows
      return $ orgToPandocTable <$> orgTbl

    orgToPandocTable :: OrgTable -> Blocks
    orgToPandocTable :: OrgTable -> Blocks
    orgToPandocTable (OrgTable [ColumnProperty]
    colProps [Blocks]
    heads [[Blocks]]
    lns) =
      let totalWidth :: Maybe Int
    totalWidth = if (ColumnProperty -> Bool) -> [ColumnProperty] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any (Maybe Int -> Bool
    forall a. Maybe a -> Bool
    isJust (Maybe Int -> Bool)
    -> (ColumnProperty -> Maybe Int) -> ColumnProperty -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ColumnProperty -> Maybe Int
    columnRelWidth) [ColumnProperty]
    colProps
                       then Int -> Maybe Int
    forall a. a -> Maybe a
    Just (Int -> Maybe Int) -> ([Int] -> Int) -> [Int] -> Maybe Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Int] -> Int
    forall a. Num a => [a] -> a
    forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
    sum ([Int] -> Maybe Int) -> [Int] -> Maybe Int
    forall a b. (a -> b) -> a -> b
    $ (ColumnProperty -> Int) -> [ColumnProperty] -> [Int]
    forall a b. (a -> b) -> [a] -> [b]
    map (Int -> Maybe Int -> Int
    forall a. a -> Maybe a -> a
    fromMaybe Int
    1 (Maybe Int -> Int)
    -> (ColumnProperty -> Maybe Int) -> ColumnProperty -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ColumnProperty -> Maybe Int
    columnRelWidth) [ColumnProperty]
    colProps
                       else Maybe Int
    forall a. Maybe a
    Nothing
      in Attr
    -> Caption
    -> [ColSpec]
    -> TableHead
    -> [TableBody]
    -> TableFoot
    -> Blocks
    B.tableWith Attr
    nullAttr (Maybe [Inline] -> [Block] -> Caption
    Caption Maybe [Inline]
    forall a. Maybe a
    Nothing [Block]
    forall a. Monoid a => a
    mempty)
                     ((ColumnProperty -> ColSpec) -> [ColumnProperty] -> [ColSpec]
    forall a b. (a -> b) -> [a] -> [b]
    map (Maybe Int -> ColumnProperty -> ColSpec
    convertColProp Maybe Int
    totalWidth) [ColumnProperty]
    colProps)
                     (Attr -> [Row] -> TableHead
    TableHead Attr
    nullAttr ([Row] -> TableHead) -> [Row] -> TableHead
    forall a b. (a -> b) -> a -> b
    $ [Blocks] -> [Row]
    toHeaderRow [Blocks]
    heads)
                     [Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
    TableBody Attr
    nullAttr RowHeadColumns
    0 [] ([Row] -> TableBody) -> [Row] -> TableBody
    forall a b. (a -> b) -> a -> b
    $ ([Blocks] -> Row) -> [[Blocks]] -> [Row]
    forall a b. (a -> b) -> [a] -> [b]
    map [Blocks] -> Row
    toRow [[Blocks]]
    lns]
                     (Attr -> [Row] -> TableFoot
    TableFoot Attr
    nullAttr [])
     where
       toRow :: [Blocks] -> Row
    toRow = Attr -> [Cell] -> Row
    Row Attr
    nullAttr ([Cell] -> Row) -> ([Blocks] -> [Cell]) -> [Blocks] -> Row
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Blocks -> Cell) -> [Blocks] -> [Cell]
    forall a b. (a -> b) -> [a] -> [b]
    map Blocks -> Cell
    B.simpleCell
       toHeaderRow :: [Blocks] -> [Row]
    toHeaderRow [Blocks]
    l = [[Blocks] -> Row
    toRow [Blocks]
    l | Bool -> Bool
    not ([Blocks] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [Blocks]
    l)]
       convertColProp :: Maybe Int -> ColumnProperty -> (Alignment, ColWidth)
       convertColProp :: Maybe Int -> ColumnProperty -> ColSpec
    convertColProp Maybe Int
    totalWidth ColumnProperty
    colProp =
         let
           align' :: Alignment
    align' = Alignment -> Maybe Alignment -> Alignment
    forall a. a -> Maybe a -> a
    fromMaybe Alignment
    AlignDefault (Maybe Alignment -> Alignment) -> Maybe Alignment -> Alignment
    forall a b. (a -> b) -> a -> b
    $ ColumnProperty -> Maybe Alignment
    columnAlignment ColumnProperty
    colProp
           width' :: Maybe Double
    width' = (\Int
    w Int
    t -> Int -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    w Double -> Double -> Double
    forall a. Fractional a => a -> a -> a
    / Int -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    t)
                    (Int -> Int -> Double) -> Maybe Int -> Maybe (Int -> Double)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ColumnProperty -> Maybe Int
    columnRelWidth ColumnProperty
    colProp
                    Maybe (Int -> Double) -> Maybe Int -> Maybe Double
    forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Maybe Int
    totalWidth
         in (Alignment
    align', ColWidth -> (Double -> ColWidth) -> Maybe Double -> ColWidth
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe ColWidth
    ColWidthDefault Double -> ColWidth
    ColWidth Maybe Double
    width')

    tableRows :: PandocMonad m => OrgParser m [OrgTableRow]
    tableRows :: forall (m :: * -> *). PandocMonad m => OrgParser m [OrgTableRow]
    tableRows = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) [OrgTableRow]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [OrgTableRow]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) [OrgTableRow]
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) [OrgTableRow])
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [OrgTableRow]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [OrgTableRow]
    forall a b. (a -> b) -> a -> b
    $ ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [OrgTableRow]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    forall (m :: * -> *). Monad m => OrgParser m OrgTableRow
    tableAlignRow ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    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) OrgTableRow
    forall (m :: * -> *). Monad m => OrgParser m OrgTableRow
    tableHline ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    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) OrgTableRow
    forall (m :: * -> *). PandocMonad m => OrgParser m OrgTableRow
    tableContentRow)

    tableContentRow :: PandocMonad m => OrgParser m OrgTableRow
    tableContentRow :: forall (m :: * -> *). PandocMonad m => OrgParser m OrgTableRow
    tableContentRow = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    forall a b. (a -> b) -> a -> b
    $
      F [Blocks] -> OrgTableRow
    OrgContentRow (F [Blocks] -> OrgTableRow)
    -> ([F Blocks] -> F [Blocks]) -> [F Blocks] -> OrgTableRow
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [F Blocks] -> F [Blocks]
    forall (t :: * -> *) (m :: * -> *) a.
    (Traversable t, Monad m) =>
    t (m a) -> m (t a)
    forall (m :: * -> *) a. Monad m => [m a] -> m [a]
    sequence ([F Blocks] -> OrgTableRow)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [F Blocks]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (OrgParser m Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    tableStart OrgParser m Char
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [F Blocks]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [F Blocks]
    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) (F Blocks)
    -> OrgParser m Char
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [F Blocks]
    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 Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    tableContentCell OrgParser m Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    newline)

    tableContentCell :: PandocMonad m => OrgParser m (F Blocks)
    tableContentCell :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    tableContentCell = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $
      (Inlines -> Blocks) -> F Inlines -> F Blocks
    forall a b.
    (a -> b) -> Future OrgParserState a -> Future OrgParserState b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Inlines -> Blocks
    B.plain (F Inlines -> F Blocks)
    -> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . 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 Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    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
    endOfCell

    tableAlignRow :: Monad m => OrgParser m OrgTableRow
    tableAlignRow :: forall (m :: * -> *). Monad m => OrgParser m OrgTableRow
    tableAlignRow = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    forall a b. (a -> b) -> a -> b
    $ do
      OrgParser m Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    tableStart
      colProps <- ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    -> OrgParser m Char
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) [ColumnProperty]
    forall end s (m :: * -> *) t st a.
    (Show end, Stream s m t) =>
    ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
    many1Till ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    forall (m :: * -> *). Monad m => OrgParser m ColumnProperty
    columnPropertyCell OrgParser m Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    newline
      -- Empty rows are regular (i.e. content) rows, not alignment rows.
      guard $ any (/= def) colProps
      return $ OrgAlignRow colProps

    columnPropertyCell :: Monad m => OrgParser m ColumnProperty
    columnPropertyCell :: forall (m :: * -> *). Monad m => OrgParser m ColumnProperty
    columnPropertyCell = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    emptyOrgCell ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    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) ColumnProperty
    propCell ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    -> String
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> String -> ParsecT s u m a
    <?> String
    "alignment info"
     where
       emptyOrgCell :: ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    emptyOrgCell = Maybe Alignment -> Maybe Int -> ColumnProperty
    ColumnProperty Maybe Alignment
    forall a. Maybe a
    Nothing Maybe Int
    forall a. Maybe a
    Nothing ColumnProperty
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    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) 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) ()
    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
    *> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    endOfCell)
       propCell :: ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    propCell = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    forall a b. (a -> b) -> a -> b
    $ Maybe Alignment -> Maybe Int -> ColumnProperty
    ColumnProperty
                     (Maybe Alignment -> Maybe Int -> ColumnProperty)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe Alignment)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Maybe Int -> ColumnProperty)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f 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) (Maybe Alignment)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe Alignment)
    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) Alignment
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe Alignment)
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m (Maybe a)
    optionMaybe ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Alignment
    forall (m :: * -> *). Monad m => OrgParser m Alignment
    tableAlignFromChar)
                     ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Maybe Int -> ColumnProperty)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe Int)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    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) Int
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe Int)
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m (Maybe a)
    optionMaybe (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 ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> (Text
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    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
    >>= Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead)
                          ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe Int)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe Int)
    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) (Maybe Int)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe Int)
    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) ColumnProperty
    emptyOrgCell)

    tableAlignFromChar :: Monad m => OrgParser m Alignment
    tableAlignFromChar :: forall (m :: * -> *). Monad m => OrgParser m Alignment
    tableAlignFromChar = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Alignment
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) Alignment
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) Alignment
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) Alignment)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) Alignment
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) Alignment
    forall a b. (a -> b) -> a -> b
    $
      [ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) Alignment]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) Alignment
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice [ 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
    'l' ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> Alignment
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) Alignment
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> Alignment
    AlignLeft
             , 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
    'c' ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> Alignment
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) Alignment
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> Alignment
    AlignCenter
             , 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
    'r' ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> Alignment
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) Alignment
    forall (f :: * -> *) a b. Functor f => f a -> b -> f b
    $> Alignment
    AlignRight
             ]

    tableHline :: Monad m => OrgParser m OrgTableRow
    tableHline :: forall (m :: * -> *). Monad m => OrgParser m OrgTableRow
    tableHline = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    forall a b. (a -> b) -> a -> b
    $
      OrgTableRow
    OrgHlineRow OrgTableRow
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
    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
    <$ (OrgParser m Char
    forall (m :: * -> *). Monad m => OrgParser m Char
    tableStart OrgParser m Char -> OrgParser m Char -> OrgParser 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 -> OrgParser m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '-' OrgParser 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
    forall (m :: * -> *). Monad m => OrgParser m Text
    anyLine)

    endOfCell :: Monad m => OrgParser m Char
    endOfCell :: forall (m :: * -> *). Monad m => OrgParser m Char
    endOfCell = 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) Char)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    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) 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
    <|> 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

    rowsToTable :: [OrgTableRow]
                -> F OrgTable
    rowsToTable :: [OrgTableRow] -> Future OrgParserState OrgTable
    rowsToTable = (OrgTable -> OrgTableRow -> Future OrgParserState OrgTable)
    -> OrgTable -> [OrgTableRow] -> Future OrgParserState OrgTable
    forall (t :: * -> *) (m :: * -> *) b a.
    (Foldable t, Monad m) =>
    (b -> a -> m b) -> b -> t a -> m b
    foldM OrgTable -> OrgTableRow -> Future OrgParserState OrgTable
    rowToContent OrgTable
    emptyTable
     where emptyTable :: OrgTable
    emptyTable = [ColumnProperty] -> [Blocks] -> [[Blocks]] -> OrgTable
    OrgTable [ColumnProperty]
    forall a. Monoid a => a
    mempty [Blocks]
    forall a. Monoid a => a
    mempty [[Blocks]]
    forall a. Monoid a => a
    mempty

    normalizeTable :: OrgTable -> OrgTable
    normalizeTable :: OrgTable -> OrgTable
    normalizeTable (OrgTable [ColumnProperty]
    colProps [Blocks]
    heads [[Blocks]]
    rows) =
      [ColumnProperty] -> [Blocks] -> [[Blocks]] -> OrgTable
    OrgTable [ColumnProperty]
    colProps' [Blocks]
    heads [[Blocks]]
    rows
     where
       refRow :: [Blocks]
    refRow = if [Blocks]
    heads [Blocks] -> [Blocks] -> Bool
    forall a. Eq a => a -> a -> Bool
    /= [Blocks]
    forall a. Monoid a => a
    mempty
                then [Blocks]
    heads
                else case [[Blocks]]
    rows of
                       ([Blocks]
    r:[[Blocks]]
    _) -> [Blocks]
    r
                       [[Blocks]]
    _     -> [Blocks]
    forall a. Monoid a => a
    mempty
       cols :: Int
    cols = [Blocks] -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Blocks]
    refRow
       fillColumns :: [a] -> a -> [a]
    fillColumns [a]
    base a
    padding = Int -> [a] -> [a]
    forall a. Int -> [a] -> [a]
    take Int
    cols ([a] -> [a]) -> [a] -> [a]
    forall a b. (a -> b) -> a -> b
    $ [a]
    base [a] -> [a] -> [a]
    forall a. [a] -> [a] -> [a]
    ++ a -> [a]
    forall a. a -> [a]
    repeat a
    padding
       colProps' :: [ColumnProperty]
    colProps' = [ColumnProperty] -> ColumnProperty -> [ColumnProperty]
    forall {a}. [a] -> a -> [a]
    fillColumns [ColumnProperty]
    colProps ColumnProperty
    forall a. Default a => a
    def

    -- One or more horizontal rules after the first content line mark the previous
    -- line as a header.  All other horizontal lines are discarded.
    rowToContent :: OrgTable
                 -> OrgTableRow
                 -> F OrgTable
    rowToContent :: OrgTable -> OrgTableRow -> Future OrgParserState OrgTable
    rowToContent OrgTable
    tbl OrgTableRow
    row =
      case OrgTableRow
    row of
        OrgTableRow
    OrgHlineRow       -> OrgTable -> Future OrgParserState OrgTable
    forall a. a -> Future OrgParserState a
    forall (m :: * -> *) a. Monad m => a -> m a
    return OrgTable
    singleRowPromotedToHeader
        OrgAlignRow [ColumnProperty]
    props -> OrgTable -> Future OrgParserState OrgTable
    forall a. a -> Future OrgParserState a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (OrgTable -> Future OrgParserState OrgTable)
    -> ([ColumnProperty] -> OrgTable)
    -> [ColumnProperty]
    -> Future OrgParserState OrgTable
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [ColumnProperty] -> OrgTable
    setProperties ([ColumnProperty] -> Future OrgParserState OrgTable)
    -> [ColumnProperty] -> Future OrgParserState OrgTable
    forall a b. (a -> b) -> a -> b
    $ [ColumnProperty]
    props
        OrgContentRow F [Blocks]
    cs  -> F [Blocks] -> Future OrgParserState OrgTable
    appendToBody F [Blocks]
    cs
     where
       singleRowPromotedToHeader :: OrgTable
       singleRowPromotedToHeader :: OrgTable
    singleRowPromotedToHeader = case OrgTable
    tbl of
         OrgTable{ orgTableHeader :: OrgTable -> [Blocks]
    orgTableHeader = [], orgTableRows :: OrgTable -> [[Blocks]]
    orgTableRows = [[Blocks]
    b] } ->
                OrgTable
    tbl{ orgTableHeader = b , orgTableRows = [] }
         OrgTable
    _   -> OrgTable
    tbl

       setProperties :: [ColumnProperty] -> OrgTable
       setProperties :: [ColumnProperty] -> OrgTable
    setProperties [ColumnProperty]
    ps = OrgTable
    tbl{ orgTableColumnProperties = ps }

       appendToBody :: F [Blocks] -> F OrgTable
       appendToBody :: F [Blocks] -> Future OrgParserState OrgTable
    appendToBody F [Blocks]
    frow = do
         newRow <- F [Blocks]
    frow
         let oldRows = OrgTable -> [[Blocks]]
    orgTableRows OrgTable
    tbl
         -- NOTE: This is an inefficient O(n) operation.  This should be changed
         -- if performance ever becomes a problem.
         return tbl{ orgTableRows = oldRows ++ [newRow] }

    --
    -- LaTeX fragments
    --
    latexFragment :: PandocMonad m => OrgParser m (F Blocks)
    latexFragment :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    latexFragment = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      envName <- OrgParser m Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    latexEnvStart
      guard $ envName `notElem` inlineEnvironmentNames
      texOpt  <- getExportSetting exportWithLatex
      let envStart = Text
    "\\begin{" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    envName Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    "}"
      let envEnd = Text
    "\\end{" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    envName Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    "}"
      envContent <- do
        content <- manyTillChar anyChar (latexEnd envName)
        return $ envStart <> content <> envEnd
      returnF $ case texOpt of
        TeXExport
    TeXExport -> Text -> Text -> Blocks
    B.rawBlock Text
    "latex" (Text
    envContent Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    "\n")
        TeXExport
    TeXIgnore   -> Blocks
    forall a. Monoid a => a
    mempty
        TeXExport
    TeXVerbatim -> Inlines -> Blocks
    B.para (Inlines -> Blocks) -> (Text -> Inlines) -> Text -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Inlines
    B.text (Text -> Blocks) -> Text -> Blocks
    forall a b. (a -> b) -> a -> b
    $ Text
    envContent
     where
      latexEnd :: Monad m => Text -> OrgParser m ()
      latexEnd :: forall (m :: * -> *). Monad m => Text -> OrgParser m ()
    latexEnd Text
    envName = 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) Text
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void
         (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
     -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall a b. (a -> b) -> a -> b
    $ Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s st m Text
    textStr (Text
    "\\end{" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    envName Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    "}")
        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
    <* ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline

    --
    -- Footnote definitions
    --
    noteBlock :: PandocMonad m => OrgParser m (F Blocks)
    noteBlock :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    noteBlock = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      ref <- OrgParser m Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    noteMarker OrgParser m Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> OrgParser 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 OrgParser m Text
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    -> OrgParser 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 (m :: * -> *). Monad m => OrgParser m ()
    updateLastPreCharPos
      content <- mconcat <$> many1Till block endOfFootnote
      addToNotesTable (ref, content)
      return mempty
     where
       endOfFootnote :: ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    endOfFootnote =  ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) t u.
    (Stream s m t, Show t) =>
    ParsecT s u m ()
    eof
                    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
    <|> () ()
    -> OrgParser 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
    <$ OrgParser m Text -> OrgParser m Text
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead OrgParser m Text
    forall (m :: * -> *). Monad m => OrgParser m Text
    noteMarker
                    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) Int
    -> 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
    <$ ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    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) Int
    forall (m :: * -> *). Monad m => OrgParser m Int
    headerStart
                    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 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) 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
    -> 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) Char)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall a b. (a -> b) -> a -> b
    $ ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> 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
    *> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline)

    -- Paragraphs or Plain text
    paraOrPlain :: PandocMonad m => OrgParser m (F Blocks)
    paraOrPlain :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    paraOrPlain = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      -- Make sure we are not looking at a headline
      ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall b s (m :: * -> *) a st.
    (Show b, Stream s m a) =>
    ParsecT s st m b -> ParsecT s st m ()
    notFollowedBy' ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    forall (m :: * -> *). Monad m => OrgParser m Int
    headerStart
      ils <- OrgParser m (F Inlines)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
    inlines
      nl <- option False (newline $> True)
      -- Read block as paragraph, except if we are in a list context and the block
      -- is directly followed by a list item, in which case the block is read as
      -- plain text.
      try (guard nl
           *> notFollowedBy (inList *> (void orderedListStart <|> void bulletListStart))
           $> (B.para <$> ils))
        <|>  return (B.plain <$> ils)

    --
    -- list blocks
    --

    list :: PandocMonad m => OrgParser m (F Blocks)
    list :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    list = [ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)]
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice [ ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    definitionList, ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    bulletList, ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    orderedList ] ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> String
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> String -> ParsecT s u m a
    <?> String
    "list"

    definitionList :: PandocMonad m => OrgParser m (F Blocks)
    definitionList :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    definitionList = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      indent <- ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    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) Int
    forall (m :: * -> *). Monad m => OrgParser m Int
    bulletListStart
      fmap (B.definitionList . compactifyDL) . sequence
        <$> many1 (definitionListItem (bulletListStart `indented` indent))

    bulletList :: PandocMonad m => OrgParser m (F Blocks)
    bulletList :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    bulletList = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      indent <- ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
    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) Int
    forall (m :: * -> *). Monad m => OrgParser m Int
    bulletListStart
      fmap (B.bulletList . compactify) . sequence
        <$> many1 (listItem (bulletListStart `indented` indent))

    indented :: OrgParser m Int -> Int -> OrgParser m Int
    indented :: forall (m :: * -> *). OrgParser m Int -> Int -> OrgParser m Int
    indented OrgParser m Int
    indentedMarker Int
    minIndent = OrgParser m Int -> OrgParser m Int
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (OrgParser m Int -> OrgParser m Int)
    -> OrgParser m Int -> OrgParser m Int
    forall a b. (a -> b) -> a -> b
    $ do
      n <- OrgParser m Int
    indentedMarker
      guard (minIndent <= n)
      return n

    orderedList :: PandocMonad m => OrgParser m (F Blocks)
    orderedList :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    orderedList = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      (indent, attr) <- ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Int, ListAttributes)
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Int, ListAttributes)
    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)
      (Int, ListAttributes)
    forall (m :: * -> *). Monad m => OrgParser m (Int, ListAttributes)
    orderedListStart
      fmap (B.orderedListWith attr . compactify) . sequence
        <$> many1 (listItem ((fst <$> orderedListStart) `indented` indent))

    definitionListItem :: PandocMonad m
                       => OrgParser m Int
                       -> OrgParser m (F (Inlines, [Blocks]))
    definitionListItem :: forall (m :: * -> *).
    PandocMonad m =>
    OrgParser m Int
    -> OrgParser m (Future OrgParserState (Inlines, [Blocks]))
    definitionListItem OrgParser m Int
    parseIndentedMarker = ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Future OrgParserState (Inlines, [Blocks]))
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Future OrgParserState (Inlines, [Blocks]))
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources
       OrgParserState
       (ReaderT OrgParserLocal m)
       (Future OrgParserState (Inlines, [Blocks]))
     -> ParsecT
          Sources
          OrgParserState
          (ReaderT OrgParserLocal m)
          (Future OrgParserState (Inlines, [Blocks])))
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Future OrgParserState (Inlines, [Blocks]))
    -> ParsecT
         Sources
         OrgParserState
         (ReaderT OrgParserLocal m)
         (Future OrgParserState (Inlines, [Blocks]))
    forall a b. (a -> b) -> a -> b
    $ do
      markerLength <- OrgParser m Int
    parseIndentedMarker
      term <- manyTillChar (noneOf "\n\r") (try definitionMarker)
      line1 <- anyLineNewline
      blank <- option "" ("\n" <$ blankline)
      cont <- T.concat <$> many (listContinuation markerLength)
      term' <- parseFromString inlines term
      contents' <- parseFromString blocks $ line1 <> blank <> cont
      return $ (,) <$> term' <*> fmap (:[]) contents'
     where
       definitionMarker :: ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    definitionMarker =
         ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    spaceChar ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    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) String
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    String -> ParsecT s u m String
    string String
    "::" ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
    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 s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    spaceChar 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
    <|> 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)

    -- | Checkbox for tasks.
    data Checkbox
      = UncheckedBox
      | CheckedBox
      | SemicheckedBox

    -- | Parses a checkbox in a plain list.
    checkbox :: PandocMonad m
             => OrgParser m Checkbox
    checkbox :: forall (m :: * -> *). PandocMonad m => OrgParser m Checkbox
    checkbox = do
      Extension
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasReaderOptions st) =>
    Extension -> ParsecT s st m ()
    guardEnabled Extension
    Ext_task_lists
      ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Checkbox
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) Checkbox
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (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) Checkbox
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) Checkbox
    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) Checkbox
    forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) Checkbox
    status ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Checkbox
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) Checkbox
    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) Checkbox
    -> String
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) Checkbox
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> String -> ParsecT s u m a
    <?> String
    "checkbox"
      where
        status :: ParsecT Sources u (ReaderT OrgParserLocal m) Checkbox
    status = [ParsecT Sources u (ReaderT OrgParserLocal m) Checkbox]
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Checkbox
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice
          [ Checkbox
    UncheckedBox   Checkbox
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Checkbox
    forall a b.
    a
    -> ParsecT Sources u (ReaderT OrgParserLocal m) b
    -> ParsecT Sources u (ReaderT OrgParserLocal m) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ Char -> ParsecT Sources u (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
    ' '
          , Checkbox
    CheckedBox     Checkbox
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Checkbox
    forall a b.
    a
    -> ParsecT Sources u (ReaderT OrgParserLocal m) b
    -> ParsecT Sources u (ReaderT OrgParserLocal m) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ Char -> ParsecT Sources u (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
    'X'
          , Checkbox
    SemicheckedBox Checkbox
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources u (ReaderT OrgParserLocal m) Checkbox
    forall a b.
    a
    -> ParsecT Sources u (ReaderT OrgParserLocal m) b
    -> ParsecT Sources u (ReaderT OrgParserLocal m) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ Char -> ParsecT Sources u (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
    '-'
          ]

    checkboxToInlines :: Checkbox -> Inline
    checkboxToInlines :: Checkbox -> Inline
    checkboxToInlines = Text -> Inline
    B.Str (Text -> Inline) -> (Checkbox -> Text) -> Checkbox -> Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . \case
      Checkbox
    UncheckedBox   -> Text
    "☐"
      Checkbox
    SemicheckedBox -> Text
    "☐"
      Checkbox
    CheckedBox     -> Text
    "☒"

    -- | parse raw text for one list item
    listItem :: PandocMonad m
             => OrgParser m Int
             -> OrgParser m (F Blocks)
    listItem :: forall (m :: * -> *).
    PandocMonad m =>
    OrgParser m Int -> OrgParser m (F Blocks)
    listItem OrgParser m Int
    parseIndentedMarker = ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> (ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
        -> ParsecT
             Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ParserContext
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *) a.
    Monad m =>
    ParserContext -> OrgParser m a -> OrgParser m a
    withContext ParserContext
    ListItemState (ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
     -> ParsecT
          Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      markerLength <- OrgParser m Int -> OrgParser m Int
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try OrgParser m Int
    parseIndentedMarker
      box <- optionMaybe checkbox
      firstLine <- anyLineNewline
      blank <- option "" ("\n" <$ blankline)
      rest <- T.concat <$> many (listContinuation markerLength)
      contents <- parseFromString (do initial <- paraOrPlain <|> pure mempty
                                      subsequent <- blocks
                                      return $ initial <> subsequent)
                    (firstLine <> blank <> rest)
      return (maybe id (prependInlines . checkboxToInlines) box <$> contents)

    -- | Prepend inlines to blocks, adding them to the first paragraph or
    -- creating a new Plain element if necessary.
    prependInlines :: Inline -> Blocks -> Blocks
    prependInlines :: Inline -> Blocks -> Blocks
    prependInlines Inline
    inlns = [Block] -> Blocks
    forall a. [a] -> Many a
    B.fromList ([Block] -> Blocks) -> (Blocks -> [Block]) -> Blocks -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Block] -> [Block]
    prepend ([Block] -> [Block]) -> (Blocks -> [Block]) -> Blocks -> [Block]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Blocks -> [Block]
    forall a. Many a -> [a]
    B.toList
      where
        prepend :: [Block] -> [Block]
    prepend (Plain [Inline]
    is : [Block]
    bs) = [Inline] -> Block
    Plain (Inline
    inlns Inline -> [Inline] -> [Inline]
    forall a. a -> [a] -> [a]
    : Inline
    Space Inline -> [Inline] -> [Inline]
    forall a. a -> [a] -> [a]
    : [Inline]
    is) Block -> [Block] -> [Block]
    forall a. a -> [a] -> [a]
    : [Block]
    bs
        prepend (Para  [Inline]
    is : [Block]
    bs) = [Inline] -> Block
    Para  (Inline
    inlns Inline -> [Inline] -> [Inline]
    forall a. a -> [a] -> [a]
    : Inline
    Space Inline -> [Inline] -> [Inline]
    forall a. a -> [a] -> [a]
    : [Inline]
    is) Block -> [Block] -> [Block]
    forall a. a -> [a] -> [a]
    : [Block]
    bs
        prepend [Block]
    bs              = [Inline] -> Block
    Plain [Inline
    inlns, Inline
    Space] Block -> [Block] -> [Block]
    forall a. a -> [a] -> [a]
    : [Block]
    bs

    -- continuation of a list item - indented and separated by blankline or endline.
    -- Note: nested lists are parsed as continuations.
    listContinuation :: PandocMonad m => Int -> OrgParser m Text
    listContinuation :: forall (m :: * -> *). PandocMonad m => Int -> OrgParser m Text
    listContinuation Int
    markerLength = 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
      ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
    forall b s (m :: * -> *) a st.
    (Show b, Stream s m a) =>
    ParsecT s st m b -> ParsecT s st m ()
    notFollowedBy' ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline
      Text -> Text -> Text
    forall a. Monoid a => a -> a -> a
    mappend (Text -> Text -> Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ([Text] -> Text
    T.concat ([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
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 (Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). PandocMonad m => Int -> OrgParser m Text
    listContinuation' Int
    markerLength))
              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 s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline
     where
       listContinuation' :: Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    listContinuation' Int
    indentation =
          Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall (m :: * -> *). PandocMonad m => Int -> OrgParser m Text
    blockLines Int
    indentation ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> 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 -> ParsecT s u m a
    <|> Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall {m :: * -> *} {u}.
    (Monad m, HasReaderOptions u) =>
    Int -> ParsecT Sources u m Text
    listLine Int
    indentation
       listLine :: Int -> ParsecT Sources u m Text
    listLine Int
    indentation = ParsecT Sources u m Text -> ParsecT Sources u m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources u m Text -> ParsecT Sources u m Text)
    -> ParsecT Sources u m Text -> ParsecT Sources u m Text
    forall a b. (a -> b) -> a -> b
    $ Int -> ParsecT Sources u m Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char, HasReaderOptions st) =>
    Int -> ParsecT s st m Text
    indentWith Int
    indentation ParsecT Sources u m Text
    -> ParsecT Sources u m Text -> ParsecT Sources u m Text
    forall a b.
    ParsecT Sources u m a
    -> ParsecT Sources u m b -> ParsecT Sources u m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources u m Text
    forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
    anyLineNewline
      -- The block attributes and start must be appropriately indented,
      -- but the contents, and end do not.
       blockLines :: Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    blockLines Int
    indentation =
          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) Text
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char, HasReaderOptions st) =>
    Int -> ParsecT s st m Text
    indentWith Int
    indentation
                           ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) BlockAttributes
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) BlockAttributes
    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 (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) BlockAttributes
    forall (m :: * -> *). PandocMonad m => OrgParser m BlockAttributes
    blockAttributes
                           ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) BlockAttributes
    -> (BlockAttributes
        -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text)
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    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
    >>= (\BlockAttributes
    blockAttrs ->
                                  case BlockAttributes -> Attr
    attrFromBlockAttributes BlockAttributes
    blockAttrs of
                                    (Text
    "", [], []) -> Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char, Monad m) =>
    Int -> ParsecT s st m Char -> ParsecT s st m Text
    countChar Int
    1 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
    anyChar
                                    Attr
    _ -> Int
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char, HasReaderOptions st) =>
    Int -> ParsecT s st m Text
    indentWith Int
    indentation))
                ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) 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
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ((F Blocks, Text) -> Text
    forall a b. (a, b) -> b
    snd ((F Blocks, Text) -> Text)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks, 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) (F Blocks)
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks, Text)
    forall (m :: * -> *) st a.
    Monad m =>
    ParsecT Sources st m a -> ParsecT Sources st m (a, Text)
    withRaw ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
    forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
    orgBlock)