{-# LANGUAGE FlexibleContexts  #-}
{-# LANGUAGE LambdaCase        #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
{- |
   Module      : Text.Pandoc.Readers.Org.Blocks
   Copyright   : Copyright (C) 2014-2023 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)
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.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  <- forall (m :: * -> *).
PandocMonad m =>
OrgParser m (F Blocks)
-> OrgParser m (F Inlines) -> OrgParser m (F Headline)
documentTree forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
blocks forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline
  OrgParserState
st             <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let headlineTree :: Headline
headlineTree = forall s a. Future s a -> s -> a
runF F Headline
fHeadlineTree OrgParserState
st
  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' <- forall (m :: * -> *). Monad m => OrgParser m (F Meta)
metaExport
  forall s a. Future s a -> s -> a
runF F Meta
meta' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 = forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
block (forall (f :: * -> *) a. Functor f => f a -> f ()
void (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). Monad m => OrgParser m Int
headerStart) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> 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 = forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). Monad m => OrgParser m Text
blanklines
               , forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
table
               , forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
orgBlock
               , forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
figure
               , forall (m :: * -> *). Monad m => OrgParser m (F Blocks)
example
               , forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
genericDrawer
               , forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
include
               , forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
specialLine
               , forall (m :: * -> *). Monad m => OrgParser m (F Blocks)
horizontalRule
               , forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
list
               , forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
latexFragment
               , forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
noteBlock
               , forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
rawOrgLine
               , forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
paraOrPlain
               ] 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 = forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
B.horizontalRule forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try 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)
blockAttrKeyValues :: [(Text, Text)]
blockAttrCaption :: Maybe (F Inlines)
blockAttrName :: Maybe Text
blockAttrKeyValues :: BlockAttributes -> [(Text, Text)]
blockAttrCaption :: BlockAttributes -> Maybe (F Inlines)
blockAttrName :: BlockAttributes -> Maybe Text
..} =
  let
    ident :: Text
ident   = forall a. a -> Maybe a -> a
fromMaybe forall a. Monoid a => a
mempty forall a b. (a -> b) -> a -> b
$ forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"id" [(Text, Text)]
blockAttrKeyValues
    classes :: [Text]
classes = forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Text -> [Text]
T.words forall a b. (a -> b) -> a -> b
$ forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"class" [(Text, Text)]
blockAttrKeyValues
    kv :: [(Text, Text)]
kv      = forall a. (a -> Bool) -> [a] -> [a]
filter ((forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Text
"id", Text
"class"]) forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). Monad m => OrgParser m ()
metaLineStart
  Text
attrName <- Text -> Text
T.toLower forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':')
  forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
  Text
attrValue <- forall (m :: * -> *). Monad m => OrgParser m Text
anyLine forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text
"" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). Monad m => OrgParser m Char
newline)
  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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  [(Text, Text)]
kv <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). Monad m => OrgParser m (Text, Text)
stringyMetaAttribute
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Text -> Bool
isBlockAttr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) [(Text, Text)]
kv
  let caption :: Maybe Text
caption = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (Text -> Maybe Text -> (Text, Text) -> Maybe Text
appendValues Text
"caption") forall a. Maybe a
Nothing [(Text, Text)]
kv
  let kvAttrs :: Maybe Text
kvAttrs = 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") forall a. Maybe a
Nothing [(Text, Text)]
kv
  let name :: Maybe Text
name    = forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"name", Text
"label"]) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) (forall a. [a] -> [a]
reverse [(Text, Text)]
kv)
  Maybe (F Inlines)
caption' <- forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Semigroup a => a -> a -> a
<> Text
"\n")) Maybe Text
caption
  [(Text, Text)]
kvAttrs' <- forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString forall (m :: * -> *). Monad m => OrgParser m [(Text, Text)]
keyValues forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Semigroup a => a -> a -> a
<> Text
"\n") forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a -> a
fromMaybe forall a. Monoid a => a
mempty Maybe Text
kvAttrs
  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 = forall a b c. (a -> b -> c) -> b -> a -> c
flip 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 forall a. Eq a => a -> a -> Bool
/= Text
attrName
     then Maybe Text
accValue
     else case Maybe Text
accValue of
            Just Text
acc -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
acc forall a. Semigroup a => a -> a -> a
<> Text
" " forall a. Semigroup a => a -> a -> a
<> Text
value
            Maybe Text
Nothing  -> 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  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 ((,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). Monad m => OrgParser m Text
key forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (m :: * -> *). Monad m => OrgParser m Text
value) forall (m :: * -> *). Monad m => OrgParser m Char
newline
 where
   key :: Monad m => OrgParser m Text
   key :: forall (m :: * -> *). Monad m => OrgParser m Text
key = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char 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 = forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> 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 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar forall (m :: * -> *). Monad m => OrgParser m ()
endOfValue

   endOfValue :: Monad m => OrgParser m ()
   endOfValue :: forall (m :: * -> *). Monad m => OrgParser m ()
endOfValue = forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). Monad m => OrgParser m Text
key))
            forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  BlockAttributes
blockAttrs <- forall (m :: * -> *). PandocMonad m => OrgParser m BlockAttributes
blockAttributes
  Text
blkType <- forall (m :: * -> *). Monad m => OrgParser m Text
blockHeaderStart
  (forall a b. (a -> b) -> a -> b
$ Text
blkType) forall a b. (a -> b) -> a -> b
$
    case Text -> Text
T.toLower Text
blkType of
      Text
"export"  -> forall (m :: * -> *). Monad m => Text -> OrgParser m (F Blocks)
exportBlock
      Text
