{-# LANGUAGE FlexibleContexts  #-}
{-# LANGUAGE TupleSections     #-}
{-# LANGUAGE OverloadedStrings #-}
{- |
   Module      : Text.Pandoc.Readers.Muse
   Copyright   : Copyright (C) 2017-2020 Alexander Krotov
   License     : GNU GPL, version 2 or above

   Maintainer  : Alexander Krotov <ilabdsf@gmail.com>
   Stability   : alpha
   Portability : portable

Conversion of Muse text to 'Pandoc' document.
-}
{-
TODO:
- <cite> tag
-}
module Text.Pandoc.Readers.Muse (readMuse) where

import Control.Monad
import Control.Monad.Reader
import Control.Monad.Except (throwError)
import Data.Bifunctor
import Data.Default
import Data.List (transpose, uncons)
import qualified Data.Map as M
import qualified Data.Set as Set
import Data.Maybe (fromMaybe, isNothing, maybeToList)
import Data.Text (Text)
import qualified Data.Text as T
import Text.Pandoc.Builder (Blocks, Inlines, underline)
import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
import Text.Pandoc.Definition
import Text.Pandoc.Error (PandocError (PandocParsecError))
import Text.Pandoc.Logging
import Text.Pandoc.Options
import Text.Pandoc.Parsing hiding (F)
import Text.Pandoc.Shared (crFilter, trimr, tshow)

-- | Read Muse from an input string and return a Pandoc document.
readMuse :: PandocMonad m
         => ReaderOptions
         -> Text
         -> m Pandoc
readMuse :: ReaderOptions -> Text -> m Pandoc
readMuse ReaderOptions
opts Text
s = do
  let input :: Text
input = Text -> Text
crFilter Text
s
  Either ParseError Pandoc
res <- (ReaderT MuseEnv m (Either ParseError Pandoc)
 -> MuseEnv -> m (Either ParseError Pandoc))
-> MuseEnv
-> ReaderT MuseEnv m (Either ParseError Pandoc)
-> m (Either ParseError Pandoc)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT MuseEnv m (Either ParseError Pandoc)
-> MuseEnv -> m (Either ParseError Pandoc)
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT MuseEnv
forall a. Default a => a
def (ReaderT MuseEnv m (Either ParseError Pandoc)
 -> m (Either ParseError Pandoc))
-> ReaderT MuseEnv m (Either ParseError Pandoc)
-> m (Either ParseError Pandoc)
forall a b. (a -> b) -> a -> b
$ ParsecT Text MuseState (ReaderT MuseEnv m) Pandoc
-> MuseState
-> SourceName
-> Text
-> ReaderT MuseEnv m (Either ParseError Pandoc)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)
runParserT ParsecT Text MuseState (ReaderT MuseEnv m) Pandoc
forall (m :: * -> *). PandocMonad m => MuseParser m Pandoc
parseMuse MuseState
forall a. Default a => a
def{ museOptions :: ReaderOptions
museOptions = ReaderOptions
opts } SourceName
"source" Text
input
  case Either ParseError Pandoc
res of
       Left ParseError
e  -> PandocError -> m Pandoc
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (PandocError -> m Pandoc) -> PandocError -> m Pandoc
forall a b. (a -> b) -> a -> b
$ Text -> ParseError -> PandocError
PandocParsecError Text
input ParseError
e
       Right Pandoc
d -> Pandoc -> m Pandoc
forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
d

type F = Future MuseState

data MuseState = MuseState { MuseState -> F Meta
museMeta :: F Meta -- ^ Document metadata
                           , MuseState -> ReaderOptions
museOptions :: ReaderOptions
                           , MuseState -> Set Text
museIdentifierList :: Set.Set Text
                           , MuseState -> Maybe SourcePos
museLastSpacePos :: Maybe SourcePos -- ^ Position after last space or newline parsed
                           , MuseState -> Maybe SourcePos
museLastStrPos :: Maybe SourcePos -- ^ Position after last str parsed
                           , MuseState -> [LogMessage]
museLogMessages :: [LogMessage]
                           , MuseState -> Map Text (SourcePos, F Blocks)
museNotes :: M.Map Text (SourcePos, F Blocks)
                           }

instance Default MuseState where
  def :: MuseState
def = MuseState :: F Meta
-> ReaderOptions
-> Set Text
-> Maybe SourcePos
-> Maybe SourcePos
-> [LogMessage]
-> Map Text (SourcePos, F Blocks)
-> MuseState
MuseState { museMeta :: F Meta
museMeta = Meta -> F Meta
forall (m :: * -> *) a. Monad m => a -> m a
return Meta
nullMeta
                  , museOptions :: ReaderOptions
museOptions = ReaderOptions
forall a. Default a => a
def
                  , museIdentifierList :: Set Text
museIdentifierList = Set Text
forall a. Set a
Set.empty
                  , museLastStrPos :: Maybe SourcePos
museLastStrPos = Maybe SourcePos
forall a. Maybe a
Nothing
                  , museLastSpacePos :: Maybe SourcePos
museLastSpacePos = Maybe SourcePos
forall a. Maybe a
Nothing
                  , museLogMessages :: [LogMessage]
museLogMessages = []
                  , museNotes :: Map Text (SourcePos, F Blocks)
museNotes = Map Text (SourcePos, F Blocks)
forall k a. Map k a
M.empty
                  }

data MuseEnv =
  MuseEnv { MuseEnv -> Bool
museInLink :: Bool -- ^ True when parsing a link description to avoid nested links
          , MuseEnv -> Bool
museInPara :: Bool -- ^ True when parsing paragraph is not allowed
          }

instance Default MuseEnv where
  def :: MuseEnv
def = MuseEnv :: Bool -> Bool -> MuseEnv
MuseEnv { museInLink :: Bool
museInLink = Bool
False
                , museInPara :: Bool
museInPara = Bool
False
                }

type MuseParser m = ParserT Text MuseState (ReaderT MuseEnv m)

instance HasReaderOptions MuseState where
  extractReaderOptions :: MuseState -> ReaderOptions
extractReaderOptions = MuseState -> ReaderOptions
museOptions

instance HasIdentifierList MuseState where
  extractIdentifierList :: MuseState -> Set Text
extractIdentifierList     = MuseState -> Set Text
museIdentifierList
  updateIdentifierList :: (Set Text -> Set Text) -> MuseState -> MuseState
updateIdentifierList Set Text -> Set Text
f MuseState
st = MuseState
st{ museIdentifierList :: Set Text
museIdentifierList = Set Text -> Set Text
f (Set Text -> Set Text) -> Set Text -> Set Text
forall a b. (a -> b) -> a -> b
$ MuseState -> Set Text
museIdentifierList MuseState
st }

instance HasLastStrPosition MuseState where
  setLastStrPos :: Maybe SourcePos -> MuseState -> MuseState
setLastStrPos Maybe SourcePos
pos MuseState
st = MuseState
st{ museLastStrPos :: Maybe SourcePos
museLastStrPos = Maybe SourcePos
pos }
  getLastStrPos :: MuseState -> Maybe SourcePos
getLastStrPos MuseState
st     = MuseState -> Maybe SourcePos
museLastStrPos MuseState
st

instance HasLogMessages MuseState where
  addLogMessage :: LogMessage -> MuseState -> MuseState
addLogMessage LogMessage
m MuseState
s = MuseState
s{ museLogMessages :: [LogMessage]
museLogMessages = LogMessage
m LogMessage -> [LogMessage] -> [LogMessage]
forall a. a -> [a] -> [a]
: MuseState -> [LogMessage]
museLogMessages MuseState
s }
  getLogMessages :: MuseState -> [LogMessage]
getLogMessages = [LogMessage] -> [LogMessage]
forall a. [a] -> [a]
reverse ([LogMessage] -> [LogMessage])
-> (MuseState -> [LogMessage]) -> MuseState -> [LogMessage]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MuseState -> [LogMessage]
museLogMessages

updateLastSpacePos :: Monad m => MuseParser m ()
updateLastSpacePos :: MuseParser m ()
updateLastSpacePos = ParsecT Text MuseState (ReaderT MuseEnv m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition ParsecT Text MuseState (ReaderT MuseEnv m) SourcePos
-> (SourcePos -> MuseParser m ()) -> MuseParser m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \SourcePos
pos ->
  (MuseState -> MuseState) -> MuseParser m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((MuseState -> MuseState) -> MuseParser m ())
-> (MuseState -> MuseState) -> MuseParser m ()
forall a b. (a -> b) -> a -> b
$ \MuseState
s -> MuseState
s { museLastSpacePos :: Maybe SourcePos
museLastSpacePos = SourcePos -> Maybe SourcePos
forall a. a -> Maybe a
Just SourcePos
pos }

-- | Parse Muse document
parseMuse :: PandocMonad m => MuseParser m Pandoc
parseMuse :: MuseParser m Pandoc
parseMuse = do
  ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) [()]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => MuseParser m ()
directive
  [F Blocks]
blocks <- (:) (F Blocks -> [F Blocks] -> [F Blocks])
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F Blocks] -> [F Blocks])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
parseBlocks ParsecT
  Text MuseState (ReaderT MuseEnv m) ([F Blocks] -> [F Blocks])
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
parseSection
  ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
  MuseState
st <- ParsecT Text MuseState (ReaderT MuseEnv m) MuseState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Future MuseState Pandoc -> MuseState -> Pandoc
forall s a. Future s a -> s -> a
runF (Meta -> [Block] -> Pandoc
Pandoc (Meta -> [Block] -> Pandoc)
-> F Meta -> Future MuseState ([Block] -> Pandoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseState -> F Meta
museMeta MuseState
st Future MuseState ([Block] -> Pandoc)
-> Future MuseState [Block] -> Future MuseState Pandoc
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Blocks -> [Block]) -> F Blocks -> Future MuseState [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Blocks -> [Block]
forall a. Many a -> [a]
B.toList ([F Blocks] -> F Blocks
forall a. Monoid a => [a] -> a
mconcat [F Blocks]
blocks)) MuseState
st Pandoc
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m Pandoc
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *) st s.
(PandocMonad m, HasLogMessages st) =>
ParserT s st m ()
reportLogMessages

-- * Utility functions

-- | Trim up to one newline from the beginning of the string.
lchop :: Text -> Text
lchop :: Text -> Text
lchop Text
s = case Text -> Maybe (Char, Text)
T.uncons Text
s of
  Just (Char
'\n', Text
xs) -> Text
xs
  Maybe (Char, Text)
_               -> Text
s

-- | Trim up to one newline from the end of the string.
rchop :: Text -> Text
rchop :: Text -> Text
rchop Text
s = case Text -> Maybe (Text, Char)
T.unsnoc Text
s of
  Just (Text
xs, Char
'\n') -> Text
xs
  Maybe (Text, Char)
_               -> Text
s

unindent :: Text -> Text
unindent :: Text -> Text
unindent = Text -> Text
rchop (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Text] -> Text
T.intercalate Text
"\n" ([Text] -> Text) -> (Text -> [Text]) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> [Text]
dropSpacePrefix ([Text] -> [Text]) -> (Text -> [Text]) -> Text -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> [Text]
T.splitOn Text
"\n" (Text -> [Text]) -> (Text -> Text) -> Text -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
lchop

dropSpacePrefix :: [Text] -> [Text]
dropSpacePrefix :: [Text] -> [Text]
dropSpacePrefix [Text]
lns = Int -> Text -> Text
T.drop Int
maxIndent (Text -> Text) -> [Text] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Text]
lns
  where isSpaceChar :: Char -> Bool
isSpaceChar Char
c = Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\t'
        maxIndent :: Int
maxIndent = [Text] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([Text] -> Int) -> [Text] -> Int
forall a b. (a -> b) -> a -> b
$ (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Char -> Bool
isSpaceChar (Char -> Bool) -> (Text -> Char) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Char
T.head) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile Text -> Bool
same ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ [Text] -> [Text]
T.transpose [Text]
lns
        same :: Text -> Bool
same Text
t = case Text -> Maybe (Char, Text)
T.uncons Text
t of
          Just (Char
c, Text
cs) -> (Char -> Bool) -> Text -> Bool
T.all (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
c) Text
cs
          Maybe (Char, Text)
Nothing      -> Bool
True

atStart :: PandocMonad m => MuseParser m ()
atStart :: MuseParser m ()
atStart = do
  SourcePos
pos <- ParsecT Text MuseState (ReaderT MuseEnv m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  MuseState
st <- ParsecT Text MuseState (ReaderT MuseEnv m) MuseState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Bool -> MuseParser m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> MuseParser m ()) -> Bool -> MuseParser m ()
forall a b. (a -> b) -> a -> b
$ MuseState -> Maybe SourcePos
museLastStrPos MuseState
st Maybe SourcePos -> Maybe SourcePos -> Bool
forall a. Eq a => a -> a -> Bool
/= SourcePos -> Maybe SourcePos
forall a. a -> Maybe a
Just SourcePos
pos

noSpaceBefore :: PandocMonad m => MuseParser m ()
noSpaceBefore :: MuseParser m ()
noSpaceBefore = do
  SourcePos
pos <- ParsecT Text MuseState (ReaderT MuseEnv m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  MuseState
st <- ParsecT Text MuseState (ReaderT MuseEnv m) MuseState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Bool -> MuseParser m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> MuseParser m ()) -> Bool -> MuseParser m ()
forall a b. (a -> b) -> a -> b
$ MuseState -> Maybe SourcePos
museLastSpacePos MuseState
st Maybe SourcePos -> Maybe SourcePos -> Bool
forall a. Eq a => a -> a -> Bool
/= SourcePos -> Maybe SourcePos
forall a. a -> Maybe a
Just SourcePos
pos

