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

   Maintainer  : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>

Parsers for org-mode headlines and document subtrees
-}
module Text.Pandoc.Readers.Org.DocumentTree
  ( documentTree
  , unprunedHeadlineToBlocks
  ) where

import Control.Arrow ((***), first)
import Control.Monad (guard)
import Data.List (intersperse)
import Data.Maybe (mapMaybe)
import Data.Text (Text)
import Text.Pandoc.Builder (Blocks, Inlines)
import Text.Pandoc.Class.PandocMonad (PandocMonad)
import Text.Pandoc.Definition
import Text.Pandoc.Readers.Org.BlockStarts
import Text.Pandoc.Readers.Org.ParserState
import Text.Pandoc.Readers.Org.Parsing

import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Text.Pandoc.Builder as B

--
-- Org headers
--

-- | Parse input as org document tree.
documentTree :: PandocMonad m
             => OrgParser m (F Blocks)
             -> OrgParser m (F Inlines)
             -> OrgParser m (F Headline)
documentTree :: OrgParser m (F Blocks)
-> OrgParser m (F Inlines) -> OrgParser m (F Headline)
documentTree OrgParser m (F Blocks)
blocks OrgParser m (F Inlines)
inline = do
  F Blocks
initialBlocks <- OrgParser m (F Blocks)
blocks
  Future OrgParserState [Headline]
headlines <- [F Headline] -> Future OrgParserState [Headline]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([F Headline] -> Future OrgParserState [Headline])
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) [F Headline]
-> ParsecT
     Text
     OrgParserState
     (ReaderT OrgParserLocal m)
     (Future OrgParserState [Headline])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m (F Headline)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) [F Headline]
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 (OrgParser m (F Blocks)
-> OrgParser m (F Inlines) -> Int -> OrgParser m (F Headline)
forall (m :: * -> *).
PandocMonad m =>
OrgParser m (F Blocks)
-> OrgParser m (F Inlines) -> Int -> OrgParser m (F Headline)
headline OrgParser m (F Blocks)
blocks OrgParser m (F Inlines)
inline Int
1) ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
  Future OrgParserState [Inline]
title <- (Meta -> [Inline])
-> Future OrgParserState Meta -> Future OrgParserState [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Meta -> [Inline]
docTitle (Future OrgParserState Meta -> Future OrgParserState [Inline])
-> (OrgParserState -> Future OrgParserState Meta)
-> OrgParserState
-> Future OrgParserState [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> Future OrgParserState Meta
orgStateMeta (OrgParserState -> Future OrgParserState [Inline])
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT
     Text
     OrgParserState
     (ReaderT OrgParserLocal m)
     (Future OrgParserState [Inline])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  F Headline -> OrgParser m (F Headline)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Headline -> OrgParser m (F Headline))
-> F Headline -> OrgParser m (F Headline)
forall a b. (a -> b) -> a -> b
$ do
    [Headline]
headlines' <- Future OrgParserState [Headline]
headlines
    Blocks
initialBlocks' <- F Blocks
initialBlocks
    [Inline]
title' <- Future OrgParserState [Inline]
title
    Headline -> F Headline
forall (m :: * -> *) a. Monad m => a -> m a
return Headline :: Int
-> Maybe TodoMarker
-> Inlines
-> [Tag]
-> PlanningInfo
-> Properties
-> Blocks
-> [Headline]
-> Headline
Headline
      { headlineLevel :: Int
headlineLevel = Int
0
      , headlineTodoMarker :: Maybe TodoMarker
headlineTodoMarker = Maybe TodoMarker
forall a. Maybe a
Nothing
      , headlineText :: Inlines
headlineText = [Inline] -> Inlines
forall a. [a] -> Many a
B.fromList [Inline]
title'
      , headlineTags :: [Tag]
headlineTags = [Tag]
forall a. Monoid a => a
mempty
      , headlinePlanning :: PlanningInfo
headlinePlanning = PlanningInfo
emptyPlanning
      , headlineProperties :: Properties
headlineProperties = Properties
forall a. Monoid a => a
mempty
      , headlineContents :: Blocks
headlineContents = Blocks
initialBlocks'
      , headlineChildren :: [Headline]
headlineChildren = [Headline]
headlines'
      }

-- | Create a tag containing the given string.
toTag :: Text -> Tag
toTag :: Text -> Tag
toTag = Text -> Tag
Tag

-- | The key (also called name or type) of a property.
newtype PropertyKey = PropertyKey { PropertyKey -> Text
fromKey :: Text }
  deriving (Int -> PropertyKey -> ShowS
[PropertyKey] -> ShowS
PropertyKey -> String
(Int -> PropertyKey -> ShowS)
-> (PropertyKey -> String)
-> ([PropertyKey] -> ShowS)
-> Show PropertyKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PropertyKey] -> ShowS
$cshowList :: [PropertyKey] -> ShowS
show :: PropertyKey -> String
$cshow :: PropertyKey -> String
showsPrec :: Int -> PropertyKey -> ShowS
$cshowsPrec :: Int -> PropertyKey -> ShowS
Show, PropertyKey -> PropertyKey -> Bool
(PropertyKey -> PropertyKey -> Bool)
-> (PropertyKey -> PropertyKey -> Bool) -> Eq PropertyKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PropertyKey -> PropertyKey -> Bool
$c/= :: PropertyKey -> PropertyKey -> Bool
== :: PropertyKey -> PropertyKey -> Bool
$c== :: PropertyKey -> PropertyKey -> Bool
Eq, Eq PropertyKey
Eq PropertyKey
-> (PropertyKey -> PropertyKey -> Ordering)
-> (PropertyKey -> PropertyKey -> Bool)
-> (PropertyKey -> PropertyKey -> Bool)
-> (PropertyKey -> PropertyKey -> Bool)
-> (PropertyKey -> PropertyKey -> Bool)
-> (PropertyKey -> PropertyKey -> PropertyKey)
-> (PropertyKey -> PropertyKey -> PropertyKey)
-> Ord PropertyKey
PropertyKey -> PropertyKey -> Bool
PropertyKey -> PropertyKey -> Ordering
PropertyKey -> PropertyKey -> PropertyKey
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: PropertyKey -> PropertyKey -> PropertyKey
$cmin :: PropertyKey -> PropertyKey -> PropertyKey
max :: PropertyKey -> PropertyKey -> PropertyKey
$cmax :: PropertyKey -> PropertyKey -> PropertyKey
>= :: PropertyKey -> PropertyKey -> Bool
$c>= :: PropertyKey -> PropertyKey -> Bool
> :: PropertyKey -> PropertyKey -> Bool
$c> :: PropertyKey -> PropertyKey -> Bool
<= :: PropertyKey -> PropertyKey -> Bool
$c<= :: PropertyKey -> PropertyKey -> Bool
< :: PropertyKey -> PropertyKey -> Bool
$c< :: PropertyKey -> PropertyKey -> Bool
compare :: PropertyKey -> PropertyKey -> Ordering
$ccompare :: PropertyKey -> PropertyKey -> Ordering
$cp1Ord :: Eq PropertyKey
Ord)