"comment" -> forall (m :: * -> *).
Monad m =>
(Text -> F Blocks) -> Text -> OrgParser m (F Blocks)
rawBlockLines (forall a b. a -> b -> a
const forall a. Monoid a => a
mempty)
      Text
"html"    -> forall (m :: * -> *).
Monad m =>
(Text -> F Blocks) -> Text -> OrgParser m (F Blocks)
rawBlockLines (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Blocks
B.rawBlock (Text -> Text
lowercase Text
blkType))
      Text
"latex"   -> forall (m :: * -> *).
Monad m =>
(Text -> F Blocks) -> Text -> OrgParser m (F Blocks)
rawBlockLines (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Blocks
B.rawBlock (Text -> Text
lowercase Text
blkType))
      Text
"ascii"   -> forall (m :: * -> *).
Monad m =>
(Text -> F Blocks) -> Text -> OrgParser m (F Blocks)
rawBlockLines (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Blocks
B.rawBlock (Text -> Text
lowercase Text
blkType))
      Text
"example" -> forall (m :: * -> *).
PandocMonad m =>
BlockAttributes -> Text -> OrgParser m (F Blocks)
exampleBlock BlockAttributes
blockAttrs
      Text
"quote"   -> forall (m :: * -> *).
PandocMonad m =>
(F Blocks -> F Blocks) -> Text -> OrgParser m (F Blocks)
parseBlockLines (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Blocks -> Blocks
B.blockQuote)
      Text
"verse"   -> forall (m :: * -> *).
PandocMonad m =>
Text -> OrgParser m (F Blocks)
verseBlock
      Text
"src"     -> forall (m :: * -> *).
PandocMonad m =>
BlockAttributes -> Text -> OrgParser m (F Blocks)
codeBlock BlockAttributes
blockAttrs
      Text
_         ->
        -- case-sensitive checks
        case Text
blkType of
          Text
"abstract" -> forall (m :: * -> *).
PandocMonad m =>
Text -> OrgParser m (F Blocks)
metadataBlock
          Text
_ -> forall (m :: * -> *).
PandocMonad m =>
(F Blocks -> F Blocks) -> Text -> OrgParser m (F Blocks)
parseBlockLines forall a b. (a -> b) -> a -> b
$
                   let (Text
ident, [Text]
classes, [(Text, Text)]
kv) = BlockAttributes -> Attr
attrFromBlockAttributes BlockAttributes
blockAttrs
                   in forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a -> b) -> a -> b
$ Attr -> Blocks -> Blocks
B.divWith (Text
ident, [Text]
classes 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s st m Text
stringAnyCase Text
"#+begin_" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). Monad m => OrgParser m Text
orgArgWord

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

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
  forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
  ([Text]
classes, [(Text, Text)]
kv) <- forall (m :: * -> *).
Monad m =>
OrgParser m ([Text], [(Text, Text)])
switchesAsAttributes
  forall (m :: * -> *). Monad m => OrgParser m Char
newline
  Text
content <- forall (m :: * -> *). Monad m => Text -> OrgParser m Text
rawBlockContent Text
"example"
  let id' :: Text
id' = forall a. a -> Maybe a -> a
fromMaybe forall a. Monoid a => a
mempty 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"forall a. a -> [a] -> [a]
:[Text]
classes, [(Text, Text)]
kv) Text
content
  forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => a -> m a
return 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 = forall (m :: * -> *). Monad m => OrgParser m ()
ignHeaders forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Text -> F Blocks
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 = forall (m :: * -> *). Monad m => OrgParser m ()
ignHeaders forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (F Blocks -> F Blocks
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
     Text
raw <- forall (m :: * -> *). Monad m => Text -> OrgParser m Text
rawBlockContent Text
blockType
     forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
blocks (Text
raw 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  [Text]
blkLines <- 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 forall (m :: * -> *). Monad m => OrgParser m Text
rawLine forall (m :: * -> *). Monad m => OrgParser m ()
blockEnder
  Int
tabLen <- forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
getOption ReaderOptions -> Int
readerTabStop
  Bool
trimP <- OrgParserState -> Bool
orgStateTrimLeadBlkIndent forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let stripIndent :: [Text] -> [Text]
stripIndent [Text]
strs = if Bool
trimP then 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
   forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> [Text]
stripIndent
   forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (Int -> Text -> Text
tabsToSpaces Int
tabLen forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
commaEscaped)
   forall a b. (a -> b) -> a -> b
$ [Text]
blkLines)
   forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState (\OrgParserState
s -> OrgParserState
s { orgStateTrimLeadBlkIndent :: Bool
orgStateTrimLeadBlkIndent = Bool
True })
 where
   rawLine :: Monad m => OrgParser m Text
   rawLine :: forall (m :: * -> *). Monad m => OrgParser m Text
rawLine = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ (Text
"" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). Monad m => OrgParser m Text
anyLine

   blockEnder :: Monad m => OrgParser m ()
   blockEnder :: forall (m :: * -> *). Monad m => OrgParser m ()
blockEnder = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s st m Text
stringAnyCase (Text
"#+end_" forall a. Semigroup a => a -> a -> a
<> Text
blockType)

   shortestIndent :: [Text] -> Int
   shortestIndent :: [Text] -> Int
shortestIndent = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall a. Ord a => a -> a -> a
min forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Int
T.length forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> Text
T.takeWhile Char -> Bool
isSpace) forall a. Bounded a => a
maxBound
                    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not 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 forall a. Eq a => a -> a -> Bool
== Char
' ' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'\t') Text
t
         tabNum :: Int
tabNum      = Text -> Int
T.length forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.filter (forall a. Eq a => a -> a -> Bool
== Char
'\n') Text
ind
         spaceNum :: Int