firstColumn :: PandocMonad m => MuseParser m ()
firstColumn :: MuseParser m ()
firstColumn = ParsecT Text MuseState (ReaderT MuseEnv m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition ParsecT Text MuseState (ReaderT MuseEnv m) SourcePos
-> (SourcePos -> MuseParser m ()) -> MuseParser m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \SourcePos
pos -> Bool -> MuseParser m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (SourcePos -> Int
sourceColumn SourcePos
pos Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1)

-- * Parsers

-- | Parse end-of-line, which can be either a newline or end-of-file.
eol :: Stream s m Char => ParserT s st m ()
eol :: ParserT s st m ()
eol = ParsecT s st m Char -> ParserT s st m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT s st m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline ParserT s st m () -> ParserT s st m () -> ParserT s st m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT s st m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof

getIndent :: PandocMonad m
          => MuseParser m Int
getIndent :: MuseParser m Int
getIndent = Int -> Int -> Int
forall a. Num a => a -> a -> a
subtract Int
1 (Int -> Int) -> (SourcePos -> Int) -> SourcePos -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourcePos -> Int
sourceColumn (SourcePos -> Int)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) (SourcePos -> Int)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) (SourcePos -> Int)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourcePos
-> MuseParser m Int
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text MuseState (ReaderT MuseEnv m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition

-- ** HTML parsers

openTag :: PandocMonad m => Text -> MuseParser m [(Text, Text)]
openTag :: Text -> MuseParser m [(Text, Text)]
openTag Text
tag = MuseParser m [(Text, Text)] -> MuseParser m [(Text, Text)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m [(Text, Text)] -> MuseParser m [(Text, Text)])
-> MuseParser m [(Text, Text)] -> MuseParser m [(Text, Text)]
forall a b. (a -> b) -> a -> b
$
  Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'<' ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
tag ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> MuseParser m [(Text, Text)] -> MuseParser m [(Text, Text)]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text MuseState (ReaderT MuseEnv m) (Text, Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m [(Text, Text)]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text MuseState (ReaderT MuseEnv m) (Text, Text)
forall u. ParsecT Text u (ReaderT MuseEnv m) (Text, Text)
attr (Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>')
  where
    attr :: ParsecT Text u (ReaderT MuseEnv m) (Text, Text)
attr = ParsecT Text u (ReaderT MuseEnv m) (Text, Text)
-> ParsecT Text u (ReaderT MuseEnv m) (Text, Text)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u (ReaderT MuseEnv m) (Text, Text)
 -> ParsecT Text u (ReaderT MuseEnv m) (Text, Text))
-> ParsecT Text u (ReaderT MuseEnv m) (Text, Text)
-> ParsecT Text u (ReaderT MuseEnv m) (Text, Text)
forall a b. (a -> b) -> a -> b
$ (,)
      (Text -> Text -> (Text, Text))
-> ParsecT Text u (ReaderT MuseEnv m) SourceName
-> ParsecT
     Text u (ReaderT MuseEnv m) (Text -> Text -> (Text, Text))
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
      ParsecT Text u (ReaderT MuseEnv m) (Text -> Text -> (Text, Text))
-> ParsecT Text u (ReaderT MuseEnv m) Text
-> ParsecT Text u (ReaderT MuseEnv m) (Text -> (Text, Text))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char (SourceName -> ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m Char
noneOf SourceName
"=\n")
      ParsecT Text u (ReaderT MuseEnv m) (Text -> (Text, Text))
-> ParsecT Text u (ReaderT MuseEnv m) SourceName
-> ParsecT Text u (ReaderT MuseEnv m) (Text -> (Text, Text))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  SourceName -> ParsecT Text u (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"=\""
      ParsecT Text u (ReaderT MuseEnv m) (Text -> (Text, Text))
-> ParsecT Text u (ReaderT MuseEnv m) Text
-> ParsecT Text u (ReaderT MuseEnv m) (Text, Text)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv 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 (SourceName -> ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m Char
noneOf SourceName
"\"") (Char -> ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'"')

closeTag :: PandocMonad m => Text -> MuseParser m ()
closeTag :: Text -> MuseParser m ()
closeTag Text
tag = MuseParser m () -> MuseParser m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m () -> MuseParser m ())
-> MuseParser m () -> MuseParser m ()
forall a b. (a -> b) -> a -> b
$ SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"</" ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
tag ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> MuseParser m () -> MuseParser m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text MuseState (ReaderT MuseEnv m) Char -> MuseParser m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>')

-- | Convert HTML attributes to Pandoc 'Attr'
htmlAttrToPandoc :: [(Text, Text)] -> Attr
htmlAttrToPandoc :: [(Text, Text)] -> Attr
htmlAttrToPandoc [(Text, Text)]
attrs = (Text
ident, [Text]
classes, [(Text, Text)]
keyvals)
  where
    ident :: Text
ident   = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" (Maybe Text -> Text) -> Maybe Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"id" [(Text, Text)]
attrs
    classes :: [Text]
classes = [Text] -> (Text -> [Text]) -> Maybe Text -> [Text]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Text -> [Text]
T.words (Maybe Text -> [Text]) -> Maybe Text -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"class" [(Text, Text)]
attrs
    keyvals :: [(Text, Text)]
keyvals = [(Text
k,Text
v) | (Text
k,Text
v) <- [(Text, Text)]
attrs, Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"id", Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"class"]

parseHtmlContent :: PandocMonad m
                 => Text -- ^ Tag name
                 -> MuseParser m (Attr, F Blocks)
parseHtmlContent :: Text -> MuseParser m (Attr, F Blocks)
parseHtmlContent Text
tag = MuseParser m (Attr, F Blocks) -> MuseParser m (Attr, F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (Attr, F Blocks) -> MuseParser m (Attr, F Blocks))
-> MuseParser m (Attr, F Blocks) -> MuseParser m (Attr, F Blocks)
forall a b. (a -> b) -> a -> b
$ MuseParser m Int
forall (m :: * -> *). PandocMonad m => MuseParser m Int
getIndent MuseParser m Int
-> (Int -> MuseParser m (Attr, F Blocks))
-> MuseParser m (Attr, F Blocks)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
indent -> (,)
  (Attr -> F Blocks -> (Attr, F Blocks))
-> ParsecT Text MuseState (ReaderT MuseEnv m) Attr
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks -> (Attr, F Blocks))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([(Text, Text)] -> Attr)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
-> ParsecT Text MuseState (ReaderT MuseEnv m) Attr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(Text, Text)] -> Attr
htmlAttrToPandoc (Text -> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m [(Text, Text)]
openTag Text
tag)
  ParsecT
  Text MuseState (ReaderT MuseEnv m) (F Blocks -> (Attr, F Blocks))
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks -> (Attr, F Blocks))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol
  ParsecT
  Text MuseState (ReaderT MuseEnv m) (F Blocks -> (Attr, F Blocks))
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
-> MuseParser m (Attr, F Blocks)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
forall (m :: * -> *) a. MonadReader MuseEnv m => m a -> m a
allowPara (ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks)
parseBlocksTill (ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text MuseState (ReaderT MuseEnv m) ()
 -> ParsecT Text MuseState (ReaderT MuseEnv m) ())
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall a b. (a -> b) -> a -> b
$ Int -> ParserT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) st.
(Stream s m Char, HasReaderOptions st) =>
Int -> ParserT s st m Text
indentWith Int
indent ParserT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => Text -> MuseParser m ()
closeTag Text
tag))
  MuseParser m (Attr, F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (Attr, F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol -- closing tag must be followed by optional whitespace and newline

-- ** Directive parsers

-- While not documented, Emacs Muse allows "-" in directive name
parseDirectiveKey :: PandocMonad m => MuseParser m Text
parseDirectiveKey :: MuseParser m Text
parseDirectiveKey = Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'#' ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m Text -> MuseParser m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
manyChar (ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'-')

parseEmacsDirective :: PandocMonad m => MuseParser m (Text, F Inlines)
parseEmacsDirective :: MuseParser m (Text, F Inlines)
parseEmacsDirective = (,)
  (Text -> F Inlines -> (Text, F Inlines))
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Inlines -> (Text, F Inlines))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (m :: * -> *). PandocMonad m => MuseParser m Text
parseDirectiveKey
  ParsecT
  Text MuseState (ReaderT MuseEnv m) (F Inlines -> (Text, F Inlines))
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Inlines -> (Text, F Inlines))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
  ParsecT
  Text MuseState (ReaderT MuseEnv m) (F Inlines -> (Text, F Inlines))
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> MuseParser m (Text, F Inlines)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline' ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol)

parseAmuseDirective :: PandocMonad m => MuseParser m (Text, F Inlines)
parseAmuseDirective :: MuseParser m (Text, F Inlines)
parseAmuseDirective = (,)
  (Text -> F Inlines -> (Text, F Inlines))
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Inlines -> (Text, F Inlines))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (m :: * -> *). PandocMonad m => MuseParser m Text
parseDirectiveKey
  ParsecT
  Text MuseState (ReaderT MuseEnv m) (F Inlines -> (Text, F Inlines))
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Inlines -> (Text, F Inlines))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
  ParsecT
  Text MuseState (ReaderT MuseEnv m) (F Inlines -> (Text, F Inlines))
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> MuseParser m (Text, F Inlines)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline ParserT Text MuseState (ReaderT MuseEnv m) ()
endOfDirective)
  MuseParser m (Text, F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (Text, F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline
  where
    endOfDirective :: ParserT Text MuseState (ReaderT MuseEnv m) ()
endOfDirective = ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParserT Text MuseState (ReaderT MuseEnv m) ()
 -> ParserT Text MuseState (ReaderT MuseEnv m) ())
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall a b. (a -> b) -> a -> b
$ ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (m :: * -> *). PandocMonad m => MuseParser m Text
parseDirectiveKey))

directive :: PandocMonad m => MuseParser m ()
directive :: MuseParser m ()
directive = do
  Extensions
ext <- (ReaderOptions -> Extensions)
-> ParserT Text MuseState (ReaderT MuseEnv m) Extensions
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParserT s st m b
getOption ReaderOptions -> Extensions
readerExtensions
  (Text
key, F Inlines
value) <- if Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_amuse Extensions
ext then MuseParser m (Text, F Inlines)
forall (m :: * -> *).
PandocMonad m =>
MuseParser m (Text, F Inlines)
parseAmuseDirective else MuseParser m (Text, F Inlines)
forall (m :: * -> *).
PandocMonad m =>
MuseParser m (Text, F Inlines)
parseEmacsDirective
  (MuseState -> MuseState) -> MuseParser m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((MuseState -> MuseState) -> MuseParser m ())
-> (MuseState -> MuseState) -> MuseParser m ()
forall a b. (a -> b) -> a -> b
$ \MuseState
st -> MuseState
st { museMeta :: F Meta
museMeta = Text -> Inlines -> Meta -> Meta
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
B.setMeta (Text -> Text
forall p. (Eq p, IsString p) => p -> p
translateKey Text
key) (Inlines -> Meta -> Meta)
-> F Inlines -> Future MuseState (Meta -> Meta)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
value Future MuseState (Meta -> Meta) -> F Meta -> F Meta
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MuseState -> F Meta
museMeta MuseState
st }
  where translateKey :: p -> p
translateKey p
"cover" = p
"cover-image"
        translateKey p
x = p
x

-- ** Block parsers

allowPara :: MonadReader MuseEnv m => m a -> m a
allowPara :: m a -> m a
allowPara m a
p = (MuseEnv -> MuseEnv) -> m a -> m a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\MuseEnv
s -> MuseEnv
s { museInPara :: Bool
museInPara = Bool
False }) m a
p

-- | Parse section contents until EOF or next header
parseBlocks :: PandocMonad m
            => MuseParser m (F Blocks)
parseBlocks :: MuseParser m (F Blocks)
parseBlocks =
  MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks)
forall u. ParsecT Text u (ReaderT MuseEnv m) (F Blocks)
parseEnd MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
       MuseParser m (F Blocks)
nextSection MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
       MuseParser m (F Blocks)
listStart MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
       MuseParser m (F Blocks)
blockStart MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
       MuseParser m (F Blocks)
paraStart)
  where
    nextSection :: MuseParser m (F Blocks)
nextSection = F Blocks
forall a. Monoid a => a
mempty F Blocks
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text, Int)
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text MuseState (ReaderT MuseEnv m) (Text, Int)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text, Int)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Text MuseState (ReaderT MuseEnv m) (Text, Int)
forall (m :: * -> *). PandocMonad m => MuseParser m (Text, Int)
headingStart
    parseEnd :: ParsecT Text u (ReaderT MuseEnv m) (F Blocks)
parseEnd = F Blocks
forall a. Monoid a => a
mempty F Blocks
-> ParsecT Text u (ReaderT MuseEnv m) ()
-> ParsecT Text u (ReaderT MuseEnv m) (F Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text u (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
    blockStart :: MuseParser m (F Blocks)
blockStart = F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
(B.<>) (F Blocks -> F Blocks -> F Blocks)
-> MuseParser m (F Blocks)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks -> F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
blockElements MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
emacsNoteBlock)
                        ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks -> F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall (m :: * -> *) a. MonadReader MuseEnv m => m a -> m a
allowPara MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
parseBlocks
    listStart :: MuseParser m (F Blocks)
listStart =
      (F Blocks -> F Blocks -> F Blocks)
-> (F Blocks, F Blocks) -> F Blocks
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
(B.<>) ((F Blocks, F Blocks) -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
forall (m :: * -> *) a. MonadReader MuseEnv m => m a -> m a
allowPara (MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks, a)
anyListUntil MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
parseBlocks ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks, a)
amuseNoteBlockUntil MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
parseBlocks)
    paraStart :: MuseParser m (F Blocks)
paraStart = do
      Int
indent <- SourceName -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (SourceName -> Int)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
      (F Blocks -> F Blocks -> F Blocks)
-> (F Blocks, F Blocks) -> F Blocks
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
(B.<>) ((F Blocks, F Blocks) -> F Blocks)
-> ((F Blocks, F Blocks) -> (F Blocks, F Blocks))
-> (F Blocks, F Blocks)
-> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (F Blocks -> F Blocks)
-> (F Blocks, F Blocks) -> (F Blocks, F Blocks)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (Int -> F Blocks -> F Blocks
forall a (f :: * -> *).
(Ord a, Num a, Functor f) =>
a -> f Blocks -> f Blocks
p Int
indent) ((F Blocks, F Blocks) -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks, a)
paraUntil MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
parseBlocks
      where p :: a -> f Blocks -> f Blocks
p a
indent = if a
indent a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
2 Bool -> Bool -> Bool
&& a
indent a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
6 then (Blocks -> Blocks) -> f Blocks -> f Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Blocks -> Blocks
B.blockQuote else f Blocks -> f Blocks
forall a. a -> a
id

-- | Parse section that starts with a header
parseSection :: PandocMonad m
             => MuseParser m (F Blocks)
parseSection :: MuseParser m (F Blocks)
parseSection =
  (F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
(B.<>) (F Blocks -> F Blocks -> F Blocks)
-> MuseParser m (F Blocks)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks -> F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
emacsHeading ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks -> F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
parseBlocks) MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
  ((F Blocks -> F Blocks -> F Blocks)
-> (F Blocks, F Blocks) -> F Blocks
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
(B.<>) ((F Blocks, F Blocks) -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks, a)
amuseHeadingUntil MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
parseBlocks)

parseBlocksTill :: PandocMonad m
                => MuseParser m a
                -> MuseParser m (F Blocks)
parseBlocksTill :: MuseParser m a -> MuseParser m (F Blocks)
parseBlocksTill MuseParser m a
end = MuseParser m (F Blocks)
continuation
  where
    parseEnd :: MuseParser m (F Blocks)
parseEnd = F Blocks
forall a. Monoid a => a
mempty F Blocks -> MuseParser m a -> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ MuseParser m a
end
    blockStart :: MuseParser m (F Blocks)
blockStart = F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
(B.<>) (F Blocks -> F Blocks -> F Blocks)
-> MuseParser m (F Blocks)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks -> F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
blockElements ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks -> F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall (m :: * -> *) a. MonadReader MuseEnv m => m a -> m a
allowPara MuseParser m (F Blocks)
continuation
    listStart :: MuseParser m (F Blocks)
listStart = (F Blocks -> F Blocks -> F Blocks)
-> (F Blocks, F Blocks) -> F Blocks
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
(B.<>) ((F Blocks, F Blocks) -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
forall (m :: * -> *) a. MonadReader MuseEnv m => m a -> m a
allowPara (MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks, a)
anyListUntil (MuseParser m (F Blocks)
parseEnd MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
continuation))
    paraStart :: MuseParser m (F Blocks)
paraStart = (F Blocks -> F Blocks -> F Blocks)
-> (F Blocks, F Blocks) -> F Blocks
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
(B.<>) ((F Blocks, F Blocks) -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, F Blocks)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks, a)
paraUntil (MuseParser m (F Blocks)
parseEnd MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
continuation)
    continuation :: MuseParser m (F Blocks)
continuation = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ MuseParser m (F Blocks)
parseEnd MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
listStart MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
blockStart MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
paraStart

listItemContentsUntil :: PandocMonad m
                      => Int
                      -> MuseParser m a
                      -> MuseParser m a
                      -> MuseParser m (F Blocks, a)
listItemContentsUntil :: Int
-> MuseParser m a -> MuseParser m a -> MuseParser m (F Blocks, a)
listItemContentsUntil Int
col MuseParser m a
pre MuseParser m a
end = MuseParser m (F Blocks, a)
p
  where
    p :: MuseParser m (F Blocks, a)
p = MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try MuseParser m (F Blocks, a)
listStart MuseParser m (F Blocks, a)
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try MuseParser m (F Blocks, a)
blockStart MuseParser m (F Blocks, a)
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try MuseParser m (F Blocks, a)
paraStart
    parsePre :: MuseParser m (F Blocks, a)
parsePre = (F Blocks
forall a. Monoid a => a
mempty,) (a -> (F Blocks, a))
-> MuseParser m a -> MuseParser m (F Blocks, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m a
pre
    parseEnd :: MuseParser m (F Blocks, a)
parseEnd = (F Blocks
forall a. Monoid a => a
mempty,) (a -> (F Blocks, a))
-> MuseParser m a -> MuseParser m (F Blocks, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m a
end
    paraStart :: MuseParser m (F Blocks, a)
paraStart = do
      (F Blocks
f, (F Blocks
r, a
e)) <- MuseParser m (F Blocks, a)
-> MuseParser m (F Blocks, (F Blocks, a))
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks, a)
paraUntil (MuseParser m (F Blocks, a)
parsePre MuseParser m (F Blocks, a)
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks, a)
continuation MuseParser m (F Blocks, a)
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks, a)
parseEnd)
      (F Blocks, a) -> MuseParser m (F Blocks, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Blocks
f F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
B.<> F Blocks
r, a
e)
    blockStart :: MuseParser m (F Blocks, a)