-- | Create a property key containing the given string.  Org mode keys are
-- case insensitive and are hence converted to lower case.
toPropertyKey :: Text -> PropertyKey
toPropertyKey :: Text -> PropertyKey
toPropertyKey = Text -> PropertyKey
PropertyKey (Text -> PropertyKey) -> (Text -> Text) -> Text -> PropertyKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.toLower

-- | The value assigned to a property.
newtype PropertyValue = PropertyValue { PropertyValue -> Text
fromValue :: Text }

-- | Create a property value containing the given string.
toPropertyValue :: Text -> PropertyValue
toPropertyValue :: Text -> PropertyValue
toPropertyValue = Text -> PropertyValue
PropertyValue

-- | Check whether the property value is non-nil (i.e. truish).
isNonNil :: PropertyValue -> Bool
isNonNil :: PropertyValue -> Bool
isNonNil PropertyValue
p = Text -> Text
T.toLower (PropertyValue -> Text
fromValue PropertyValue
p) Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Text
"()", Text
"{}", Text
"nil"]

-- | Key/value pairs from a PROPERTIES drawer
type Properties = [(PropertyKey, PropertyValue)]

-- | Org mode headline (i.e. a document subtree).
data Headline = Headline
  { Headline -> Int
headlineLevel      :: Int
  , Headline -> Maybe TodoMarker
headlineTodoMarker :: Maybe TodoMarker
  , Headline -> Inlines
headlineText       :: Inlines
  , Headline -> [Tag]
headlineTags       :: [Tag]
  , Headline -> PlanningInfo
headlinePlanning   :: PlanningInfo -- ^ subtree planning information
  , Headline -> Properties
headlineProperties :: Properties
  , Headline -> Blocks
headlineContents   :: Blocks
  , Headline -> [Headline]
headlineChildren   :: [Headline]
  }

-- | Read an Org mode headline and its contents (i.e. a document subtree).
-- @lvl@ gives the minimum acceptable level of the tree.
headline :: PandocMonad m
         => OrgParser m (F Blocks)
         -> OrgParser m (F Inlines)
         -> Int
         -> OrgParser m (F Headline)
headline :: OrgParser m (F Blocks)
-> OrgParser m (F Inlines) -> Int -> OrgParser m (F Headline)
headline OrgParser m (F Blocks)
blocks OrgParser m (F Inlines)
inline Int
lvl = OrgParser m (F Headline) -> OrgParser m (F Headline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Headline) -> OrgParser m (F Headline))
-> OrgParser m (F Headline) -> OrgParser m (F Headline)
forall a b. (a -> b) -> a -> b
$ do
  Int
level <- OrgParser m Int
forall (m :: * -> *). Monad m => OrgParser m Int
headerStart
  Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Int
lvl Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
level)
  Maybe TodoMarker
todoKw <- ParsecT Text OrgParserState (ReaderT OrgParserLocal m) TodoMarker
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) (Maybe TodoMarker)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ParsecT Text OrgParserState (ReaderT OrgParserLocal m) TodoMarker
forall (m :: * -> *). Monad m => OrgParser m TodoMarker
todoKeyword
  ([F Inlines]
title, [Tag]
tags) <- OrgParser m (F Inlines)
-> OrgParser m [Tag] -> OrgParser m ([F Inlines], [Tag])
forall (m :: * -> *) a b.
Monad m =>
OrgParser m a -> OrgParser m b -> OrgParser m ([a], b)
manyThen OrgParser m (F Inlines)
inline OrgParser m [Tag]
forall (m :: * -> *). Monad m => OrgParser m [Tag]
endOfTitle
  PlanningInfo
planning   <- PlanningInfo
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) PlanningInfo
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) PlanningInfo
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option PlanningInfo
emptyPlanning ParsecT Text OrgParserState (ReaderT OrgParserLocal m) PlanningInfo
forall (m :: * -> *). Monad m => OrgParser m PlanningInfo
planningInfo
  Properties
properties <- Properties
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) Properties
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) Properties
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Properties
forall a. Monoid a => a
mempty ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Properties
forall (m :: * -> *). Monad m => OrgParser m Properties
propertiesDrawer
  F Blocks
contents   <- OrgParser m (F Blocks)
blocks
  [F Headline]
children   <- OrgParser m (F Headline)
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) [F Headline]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (OrgParser m (F Blocks)
-> OrgParser m (F Inlines) -> Int -> OrgParser m (F Headline)
forall (m :: * -> *).
PandocMonad m =>
OrgParser m (F Blocks)
-> OrgParser m (F Inlines) -> Int -> OrgParser m (F Headline)
headline OrgParser m (F Blocks)
blocks OrgParser m (F Inlines)
inline (Int
level Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1))
  F Headline -> OrgParser m (F Headline)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Headline -> OrgParser m (F Headline))
-> F Headline -> OrgParser m (F Headline)
forall a b. (a -> b) -> a -> b
$ do
    Inlines
title'    <- F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF ([F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat [F Inlines]
title)
    Blocks
contents' <- F Blocks
contents
    [Headline]
children' <- [F Headline] -> Future OrgParserState [Headline]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [F Headline]
children
    Headline -> F Headline
forall (m :: * -> *) a. Monad m => a -> m a
return Headline :: Int
-> Maybe TodoMarker
-> Inlines
-> [Tag]
-> PlanningInfo
-> Properties
-> Blocks
-> [Headline]
-> Headline
Headline
      { headlineLevel :: Int
headlineLevel = Int
level
      , headlineTodoMarker :: Maybe TodoMarker
headlineTodoMarker = Maybe TodoMarker
todoKw
      , headlineText :: Inlines
headlineText = Inlines
title'
      , headlineTags :: [Tag]
headlineTags = [Tag]
tags
      , headlinePlanning :: PlanningInfo
headlinePlanning = PlanningInfo
planning
      , headlineProperties :: Properties
headlineProperties = Properties
properties
      , headlineContents :: Blocks
headlineContents = Blocks
contents'
      , headlineChildren :: [Headline]
headlineChildren = [Headline]
children'
      }
 where
   endOfTitle :: Monad m => OrgParser m [Tag]
   endOfTitle :: OrgParser m [Tag]