spaceNum    = Text -> Int
T.length Text
ind forall a. Num a => a -> a -> a
- Int
tabNum
     in  Int -> Text -> Text
T.replicate (Int
spaceNum forall a. Num a => a -> a -> a
+ Int
tabStop forall a. Num a => a -> a -> a
* Int
tabNum) 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 forall a. Eq a => a -> a -> Bool
== Char
' ' Bool -> Bool -> Bool
|| Char
c 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 forall a. Semigroup a => a -> a -> a
<> Text
cs
             | Text
"#+" <- Int -> Text -> Text
T.take Int
2 Text
cs -> Text
ind 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 = (() forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). Monad m => OrgParser m Char
newline) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (() forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Text
exportType <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). Monad m => OrgParser m Text
orgArgWord forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). Monad m => OrgParser m ()
ignHeaders
  Text
contents   <- forall (m :: * -> *). Monad m => Text -> OrgParser m Text
rawBlockContent Text
blockType
  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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). Monad m => OrgParser m ()
ignHeaders
  Text
content <- forall (m :: * -> *). Monad m => Text -> OrgParser m Text
rawBlockContent Text
blockType
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Inlines] -> Blocks
B.lineBlock forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM 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 forall a. Monoid a => a
mempty
                      else Text -> Inlines
B.str forall a b. (a -> b) -> a -> b
$ (Char -> Char) -> Text -> Text
T.map (forall a b. a -> b -> a
const Char
'\160') Text
initialSpaces
     F Inlines
line <- forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlines (Text
indentedLine forall a. Semigroup a => a -> a -> a
<> Text
"\n")
     forall (m :: * -> *) a. Monad m => a -> m a
return (forall s. Future s Inlines -> Future s Inlines
trimInlinesF forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
nbspIndent 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  F Blocks
content <- forall (m :: * -> *).
PandocMonad m =>
(F Blocks -> F Blocks) -> Text -> OrgParser m (F Blocks)
parseBlockLines forall a. a -> a
id Text
blockType
  F Meta
meta'   <- OrgParserState -> F Meta
orgStateMeta forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \OrgParserState
st ->
    OrgParserState
st { orgStateMeta :: F Meta
orgStateMeta = forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
B.setMeta Text
blockType forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Blocks
content forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> F Meta
meta' }
  forall (m :: * -> *) a. Monad m => a -> m a
return 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
  forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
  ([Text]
classes, [(Text, Text)]
kv)  <- forall (m :: * -> *).
Monad m =>
OrgParser m ([Text], [(Text, Text)])
codeHeaderArgs forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). Monad m => OrgParser m ()
ignHeaders)
  Text
content        <- forall (m :: * -> *). Monad m => Text -> OrgParser m Text
rawBlockContent Text
blockType
  F Blocks
resultsContent <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option forall a. Monoid a => a
mempty forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
babelResultsBlock
  let identifier :: Text
identifier = forall a. a -> Maybe a -> a
fromMaybe forall a. Monoid a => a
mempty 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' forall a. a -> [a] -> [a]
: Text
"code" 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       = forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall (f :: * -> *) a. Applicative f => a -> f a
pure F Inlines -> Blocks -> F Blocks
addCaption (BlockAttributes -> Maybe (F Inlines)
blockAttrCaption BlockAttributes
blockAttrs)
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
    (if [(Text, Text)] -> Bool
exportsCode [(Text, Text)]
kv    then Blocks -> F Blocks
wrap Blocks
codeBlk   else forall a. Monoid a => a
mempty) forall a. Semigroup a => a -> a -> a
<>
    (if [(Text, Text)] -> Bool
exportsResults [(Text, Text)]
kv then F Blocks
resultsContent else 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"], [])
                         forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (F Inlines -> F Blocks
mkCaptionBlock F Inlines
caption forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
blk)

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

   exportsResults :: [(Text, Text)] -> Bool
   exportsResults :: [(Text, Text)] -> Bool
exportsResults = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"results", Text
"both"]) forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). Monad m => OrgParser m Text
blanklines
  forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) ()
resultsMarker forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Functor f => f a -> f ()
void forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
      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 (forall (m :: * -> *). Monad m => OrgParser m ()
metaLineStart forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLineNewline) forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) ()
resultsMarker)
  forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
block
 where
  resultsMarker :: ParsecT Sources u (ReaderT OrgParserLocal m) ()
resultsMarker = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s st m Text
stringAnyCase Text
"#+RESULTS:" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Text
language   <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). Monad m => OrgParser m Text
orgArgWord
  ([Text]
switchClasses, [(Text, Text)]
switchKv) <- forall (m :: * -> *).
Monad m =>
OrgParser m ([Text], [(Text, Text)])
switchesAsAttributes
  [(Text, Text)]
parameters <- 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 forall (m :: * -> *). Monad m => OrgParser m (Text, Text)
blockOption forall (m :: * -> *). Monad m => OrgParser m Char
newline
  forall (m :: * -> *) a. Monad m => a -> m a
