{-# 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 <tarleb+pandoc@moltkeplatz.de>

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.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.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
  F Headline
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
  OrgParserState
st             <- ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let headlineTree :: Headline
headlineTree = F Headline -> OrgParserState -> Headline
forall s a. Future s a -> s -> a
runF F Headline
fHeadlineTree OrgParserState
st
  Headline -> OrgParserState -> OrgParser m [Block]
forall (m :: * -> *).
Monad m =>
Headline -> OrgParserState -> OrgParser m [Block]
unprunedHeadlineToBlocks Headline
headlineTree OrgParserState
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
  F Meta
meta' <- OrgParser m (F Meta)
forall (m :: * -> *). Monad m => OrgParser m (F Meta)
metaExport
  F Meta -> OrgParserState -> Meta
forall s a. Future s a -> s -> a
runF F Meta
meta' (OrgParserState -> Meta)
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> OrgParser m Meta
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
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
  Text
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
':')
  OrgParser m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
  Text
attrValue <- ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *). Monad m => OrgParser m Text
anyLine 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
<|> (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 (m :: * -> *). Monad m => OrgParser m Char
newline)
  (Text, Text)
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (Text, Text)
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
attrName, Text
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
  [(Text, Text)]
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
  Bool
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool
 -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
-> Bool
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ ((Text, Text) -> Bool) -> [(Text, Text)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Text -> Bool
isBlockAttr (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)]
kv
  let caption :: Maybe Text
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
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 :: Maybe Text
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)
  Maybe (F Inlines)
caption' <- (Text
 -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines))
-> Maybe Text
-> ParsecT
     Sources
     OrgParserState
     (ReaderT OrgParserLocal m)
     (Maybe (F Inlines))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse (ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> Text
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlines (Text
 -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines))
-> (Text -> Text)
-> Text
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n")) Maybe Text
caption
  [(Text, Text)]
kvAttrs' <- ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)]
-> Text
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)]
forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)]
forall (m :: * -> *). Monad m => OrgParser m [(Text, Text)]
keyValues (Text
 -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)])
-> (Text -> Text)
-> Text
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n") (Text
 -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)])