blockStart = (F Blocks -> F Blocks) -> (F Blocks, a) -> (F Blocks, a)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ((F Blocks -> F Blocks) -> (F Blocks, a) -> (F Blocks, a))
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks -> F Blocks)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ((F Blocks, a) -> (F Blocks, a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
(B.<>) (F Blocks -> F Blocks -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks -> F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
blockElements)
                       ParsecT
  Text MuseState (ReaderT MuseEnv m) ((F Blocks, a) -> (F Blocks, a))
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall (m :: * -> *) a. MonadReader MuseEnv m => m a -> m a
allowPara (MuseParser m (F Blocks, a)
parsePre MuseParser m (F Blocks, a)
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks, a)
continuation MuseParser m (F Blocks, a)
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks, a)
parseEnd)
    listStart :: MuseParser m (F Blocks, a)
listStart = do
      (F Blocks
f, (F Blocks
r, a
e)) <- MuseParser m (F Blocks, (F Blocks, a))
-> MuseParser m (F Blocks, (F Blocks, a))
forall (m :: * -> *) a. MonadReader MuseEnv m => m a -> m a
allowPara (MuseParser m (F Blocks, (F Blocks, a))
 -> MuseParser m (F Blocks, (F Blocks, a)))
-> MuseParser m (F Blocks, (F Blocks, a))
-> MuseParser m (F Blocks, (F Blocks, a))
forall a b. (a -> b) -> a -> b
$ MuseParser m (F Blocks, a)
-> MuseParser m (F Blocks, (F Blocks, a))
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks, a)
anyListUntil (MuseParser m (F Blocks, a)
parsePre MuseParser m (F Blocks, a)
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks, a)
continuation MuseParser m (F Blocks, a)
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks, a)
parseEnd)
      (F Blocks, a) -> MuseParser m (F Blocks, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Blocks
f F Blocks -> F Blocks -> F Blocks
forall a. Semigroup a => a -> a -> a
B.<> F Blocks
r, a
e)
    continuation :: MuseParser m (F Blocks, a)
continuation = MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a))
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall a b. (a -> b) -> a -> b
$ do Maybe Char
blank <- ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Maybe Char)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline
                            ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline
                            Int -> ParserT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) st.
(Stream s m Char, HasReaderOptions st) =>
Int -> ParserT s st m Text
indentWith Int
col
                            (MuseEnv -> MuseEnv)
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\MuseEnv
s -> MuseEnv
s { museInPara :: Bool
museInPara = MuseEnv -> Bool
museInPara MuseEnv
s Bool -> Bool -> Bool
&& Maybe Char -> Bool
forall a. Maybe a -> Bool
isNothing Maybe Char
blank }) MuseParser m (F Blocks, a)
p

parseBlock :: PandocMonad m => MuseParser m (F Blocks)
parseBlock :: MuseParser m (F Blocks)
parseBlock = do
  F Blocks
res <- MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
blockElements MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
para
  Text -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => Text -> m ()
trace (Int -> Text -> Text
T.take Int
60 (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ [Block] -> Text
forall a. Show a => a -> Text
tshow ([Block] -> Text) -> [Block] -> Text
forall a b. (a -> b) -> a -> b
$ Blocks -> [Block]
forall a. Many a -> [a]
B.toList (Blocks -> [Block]) -> Blocks -> [Block]
forall a b. (a -> b) -> a -> b
$ F Blocks -> MuseState -> Blocks
forall s a. Future s a -> s -> a
runF F Blocks
res MuseState
forall a. Default a => a
def)
  F Blocks -> MuseParser m (F Blocks)
forall (m :: * -> *) a. Monad m => a -> m a
return F Blocks
res
  where para :: MuseParser m (F Blocks)
para = (F Blocks, ()) -> F Blocks
forall a b. (a, b) -> a
fst ((F Blocks, ()) -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, ())
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks, ())
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks, a)
paraUntil (ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
blockElements)))

blockElements :: PandocMonad m => MuseParser m (F Blocks)
blockElements :: MuseParser m (F Blocks)
blockElements = (F Blocks
forall a. Monoid a => a
mempty F Blocks
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline)
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
comment
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
separator
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
pagebreak
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
example
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
exampleTag
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
literalTag
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
centerTag
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
rightTag
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
quoteTag
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
divTag
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
biblioTag
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
playTag
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
verseTag
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
lineBlock
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
museGridTable
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
table
            MuseParser m (F Blocks)
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
commentTag

-- | Parse a line comment, starting with @;@ in the first column.
comment :: PandocMonad m => MuseParser m (F Blocks)
comment :: MuseParser m (F Blocks)
comment = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ F Blocks
forall a. Monoid a => a
mempty
  F Blocks
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => MuseParser m ()
firstColumn
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
';'
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m Char
noneOf SourceName
"\n"))
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol

-- | Parse a horizontal rule, consisting of 4 or more @\'-\'@ characters.
separator :: PandocMonad m => MuseParser m (F Blocks)
separator :: MuseParser m (F Blocks)
separator = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ Blocks -> F Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
B.horizontalRule
  F Blocks
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"----"
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'-')
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol

-- | Parse a page break
pagebreak :: PandocMonad m => MuseParser m (F Blocks)
pagebreak :: MuseParser m (F Blocks)
pagebreak = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ Blocks -> F Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Attr -> Blocks -> Blocks
B.divWith (Text
"", [], [(Text
"style", Text
"page-break-before: always;")]) Blocks
forall a. Monoid a => a
mempty)
  F Blocks
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Int
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
6 ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"* * * * *"
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol

headingStart :: PandocMonad m => MuseParser m (Text, Int)
headingStart :: MuseParser m (Text, Int)
headingStart = MuseParser m (Text, Int) -> MuseParser m (Text, Int)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (Text, Int) -> MuseParser m (Text, Int))
-> MuseParser m (Text, Int) -> MuseParser m (Text, Int)
forall a b. (a -> b) -> a -> b
$ (,)
  (Text -> Int -> (Text, Int))
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Int -> (Text, Int))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" (ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (m :: * -> *). PandocMonad m => MuseParser m Text
parseAnchor ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol))
  ParsecT Text MuseState (ReaderT MuseEnv m) (Int -> (Text, Int))
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Int -> (Text, Int))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => MuseParser m ()
firstColumn
  ParsecT Text MuseState (ReaderT MuseEnv m) (Int -> (Text, Int))
-> ParsecT Text MuseState (ReaderT MuseEnv m) Int
-> MuseParser m (Text, Int)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (SourceName -> Int)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SourceName -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Text MuseState (ReaderT MuseEnv m) Char
 -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'*')
  MuseParser m (Text, Int)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m (Text, Int)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar

-- | Parse a single-line heading.
emacsHeading :: PandocMonad m => MuseParser m (F Blocks)
emacsHeading :: MuseParser m (F Blocks)
emacsHeading = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ do
  Extension -> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardDisabled Extension
Ext_amuse
  (Text
anchorId, Int
level) <- MuseParser m (Text, Int)
forall (m :: * -> *). PandocMonad m => MuseParser m (Text, Int)
headingStart
  F Inlines
content <- F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol
  Attr
attr <- Attr -> Inlines -> ParserT Text MuseState (ReaderT MuseEnv 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 (Text
anchorId, [], []) (F Inlines -> MuseState -> Inlines
forall s a. Future s a -> s -> a
runF F Inlines
content MuseState
forall a. Default a => a
def)
  F Blocks -> MuseParser m (F Blocks)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Blocks -> MuseParser m (F Blocks))
-> F Blocks -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ Attr -> Int -> Inlines -> Blocks
B.headerWith Attr
attr Int
level (Inlines -> Blocks) -> F Inlines -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
content

-- | Parse a multi-line heading.
-- It is a Text::Amuse extension, Emacs Muse does not allow heading to span multiple lines.
amuseHeadingUntil :: PandocMonad m
                  => MuseParser m a -- ^ Terminator parser
                  -> MuseParser m (F Blocks, a)
amuseHeadingUntil :: MuseParser m a -> MuseParser m (F Blocks, a)
amuseHeadingUntil MuseParser m a
end = MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a))
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall a b. (a -> b) -> a -> b
$ do
  Extension -> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_amuse
  (Text
anchorId, Int
level) <- MuseParser m (Text, Int)
forall (m :: * -> *). PandocMonad m => MuseParser m (Text, Int)
headingStart
  (F Inlines
content, a
e) <- MuseParser m a -> MuseParser m (F Inlines, a)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Inlines, a)
paraContentsUntil MuseParser m a
end
  Attr
attr <- Attr -> Inlines -> ParserT Text MuseState (ReaderT MuseEnv 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 (Text
anchorId, [], []) (F Inlines -> MuseState -> Inlines
forall s a. Future s a -> s -> a
runF F Inlines
content MuseState
forall a. Default a => a
def)
  (F Blocks, a) -> MuseParser m (F Blocks, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Attr -> Int -> Inlines -> Blocks
B.headerWith Attr
attr Int
level (Inlines -> Blocks) -> F Inlines -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
content, a
e)

-- | Parse an example between @{{{@ and @}}}@.
-- It is an Amusewiki extension influenced by Creole wiki, as described in @Text::Amuse@ documentation.
example :: PandocMonad m => MuseParser m (F Blocks)
example :: MuseParser m (F Blocks)
example = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ Blocks -> F Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Blocks -> F Blocks) -> (Text -> Blocks) -> Text -> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Blocks
B.codeBlock
  (Text -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> F Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"{{{"
  ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
  ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Text -> Text
unindent (Text -> Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv 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 ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"}}}"))

-- | Parse an @\<example>@ tag.
exampleTag :: PandocMonad m => MuseParser m (F Blocks)
exampleTag :: MuseParser m (F Blocks)
exampleTag = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ (Blocks -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Blocks
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Blocks -> F Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ParsecT Text MuseState (ReaderT MuseEnv m) Blocks
 -> MuseParser m (F Blocks))
-> ParsecT Text MuseState (ReaderT MuseEnv m) Blocks
-> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Blocks
B.codeBlockWith
  (Attr -> Text -> Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Attr -> Text -> Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
  ParsecT Text MuseState (ReaderT MuseEnv m) (Attr -> Text -> Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Attr
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Blocks)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([(Text, Text)] -> Attr
htmlAttrToPandoc ([(Text, Text)] -> Attr)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
-> ParsecT Text MuseState (ReaderT MuseEnv m) Attr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m [(Text, Text)]
openTag Text
"example")
  ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Blocks
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Text -> Text
unindent (Text -> Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv 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 ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (Text -> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => Text -> MuseParser m ()
closeTag Text
"example"))
  ParsecT Text MuseState (ReaderT MuseEnv m) Blocks
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol

-- | Parse a @\<literal>@ tag as a raw block.
-- For 'RawInline' @\<literal>@ parser, see 'inlineLiteralTag'.
literalTag :: PandocMonad m => MuseParser m (F Blocks)
literalTag :: MuseParser m (F Blocks)
literalTag = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ (Blocks -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Blocks
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Blocks -> F Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ParsecT Text MuseState (ReaderT MuseEnv m) Blocks
 -> MuseParser m (F Blocks))
-> ParsecT Text MuseState (ReaderT MuseEnv m) Blocks
-> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Blocks
B.rawBlock
  (Text -> Text -> Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Text -> Text -> Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
  ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Text -> Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Blocks)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"html" (Maybe Text -> Text)
-> ([(Text, Text)] -> Maybe Text) -> [(Text, Text)] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"style" ([(Text, Text)] -> Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m [(Text, Text)]
openTag Text
"literal") -- FIXME: Emacs Muse inserts <literal> without style into all output formats, but we assume HTML
  ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol
  ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Blocks
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Text -> Text
unindent (Text -> Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv 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 ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (Text -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => Text -> MuseParser m ()
closeTag Text
"literal"))
  ParsecT Text MuseState (ReaderT MuseEnv m) Blocks
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol

-- | Parse @\<center>@ tag.
-- Currently it is ignored as Pandoc cannot represent centered blocks.
centerTag :: PandocMonad m => MuseParser m (F Blocks)
centerTag :: MuseParser m (F Blocks)
centerTag = (Attr, F Blocks) -> F Blocks
forall a b. (a, b) -> b
snd ((Attr, F Blocks) -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Attr, F Blocks)
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) (Attr, F Blocks)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (Attr, F Blocks)
parseHtmlContent Text
"center"

-- | Parse @\<right>@ tag.
-- Currently it is ignored as Pandoc cannot represent centered blocks.
rightTag :: PandocMonad m => MuseParser m (F Blocks)
rightTag :: MuseParser m (F Blocks)
rightTag = (Attr, F Blocks) -> F Blocks
forall a b. (a, b) -> b
snd ((Attr, F Blocks) -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Attr, F Blocks)
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) (Attr, F Blocks)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (Attr, F Blocks)
parseHtmlContent Text
"right"

-- | Parse @\<quote>@ tag.
quoteTag :: PandocMonad m => MuseParser m (F Blocks)
quoteTag :: MuseParser m (F Blocks)
quoteTag = (Blocks -> Blocks) -> F Blocks -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Blocks -> Blocks
B.blockQuote (F Blocks -> F Blocks)
-> ((Attr, F Blocks) -> F Blocks) -> (Attr, F Blocks) -> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Attr, F Blocks) -> F Blocks
forall a b. (a, b) -> b
snd ((Attr, F Blocks) -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Attr, F Blocks)
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) (Attr, F Blocks)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (Attr, F Blocks)
parseHtmlContent Text
"quote"

-- | Parse @\<div>@ tag.
-- @\<div>@ tag is supported by Emacs Muse, but not Amusewiki 2.025.
divTag :: PandocMonad m => MuseParser m (F Blocks)
divTag :: MuseParser m (F Blocks)
divTag = do
  (Attr
attrs, F Blocks
content) <- Text -> MuseParser m (Attr, F Blocks)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (Attr, F Blocks)
parseHtmlContent Text
"div"
  F Blocks -> MuseParser m (F Blocks)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Blocks -> MuseParser m (F Blocks))
-> F Blocks -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ Attr -> Blocks -> Blocks
B.divWith Attr
attrs (Blocks -> Blocks) -> F Blocks -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Blocks
content

-- | Parse @\<biblio>@ tag, the result is the same as @\<div class="biblio">@.
-- @\<biblio>@ tag is supported only in Text::Amuse mode.
biblioTag :: PandocMonad m => MuseParser m (F Blocks)
biblioTag :: MuseParser m (F Blocks)
biblioTag = (Blocks -> Blocks) -> F Blocks -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Attr -> Blocks -> Blocks
B.divWith (Text
"", [Text
"biblio"], [])) (F Blocks -> F Blocks)
-> ((Attr, F Blocks) -> F Blocks) -> (Attr, F Blocks) -> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Attr, F Blocks) -> F Blocks
forall a b. (a, b) -> b
snd
  ((Attr, F Blocks) -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ((Attr, F Blocks) -> F Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  Extension -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_amuse
  ParsecT
  Text MuseState (ReaderT MuseEnv m) ((Attr, F Blocks) -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Attr, F Blocks)
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) (Attr, F Blocks)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (Attr, F Blocks)
parseHtmlContent Text
"biblio"

-- | Parse @\<play>@ tag, the result is the same as @\<div class="play">@.
-- @\<play>@ tag is supported only in Text::Amuse mode.
playTag :: PandocMonad m => MuseParser m (F Blocks)
playTag :: MuseParser m (F Blocks)
playTag = do
  Extension -> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_amuse
  (Blocks -> Blocks) -> F Blocks -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Attr -> Blocks -> Blocks
B.divWith (Text
"", [Text
"play"], [])) (F Blocks -> F Blocks)
-> ((Attr, F Blocks) -> F Blocks) -> (Attr, F Blocks) -> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Attr, F Blocks) -> F Blocks
forall a b. (a, b) -> b
snd ((Attr, F Blocks) -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Attr, F Blocks)
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) (Attr, F Blocks)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (Attr, F Blocks)
parseHtmlContent Text
"play"