return ( Text -> Text
translateLang Text
language forall a. a -> [a] -> [a]
: [Text]
switchClasses
         , Text -> [(Text, Text)]
originalLang Text
language forall a. Semigroup a => a -> a -> a
<> [(Text, Text)]
switchKv 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  [(Char, Maybe Text, SwitchPolarity)]
switches <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *).
Monad m =>
OrgParser m (Char, Maybe Text, SwitchPolarity)
switch 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` forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar)
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> 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)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"forall a. a -> [a] -> [a]
:[Text]
cls
                 SwitchPolarity
SwitchMinus -> [Text]
cls
    in (Text
"numberLines"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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SwitchPolarity] -> ShowS
$cshowList :: [SwitchPolarity] -> ShowS
show :: SwitchPolarity -> String
$cshow :: SwitchPolarity -> String
showsPrec :: Int -> SwitchPolarity -> ShowS
$cshowsPrec :: Int -> SwitchPolarity -> ShowS
Show, SwitchPolarity -> SwitchPolarity -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SwitchPolarity -> SwitchPolarity -> Bool
$c/= :: SwitchPolarity -> SwitchPolarity -> Bool
== :: SwitchPolarity -> SwitchPolarity -> Bool
$c== :: 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 forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-') forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (SwitchPolarity
SwitchPlus forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
Monad m =>
OrgParser m (Char, Maybe Text, SwitchPolarity)
lineNumberSwitch 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
               forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *).
Monad m =>
OrgParser m (Char, Maybe Text, SwitchPolarity)
whitespaceSwitch forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> 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, forall a. Maybe a
Nothing, SwitchPolarity
pol)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). Monad m => OrgParser m SwitchPolarity
switchPolarity forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> 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 = forall (m :: * -> *).
Monad m =>
Char
-> OrgParser m Text
-> OrgParser m (Char, Maybe Text, SwitchPolarity)
genericSwitch Char
'l' forall a b. (a -> b) -> a -> b
$
     forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> 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 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar (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
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"-i"
  forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s { orgStateTrimLeadBlkIndent :: Bool
orgStateTrimLeadBlkIndent = Bool
False }
  forall (m :: * -> *) a. Monad m => a -> m a
return (Char
'i', 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  SwitchPolarity
polarity <- forall (m :: * -> *). Monad m => OrgParser m SwitchPolarity
switchPolarity forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
  Maybe Text
arg <- 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
  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 = forall (m :: * -> *).
Monad m =>
Char
-> OrgParser m Text
-> OrgParser m (Char, Maybe Text, SwitchPolarity)
genericSwitch Char
'n' (forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Text
argKey <- forall (m :: * -> *). Monad m => OrgParser m Text
orgArgKey
  Text
paramValue <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"yes" forall (m :: * -> *). Monad m => OrgParser m Text
orgParamValue
  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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
T.pack forall a b. (a -> b) -> a -> b
$
  forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall (m :: * -> *). Monad m => OrgParser m Text
orgArgKey
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf String
"\n\r" 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
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* 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 = forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall a b. (a -> b) -> a -> b
$  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
oneOf String
"\n\r")
                        forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *). Monad m => OrgParser m ()
skipSpaces1 forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Text
name    <- Text -> Text
T.toUpper forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). Monad m => OrgParser m Text
drawerStart
  [Text]
content <- 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 forall (m :: * -> *). Monad m => OrgParser m Text
drawerLine (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall (m :: * -> *). Monad m => OrgParser m Text
drawerEnd)
  OrgParserState
state   <- 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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> ExportSettings
orgStateExportSettings forall a b. (a -> b) -> a -> b
$ OrgParserState
state of
    Either [Text] [Text]
_           | Text
name forall a. Eq a => a -> a -> Bool
== Text
"PROPERTIES" -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
    Left  [Text]
names | Text
name forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem`    [Text]
names -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
    Right [Text]
names | Text
name forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Text]
names -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
    Either [Text] [Text]
_           -> Text -> F Blocks -> F Blocks
drawerDiv Text
name forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 = forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
blocks forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Semigroup a => a -> a -> a
<> Text
"\n") 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 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a -> b) -> a -> b
$ Attr -> Blocks -> Blocks
B.divWith (forall a. Monoid a => a
mempty, [Text
drawerName, Text
"drawer"], forall a. Monoid a => a
mempty)

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

drawerEnd :: Monad m => OrgParser m Text
drawerEnd :: forall (m :: * -> *). Monad m => OrgParser m Text
drawerEnd = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s st m Text
stringAnyCase Text
":END:" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  BlockAttributes
figAttrs <- forall (m :: * -> *). PandocMonad m => OrgParser m BlockAttributes
blockAttributes
  Text
src <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => OrgParser m Text
selfTarget forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). Monad m => OrgParser m ()
endOfParagraph
  case Text -> Maybe Text
cleanLinkText Text
src of
    Maybe Text
Nothing     -> forall (m :: * -> *) a. MonadPlus m => m a
mzero
    Just Text
imgSrc -> do
      forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Text -> Bool
isImageFilename Text
imgSrc)
      let isFigure :: Bool
isFigure = forall a. Maybe a -> Bool
isJust forall a b. (a -> b) -> a -> b
$ BlockAttributes -> Maybe (F Inlines)
blockAttrCaption BlockAttributes
figAttrs
      forall (m :: * -> *) a. Monad m => a -> m a
return 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'[' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => OrgParser m Text
linkTarget forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* 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    = forall a. a -> Maybe a -> a
fromMaybe forall a. Monoid a => a
mempty forall a b. (a -> b) -> a -> b
$ BlockAttributes -> Maybe Text
blockAttrName BlockAttributes
figAttrs
       figCaption :: F Inlines
figCaption = forall a. a -> Maybe a -> a
fromMaybe forall a. Monoid a => a
mempty 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, 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 forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.image Text
imgSrc Text
"" forall a. Monoid a => a
mempty))
                forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
figCaption
           else Inlines -> Blocks
B.para forall b c a. (b -> c) -> (a -> b) -> a -> c
. Attr -> Text -> Text -> Inlines -> Inlines
B.imageWith Attr
attr Text
imgSrc Text
figName 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). Monad m => OrgParser m Char
newline forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Blocks
exampleCode forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
T.unlines forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *). Monad m => OrgParser m Text
exampleLine
 where
   exampleLine :: Monad m => OrgParser m Text
   exampleLine :: forall (m :: * -> *). Monad m => OrgParser m Text
