{-# LANGUAGE FlexibleContexts  #-}
{-# LANGUAGE LambdaCase        #-}
{-# LANGUAGE OverloadedStrings #-}
{- |
   Module      : Text.Pandoc.Readers.Org.Meta
   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 meta declarations.
-}
module Text.Pandoc.Readers.Org.Meta
  ( metaExport
  , metaKey
  , metaLine
  ) where

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

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

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

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

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

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

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

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

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

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

parseThen :: PandocMonad m
          => OrgParser m (F a)
          -> (a -> Meta -> Meta)
          -> OrgParser m ()
parseThen :: forall (m :: * -> *) a.
PandocMonad m =>
OrgParser m (F a) -> (a -> Meta -> Meta) -> OrgParser m ()
parseThen OrgParser m (F a)
p a -> Meta -> Meta
modMeta = do
  F a
value <- OrgParser m (F a)
p
  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 (\OrgParserState
st -> OrgParserState
st { orgStateMeta :: F Meta
orgStateMeta = a -> Meta -> Meta
modMeta forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F a
value forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> F Meta
meta })

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

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

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

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

-- | Read an format specific meta definition
metaExportSnippet :: Monad m => Text -> OrgParser m (F Inlines)
metaExportSnippet :: forall (m :: * -> *). Monad m => Text -> OrgParser m (F Inlines)
metaExportSnippet Text
format = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Inlines
B.rawInline Text
format forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). Monad m => OrgParser m Text
anyLine

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

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

   rest :: ParsecT Sources st (ReaderT OrgParserLocal m) Text
rest            = 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 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 (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
"\n\r")
   tillSpecifier :: Char -> ParsecT s st m Text
tillSpecifier Char
c = 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) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r") (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]
string (Char
'%'forall a. a -> [a] -> [a]
:Char
cforall a. a -> [a] -> [a]
:[Char]
""))

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

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

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

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

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

-- | Parses emphasis border character like @".,?!"@
emphChars :: Monad m => OrgParser m (Maybe [Char])
emphChars :: forall (m :: * -> *). Monad m => OrgParser m (Maybe [Char])
emphChars = do
  forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
  forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). Monad m => OrgParser m Text
anyLine

lineOfInlines :: PandocMonad m => OrgParser m (F Inlines)
lineOfInlines :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
lineOfInlines = do
  forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
  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
newline

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

 where
   todoKeyword :: Monad m => OrgParser m Text
   todoKeyword :: forall (m :: * -> *). Monad m => OrgParser m Text
todoKeyword = 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 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

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

   doneKeywords :: Monad m => OrgParser m [Text]
   doneKeywords :: forall (m :: * -> *). Monad m => OrgParser m [Text]
doneKeywords = 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 Text
todoKeyword 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 ()
optional forall (m :: * -> *). Monad m => OrgParser m ()
todoDoneSep) (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)

   todoDoneSep :: Monad m => OrgParser m ()
   todoDoneSep :: forall (m :: * -> *). Monad m => OrgParser m ()
todoDoneSep = 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 :: * -> *) 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 a
<* forall (m :: * -> *). Monad m => OrgParser m ()
skipSpaces1

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

macroDefinition :: Monad m => OrgParser m (Text, [Text] -> Text)
macroDefinition :: forall (m :: * -> *). Monad m => OrgParser m (Text, [Text] -> Text)
macroDefinition = 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
macroName <- 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 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
  Text
firstPart <- forall (m :: * -> *). Monad m => OrgParser m Text
expansionPart
  ([Int]
elemOrder, [Text]
parts) <- forall a b. [(a, b)] -> ([a], [b])
unzip 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 (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). Monad m => OrgParser m Int
placeholder forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (m :: * -> *). Monad m => OrgParser m Text
expansionPart)
  let expander :: [Text] -> Text
expander = forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> [a] -> [a]
alternate (Text
firstPartforall a. a -> [a] -> [a]
:[Text]
parts) forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> [Text] -> [Text]
reorder [Int]
elemOrder
  forall (m :: * -> *) a. Monad m => a -> m a
return (Text
macroName, [Text] -> Text
expander)
 where
  placeholder :: Monad m => OrgParser m Int
  placeholder :: forall (m :: * -> *). Monad m => OrgParser m Int
placeholder = 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 b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. a -> Maybe a -> a
fromMaybe Int
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead) 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 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

  expansionPart :: Monad m => OrgParser m Text
  expansionPart :: forall (m :: * -> *). Monad m => OrgParser m Text
expansionPart = 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 st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar (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 Int
placeholder 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
noneOf [Char]
"\n\r")

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

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