verseLine :: PandocMonad m => MuseParser m (F Inlines)
verseLine :: MuseParser m (F Inlines)
verseLine = F Inlines -> F Inlines -> F Inlines
forall a. Semigroup a => a -> a -> a
(<>)
  (F Inlines -> F Inlines -> F Inlines)
-> MuseParser m (F Inlines)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Inlines -> F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Inlines -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Inlines
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Inlines
forall a. Monoid a => a
mempty (Text -> Inlines
B.str (Text -> Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char (Char
'\160' Char
-> ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) Char
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParserT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
' ')))
  ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines -> F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat) (MuseParser m (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline' ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol)

-- | Parse @\<verse>@ tag.
verseTag :: PandocMonad m => MuseParser m (F Blocks)
verseTag :: MuseParser m (F Blocks)
verseTag = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ MuseParser m Int
forall (m :: * -> *). PandocMonad m => MuseParser m Int
getIndent MuseParser m Int
-> (Int -> MuseParser m (F Blocks)) -> MuseParser m (F Blocks)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
indent -> ([Inlines] -> Blocks) -> Future MuseState [Inlines] -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Inlines] -> Blocks
B.lineBlock (Future MuseState [Inlines] -> F Blocks)
-> ([F Inlines] -> Future MuseState [Inlines])
-> [F Inlines]
-> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> Future MuseState [Inlines]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
  ([F Inlines] -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  Text -> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m [(Text, Text)]
openTag Text
"verse"
  ParsecT
  Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol
  ParsecT
  Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill (Int -> ParserT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) st.
(Stream s m Char, HasReaderOptions st) =>
Int -> ParserT s st m Text
indentWith Int
indent ParserT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
verseLine) (ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text MuseState (ReaderT MuseEnv m) ()
 -> ParsecT Text MuseState (ReaderT MuseEnv m) ())
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall a b. (a -> b) -> a -> b
$ Int -> ParserT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) st.
(Stream s m Char, HasReaderOptions st) =>
Int -> ParserT s st m Text
indentWith Int
indent ParserT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => Text -> MuseParser m ()
closeTag Text
"verse")
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol

-- | Parse @\<comment>@ tag.
commentTag :: PandocMonad m => MuseParser m (F Blocks)
commentTag :: MuseParser m (F Blocks)
commentTag = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ F Blocks
forall a. Monoid a => a
mempty
  F Blocks
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Text -> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m [(Text, Text)]
openTag Text
"comment"
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (Text -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => Text -> MuseParser m ()
closeTag Text
"comment")
  MuseParser m (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol

-- | Parse paragraph contents.
paraContentsUntil :: PandocMonad m
                  => MuseParser m a -- ^ Terminator parser
                  -> MuseParser m (F Inlines, a)
paraContentsUntil :: MuseParser m a -> MuseParser m (F Inlines, a)
paraContentsUntil MuseParser m a
end = ([F Inlines] -> F Inlines) -> ([F Inlines], a) -> (F Inlines, a)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat)
  (([F Inlines], a) -> (F Inlines, a))
-> ParsecT Text MuseState (ReaderT MuseEnv m) ([F Inlines], a)
-> MuseParser m (F Inlines, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> MuseParser m a
-> ParsecT Text MuseState (ReaderT MuseEnv m) ([F Inlines], a)
forall s u (m :: * -> *) a b.
ParserT s u m a -> ParserT s u m b -> ParserT s u m ([a], b)
manyUntil ParserT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline (MuseParser m a -> MuseParser m a
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m a -> MuseParser m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (MuseEnv -> MuseEnv) -> MuseParser m a -> MuseParser m a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\MuseEnv
s -> MuseEnv
s { museInPara :: Bool
museInPara = Bool
True}) MuseParser m a
end))

-- | Parse a paragraph.
paraUntil :: PandocMonad m
          => MuseParser m a -- ^ Terminator parser
          -> MuseParser m (F Blocks, a)
paraUntil :: MuseParser m a -> MuseParser m (F Blocks, a)
paraUntil MuseParser m a
end = do
  Bool
inPara <- (MuseEnv -> Bool)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks MuseEnv -> Bool
museInPara
  Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ())
-> Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not Bool
inPara
  (F Inlines -> F Blocks) -> (F Inlines, a) -> (F Blocks, a)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ((Inlines -> Blocks) -> F Inlines -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Blocks
B.para) ((F Inlines, a) -> (F Blocks, a))
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines, a)
-> MuseParser m (F Blocks, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m a
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines, a)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Inlines, a)
paraContentsUntil MuseParser m a
end

noteMarker' :: PandocMonad m
            => Char
            -> Char
            -> MuseParser m Text
noteMarker' :: Char -> Char -> MuseParser m Text
noteMarker' Char
l Char
r = MuseParser m Text -> MuseParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m Text -> MuseParser m Text)
-> MuseParser m Text -> MuseParser m Text
forall a b. (a -> b) -> a -> b
$ (\Char
x SourceName
y -> SourceName -> Text
T.pack (SourceName -> Text) -> SourceName -> Text
forall a b. (a -> b) -> a -> b
$ Char
lChar -> SourceName -> SourceName
forall a. a -> [a] -> [a]
:Char
xChar -> SourceName -> SourceName
forall a. a -> [a] -> [a]
:SourceName
y SourceName -> SourceName -> SourceName
forall a. [a] -> [a] -> [a]
++ [Char
r])
  (Char -> SourceName -> Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Char -> SourceName -> Text)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
l
  ParsecT
  Text MuseState (ReaderT MuseEnv m) (Char -> SourceName -> Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) (SourceName -> Text)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m Char
oneOf SourceName
"123456789"
  ParsecT Text MuseState (ReaderT MuseEnv m) (SourceName -> Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m Text
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit (Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
r)

noteMarker :: PandocMonad m => MuseParser m Text
noteMarker :: MuseParser m Text
noteMarker = Char -> Char -> MuseParser m Text
forall (m :: * -> *).
PandocMonad m =>
Char -> Char -> MuseParser m Text
noteMarker' Char
'[' Char
']' MuseParser m Text -> MuseParser m Text -> MuseParser m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> Char -> MuseParser m Text
forall (m :: * -> *).
PandocMonad m =>
Char -> Char -> MuseParser m Text
noteMarker' Char
'{' Char
'}'

addNote :: PandocMonad m
        => Text
        -> SourcePos
        -> F Blocks
        -> MuseParser m ()
addNote :: Text -> SourcePos -> F Blocks -> MuseParser m ()
addNote Text
ref SourcePos
pos F Blocks
content = do
  Map Text (SourcePos, F Blocks)
oldnotes <- MuseState -> Map Text (SourcePos, F Blocks)
museNotes (MuseState -> Map Text (SourcePos, F Blocks))
-> ParsecT Text MuseState (ReaderT MuseEnv m) MuseState
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Map Text (SourcePos, F Blocks))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) MuseState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Bool -> MuseParser m () -> MuseParser m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Text -> Map Text (SourcePos, F Blocks) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
M.member Text
ref Map Text (SourcePos, F Blocks)
oldnotes)
    (LogMessage -> MuseParser m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasLogMessages st) =>
LogMessage -> ParserT s st m ()
logMessage (LogMessage -> MuseParser m ()) -> LogMessage -> MuseParser m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
DuplicateNoteReference Text
ref SourcePos
pos)
  (MuseState -> MuseState) -> MuseParser m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((MuseState -> MuseState) -> MuseParser m ())
-> (MuseState -> MuseState) -> MuseParser m ()
forall a b. (a -> b) -> a -> b
$ \MuseState
s -> MuseState
s{ museNotes :: Map Text (SourcePos, F Blocks)
museNotes = Text
-> (SourcePos, F Blocks)
-> Map Text (SourcePos, F Blocks)
-> Map Text (SourcePos, F Blocks)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
ref (SourcePos
pos, F Blocks
content) Map Text (SourcePos, F Blocks)
oldnotes }

-- Amusewiki version of note
-- Parsing is similar to list item, except that note marker is used instead of list marker
amuseNoteBlockUntil :: PandocMonad m
                    => MuseParser m a
                    -> MuseParser m (F Blocks, a)
amuseNoteBlockUntil :: MuseParser m a -> MuseParser m (F Blocks, a)
amuseNoteBlockUntil MuseParser m a
end = MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a))
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall a b. (a -> b) -> a -> b
$ do
  Extension -> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_amuse
  Text
ref <- MuseParser m Text
forall (m :: * -> *). PandocMonad m => MuseParser m Text
noteMarker
  SourcePos
pos <- ParsecT Text MuseState (ReaderT MuseEnv m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol
  (F Blocks
content, a
e) <- MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall (m :: * -> *) a. MonadReader MuseEnv m => m a -> m a
allowPara (MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a))
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall a b. (a -> b) -> a -> b
$ Int
-> MuseParser m a -> MuseParser m a -> MuseParser m (F Blocks, a)
forall (m :: * -> *) a.
PandocMonad m =>
Int
-> MuseParser m a -> MuseParser m a -> MuseParser m (F Blocks, a)
listItemContentsUntil (SourcePos -> Int
sourceColumn SourcePos
pos) (SourceName -> MuseParser m a
forall (m :: * -> *) a. MonadFail m => SourceName -> m a
Prelude.fail SourceName
"x") MuseParser m a
end
  Text
-> SourcePos
-> F Blocks
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *).
PandocMonad m =>
Text -> SourcePos -> F Blocks -> MuseParser m ()
addNote Text
ref SourcePos
pos F Blocks
content
  (F Blocks, a) -> MuseParser m (F Blocks, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Blocks
forall a. Monoid a => a
mempty, a
e)

-- Emacs version of note
-- Notes are allowed only at the end of text, no indentation is required.
emacsNoteBlock :: PandocMonad m => MuseParser m (F Blocks)
emacsNoteBlock :: MuseParser m (F Blocks)
emacsNoteBlock = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ do
  Extension -> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardDisabled Extension
Ext_amuse
  Text
ref <- MuseParser m Text
forall (m :: * -> *). PandocMonad m => MuseParser m Text
noteMarker
  SourcePos
pos <- ParsecT Text MuseState (ReaderT MuseEnv m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  F Blocks
content <- ([F Blocks] -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [F Blocks] -> F Blocks
forall a. Monoid a => [a] -> a
mconcat ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
blocksTillNote
  Text
-> SourcePos
-> F Blocks
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *).
PandocMonad m =>
Text -> SourcePos -> F Blocks -> MuseParser m ()
addNote Text
ref SourcePos
pos F Blocks
content
  F Blocks -> MuseParser m (F Blocks)
forall (m :: * -> *) a. Monad m => a -> m a
return F Blocks
forall a. Monoid a => a
mempty
  where
    blocksTillNote :: ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
blocksTillNote =
      MuseParser m (F Blocks)
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till MuseParser m (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
parseBlock (ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () ()
-> MuseParser m Text
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ MuseParser m Text -> MuseParser m Text
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead MuseParser m Text
forall (m :: * -> *). PandocMonad m => MuseParser m Text
noteMarker)

--
-- Verse markup
--

-- | Parse a line block indicated by @\'>\'@ characters.
lineBlock :: PandocMonad m => MuseParser m (F Blocks)
lineBlock :: MuseParser m (F Blocks)
lineBlock = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ MuseParser m Int
forall (m :: * -> *). PandocMonad m => MuseParser m Int
getIndent MuseParser m Int
-> (Int -> MuseParser m (F Blocks)) -> MuseParser m (F Blocks)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
indent -> ([Inlines] -> Blocks) -> Future MuseState [Inlines] -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Inlines] -> Blocks
B.lineBlock (Future MuseState [Inlines] -> F Blocks)
-> ([F Inlines] -> Future MuseState [Inlines])
-> [F Inlines]
-> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> Future MuseState [Inlines]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
  ([F Inlines] -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall u. ParsecT Text u (ReaderT MuseEnv m) (F Inlines)
blankVerseLine ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
nonblankVerseLine) ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall s u (m :: * -> *) a sep.
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
`sepBy1'` ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Int -> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) st.
(Stream s m Char, HasReaderOptions st) =>
Int -> ParserT s st m Text
indentWith Int
indent)
  where
    blankVerseLine :: ParsecT Text u (ReaderT MuseEnv m) (F Inlines)
blankVerseLine = ParsecT Text u (ReaderT MuseEnv m) (F Inlines)
-> ParsecT Text u (ReaderT MuseEnv m) (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u (ReaderT MuseEnv m) (F Inlines)
 -> ParsecT Text u (ReaderT MuseEnv m) (F Inlines))
-> ParsecT Text u (ReaderT MuseEnv m) (F Inlines)
-> ParsecT Text u (ReaderT MuseEnv m) (F Inlines)
forall a b. (a -> b) -> a -> b
$ F Inlines
forall a. Monoid a => a
mempty F Inlines
-> ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv m) (F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>' ParsecT Text u (ReaderT MuseEnv m) (F Inlines)
-> ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv m) (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline
    nonblankVerseLine :: ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
nonblankVerseLine = ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"> ") ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
verseLine

-- *** List parsers

bulletListItemsUntil :: PandocMonad m
                     => Int -- ^ Indentation
                     -> MuseParser m a -- ^ Terminator parser
                     -> MuseParser m ([F Blocks], a)
bulletListItemsUntil :: Int -> MuseParser m a -> MuseParser m ([F Blocks], a)
bulletListItemsUntil Int
indent MuseParser m a
end = MuseParser m ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m ([F Blocks], a) -> MuseParser m ([F Blocks], a))
-> MuseParser m ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall a b. (a -> b) -> a -> b
$ do
  Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'-'
  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol
  (F Blocks
x, ([F Blocks]
xs, a
e)) <- ParsecT
  Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
forall (m :: * -> *) a. MonadReader MuseEnv m => m a -> m a
allowPara (ParsecT
   Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
 -> ParsecT
      Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a)))
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
forall a b. (a -> b) -> a -> b
$ Int
-> MuseParser m ([F Blocks], a)
-> MuseParser m ([F Blocks], a)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
forall (m :: * -> *) a.
PandocMonad m =>
Int
-> MuseParser m a -> MuseParser m a -> MuseParser m (F Blocks, a)
listItemContentsUntil (Int
indent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (MuseParser m ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) st.
(Stream s m Char, HasReaderOptions st) =>
Int -> ParserT s st m Text
indentWith Int
indent ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> MuseParser m ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> MuseParser m a -> MuseParser m ([F Blocks], a)
forall (m :: * -> *) a.
PandocMonad m =>
Int -> MuseParser m a -> MuseParser m ([F Blocks], a)
bulletListItemsUntil Int
indent MuseParser m a
end)) (([],) (a -> ([F Blocks], a))
-> MuseParser m a -> MuseParser m ([F Blocks], a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m a
end)
  ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Blocks
xF Blocks -> [F Blocks] -> [F Blocks]
forall a. a -> [a] -> [a]
:[F Blocks]
xs, a
e)

-- | Parse a bullet list.
bulletListUntil :: PandocMonad m
                => MuseParser m a
                -> MuseParser m (F Blocks, a)
bulletListUntil :: MuseParser m a -> MuseParser m (F Blocks, a)
bulletListUntil MuseParser m a
end = MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a))
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall a b. (a -> b) -> a -> b
$ do
  Int
indent <- MuseParser m Int
forall (m :: * -> *). PandocMonad m => MuseParser m Int
getIndent
  Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ())
-> Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall a b. (a -> b) -> a -> b
$ Int
indent Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0
  ([F Blocks] -> F Blocks) -> ([F Blocks], a) -> (F Blocks, a)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (([Blocks] -> Blocks) -> Future MuseState [Blocks] -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Blocks] -> Blocks