exampleLine = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). Monad m => OrgParser m ()
exampleLineStart forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> 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 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  forall (m :: * -> *). PandocMonad m => OrgParser m Blocks
rawExportLine forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => OrgParser m Blocks
printbibliographyLine forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => OrgParser m Blocks
metaLine forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). Monad m => OrgParser m Blocks
commentLine

printbibliographyLine :: PandocMonad m => OrgParser m Blocks
printbibliographyLine :: forall (m :: * -> *). PandocMonad m => OrgParser m Blocks
printbibliographyLine = do
  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"#+print_bibliography:" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). Monad m => OrgParser m Text
anyLine
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Blocks -> Blocks
B.divWith (Text
"refs",[],[]) 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). Monad m => OrgParser m ()
metaLineStart forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s st m Text
stringAnyCase Text
"include:" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
  String
filename <- forall (m :: * -> *). PandocMonad m => OrgParser m String
includeTarget
  [Text]
includeArgs <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum)
  [(Text, Text)]
params <- 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]
_) -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Blocks
B.codeBlock forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => OrgParser m Text
parseRaw
      [Text
"export"] -> forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF forall a b. (a -> b) -> a -> b
$ forall a. [a] -> Many a
B.fromList []
      [Text
"export", Text
format] -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Blocks
B.rawBlock Text
format forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => OrgParser m Text
parseRaw
      (Text
"src" : [Text]
rest) -> do
        let attr :: Attr
attr = case [Text]
rest of
                     [Text
lang] -> (forall a. Monoid a => a
mempty, [Text
lang], forall a. Monoid a => a
mempty)
                     [Text]
_ -> Attr
nullAttr
        forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. Attr -> Text -> Blocks
B.codeBlockWith Attr
attr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => OrgParser m Text
parseRaw
      [Text]
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Many a
B.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Text, Text)] -> [Block] -> [Block]
blockFilter [(Text, Text)]
params forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => OrgParser m [Block]
blockList
  String
currentDir <- ShowS
takeDirectory forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourcePos -> String
sourceName forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  let (Maybe Int
startLine, Maybe Int
endLine) =
        case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"lines" [(Text, Text)]
params of
          Maybe Text
Nothing -> (forall a. Maybe a
Nothing, 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 (forall a. Eq a => a -> a -> Bool
/= Char
'-') Text
boundStr
                             endStr :: Text
endStr = (Char -> Bool) -> Text -> Text
T.takeWhileEnd (forall a. Eq a => a -> a -> Bool
/= Char
'-') Text
boundStr
                         in (forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead Text
begStr, forall a. Enum a => a -> a
pred forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead Text
endStr)
  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 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
    forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"'
    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 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf String
"\n\r\t") (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 = forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar 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 = forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"minlevel" [(Text, Text)]
params
    in case (Maybe Text
minlvl forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= 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 = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
Walk.query Block -> [Int]
headerLevel [Block]
blks
                         curMin :: Int
curMin = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum forall a b. (a -> b) -> a -> b
$ forall a. [a] -> Maybe (NonEmpty a)
nonEmpty [Int]
levels
                     in forall a b. Walkable a b => (a -> a) -> b -> b
Walk.walk (Int -> Block -> Block
shiftHeader (Int
curMin 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 forall a. Num a => a -> a -> a
- Int
shift forall a. Ord a => a -> a -> Bool
> Int
0  -> Int -> Attr -> [Inline] -> Block
Header (Int
lvl 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). Monad m => OrgParser m ()
metaLineStart
  Text
key <- forall (m :: * -> *). Monad m => OrgParser m Text
metaKey
  if Text
key 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). Monad m => OrgParser m Text
anyLine
    else 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 <- forall (m :: * -> *). Monad m => OrgParser m ()
metaLineStart forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). Monad m => OrgParser m Text
anyLine
  forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF forall a b. (a -> b) -> a -> b
$ Text -> Text -> Blocks
B.rawBlock Text
"org" forall a b. (a -> b) -> a -> b
$ 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 = forall (m :: * -> *). Monad m => OrgParser m ()
commentLineStart forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). Monad m => OrgParser m Text
anyLine forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColumnProperty] -> ShowS
$cshowList :: [ColumnProperty] -> ShowS
show :: ColumnProperty -> String
$cshow :: ColumnProperty -> String
showsPrec :: Int -> ColumnProperty -> ShowS
$cshowsPrec :: Int -> ColumnProperty -> ShowS
Show, ColumnProperty -> ColumnProperty -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ColumnProperty -> ColumnProperty -> Bool
$c/= :: ColumnProperty -> ColumnProperty -> Bool
== :: ColumnProperty -> ColumnProperty -> Bool
$c== :: ColumnProperty -> ColumnProperty -> Bool
Eq)

instance Default ColumnProperty where
  def :: ColumnProperty
def = Maybe Alignment -> Maybe Int -> ColumnProperty
ColumnProperty forall a. Maybe a
Nothing 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 = do
  Bool
withTables <- forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportWithTables
  F Blocks
tbl <- 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 forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
blocks forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
orgTable
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Bool
withTables then F Blocks
tbl else 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try 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 forall a. Eq a => a -> a -> Bool
== ParserContext
ListItemState Bool -> Bool -> Bool
&&
                             forall a. Maybe a -> Bool
isNothing (OrgParserState -> Maybe SourcePos
orgStateLastPreCharPos OrgParserState
st)
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> Bool
isFirstInListItem forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  BlockAttributes
blockAttrs <- forall (m :: * -> *). PandocMonad m => OrgParser m BlockAttributes
blockAttributes
  forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). Monad m => OrgParser m Char
tableStart
  [OrgTableRow]
