{-# LANGUAGE OverloadedStrings #-}
{- |
   Module      : Text.Pandoc.Readers.Creole
   Copyright   : Copyright (C) 2017 Sascha Wilde
   License     : GNU GPL, version 2 or above

   Maintainer  : Sascha Wilde <wilde@sha-bang.de>
   Stability   : alpha
   Portability : portable

Conversion of creole text to 'Pandoc' document.
-}
module Text.Pandoc.Readers.Creole ( readCreole
                                  ) where

import Control.Monad.Except (guard, liftM2, throwError)
import qualified Data.Foldable as F
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
import Text.Pandoc.Definition
import Text.Pandoc.Options
import Text.Pandoc.Parsing hiding (enclosed)
import Text.Pandoc.Shared (crFilter)


-- | Read creole from an input string and return a Pandoc document.
readCreole :: PandocMonad m
          => ReaderOptions
          -> Text
          -> m Pandoc
readCreole :: ReaderOptions -> Text -> m Pandoc
readCreole ReaderOptions
opts Text
s = do
  Either PandocError Pandoc
res <- ParserT Text ParserState m Pandoc
-> ParserState -> Text -> m (Either PandocError Pandoc)
forall s (m :: * -> *) st a.
(Stream s m Char, ToText s) =>
ParserT s st m a -> st -> s -> m (Either PandocError a)
readWithM ParserT Text ParserState m Pandoc
forall (m :: * -> *). PandocMonad m => CRLParser m Pandoc
parseCreole ParserState
forall a. Default a => a
def{ stateOptions :: ReaderOptions
stateOptions = ReaderOptions
opts } (Text -> m (Either PandocError Pandoc))
-> Text -> m (Either PandocError Pandoc)
forall a b. (a -> b) -> a -> b
$ Text -> Text
crFilter Text
s Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n\n"
  case Either PandocError Pandoc
res of
       Left PandocError
e  -> PandocError -> m Pandoc
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PandocError
e
       Right Pandoc
d -> Pandoc -> m Pandoc
forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
d

type CRLParser = ParserT Text ParserState

--
-- Utility functions
--

(<+>) :: (Monad m, Semigroup a) => m a -> m a -> m a
<+> :: m a -> m a -> m a
(<+>) = (a -> a -> a) -> m a -> m a -> m a
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 a -> a -> a
forall a. Semigroup a => a -> a -> a
(<>)

-- we have to redefine `enclosed' from Text.Pandoc.Parsing, because it
-- assumes, that there can't be a space after the start parser, but
-- with creole this is possible.
enclosed :: (Show end, PandocMonad m) => CRLParser m start   -- ^ start parser
         -> CRLParser m end  -- ^ end parser
         -> CRLParser m a    -- ^ content parser (to be used repeatedly)
         -> CRLParser m [a]
enclosed :: CRLParser m start
-> CRLParser m end -> CRLParser m a -> CRLParser m [a]
enclosed CRLParser m start
start CRLParser m end
end CRLParser m a
parser = CRLParser m [a] -> CRLParser m [a]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m [a] -> CRLParser m [a])
-> CRLParser m [a] -> CRLParser m [a]
forall a b. (a -> b) -> a -> b
$ CRLParser m start
start CRLParser m start -> CRLParser m [a] -> CRLParser m [a]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CRLParser m a -> CRLParser m end -> CRLParser m [a]
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 CRLParser m a
parser CRLParser m end
end

--
-- main parser
--

specialChars :: [Char]
specialChars :: [Char]
specialChars = [Char]
"*/~{}\\|[]()<>\"'"

parseCreole :: PandocMonad m => CRLParser m Pandoc
parseCreole :: CRLParser m Pandoc
parseCreole = do
  Blocks
bs <- [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Blocks)
-> ParsecT Text ParserState m [Blocks]
-> ParsecT Text ParserState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Blocks
-> ParsecT Text ParserState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text ParserState m Blocks
forall (m :: * -> *). PandocMonad m => CRLParser m Blocks
block
  ParsecT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
  ParsecT Text ParserState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
  Pandoc -> CRLParser m Pandoc
forall (m :: * -> *) a. Monad m => a -> m a
return (Pandoc -> CRLParser m Pandoc) -> Pandoc -> CRLParser m Pandoc
forall a b. (a -> b) -> a -> b
$ Blocks -> Pandoc
B.doc Blocks
bs

--
-- block parsers
--

block :: PandocMonad m => CRLParser m B.Blocks
block :: CRLParser m Blocks
block = do
  Blocks
res <- Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT Text ParserState m () -> CRLParser m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
blankline
         CRLParser m Blocks -> CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => CRLParser m Blocks
nowiki
         CRLParser m Blocks -> CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => CRLParser m Blocks
header
         CRLParser m Blocks -> CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => CRLParser m Blocks
horizontalRule
         CRLParser m Blocks -> CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int -> CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => Int -> CRLParser m Blocks
anyList Int
1
         CRLParser m Blocks -> CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => CRLParser m Blocks
table
         CRLParser m Blocks -> CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => CRLParser m Blocks
para
  ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
blankline
  Blocks -> CRLParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
res

nowiki :: PandocMonad m => CRLParser m B.Blocks
nowiki :: CRLParser m Blocks
nowiki = CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m Blocks -> CRLParser m Blocks)
-> CRLParser m Blocks -> CRLParser m Blocks
forall a b. (a -> b) -> a -> b
$ ([Text] -> Blocks)
-> ParsecT Text ParserState m [Text] -> CRLParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> Blocks
B.codeBlock (Text -> Blocks) -> ([Text] -> Text) -> [Text] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat) (ParsecT Text ParserState m Char
forall u. ParsecT Text u m Char
nowikiStart
                                             ParsecT Text ParserState m Char
-> ParsecT Text ParserState m [Text]
-> ParsecT Text ParserState m [Text]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m [Text]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text ParserState m Text
content ParsecT Text ParserState m Char
nowikiEnd)
  where
    content :: ParsecT Text ParserState m Text
content = ParsecT Text ParserState m Text
brackets ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text ParserState m Text
line
    brackets :: ParsecT Text ParserState m Text
brackets = ParsecT Text ParserState m Text -> ParsecT Text ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m Text
 -> ParsecT Text ParserState m Text)
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall a b. (a -> b) -> a -> b
$ Text
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState 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
"" (Char -> Text
T.singleton (Char -> Text)
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
newline)
               ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall (m :: * -> *) a. (Monad m, Semigroup a) => m a -> m a -> m a
<+> (Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
' ' ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (ParsecT Text ParserState m Char -> ParsecT Text ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
manyChar (Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
' ') ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall (m :: * -> *) a. (Monad m, Semigroup a) => m a -> m a -> m a
<+> Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
"}}}") ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text ParserState m Char
eol)
    line :: ParsecT Text ParserState m Text
line = Text
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState 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
"" (Char -> Text
T.singleton (Char -> Text)
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
newline) ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall (m :: * -> *) a. (Monad m, Semigroup a) => m a -> m a -> m a
<+> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState 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 ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
anyChar ParsecT Text ParserState m Char
eol
    eol :: ParsecT Text ParserState m Char
eol = ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Text ParserState m Char
 -> ParsecT Text ParserState m Char)
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall a b. (a -> b) -> a -> b
$ ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m Char
 -> ParsecT Text ParserState m Char)
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall a b. (a -> b) -> a -> b
$ ParsecT Text ParserState m Char
nowikiEnd ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
newline
    nowikiStart :: ParsecT Text u m Char
nowikiStart = ParsecT Text u m Char -> ParsecT Text u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Text u m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
newline ParsecT Text u m ()
-> ParsecT Text u m [Char] -> ParsecT Text u m [Char]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> ParsecT Text u m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"{{{" ParsecT Text u m [Char]
-> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m Char -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text u m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
spaceChar ParsecT Text u m ()
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
newline
    nowikiEnd :: ParsecT Text ParserState m Char
nowikiEnd = ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m Char
 -> ParsecT Text ParserState m Char)
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall a b. (a -> b) -> a -> b
$ CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
linebreak CRLParser m Inlines
-> ParsecT Text ParserState m [Char]
-> ParsecT Text ParserState m [Char]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> ParsecT Text ParserState m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"}}}" ParsecT Text ParserState m [Char]
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
spaceChar ParsecT Text ParserState m ()
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
newline

header :: PandocMonad m => CRLParser m B.Blocks
header :: CRLParser m Blocks
header = CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m Blocks -> CRLParser m Blocks)
-> CRLParser m Blocks -> CRLParser m Blocks
forall a b. (a -> b) -> a -> b
$ do
  ParserT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces
  Int
level <-
    ([Char] -> Int)
-> ParsecT Text ParserState m [Char]
-> ParsecT Text ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Char] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (ParsecT Text ParserState m Char
-> ParsecT Text ParserState m [Char]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'='))
  Bool -> ParserT Text ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParserT Text ParserState m ())
-> Bool -> ParserT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ Int
level Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
6
  ParserT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces
  Inlines
content <- Text -> Inlines
B.str (Text -> Inlines)
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState 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 ([Char] -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n") ParsecT Text ParserState m Char
forall u. ParsecT Text u m Char
headerEnd
  Blocks -> CRLParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> CRLParser m Blocks) -> Blocks -> CRLParser m Blocks
forall a b. (a -> b) -> a -> b
$ Int -> Inlines -> Blocks
B.header Int
level Inlines
content
  where
    headerEnd :: ParsecT Text u m Char
headerEnd = ParsecT Text u m Char -> ParsecT Text u m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m Char -> ParsecT Text u m Char)
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall a b. (a -> b) -> a -> b
$ ParserT Text u m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces ParserT Text u m ()
-> ParsecT Text u m [Char] -> ParsecT Text u m [Char]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m Char -> ParsecT Text u m [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (Char -> ParsecT Text u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'=') ParsecT Text u m [Char]
-> ParserT Text u m () -> ParserT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParserT Text u m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces ParserT Text u m ()
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
newline

unorderedList :: PandocMonad m => Int -> CRLParser m B.Blocks
unorderedList :: Int -> CRLParser m Blocks
unorderedList = Char -> ([Blocks] -> Blocks) -> Int -> CRLParser m Blocks
forall (m :: * -> *).
PandocMonad m =>
Char -> ([Blocks] -> Blocks) -> Int -> CRLParser m Blocks
list Char
'*' [Blocks] -> Blocks
B.bulletList

orderedList :: PandocMonad m => Int -> CRLParser m B.Blocks
orderedList :: Int -> CRLParser m Blocks
orderedList = Char -> ([Blocks] -> Blocks) -> Int -> CRLParser m Blocks
forall (m :: * -> *).
PandocMonad m =>
Char -> ([Blocks] -> Blocks) -> Int -> CRLParser m Blocks
list Char
'#' [Blocks] -> Blocks
B.orderedList

anyList :: PandocMonad m => Int -> CRLParser m B.Blocks
anyList :: Int -> CRLParser m Blocks
anyList Int
n = Int -> CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => Int -> CRLParser m Blocks
unorderedList Int
n CRLParser m Blocks -> CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int -> CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => Int -> CRLParser m Blocks
orderedList Int
n

anyListItem :: PandocMonad m => Int -> CRLParser m B.Blocks
anyListItem :: Int -> CRLParser m Blocks
anyListItem Int
n = Char -> Int -> CRLParser m Blocks
forall (m :: * -> *).
PandocMonad m =>
Char -> Int -> CRLParser m Blocks
listItem Char
'*' Int
n CRLParser m Blocks -> CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> Int -> CRLParser m Blocks
forall (m :: * -> *).
PandocMonad m =>
Char -> Int -> CRLParser m Blocks
listItem Char
'#' Int
n

list :: PandocMonad m => Char -> ([B.Blocks] -> B.Blocks) -> Int -> CRLParser m B.Blocks
list :: Char -> ([Blocks] -> Blocks) -> Int -> CRLParser m Blocks
list Char
c [Blocks] -> Blocks
f Int
n =
  ([Blocks] -> Blocks)
-> ParsecT Text ParserState m [Blocks] -> CRLParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Blocks] -> Blocks
f (CRLParser m Blocks -> ParsecT Text ParserState m [Blocks]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (CRLParser m Blocks
itemPlusSublist CRLParser m Blocks -> CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> Int -> CRLParser m Blocks
forall (m :: * -> *).
PandocMonad m =>
Char -> Int -> CRLParser m Blocks
listItem Char
c Int
n))
  where itemPlusSublist :: CRLParser m Blocks
itemPlusSublist = CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m Blocks -> CRLParser m Blocks)
-> CRLParser m Blocks -> CRLParser m Blocks
forall a b. (a -> b) -> a -> b
$ Char -> Int -> CRLParser m Blocks
forall (m :: * -> *).
PandocMonad m =>
Char -> Int -> CRLParser m Blocks
listItem Char
c Int
n CRLParser m Blocks -> CRLParser m Blocks -> CRLParser m Blocks
forall (m :: * -> *) a. (Monad m, Semigroup a) => m a -> m a -> m a
<+> Int -> CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => Int -> CRLParser m Blocks
anyList (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)

listItem :: PandocMonad m => Char -> Int -> CRLParser m B.Blocks
listItem :: Char -> Int -> CRLParser m Blocks
listItem Char
c Int
n =
  ([Inlines] -> Blocks)
-> ParsecT Text ParserState m [Inlines] -> CRLParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Inlines -> Blocks
B.plain (Inlines -> Blocks)
-> ([Inlines] -> Inlines) -> [Inlines] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
.[Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat) (ParsecT Text ParserState m ()
forall u. ParsecT Text u m ()
listStart ParsecT Text ParserState m ()
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParserT Text ParserState m Inlines
-> ParsecT Text ParserState m ()
-> ParsecT Text ParserState m [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 ParserState m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
inline ParsecT Text ParserState m ()
itemEnd)
  where
    listStart :: ParsecT Text u m ()
listStart = ParsecT Text u m () -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m () -> ParsecT Text u m ())
-> ParsecT Text u m () -> ParsecT Text u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Text u m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m Char -> ParsecT Text u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Text u m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
newline ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces
                ParsecT Text u m ()
-> ParsecT Text u m [Char] -> ParsecT Text u m [Char]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> ParsecT Text u m Char -> ParsecT Text u m [Char]
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 m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c)
                ParsecT Text u m [Char]
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m Char -> ParsecT Text u m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ([Char] -> ParsecT Text u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char
c]) ParsecT Text u m Char -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces
    itemEnd :: ParsecT Text ParserState m ()
itemEnd = ParsecT Text ParserState m ()
forall (m :: * -> *). PandocMonad m => CRLParser m ()
endOfParaElement ParsecT Text ParserState m ()
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int -> ParsecT Text ParserState m ()
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
Int -> ParsecT Text ParserState m a
nextItem Int
n
              ParsecT Text ParserState m ()
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
3 then Int -> ParsecT Text ParserState m ()
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
Int -> ParsecT Text ParserState m a
nextItem (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
                  else Int -> ParsecT Text ParserState m ()
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
Int -> ParsecT Text ParserState m a
nextItem (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) ParsecT Text ParserState m ()
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int -> ParsecT Text ParserState m ()
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
Int -> ParsecT Text ParserState m a
nextItem (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)
    nextItem :: Int -> ParsecT Text ParserState m a
nextItem Int
x = ParsecT Text ParserState m a -> ParsecT Text ParserState m a
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Text ParserState m a -> ParsecT Text ParserState m a)
-> ParsecT Text ParserState m a -> ParsecT Text ParserState m a
forall a b. (a -> b) -> a -> b
$ ParsecT Text ParserState m a -> ParsecT Text ParserState m a
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m a -> ParsecT Text ParserState m a)
-> ParsecT Text ParserState m a -> ParsecT Text ParserState m a
forall a b. (a -> b) -> a -> b
$ ParserT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
blankline ParserT Text ParserState m Char
-> ParsecT Text ParserState m Blocks
-> ParsecT Text ParserState m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> ParsecT Text ParserState m Blocks
forall (m :: * -> *). PandocMonad m => Int -> CRLParser m Blocks
anyListItem Int
x ParsecT Text ParserState m Blocks
-> ParsecT Text ParserState m a -> ParsecT Text ParserState m a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> a -> ParsecT Text ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
forall a. Monoid a => a
mempty

table :: PandocMonad m => CRLParser m B.Blocks
table :: CRLParser m Blocks
table = CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m Blocks -> CRLParser m Blocks)
-> CRLParser m Blocks -> CRLParser m Blocks
forall a b. (a -> b) -> a -> b
$ do
  Maybe [Blocks]
headers <- ParsecT Text ParserState m [Blocks]
-> ParsecT Text ParserState m (Maybe [Blocks])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ParsecT Text ParserState m [Blocks]
headerRow
  [[Blocks]]
rows <- ParsecT Text ParserState m [Blocks]
-> ParsecT Text ParserState m [[Blocks]]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Text ParserState m [Blocks]
row
  Blocks -> CRLParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> CRLParser m Blocks) -> Blocks -> CRLParser m Blocks
forall a b. (a -> b) -> a -> b
$ [Blocks] -> [[Blocks]] -> Blocks
B.simpleTable ([Blocks] -> Maybe [Blocks] -> [Blocks]
forall a. a -> Maybe a -> a
fromMaybe [Blocks
forall a. Monoid a => a
mempty] Maybe [Blocks]
headers) [[Blocks]]
rows
  where
    headerRow :: ParsecT Text ParserState m [Blocks]
headerRow = ParsecT Text ParserState m [Blocks]
-> ParsecT Text ParserState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m [Blocks]
 -> ParsecT Text ParserState m [Blocks])
-> ParsecT Text ParserState m [Blocks]
-> ParsecT Text ParserState m [Blocks]
forall a b. (a -> b) -> a -> b
$ ParserT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces ParserT Text ParserState m ()
-> ParsecT Text ParserState m [Blocks]
-> ParsecT Text ParserState m [Blocks]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CRLParser m Blocks
-> ParserT Text ParserState m Char
-> ParsecT Text ParserState m [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 CRLParser m Blocks
headerCell ParserT Text ParserState m Char
forall u. ParsecT Text u m Char
rowEnd
    headerCell :: CRLParser m Blocks
headerCell = Inlines -> Blocks
B.plain (Inlines -> Blocks)
-> ([Inlines] -> Inlines) -> [Inlines] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat
                 ([Inlines] -> Blocks)
-> ParsecT Text ParserState m [Inlines] -> CRLParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Char] -> ParsecT Text ParserState m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"|=" ParsecT Text ParserState m [Char]
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParserT Text ParserState m Inlines
-> ParserT Text ParserState m Char
-> ParsecT Text ParserState m [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 ParserState m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
inline ParserT Text ParserState m Char
forall u. ParsecT Text u m Char
cellEnd)
    row :: ParsecT Text ParserState m [Blocks]
row = ParsecT Text ParserState m [Blocks]
-> ParsecT Text ParserState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m [Blocks]
 -> ParsecT Text ParserState m [Blocks])
-> ParsecT Text ParserState m [Blocks]
-> ParsecT Text ParserState m [Blocks]
forall a b. (a -> b) -> a -> b
$ ParserT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces ParserT Text ParserState m ()
-> ParsecT Text ParserState m [Blocks]
-> ParsecT Text ParserState m [Blocks]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CRLParser m Blocks
-> ParserT Text ParserState m Char
-> ParsecT Text ParserState m [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 CRLParser m Blocks
cell ParserT Text ParserState m Char
forall u. ParsecT Text u m Char
rowEnd
    cell :: CRLParser m Blocks
cell = Inlines -> Blocks
B.plain (Inlines -> Blocks)
-> ([Inlines] -> Inlines) -> [Inlines] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat
           ([Inlines] -> Blocks)
-> ParsecT Text ParserState m [Inlines] -> CRLParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParserT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|' ParserT Text ParserState m Char
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParserT Text ParserState m Inlines
-> ParserT Text ParserState m Char
-> ParsecT Text ParserState m [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 ParserState m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
inline ParserT Text ParserState m Char
forall u. ParsecT Text u m Char
cellEnd)
    rowEnd :: ParsecT Text u m Char
rowEnd = ParsecT Text u m Char -> ParsecT Text u m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m Char -> ParsecT Text u m Char)
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall a b. (a -> b) -> a -> b
$ ParsecT Text u m Char -> ParsecT Text u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (Char -> ParsecT Text u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|') ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces ParsecT Text u m ()
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
newline
    cellEnd :: ParsecT Text u m Char
cellEnd = ParsecT Text u m Char -> ParsecT Text u m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Text u m Char -> ParsecT Text u m Char)
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall a b. (a -> b) -> a -> b
$ ParsecT Text u m Char -> ParsecT Text u m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m Char -> ParsecT Text u m Char)
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Text u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|' ParsecT Text u m Char
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text u m Char
forall u. ParsecT Text u m Char
rowEnd

para :: PandocMonad m => CRLParser m B.Blocks
para :: CRLParser m Blocks
para = ([Inlines] -> Blocks)
-> ParsecT Text ParserState m [Inlines] -> CRLParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Inlines -> Blocks
result (Inlines -> Blocks)
-> ([Inlines] -> Inlines) -> [Inlines] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat) (ParserT Text ParserState m Inlines
-> ParserT Text ParserState m ()
-> ParsecT Text ParserState m [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 ParserState m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
inline ParserT Text ParserState m ()
forall (m :: * -> *). PandocMonad m => CRLParser m ()
endOfParaElement)
 where
   result :: Inlines -> Blocks
result Inlines
content   = if (Inline -> Bool) -> Inlines -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
F.all (Inline -> Inline -> Bool
forall a. Eq a => a -> a -> Bool
==Inline
Space) Inlines
content
                      then Blocks
forall a. Monoid a => a
mempty
                      else Inlines -> Blocks
B.para (Inlines -> Blocks) -> Inlines -> Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.trimInlines Inlines
content

endOfParaElement :: PandocMonad m => CRLParser m ()
endOfParaElement :: CRLParser m ()
endOfParaElement = CRLParser m () -> CRLParser m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (CRLParser m () -> CRLParser m ())
-> CRLParser m () -> CRLParser m ()
forall a b. (a -> b) -> a -> b
$ CRLParser m ()
forall u. ParsecT Text u m ()
endOfInput CRLParser m () -> CRLParser m () -> CRLParser m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m ()
forall u. ParsecT Text u m ()
endOfPara
                   CRLParser m () -> CRLParser m () -> CRLParser m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m ()
startOfList CRLParser m () -> CRLParser m () -> CRLParser m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m ()
startOfTable
                   CRLParser m () -> CRLParser m () -> CRLParser m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m ()
startOfHeader CRLParser m () -> CRLParser m () -> CRLParser m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m ()
hr CRLParser m () -> CRLParser m () -> CRLParser m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m ()
startOfNowiki
  where
   endOfInput :: ParsecT Text u m ()
endOfInput    = ParsecT Text u m () -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m () -> ParsecT Text u m ())
-> ParsecT Text u m () -> ParsecT Text u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Text u m Char -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text u m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
blankline ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
   endOfPara :: ParsecT Text u m ()
endOfPara     = ParsecT Text u m () -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m () -> ParsecT Text u m ())
-> ParsecT Text u m () -> ParsecT Text u m ()
forall a b. (a -> b) -> a -> b
$ ParserT Text u m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
blankline ParserT Text u m Char -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParserT Text u m Char -> ParsecT Text u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParserT Text u m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
blankline
   startOf      :: PandocMonad m => CRLParser m a -> CRLParser m ()
   startOf :: CRLParser m a -> CRLParser m ()
startOf CRLParser m a
p     = CRLParser m () -> CRLParser m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m () -> CRLParser m ())
-> CRLParser m () -> CRLParser m ()
forall a b. (a -> b) -> a -> b
$ ParserT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
blankline ParserT Text ParserState m Char -> CRLParser m a -> CRLParser m a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CRLParser m a
p CRLParser m a -> CRLParser m () -> CRLParser m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> CRLParser m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
forall a. Monoid a => a
mempty
   startOfList :: CRLParser m ()
startOfList   = CRLParser m Blocks -> CRLParser m ()
forall (m :: * -> *) a.
PandocMonad m =>
CRLParser m a -> CRLParser m ()
startOf (CRLParser m Blocks -> CRLParser m ())
-> CRLParser m Blocks -> CRLParser m ()
forall a b. (a -> b) -> a -> b
$ Int -> CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => Int -> CRLParser m Blocks
anyListItem Int
1
   startOfTable :: CRLParser m ()
startOfTable  = CRLParser m Blocks -> CRLParser m ()
forall (m :: * -> *) a.
PandocMonad m =>
CRLParser m a -> CRLParser m ()
startOf CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => CRLParser m Blocks
table
   startOfHeader :: CRLParser m ()
startOfHeader = CRLParser m Blocks -> CRLParser m ()
forall (m :: * -> *) a.
PandocMonad m =>
CRLParser m a -> CRLParser m ()
startOf CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => CRLParser m Blocks
header
   startOfNowiki :: CRLParser m ()
startOfNowiki = CRLParser m Blocks -> CRLParser m ()
forall (m :: * -> *) a.
PandocMonad m =>
CRLParser m a -> CRLParser m ()
startOf CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => CRLParser m Blocks
nowiki
   hr :: CRLParser m ()
hr            = CRLParser m Blocks -> CRLParser m ()
forall (m :: * -> *) a.
PandocMonad m =>
CRLParser m a -> CRLParser m ()
startOf CRLParser m Blocks
forall (m :: * -> *). PandocMonad m => CRLParser m Blocks
horizontalRule

horizontalRule :: PandocMonad m => CRLParser m B.Blocks
horizontalRule :: CRLParser m Blocks
horizontalRule = CRLParser m Blocks -> CRLParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m Blocks -> CRLParser m Blocks)
-> CRLParser m Blocks -> CRLParser m Blocks
forall a b. (a -> b) -> a -> b
$ ParserT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces ParserT Text ParserState m ()
-> ParsecT Text ParserState m [Char]
-> ParsecT Text ParserState m [Char]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> ParsecT Text ParserState m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"----" ParsecT Text ParserState m [Char]
-> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParserT Text ParserState m ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
skipSpaces ParserT Text ParserState m ()
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
newline
                 ParsecT Text ParserState m Char
-> CRLParser m Blocks -> CRLParser m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> CRLParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
B.horizontalRule

--
-- inline parsers
--

inline :: PandocMonad m => CRLParser m B.Inlines
inline :: CRLParser m Inlines
inline = [CRLParser m Inlines] -> CRLParser m Inlines
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
whitespace
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
escapedLink
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
escapedChar
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
link
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
inlineNowiki
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
placeholder
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
image
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
forcedLinebreak
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
bold
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
finalBold
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
italics
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
finalItalics
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
str
                , CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
symbol
                ] CRLParser m Inlines -> [Char] -> CRLParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"inline"

escapedChar :: PandocMonad m => CRLParser m B.Inlines
escapedChar :: CRLParser m Inlines
escapedChar =
  (Char -> Inlines)
-> ParsecT Text ParserState m Char -> CRLParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> Inlines
B.str (Text -> Inlines) -> (Char -> Text) -> Char -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton) (ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m Char
 -> ParsecT Text ParserState m Char)
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'~' ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\t\n ")

escapedLink :: PandocMonad m => CRLParser m B.Inlines
escapedLink :: CRLParser m Inlines
escapedLink = CRLParser m Inlines -> CRLParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m Inlines -> CRLParser m Inlines)
-> CRLParser m Inlines -> CRLParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
  Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'~'
  (Text
orig, Text
_) <- ParserT Text ParserState m (Text, Text)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (Text, Text)
uri
  Inlines -> CRLParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> CRLParser m Inlines) -> Inlines -> CRLParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
orig

image :: PandocMonad m => CRLParser m B.Inlines
image :: CRLParser m Inlines
image = CRLParser m Inlines -> CRLParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m Inlines -> CRLParser m Inlines)
-> CRLParser m Inlines -> CRLParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
  (Text
orig, Text
src) <- ParsecT Text ParserState m (Text, Text)
forall u. ParsecT Text u m (Text, Text)
wikiImg
  Inlines -> CRLParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> CRLParser m Inlines) -> Inlines -> CRLParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.image Text
src Text
"" (Text -> Inlines
B.str Text
orig)
  where
    linkSrc :: ParserT Text st m Text
linkSrc = ParserT Text st m Char -> ParserT Text st m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
manyChar (ParserT Text st m Char -> ParserT Text st m Text)
-> ParserT Text st m Char -> ParserT Text st m Text
forall a b. (a -> b) -> a -> b
$ [Char] -> ParserT Text st m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"|}\n\r\t"
    linkDsc :: ParsecT Text u m Text
linkDsc = Char -> ParsecT Text u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|' ParsecT Text u m Char
-> ParsecT Text u m Text -> ParsecT Text u m Text
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m Char -> ParsecT Text u m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
manyChar ([Char] -> ParsecT Text u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"}\n\r\t")
    wikiImg :: ParsecT Text u m (Text, Text)
wikiImg = ParsecT Text u m (Text, Text) -> ParsecT Text u m (Text, Text)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m (Text, Text) -> ParsecT Text u m (Text, Text))
-> ParsecT Text u m (Text, Text) -> ParsecT Text u m (Text, Text)
forall a b. (a -> b) -> a -> b
$ do
      [Char] -> ParsecT Text u m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"{{"
      Text
src <- ParserT Text u m Text
forall st. ParserT Text st m Text
linkSrc
      Text
dsc <- Text -> ParserT Text u m Text -> ParserT Text u 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
"" ParserT Text u m Text
forall st. ParserT Text st m Text
linkDsc
      [Char] -> ParsecT Text u m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"}}"
      (Text, Text) -> ParsecT Text u m (Text, Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
dsc, Text
src)

link :: PandocMonad m => CRLParser m B.Inlines
link :: CRLParser m Inlines
link = CRLParser m Inlines -> CRLParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m Inlines -> CRLParser m Inlines)
-> CRLParser m Inlines -> CRLParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
  (Inlines
orig, Text
src) <- ParsecT Text ParserState m (Inlines, Text)
forall u. ParsecT Text u m (Inlines, Text)
uriLink ParsecT Text ParserState m (Inlines, Text)
-> ParsecT Text ParserState m (Inlines, Text)
-> ParsecT Text ParserState m (Inlines, Text)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text ParserState m (Inlines, Text)
wikiLink
  Inlines -> CRLParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> CRLParser m Inlines) -> Inlines -> CRLParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link Text
src Text
"" Inlines
orig
  where
    linkSrc :: ParserT Text st m Text
linkSrc = ParserT Text st m Char -> ParserT Text st m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
manyChar (ParserT Text st m Char -> ParserT Text st m Text)
-> ParserT Text st m Char -> ParserT Text st m Text
forall a b. (a -> b) -> a -> b
$ [Char] -> ParserT Text st m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"|]\n\r\t"
    linkDsc :: PandocMonad m => Text -> CRLParser m B.Inlines
    linkDsc :: Text -> CRLParser m Inlines
linkDsc Text
otxt = Text -> Inlines
B.str
                   (Text -> Inlines)
-> ParsecT Text ParserState m Text -> CRLParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Text -> ParsecT Text ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Text
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState 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
otxt
                         (Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|' ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Char -> ParsecT Text ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
manyChar ([Char] -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"]\n\r\t")))
    linkImg :: CRLParser m Inlines
linkImg = CRLParser m Inlines -> CRLParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m Inlines -> CRLParser m Inlines)
-> CRLParser m Inlines -> CRLParser m Inlines
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|' ParsecT Text ParserState m Char
-> CRLParser m Inlines -> CRLParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
image
    wikiLink :: ParsecT Text ParserState m (Inlines, Text)
wikiLink = ParsecT Text ParserState m (Inlines, Text)
-> ParsecT Text ParserState m (Inlines, Text)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m (Inlines, Text)
 -> ParsecT Text ParserState m (Inlines, Text))
-> ParsecT Text ParserState m (Inlines, Text)
-> ParsecT Text ParserState m (Inlines, Text)
forall a b. (a -> b) -> a -> b
$ do
      [Char] -> ParsecT Text ParserState m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"[["
      Text
src <- ParserT Text ParserState m Text
forall st. ParserT Text st m Text
linkSrc
      Inlines
dsc <- CRLParser m Inlines
linkImg CRLParser m Inlines -> CRLParser m Inlines -> CRLParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => Text -> CRLParser m Inlines
linkDsc Text
src
      [Char] -> ParsecT Text ParserState m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"]]"
      (Inlines, Text) -> ParsecT Text ParserState m (Inlines, Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines
dsc, Text
src)
    uriLink :: ParsecT Text u m (Inlines, Text)
uriLink = ParsecT Text u m (Inlines, Text)
-> ParsecT Text u m (Inlines, Text)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m (Inlines, Text)
 -> ParsecT Text u m (Inlines, Text))
-> ParsecT Text u m (Inlines, Text)
-> ParsecT Text u m (Inlines, Text)
forall a b. (a -> b) -> a -> b
$ do
      (Text
orig, Text
src) <- ParserT Text u m (Text, Text)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (Text, Text)
uri
      (Inlines, Text) -> ParsecT Text u m (Inlines, Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
B.str Text
orig, Text
src)

inlineNowiki :: PandocMonad m => CRLParser m B.Inlines
inlineNowiki :: CRLParser m Inlines
inlineNowiki = Text -> Inlines
B.code (Text -> Inlines)
-> ParsecT Text ParserState m Text -> CRLParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Text ParserState m [Char]
forall u. ParsecT Text u m [Char]
start ParsecT Text ParserState m [Char]
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParserT Text ParserState m Char
-> ParserT Text ParserState m Char
-> ParsecT Text ParserState 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 ([Char] -> ParserT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r") ParserT Text ParserState m Char
forall u. ParsecT Text u m Char
end)
  where
    start :: ParsecT Text u m [Char]
start = ParsecT Text u m [Char] -> ParsecT Text u m [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m [Char] -> ParsecT Text u m [Char])
-> ParsecT Text u m [Char] -> ParsecT Text u m [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> ParsecT Text u m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"{{{"
    end :: ParsecT Text u m Char
end = ParsecT Text u m Char -> ParsecT Text u m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m Char -> ParsecT Text u m Char)
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall a b. (a -> b) -> a -> b
$ [Char] -> ParsecT Text u m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"}}}" ParsecT Text u m [Char]
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m Char -> ParsecT Text u m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ([Char] -> ParsecT Text u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"}")

placeholder :: PandocMonad m => CRLParser m B.Inlines
-- The semantics of the placeholder is basically implementation
-- dependent, so there is no way to DTRT for all cases.
-- So for now we just drop them.
placeholder :: CRLParser m Inlines
placeholder = Text -> Inlines
B.text (Text -> Inlines)
-> ParsecT Text ParserState m Text -> CRLParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Text -> ParsecT Text ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([Char] -> ParsecT Text ParserState m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"<<<" ParsecT Text ParserState m [Char]
-> ParsecT Text ParserState m [Char]
-> ParsecT Text ParserState m [Char]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m [Char]
-> ParsecT Text ParserState m [Char]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
anyChar ([Char] -> ParsecT Text ParserState m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
">>>")
              ParsecT Text ParserState m [Char]
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Text -> ParsecT Text ParserState m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"")

whitespace :: PandocMonad m => CRLParser m B.Inlines
whitespace :: CRLParser m Inlines
whitespace = CRLParser m Inlines
lb CRLParser m Inlines -> CRLParser m Inlines -> CRLParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m Inlines
forall u. ParsecT Text u m Inlines
regsp
  where lb :: CRLParser m Inlines
lb = CRLParser m Inlines -> CRLParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m Inlines -> CRLParser m Inlines)
-> CRLParser m Inlines -> CRLParser m Inlines
forall a b. (a -> b) -> a -> b
$ ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
spaceChar ParsecT Text ParserState m ()
-> CRLParser m Inlines -> CRLParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
linebreak CRLParser m Inlines -> CRLParser m Inlines -> CRLParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> CRLParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.space
        regsp :: ParsecT Text u m Inlines
regsp = ParsecT Text u m Inlines -> ParsecT Text u m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m Inlines -> ParsecT Text u m Inlines)
-> ParsecT Text u m Inlines -> ParsecT Text u m Inlines
forall a b. (a -> b) -> a -> b
$ ParsecT Text u m Char -> ParsecT Text u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Text u m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
spaceChar ParsecT Text u m ()
-> ParsecT Text u m Inlines -> ParsecT Text u m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> ParsecT Text u m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.space

linebreak :: PandocMonad m => CRLParser m B.Inlines
linebreak :: CRLParser m Inlines
linebreak = ParsecT Text ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
newline ParsecT Text ParserState m Char
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Char -> ParsecT Text ParserState 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 ParserState m Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
newline ParsecT Text ParserState m ()
-> CRLParser m Inlines -> CRLParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (CRLParser m Inlines
forall u. ParsecT Text u m Inlines
lastNewline CRLParser m Inlines -> CRLParser m Inlines -> CRLParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CRLParser m Inlines
innerNewline)
  where lastNewline :: ParsecT Text u m Inlines
lastNewline  = ParsecT Text u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParsecT Text u m ()
-> ParsecT Text u m Inlines -> ParsecT Text u m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> ParsecT Text u m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
        innerNewline :: CRLParser m Inlines
innerNewline = Inlines -> CRLParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.space

symbol :: PandocMonad m => CRLParser m B.Inlines
symbol :: CRLParser m Inlines
symbol = (Char -> Inlines)
-> ParsecT Text ParserState m Char -> CRLParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (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] -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
oneOf [Char]
specialChars)

str :: PandocMonad m => CRLParser m B.Inlines
str :: CRLParser m Inlines
str = let strChar :: ParsecT Text u m Char
strChar = [Char] -> ParsecT Text u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf ([Char]
"\t\n " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
specialChars) in
        (Text -> Inlines)
-> ParsecT Text ParserState m Text -> CRLParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Inlines
B.str (ParserT Text ParserState m Char -> ParsecT Text ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParserT Text ParserState m Char
forall u. ParsecT Text u m Char
strChar)

bold :: PandocMonad m => CRLParser m B.Inlines
bold :: CRLParser m Inlines
bold = Inlines -> Inlines
B.strong (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Text ParserState m [Inlines] -> CRLParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
       CRLParser m [Char]
-> CRLParser m [Char]
-> CRLParser m Inlines
-> ParsecT Text ParserState m [Inlines]
forall end (m :: * -> *) start a.
(Show end, PandocMonad m) =>
CRLParser m start
-> CRLParser m end -> CRLParser m a -> CRLParser m [a]
enclosed ([Char] -> CRLParser m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"**") (CRLParser m [Char] -> CRLParser m [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m [Char] -> CRLParser m [Char])
-> CRLParser m [Char] -> CRLParser m [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> CRLParser m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"**") CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
inline

italics :: PandocMonad m => CRLParser m B.Inlines
italics :: CRLParser m Inlines
italics = Inlines -> Inlines
B.emph (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Text ParserState m [Inlines] -> CRLParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          CRLParser m [Char]
-> CRLParser m [Char]
-> CRLParser m Inlines
-> ParsecT Text ParserState m [Inlines]
forall end (m :: * -> *) start a.
(Show end, PandocMonad m) =>
CRLParser m start
-> CRLParser m end -> CRLParser m a -> CRLParser m [a]
enclosed ([Char] -> CRLParser m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"//") (CRLParser m [Char] -> CRLParser m [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m [Char] -> CRLParser m [Char])
-> CRLParser m [Char] -> CRLParser m [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> CRLParser m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"//") CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
inline

finalBold :: PandocMonad m => CRLParser m B.Inlines
finalBold :: CRLParser m Inlines
finalBold = Inlines -> Inlines
B.strong (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Text ParserState m [Inlines] -> CRLParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
            ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([Char] -> ParsecT Text ParserState m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"**" ParsecT Text ParserState m [Char]
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CRLParser m Inlines
-> ParserT Text ParserState m ()
-> ParsecT Text ParserState m [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 CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
inline ParserT Text ParserState m ()
forall (m :: * -> *). PandocMonad m => CRLParser m ()
endOfParaElement)

finalItalics :: PandocMonad m => CRLParser m B.Inlines
finalItalics :: CRLParser m Inlines
finalItalics = Inlines -> Inlines
B.emph (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Text ParserState m [Inlines] -> CRLParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
               ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([Char] -> ParsecT Text ParserState m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"//" ParsecT Text ParserState m [Char]
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CRLParser m Inlines
-> ParserT Text ParserState m ()
-> ParsecT Text ParserState m [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 CRLParser m Inlines
forall (m :: * -> *). PandocMonad m => CRLParser m Inlines
inline ParserT Text ParserState m ()
forall (m :: * -> *). PandocMonad m => CRLParser m ()
endOfParaElement)

forcedLinebreak :: PandocMonad m => CRLParser m B.Inlines
forcedLinebreak :: CRLParser m Inlines
forcedLinebreak = CRLParser m Inlines -> CRLParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (CRLParser m Inlines -> CRLParser m Inlines)
-> CRLParser m Inlines -> CRLParser m Inlines
forall a b. (a -> b) -> a -> b
$ [Char] -> ParsecT Text ParserState m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"\\\\" ParsecT Text ParserState m [Char]
-> CRLParser m Inlines -> CRLParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> CRLParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.linebreak