-> Text
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)]
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
forall a. Monoid a => a
mempty Maybe Text
kvAttrs
  BlockAttributes
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) BlockAttributes
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return BlockAttributes
           { blockAttrName :: Maybe Text
blockAttrName = Maybe Text
name
           , blockAttrCaption :: Maybe (F Inlines)
blockAttrCaption = Maybe (F Inlines)
caption'
           , blockAttrKeyValues :: [(Text, Text)]
blockAttrKeyValues = [(Text, Text)]
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 (m :: * -> *) t u a.
Stream s m t =>
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
  BlockAttributes
blockAttrs <- OrgParser m BlockAttributes
forall (m :: * -> *). PandocMonad m => OrgParser m BlockAttributes
blockAttributes
  Text
blkType <- OrgParser m Text
forall (m :: * -> *). Monad m => OrgParser m Text
blockHeaderStart
  ((Text
 -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
-> Text
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall a b. (a -> b) -> a -> b
$ Text
blkType) ((Text
  -> ParsecT
       Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
 -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
-> (Text
    -> ParsecT
         Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks))
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall a b. (a -> b) -> a -> b
$
    case Text -> Text
T.toLower Text
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
  F Blocks
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
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
  F Blocks -> OrgParser m (F Blocks)
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F Blocks -> OrgParser m (F Blocks))
-> F Blocks -> OrgParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ (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
    (Attr -> Blocks -> Blocks
B.divWith (Text
id', [Text
blockType], []) (Blocks -> Blocks) -> (Blocks -> Blocks) -> Blocks -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
     (Attr -> Blocks -> Blocks
B.divWith (Text
"", [Text
"title"], []) (Inlines -> Blocks
B.para (Text -> Inlines
B.str (Text -> Text
T.toTitle Text
blockType))) Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<>))
    F Blocks
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
  ([Text]
classes, [(Text, Text)]
kv) <- OrgParser m ([Text], [(Text, Text)])
forall (m :: * -> *).
Monad m =>
OrgParser m ([Text], [(Text, Text)])
switchesAsAttributes
  OrgParser m Char
forall (m :: * -> *). Monad m => OrgParser m Char
newline
  Text
content <- Text -> OrgParser m Text
forall (m :: * -> *). Monad m => Text -> OrgParser m Text
rawBlockContent Text
"example"
  let id' :: Text
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 :: Blocks
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
  F Blocks -> OrgParser m (F Blocks)
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return (F Blocks -> OrgParser m (F Blocks))
-> (Blocks -> F Blocks) -> Blocks -> OrgParser m (F Blocks)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blocks -> F Blocks
forall a. a -> Future OrgParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> OrgParser m (F Blocks))
-> Blocks -> OrgParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ Blocks
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
     Text
raw <- Text -> OrgParser m Text
forall (m :: * -> *). Monad m => Text -> OrgParser m Text
rawBlockContent Text
blockType
     ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
-> Text
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
blocks (Text
raw Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\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
  [Text]
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
  Int
tabLen <- (ReaderOptions -> Int)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
forall s (m :: * -> *) t b.
Stream s m t =>
(ReaderOptions -> b) -> ParsecT s OrgParserState m b
getOption ReaderOptions -> Int
readerTabStop
  Bool
trimP <- OrgParserState -> Bool
orgStateTrimLeadBlkIndent (OrgParserState -> Bool)
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let stripIndent :: [Text] -> [Text]
stripIndent [Text]
strs = if Bool
trimP then (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Text -> Text
T.drop ([Text] -> Int
shortestIndent [Text]
strs)) [Text]
strs else [Text]
strs
  ([Text] -> Text
T.unlines
   ([Text] -> Text) -> ([Text] -> [Text]) -> [Text] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> [Text]
stripIndent
   ([Text] -> [Text]) -> ([Text] -> [Text]) -> [Text] -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Text -> Text
tabsToSpaces Int
tabLen (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
commaEscaped)
   ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ [Text]
blkLines)
   Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
-> 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
<$ (OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
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)

   shortestIndent :: [Text] -> Int
   shortestIndent :: [Text] -> Int
shortestIndent = (Text -> Int -> Int) -> Int -> [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 -> Int) -> Text -> Int -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Int
T.length (Text -> Int) -> (Text -> Text) -> Text -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> Text
T.takeWhile Char -> Bool
isSpace) Int
forall a. Bounded a => a
maxBound
                    ([Text] -> Int) -> ([Text] -> [Text]) -> [Text] -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Text -> Bool) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Bool
T.null)

   tabsToSpaces :: Int -> Text -> Text
   tabsToSpaces :: Int -> Text -> Text