rows <- forall (m :: * -> *). PandocMonad m => OrgParser m [OrgTableRow]
tableRows

  let caption :: F Inlines
caption = forall a. a -> Maybe a -> a
fromMaybe forall a. Monoid a => a
mempty (BlockAttributes -> Maybe (F Inlines)
blockAttrCaption BlockAttributes
blockAttrs)
  let orgTbl :: Future OrgParserState OrgTable
orgTbl = OrgTable -> OrgTable
normalizeTable forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [OrgTableRow] -> Future OrgParserState OrgTable
rowsToTable [OrgTableRow]
rows
  let identMb :: Maybe Text
identMb = BlockAttributes -> Maybe Text
blockAttrName BlockAttributes
blockAttrs
  let attr :: (Text, [a], [(Text, Text)])
attr = (forall a. a -> Maybe a -> a
fromMaybe forall a. Monoid a => a
mempty Maybe Text
identMb, [], BlockAttributes -> [(Text, Text)]
blockAttrKeyValues BlockAttributes
blockAttrs)
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> OrgTable -> Inlines -> Blocks
orgToPandocTable forall {a}. (Text, [a], [(Text, Text)])
attr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Future OrgParserState OrgTable
orgTbl forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> F Inlines
caption

orgToPandocTable :: Attr
                 -> OrgTable
                 -> Inlines
                 -> Blocks
orgToPandocTable :: Attr -> OrgTable -> Inlines -> Blocks
orgToPandocTable Attr
attr (OrgTable [ColumnProperty]
colProps [Blocks]
heads [[Blocks]]
lns) Inlines
caption =
  let totalWidth :: Maybe Int
totalWidth = if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (forall a. Maybe a -> Bool
isJust forall b c a. (b -> c) -> (a -> b) -> a -> c
. ColumnProperty -> Maybe Int
columnRelWidth) [ColumnProperty]
colProps
                   then forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall a. a -> Maybe a -> a
fromMaybe Int
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. ColumnProperty -> Maybe Int
columnRelWidth) [ColumnProperty]
colProps
                   else forall a. Maybe a
Nothing
  in Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Blocks
B.tableWith Attr
attr (Blocks -> Caption
B.simpleCaption forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
B.plain Inlines
caption)
                 (forall a b. (a -> b) -> [a] -> [b]
map (Maybe Int -> ColumnProperty -> ColSpec
convertColProp Maybe Int
totalWidth) [ColumnProperty]
colProps)
                 (Attr -> [Row] -> TableHead
TableHead Attr
nullAttr forall a b. (a -> b) -> a -> b
$ [Blocks] -> [Row]
toHeaderRow [Blocks]
heads)
                 [Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody Attr
nullAttr RowHeadColumns
0 [] forall a b. (a -> b) -> a -> b
$ 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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 (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' = forall a. a -> Maybe a -> a
fromMaybe Alignment
AlignDefault forall a b. (a -> b) -> a -> b
$ ColumnProperty -> Maybe Alignment
columnAlignment ColumnProperty
colProp
       width' :: Maybe Double
width' = (\Int
w Int
t -> forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
w forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
t)
                forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ColumnProperty -> Maybe Int
columnRelWidth ColumnProperty
colProp
                forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Int
totalWidth
     in (Alignment
align', 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall (m :: * -> *). Monad m => OrgParser m OrgTableRow
tableAlignRow forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). Monad m => OrgParser m OrgTableRow
tableHline forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => OrgParser m OrgTableRow
tableContentRow)

tableContentRow :: PandocMonad m => OrgParser m OrgTableRow
tableContentRow :: forall (m :: * -> *). PandocMonad m => OrgParser m OrgTableRow
tableContentRow = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  F [Blocks] -> OrgTableRow
OrgContentRow forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *). Monad m => OrgParser m Char
tableStart forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> 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 forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
tableContentCell 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Blocks
B.plain forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Future s Inlines -> Future s Inlines
trimInlinesF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline forall (m :: * -> *). Monad m => OrgParser m Char
endOfCell

tableAlignRow :: Monad m => OrgParser m OrgTableRow
tableAlignRow :: forall (m :: * -> *). Monad m => OrgParser m OrgTableRow
tableAlignRow = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). Monad m => OrgParser m Char
tableStart
  [ColumnProperty]
colProps <- 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 forall (m :: * -> *). Monad m => OrgParser m ColumnProperty
columnPropertyCell forall (m :: * -> *). Monad m => OrgParser m Char
newline
  -- Empty rows are regular (i.e. content) rows, not alignment rows.
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (forall a. Eq a => a -> a -> Bool
/= forall a. Default a => a
def) [ColumnProperty]
colProps
  forall (m :: * -> *) a. Monad m => a -> m a
return 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 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 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 forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). Monad m => OrgParser m Char
endOfCell)
   propCell :: ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) ColumnProperty
propCell = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Maybe Alignment -> Maybe Int -> ColumnProperty
ColumnProperty
                 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
                      forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'<'
                      forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe forall (m :: * -> *). Monad m => OrgParser m Alignment
tableAlignFromChar)
                 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead)
                      forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>'
                      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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'l' forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Alignment
AlignLeft
         , forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'c' forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Alignment
AlignCenter
         , forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'r' 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  OrgTableRow
OrgHlineRow forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). Monad m => OrgParser m Char
tableStart forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). Monad m => OrgParser m Text
anyLine)

endOfCell :: Monad m => OrgParser m Char
endOfCell :: forall (m :: * -> *). Monad m => OrgParser m Char
endOfCell = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). Monad m => OrgParser m Char
newline

rowsToTable :: [OrgTableRow]
            -> F OrgTable