endOfTitle = OrgParser m [Tag] -> OrgParser m [Tag]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m [Tag] -> OrgParser m [Tag])
-> OrgParser m [Tag] -> OrgParser m [Tag]
forall a b. (a -> b) -> a -> b
$ do
     ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces
     [Tag]
tags <- [Tag] -> OrgParser m [Tag] -> OrgParser m [Tag]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] (OrgParser m [Tag]
forall (m :: * -> *). Monad m => OrgParser m [Tag]
headerTags OrgParser m [Tag]
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m [Tag]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces)
     OrgParser m Char
forall (m :: * -> *). Monad m => OrgParser m Char
newline
     [Tag] -> OrgParser m [Tag]
forall (m :: * -> *) a. Monad m => a -> m a
return [Tag]
tags

   headerTags :: Monad m => OrgParser m [Tag]
   headerTags :: OrgParser m [Tag]
headerTags = OrgParser m [Tag] -> OrgParser m [Tag]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m [Tag] -> OrgParser m [Tag])
-> OrgParser m [Tag] -> OrgParser m [Tag]
forall a b. (a -> b) -> a -> b
$ do
     Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
':'
     ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Tag
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m [Tag]
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]
endBy1 (Text -> Tag
toTag (Text -> Tag)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Tag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *). Monad m => OrgParser m Text
orgTagWord) (Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
':')

   manyThen :: Monad m
            => OrgParser m a
            -> OrgParser m b
            -> OrgParser m ([a], b)
   manyThen :: OrgParser m a -> OrgParser m b -> OrgParser m ([a], b)
manyThen OrgParser m a
p OrgParser m b
end = (([],) (b -> ([a], b)) -> OrgParser m b -> OrgParser m ([a], b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m b -> OrgParser m b
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try OrgParser m b
end) OrgParser m ([a], b)
-> OrgParser m ([a], b) -> OrgParser m ([a], b)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do
     a
x <- OrgParser m a
p
     ([a] -> [a]) -> ([a], b) -> ([a], b)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:) (([a], b) -> ([a], b))
-> OrgParser m ([a], b) -> OrgParser m ([a], b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m a -> OrgParser m b -> OrgParser m ([a], b)
forall (m :: * -> *) a b.
Monad m =>
OrgParser m a -> OrgParser m b -> OrgParser m ([a], b)
manyThen OrgParser m a
p OrgParser m b
end

   -- titleFollowedByTags :: Monad m => OrgParser m (Inlines, [Tag])
   -- titleFollowedByTags = do


unprunedHeadlineToBlocks :: Monad m => Headline -> OrgParserState -> OrgParser m [Block]
unprunedHeadlineToBlocks :: Headline -> OrgParserState -> OrgParser m [Block]
unprunedHeadlineToBlocks Headline
hdln OrgParserState
st =
  let usingSelectedTags :: Bool
usingSelectedTags = Headline -> OrgParserState -> Bool
docContainsSelectTags Headline
hdln OrgParserState
st
      rootNode :: Headline
rootNode = if Bool -> Bool
not Bool
usingSelectedTags
                   then Headline
hdln
                   else Headline -> OrgParserState -> Headline
includeRootAndSelected Headline
hdln OrgParserState
st
      rootNode' :: Headline
rootNode' = Headline -> OrgParserState -> Headline
removeExplicitlyExcludedNodes Headline
rootNode OrgParserState
st
  in if Bool -> Bool
not Bool
usingSelectedTags Bool -> Bool -> Bool
||
        (Tag -> Bool) -> [Tag] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Tag -> Set Tag -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` OrgParserState -> Set Tag
orgStateSelectTags OrgParserState
st) (Headline -> [Tag]
headlineTags Headline
rootNode')
        then do Blocks
headlineBlocks <- Headline -> OrgParser m Blocks
forall (m :: * -> *). Monad m => Headline -> OrgParser m Blocks
headlineToBlocks Headline
rootNode'
                -- ignore first headline, it's the document's title
                [Block] -> OrgParser m [Block]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Block] -> OrgParser m [Block])
-> (Blocks -> [Block]) -> Blocks -> OrgParser m [Block]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Block] -> [Block]
forall a. Int -> [a] -> [a]
drop Int
1 ([Block] -> [Block]) -> (Blocks -> [Block]) -> Blocks -> [Block]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blocks -> [Block]
forall a. Many a -> [a]
B.toList (Blocks -> OrgParser m [Block]) -> Blocks -> OrgParser m [Block]
forall a b. (a -> b) -> a -> b
$ Blocks
headlineBlocks
        else do Blocks
headlineBlocks <- [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Blocks)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Blocks]
-> OrgParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Headline -> OrgParser m Blocks)
-> [Headline]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Headline -> OrgParser m Blocks
forall (m :: * -> *). Monad m => Headline -> OrgParser m Blocks
headlineToBlocks
                                                   (Headline -> [Headline]
headlineChildren Headline
rootNode')
                [Block] -> OrgParser m [Block]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Block] -> OrgParser m [Block])
-> (Blocks -> [Block]) -> Blocks -> OrgParser m [Block]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blocks -> [Block]
forall a. Many a -> [a]
B.toList (Blocks -> OrgParser m [Block]) -> Blocks -> OrgParser m [Block]
forall a b. (a -> b) -> a -> b
$ Blocks
headlineBlocks

-- | Convert an Org mode headline (i.e. a document tree) into pandoc's Blocks
headlineToBlocks :: Monad m => Headline -> OrgParser m Blocks
headlineToBlocks :: Headline -> OrgParser m Blocks
headlineToBlocks Headline
hdln = do
  Int
maxLevel <- (ExportSettings -> Int) -> OrgParser m Int
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Int
exportHeadlineLevels
  let tags :: [Tag]
tags = Headline -> [Tag]
headlineTags Headline
hdln
  let text :: Inlines
text = Headline -> Inlines
headlineText Headline
hdln
  let level :: Int
level = Headline -> Int
headlineLevel Headline
hdln
  case () of
    ()
_ | (Tag -> Bool) -> [Tag] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Tag -> Bool
isArchiveTag  [Tag]
tags -> Headline -> OrgParser m Blocks
forall (m :: * -> *). Monad m => Headline -> OrgParser m Blocks
archivedHeadlineToBlocks Headline
hdln
    ()
_ | Inlines -> Bool
isCommentTitle Inlines
text    -> Blocks -> OrgParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
    ()
_ | Int
maxLevel Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
level      -> Headline -> OrgParser m Blocks
forall (m :: * -> *). Monad m => Headline -> OrgParser m Blocks
headlineToHeaderWithList Headline
hdln
    ()
_ | Bool
otherwise              -> Headline -> OrgParser m Blocks
forall (m :: * -> *). Monad m => Headline -> OrgParser m Blocks
headlineToHeaderWithContents Headline
hdln

removeExplicitlyExcludedNodes :: Headline -> OrgParserState -> Headline
removeExplicitlyExcludedNodes :: Headline -> OrgParserState -> Headline
removeExplicitlyExcludedNodes Headline
hdln OrgParserState
st =
  Headline
hdln { headlineChildren :: [Headline]
headlineChildren =
           [Headline -> OrgParserState -> Headline
removeExplicitlyExcludedNodes Headline
childHdln OrgParserState
st |
              Headline
childHdln <- Headline -> [Headline]
headlineChildren Headline
hdln,
              Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Headline -> OrgParserState -> Bool
headlineContainsExcludeTags Headline
childHdln OrgParserState
st] }

includeRootAndSelected :: Headline -> OrgParserState -> Headline
includeRootAndSelected :: Headline -> OrgParserState -> Headline
includeRootAndSelected Headline
hdln OrgParserState
st =
  Headline
hdln { headlineChildren :: [Headline]
headlineChildren = (Headline -> Maybe Headline) -> [Headline] -> [Headline]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Headline -> OrgParserState -> Maybe Headline
`includeAncestorsAndSelected` OrgParserState
st)
                                     (Headline -> [Headline]
headlineChildren Headline
hdln)}

docContainsSelectTags :: Headline -> OrgParserState -> Bool
docContainsSelectTags :: Headline -> OrgParserState -> Bool
docContainsSelectTags Headline
hdln OrgParserState
st =
  Headline -> OrgParserState -> Bool
headlineContainsSelectTags Headline
hdln OrgParserState
st Bool -> Bool -> Bool
||
  (Headline -> Bool) -> [Headline] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Headline -> OrgParserState -> Bool
`docContainsSelectTags` OrgParserState
st) (Headline -> [Headline]
headlineChildren Headline
hdln)

includeAncestorsAndSelected :: Headline -> OrgParserState -> Maybe Headline
includeAncestorsAndSelected :: Headline -> OrgParserState -> Maybe Headline
includeAncestorsAndSelected Headline
hdln OrgParserState
st =
  if Headline -> OrgParserState -> Bool
headlineContainsSelectTags Headline
hdln OrgParserState
st
    then Headline -> Maybe Headline
forall a. a -> Maybe a
Just Headline
hdln
    else let children :: [Headline]
children = (Headline -> Maybe Headline) -> [Headline] -> [Headline]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Headline -> OrgParserState -> Maybe Headline
`includeAncestorsAndSelected` OrgParserState
st)
                                 (Headline -> [Headline]
headlineChildren Headline
hdln)
         in case [Headline]
children of
              [] -> Maybe Headline
forall a. Maybe a
Nothing
              [Headline]
_ -> Headline -> Maybe Headline
forall a. a -> Maybe a
Just (Headline -> Maybe Headline) -> Headline -> Maybe Headline
forall a b. (a -> b) -> a -> b
$ Headline
hdln { headlineChildren :: [Headline]
headlineChildren = [Headline]
children }

headlineContainsSelectTags :: Headline -> OrgParserState -> Bool
headlineContainsSelectTags :: Headline -> OrgParserState -> Bool
headlineContainsSelectTags Headline
hdln OrgParserState
st =
  (Tag -> Bool) -> [Tag] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Tag -> Set Tag -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` OrgParserState -> Set Tag
orgStateSelectTags OrgParserState
st) (Headline -> [Tag]
headlineTags Headline
hdln)