B.bulletList (Future MuseState [Blocks] -> F Blocks)
-> ([F Blocks] -> Future MuseState [Blocks])
-> [F Blocks]
-> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Blocks] -> Future MuseState [Blocks]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence) (([F Blocks], a) -> (F Blocks, a))
-> ParsecT Text MuseState (ReaderT MuseEnv m) ([F Blocks], a)
-> MuseParser m (F Blocks, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> MuseParser m a
-> ParsecT Text MuseState (ReaderT MuseEnv m) ([F Blocks], a)
forall (m :: * -> *) a.
PandocMonad m =>
Int -> MuseParser m a -> MuseParser m ([F Blocks], a)
bulletListItemsUntil Int
indent MuseParser m a
end

museOrderedListMarker :: PandocMonad m
                      => ListNumberStyle
                      -> MuseParser m Int
museOrderedListMarker :: ListNumberStyle -> MuseParser m Int
museOrderedListMarker ListNumberStyle
style =
  (ListNumberStyle, Int) -> Int
forall a b. (a, b) -> b
snd ((ListNumberStyle, Int) -> Int)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
-> MuseParser m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall st.
ParserT Text st (ReaderT MuseEnv m) (ListNumberStyle, Int)
p MuseParser m Int
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'.'
  where p :: ParserT Text st (ReaderT MuseEnv m) (ListNumberStyle, Int)
p = case ListNumberStyle
style of
              ListNumberStyle
Decimal    -> ParserT Text st (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (ListNumberStyle, Int)
decimal
              ListNumberStyle
UpperRoman -> ParserT Text st (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (ListNumberStyle, Int)
upperRoman
              ListNumberStyle
LowerRoman -> ParserT Text st (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (ListNumberStyle, Int)
lowerRoman
              ListNumberStyle
UpperAlpha -> ParserT Text st (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (ListNumberStyle, Int)
upperAlpha
              ListNumberStyle
LowerAlpha -> ParserT Text st (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (ListNumberStyle, Int)
lowerAlpha
              ListNumberStyle
_          -> SourceName
-> ParserT Text st (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall (m :: * -> *) a. MonadFail m => SourceName -> m a
Prelude.fail SourceName
"Unhandled case"

orderedListItemsUntil :: PandocMonad m
                      => Int
                      -> ListNumberStyle
                      -> MuseParser m a
                      -> MuseParser m ([F Blocks], a)
orderedListItemsUntil :: Int
-> ListNumberStyle
-> MuseParser m a
-> MuseParser m ([F Blocks], a)
orderedListItemsUntil Int
indent ListNumberStyle
style MuseParser m a
end =
  MuseParser m ([F Blocks], a)
continuation
  where
    continuation :: MuseParser m ([F Blocks], a)
continuation = MuseParser m ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m ([F Blocks], a) -> MuseParser m ([F Blocks], a))
-> MuseParser m ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall a b. (a -> b) -> a -> b
$ do
      SourcePos
pos <- ParsecT Text MuseState (ReaderT MuseEnv m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
      ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol
      (F Blocks
x, ([F Blocks]
xs, a
e)) <- ParsecT
  Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
forall (m :: * -> *) a. MonadReader MuseEnv m => m a -> m a
allowPara (ParsecT
   Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
 -> ParsecT
      Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a)))
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
forall a b. (a -> b) -> a -> b
$ Int
-> MuseParser m ([F Blocks], a)
-> MuseParser m ([F Blocks], a)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
forall (m :: * -> *) a.
PandocMonad m =>
Int
-> MuseParser m a -> MuseParser m a -> MuseParser m (F Blocks, a)
listItemContentsUntil (SourcePos -> Int
sourceColumn SourcePos
pos) (MuseParser m ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) st.
(Stream s m Char, HasReaderOptions st) =>
Int -> ParserT s st m Text
indentWith Int
indent ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Int
-> ParsecT Text MuseState (ReaderT MuseEnv m) Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ListNumberStyle -> ParsecT Text MuseState (ReaderT MuseEnv m) Int
forall (m :: * -> *).
PandocMonad m =>
ListNumberStyle -> MuseParser m Int
museOrderedListMarker ListNumberStyle
style ParsecT Text MuseState (ReaderT MuseEnv m) Int
-> MuseParser m ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> MuseParser m ([F Blocks], a)
continuation)) (([],) (a -> ([F Blocks], a))
-> MuseParser m a -> MuseParser m ([F Blocks], a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m a
end)
      ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Blocks
xF Blocks -> [F Blocks] -> [F Blocks]
forall a. a -> [a] -> [a]
:[F Blocks]
xs, a
e)

-- | Parse an ordered list.
orderedListUntil :: PandocMonad m
                 => MuseParser m a
                 -> MuseParser m (F Blocks, a)
orderedListUntil :: MuseParser m a -> MuseParser m (F Blocks, a)
orderedListUntil MuseParser m a
end = MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a))
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall a b. (a -> b) -> a -> b
$ do
  Int
indent <- MuseParser m Int
forall (m :: * -> *). PandocMonad m => MuseParser m Int
getIndent
  Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ())
-> Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall a b. (a -> b) -> a -> b
$ Int
indent Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0
  (ListNumberStyle
style, Int
start) <- ParserT Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (ListNumberStyle, Int)
decimal ParserT Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
-> ParserT
     Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
-> ParserT
     Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (ListNumberStyle, Int)
lowerRoman ParserT Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
-> ParserT
     Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
-> ParserT
     Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (ListNumberStyle, Int)
upperRoman ParserT Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
-> ParserT
     Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
-> ParserT
     Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (ListNumberStyle, Int)
lowerAlpha ParserT Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
-> ParserT
     Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
-> ParserT
     Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text MuseState (ReaderT MuseEnv m) (ListNumberStyle, Int)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (ListNumberStyle, Int)
upperAlpha
  Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'.'
  ([F Blocks] -> F Blocks) -> ([F Blocks], a) -> (F Blocks, a)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (([Blocks] -> Blocks) -> Future MuseState [Blocks] -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ListAttributes -> [Blocks] -> Blocks
B.orderedListWith (Int
start, ListNumberStyle
style, ListNumberDelim
Period)) (Future MuseState [Blocks] -> F Blocks)
-> ([F Blocks] -> Future MuseState [Blocks])
-> [F Blocks]
-> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Blocks] -> Future MuseState [Blocks]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence)
    (([F Blocks], a) -> (F Blocks, a))
-> ParsecT Text MuseState (ReaderT MuseEnv m) ([F Blocks], a)
-> MuseParser m (F Blocks, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> ListNumberStyle
-> MuseParser m a
-> ParsecT Text MuseState (ReaderT MuseEnv m) ([F Blocks], a)
forall (m :: * -> *) a.
PandocMonad m =>
Int
-> ListNumberStyle
-> MuseParser m a
-> MuseParser m ([F Blocks], a)
orderedListItemsUntil Int
indent ListNumberStyle
style MuseParser m a
end

descriptionsUntil :: PandocMonad m
                  => Int
                  -> MuseParser m a
                  -> MuseParser m ([F Blocks], a)
descriptionsUntil :: Int -> MuseParser m a -> MuseParser m ([F Blocks], a)
descriptionsUntil Int
indent MuseParser m a
end = do
  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol
  (F Blocks
x, ([F Blocks]
xs, a
e)) <- ParsecT
  Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
forall (m :: * -> *) a. MonadReader MuseEnv m => m a -> m a
allowPara (ParsecT
   Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
 -> ParsecT
      Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a)))
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
forall a b. (a -> b) -> a -> b
$ Int
-> MuseParser m ([F Blocks], a)
-> MuseParser m ([F Blocks], a)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Blocks, ([F Blocks], a))
forall (m :: * -> *) a.
PandocMonad m =>
Int
-> MuseParser m a -> MuseParser m a -> MuseParser m (F Blocks, a)
listItemContentsUntil Int
indent (MuseParser m ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) st.
(Stream s m Char, HasReaderOptions st) =>
Int -> ParserT s st m Text
indentWith Int
indent ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar (SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"::") ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> MuseParser m a -> MuseParser m ([F Blocks], a)
forall (m :: * -> *) a.
PandocMonad m =>
Int -> MuseParser m a -> MuseParser m ([F Blocks], a)
descriptionsUntil Int
indent MuseParser m a
end)) (([],) (a -> ([F Blocks], a))
-> MuseParser m a -> MuseParser m ([F Blocks], a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m a
end)
  ([F Blocks], a) -> MuseParser m ([F Blocks], a)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Blocks
xF Blocks -> [F Blocks] -> [F Blocks]
forall a. a -> [a] -> [a]
:[F Blocks]
xs, a
e)

definitionListItemsUntil :: PandocMonad m
                         => Int
                         -> MuseParser m a
                         -> MuseParser m ([F (Inlines, [Blocks])], a)
definitionListItemsUntil :: Int -> MuseParser m a -> MuseParser m ([F (Inlines, [Blocks])], a)
definitionListItemsUntil Int
indent MuseParser m a
end =
  MuseParser m ([F (Inlines, [Blocks])], a)
continuation
  where
    continuation :: MuseParser m ([F (Inlines, [Blocks])], a)
continuation = MuseParser m ([F (Inlines, [Blocks])], a)
-> MuseParser m ([F (Inlines, [Blocks])], a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m ([F (Inlines, [Blocks])], a)
 -> MuseParser m ([F (Inlines, [Blocks])], a))
-> MuseParser m ([F (Inlines, [Blocks])], a)
-> MuseParser m ([F (Inlines, [Blocks])], a)
forall a b. (a -> b) -> a -> b
$ do
      SourcePos
pos <- ParsecT Text MuseState (ReaderT MuseEnv m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
      F Inlines
term <- F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline' (ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
 -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall a b. (a -> b) -> a -> b
$ SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"::")
      ([F Blocks]
x, ([F (Inlines, [Blocks])]
xs, a
e)) <- Int
-> MuseParser m ([F (Inlines, [Blocks])], a)
-> MuseParser m ([F Blocks], ([F (Inlines, [Blocks])], a))
forall (m :: * -> *) a.
PandocMonad m =>
Int -> MuseParser m a -> MuseParser m ([F Blocks], a)
descriptionsUntil (SourcePos -> Int
sourceColumn SourcePos
pos) (MuseParser m ([F (Inlines, [Blocks])], a)
-> MuseParser m ([F (Inlines, [Blocks])], a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) st.
(Stream s m Char, HasReaderOptions st) =>
Int -> ParserT s st m Text
indentWith Int
indent ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> MuseParser m ([F (Inlines, [Blocks])], a)
-> MuseParser m ([F (Inlines, [Blocks])], a)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> MuseParser m ([F (Inlines, [Blocks])], a)
continuation) MuseParser m ([F (Inlines, [Blocks])], a)
-> MuseParser m ([F (Inlines, [Blocks])], a)
-> MuseParser m ([F (Inlines, [Blocks])], a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (([],) (a -> ([F (Inlines, [Blocks])], a))
-> MuseParser m a -> MuseParser m ([F (Inlines, [Blocks])], a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m a
end))
      let xx :: F (Inlines, [Blocks])
xx = (,) (Inlines -> [Blocks] -> (Inlines, [Blocks]))
-> F Inlines -> Future MuseState ([Blocks] -> (Inlines, [Blocks]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
term Future MuseState ([Blocks] -> (Inlines, [Blocks]))
-> Future MuseState [Blocks] -> F (Inlines, [Blocks])
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [F Blocks] -> Future MuseState [Blocks]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [F Blocks]
x
      ([F (Inlines, [Blocks])], a)
-> MuseParser m ([F (Inlines, [Blocks])], a)
forall (m :: * -> *) a. Monad m => a -> m a
return (F (Inlines, [Blocks])
xxF (Inlines, [Blocks])
-> [F (Inlines, [Blocks])] -> [F (Inlines, [Blocks])]
forall a. a -> [a] -> [a]
:[F (Inlines, [Blocks])]
xs, a
e)

-- | Parse a definition list.
definitionListUntil :: PandocMonad m
                    => MuseParser m a -- ^ Terminator parser
                    -> MuseParser m (F Blocks, a)
definitionListUntil :: MuseParser m a -> MuseParser m (F Blocks, a)
definitionListUntil MuseParser m a
end = MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a))
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall a b. (a -> b) -> a -> b
$ do
  Int
indent <- MuseParser m Int
forall (m :: * -> *). PandocMonad m => MuseParser m Int
getIndent
  Extension -> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardDisabled Extension
Ext_amuse ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool -> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Int
indent Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0) -- Initial space is required by Amusewiki, but not Emacs Muse
  ([F (Inlines, [Blocks])] -> F Blocks)
-> ([F (Inlines, [Blocks])], a) -> (F Blocks, a)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (([(Inlines, [Blocks])] -> Blocks)
-> Future MuseState [(Inlines, [Blocks])] -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(Inlines, [Blocks])] -> Blocks
B.definitionList (Future MuseState [(Inlines, [Blocks])] -> F Blocks)
-> ([F (Inlines, [Blocks])]
    -> Future MuseState [(Inlines, [Blocks])])
-> [F (Inlines, [Blocks])]
-> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F (Inlines, [Blocks])] -> Future MuseState [(Inlines, [Blocks])]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence) (([F (Inlines, [Blocks])], a) -> (F Blocks, a))
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F (Inlines, [Blocks])], a)
-> MuseParser m (F Blocks, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> MuseParser m a
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F (Inlines, [Blocks])], a)
forall (m :: * -> *) a.
PandocMonad m =>
Int -> MuseParser m a -> MuseParser m ([F (Inlines, [Blocks])], a)
definitionListItemsUntil Int
indent MuseParser m a
end

anyListUntil :: PandocMonad m
             => MuseParser m a -- ^ Terminator parser
             -> MuseParser m (F Blocks, a)
anyListUntil :: MuseParser m a -> MuseParser m (F Blocks, a)
anyListUntil MuseParser m a
end =
  MuseParser m a -> MuseParser m (F Blocks, a)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks, a)
bulletListUntil MuseParser m a
end MuseParser m (F Blocks, a)
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m a -> MuseParser m (F Blocks, a)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks, a)
orderedListUntil MuseParser m a
end MuseParser m (F Blocks, a)
-> MuseParser m (F Blocks, a) -> MuseParser m (F Blocks, a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m a -> MuseParser m (F Blocks, a)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks, a)
definitionListUntil MuseParser m a
end

-- *** Table parsers

-- | Internal Muse table representation.
data MuseTable = MuseTable
  { MuseTable -> Inlines
museTableCaption :: Inlines
  , MuseTable -> [[Blocks]]
museTableHeaders :: [[Blocks]]
  , MuseTable -> [[Blocks]]
museTableRows    :: [[Blocks]]
  , MuseTable -> [[Blocks]]
museTableFooters :: [[Blocks]]
  }

data MuseTableElement = MuseHeaderRow [Blocks]
                      | MuseBodyRow [Blocks]
                      | MuseFooterRow [Blocks]
                      | MuseCaption Inlines

museToPandocTable :: MuseTable -> Blocks
museToPandocTable :: MuseTable -> Blocks
museToPandocTable (MuseTable Inlines
caption [[Blocks]]
headers [[Blocks]]
body [[Blocks]]
footers) =
  Caption
-> [ColSpec] -> TableHead -> [TableBody] -> TableFoot -> Blocks
B.table (Blocks -> Caption
B.simpleCaption (Blocks -> Caption) -> Blocks -> Caption
forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
B.plain Inlines
caption)
          [ColSpec]
attrs
          (Attr -> [Row] -> TableHead
TableHead Attr
nullAttr ([Row] -> TableHead) -> [Row] -> TableHead
forall a b. (a -> b) -> a -> b
$ [Blocks] -> [Row]
toHeaderRow [Blocks]
headRow)
          [Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody Attr
nullAttr RowHeadColumns
0 [] ([Row] -> TableBody) -> [Row] -> TableBody
forall a b. (a -> b) -> a -> b
$ ([Blocks] -> Row) -> [[Blocks]] -> [Row]
forall a b. (a -> b) -> [a] -> [b]
map [Blocks] -> Row
toRow ([[Blocks]] -> [Row]) -> [[Blocks]] -> [Row]
forall a b. (a -> b) -> a -> b
$ [[Blocks]]
rows [[Blocks]] -> [[Blocks]] -> [[Blocks]]
forall a. [a] -> [a] -> [a]
++ [[Blocks]]
body [[Blocks]] -> [[Blocks]] -> [[Blocks]]
forall a. [a] -> [a] -> [a]
++ [[Blocks]]
footers]
          (Attr -> [Row] -> TableFoot
TableFoot Attr
nullAttr [])
  where attrs :: [ColSpec]