rowsToTable :: [OrgTableRow] -> Future OrgParserState OrgTable
rowsToTable = 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 forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty 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 forall a. Eq a => a -> a -> Bool
/= forall a. Monoid a => a
mempty
            then [Blocks]
heads
            else case [[Blocks]]
rows of
                   ([Blocks]
r:[[Blocks]]
_) -> [Blocks]
r
                   [[Blocks]]
_     -> forall a. Monoid a => a
mempty
   cols :: Int
cols = forall (t :: * -> *) a. Foldable t => t a -> Int
length [Blocks]
refRow
   fillColumns :: [a] -> a -> [a]
fillColumns [a]
base a
padding = forall a. Int -> [a] -> [a]
take Int
cols forall a b. (a -> b) -> a -> b
$ [a]
base forall a. [a] -> [a] -> [a]
++ forall a. a -> [a]
repeat a
padding
   colProps' :: [ColumnProperty]
colProps' = forall {a}. [a] -> a -> [a]
fillColumns [ColumnProperty]
colProps 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       -> forall (m :: * -> *) a. Monad m => a -> m a
return OrgTable
singleRowPromotedToHeader
    OrgAlignRow [ColumnProperty]
props -> forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ColumnProperty] -> OrgTable
setProperties 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 :: [Blocks]
orgTableHeader = [Blocks]
b , orgTableRows :: [[Blocks]]
orgTableRows = [] }
     OrgTable
_   -> OrgTable
tbl

   setProperties :: [ColumnProperty] -> OrgTable
   setProperties :: [ColumnProperty] -> OrgTable
setProperties [ColumnProperty]
ps = OrgTable
tbl{ orgTableColumnProperties :: [ColumnProperty]
orgTableColumnProperties = [ColumnProperty]
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.
     forall (m :: * -> *) a. Monad m => a -> m a
return OrgTable
tbl{ orgTableRows :: [[Blocks]]
orgTableRows = [[Blocks]]
oldRows forall a. [a] -> [a] -> [a]
++ [[Blocks]
newRow] }


--
-- LaTeX fragments
--
latexFragment :: PandocMonad m => OrgParser m (F Blocks)
latexFragment :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
latexFragment = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Text
envName <- forall (m :: * -> *). Monad m => OrgParser m Text
latexEnvStart
  TeXExport
texOpt  <- forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> TeXExport
exportWithLatex
  let envStart :: Text
envStart = Text
"\\begin{" forall a. Semigroup a => a -> a -> a
<> Text
envName forall a. Semigroup a => a -> a -> a
<> Text
"}"
  let envEnd :: Text
envEnd = Text
"\\end{" forall a. Semigroup a => a -> a -> a
<> Text
envName forall a. Semigroup a => a -> a -> a
<> Text
"}"
  Text
envContent <- do
    Text
content <- 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 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall (m :: * -> *). Monad m => Text -> OrgParser m ()
latexEnd Text
envName)
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
envStart forall a. Semigroup a => a -> a -> a
<> Text
content forall a. Semigroup a => a -> a -> a
<> Text
envEnd
  forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF forall a b. (a -> b) -> a -> b
$ case TeXExport
texOpt of
    TeXExport
TeXExport -> Text -> Text -> Blocks
B.rawBlock Text
"latex" (Text
envContent forall a. Semigroup a => a -> a -> a
<> Text
"\n")
    TeXExport
TeXIgnore   -> forall a. Monoid a => a
mempty
    TeXExport
TeXVerbatim -> Inlines -> Blocks
B.para forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.text 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Functor f => f a -> f ()
void
     forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s st m Text
textStr (Text
"\\end{" forall a. Semigroup a => a -> a -> a
<> Text
envName forall a. Semigroup a => a -> a -> a
<> Text
"}")
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Text
ref <- forall (m :: * -> *). Monad m => OrgParser m Text
noteMarker forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
  F Blocks
content <- forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
block ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
endOfFootnote
  forall (m :: * -> *).
PandocMonad m =>
OrgNoteRecord -> OrgParser m ()
addToNotesTable (Text
ref, F Blocks
content)
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
 where
   endOfFootnote :: ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
endOfFootnote =  forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
                forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). Monad m => OrgParser m Text
noteMarker
                forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). Monad m => OrgParser m Int
headerStart
                forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  -- Make sure we are not looking at a headline
  forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' forall (m :: * -> *). Monad m => OrgParser m Int
headerStart
  F Inlines
ils <- forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlines
  Bool
nl <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (forall (m :: * -> *). Monad m => OrgParser m Char
newline 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.
  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
nl
       forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *). Monad m => OrgParser m ()
inList forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (forall (f :: * -> *) a. Functor f => f a -> f ()
void forall (m :: * -> *). Monad m => OrgParser m (Int, ListAttributes)
orderedListStart forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (f :: * -> *) a. Functor f => f a -> f ()
void forall (m :: * -> *). Monad m => OrgParser m Int
bulletListStart))
       forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> (Inlines -> Blocks
B.para forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
ils))
    forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>  forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Blocks
B.plain 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 = forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
definitionList, forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
bulletList, forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
orderedList ] 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Int
indent <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). Monad m => OrgParser m Int
bulletListStart
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([(Inlines, [Blocks])] -> Blocks
B.definitionList forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
compactifyDL) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *).
PandocMonad m =>
OrgParser m Int
-> OrgParser m (Future OrgParserState (Inlines, [Blocks]))
definitionListItem (forall (m :: * -> *). Monad m => OrgParser m Int
bulletListStart 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Int
indent <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). Monad m => OrgParser m Int
bulletListStart
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Blocks] -> Blocks
B.bulletList forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blocks] -> [Blocks]
compactify) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *).
PandocMonad m =>
OrgParser m Int -> OrgParser m (F Blocks)
listItem (forall (m :: * -> *). Monad m => OrgParser m Int
bulletListStart 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Int
n <- OrgParser m Int
indentedMarker
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Int
minIndent forall a. Ord a => a -> a -> Bool
<= Int
n)
  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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  (Int
indent, ListAttributes
attr) <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *). Monad m => OrgParser m (Int, ListAttributes)
orderedListStart
  ListAttributes