tabsToSpaces Int
tabStop Text
t =
     let (Text
ind, Text
suff) = (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
t
         tabNum :: Int
tabNum      = Text -> Int
T.length (Text -> Int) -> Text -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\n') Text
ind
         spaceNum :: Int
spaceNum    = Text -> Int
T.length Text
ind Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
tabNum
     in  Int -> Text -> Text
T.replicate (Int
spaceNum Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
tabStop Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
tabNum) Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
suff

   commaEscaped :: Text -> Text
commaEscaped Text
t =
     let (Text
ind, Text
suff) = (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
t
     in  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
ind Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
cs
             | Text
"#+" <- Int -> Text -> Text
T.take Int
2 Text
cs -> Text
ind Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
cs
           Maybe (Char, Text)
_                       -> Text
t

-- | 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
  Text
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
  Text
contents   <- Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *). Monad m => Text -> OrgParser m Text
rawBlockContent Text
blockType
  Blocks
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (Text -> Text -> Blocks
B.rawBlock (Text -> Text
T.toLower Text
exportType) Text
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
  Text
content <- Text -> OrgParser m Text
forall (m :: * -> *). Monad m => Text -> OrgParser m Text
rawBlockContent Text
blockType
  ([Inlines] -> Blocks)
-> Future OrgParserState [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.lineBlock (Future OrgParserState [Inlines] -> F Blocks)
-> ([F Inlines] -> Future OrgParserState [Inlines])
-> [F Inlines]
-> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> Future OrgParserState [Inlines]
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 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
<$> (Text
 -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines))
-> [Text]
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Text
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Text -> OrgParser m (F Inlines)
parseVerseLine (Text -> [Text]
T.lines Text
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
     F Inlines
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")
     F Inlines -> OrgParser m (F Inlines)
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines) -> F Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> F Inlines
forall a. a -> Future OrgParserState a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
nbspIndent F Inlines -> F Inlines -> F Inlines
forall a. Semigroup a => a -> a -> a
<> F Inlines
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
  F Blocks
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
  F Meta
meta'   <- OrgParserState -> F Meta
orgStateMeta (OrgParserState -> F Meta)
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Meta)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  (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
st ->
    OrgParserState
st { orgStateMeta = B.setMeta blockType <$> content <*> meta' }
  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

-- | 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
  ([Text]
classes, [(Text, Text)]
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)
  Text
content        <- Text -> OrgParser m Text
forall (m :: * -> *). Monad m => Text -> OrgParser m Text
rawBlockContent Text
blockType
  F Blocks
resultsContent <- F Blocks -> OrgParser m (F Blocks) -> OrgParser m (F Blocks)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option F Blocks
forall a. Monoid a => a
mempty OrgParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
babelResultsBlock
  let identifier :: Text
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' :: [Text]
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 :: Blocks
codeBlk    = Attr -> Text -> Blocks
B.codeBlockWith (Text
identifier, [Text]
classes', [(Text, Text)]
kv) Text
content
  let wrap :: Blocks -> F Blocks
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)
  F Blocks -> OrgParser m (F Blocks)
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return (F Blocks -> OrgParser m (F Blocks))
-> F Blocks -> OrgParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$
    (if [(Text, Text)] -> Bool
exportsCode [(Text, Text)]
kv    then Blocks -> F Blocks
wrap Blocks
codeBlk   else F Blocks
forall a. Monoid a => a
mempty) F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
<>
    (if [(Text, Text)] -> Bool
exportsResults [(Text, Text)]
kv then F Blocks
resultsContent else F Blocks
forall a. Monoid a => a
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
  Text
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
  ([Text]
switchClasses, [(Text, Text)]
switchKv) <- ParsecT
  Sources
  OrgParserState
  (ReaderT OrgParserLocal m)
  ([Text], [(Text, Text)])
forall (m :: * -> *).
Monad m =>
OrgParser m ([Text], [(Text, Text)])
switchesAsAttributes
  [(Text, Text)]
parameters <- 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 ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (Text, Text)
forall (m :: * -> *). Monad m => OrgParser m (Text, Text)
blockOption ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *). Monad m => OrgParser m Char
newline
  ([Text], [(Text, Text)])
-> ParsecT
     Sources
     OrgParserState
     (ReaderT OrgParserLocal m)
     ([Text], [(Text, Text)])
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( Text -> Text
translateLang Text
language Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: [Text]
switchClasses
         , Text -> [(Text, Text)]
originalLang Text
language [(Text, Text)] -> [(Text, Text)] -> [(Text, Text)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Text)]
switchKv [(Text, Text)] -> [(Text, Text)] -> [(Text, Text)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Text)]
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
  [(Char, Maybe Text, SwitchPolarity)]
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 (m :: * -> *) t u a.
Stream s m t =>
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)
  ([Text], [(Text, Text)])
-> ParsecT
     Sources
     OrgParserState
     (ReaderT OrgParserLocal m)
     ([Text], [(Text, Text)])
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return (([Text], [(Text, Text)])
 -> ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      ([Text], [(Text, Text)]))
-> ([Text], [(Text, Text)])
-> ParsecT
     Sources
     OrgParserState
     (ReaderT OrgParserLocal m)
     ([Text], [(Text, Text)])
forall a b. (a -> b) -> a -> b
$ ((Char, Maybe Text, SwitchPolarity)
 -> ([Text], [(Text, Text)]) -> ([Text], [(Text, Text)]))
-> ([Text], [(Text, Text)])
-> [(Char, Maybe Text, SwitchPolarity)]
-> ([Text], [(Text, Text)])
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Char, Maybe Text, SwitchPolarity)
-> ([Text], [(Text, Text)]) -> ([Text], [(Text, Text)])
addToAttr ([], []) [(Char, Maybe Text, SwitchPolarity)]
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)
-> OrgParser 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
  SwitchPolarity
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
  Maybe Text