headlineContainsExcludeTags :: Headline -> OrgParserState -> Bool
headlineContainsExcludeTags :: Headline -> OrgParserState -> Bool
headlineContainsExcludeTags Headline
hdln OrgParserState
st =
  (Tag -> Bool) -> [Tag] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Tag -> Set Tag -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` OrgParserState -> Set Tag
orgStateExcludeTags OrgParserState
st) (Headline -> [Tag]
headlineTags Headline
hdln)

isArchiveTag :: Tag -> Bool
isArchiveTag :: Tag -> Bool
isArchiveTag = (Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Tag
toTag Text
"ARCHIVE")

-- | Check if the title starts with COMMENT.
-- FIXME: This accesses builder internals not intended for use in situations
-- like these.  Replace once keyword parsing is supported.
isCommentTitle :: Inlines -> Bool
isCommentTitle :: Inlines -> Bool
isCommentTitle Inlines
inlns = case Inlines -> [Inline]
forall a. Many a -> [a]
B.toList Inlines
inlns of
  (Str Text
"COMMENT":[Inline]
_) -> Bool
True
  [Inline]
_ -> Bool
False

archivedHeadlineToBlocks :: Monad m => Headline -> OrgParser m Blocks
archivedHeadlineToBlocks :: Headline -> OrgParser m Blocks
archivedHeadlineToBlocks Headline
hdln = do
  ArchivedTreesOption
archivedTreesOption <- (ExportSettings -> ArchivedTreesOption)
-> OrgParser m ArchivedTreesOption
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> ArchivedTreesOption
exportArchivedTrees
  case ArchivedTreesOption
archivedTreesOption of
    ArchivedTreesOption
ArchivedTreesNoExport     -> Blocks -> OrgParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
    ArchivedTreesOption
ArchivedTreesExport       -> Headline -> OrgParser m Blocks
forall (m :: * -> *). Monad m => Headline -> OrgParser m Blocks
headlineToHeaderWithContents Headline
hdln
    ArchivedTreesOption
ArchivedTreesHeadlineOnly -> Headline -> OrgParser m Blocks
forall (m :: * -> *). Monad m => Headline -> OrgParser m Blocks
headlineToHeader Headline
hdln

headlineToHeaderWithList :: Monad m => Headline -> OrgParser m Blocks
headlineToHeaderWithList :: Headline -> OrgParser m Blocks
headlineToHeaderWithList Headline
hdln = do
  Int
maxHeadlineLevels <- (ExportSettings -> Int) -> OrgParser m Int
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Int
exportHeadlineLevels
  Blocks
header        <- Headline -> OrgParser m Blocks
forall (m :: * -> *). Monad m => Headline -> OrgParser m Blocks
headlineToHeader Headline
hdln
  [Blocks]
listElements  <- (Headline -> OrgParser m Blocks)
-> [Headline]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Headline -> OrgParser m Blocks
forall (m :: * -> *). Monad m => Headline -> OrgParser m Blocks
headlineToBlocks (Headline -> [Headline]
headlineChildren Headline
hdln)
  Blocks
planningBlock <- PlanningInfo -> OrgParser m Blocks
forall (m :: * -> *). Monad m => PlanningInfo -> OrgParser m Blocks
planningToBlock (Headline -> PlanningInfo
headlinePlanning Headline
hdln)
  let listBlock :: Blocks
listBlock  = if [Blocks] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Blocks]
listElements
                   then Blocks
forall a. Monoid a => a
mempty
                   else [Blocks] -> Blocks
B.orderedList [Blocks]
listElements
  let headerText :: Blocks
headerText = if Int
maxHeadlineLevels Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Headline -> Int
headlineLevel Headline
hdln
                   then Blocks
header
                   else Blocks -> Blocks
flattenHeader Blocks
header
  Blocks -> OrgParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> OrgParser m Blocks)
-> ([Blocks] -> Blocks) -> [Blocks] -> OrgParser m Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> OrgParser m Blocks) -> [Blocks] -> OrgParser m Blocks
forall a b. (a -> b) -> a -> b
$
    [ Blocks
headerText
    , Blocks
planningBlock
    , Headline -> Blocks
headlineContents Headline
hdln
    , Blocks
listBlock
    ]
 where
   flattenHeader :: Blocks -> Blocks
   flattenHeader :: Blocks -> Blocks
flattenHeader Blocks
blks =
     case Blocks -> [Block]
forall a. Many a -> [a]
B.toList Blocks
blks of
       (Header Int
_ Attr
_ [Inline]
inlns:[Block]
_) -> Inlines -> Blocks
B.para ([Inline] -> Inlines
forall a. [a] -> Many a
B.fromList [Inline]
inlns)
       [Block]
_                    -> Blocks
forall a. Monoid a => a
mempty

headlineToHeaderWithContents :: Monad m => Headline -> OrgParser m Blocks
headlineToHeaderWithContents :: Headline -> OrgParser m Blocks
headlineToHeaderWithContents Headline
hdln = do
  Blocks
header         <- Headline -> OrgParser m Blocks
forall (m :: * -> *). Monad m => Headline -> OrgParser m Blocks
headlineToHeader Headline
hdln
  Blocks
planningBlock <- PlanningInfo -> OrgParser m Blocks
forall (m :: * -> *). Monad m => PlanningInfo -> OrgParser m Blocks
planningToBlock (Headline -> PlanningInfo
headlinePlanning Headline
hdln)
  Blocks
childrenBlocks <- [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Blocks)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Blocks]
-> OrgParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Headline -> OrgParser m Blocks)
-> [Headline]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Headline -> OrgParser m Blocks
forall (m :: * -> *). Monad m => Headline -> OrgParser m Blocks
headlineToBlocks (Headline -> [Headline]
headlineChildren Headline
hdln)
  Blocks -> OrgParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> OrgParser m Blocks) -> Blocks -> OrgParser m Blocks
forall a b. (a -> b) -> a -> b
$ Blocks
header Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Blocks
planningBlock Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Headline -> Blocks
headlineContents Headline
hdln Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Blocks
childrenBlocks

headlineToHeader :: Monad m => Headline -> OrgParser m Blocks
headlineToHeader :: Headline -> OrgParser m Blocks
headlineToHeader Headline
hdln = do
  Bool
exportTodoKeyword <- (ExportSettings -> Bool) -> OrgParser m Bool
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportWithTodoKeywords
  Bool
exportTags        <- (ExportSettings -> Bool) -> OrgParser m Bool
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportWithTags
  let todoText :: Inlines
todoText    = if Bool
exportTodoKeyword
                    then case Headline -> Maybe TodoMarker
headlineTodoMarker Headline
hdln of
                      Just TodoMarker
kw -> TodoMarker -> Inlines
todoKeywordToInlines TodoMarker
kw Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space
                      Maybe TodoMarker
Nothing -> Inlines
forall a. Monoid a => a
mempty
                    else Inlines
forall a. Monoid a => a
mempty
  let text :: Inlines
text        = Inlines
todoText Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Headline -> Inlines
headlineText Headline
hdln Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>
                    if Bool
exportTags
                    then [Tag] -> Inlines
tagsToInlines (Headline -> [Tag]
headlineTags Headline
hdln)
                    else Inlines
forall a. Monoid a => a
mempty
  let propAttr :: Attr
propAttr    = Properties -> Attr
propertiesToAttr (Headline -> Properties
headlineProperties Headline
hdln)
  Attr
attr           <- Attr
-> Inlines
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Attr
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st, HasLogMessages st,
 HasIdentifierList st) =>
Attr -> Inlines -> ParserT s st m Attr
registerHeader Attr
propAttr (Headline -> Inlines
headlineText Headline
hdln)
  Blocks -> OrgParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> OrgParser m Blocks) -> Blocks -> OrgParser m Blocks
forall a b. (a -> b) -> a -> b
$ Attr -> Int -> Inlines -> Blocks
B.headerWith Attr
attr (Headline -> Int
headlineLevel Headline
hdln) Inlines
text

todoKeyword :: Monad m => OrgParser m TodoMarker
todoKeyword :: OrgParser m TodoMarker
todoKeyword = OrgParser m TodoMarker -> OrgParser m TodoMarker
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m TodoMarker -> OrgParser m TodoMarker)
-> OrgParser m TodoMarker -> OrgParser m TodoMarker
forall a b. (a -> b) -> a -> b
$ do
  TodoSequence
taskStates <- OrgParserState -> TodoSequence
activeTodoMarkers (OrgParserState -> TodoSequence)
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) TodoSequence
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let kwParser :: TodoMarker
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) TodoMarker
kwParser TodoMarker
tdm = ParsecT Text OrgParserState (ReaderT OrgParserLocal m) TodoMarker
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) TodoMarker
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TodoMarker
tdm TodoMarker
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) TodoMarker
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr (TodoMarker -> Text
todoMarkerName TodoMarker
tdm)
                              ParsecT Text OrgParserState (ReaderT OrgParserLocal m) TodoMarker
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) TodoMarker
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
spaceChar
                              ParsecT Text OrgParserState (ReaderT OrgParserLocal m) TodoMarker
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) TodoMarker
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos)
  [OrgParser m TodoMarker] -> OrgParser m TodoMarker
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ((TodoMarker -> OrgParser m TodoMarker)
-> TodoSequence -> [OrgParser m TodoMarker]
forall a b. (a -> b) -> [a] -> [b]
map TodoMarker -> OrgParser m TodoMarker
forall (m :: * -> *).
Monad m =>
TodoMarker
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) TodoMarker
kwParser TodoSequence
taskStates)

todoKeywordToInlines :: TodoMarker -> Inlines
todoKeywordToInlines :: TodoMarker -> Inlines
todoKeywordToInlines TodoMarker
tdm =
  let todoText :: Text
todoText  = TodoMarker -> Text
todoMarkerName TodoMarker
tdm
      todoState :: Text
todoState = Text -> Text
T.toLower (Text -> Text) -> (TodoState -> Text) -> TodoState -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text) -> (TodoState -> String) -> TodoState -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TodoState -> String
forall a. Show a => a -> String
show (TodoState -> Text) -> TodoState -> Text
forall a b. (a -> b) -> a -> b
$ TodoMarker -> TodoState
todoMarkerState TodoMarker
tdm
      classes :: [Text]
classes = [Text
todoState, Text
todoText]
  in Attr -> Inlines -> Inlines
B.spanWith (Text
forall a. Monoid a => a
mempty, [Text]
classes, [(Text, Text)]
forall a. Monoid a => a
mempty) (Text -> Inlines
B.str Text
todoText)

propertiesToAttr :: Properties -> Attr
propertiesToAttr :: Properties -> Attr
propertiesToAttr Properties
properties =
  let
    toTextPair :: (PropertyKey, PropertyValue) -> (Text, Text)
toTextPair = PropertyKey -> Text
fromKey (PropertyKey -> Text)
-> (PropertyValue -> Text)
-> (PropertyKey, PropertyValue)
-> (Text, Text)
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** PropertyValue -> Text
fromValue
    customIdKey :: PropertyKey
customIdKey = Text -> PropertyKey
toPropertyKey Text
"custom_id"
    classKey :: PropertyKey
classKey    = Text -> PropertyKey
toPropertyKey Text
"class"
    unnumberedKey :: PropertyKey
unnumberedKey = Text -> PropertyKey
toPropertyKey Text
"unnumbered"
    specialProperties :: [PropertyKey]
specialProperties = [PropertyKey
customIdKey, PropertyKey
classKey, PropertyKey
unnumberedKey]
    id' :: Text
id'  = Text -> (PropertyValue -> Text) -> Maybe PropertyValue -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
forall a. Monoid a => a
mempty PropertyValue -> Text
fromValue (Maybe PropertyValue -> Text)
-> (Properties -> Maybe PropertyValue) -> Properties -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PropertyKey -> Properties -> Maybe PropertyValue
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup PropertyKey
customIdKey (Properties -> Text) -> Properties -> Text
forall a b. (a -> b) -> a -> b
$ Properties
properties
    cls :: Text
cls  = Text -> (PropertyValue -> Text) -> Maybe PropertyValue -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
forall a. Monoid a => a
mempty PropertyValue -> Text
fromValue (Maybe PropertyValue -> Text)
-> (Properties -> Maybe PropertyValue) -> Properties -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PropertyKey -> Properties -> Maybe PropertyValue
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup PropertyKey
classKey    (Properties -> Text) -> Properties -> Text
forall a b. (a -> b) -> a -> b
$ Properties
properties
    kvs' :: [(Text, Text)]
kvs' = ((PropertyKey, PropertyValue) -> (Text, Text))
-> Properties -> [(Text, Text)]
forall a b. (a -> b) -> [a] -> [b]
map (PropertyKey, PropertyValue) -> (Text, Text)
toTextPair (Properties -> [(Text, Text)])
-> (Properties -> Properties) -> Properties -> [(Text, Text)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PropertyKey, PropertyValue) -> Bool) -> Properties -> Properties
forall a. (a -> Bool) -> [a] -> [a]
filter ((PropertyKey -> [PropertyKey] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [PropertyKey]
specialProperties) (PropertyKey -> Bool)
-> ((PropertyKey, PropertyValue) -> PropertyKey)
-> (PropertyKey, PropertyValue)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PropertyKey, PropertyValue) -> PropertyKey
forall a b. (a, b) -> a
fst)
           (Properties -> [(Text, Text)]) -> Properties -> [(Text, Text)]
forall a b. (a -> b) -> a -> b
$ Properties
properties
    isUnnumbered :: Bool
isUnnumbered =
      Bool -> (PropertyValue -> Bool) -> Maybe PropertyValue -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False PropertyValue -> Bool
isNonNil (Maybe PropertyValue -> Bool)
-> (Properties -> Maybe PropertyValue) -> Properties -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PropertyKey -> Properties -> Maybe PropertyValue
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup PropertyKey
unnumberedKey (Properties -> Bool) -> Properties -> Bool
forall a b. (a -> b) -> a -> b
$ Properties
properties
  in
    (Text
id', Text -> [Text]
T.words Text
cls [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [Text
"unnumbered" | Bool
isUnnumbered], [(Text, Text)]
kvs')

tagsToInlines :: [Tag] -> Inlines
tagsToInlines :: [Tag] -> Inlines
tagsToInlines [] = Inlines
forall a. Monoid a => a
mempty
tagsToInlines [Tag]
tags =
  (Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>) (Inlines -> Inlines) -> ([Tag] -> Inlines) -> [Tag] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines) -> ([Tag] -> [Inlines]) -> [Tag] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse (Text -> Inlines
B.str Text
"\160") ([Inlines] -> [Inlines])
-> ([Tag] -> [Inlines]) -> [Tag] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tag -> Inlines) -> [Tag] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map Tag -> Inlines
tagToInline ([Tag] -> Inlines) -> [Tag] -> Inlines
forall a b. (a -> b) -> a -> b
$ [Tag]
tags
 where
  tagToInline :: Tag -> Inlines
  tagToInline :: Tag -> Inlines
tagToInline Tag
t = Tag -> Inlines -> Inlines
tagSpan Tag
t (Inlines -> Inlines) -> (Text -> Inlines) -> Text -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.smallcaps (Inlines -> Inlines) -> (Text -> Inlines) -> Text -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Tag -> Text
fromTag Tag
t

-- | Wrap the given inline in a span, marking it as a tag.
tagSpan :: Tag -> Inlines -> Inlines
tagSpan :: Tag -> Inlines -> Inlines
tagSpan Tag
t = Attr -> Inlines -> Inlines
B.spanWith (Text
"", [Text
"tag"], [(Text
"tag-name", Tag -> Text
fromTag Tag
t)])

-- | Render planning info as a block iff the respective export setting is
-- enabled.
planningToBlock :: Monad m => PlanningInfo -> OrgParser m Blocks
planningToBlock :: PlanningInfo -> OrgParser m Blocks
planningToBlock PlanningInfo
planning = do
  Bool
includePlanning <- (ExportSettings -> Bool) -> OrgParser m Bool
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportWithPlanning
  Blocks -> OrgParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> OrgParser m Blocks) -> Blocks -> OrgParser m Blocks
forall a b. (a -> b) -> a -> b
$
    if Bool
includePlanning
    then Inlines -> Blocks
B.plain (Inlines -> Blocks)
-> ([Inlines] -> Inlines) -> [Inlines] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ([Inlines] -> [Inlines]) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse Inlines
B.space ([Inlines] -> [Inlines])
-> ([Inlines] -> [Inlines]) -> [Inlines] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inlines -> Bool) -> [Inlines] -> [Inlines]
forall a. (a -> Bool) -> [a] -> [a]
filter (Inlines -> Inlines -> Bool
forall a. Eq a => a -> a -> Bool
/= Inlines
forall a. Monoid a => a
mempty) ([Inlines] -> Blocks) -> [Inlines] -> Blocks
forall a b. (a -> b) -> a -> b
$
         [ (PlanningInfo -> Maybe Text) -> Text -> Inlines
datumInlines PlanningInfo -> Maybe Text
planningClosed Text
"CLOSED"
         , (PlanningInfo -> Maybe Text) -> Text -> Inlines
datumInlines PlanningInfo -> Maybe Text
planningDeadline Text
"DEADLINE"
         , (PlanningInfo -> Maybe Text) -> Text -> Inlines
datumInlines PlanningInfo -> Maybe Text
planningScheduled Text
"SCHEDULED"
         ]
    else Blocks
forall a. Monoid a => a
mempty
 where
  datumInlines :: (PlanningInfo -> Maybe Text) -> Text -> Inlines
datumInlines PlanningInfo -> Maybe Text
field Text
name =
    case PlanningInfo -> Maybe Text
field PlanningInfo
planning of
      Maybe Text
Nothing -> Inlines
forall a. Monoid a => a
mempty
      Just Text
time ->   Inlines -> Inlines
B.strong (Text -> Inlines
B.str Text
name Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
B.str Text
":")
                  Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space
                  Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
B.emph (Text -> Inlines
B.str Text
time)

-- | An Org timestamp, including repetition marks. TODO: improve
type Timestamp = Text

timestamp :: Monad m => OrgParser m Timestamp
timestamp :: OrgParser m Text
timestamp = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$ do
  Char
openChar <- String
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
"<["
  let isActive :: Bool
isActive = Char
openChar Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'<'
  let closeChar :: Char
closeChar = if Bool
isActive then Char
'>' else Char
']'
  Text
content <- ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m Text
forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParserT s st m Char -> ParserT s st m end -> ParserT s st m Text
many1TillChar ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
anyChar (Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
closeChar)
  Text -> OrgParser m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> OrgParser m Text) -> Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$ Char -> Text -> Text
T.cons Char
openChar (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text
content Text -> Char -> Text
`T.snoc` Char
closeChar

-- | Planning information for a subtree/headline.
data PlanningInfo = PlanningInfo
  { PlanningInfo -> Maybe Text
planningClosed :: Maybe Timestamp
  , PlanningInfo -> Maybe Text
planningDeadline :: Maybe Timestamp
  , PlanningInfo -> Maybe Text
planningScheduled :: Maybe Timestamp
  }

emptyPlanning :: PlanningInfo
emptyPlanning :: PlanningInfo
emptyPlanning = Maybe Text -> Maybe Text -> Maybe Text -> PlanningInfo
PlanningInfo Maybe Text
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing

-- | Read a single planning-related and timestamped line.
planningInfo :: Monad m => OrgParser m PlanningInfo
planningInfo :: OrgParser m PlanningInfo
planningInfo = OrgParser m PlanningInfo -> OrgParser m PlanningInfo
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m PlanningInfo -> OrgParser m PlanningInfo)
-> OrgParser m PlanningInfo -> OrgParser m PlanningInfo
forall a b. (a -> b) -> a -> b
$ do
  [PlanningInfo -> PlanningInfo]
updaters <- ParsecT
  Text
  OrgParserState
  (ReaderT OrgParserLocal m)
  (PlanningInfo -> PlanningInfo)
-> ParsecT
     Text
     OrgParserState
     (ReaderT OrgParserLocal m)
     [PlanningInfo -> PlanningInfo]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT
  Text
  OrgParserState
  (ReaderT OrgParserLocal m)
  (PlanningInfo -> PlanningInfo)
planningDatum ParsecT
  Text
  OrgParserState
  (ReaderT OrgParserLocal m)
  [PlanningInfo -> PlanningInfo]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT
     Text
     OrgParserState
     (ReaderT OrgParserLocal m)
     [PlanningInfo -> PlanningInfo]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParsecT
  Text
  OrgParserState
  (ReaderT OrgParserLocal m)
  [PlanningInfo -> PlanningInfo]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT
     Text
     OrgParserState
     (ReaderT OrgParserLocal m)
     [PlanningInfo -> PlanningInfo]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *). Monad m => OrgParser m Char
newline
  PlanningInfo -> OrgParser m PlanningInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (PlanningInfo -> OrgParser m PlanningInfo)
-> PlanningInfo -> OrgParser m PlanningInfo
forall a b. (a -> b) -> a -> b
$ ((PlanningInfo -> PlanningInfo) -> PlanningInfo -> PlanningInfo)
-> PlanningInfo -> [PlanningInfo -> PlanningInfo] -> PlanningInfo
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (PlanningInfo -> PlanningInfo) -> PlanningInfo -> PlanningInfo
forall a b. (a -> b) -> a -> b
($) PlanningInfo
emptyPlanning [PlanningInfo -> PlanningInfo]
updaters
 where
  planningDatum :: ParsecT
  Text
  OrgParserState
  (ReaderT OrgParserLocal m)
  (PlanningInfo -> PlanningInfo)
planningDatum = ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT
     Text
     OrgParserState
     (ReaderT OrgParserLocal m)
     (PlanningInfo -> PlanningInfo)
-> ParsecT
     Text
     OrgParserState
     (ReaderT OrgParserLocal m)
     (PlanningInfo -> PlanningInfo)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [ParsecT
   Text
   OrgParserState
   (ReaderT OrgParserLocal m)
   (PlanningInfo -> PlanningInfo)]
-> ParsecT
     Text
     OrgParserState
     (ReaderT OrgParserLocal m)
     (PlanningInfo -> PlanningInfo)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
    [ (Text -> PlanningInfo -> PlanningInfo)
-> String
-> ParsecT
     Text
     OrgParserState
     (ReaderT OrgParserLocal m)
     (PlanningInfo -> PlanningInfo)
forall (m :: * -> *) b.
Monad m =>
(Text -> b)
-> String
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) b
updateWith (\Text
s PlanningInfo
p -> PlanningInfo
p { planningScheduled :: Maybe Text
planningScheduled = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
s}) String
"SCHEDULED"
    , (Text -> PlanningInfo -> PlanningInfo)
-> String
-> ParsecT
     Text
     OrgParserState
     (ReaderT OrgParserLocal m)
     (PlanningInfo -> PlanningInfo)
forall (m :: * -> *) b.
Monad m =>
(Text -> b)
-> String
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) b
updateWith (\Text
d PlanningInfo
p -> PlanningInfo
p { planningDeadline :: Maybe Text
planningDeadline = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
d}) String
"DEADLINE"
    , (Text -> PlanningInfo -> PlanningInfo)
-> String
-> ParsecT
     Text
     OrgParserState
     (ReaderT OrgParserLocal m)
     (PlanningInfo -> PlanningInfo)
forall (m :: * -> *) b.
Monad m =>
(Text -> b)
-> String
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) b
updateWith (\Text
c PlanningInfo
p -> PlanningInfo
p { planningClosed :: Maybe Text
planningClosed = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
c}) String
"CLOSED"
    ]
  updateWith :: (Text -> b)
-> String
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) b
updateWith Text -> b
fn String
cs = Text -> b
fn (Text -> b)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
cs ParsecT Text OrgParserState (ReaderT OrgParserLocal m) String
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
':' ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *). Monad m => OrgParser m Text
timestamp)

-- | Read a :PROPERTIES: drawer and return the key/value pairs contained
-- within.
propertiesDrawer :: Monad m => OrgParser m Properties
propertiesDrawer :: OrgParser m Properties
propertiesDrawer = OrgParser m Properties -> OrgParser m Properties
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Properties -> OrgParser m Properties)
-> OrgParser m Properties -> OrgParser m Properties
forall a b. (a -> b) -> a -> b
$ do
  Text
drawerType <- OrgParser m Text
forall (m :: * -> *). Monad m => OrgParser m Text
drawerStart
  Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ Text -> Text
T.toUpper Text
drawerType Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"PROPERTIES"
  ParsecT
  Text
  OrgParserState
  (ReaderT OrgParserLocal m)
  (PropertyKey, PropertyValue)
-> OrgParser m Text -> OrgParser m Properties
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT
  Text
  OrgParserState
  (ReaderT OrgParserLocal m)
  (PropertyKey, PropertyValue)
forall (m :: * -> *).
Monad m =>
OrgParser m (PropertyKey, PropertyValue)
property (OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try OrgParser m Text
forall (m :: * -> *). Monad m => OrgParser m Text
endOfDrawer)
 where
   property :: Monad m => OrgParser m (PropertyKey, PropertyValue)
   property :: OrgParser m (PropertyKey, PropertyValue)
property = OrgParser m (PropertyKey, PropertyValue)
-> OrgParser m (PropertyKey, PropertyValue)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (PropertyKey, PropertyValue)
 -> OrgParser m (PropertyKey, PropertyValue))
-> OrgParser m (PropertyKey, PropertyValue)
-> OrgParser m (PropertyKey, PropertyValue)
forall a b. (a -> b) -> a -> b
$ (,) (PropertyKey -> PropertyValue -> (PropertyKey, PropertyValue))
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) PropertyKey
-> ParsecT
     Text
     OrgParserState
     (ReaderT OrgParserLocal m)
     (PropertyValue -> (PropertyKey, PropertyValue))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) PropertyKey
forall (m :: * -> *). Monad m => OrgParser m PropertyKey
key ParsecT
  Text
  OrgParserState
  (ReaderT OrgParserLocal m)
  (PropertyValue -> (PropertyKey, PropertyValue))
-> ParsecT
     Text OrgParserState (ReaderT OrgParserLocal m) PropertyValue
-> OrgParser m (PropertyKey, PropertyValue)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  Text OrgParserState (ReaderT OrgParserLocal m) PropertyValue
forall (m :: * -> *). Monad m => OrgParser m PropertyValue
value

   key :: Monad m => OrgParser m PropertyKey
   key :: OrgParser m PropertyKey
key = (Text -> PropertyKey)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m PropertyKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> PropertyKey
toPropertyKey (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
 -> OrgParser m PropertyKey)
-> (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m PropertyKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
 -> OrgParser m PropertyKey)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m PropertyKey
forall a b. (a -> b) -> a -> b
$
         ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
':' ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParserT s st m Char -> ParserT s st m end -> ParserT s st m Text
many1TillChar ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
nonspaceChar (Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
':')

   value :: Monad m => OrgParser m PropertyValue
   value :: OrgParser m PropertyValue
value = (Text -> PropertyValue)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m PropertyValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> PropertyValue
toPropertyValue (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
 -> OrgParser m PropertyValue)
-> (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
    -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m PropertyValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
 -> OrgParser m PropertyValue)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m PropertyValue
forall a b. (a -> b) -> a -> b
$
           ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
anyChar (ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
 -> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char)
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall a b. (a -> b) -> a -> b
$ ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *). Monad m => OrgParser m Char
newline)

   endOfDrawer :: Monad m => OrgParser m Text
   endOfDrawer :: OrgParser m Text
endOfDrawer = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$
     ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m Text -> OrgParser m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Text -> OrgParser m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
stringAnyCase Text
":END:" OrgParser m Text
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces OrgParser m Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *). Monad m => OrgParser m Char
newline