attr' <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (forall {a} {b} {c}. (a, b, c) -> a
fst3 ListAttributes
attr, ListNumberStyle
DefaultStyle, ListNumberDelim
DefaultDelim) forall a b. (a -> b) -> a -> b
$
           forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_fancy_lists forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ListAttributes
attr
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ListAttributes -> [Blocks] -> Blocks
B.orderedListWith ListAttributes
attr' forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blocks] -> [Blocks]
compactify) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *).
PandocMonad m =>
OrgParser m Int -> OrgParser m (F Blocks)
listItem ((forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). Monad m => OrgParser m (Int, ListAttributes)
orderedListStart) forall (m :: * -> *). OrgParser m Int -> Int -> OrgParser m Int
`indented` Int
indent))
  where fst3 :: (a, b, c) -> a
fst3 (a
x,b
_,c
_) = a
x

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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Int
markerLength <- OrgParser m Int
parseIndentedMarker
  Text
term <- 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 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf String
"\n\r") (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 <- forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLineNewline
  Text
blank <- 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" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline)
  Text
cont <- [Text] -> Text
T.concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall (m :: * -> *). PandocMonad m => Int -> OrgParser m Text
listContinuation Int
markerLength)
  F Inlines
term' <- forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlines Text
term
  F Blocks
contents' <- forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
blocks forall a b. (a -> b) -> a -> b
$ Text
line1 forall a. Semigroup a => a -> a -> a
<> Text
blank forall a. Semigroup a => a -> a -> a
<> Text
cont
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
term' forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. a -> [a] -> [a]
:[]) F Blocks
contents'
 where
   definitionMarker :: ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) String
definitionMarker =
     forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"::" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead 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
  forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_task_lists
  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'[' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) Checkbox
status forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']') 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 = forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
      [ Checkbox
UncheckedBox   forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
' '
      , Checkbox
CheckedBox     forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'X'
      , Checkbox
SemicheckedBox forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ 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 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
Monad m =>
ParserContext -> OrgParser m a -> OrgParser m a
withContext ParserContext
ListItemState forall a b. (a -> b) -> a -> b
$ do
  Int
markerLength <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try OrgParser m Int
parseIndentedMarker
  Maybe Checkbox
box <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe forall (m :: * -> *). PandocMonad m => OrgParser m Checkbox
checkbox
  Text
firstLine <- forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLineNewline
  Text
blank <- 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" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline)
  Text
rest <- [Text] -> Text
T.concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall (m :: * -> *). PandocMonad m => Int -> OrgParser m Text
listContinuation Int
markerLength)
  F Blocks
contents <- forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString (do F Blocks
initial <- forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
paraOrPlain forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
                                  F Blocks
subsequent <- forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
blocks
                                  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ F Blocks
initial forall a. Semigroup a => a -> a -> a
<> F Blocks
subsequent)
                (Text
firstLine forall a. Semigroup a => a -> a -> a
<> Text
blank forall a. Semigroup a => a -> a -> a
<> Text
rest)
  forall (m :: * -> *) a. Monad m => a -> m a
return (forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. a -> a
id (Inline -> Blocks -> Blocks
prependInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. Checkbox -> Inline
checkboxToInlines) Maybe Checkbox
box 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 = forall a. [a] -> Many a
B.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Block] -> [Block]
prepend forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Many a -> [a]
B.toList
  where
    prepend :: [Block] -> [Block]
prepend (Plain [Inline]
is : [Block]
bs) = [Inline] -> Block
Plain (Inline
inlns forall a. a -> [a] -> [a]
: Inline
Space forall a. a -> [a] -> [a]
: [Inline]
is) forall a. a -> [a] -> [a]
: [Block]
bs
    prepend (Para  [Inline]
is : [Block]
bs) = [Inline] -> Block
Para  (Inline
inlns forall a. a -> [a] -> [a]
: Inline
Space forall a. a -> [a] -> [a]
: [Inline]
is) forall a. a -> [a] -> [a]
: [Block]
bs
    prepend [Block]
bs              = [Inline] -> Block
Plain [Inline
inlns, Inline
Space] 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
  forall a. Monoid a => a -> a -> a
mappend forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Text] -> Text
T.concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *). PandocMonad m => Int -> OrgParser m Text
listContinuation' Int
markerLength))
          forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar 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 =
      forall (m :: * -> *). PandocMonad m => Int -> OrgParser m Text
blockLines Int
indentation forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, HasReaderOptions st) =>
Int -> ParsecT s st m Text
indentWith Int
indentation forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> 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 =
      forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, HasReaderOptions st) =>
Int -> ParsecT s st m Text
indentWith Int
indentation
                       forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => OrgParser m BlockAttributes
blockAttributes
                       forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\BlockAttributes
blockAttrs ->
                              case BlockAttributes -> Attr
attrFromBlockAttributes BlockAttributes
blockAttrs of
                                (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 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar
                                Attr
_ -> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, HasReaderOptions st) =>
Int -> ParsecT s st m Text
indentWith Int
indentation))
            forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) st a.
Monad m =>
ParsecT Sources st m a -> ParsecT Sources st m (a, Text)
withRaw forall (m :: * -> *). PandocMonad m => OrgParser m (F Blocks)
orgBlock)