arg <- OrgParser m Text
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe Text)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe OrgParser m Text
p
  (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
c, Maybe Text
arg, SwitchPolarity
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
  Text
argKey <- OrgParser m Text
forall (m :: * -> *). Monad m => OrgParser m Text
orgArgKey
  Text
paramValue <- Text -> OrgParser m Text -> OrgParser m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"yes" OrgParser m Text
forall (m :: * -> *). Monad m => OrgParser m Text
orgParamValue
  (Text, Text)
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (Text, Text)
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
argKey, Text
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
  Text
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
  [Text]
content <- ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> 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
drawerLine (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
forall (m :: * -> *). Monad m => OrgParser m Text
drawerEnd)
  OrgParserState
state   <- ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
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 ExportSettings -> Either [Text] [Text]
exportDrawers (ExportSettings -> Either [Text] [Text])
-> (OrgParserState -> ExportSettings)
-> OrgParserState
-> Either [Text] [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> ExportSettings
orgStateExportSettings (OrgParserState -> Either [Text] [Text])
-> OrgParserState -> Either [Text] [Text]
forall a b. (a -> b) -> a -> b
$ OrgParserState
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
  BlockAttributes
figAttrs <- OrgParser m BlockAttributes
forall (m :: * -> *). PandocMonad m => OrgParser m BlockAttributes
blockAttributes
  Text
src <- 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 :: * -> *). PandocMonad m => OrgParser m Text
selfTarget 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) ()
-> 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 ()
endOfParagraph
  case Text -> Maybe Text
cleanLinkText Text
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 (m :: * -> *) t u a.
Stream s m t =>
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 -> OrgParser m Blocks
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> OrgParser m Blocks) -> Blocks -> OrgParser 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
  String
filename <- OrgParser m String
forall (m :: * -> *). PandocMonad m => OrgParser m String
includeTarget
  [Text]
includeArgs <- ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> 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 s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces 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) 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
alphaNum)
  [(Text, Text)]
params <- OrgParser m [(Text, Text)]
forall (m :: * -> *). Monad m => OrgParser m [(Text, Text)]
keyValues
  ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
blocksParser <- case [Text]
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
  String
currentDir <- ShowS
takeDirectory ShowS -> (SourcePos -> String) -> SourcePos -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourcePos -> String
sourceName (SourcePos -> String)
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) SourcePos
-> OrgParser m String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  let (Maybe Int
startLine, Maybe Int
endLine) =
        case Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"lines" [(Text, Text)]
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)
  ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
-> (Text -> Sources)
-> [String]
-> String
-> Maybe Int
-> Maybe Int
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall (m :: * -> *) st a b.
(PandocMonad m, HasIncludeFiles st) =>
ParsecT a st m b
-> (Text -> a)
-> [String]
-> String
-> Maybe Int
-> Maybe Int
-> ParsecT a st m b
insertIncludedFile ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
blocksParser Text -> Sources
forall a. ToSources a => a -> Sources
toSources
                     [String
currentDir] String
filename Maybe Int
startLine Maybe Int
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
-> OrgParser 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
  Text
key <- OrgParser m Text
forall (m :: * -> *). Monad m => OrgParser m Text
metaKey
  if Text
key Text -> [Text] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"latex", Text
"html", Text
"texinfo", Text
"beamer"]
    then Text -> Text -> Blocks
B.rawBlock Text
key (Text -> Blocks)
-> OrgParser m Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m Text
forall (m :: * -> *). Monad m => OrgParser m Text
anyLine
    else ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Blocks
forall a.
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. MonadPlus m => m a
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
  Text
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
  Blocks -> OrgParser m (F Blocks)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (Blocks -> OrgParser m (F Blocks))
-> Blocks -> OrgParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Blocks
B.rawBlock Text
"org" (Text -> Blocks) -> Text -> Blocks
forall a b. (a -> b) -> a -> b
$ Text
"#+" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
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
  BlockAttributes
blockAttrs <- OrgParser m BlockAttributes
forall (m :: * -> *). PandocMonad m => OrgParser m BlockAttributes
blockAttributes
  let identMb :: Maybe Text
identMb = BlockAttributes -> Maybe Text
blockAttrName BlockAttributes
blockAttrs
  F Blocks
tbl <- ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall (m :: * -> *) (mf :: * -> *) st.
(Monad m, Monad mf, HasLastStrPosition st, HasReaderOptions st) =>
ParsecT Sources st m (mf Blocks)
-> ParsecT Sources st m (mf Blocks)
gridTableWith ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
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 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) (F Blocks)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
orgTable
  Bool