attrs = (Alignment
AlignDefault, ColWidth
ColWidthDefault) ColSpec -> [[Blocks]] -> [ColSpec]
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [[Blocks]] -> [[Blocks]]
forall a. [[a]] -> [[a]]
transpose ([[Blocks]]
headers [[Blocks]] -> [[Blocks]] -> [[Blocks]]
forall a. [a] -> [a] -> [a]
++ [[Blocks]]
body [[Blocks]] -> [[Blocks]] -> [[Blocks]]
forall a. [a] -> [a] -> [a]
++ [[Blocks]]
footers)
        ([Blocks]
headRow, [[Blocks]]
rows) = ([Blocks], [[Blocks]])
-> Maybe ([Blocks], [[Blocks]]) -> ([Blocks], [[Blocks]])
forall a. a -> Maybe a -> a
fromMaybe ([], []) (Maybe ([Blocks], [[Blocks]]) -> ([Blocks], [[Blocks]]))
-> Maybe ([Blocks], [[Blocks]]) -> ([Blocks], [[Blocks]])
forall a b. (a -> b) -> a -> b
$ [[Blocks]] -> Maybe ([Blocks], [[Blocks]])
forall a. [a] -> Maybe (a, [a])
uncons [[Blocks]]
headers
        toRow :: [Blocks] -> Row
toRow = Attr -> [Cell] -> Row
Row Attr
nullAttr ([Cell] -> Row) -> ([Blocks] -> [Cell]) -> [Blocks] -> Row
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Blocks -> Cell) -> [Blocks] -> [Cell]
forall a b. (a -> b) -> [a] -> [b]
map Blocks -> Cell
B.simpleCell
        toHeaderRow :: [Blocks] -> [Row]
toHeaderRow [Blocks]
l = [[Blocks] -> Row
toRow [Blocks]
l | Bool -> Bool
not ([Blocks] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Blocks]
l)]

museAppendElement :: MuseTableElement
                  -> MuseTable
                  -> MuseTable
museAppendElement :: MuseTableElement -> MuseTable -> MuseTable
museAppendElement MuseTableElement
element MuseTable
tbl =
  case MuseTableElement
element of
    MuseHeaderRow [Blocks]
row -> MuseTable
tbl{ museTableHeaders :: [[Blocks]]
museTableHeaders = [Blocks]
row [Blocks] -> [[Blocks]] -> [[Blocks]]
forall a. a -> [a] -> [a]
: MuseTable -> [[Blocks]]
museTableHeaders MuseTable
tbl }
    MuseBodyRow [Blocks]
row -> MuseTable
tbl{ museTableRows :: [[Blocks]]
museTableRows = [Blocks]
row [Blocks] -> [[Blocks]] -> [[Blocks]]
forall a. a -> [a] -> [a]
: MuseTable -> [[Blocks]]
museTableRows MuseTable
tbl }
    MuseFooterRow [Blocks]
row -> MuseTable
tbl{ museTableFooters :: [[Blocks]]
museTableFooters = [Blocks]
row [Blocks] -> [[Blocks]] -> [[Blocks]]
forall a. a -> [a] -> [a]
: MuseTable -> [[Blocks]]
museTableFooters MuseTable
tbl }
    MuseCaption Inlines
inlines -> MuseTable
tbl{ museTableCaption :: Inlines
museTableCaption = Inlines
inlines }

tableElements :: PandocMonad m => MuseParser m (F [MuseTableElement])
tableElements :: MuseParser m (F [MuseTableElement])
tableElements = [Future MuseState MuseTableElement] -> F [MuseTableElement]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([Future MuseState MuseTableElement] -> F [MuseTableElement])
-> ParsecT
     Text
     MuseState
     (ReaderT MuseEnv m)
     [Future MuseState MuseTableElement]
-> MuseParser m (F [MuseTableElement])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  Text
  MuseState
  (ReaderT MuseEnv m)
  (Future MuseState MuseTableElement)
-> ParsecT
     Text
     MuseState
     (ReaderT MuseEnv m)
     [Future MuseState MuseTableElement]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT
  Text
  MuseState
  (ReaderT MuseEnv m)
  (Future MuseState MuseTableElement)
forall (m :: * -> *).
PandocMonad m =>
MuseParser m (Future MuseState MuseTableElement)
tableParseElement

elementsToTable :: [MuseTableElement] -> MuseTable
elementsToTable :: [MuseTableElement] -> MuseTable
elementsToTable = (MuseTableElement -> MuseTable -> MuseTable)
-> MuseTable -> [MuseTableElement] -> MuseTable
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr MuseTableElement -> MuseTable -> MuseTable
museAppendElement MuseTable
emptyTable
  where emptyTable :: MuseTable
emptyTable = Inlines -> [[Blocks]] -> [[Blocks]] -> [[Blocks]] -> MuseTable
MuseTable Inlines
forall a. Monoid a => a
mempty [[Blocks]]
forall a. Monoid a => a
mempty [[Blocks]]
forall a. Monoid a => a
mempty [[Blocks]]
forall a. Monoid a => a
mempty

museGridPart :: PandocMonad m => MuseParser m Int
museGridPart :: MuseParser m Int
museGridPart = MuseParser m Int -> MuseParser m Int
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m Int -> MuseParser m Int)
-> MuseParser m Int -> MuseParser m Int
forall a b. (a -> b) -> a -> b
$ SourceName -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (SourceName -> Int)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'-') MuseParser m Int
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'+'

museGridTableHeader :: PandocMonad m => MuseParser m [Int]
museGridTableHeader :: MuseParser m [Int]
museGridTableHeader = MuseParser m [Int] -> MuseParser m [Int]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m [Int] -> MuseParser m [Int])
-> MuseParser m [Int] -> MuseParser m [Int]
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'+' ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m [Int] -> MuseParser m [Int]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text MuseState (ReaderT MuseEnv m) Int
-> MuseParser m [Int]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Text MuseState (ReaderT MuseEnv m) Int
forall (m :: * -> *). PandocMonad m => MuseParser m Int
museGridPart MuseParser m [Int]
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m [Int]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol

museGridTableRow :: PandocMonad m
                 => Int
                 -> [Int]
                 -> MuseParser m (F [Blocks])
museGridTableRow :: Int -> [Int] -> MuseParser m (Future MuseState [Blocks])
museGridTableRow Int
indent [Int]
indices = MuseParser m (Future MuseState [Blocks])
-> MuseParser m (Future MuseState [Blocks])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (Future MuseState [Blocks])
 -> MuseParser m (Future MuseState [Blocks]))
-> MuseParser m (Future MuseState [Blocks])
-> MuseParser m (Future MuseState [Blocks])
forall a b. (a -> b) -> a -> b
$ do
  [[Text]]
lns <- ParsecT Text MuseState (ReaderT MuseEnv m) [Text]
-> ParsecT Text MuseState (ReaderT MuseEnv m) [[Text]]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Text MuseState (ReaderT MuseEnv m) [Text]
 -> ParsecT Text MuseState (ReaderT MuseEnv m) [[Text]])
-> ParsecT Text MuseState (ReaderT MuseEnv m) [Text]
-> ParsecT Text MuseState (ReaderT MuseEnv m) [[Text]]
forall a b. (a -> b) -> a -> b
$ ParsecT Text MuseState (ReaderT MuseEnv m) [Text]
-> ParsecT Text MuseState (ReaderT MuseEnv m) [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Int -> ParserT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) st.
(Stream s m Char, HasReaderOptions st) =>
Int -> ParserT s st m Text
indentWith Int
indent ParserT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) [Text]
-> ParsecT Text MuseState (ReaderT MuseEnv m) [Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [Int] -> ParsecT Text MuseState (ReaderT MuseEnv m) [Text]
forall (m :: * -> *). PandocMonad m => [Int] -> MuseParser m [Text]
museGridTableRawLine [Int]
indices)
  let cols :: [Text]
cols = ([Text] -> Text) -> [[Text]] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map ([Text] -> Text
T.unlines ([Text] -> Text) -> ([Text] -> [Text]) -> [Text] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Text
trimr) ([[Text]] -> [Text]) -> [[Text]] -> [Text]
forall a b. (a -> b) -> a -> b
$ [[Text]] -> [[Text]]
forall a. [[a]] -> [[a]]
transpose [[Text]]
lns
  Int -> ParserT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) st.
(Stream s m Char, HasReaderOptions st) =>
Int -> ParserT s st m Text
indentWith Int
indent ParserT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) [Int]
-> ParsecT Text MuseState (ReaderT MuseEnv m) [Int]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text MuseState (ReaderT MuseEnv m) [Int]
forall (m :: * -> *). PandocMonad m => MuseParser m [Int]
museGridTableHeader
  [F Blocks] -> Future MuseState [Blocks]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([F Blocks] -> Future MuseState [Blocks])
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
-> MuseParser m (Future MuseState [Blocks])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks))
-> [Text] -> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
-> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
forall s (m :: * -> *) u a.
(Stream s m Char, IsString s, HasLastStrPosition u) =>
ParserT s u m a -> Text -> ParserT s u m a
parseFromString' ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Blocks)
parseBlocks) [Text]
cols

museGridTableRawLine :: PandocMonad m
                     => [Int]
                     -> MuseParser m [Text]
museGridTableRawLine :: [Int] -> MuseParser m [Text]
museGridTableRawLine [Int]
indices =
  Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|' ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m [Text] -> MuseParser m [Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [Int]
-> (Int -> ParsecT Text MuseState (ReaderT MuseEnv m) Text)
-> MuseParser m [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Int]
indices (\Int
n -> Int
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) st.
(Stream s m Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
n ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|') MuseParser m [Text]
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m [Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol

museGridTable :: PandocMonad m => MuseParser m (F Blocks)
museGridTable :: MuseParser m (F Blocks)
museGridTable = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ do
  Int
indent <- MuseParser m Int
forall (m :: * -> *). PandocMonad m => MuseParser m Int
getIndent
  [Int]
indices <- MuseParser m [Int]
forall (m :: * -> *). PandocMonad m => MuseParser m [Int]
museGridTableHeader
  ([[Blocks]] -> Blocks) -> Future MuseState [[Blocks]] -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [[Blocks]] -> Blocks
rowsToTable (Future MuseState [[Blocks]] -> F Blocks)
-> ([Future MuseState [Blocks]] -> Future MuseState [[Blocks]])
-> [Future MuseState [Blocks]]
-> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Future MuseState [Blocks]] -> Future MuseState [[Blocks]]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([Future MuseState [Blocks]] -> F Blocks)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) [Future MuseState [Blocks]]
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  Text MuseState (ReaderT MuseEnv m) (Future MuseState [Blocks])
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) [Future MuseState [Blocks]]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (Int
-> [Int]
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Future MuseState [Blocks])
forall (m :: * -> *).
PandocMonad m =>
Int -> [Int] -> MuseParser m (Future MuseState [Blocks])
museGridTableRow Int
indent [Int]
indices)
  where rowsToTable :: [[Blocks]] -> Blocks
rowsToTable [[Blocks]]
rows = Caption
-> [ColSpec] -> TableHead -> [TableBody] -> TableFoot -> Blocks
B.table Caption
B.emptyCaption
                                   [ColSpec]
attrs
                                   (Attr -> [Row] -> TableHead
TableHead Attr
nullAttr [])
                                   [Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody Attr
nullAttr RowHeadColumns
0 [] ([Row] -> TableBody) -> [Row] -> TableBody
forall a b. (a -> b) -> a -> b
$ ([Blocks] -> Row) -> [[Blocks]] -> [Row]
forall a b. (a -> b) -> [a] -> [b]
map [Blocks] -> Row
toRow [[Blocks]]
rows]
                                   (Attr -> [Row] -> TableFoot
TableFoot Attr
nullAttr [])
                           where attrs :: [ColSpec]
attrs = (Alignment
AlignDefault, ColWidth
ColWidthDefault) ColSpec -> [[Blocks]] -> [ColSpec]
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [[Blocks]] -> [[Blocks]]
forall a. [[a]] -> [[a]]
transpose [[Blocks]]
rows
                                 toRow :: [Blocks] -> Row
toRow = Attr -> [Cell] -> Row
Row Attr
nullAttr ([Cell] -> Row) -> ([Blocks] -> [Cell]) -> [Blocks] -> Row
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Blocks -> Cell) -> [Blocks] -> [Cell]
forall a b. (a -> b) -> [a] -> [b]
map Blocks -> Cell
B.simpleCell

-- | Parse a table.
table :: PandocMonad m => MuseParser m (F Blocks)
table :: MuseParser m (F Blocks)
table = MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Blocks) -> MuseParser m (F Blocks))
-> MuseParser m (F Blocks) -> MuseParser m (F Blocks)
forall a b. (a -> b) -> a -> b
$ ([MuseTableElement] -> Blocks) -> F [MuseTableElement] -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (MuseTable -> Blocks
museToPandocTable (MuseTable -> Blocks)
-> ([MuseTableElement] -> MuseTable)
-> [MuseTableElement]
-> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [MuseTableElement] -> MuseTable
elementsToTable) (F [MuseTableElement] -> F Blocks)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F [MuseTableElement])
-> MuseParser m (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) (F [MuseTableElement])
forall (m :: * -> *).
PandocMonad m =>
MuseParser m (F [MuseTableElement])
tableElements

tableParseElement :: PandocMonad m => MuseParser m (F MuseTableElement)
tableParseElement :: MuseParser m (Future MuseState MuseTableElement)
tableParseElement = MuseParser m (Future MuseState MuseTableElement)
forall (m :: * -> *).
PandocMonad m =>
MuseParser m (Future MuseState MuseTableElement)
tableParseHeader
                MuseParser m (Future MuseState MuseTableElement)
-> MuseParser m (Future MuseState MuseTableElement)
-> MuseParser m (Future MuseState MuseTableElement)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (Future MuseState MuseTableElement)
forall (m :: * -> *).
PandocMonad m =>
MuseParser m (Future MuseState MuseTableElement)
tableParseBody
                MuseParser m (Future MuseState MuseTableElement)
-> MuseParser m (Future MuseState MuseTableElement)
-> MuseParser m (Future MuseState MuseTableElement)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (Future MuseState MuseTableElement)
forall (m :: * -> *).
PandocMonad m =>
MuseParser m (Future MuseState MuseTableElement)
tableParseFooter
                MuseParser m (Future MuseState MuseTableElement)
-> MuseParser m (Future MuseState MuseTableElement)
-> MuseParser m (Future MuseState MuseTableElement)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (Future MuseState MuseTableElement)
forall (m :: * -> *).
PandocMonad m =>
MuseParser m (Future MuseState MuseTableElement)
tableParseCaption

tableParseRow :: PandocMonad m
              => Int -- ^ Number of separator characters
              -> MuseParser m (F [Blocks])
tableParseRow :: Int -> MuseParser m (Future MuseState [Blocks])
tableParseRow Int
n = MuseParser m (Future MuseState [Blocks])
-> MuseParser m (Future MuseState [Blocks])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (Future MuseState [Blocks])
 -> MuseParser m (Future MuseState [Blocks]))
-> MuseParser m (Future MuseState [Blocks])
-> MuseParser m (Future MuseState [Blocks])
forall a b. (a -> b) -> a -> b
$ [F Blocks] -> Future MuseState [Blocks]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([F Blocks] -> Future MuseState [Blocks])
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
-> MuseParser m (Future MuseState [Blocks])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
tableCells
  where tableCells :: ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
tableCells = (:) (F Blocks -> [F Blocks] -> [F Blocks])
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F Blocks] -> [F Blocks])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks)
tableCell ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall u. ParsecT Text u (ReaderT MuseEnv m) ()
sep ParsecT
  Text MuseState (ReaderT MuseEnv m) ([F Blocks] -> [F Blocks])
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
tableCells ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (F Blocks -> [F Blocks])
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Blocks]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap F Blocks -> [F Blocks]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
forall (m :: * -> *) a.
PandocMonad m =>
MuseParser m a -> MuseParser m (F Blocks)
tableCell ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol))
        tableCell :: ParsecT Text MuseState (ReaderT MuseEnv m) end
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
tableCell ParsecT Text MuseState (ReaderT MuseEnv m) end
p = ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
 -> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks))
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
forall a b. (a -> b) -> a -> b
$ (Inlines -> Blocks) -> F Inlines -> F Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Blocks
B.plain (F Inlines -> F Blocks)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Blocks)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> ParsecT Text MuseState (ReaderT MuseEnv m) (F Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) end
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline' ParsecT Text MuseState (ReaderT MuseEnv m) end
p
        sep :: ParsecT Text u (ReaderT MuseEnv m) ()