withTables <- (ExportSettings -> Bool) -> OrgParser m Bool
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportWithTables
  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
$ if Bool
withTables
              then do
                Seq Block
xs <- Blocks -> Seq Block
forall a. Many a -> Seq a
unMany (Blocks -> Seq Block)
-> F Blocks -> Future OrgParserState (Seq Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Blocks
tbl
                case Seq Block -> [Block]
forall a. Seq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList Seq Block
xs of
                  [Table Attr
_ Caption
_ [ColSpec]
cs TableHead
th [TableBody]
tb TableFoot
tf] -> do
                    Caption
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
                                Inlines
ils' <- F Inlines
ils
                                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
$ Blocks -> Caption
B.simpleCaption (Blocks -> Caption) -> (Inlines -> Blocks) -> Inlines -> Caption
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Blocks
B.plain (Inlines -> Caption) -> Inlines -> Caption
forall a b. (a -> b) -> a -> b
$ Inlines
ils'
                    let attr :: (Text, [a], [(Text, Text)])
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)
                    Blocks -> F Blocks
forall a. a -> Future OrgParserState a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Blocks -> F Blocks) -> Blocks -> F Blocks
forall a b. (a -> b) -> a -> b
$ Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Blocks
B.tableWith Attr
forall {a}. (Text, [a], [(Text, Text)])
attr Caption
capt [ColSpec]
cs TableHead
th [TableBody]
tb TableFoot
tf
                  [Block]
_ -> F Blocks
tbl   -- should not happen
              else F Blocks
forall a. Monoid a => a
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
  [OrgTableRow]
rows <- OrgParser m [OrgTableRow]
forall (m :: * -> *). PandocMonad m => OrgParser m [OrgTableRow]
tableRows
  let orgTbl :: Future OrgParserState OrgTable
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
  F Blocks -> OrgParser m (F Blocks)
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return (F Blocks -> OrgParser m (F Blocks))
-> F Blocks -> OrgParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ OrgTable -> Blocks
orgToPandocTable (OrgTable -> Blocks) -> Future OrgParserState OrgTable -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Future OrgParserState OrgTable
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
  [ColumnProperty]
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.
  Bool
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool
 -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
-> Bool
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ (ColumnProperty -> Bool) -> [ColumnProperty] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (ColumnProperty -> ColumnProperty -> Bool
forall a. Eq a => a -> a -> Bool
/= ColumnProperty
forall a. Default a => a
def) [ColumnProperty]
colProps
  OrgTableRow
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return (OrgTableRow
 -> ParsecT
      Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow)
-> OrgTableRow
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) OrgTableRow
forall a b. (a -> b) -> a -> b
$ [ColumnProperty] -> OrgTableRow
OrgAlignRow [ColumnProperty]
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
     [Blocks]
newRow <- F [Blocks]
frow
     let oldRows :: [[Blocks]]
oldRows = OrgTable -> [[Blocks]]
orgTableRows OrgTable
tbl
     -- NOTE: This is an inefficient O(n) operation.  This should be changed
     -- if performance ever becomes a problem.
     OrgTable -> Future OrgParserState OrgTable
forall a. a -> Future OrgParserState a
forall (m :: * -> *) a. Monad m => a -> m a
return OrgTable
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
  Text
envName <- OrgParser m Text
forall (m :: * -> *). Monad m => OrgParser m Text
latexEnvStart
  TeXExport
texOpt  <- (ExportSettings -> TeXExport) -> OrgParser m TeXExport
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> TeXExport
exportWithLatex
  let envStart :: Text
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
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
"}"
  Text
envContent <- do
    Text
content <- ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser 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 (Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => Text -> OrgParser m ()
latexEnd Text
envName)
    Text -> OrgParser m Text
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> OrgParser m Text) -> Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$ Text
envStart Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
content Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
envEnd
  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))
-> Blocks
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall a b. (a -> b) -> a -> b
$ case TeXExport
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
  Text
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
  F Blocks
content <- [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 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) (F Blocks)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
block ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
endOfFootnote
  OrgNoteRecord
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *).
PandocMonad m =>
OrgNoteRecord -> OrgParser m ()
addToNotesTable (Text
ref, F Blocks
content)
  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
 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
  F Inlines
ils <- OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlines
  Bool
nl <- Bool
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Bool
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (OrgParser m Char
forall (m :: * -> *). Monad m => OrgParser m Char
newline OrgParser m Char
-> Bool
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
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.
  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 (Bool
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
nl
       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) ()
-> 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) ()
forall (m :: * -> *). Monad m => OrgParser m ()
inList 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)
  (Int, ListAttributes)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT
  Sources
  OrgParserState
  (ReaderT OrgParserLocal m)
  (Int, ListAttributes)
forall (m :: * -> *). Monad m => OrgParser m (Int, ListAttributes)
orderedListStart 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 (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
forall (m :: * -> *). Monad m => OrgParser m Int
bulletListStart))
       ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
-> F Blocks
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> (Inlines -> Blocks
B.para (Inlines -> Blocks) -> F Inlines -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
ils))
    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 s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>  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 (Inlines -> Blocks
B.plain (Inlines -> Blocks) -> F Inlines -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
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
  Int
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
  ([(Inlines, [Blocks])] -> Blocks)
-> Future OrgParserState [(Inlines, [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 ([(Inlines, [Blocks])] -> Blocks
B.definitionList ([(Inlines, [Blocks])] -> Blocks)
-> ([(Inlines, [Blocks])] -> [(Inlines, [Blocks])])
-> [(Inlines, [Blocks])]
-> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
compactifyDL) (Future OrgParserState [(Inlines, [Blocks])] -> F Blocks)
-> ([Future OrgParserState (Inlines, [Blocks])]
    -> Future OrgParserState [(Inlines, [Blocks])])
-> [Future OrgParserState (Inlines, [Blocks])]
-> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Future OrgParserState (Inlines, [Blocks])]
-> Future OrgParserState [(Inlines, [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
    ([Future OrgParserState (Inlines, [Blocks])] -> F Blocks)
-> ParsecT
     Sources
     OrgParserState
     (ReaderT OrgParserLocal m)
     [Future OrgParserState (Inlines, [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)
  (Future OrgParserState (Inlines, [Blocks]))
-> ParsecT
     Sources
     OrgParserState
     (ReaderT OrgParserLocal m)
     [Future OrgParserState (Inlines, [Blocks])]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
-> ParsecT
     Sources
     OrgParserState
     (ReaderT OrgParserLocal m)
     (Future OrgParserState (Inlines, [Blocks]))
forall (m :: * -> *).
PandocMonad m =>
OrgParser m Int
-> OrgParser m (Future OrgParserState (Inlines, [Blocks]))
definitionListItem (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
forall (m :: * -> *). Monad m => OrgParser m Int
bulletListStart ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
-> Int
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
forall (m :: * -> *). OrgParser m Int -> Int -> OrgParser m Int
`indented` Int
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
  Int
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
  ([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.bulletList ([Blocks] -> Blocks)
-> ([Blocks] -> [Blocks]) -> [Blocks] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blocks] -> [Blocks]
compactify) (F [Blocks] -> F Blocks)
-> ([F Blocks] -> F [Blocks]) -> [F Blocks] -> F Blocks
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] -> 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) [F Blocks]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall (m :: * -> *).
PandocMonad m =>
OrgParser m Int -> OrgParser m (F Blocks)
listItem (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
forall (m :: * -> *). Monad m => OrgParser m Int
bulletListStart ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
-> Int
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Int
forall (m :: * -> *). OrgParser m Int -> Int -> OrgParser m Int
`indented` Int
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
  Int
n <- OrgParser m Int
indentedMarker
  Bool
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Int
minIndent Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
n)
  Int -> OrgParser m Int
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return Int
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
  (Int
indent, ListAttributes
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
  ([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 (ListAttributes -> [Blocks] -> Blocks
B.orderedListWith ListAttributes
attr ([Blocks] -> Blocks)
-> ([Blocks] -> [Blocks]) -> [Blocks] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blocks] -> [Blocks]
compactify) (F [Blocks] -> F Blocks)
-> ([F Blocks] -> F [Blocks]) -> [F Blocks] -> F Blocks
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] -> 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) [F Blocks]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (OrgParser m Int
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall (m :: * -> *).
PandocMonad m =>
OrgParser m Int -> OrgParser m (F Blocks)
listItem (((Int, ListAttributes) -> Int
forall a b. (a, b) -> a
fst ((Int, ListAttributes) -> Int)
-> ParsecT
     Sources
     OrgParserState
     (ReaderT OrgParserLocal m)
     (Int, ListAttributes)
-> OrgParser m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  Sources
  OrgParserState
  (ReaderT OrgParserLocal m)
  (Int, ListAttributes)
forall (m :: * -> *). Monad m => OrgParser m (Int, ListAttributes)
orderedListStart) OrgParser m Int -> Int -> OrgParser m Int
forall (m :: * -> *). OrgParser m Int -> Int -> OrgParser m Int
`indented` Int
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
  Int
markerLength <- OrgParser m Int
parseIndentedMarker
  Text
term <- ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
-> 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 (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) 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) String
definitionMarker)
  Text
line1 <- ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLineNewline
  Text
blank <- Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" (Text
"\n" 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)
  Text
cont <- [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]
many (Int
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *). PandocMonad m => Int -> OrgParser m Text
listContinuation Int
markerLength)
  F Inlines
term' <- 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
term
  F Blocks
contents' <- 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 -> OrgParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ Text
line1 Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
blank Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
cont
  Future OrgParserState (Inlines, [Blocks])
-> ParsecT
     Sources
     OrgParserState
     (ReaderT OrgParserLocal m)
     (Future OrgParserState (Inlines, [Blocks]))
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Future OrgParserState (Inlines, [Blocks])
 -> ParsecT
      Sources
      OrgParserState
      (ReaderT OrgParserLocal m)
      (Future OrgParserState (Inlines, [Blocks])))
-> Future OrgParserState (Inlines, [Blocks])
-> ParsecT
     Sources
     OrgParserState
     (ReaderT OrgParserLocal m)
     (Future OrgParserState (Inlines, [Blocks]))
forall a b. (a -> b) -> a -> b
$ (,) (Inlines -> [Blocks] -> (Inlines, [Blocks]))
-> F Inlines
-> Future OrgParserState ([Blocks] -> (Inlines, [Blocks]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
term' Future OrgParserState ([Blocks] -> (Inlines, [Blocks]))
-> F [Blocks] -> Future OrgParserState (Inlines, [Blocks])
forall a b.
Future OrgParserState (a -> b)
-> Future OrgParserState a -> Future OrgParserState b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (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] -> [Blocks]
forall a. a -> [a] -> [a]
:[]) F Blocks
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
  OrgParser m Checkbox -> OrgParser 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
-> OrgParser m Checkbox -> OrgParser 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
*> OrgParser m Checkbox
forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) Checkbox
status OrgParser m Checkbox
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser 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
']') OrgParser m Checkbox -> String -> OrgParser 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
  Int
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
  Maybe Checkbox
box <- ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Checkbox
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe Checkbox)
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) Checkbox
forall (m :: * -> *). PandocMonad m => OrgParser m Checkbox
checkbox
  Text
firstLine <- ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLineNewline
  Text
blank <- Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" (Text
"\n" 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)
  Text
rest <- [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]
many (Int
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *). PandocMonad m => Int -> OrgParser m Text
listContinuation Int
markerLength)
  F Blocks
contents <- ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
-> Text
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString (do F Blocks
initial <- 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)
-> 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 -> ParsecT s u m a
<|> F Blocks
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure F Blocks
forall a. Monoid a => a
mempty
                                  F Blocks
subsequent <- ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Blocks)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
blocks
                                  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
$ F Blocks
initial F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
<> F Blocks
subsequent)
                (Text
firstLine Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
blank Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
rest)
  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 ((Blocks -> Blocks)
-> (Checkbox -> Blocks -> Blocks)
-> Maybe Checkbox
-> Blocks
-> Blocks
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Blocks -> Blocks
forall a. a -> a
id (Inline -> Blocks -> Blocks
prependInlines (Inline -> Blocks -> Blocks)
-> (Checkbox -> Inline) -> Checkbox -> Blocks -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Checkbox -> Inline
checkboxToInlines) Maybe Checkbox
box (Blocks -> Blocks) -> F Blocks -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Blocks
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 (m :: * -> *) t u a.
Stream s m t =>
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)