sep = ParsecT Text u (ReaderT MuseEnv m) ()
-> ParsecT Text u (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u (ReaderT MuseEnv m) ()
 -> ParsecT Text u (ReaderT MuseEnv m) ())
-> ParsecT Text u (ReaderT MuseEnv m) ()
-> ParsecT Text u (ReaderT MuseEnv m) ()
forall a b. (a -> b) -> a -> b
$ ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text u (ReaderT MuseEnv m) SourceName
-> ParsecT Text u (ReaderT MuseEnv m) SourceName
-> ParsecT Text u (ReaderT MuseEnv m) SourceName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int
-> ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
n (Char -> ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|') ParsecT Text u (ReaderT MuseEnv m) SourceName
-> ParsecT Text u (ReaderT MuseEnv m) ()
-> ParsecT Text u (ReaderT MuseEnv m) ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text u (ReaderT MuseEnv m) ()
-> ParsecT Text u (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Text u (ReaderT MuseEnv m) SourceName
-> ParsecT Text u (ReaderT MuseEnv m) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar) ParsecT Text u (ReaderT MuseEnv m) ()
-> ParsecT Text u (ReaderT MuseEnv m) ()
-> ParsecT Text u (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text u (ReaderT MuseEnv m) ()
-> ParsecT Text u (ReaderT MuseEnv m) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Text u (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol)

-- | Parse a table header row.
tableParseHeader :: PandocMonad m => MuseParser m (F MuseTableElement)
tableParseHeader :: MuseParser m (Future MuseState MuseTableElement)
tableParseHeader = ([Blocks] -> MuseTableElement)
-> Future MuseState [Blocks] -> Future MuseState MuseTableElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Blocks] -> MuseTableElement
MuseHeaderRow (Future MuseState [Blocks] -> Future MuseState MuseTableElement)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Future MuseState [Blocks])
-> MuseParser m (Future MuseState MuseTableElement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Future MuseState [Blocks])
forall (m :: * -> *).
PandocMonad m =>
Int -> MuseParser m (Future MuseState [Blocks])
tableParseRow Int
2

-- | Parse a table body row.
tableParseBody :: PandocMonad m => MuseParser m (F MuseTableElement)
tableParseBody :: MuseParser m (Future MuseState MuseTableElement)
tableParseBody = ([Blocks] -> MuseTableElement)
-> Future MuseState [Blocks] -> Future MuseState MuseTableElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Blocks] -> MuseTableElement
MuseBodyRow (Future MuseState [Blocks] -> Future MuseState MuseTableElement)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Future MuseState [Blocks])
-> MuseParser m (Future MuseState MuseTableElement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Future MuseState [Blocks])
forall (m :: * -> *).
PandocMonad m =>
Int -> MuseParser m (Future MuseState [Blocks])
tableParseRow Int
1

-- | Parse a table footer row.
tableParseFooter :: PandocMonad m => MuseParser m (F MuseTableElement)
tableParseFooter :: MuseParser m (Future MuseState MuseTableElement)
tableParseFooter = ([Blocks] -> MuseTableElement)
-> Future MuseState [Blocks] -> Future MuseState MuseTableElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Blocks] -> MuseTableElement
MuseFooterRow (Future MuseState [Blocks] -> Future MuseState MuseTableElement)
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Future MuseState [Blocks])
-> MuseParser m (Future MuseState MuseTableElement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Future MuseState [Blocks])
forall (m :: * -> *).
PandocMonad m =>
Int -> MuseParser m (Future MuseState [Blocks])
tableParseRow Int
3

-- | Parse table caption.
tableParseCaption :: PandocMonad m => MuseParser m (F MuseTableElement)
tableParseCaption :: MuseParser m (Future MuseState MuseTableElement)
tableParseCaption = MuseParser m (Future MuseState MuseTableElement)
-> MuseParser m (Future MuseState MuseTableElement)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (Future MuseState MuseTableElement)
 -> MuseParser m (Future MuseState MuseTableElement))
-> MuseParser m (Future MuseState MuseTableElement)
-> MuseParser m (Future MuseState MuseTableElement)
forall a b. (a -> b) -> a -> b
$ (Inlines -> MuseTableElement)
-> F Inlines -> Future MuseState MuseTableElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> MuseTableElement
MuseCaption (F Inlines -> Future MuseState MuseTableElement)
-> ([F Inlines] -> F Inlines)
-> [F Inlines]
-> Future MuseState MuseTableElement
forall b c a. (b -> c) -> (a -> b) -> a -> c
. F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat
  ([F Inlines] -> Future MuseState MuseTableElement)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT
     Text
     MuseState
     (ReaderT MuseEnv m)
     ([F Inlines] -> Future MuseState MuseTableElement)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
  ParsecT
  Text
  MuseState
  (ReaderT MuseEnv m)
  ([F Inlines] -> Future MuseState MuseTableElement)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT
     Text
     MuseState
     (ReaderT MuseEnv m)
     ([F Inlines] -> Future MuseState MuseTableElement)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"|+"
  ParsecT
  Text
  MuseState
  (ReaderT MuseEnv m)
  ([F Inlines] -> Future MuseState MuseTableElement)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> MuseParser m (Future MuseState MuseTableElement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParserT Text MuseState (ReaderT MuseEnv m) (F Inlines)
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till ParserT Text MuseState (ReaderT MuseEnv m) (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline (ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParserT Text MuseState (ReaderT MuseEnv m) ()
 -> ParserT Text MuseState (ReaderT MuseEnv m) ())
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall a b. (a -> b) -> a -> b
$ SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"+|" ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
eol)

-- ** Inline parsers

inline' :: PandocMonad m => MuseParser m (F Inlines)
inline' :: MuseParser m (F Inlines)
inline' = MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
whitespace
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
br
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
anchor
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
footnote
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
strongEmph
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
strong
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
strongTag
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
emph
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
emphTag
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
underlined
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
superscriptTag
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
subscriptTag
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
strikeoutTag
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
verbatimTag
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
classTag
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inlineRtl
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inlineLtr
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
nbsp
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
linkOrImage
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
code
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
codeTag
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
mathTag
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inlineLiteralTag
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
str
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
asterisks
      MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
symbol
      MuseParser m (F Inlines) -> SourceName -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> SourceName -> ParsecT s u m a
<?> SourceName
"inline"

inline :: PandocMonad m => MuseParser m (F Inlines)
inline :: MuseParser m (F Inlines)
inline = MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
endline MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline'

-- | Parse a soft break.
endline :: PandocMonad m => MuseParser m (F Inlines)
endline :: MuseParser m (F Inlines)
endline = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
B.softbreak F Inlines
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline MuseParser m (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline MuseParser m (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). Monad m => MuseParser m ()
updateLastSpacePos

parseAnchor :: PandocMonad m => MuseParser m Text
parseAnchor :: MuseParser m Text
parseAnchor = MuseParser m Text -> MuseParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m Text -> MuseParser m Text)
-> MuseParser m Text -> MuseParser m Text
forall a b. (a -> b) -> a -> b
$ Char -> Text -> Text
T.cons
  (Char -> Text -> Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Char -> Text -> Text)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => MuseParser m ()
firstColumn
  ParsecT Text MuseState (ReaderT MuseEnv m) (Char -> Text -> Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (Char -> Text -> Text)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'#'
  ParsecT Text MuseState (ReaderT MuseEnv m) (Char -> Text -> Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Text)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter
  ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Text)
-> MuseParser m Text -> MuseParser m Text
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
manyChar (ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'-')

anchor :: PandocMonad m => MuseParser m (F Inlines)
anchor :: MuseParser m (F Inlines)
anchor = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
  Text
anchorId <- MuseParser m Text
forall (m :: * -> *). PandocMonad m => MuseParser m Text
parseAnchor
  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline
  F Inlines -> MuseParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> MuseParser m (F Inlines))
-> F Inlines -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Attr -> Inlines -> Inlines
B.spanWith (Text
anchorId, [], []) Inlines
forall a. Monoid a => a
mempty

-- | Parse a footnote reference.
footnote :: PandocMonad m => MuseParser m (F Inlines)
footnote :: MuseParser m (F Inlines)
footnote = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
  Bool
inLink <- (MuseEnv -> Bool)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks MuseEnv -> Bool
museInLink
  Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ())
-> Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not Bool
inLink
  Text
ref <- MuseParser m Text
forall (m :: * -> *). PandocMonad m => MuseParser m Text
noteMarker
  F Inlines -> MuseParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> MuseParser m (F Inlines))
-> F Inlines -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
    Map Text (SourcePos, F Blocks)
notes <- (MuseState -> Map Text (SourcePos, F Blocks))
-> Future MuseState (Map Text (SourcePos, F Blocks))
forall s a. (s -> a) -> Future s a
asksF MuseState -> Map Text (SourcePos, F Blocks)
museNotes
    case Text
-> Map Text (SourcePos, F Blocks) -> Maybe (SourcePos, F Blocks)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
ref Map Text (SourcePos, F Blocks)
notes of
      Maybe (SourcePos, F Blocks)
Nothing -> Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
ref
      Just (SourcePos
_pos, F Blocks
contents) -> do
        MuseState
st <- Future MuseState MuseState
forall s. Future s s
askF
        let contents' :: Blocks
contents' = F Blocks -> MuseState -> Blocks
forall s a. Future s a -> s -> a
runF F Blocks
contents MuseState
st { museNotes :: Map Text (SourcePos, F Blocks)
museNotes = Text
-> Map Text (SourcePos, F Blocks) -> Map Text (SourcePos, F Blocks)
forall k a. Ord k => k -> Map k a -> Map k a
M.delete Text
ref (MuseState -> Map Text (SourcePos, F Blocks)
museNotes MuseState
st) }
        Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Blocks -> Inlines
B.note Blocks
contents'

whitespace :: PandocMonad m => MuseParser m (F Inlines)
whitespace :: MuseParser m (F Inlines)
whitespace = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
B.space F Inlines
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar MuseParser m (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). Monad m => MuseParser m ()
updateLastSpacePos

-- | Parse @\<br>@ tag.
br :: PandocMonad m => MuseParser m (F Inlines)
br :: MuseParser m (F Inlines)
br = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
B.linebreak F Inlines
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<br>"

emphasisBetween :: (PandocMonad m, Show a)
                => MuseParser m a
                -> MuseParser m (F Inlines)
emphasisBetween :: MuseParser m a -> MuseParser m (F Inlines)
emphasisBetween MuseParser m a
p = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat
  ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => MuseParser m ()
atStart
  ParsecT
  Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
-> MuseParser m a
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  MuseParser m a
p
  ParsecT
  Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
space
  ParsecT
  Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MuseParser m (F Inlines)
-> MuseParser m a
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline (MuseParser m a -> MuseParser m a
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m a -> MuseParser m a)
-> MuseParser m a -> MuseParser m a
forall a b. (a -> b) -> a -> b
$ ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => MuseParser m ()
noSpaceBefore ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m a -> MuseParser m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> MuseParser m a
p MuseParser m a
-> ParsecT Text MuseState (ReaderT MuseEnv m) () -> MuseParser m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum)

-- | Parse an inline tag, such as @\<em>@ and @\<strong>@.
inlineTag :: PandocMonad m
          => Text -- ^ Tag name
          -> MuseParser m (F Inlines)
inlineTag :: Text -> MuseParser m (F Inlines)
inlineTag Text
tag = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat
  ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  Text -> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m [(Text, Text)]
openTag Text
tag
  ParsecT
  Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MuseParser m (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline (Text -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => Text -> MuseParser m ()
closeTag Text
tag)

-- | Parse strong emphasis inline markup, indicated by @***@.
strongEmph :: PandocMonad m => MuseParser m (F Inlines)
strongEmph :: MuseParser m (F Inlines)
strongEmph = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Inlines -> Inlines
B.strong (Inlines -> Inlines) -> (Inlines -> Inlines) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.emph) (F Inlines -> F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m SourceName -> MuseParser m (F Inlines)
forall (m :: * -> *) a.
(PandocMonad m, Show a) =>
MuseParser m a -> MuseParser m (F Inlines)
emphasisBetween (SourceName -> MuseParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"***" MuseParser m SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m SourceName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'*'))

-- | Parse strong inline markup, indicated by @**@.
strong :: PandocMonad m => MuseParser m (F Inlines)
strong :: MuseParser m (F Inlines)
strong = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.strong (F Inlines -> F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m SourceName -> MuseParser m (F Inlines)
forall (m :: * -> *) a.
(PandocMonad m, Show a) =>
MuseParser m a -> MuseParser m (F Inlines)
emphasisBetween (SourceName -> MuseParser m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"**" MuseParser m SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m SourceName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'*'))

-- | Parse emphasis inline markup, indicated by @*@.
emph :: PandocMonad m => MuseParser m (F Inlines)
emph :: MuseParser m (F Inlines)
emph = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.emph (F Inlines -> F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m Char -> MuseParser m (F Inlines)
forall (m :: * -> *) a.
(PandocMonad m, Show a) =>
MuseParser m a -> MuseParser m (F Inlines)
emphasisBetween (Char -> MuseParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'*' MuseParser m Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* MuseParser m Char -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> MuseParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'*'))

-- | Parse underline inline markup, indicated by @_@.
-- Supported only in Emacs Muse mode, not Text::Amuse.
underlined :: PandocMonad m => MuseParser m (F Inlines)
underlined :: MuseParser m (F Inlines)
underlined = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
underline
  (F Inlines -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) (F Inlines -> F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  Extension -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardDisabled Extension
Ext_amuse -- Supported only by Emacs Muse
  ParsecT Text MuseState (ReaderT MuseEnv m) (F Inlines -> F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MuseParser m Char -> MuseParser m (F Inlines)
forall (m :: * -> *) a.
(PandocMonad m, Show a) =>
MuseParser m a -> MuseParser m (F Inlines)
emphasisBetween (Char -> MuseParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'_')

-- | Parse @\<strong>@ tag.
strongTag :: PandocMonad m => MuseParser m (F Inlines)
strongTag :: MuseParser m (F Inlines)
strongTag = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.strong (F Inlines -> F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> MuseParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (F Inlines)
inlineTag Text
"strong"

-- | Parse @\<em>@ tag.
emphTag :: PandocMonad m => MuseParser m (F Inlines)
emphTag :: MuseParser m (F Inlines)
emphTag = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.emph (F Inlines -> F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> MuseParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (F Inlines)
inlineTag Text
"em"

-- | Parse @\<sup>@ tag.
superscriptTag :: PandocMonad m => MuseParser m (F Inlines)
superscriptTag :: MuseParser m (F Inlines)
superscriptTag = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.superscript (F Inlines -> F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> MuseParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (F Inlines)
inlineTag Text
"sup"

-- | Parse @\<sub>@ tag.
subscriptTag :: PandocMonad m => MuseParser m (F Inlines)
subscriptTag :: MuseParser m (F Inlines)
subscriptTag = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.subscript (F Inlines -> F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> MuseParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (F Inlines)
inlineTag Text
"sub"

-- | Parse @\<del>@ tag.
strikeoutTag :: PandocMonad m => MuseParser m (F Inlines)
strikeoutTag :: MuseParser m (F Inlines)
strikeoutTag = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.strikeout (F Inlines -> F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> MuseParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (F Inlines)
inlineTag Text
"del"

-- | Parse @\<verbatim>@ tag.
verbatimTag :: PandocMonad m => MuseParser m (F Inlines)
verbatimTag :: MuseParser m (F Inlines)
verbatimTag = Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.text
  (Text -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  Text -> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m [(Text, Text)]
openTag Text
"verbatim"
  ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv 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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (Text -> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => Text -> MuseParser m ()
closeTag Text
"verbatim")

-- | Parse @\<class>@ tag.
classTag :: PandocMonad m => MuseParser m (F Inlines)
classTag :: MuseParser m (F Inlines)
classTag = do
  [Text]
classes <- [Text] -> (Text -> [Text]) -> Maybe Text -> [Text]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Text -> [Text]
T.words (Maybe Text -> [Text])
-> ([(Text, Text)] -> Maybe Text) -> [(Text, Text)] -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"name" ([(Text, Text)] -> [Text])
-> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
-> ParsecT Text MuseState (ReaderT MuseEnv m) [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m [(Text, Text)]
openTag Text
"class"
  (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Attr -> Inlines -> Inlines
B.spanWith (Text
"", [Text]
classes, [])) (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MuseParser m (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline (Text -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => Text -> MuseParser m ()
closeTag Text
"class")

-- | Parse @\<\<\<RTL>>>@ text.
inlineRtl :: PandocMonad m => MuseParser m (F Inlines)
inlineRtl :: MuseParser m (F Inlines)
inlineRtl = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$
  (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Attr -> Inlines -> Inlines
B.spanWith (Text
"", [], [(Text
"dir", Text
"rtl")])) (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<<<" ParsecT
  Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MuseParser m (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline (SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
">>>")

-- | Parse @\<\<\<LTR>>>@ text.
inlineLtr :: PandocMonad m => MuseParser m (F Inlines)
inlineLtr :: MuseParser m (F Inlines)
inlineLtr = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$
  (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Attr -> Inlines -> Inlines
B.spanWith (Text
"", [], [(Text
"dir", Text
"ltr")])) (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
">>>" ParsecT
  Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MuseParser m (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline (SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"<<<")

-- | Parse "~~" as nonbreaking space.
nbsp :: PandocMonad m => MuseParser m (F Inlines)
nbsp :: MuseParser m (F Inlines)
nbsp = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Inlines
B.str Text
"\160") F Inlines
-> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"~~"

-- | Parse code markup, indicated by @\'=\'@ characters.
code :: PandocMonad m => MuseParser m (F Inlines)
code :: MuseParser m (F Inlines)
code = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ (Inlines -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
 -> MuseParser m (F Inlines))
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
-> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.code (Text -> Inlines)
-> ((Text, Text) -> Text) -> (Text, Text) -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Text -> Text) -> (Text, Text) -> Text
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
(<>)
  ((Text, Text) -> Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ((Text, Text) -> Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => MuseParser m ()
atStart
  ParsecT
  Text MuseState (ReaderT MuseEnv m) ((Text, Text) -> Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ((Text, Text) -> Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'='
  ParsecT
  Text MuseState (ReaderT MuseEnv m) ((Text, Text) -> Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ((Text, Text) -> Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline)
  ParsecT
  Text MuseState (ReaderT MuseEnv m) ((Text, Text) -> Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text, Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text, Text)
forall s u (m :: * -> *) b.
ParserT s u m Char -> ParserT s u m b -> ParserT s u m (Text, b)
manyUntilChar (SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m Char
noneOf SourceName
"\n\r" ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline)) (ParserT Text MuseState (ReaderT MuseEnv m) Text
-> ParserT Text MuseState (ReaderT MuseEnv m) Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParserT Text MuseState (ReaderT MuseEnv m) Text
 -> ParserT Text MuseState (ReaderT MuseEnv m) Text)
-> ParserT Text MuseState (ReaderT MuseEnv m) Text
-> ParserT Text MuseState (ReaderT MuseEnv m) Text
forall a b. (a -> b) -> a -> b
$ (Char -> Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Char -> Text
T.singleton (ParsecT Text MuseState (ReaderT MuseEnv m) Char
 -> ParserT Text MuseState (ReaderT MuseEnv m) Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) Text
forall a b. (a -> b) -> a -> b
$ SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m Char
noneOf SourceName
" \t\n\r=" ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'=')
  ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum

-- | Parse @\<code>@ tag.
codeTag :: PandocMonad m => MuseParser m (F Inlines)
codeTag :: MuseParser m (F Inlines)
codeTag = (Inlines -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
 -> MuseParser m (F Inlines))
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
-> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Inlines
B.codeWith
  (Attr -> Text -> Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Attr
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([(Text, Text)] -> Attr
htmlAttrToPandoc ([(Text, Text)] -> Attr)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
-> ParsecT Text MuseState (ReaderT MuseEnv m) Attr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m [(Text, Text)]
openTag Text
"code")
  ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv 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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (Text -> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => Text -> MuseParser m ()
closeTag Text
"code")

-- | Parse @\<math>@ tag.
-- @\<math>@ tag is an Emacs Muse extension enabled by @(require 'muse-latex2png)@
mathTag :: PandocMonad m => MuseParser m (F Inlines)
mathTag :: MuseParser m (F Inlines)
mathTag = Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.math
  (Text -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  Text -> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m [(Text, Text)]
openTag Text
"math"
  ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv 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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (Text -> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => Text -> MuseParser m ()
closeTag Text
"math")

-- | Parse inline @\<literal>@ tag as a raw inline.
inlineLiteralTag :: PandocMonad m => MuseParser m (F Inlines)
inlineLiteralTag :: MuseParser m (F Inlines)
inlineLiteralTag = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ (Inlines -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
 -> MuseParser m (F Inlines))
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
-> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines
B.rawInline
  (Text -> Text -> Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"html" (Maybe Text -> Text)
-> ([(Text, Text)] -> Maybe Text) -> [(Text, Text)] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"style" ([(Text, Text)] -> Text)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) [(Text, Text)]
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m [(Text, Text)]
openTag Text
"literal") -- FIXME: Emacs Muse inserts <literal> without style into all output formats, but we assume HTML
  ParsecT Text MuseState (ReaderT MuseEnv m) (Text -> Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> ParsecT Text MuseState (ReaderT MuseEnv m) Inlines
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) ()
-> ParsecT Text MuseState (ReaderT MuseEnv 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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (Text -> ParserT Text MuseState (ReaderT MuseEnv m) ()
forall (m :: * -> *). PandocMonad m => Text -> MuseParser m ()
closeTag Text
"literal")

str :: PandocMonad m => MuseParser m (F Inlines)
str :: MuseParser m (F Inlines)
str = Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.str (Text -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParserT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum MuseParser m (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) ()
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall s (m :: * -> *) a st.
(Stream s m a, HasLastStrPosition st) =>
ParserT s st m ()
updateLastStrPos

-- | Consume asterisks that were not used as emphasis opening.
-- This prevents series of asterisks from being split into
-- literal asterisk and emphasis opening.
asterisks :: PandocMonad m => MuseParser m (F Inlines)
asterisks :: MuseParser m (F Inlines)
asterisks = Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.str (Text -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char (Char -> ParserT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'*')

symbol :: PandocMonad m => MuseParser m (F Inlines)
symbol :: MuseParser m (F Inlines)
symbol = Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Inlines -> F Inlines) -> (Char -> Inlines) -> Char -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.str (Text -> Inlines) -> (Char -> Text) -> Char -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton (Char -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
nonspaceChar

-- | Parse a link or image.
linkOrImage :: PandocMonad m => MuseParser m (F Inlines)
linkOrImage :: MuseParser m (F Inlines)
linkOrImage = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Text -> MuseParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (F Inlines)
link Text
"URL:" MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
image MuseParser m (F Inlines)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> MuseParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Text -> MuseParser m (F Inlines)
link Text
""

linkContent :: PandocMonad m => MuseParser m (F Inlines)
linkContent :: MuseParser m (F Inlines)
linkContent = F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat
  ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT
     Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'['
  ParsecT
  Text MuseState (ReaderT MuseEnv m) ([F Inlines] -> F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
-> MuseParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MuseParser m (F Inlines)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) [F Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
inline (Char -> ParsecT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']')

-- | Parse a link starting with (possibly null) prefix
link :: PandocMonad m => Text -> MuseParser m (F Inlines)
link :: Text -> MuseParser m (F Inlines)
link Text
prefix = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
  Bool
inLink <- (MuseEnv -> Bool)
-> ParsecT Text MuseState (ReaderT MuseEnv m) Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks MuseEnv -> Bool
museInLink
  Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ())
-> Bool -> ParsecT Text MuseState (ReaderT MuseEnv m) ()
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not Bool
inLink
  Text -> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr (Text -> ParsecT Text MuseState (ReaderT MuseEnv m) Text)
-> Text -> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall a b. (a -> b) -> a -> b
$ Text
"[[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
prefix
  Text
url <- ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv 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 MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParserT Text MuseState (ReaderT MuseEnv m) Char
 -> ParsecT Text MuseState (ReaderT MuseEnv m) Text)
-> ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParsecT Text MuseState (ReaderT MuseEnv m) Text
forall a b. (a -> b) -> a -> b
$ Char -> ParserT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']'
  F Inlines
content <- F Inlines -> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
url) ((MuseEnv -> MuseEnv)
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\MuseEnv
s -> MuseEnv
s { museInLink :: Bool
museInLink = Bool
True }) MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
linkContent)
  Char -> ParserT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']'
  F Inlines -> MuseParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> MuseParser m (F Inlines))
-> F Inlines -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link Text
url Text
"" (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
content

image :: PandocMonad m => MuseParser m (F Inlines)
image :: MuseParser m (F Inlines)
image = MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (MuseParser m (F Inlines) -> MuseParser m (F Inlines))
-> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
  SourceName -> ParsecT Text MuseState (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string SourceName
"[["
  (Text
url, (Text
ext, Maybe Text
width, Maybe Char
align)) <- ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT
     Text MuseState (ReaderT MuseEnv m) (Text, Maybe Text, Maybe Char)
-> ParserT
     Text
     MuseState
     (ReaderT MuseEnv m)
     (Text, (Text, Maybe Text, Maybe Char))
forall s u (m :: * -> *) b.
ParserT s u m Char -> ParserT s u m b -> ParserT s u m (Text, b)
manyUntilChar (SourceName -> ParserT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m Char
noneOf SourceName
"]") (ParserT
  Text MuseState (ReaderT MuseEnv m) (Text, Maybe Text, Maybe Char)
forall u.
ParsecT Text u (ReaderT MuseEnv m) (Text, Maybe Text, Maybe Char)
imageExtensionAndOptions ParserT
  Text MuseState (ReaderT MuseEnv m) (Text, Maybe Text, Maybe Char)
-> ParserT Text MuseState (ReaderT MuseEnv m) Char
-> ParserT
     Text MuseState (ReaderT MuseEnv m) (Text, Maybe Text, Maybe Char)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParserT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']')
  F Inlines
content <- F Inlines -> MuseParser m (F Inlines) -> MuseParser m (F Inlines)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option F Inlines
forall a. Monoid a => a
mempty MuseParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => MuseParser m (F Inlines)
linkContent
  Char -> ParserT Text MuseState (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']'
  let widthAttr :: [(Text, Text)]
widthAttr = case Maybe Char
align of
                    Just Char
'f' -> [(Text
"width", Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"100" Maybe Text
width Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"%"), (Text
"height", Text
"75%")]
                    Maybe Char
_ -> Maybe (Text, Text) -> [(Text, Text)]
forall a. Maybe a -> [a]
maybeToList ((Text
"width",) (Text -> (Text, Text)) -> (Text -> Text) -> Text -> (Text, Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"%") (Text -> (Text, Text)) -> Maybe Text -> Maybe (Text, Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
width)
  let alignClass :: [Text]
alignClass = case Maybe Char
align of
                     Just Char
'r' -> [Text
"align-right"]
                     Just Char
'l' -> [Text
"align-left"]
                     Just Char
'f' -> []
                     Maybe Char
_        -> []
  F Inlines -> MuseParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> MuseParser m (F Inlines))
-> F Inlines -> MuseParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Text -> Inlines -> Inlines
B.imageWith (Text
"", [Text]
alignClass, [(Text, Text)]
widthAttr) (Text
url Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ext) Text
forall a. Monoid a => a
mempty (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
content
  where -- Taken from muse-image-regexp defined in Emacs Muse file lisp/muse-regexps.el
        imageExtensions :: [Text]
imageExtensions = [Text
".eps", Text
".gif", Text
".jpg", Text
".jpeg", Text
".pbm", Text
".png", Text
".tiff", Text
".xbm", Text
".xpm"]
        imageExtension :: ParsecT Text u (ReaderT MuseEnv m) Text
imageExtension = [ParsecT Text u (ReaderT MuseEnv m) Text]
-> ParsecT Text u (ReaderT MuseEnv m) Text
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice (ParsecT Text u (ReaderT MuseEnv m) Text
-> ParsecT Text u (ReaderT MuseEnv m) Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u (ReaderT MuseEnv m) Text
 -> ParsecT Text u (ReaderT MuseEnv m) Text)
-> (Text -> ParsecT Text u (ReaderT MuseEnv m) Text)
-> Text
-> ParsecT Text u (ReaderT MuseEnv m) Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ParsecT Text u (ReaderT MuseEnv m) Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr (Text -> ParsecT Text u (ReaderT MuseEnv m) Text)
-> [Text] -> [ParsecT Text u (ReaderT MuseEnv m) Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Text]
imageExtensions)
        imageExtensionAndOptions :: ParsecT Text u (ReaderT MuseEnv m) (Text, Maybe Text, Maybe Char)
imageExtensionAndOptions = do
          Text
ext <- ParsecT Text u (ReaderT MuseEnv m) Text
forall u. ParsecT Text u (ReaderT MuseEnv m) Text
imageExtension
          (Maybe Text
width, Maybe Char
align) <- (Maybe Text, Maybe Char)
-> ParsecT Text u (ReaderT MuseEnv m) (Maybe Text, Maybe Char)
-> ParsecT Text u (ReaderT MuseEnv m) (Maybe Text, Maybe Char)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Maybe Text
forall a. Maybe a
Nothing, Maybe Char
forall a. Maybe a
Nothing) ParsecT Text u (ReaderT MuseEnv m) (Maybe Text, Maybe Char)
forall u.
ParsecT Text u (ReaderT MuseEnv m) (Maybe Text, Maybe Char)
imageAttrs
          (Text, Maybe Text, Maybe Char)
-> ParsecT
     Text u (ReaderT MuseEnv m) (Text, Maybe Text, Maybe Char)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
ext, Maybe Text
width, Maybe Char
align)
        imageAttrs :: ParsecT Text u (ReaderT MuseEnv m) (Maybe Text, Maybe Char)
imageAttrs = (,)
          (Maybe Text -> Maybe Char -> (Maybe Text, Maybe Char))
-> ParsecT Text u (ReaderT MuseEnv m) SourceName
-> ParsecT
     Text
     u
     (ReaderT MuseEnv m)
     (Maybe Text -> Maybe Char -> (Maybe Text, Maybe Char))
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv m) SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
          ParsecT
  Text
  u
  (ReaderT MuseEnv m)
  (Maybe Text -> Maybe Char -> (Maybe Text, Maybe Char))
-> ParsecT Text u (ReaderT MuseEnv m) (Maybe Text)
-> ParsecT
     Text u (ReaderT MuseEnv m) (Maybe Char -> (Maybe Text, Maybe Char))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text u (ReaderT MuseEnv m) Text
-> ParsecT Text u (ReaderT MuseEnv m) (Maybe Text)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit)
          ParsecT
  Text u (ReaderT MuseEnv m) (Maybe Char -> (Maybe Text, Maybe Char))
-> ParsecT Text u (ReaderT MuseEnv m) SourceName
-> ParsecT
     Text u (ReaderT MuseEnv m) (Maybe Char -> (Maybe Text, Maybe Char))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv m) SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
          ParsecT
  Text u (ReaderT MuseEnv m) (Maybe Char -> (Maybe Text, Maybe Char))
-> ParsecT Text u (ReaderT MuseEnv m) (Maybe Char)
-> ParsecT Text u (ReaderT MuseEnv m) (Maybe Text, Maybe Char)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text u (ReaderT MuseEnv m) Char
-> ParsecT Text u (ReaderT MuseEnv m) (Maybe Char)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (SourceName -> ParsecT Text u (ReaderT MuseEnv m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m Char
oneOf SourceName
"rlf")