{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Readers.TWiki ( readTWiki
) where
import Control.Monad
import Control.Monad.Except (throwError)
import Data.Char (isAlphaNum)
import qualified Data.Foldable as F
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import qualified Data.Text as T
import Text.HTML.TagSoup
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, nested)
import Text.Pandoc.Readers.HTML (htmlTag, isCommentTag)
import Text.Pandoc.Shared (tshow)
import Text.Pandoc.XML (fromEntities)
readTWiki :: (PandocMonad m, ToSources a)
=> ReaderOptions
-> a
-> m Pandoc
readTWiki :: ReaderOptions -> a -> m Pandoc
readTWiki ReaderOptions
opts a
s = do
let sources :: Sources
sources = Int -> Sources -> Sources
ensureFinalNewlines Int
2 (a -> Sources
forall a. ToSources a => a -> Sources
toSources a
s)
Either PandocError Pandoc
res <- ParserT Sources ParserState m Pandoc
-> ParserState -> Sources -> m (Either PandocError Pandoc)
forall (m :: * -> *) t st a.
(Monad m, ToSources t) =>
ParserT Sources st m a -> st -> t -> m (Either PandocError a)
readWithM ParserT Sources ParserState m Pandoc
forall (m :: * -> *). PandocMonad m => TWParser m Pandoc
parseTWiki ParserState
forall a. Default a => a
def{ stateOptions :: ReaderOptions
stateOptions = ReaderOptions
opts } Sources
sources
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 TWParser = ParserT Sources ParserState
tryMsg :: Text -> TWParser m a -> TWParser m a
tryMsg :: Text -> TWParser m a -> TWParser m a
tryMsg Text
msg TWParser m a
p = TWParser m a -> TWParser m a
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try TWParser m a
p TWParser m a -> String -> TWParser m a
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> Text -> String
T.unpack Text
msg
nested :: PandocMonad m => TWParser m a -> TWParser m a
nested :: TWParser m a -> TWParser m a
nested TWParser m a
p = do
Int
nestlevel <- ParserState -> Int
stateMaxNestingLevel (ParserState -> Int)
-> ParsecT Sources ParserState m ParserState
-> ParsecT Sources ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Sources ParserState m ())
-> Bool -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ Int
nestlevel Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
(ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((ParserState -> ParserState) -> ParsecT Sources ParserState m ())
-> (ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ \ParserState
st -> ParserState
st{ stateMaxNestingLevel :: Int
stateMaxNestingLevel = ParserState -> Int
stateMaxNestingLevel ParserState
st Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 }
a
res <- TWParser m a
p
(ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((ParserState -> ParserState) -> ParsecT Sources ParserState m ())
-> (ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ \ParserState
st -> ParserState
st{ stateMaxNestingLevel :: Int
stateMaxNestingLevel = Int
nestlevel }
a -> TWParser m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
res
htmlElement :: PandocMonad m => Text -> TWParser m (Attr, Text)
htmlElement :: Text -> TWParser m (Attr, Text)
htmlElement Text
tag = Text -> TWParser m (Attr, Text) -> TWParser m (Attr, Text)
forall (m :: * -> *) a. Text -> TWParser m a -> TWParser m a
tryMsg Text
tag (TWParser m (Attr, Text) -> TWParser m (Attr, Text))
-> TWParser m (Attr, Text) -> TWParser m (Attr, Text)
forall a b. (a -> b) -> a -> b
$ do
(TagOpen Text
_ [Attribute Text]
attr, Text
_) <- (Tag Text -> Bool)
-> ParserT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParserT Sources st m (Tag Text, Text)
htmlTag (Tag Text -> Tag Text -> Bool
forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Text -> [Attribute Text] -> Tag Text
forall str. str -> [Attribute str] -> Tag str
TagOpen Text
tag [])
Text
content <- String -> Text
T.pack (String -> Text)
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m String
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 Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (ParsecT Sources ParserState m ()
endtag ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m ()
forall u. ParsecT Sources u m ()
endofinput)
(Attr, Text) -> TWParser m (Attr, Text)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Attribute Text] -> Attr
htmlAttrToPandoc [Attribute Text]
attr, Text -> Text
trim Text
content)
where
endtag :: ParsecT Sources ParserState m ()
endtag = ParserT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParserT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m ())
-> ParserT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ (Tag Text -> Bool)
-> ParserT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParserT Sources st m (Tag Text, Text)
htmlTag (Tag Text -> Tag Text -> Bool
forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Text -> Tag Text
forall str. str -> Tag str
TagClose Text
tag)
endofinput :: ParsecT Sources u m ()
endofinput = ParsecT Sources u m () -> ParsecT Sources u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
blankline ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m ()
skipSpaces ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
trim :: Text -> Text
trim = (Char -> Bool) -> Text -> Text
T.dropAround (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'\n')
htmlAttrToPandoc :: [Attribute Text] -> Attr
htmlAttrToPandoc :: [Attribute Text] -> Attr
htmlAttrToPandoc [Attribute Text]
attrs = (Text
ident, [Text]
classes, [Attribute 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 -> [Attribute Text] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"id" [Attribute 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 -> [Attribute Text] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"class" [Attribute Text]
attrs
keyvals :: [Attribute Text]
keyvals = [(Text
k,Text
v) | (Text
k,Text
v) <- [Attribute Text]
attrs, Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"id" Bool -> Bool -> Bool
&& Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"class"]
parseHtmlContentWithAttrs :: PandocMonad m
=> Text -> TWParser m a -> TWParser m (Attr, [a])
parseHtmlContentWithAttrs :: Text -> TWParser m a -> TWParser m (Attr, [a])
parseHtmlContentWithAttrs Text
tag TWParser m a
parser = do
(Attr
attr, Text
content) <- Text -> TWParser m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Attr, Text)
htmlElement Text
tag
[a]
parsedContent <- ParsecT Sources ParserState m [a]
-> ParsecT Sources ParserState m [a]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m [a]
-> ParsecT Sources ParserState m [a])
-> ParsecT Sources ParserState m [a]
-> ParsecT Sources ParserState m [a]
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Sources ParserState m [a]
parseContent Text
content
(Attr, [a]) -> TWParser m (Attr, [a])
forall (m :: * -> *) a. Monad m => a -> m a
return (Attr
attr, [a]
parsedContent)
where
parseContent :: Text -> ParsecT Sources ParserState m [a]
parseContent = ParsecT Sources ParserState m [a]
-> Text -> ParsecT Sources ParserState m [a]
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParserT Sources u m a -> Text -> ParserT Sources u m a
parseFromString' (ParsecT Sources ParserState m [a]
-> Text -> ParsecT Sources ParserState m [a])
-> ParsecT Sources ParserState m [a]
-> Text
-> ParsecT Sources ParserState m [a]
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m [a]
-> ParsecT Sources ParserState m [a]
forall (m :: * -> *) a.
PandocMonad m =>
TWParser m a -> TWParser m a
nested (ParsecT Sources ParserState m [a]
-> ParsecT Sources ParserState m [a])
-> ParsecT Sources ParserState m [a]
-> ParsecT Sources ParserState m [a]
forall a b. (a -> b) -> a -> b
$ TWParser m a
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [a]
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 TWParser m a
parser ParsecT Sources ParserState m ()
forall u. ParsecT Sources u m ()
endOfContent
endOfContent :: ParsecT Sources u m ()
endOfContent = ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
blankline ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m ()
skipSpaces ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
parseCharHtmlContentWithAttrs :: PandocMonad m
=> Text -> TWParser m Char -> TWParser m (Attr, Text)
parseCharHtmlContentWithAttrs :: Text -> TWParser m Char -> TWParser m (Attr, Text)
parseCharHtmlContentWithAttrs Text
tag = ((Attr, String) -> (Attr, Text))
-> ParsecT Sources ParserState m (Attr, String)
-> TWParser m (Attr, Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Attr, String) -> (Attr, Text)
forall a. (a, String) -> (a, Text)
go (ParsecT Sources ParserState m (Attr, String)
-> TWParser m (Attr, Text))
-> (TWParser m Char
-> ParsecT Sources ParserState m (Attr, String))
-> TWParser m Char
-> TWParser m (Attr, Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text
-> TWParser m Char -> ParsecT Sources ParserState m (Attr, String)
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m (Attr, [a])
parseHtmlContentWithAttrs Text
tag
where
go :: (a, String) -> (a, Text)
go (a
x, String
y) = (a
x, String -> Text
T.pack String
y)
parseHtmlContent :: PandocMonad m => Text -> TWParser m a -> TWParser m [a]
parseHtmlContent :: Text -> TWParser m a -> TWParser m [a]
parseHtmlContent Text
tag TWParser m a
p = (Attr, [a]) -> [a]
forall a b. (a, b) -> b
snd ((Attr, [a]) -> [a])
-> ParsecT Sources ParserState m (Attr, [a]) -> TWParser m [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> TWParser m a -> ParsecT Sources ParserState m (Attr, [a])
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m (Attr, [a])
parseHtmlContentWithAttrs Text
tag TWParser m a
p
parseTWiki :: PandocMonad m => TWParser m Pandoc
parseTWiki :: TWParser m Pandoc
parseTWiki =
Blocks -> Pandoc
B.doc (Blocks -> Pandoc) -> ([Blocks] -> Blocks) -> [Blocks] -> Pandoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Pandoc)
-> ParsecT Sources ParserState m [Blocks] -> TWParser m Pandoc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Blocks
-> ParsecT Sources ParserState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
block TWParser m Pandoc
-> ParsecT Sources ParserState m () -> TWParser m Pandoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m ()
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces TWParser m Pandoc
-> ParsecT Sources ParserState m () -> TWParser m Pandoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
block :: PandocMonad m => TWParser m B.Blocks
block :: TWParser m Blocks
block = do
Blocks
res <- Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT Sources ParserState m () -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
blankline
TWParser m Blocks -> TWParser m Blocks -> TWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TWParser m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
blockElements
TWParser m Blocks -> TWParser m Blocks -> TWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TWParser m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
para
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
blankline
Text -> ParsecT Sources ParserState 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
res)
Blocks -> TWParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
res
blockElements :: PandocMonad m => TWParser m B.Blocks
blockElements :: TWParser m Blocks
blockElements = [TWParser m Blocks] -> TWParser m Blocks
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ TWParser m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
separator
, TWParser m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
header
, TWParser m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
verbatim
, TWParser m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
literal
, Text -> TWParser m Blocks
forall (m :: * -> *). PandocMonad m => Text -> TWParser m Blocks
list Text
""
, TWParser m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
table
, TWParser m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
blockQuote
, TWParser m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
noautolink
]
separator :: PandocMonad m => TWParser m B.Blocks
separator :: TWParser m Blocks
separator = Text -> TWParser m Blocks -> TWParser m Blocks
forall (m :: * -> *) a. Text -> TWParser m a -> TWParser m a
tryMsg Text
"separator" (TWParser m Blocks -> TWParser m Blocks)
-> TWParser m Blocks -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$ String -> ParsecT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"---" ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline ParsecT Sources ParserState m Char
-> TWParser m Blocks -> TWParser m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> TWParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
B.horizontalRule
header :: PandocMonad m => TWParser m B.Blocks
= Text -> TWParser m Blocks -> TWParser m Blocks
forall (m :: * -> *) a. Text -> TWParser m a -> TWParser m a
tryMsg Text
"header" (TWParser m Blocks -> TWParser m Blocks)
-> TWParser m Blocks -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$ do
String -> ParsecT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"---"
Int
level <- String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (String -> Int)
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'+')
Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Sources ParserState m ())
-> Bool -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ Int
level Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
6
[Text]
classes <- [Text]
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources 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 [] (ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text])
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ String -> ParsecT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"!!" ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Text] -> ParsecT Sources ParserState m [Text]
forall (m :: * -> *) a. Monad m => a -> m a
return [Text
"unnumbered"]
ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m ()
skipSpaces
Inlines
content <- 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] -> Inlines)
-> ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [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 Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
Attr
attr <- Attr -> Inlines -> ParserT Sources ParserState 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
"", [Text]
classes, []) Inlines
content
Blocks -> TWParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> TWParser m Blocks) -> Blocks -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$ Attr -> Int -> Inlines -> Blocks
B.headerWith Attr
attr Int
level Inlines
content
verbatim :: PandocMonad m => TWParser m B.Blocks
verbatim :: TWParser m Blocks
verbatim = (Attr -> Text -> Blocks) -> (Attr, Text) -> Blocks
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Attr -> Text -> Blocks
B.codeBlockWith ((Attr, Text) -> Blocks)
-> ParsecT Sources ParserState m (Attr, Text) -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> ParsecT Sources ParserState m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Attr, Text)
htmlElement Text
"verbatim" ParsecT Sources ParserState m (Attr, Text)
-> ParsecT Sources ParserState m (Attr, Text)
-> ParsecT Sources ParserState m (Attr, Text)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> ParsecT Sources ParserState m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Attr, Text)
htmlElement Text
"pre")
literal :: PandocMonad m => TWParser m B.Blocks
literal :: TWParser m Blocks
literal = (Attr, Text) -> Blocks
forall a a b.
(Eq a, IsString a) =>
((a, b, [(a, Text)]), Text) -> Blocks
rawBlock ((Attr, Text) -> Blocks)
-> ParsecT Sources ParserState m (Attr, Text) -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT Sources ParserState m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Attr, Text)
htmlElement Text
"literal"
where
format :: (a, b, [(a, a)]) -> a
format (a
_, b
_, [(a, a)]
kvs) = a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe a
"html" (Maybe a -> a) -> Maybe a -> a
forall a b. (a -> b) -> a -> b
$ a -> [(a, a)] -> Maybe a
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup a
"format" [(a, a)]
kvs
rawBlock :: ((a, b, [(a, Text)]), Text) -> Blocks
rawBlock ((a, b, [(a, Text)])
attrs, Text
content) = Text -> Text -> Blocks
B.rawBlock ((a, b, [(a, Text)]) -> Text
forall a a a b.
(Eq a, IsString a, IsString a) =>
(a, b, [(a, a)]) -> a
format (a, b, [(a, Text)])
attrs) Text
content
list :: PandocMonad m => Text -> TWParser m B.Blocks
list :: Text -> TWParser m Blocks
list Text
prefix = [TWParser m Blocks] -> TWParser m Blocks
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ Text -> TWParser m Blocks
forall (m :: * -> *). PandocMonad m => Text -> TWParser m Blocks
bulletList Text
prefix
, Text -> TWParser m Blocks
forall (m :: * -> *). PandocMonad m => Text -> TWParser m Blocks
orderedList Text
prefix
, Text -> TWParser m Blocks
forall (m :: * -> *). PandocMonad m => Text -> TWParser m Blocks
definitionList Text
prefix]
definitionList :: PandocMonad m => Text -> TWParser m B.Blocks
definitionList :: Text -> TWParser m Blocks
definitionList Text
prefix = Text -> TWParser m Blocks -> TWParser m Blocks
forall (m :: * -> *) a. Text -> TWParser m a -> TWParser m a
tryMsg Text
"definitionList" (TWParser m Blocks -> TWParser m Blocks)
-> TWParser m Blocks -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$ do
[Text]
indent <- ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text])
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
" ") ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
"$ "
[(Inlines, [Blocks])]
elements <- ParsecT Sources ParserState m (Inlines, [Blocks])
-> ParsecT Sources ParserState m [(Inlines, [Blocks])]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Sources ParserState m (Inlines, [Blocks])
-> ParsecT Sources ParserState m [(Inlines, [Blocks])])
-> ParsecT Sources ParserState m (Inlines, [Blocks])
-> ParsecT Sources ParserState m [(Inlines, [Blocks])]
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Sources ParserState m (Inlines, [Blocks])
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Inlines, [Blocks])
parseDefinitionListItem (Text
prefix Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
T.concat [Text]
indent)
Blocks -> TWParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> TWParser m Blocks) -> Blocks -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$ [(Inlines, [Blocks])] -> Blocks
B.definitionList [(Inlines, [Blocks])]
elements
where
parseDefinitionListItem :: PandocMonad m
=> Text -> TWParser m (B.Inlines, [B.Blocks])
parseDefinitionListItem :: Text -> TWParser m (Inlines, [Blocks])
parseDefinitionListItem Text
indent = do
Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr (Text
indent Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"$ ") ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m ()
skipSpaces
[Inlines]
term <- ParserT Sources ParserState m Inlines
-> ParserT Sources ParserState m String
-> ParserT Sources 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 Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline (ParserT Sources ParserState m String
-> ParserT Sources ParserState m [Inlines])
-> ParserT Sources ParserState m String
-> ParserT Sources ParserState m [Inlines]
forall a b. (a -> b) -> a -> b
$ String -> ParserT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
": "
Blocks
line <- Text -> ParserT Sources ParserState m String -> TWParser m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Show a) =>
Text -> TWParser m a -> TWParser m Blocks
listItemLine Text
indent (ParserT Sources ParserState m String -> TWParser m Blocks)
-> ParserT Sources ParserState m String -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$ String -> ParserT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"$ "
(Inlines, [Blocks]) -> TWParser m (Inlines, [Blocks])
forall (m :: * -> *) a. Monad m => a -> m a
return ([Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat [Inlines]
term, [Blocks
line])
bulletList :: PandocMonad m => Text -> TWParser m B.Blocks
bulletList :: Text -> TWParser m Blocks
bulletList Text
prefix = Text -> TWParser m Blocks -> TWParser m Blocks
forall (m :: * -> *) a. Text -> TWParser m a -> TWParser m a
tryMsg Text
"bulletList" (TWParser m Blocks -> TWParser m Blocks)
-> TWParser m Blocks -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$
Text -> TWParser m Char -> TWParser m Char -> TWParser m Blocks
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m Char -> TWParser m a -> TWParser m Blocks
parseList Text
prefix (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'*') (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
' ')
orderedList :: PandocMonad m => Text -> TWParser m B.Blocks
orderedList :: Text -> TWParser m Blocks
orderedList Text
prefix = Text -> TWParser m Blocks -> TWParser m Blocks
forall (m :: * -> *) a. Text -> TWParser m a -> TWParser m a
tryMsg Text
"orderedList" (TWParser m Blocks -> TWParser m Blocks)
-> TWParser m Blocks -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$
Text -> TWParser m Char -> TWParser m String -> TWParser m Blocks
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m Char -> TWParser m a -> TWParser m Blocks
parseList Text
prefix (String -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
oneOf String
"1iIaA") (String -> TWParser m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
". ")
parseList :: PandocMonad m
=> Text -> TWParser m Char -> TWParser m a -> TWParser m B.Blocks
parseList :: Text -> TWParser m Char -> TWParser m a -> TWParser m Blocks
parseList Text
prefix TWParser m Char
marker TWParser m a
delim = do
(Text
indent, Char
style) <- ParsecT Sources ParserState m (Text, Char)
-> ParsecT Sources ParserState m (Text, Char)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources ParserState m (Text, Char)
-> ParsecT Sources ParserState m (Text, Char))
-> ParsecT Sources ParserState m (Text, Char)
-> ParsecT Sources ParserState m (Text, Char)
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (Text, Char)
-> ParsecT Sources ParserState m (Text, Char)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m (Text, Char)
listStyle ParsecT Sources ParserState m (Text, Char)
-> TWParser m a -> ParsecT Sources ParserState m (Text, Char)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* TWParser m a
delim
[Blocks]
blocks <- TWParser m Blocks -> ParsecT Sources ParserState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (TWParser m Blocks -> ParsecT Sources ParserState m [Blocks])
-> TWParser m Blocks -> ParsecT Sources ParserState m [Blocks]
forall a b. (a -> b) -> a -> b
$ Text -> TWParser m Char -> TWParser m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Show a) =>
Text -> TWParser m a -> TWParser m Blocks
parseListItem (Text
prefix Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
indent) (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
style TWParser m Char -> TWParser m a -> TWParser m Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* TWParser m a
delim)
Blocks -> TWParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> TWParser m Blocks) -> Blocks -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$ case Char
style of
Char
'1' -> ListAttributes -> [Blocks] -> Blocks
B.orderedListWith (Int
1, ListNumberStyle
DefaultStyle, ListNumberDelim
DefaultDelim) [Blocks]
blocks
Char
'i' -> ListAttributes -> [Blocks] -> Blocks
B.orderedListWith (Int
1, ListNumberStyle
LowerRoman, ListNumberDelim
DefaultDelim) [Blocks]
blocks
Char
'I' -> ListAttributes -> [Blocks] -> Blocks
B.orderedListWith (Int
1, ListNumberStyle
UpperRoman, ListNumberDelim
DefaultDelim) [Blocks]
blocks
Char
'a' -> ListAttributes -> [Blocks] -> Blocks
B.orderedListWith (Int
1, ListNumberStyle
LowerAlpha, ListNumberDelim
DefaultDelim) [Blocks]
blocks
Char
'A' -> ListAttributes -> [Blocks] -> Blocks
B.orderedListWith (Int
1, ListNumberStyle
UpperAlpha, ListNumberDelim
DefaultDelim) [Blocks]
blocks
Char
_ -> [Blocks] -> Blocks
B.bulletList [Blocks]
blocks
where
listStyle :: ParsecT Sources ParserState m (Text, Char)
listStyle = do
[Text]
indent <- ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text])
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
" "
Char
style <- TWParser m Char
marker
(Text, Char) -> ParsecT Sources ParserState m (Text, Char)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Text] -> Text
T.concat [Text]
indent, Char
style)
parseListItem :: (PandocMonad m, Show a)
=> Text -> TWParser m a -> TWParser m B.Blocks
parseListItem :: Text -> TWParser m a -> TWParser m Blocks
parseListItem Text
prefix TWParser m a
marker = Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Sources ParserState m Text -> TWParser m a -> TWParser m a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m a
marker TWParser m a -> TWParser m Blocks -> TWParser m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Text -> TWParser m a -> TWParser m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Show a) =>
Text -> TWParser m a -> TWParser m Blocks
listItemLine Text
prefix TWParser m a
marker
listItemLine :: (PandocMonad m, Show a)
=> Text -> TWParser m a -> TWParser m B.Blocks
listItemLine :: Text -> TWParser m a -> TWParser m Blocks
listItemLine Text
prefix TWParser m a
marker = [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Blocks)
-> ParsecT Sources ParserState m [Blocks] -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Sources ParserState m Text
lineContent ParsecT Sources ParserState m Text
-> (Text -> ParsecT Sources ParserState m [Blocks])
-> ParsecT Sources ParserState m [Blocks]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> ParsecT Sources ParserState m [Blocks]
parseContent)
where
lineContent :: ParsecT Sources ParserState m Text
lineContent = do
Text
content <- ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParserT Sources st m Text
anyLine
Maybe Text
continuation <- ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState 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 Sources ParserState m Text
listContinuation
Text -> ParsecT Sources ParserState m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> ParsecT Sources ParserState m Text)
-> Text -> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ Text -> Text
filterSpaces Text
content Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> (Text -> Text) -> Maybe Text -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" (Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) Maybe Text
continuation
filterSpaces :: Text -> Text
filterSpaces = (Char -> Bool) -> Text -> Text
T.dropWhileEnd (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ')
listContinuation :: ParsecT Sources ParserState m Text
listContinuation = TWParser m a -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Sources ParserState m Text -> TWParser m a -> TWParser m a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m a
marker) ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
String -> ParsecT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
" " ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Text
lineContent
parseContent :: Text -> ParsecT Sources ParserState m [Blocks]
parseContent = ParsecT Sources ParserState m [Blocks]
-> Text -> ParsecT Sources ParserState m [Blocks]
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParserT Sources u m a -> Text -> ParserT Sources u m a
parseFromString' (ParsecT Sources ParserState m [Blocks]
-> Text -> ParsecT Sources ParserState m [Blocks])
-> ParsecT Sources ParserState m [Blocks]
-> Text
-> ParsecT Sources ParserState m [Blocks]
forall a b. (a -> b) -> a -> b
$ TWParser m Blocks -> ParsecT Sources ParserState m [Blocks]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (TWParser m Blocks -> ParsecT Sources ParserState m [Blocks])
-> TWParser m Blocks -> ParsecT Sources ParserState m [Blocks]
forall a b. (a -> b) -> a -> b
$ TWParser m Blocks
nestedList TWParser m Blocks -> TWParser m Blocks -> TWParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TWParser m Blocks
parseInline
parseInline :: TWParser m Blocks
parseInline = Inlines -> Blocks
B.plain (Inlines -> Blocks)
-> ([Inlines] -> Inlines) -> [Inlines] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Blocks)
-> ParsecT Sources ParserState m [Inlines] -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Sources ParserState m Inlines
-> ParserT Sources ParserState m Char
-> ParsecT Sources 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 Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline (ParserT Sources ParserState m Char
forall u. ParsecT Sources u m Char
lastNewline ParserT Sources ParserState m Char
-> ParserT Sources ParserState m Char
-> ParserT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Sources ParserState m Char
newlineBeforeNestedList)
nestedList :: TWParser m Blocks
nestedList = Text -> TWParser m Blocks
forall (m :: * -> *). PandocMonad m => Text -> TWParser m Blocks
list Text
prefix
lastNewline :: ParsecT Sources u m Char
lastNewline = ParsecT Sources u m Char -> ParsecT Sources u m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m Char -> ParsecT Sources u m Char)
-> ParsecT Sources u m Char -> ParsecT Sources u m Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\n' ParsecT Sources u m Char
-> ParsecT Sources u m () -> ParsecT Sources u m Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
newlineBeforeNestedList :: ParserT Sources ParserState m Char
newlineBeforeNestedList = ParserT Sources ParserState m Char
-> ParserT Sources ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParserT Sources ParserState m Char
-> ParserT Sources ParserState m Char)
-> ParserT Sources ParserState m Char
-> ParserT Sources ParserState m Char
forall a b. (a -> b) -> a -> b
$ Char -> ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\n' ParserT Sources ParserState m Char
-> TWParser m Blocks -> ParserT Sources ParserState m Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* TWParser m Blocks -> TWParser m Blocks
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead TWParser m Blocks
nestedList
table :: PandocMonad m => TWParser m B.Blocks
table :: TWParser m Blocks
table = TWParser m Blocks -> TWParser m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Blocks -> TWParser m Blocks)
-> TWParser m Blocks -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$ do
Maybe ([(Alignment, ColWidth)], [Blocks])
tableHead <- ParsecT Sources ParserState m ([(Alignment, ColWidth)], [Blocks])
-> ParsecT
Sources ParserState m (Maybe ([(Alignment, ColWidth)], [Blocks]))
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ([((Alignment, ColWidth), Blocks)]
-> ([(Alignment, ColWidth)], [Blocks])
forall a b. [(a, b)] -> ([a], [b])
unzip ([((Alignment, ColWidth), Blocks)]
-> ([(Alignment, ColWidth)], [Blocks]))
-> ParsecT Sources ParserState m [((Alignment, ColWidth), Blocks)]
-> ParsecT
Sources ParserState m ([(Alignment, ColWidth)], [Blocks])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Sources ParserState m ((Alignment, ColWidth), Blocks)
-> ParserT Sources ParserState m Char
-> ParsecT Sources ParserState m [((Alignment, ColWidth), 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 ParserT Sources ParserState m ((Alignment, ColWidth), Blocks)
forall (m :: * -> *).
PandocMonad m =>
TWParser m ((Alignment, ColWidth), Blocks)
tableParseHeader ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline)
[[Blocks]]
rows <- ParsecT Sources ParserState m [Blocks]
-> ParsecT Sources 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 Sources ParserState m [Blocks]
forall (m :: * -> *). PandocMonad m => TWParser m [Blocks]
tableParseRow
Blocks -> TWParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> TWParser m Blocks) -> Blocks -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$ Inlines
-> [[Blocks]] -> ([(Alignment, ColWidth)], [Blocks]) -> Blocks
buildTable Inlines
forall a. Monoid a => a
mempty [[Blocks]]
rows (([(Alignment, ColWidth)], [Blocks]) -> Blocks)
-> ([(Alignment, ColWidth)], [Blocks]) -> Blocks
forall a b. (a -> b) -> a -> b
$ ([(Alignment, ColWidth)], [Blocks])
-> Maybe ([(Alignment, ColWidth)], [Blocks])
-> ([(Alignment, ColWidth)], [Blocks])
forall a. a -> Maybe a -> a
fromMaybe ([[Blocks]] -> [(Alignment, ColWidth)]
forall (t :: * -> *) a.
Foldable t =>
[t a] -> [(Alignment, ColWidth)]
align [[Blocks]]
rows, [[Blocks]] -> [Blocks]
forall (t :: * -> *) a a. (Foldable t, Monoid a) => [t a] -> [a]
columns [[Blocks]]
rows) Maybe ([(Alignment, ColWidth)], [Blocks])
tableHead
where
buildTable :: Inlines
-> [[Blocks]] -> ([(Alignment, ColWidth)], [Blocks]) -> Blocks
buildTable Inlines
caption [[Blocks]]
rows ([(Alignment, ColWidth)]
aligns, [Blocks]
heads)
= Caption
-> [(Alignment, ColWidth)]
-> 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)
[(Alignment, ColWidth)]
aligns
(Attr -> [Row] -> TableHead
TableHead Attr
nullAttr ([Row] -> TableHead) -> [Row] -> TableHead
forall a b. (a -> b) -> a -> b
$ [Blocks] -> [Row]
toHeaderRow [Blocks]
heads)
[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 [])
align :: [t a] -> [(Alignment, ColWidth)]
align [t a]
rows = Int -> (Alignment, ColWidth) -> [(Alignment, ColWidth)]
forall a. Int -> a -> [a]
replicate ([t a] -> Int
forall (t :: * -> *) a. Foldable t => [t a] -> Int
columCount [t a]
rows) (Alignment
AlignDefault, ColWidth
ColWidthDefault)
columns :: [t a] -> [a]
columns [t a]
rows = Int -> a -> [a]
forall a. Int -> a -> [a]
replicate ([t a] -> Int
forall (t :: * -> *) a. Foldable t => [t a] -> Int
columCount [t a]
rows) a
forall a. Monoid a => a
mempty
columCount :: [t a] -> Int
columCount [t a]
rows = t a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (t a -> Int) -> t a -> Int
forall a b. (a -> b) -> a -> b
$ [t a] -> t a
forall a. [a] -> a
head [t a]
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
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)]
tableParseHeader :: PandocMonad m => TWParser m ((Alignment, ColWidth), B.Blocks)
= TWParser m ((Alignment, ColWidth), Blocks)
-> TWParser m ((Alignment, ColWidth), Blocks)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m ((Alignment, ColWidth), Blocks)
-> TWParser m ((Alignment, ColWidth), Blocks))
-> TWParser m ((Alignment, ColWidth), Blocks)
-> TWParser m ((Alignment, ColWidth), Blocks)
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|'
Int
leftSpaces <- String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (String -> Int)
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'*'
Blocks
content <- ParsecT Sources ParserState m Char -> TWParser m Blocks
forall (m :: * -> *) a.
PandocMonad m =>
TWParser m a -> TWParser m Blocks
tableColumnContent (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'*' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m ()
skipSpaces ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|')
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'*'
Int
rightSpaces <- String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (String -> Int)
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => TWParser m Char
tableEndOfRow
((Alignment, ColWidth), Blocks)
-> TWParser m ((Alignment, ColWidth), Blocks)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Int -> (Alignment, ColWidth)
forall a. (Ord a, Num a) => a -> a -> (Alignment, ColWidth)
tableAlign Int
leftSpaces Int
rightSpaces, Blocks
content)
where
tableAlign :: a -> a -> (Alignment, ColWidth)
tableAlign a
left a
right
| a
left a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
2 Bool -> Bool -> Bool
&& a
left a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
right = (Alignment
AlignCenter, ColWidth
ColWidthDefault)
| a
left a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
right = (Alignment
AlignRight, ColWidth
ColWidthDefault)
| Bool
otherwise = (Alignment
AlignLeft, ColWidth
ColWidthDefault)
tableParseRow :: PandocMonad m => TWParser m [B.Blocks]
tableParseRow :: TWParser m [Blocks]
tableParseRow = ParserT Sources ParserState m Blocks
-> ParserT Sources ParserState m Char -> TWParser 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 ParserT Sources ParserState m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
tableParseColumn ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
tableParseColumn :: PandocMonad m => TWParser m B.Blocks
tableParseColumn :: TWParser m Blocks
tableParseColumn = Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m ()
skipSpaces ParsecT Sources ParserState m ()
-> TWParser m Blocks -> TWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
ParsecT Sources ParserState m Char -> TWParser m Blocks
forall (m :: * -> *) a.
PandocMonad m =>
TWParser m a -> TWParser m Blocks
tableColumnContent (ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m ()
skipSpaces ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|')
TWParser m Blocks
-> ParsecT Sources ParserState m () -> TWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m ()
skipSpaces TWParser m Blocks
-> ParsecT Sources ParserState m () -> TWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => TWParser m Char
tableEndOfRow
tableEndOfRow :: PandocMonad m => TWParser m Char
tableEndOfRow :: TWParser m Char
tableEndOfRow = TWParser m Char -> TWParser m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (TWParser m Char -> TWParser m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Char -> TWParser m Char)
-> TWParser m Char -> TWParser m Char
forall a b. (a -> b) -> a -> b
$ Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' TWParser m Char -> TWParser m Char -> TWParser m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\n') TWParser m Char -> TWParser m Char -> TWParser m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|'
tableColumnContent :: PandocMonad m => TWParser m a -> TWParser m B.Blocks
tableColumnContent :: TWParser m a -> TWParser m Blocks
tableColumnContent TWParser m a
end = Inlines -> Blocks
B.plain (Inlines -> Blocks)
-> ([Inlines] -> Inlines) -> [Inlines] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Blocks)
-> ParsecT Sources ParserState m [Inlines] -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
-> TWParser m a -> ParsecT Sources ParserState m [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 Sources ParserState m Inlines
content (TWParser m a -> TWParser m a
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (TWParser m a -> TWParser m a) -> TWParser m a -> TWParser m a
forall a b. (a -> b) -> a -> b
$ TWParser m a -> TWParser m a
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try TWParser m a
end)
where
content :: ParsecT Sources ParserState m Inlines
content = ParsecT Sources ParserState m Inlines
forall u. ParsecT Sources u m Inlines
continuation ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline
continuation :: ParsecT Sources u m Inlines
continuation = ParsecT Sources u m Inlines -> ParsecT Sources u m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m Inlines -> ParsecT Sources u m Inlines)
-> ParsecT Sources u m Inlines -> ParsecT Sources u m Inlines
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\' ParsecT Sources u m Char
-> ParsecT Sources u m Char -> ParsecT Sources u m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline ParsecT Sources u m Char
-> ParsecT Sources u m Inlines -> ParsecT Sources u m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> ParsecT Sources u m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
blockQuote :: PandocMonad m => TWParser m B.Blocks
blockQuote :: TWParser m Blocks
blockQuote = Blocks -> Blocks
B.blockQuote (Blocks -> Blocks) -> ([Blocks] -> Blocks) -> [Blocks] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Blocks)
-> ParsecT Sources ParserState m [Blocks] -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> TWParser m Blocks -> ParsecT Sources ParserState m [Blocks]
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m [a]
parseHtmlContent Text
"blockquote" TWParser m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
block
noautolink :: PandocMonad m => TWParser m B.Blocks
noautolink :: TWParser m Blocks
noautolink = do
(Attr
_, Text
content) <- Text -> TWParser m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Attr, Text)
htmlElement Text
"noautolink"
ParserState
st <- ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
ParserState -> ParsecT Sources ParserState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState (ParserState -> ParsecT Sources ParserState m ())
-> ParserState -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState
st{ stateAllowLinks :: Bool
stateAllowLinks = Bool
False }
[Blocks]
blocks <- ParsecT Sources ParserState m [Blocks]
-> ParsecT Sources ParserState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m [Blocks]
-> ParsecT Sources ParserState m [Blocks])
-> ParsecT Sources ParserState m [Blocks]
-> ParsecT Sources ParserState m [Blocks]
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Sources ParserState m [Blocks]
parseContent Text
content
ParserState -> ParsecT Sources ParserState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState (ParserState -> ParsecT Sources ParserState m ())
-> ParserState -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState
st{ stateAllowLinks :: Bool
stateAllowLinks = Bool
True }
Blocks -> TWParser m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> TWParser m Blocks) -> Blocks -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$ [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat [Blocks]
blocks
where
parseContent :: Text -> ParsecT Sources ParserState m [Blocks]
parseContent = ParsecT Sources ParserState m [Blocks]
-> Text -> ParsecT Sources ParserState m [Blocks]
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParserT Sources u m a -> Text -> ParserT Sources u m a
parseFromString' (ParsecT Sources ParserState m [Blocks]
-> Text -> ParsecT Sources ParserState m [Blocks])
-> ParsecT Sources ParserState m [Blocks]
-> Text
-> ParsecT Sources ParserState m [Blocks]
forall a b. (a -> b) -> a -> b
$ TWParser m Blocks -> ParsecT Sources ParserState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many TWParser m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
block
para :: PandocMonad m => TWParser m B.Blocks
para :: TWParser m Blocks
para = 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 ([Inlines] -> Blocks)
-> ParsecT Sources ParserState m [Inlines] -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Sources ParserState m Inlines
-> ParserT Sources ParserState m ()
-> ParsecT Sources 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 Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline ParserT Sources ParserState m ()
endOfParaElement
where
endOfParaElement :: ParserT Sources ParserState m ()
endOfParaElement = ParserT Sources ParserState m ()
-> ParserT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParserT Sources ParserState m ()
-> ParserT Sources ParserState m ())
-> ParserT Sources ParserState m ()
-> ParserT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserT Sources ParserState m ()
forall u. ParsecT Sources u m ()
endOfInput ParserT Sources ParserState m ()
-> ParserT Sources ParserState m ()
-> ParserT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Sources ParserState m ()
forall u. ParsecT Sources u m ()
endOfPara ParserT Sources ParserState m ()
-> ParserT Sources ParserState m ()
-> ParserT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Sources ParserState m ()
newBlockElement
endOfInput :: ParsecT Sources u m ()
endOfInput = ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
blankline ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m ()
skipSpaces ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
endOfPara :: ParsecT Sources u m ()
endOfPara = ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ ParserT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
blankline ParserT Sources u m Char
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParserT Sources u m Char -> ParsecT Sources u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParserT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
blankline
newBlockElement :: ParserT Sources ParserState m ()
newBlockElement = ParserT Sources ParserState m ()
-> ParserT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParserT Sources ParserState m ()
-> ParserT Sources ParserState m ())
-> ParserT Sources ParserState m ()
-> ParserT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
blankline ParserT Sources ParserState m Char
-> ParserT Sources ParserState m ()
-> ParserT Sources ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m Blocks -> ParserT Sources ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void TWParser m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
blockElements
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
inline :: PandocMonad m => TWParser m B.Inlines
inline :: TWParser m Inlines
inline = [TWParser m Inlines] -> TWParser m Inlines
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
whitespace
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
br
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
macro
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
strong
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
strongHtml
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
strongAndEmph
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
emph
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
emphHtml
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
boldCode
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
smart
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
link
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
htmlComment
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
code
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
codeHtml
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
nop
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
autoLink
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
str
, TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
symbol
] TWParser m Inlines -> String -> TWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"inline"
whitespace :: PandocMonad m => TWParser m B.Inlines
whitespace :: TWParser m Inlines
whitespace = TWParser m Inlines
lb TWParser m Inlines -> TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TWParser m Inlines
forall u. ParsecT Sources u m Inlines
regsp
where lb :: TWParser m Inlines
lb = TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Inlines -> TWParser m Inlines)
-> TWParser m Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar ParsecT Sources ParserState m ()
-> TWParser m Inlines -> TWParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
linebreak TWParser m Inlines -> TWParser m Inlines -> TWParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> TWParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.space
regsp :: ParsecT Sources u m Inlines
regsp = ParsecT Sources u m Inlines -> ParsecT Sources u m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m Inlines -> ParsecT Sources u m Inlines)
-> ParsecT Sources u m Inlines -> ParsecT Sources u m Inlines
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar ParsecT Sources u m ()
-> ParsecT Sources u m Inlines -> ParsecT Sources u m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> ParsecT Sources u m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.space
br :: PandocMonad m => TWParser m B.Inlines
br :: TWParser m Inlines
br = TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Inlines -> TWParser m Inlines)
-> TWParser m Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ String -> ParsecT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"%BR%" ParsecT Sources ParserState m String
-> TWParser m Inlines -> TWParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> TWParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.linebreak
linebreak :: PandocMonad m => TWParser m B.Inlines
linebreak :: TWParser m Inlines
linebreak = ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
-> ParsecT Sources 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 Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline ParsecT Sources ParserState m ()
-> TWParser m Inlines -> TWParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (TWParser m Inlines
forall u. ParsecT Sources u m Inlines
lastNewline TWParser m Inlines -> TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TWParser m Inlines
innerNewline)
where lastNewline :: ParsecT Sources u m Inlines
lastNewline = ParsecT Sources u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParsecT Sources u m ()
-> ParsecT Sources u m Inlines -> ParsecT Sources u m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> ParsecT Sources u m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
innerNewline :: TWParser m Inlines
innerNewline = Inlines -> TWParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.space
between :: (Monoid c, PandocMonad m, Show b)
=> TWParser m a -> TWParser m b -> (TWParser m b -> TWParser m c)
-> TWParser m c
between :: TWParser m a
-> TWParser m b -> (TWParser m b -> TWParser m c) -> TWParser m c
between TWParser m a
start TWParser m b
end TWParser m b -> TWParser m c
p =
[c] -> c
forall a. Monoid a => [a] -> a
mconcat ([c] -> c) -> ParsecT Sources ParserState m [c] -> TWParser m c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m [c]
-> ParsecT Sources ParserState m [c]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m a
start TWParser m a
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Inlines
-> ParsecT Sources 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 Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
whitespace ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [c]
-> ParsecT Sources ParserState m [c]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m c -> TWParser m b -> ParsecT Sources ParserState m [c]
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 (TWParser m b -> TWParser m c
p TWParser m b
end) TWParser m b
end)
enclosed :: (Monoid b, PandocMonad m, Show a)
=> TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed :: TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed TWParser m a
sep TWParser m a -> TWParser m b
p = TWParser m a
-> TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
forall c (m :: * -> *) b a.
(Monoid c, PandocMonad m, Show b) =>
TWParser m a
-> TWParser m b -> (TWParser m b -> TWParser m c) -> TWParser m c
between TWParser m a
sep (TWParser m a -> TWParser m a
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m a -> TWParser m a) -> TWParser m a -> TWParser m a
forall a b. (a -> b) -> a -> b
$ TWParser m a
sep TWParser m a -> ParsecT Sources ParserState m () -> TWParser m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m ()
forall u. ParsecT Sources u m ()
endMarker) TWParser m a -> TWParser m b
p
where
endMarker :: ParsecT Sources u m ()
endMarker = ParsecT Sources u m () -> ParsecT Sources u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m Inlines -> ParsecT Sources u m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Sources u m Inlines
forall u. ParsecT Sources u m Inlines
endSpace ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources u m Char -> ParsecT Sources u m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (String -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
oneOf String
".,!?:)|") ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
endSpace :: ParsecT Sources u m Inlines
endSpace = (ParserT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar ParserT Sources u m Char
-> ParserT Sources u m Char -> ParserT Sources u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline) ParserT Sources u m Char
-> ParsecT Sources u m Inlines -> ParsecT Sources u m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> ParsecT Sources u m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.space
macro :: PandocMonad m => TWParser m B.Inlines
macro :: TWParser m Inlines
macro = TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
macroWithParameters TWParser m Inlines -> TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TWParser m Inlines
withoutParameters
where
withoutParameters :: TWParser m Inlines
withoutParameters = Text -> Inlines
emptySpan (Text -> Inlines)
-> ParsecT Sources ParserState m Text -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m Char
-> (TWParser m Char -> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'%') (ParsecT Sources ParserState m Text
-> TWParser m Char -> ParsecT Sources ParserState m Text
forall a b. a -> b -> a
const ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => TWParser m Text
macroName)
emptySpan :: Text -> Inlines
emptySpan Text
name = Text -> [Attribute Text] -> Inlines -> Inlines
buildSpan Text
name [] Inlines
forall a. Monoid a => a
mempty
macroWithParameters :: PandocMonad m => TWParser m B.Inlines
macroWithParameters :: TWParser m Inlines
macroWithParameters = TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Inlines -> TWParser m Inlines)
-> TWParser m Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'%'
Text
name <- TWParser m Text
forall (m :: * -> *). PandocMonad m => TWParser m Text
macroName
(Text
content, [Attribute Text]
kvs) <- TWParser m (Text, [Attribute Text])
forall (m :: * -> *).
PandocMonad m =>
TWParser m (Text, [Attribute Text])
attributes
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'%'
Inlines -> TWParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> TWParser m Inlines) -> Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> [Attribute Text] -> Inlines -> Inlines
buildSpan Text
name [Attribute Text]
kvs (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
content
buildSpan :: Text -> [(Text, Text)] -> B.Inlines -> B.Inlines
buildSpan :: Text -> [Attribute Text] -> Inlines -> Inlines
buildSpan Text
className [Attribute Text]
kvs = Attr -> Inlines -> Inlines
B.spanWith Attr
attrs
where
attrs :: Attr
attrs = (Text
"", [Text
"twiki-macro", Text
className] [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [Text]
additionalClasses, [Attribute Text]
kvsWithoutClasses)
additionalClasses :: [Text]
additionalClasses = [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 -> [Attribute Text] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"class" [Attribute Text]
kvs
kvsWithoutClasses :: [Attribute Text]
kvsWithoutClasses = [(Text
k,Text
v) | (Text
k,Text
v) <- [Attribute Text]
kvs, Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"class"]
macroName :: PandocMonad m => TWParser m Text
macroName :: TWParser m Text
macroName = do
Char
first <- ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
letter
String
rest <- ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m String)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m String
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'_'
Text -> TWParser m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> TWParser m Text) -> Text -> TWParser m Text
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Char
firstChar -> String -> String
forall a. a -> [a] -> [a]
:String
rest
attributes :: PandocMonad m => TWParser m (Text, [(Text, Text)])
attributes :: TWParser m (Text, [Attribute Text])
attributes = (Either Text (Attribute Text)
-> (Text, [Attribute Text]) -> (Text, [Attribute Text]))
-> (Text, [Attribute Text])
-> [Either Text (Attribute Text)]
-> (Text, [Attribute Text])
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((Text -> (Text, [Attribute Text]) -> (Text, [Attribute Text]))
-> (Attribute Text
-> (Text, [Attribute Text]) -> (Text, [Attribute Text]))
-> Either Text (Attribute Text)
-> (Text, [Attribute Text])
-> (Text, [Attribute Text])
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Text -> (Text, [Attribute Text]) -> (Text, [Attribute Text])
forall a b.
(Eq a, IsString a, Semigroup a) =>
a -> (a, b) -> (a, b)
mkContent Attribute Text
-> (Text, [Attribute Text]) -> (Text, [Attribute Text])
forall a a. a -> (a, [a]) -> (a, [a])
mkKvs) (Text
"", [])
([Either Text (Attribute Text)] -> (Text, [Attribute Text]))
-> ParsecT Sources ParserState m [Either Text (Attribute Text)]
-> TWParser m (Text, [Attribute Text])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'{' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m ()
forall u. ParsecT Sources u m ()
spnl ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [Either Text (Attribute Text)]
-> ParsecT Sources ParserState m [Either Text (Attribute Text)]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m (Either Text (Attribute Text))
-> ParsecT Sources ParserState m [Either Text (Attribute Text)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Sources ParserState m (Either Text (Attribute Text))
forall (m :: * -> *).
PandocMonad m =>
TWParser m (Either Text (Attribute Text))
attribute ParsecT Sources ParserState m (Either Text (Attribute Text))
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Either Text (Attribute Text))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m ()
forall u. ParsecT Sources u m ()
spnl) ParsecT Sources ParserState m [Either Text (Attribute Text)]
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Either Text (Attribute Text)]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'}')
where
spnl :: ParsecT Sources u m ()
spnl = ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar ParsecT Sources u m Char
-> ParsecT Sources u m Char -> ParsecT Sources u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline)
mkContent :: a -> (a, b) -> (a, b)
mkContent a
c (a
"", b
kvs) = (a
c, b
kvs)
mkContent a
c (a
rest, b
kvs) = (a
c a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
" " a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
rest, b
kvs)
mkKvs :: a -> (a, [a]) -> (a, [a])
mkKvs a
kv (a
cont, [a]
rest) = (a
cont, a
kv a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
rest)
attribute :: PandocMonad m => TWParser m (Either Text (Text, Text))
attribute :: TWParser m (Either Text (Attribute Text))
attribute = TWParser m (Either Text (Attribute Text))
forall a. ParsecT Sources ParserState m (Either a (Attribute Text))
withKey TWParser m (Either Text (Attribute Text))
-> TWParser m (Either Text (Attribute Text))
-> TWParser m (Either Text (Attribute Text))
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TWParser m (Either Text (Attribute Text))
forall b. ParsecT Sources ParserState m (Either Text b)
withoutKey
where
withKey :: ParsecT Sources ParserState m (Either a (Attribute Text))
withKey = ParsecT Sources ParserState m (Either a (Attribute Text))
-> ParsecT Sources ParserState m (Either a (Attribute Text))
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Either a (Attribute Text))
-> ParsecT Sources ParserState m (Either a (Attribute Text)))
-> ParsecT Sources ParserState m (Either a (Attribute Text))
-> ParsecT Sources ParserState m (Either a (Attribute Text))
forall a b. (a -> b) -> a -> b
$ do
Text
key <- TWParser m Text
forall (m :: * -> *). PandocMonad m => TWParser m Text
macroName
Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'='
(Attribute Text -> Either a (Attribute Text))
-> Text -> Text -> Either a (Attribute Text)
forall a b c. ((a, b) -> c) -> a -> b -> c
curry Attribute Text -> Either a (Attribute Text)
forall a b. b -> Either a b
Right Text
key (Text -> Either a (Attribute Text))
-> TWParser m Text
-> ParsecT Sources ParserState m (Either a (Attribute Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> TWParser m Text
parseValue Bool
False
withoutKey :: ParsecT Sources ParserState m (Either Text b)
withoutKey = ParsecT Sources ParserState m (Either Text b)
-> ParsecT Sources ParserState m (Either Text b)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Either Text b)
-> ParsecT Sources ParserState m (Either Text b))
-> ParsecT Sources ParserState m (Either Text b)
-> ParsecT Sources ParserState m (Either Text b)
forall a b. (a -> b) -> a -> b
$ Text -> Either Text b
forall a b. a -> Either a b
Left (Text -> Either Text b)
-> TWParser m Text -> ParsecT Sources ParserState m (Either Text b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> TWParser m Text
parseValue Bool
True
parseValue :: Bool -> TWParser m Text
parseValue Bool
allowSpaces = Text -> Text
fromEntities (Text -> Text) -> TWParser m Text -> TWParser m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (TWParser m Text
withQuotes TWParser m Text -> TWParser m Text -> TWParser m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool -> TWParser m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Bool -> ParserT s st m Text
withoutQuotes Bool
allowSpaces)
withQuotes :: TWParser m Text
withQuotes = ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> (ParsecT Sources ParserState m Char -> TWParser m Text)
-> TWParser m Text
forall c (m :: * -> *) b a.
(Monoid c, PandocMonad m, Show b) =>
TWParser m a
-> TWParser m b -> (TWParser m b -> TWParser m c) -> TWParser m c
between (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"') (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"') (\ParsecT Sources ParserState m Char
_ -> Int -> ParsecT Sources ParserState m Char -> TWParser m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 (ParsecT Sources ParserState m Char -> TWParser m Text)
-> ParsecT Sources ParserState m Char -> TWParser m Text
forall a b. (a -> b) -> a -> b
$ String -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf [Char
'"'])
withoutQuotes :: Bool -> ParserT s st m Text
withoutQuotes Bool
allowSpaces
| Bool
allowSpaces = ParserT s st m Char -> ParserT s st m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char (ParserT s st m Char -> ParserT s st m Text)
-> ParserT s st m Char -> ParserT s st m Text
forall a b. (a -> b) -> a -> b
$ String -> ParserT s st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf String
"}"
| Bool
otherwise = ParserT s st m Char -> ParserT s st m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char (ParserT s st m Char -> ParserT s st m Text)
-> ParserT s st m Char -> ParserT s st m Text
forall a b. (a -> b) -> a -> b
$ String -> ParserT s st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf String
" }"
nestedInlines :: (Show a, PandocMonad m)
=> TWParser m a -> TWParser m B.Inlines
nestedInlines :: TWParser m a -> TWParser m Inlines
nestedInlines TWParser m a
end = TWParser m Inlines
innerSpace TWParser m Inlines -> TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TWParser m Inlines
nestedInline
where
innerSpace :: TWParser m Inlines
innerSpace = TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Inlines -> TWParser m Inlines)
-> TWParser m Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
whitespace TWParser m Inlines
-> ParsecT Sources ParserState m () -> TWParser m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* TWParser m a -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy TWParser m a
end
nestedInline :: TWParser m Inlines
nestedInline = TWParser m Inlines -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
whitespace ParsecT Sources ParserState m ()
-> TWParser m Inlines -> TWParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m Inlines -> TWParser m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
TWParser m a -> TWParser m a
nested TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline
strong :: PandocMonad m => TWParser m B.Inlines
strong :: TWParser m Inlines
strong = TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Inlines -> TWParser m Inlines)
-> TWParser m Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.strong (Inlines -> Inlines) -> TWParser m Inlines -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m Char
-> (TWParser m Char -> TWParser m Inlines) -> TWParser m Inlines
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'*') TWParser m Char -> TWParser m Inlines
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m Inlines
nestedInlines
strongHtml :: PandocMonad m => TWParser m B.Inlines
strongHtml :: TWParser m Inlines
strongHtml = 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 Sources ParserState m [Inlines] -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text
-> TWParser m Inlines -> ParsecT Sources ParserState m [Inlines]
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m [a]
parseHtmlContent Text
"strong" TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m [Inlines]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text
-> TWParser m Inlines -> ParsecT Sources ParserState m [Inlines]
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m [a]
parseHtmlContent Text
"b" TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline)
strongAndEmph :: PandocMonad m => TWParser m B.Inlines
strongAndEmph :: TWParser m Inlines
strongAndEmph = TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Inlines -> TWParser m Inlines)
-> TWParser m Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.emph (Inlines -> Inlines) -> (Inlines -> Inlines) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.strong (Inlines -> Inlines) -> TWParser m Inlines -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m String
-> (TWParser m String -> TWParser m Inlines) -> TWParser m Inlines
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed (String -> TWParser m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"__") TWParser m String -> TWParser m Inlines
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m Inlines
nestedInlines
emph :: PandocMonad m => TWParser m B.Inlines
emph :: TWParser m Inlines
emph = TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Inlines -> TWParser m Inlines)
-> TWParser m Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.emph (Inlines -> Inlines) -> TWParser m Inlines -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m Char
-> (TWParser m Char -> TWParser m Inlines) -> TWParser m Inlines
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'_')
(\TWParser m Char
p -> TWParser m Char -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|') ParsecT Sources ParserState m ()
-> TWParser m Inlines -> TWParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m Char -> TWParser m Inlines
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m Inlines
nestedInlines TWParser m Char
p)
emphHtml :: PandocMonad m => TWParser m B.Inlines
emphHtml :: TWParser m Inlines
emphHtml = 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 Sources ParserState m [Inlines] -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text
-> TWParser m Inlines -> ParsecT Sources ParserState m [Inlines]
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m [a]
parseHtmlContent Text
"em" TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m [Inlines]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text
-> TWParser m Inlines -> ParsecT Sources ParserState m [Inlines]
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m [a]
parseHtmlContent Text
"i" TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline)
nestedString :: (Show a, PandocMonad m)
=> TWParser m a -> TWParser m Text
nestedString :: TWParser m a -> TWParser m Text
nestedString TWParser m a
end = TWParser m Text
innerSpace TWParser m Text -> TWParser m Text -> TWParser m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int -> ParsecT Sources ParserState m Char -> TWParser m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
nonspaceChar
where
innerSpace :: TWParser m Text
innerSpace = TWParser m Text -> TWParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Text -> TWParser m Text)
-> TWParser m Text -> TWParser m Text
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Char -> TWParser m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar TWParser m Text
-> ParsecT Sources ParserState m () -> TWParser m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* TWParser m a -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy TWParser m a
end
boldCode :: PandocMonad m => TWParser m B.Inlines
boldCode :: TWParser m Inlines
boldCode = TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Inlines -> TWParser m Inlines)
-> TWParser m Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.strong (Inlines -> Inlines) -> (Text -> Inlines) -> Text -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.code (Text -> Inlines) -> (Text -> Text) -> Text -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
fromEntities (Text -> Inlines)
-> ParsecT Sources ParserState m Text -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m String
-> (TWParser m String -> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed (String -> TWParser m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"==") TWParser m String -> ParsecT Sources ParserState m Text
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m Text
nestedString
htmlComment :: PandocMonad m => TWParser m B.Inlines
= (Tag Text -> Bool)
-> ParserT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParserT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isCommentTag ParserT Sources ParserState m (Tag Text, Text)
-> TWParser m Inlines -> TWParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> TWParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
code :: PandocMonad m => TWParser m B.Inlines
code :: TWParser m Inlines
code = TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Inlines -> TWParser m Inlines)
-> TWParser m Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.code (Text -> Inlines) -> (Text -> Text) -> Text -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
fromEntities (Text -> Inlines)
-> ParsecT Sources ParserState m Text -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m Char
-> (TWParser m Char -> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'=') TWParser m Char -> ParsecT Sources ParserState m Text
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m Text
nestedString
codeHtml :: PandocMonad m => TWParser m B.Inlines
codeHtml :: TWParser m Inlines
codeHtml = do
(Attr
attrs, Text
content) <- Text -> TWParser m Char -> TWParser m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m Char -> TWParser m (Attr, Text)
parseCharHtmlContentWithAttrs Text
"code" TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar
Inlines -> TWParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> TWParser m Inlines) -> Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Inlines
B.codeWith Attr
attrs (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text
fromEntities Text
content
autoLink :: PandocMonad m => TWParser m B.Inlines
autoLink :: TWParser m Inlines
autoLink = TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Inlines -> TWParser m Inlines)
-> TWParser m Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
ParserState
state <- ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Sources ParserState m ())
-> Bool -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState -> Bool
stateAllowLinks ParserState
state
(Text
text, Text
url) <- ParsecT Sources ParserState m (Attribute Text)
parseLink
Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Sources ParserState m ())
-> Bool -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ Char -> Bool
checkLink (Text -> Char
T.last Text
url)
Inlines -> TWParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> TWParser m Inlines) -> Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Attribute Text -> Inlines
makeLink (Text
text, Text
url)
where
parseLink :: ParsecT Sources ParserState m (Attribute Text)
parseLink = TWParser m Inlines -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
nop ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Attribute Text)
-> ParsecT Sources ParserState m (Attribute Text)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (ParsecT Sources ParserState m (Attribute Text)
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m (Attribute Text)
uri ParsecT Sources ParserState m (Attribute Text)
-> ParsecT Sources ParserState m (Attribute Text)
-> ParsecT Sources ParserState m (Attribute Text)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Attribute Text)
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m (Attribute Text)
emailAddress)
makeLink :: Attribute Text -> Inlines
makeLink (Text
text, Text
url) = Text -> Text -> Inlines -> Inlines
B.link Text
url Text
"" (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
text
checkLink :: Char -> Bool
checkLink Char
c
| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'/' = Bool
True
| Bool
otherwise = Char -> Bool
isAlphaNum Char
c
str :: PandocMonad m => TWParser m B.Inlines
str :: TWParser m Inlines
str = Text -> Inlines
B.str (Text -> Inlines)
-> ParsecT Sources ParserState m Text -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParserT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int
-> ParserT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 ParserT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
characterReference)
nop :: PandocMonad m => TWParser m B.Inlines
nop :: TWParser m Inlines
nop = TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Inlines -> TWParser m Inlines)
-> TWParser m Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Sources ParserState m Char
forall u. ParsecT Sources u m Char
exclamation ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Sources ParserState m Text
forall st. ParserT Sources st m Text
nopTag) ParsecT Sources ParserState m ()
-> TWParser m Inlines -> TWParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m Inlines
forall st. ParsecT Sources st m Inlines
followContent
where
exclamation :: ParsecT Sources u m Char
exclamation = Char -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'!'
nopTag :: ParserT Sources st m Text
nopTag = Text -> ParserT Sources st m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
stringAnyCase Text
"<nop>"
followContent :: ParsecT Sources st m Inlines
followContent = Text -> Inlines
B.str (Text -> Inlines) -> (Text -> Text) -> Text -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
fromEntities (Text -> Inlines)
-> ParsecT Sources st m Text -> ParsecT Sources st m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Sources st m Char -> ParsecT Sources st m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParserT Sources st m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
nonspaceChar
symbol :: PandocMonad m => TWParser m B.Inlines
symbol :: TWParser m Inlines
symbol = Text -> Inlines
B.str (Text -> Inlines)
-> ParsecT Sources ParserState m Text -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
nonspaceChar
smart :: PandocMonad m => TWParser m B.Inlines
smart :: TWParser m Inlines
smart = TWParser m Inlines -> TWParser m Inlines
forall st (m :: * -> *) s.
(HasReaderOptions st, HasLastStrPosition st, HasQuoteContext st m,
Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Inlines -> ParserT s st m Inlines
smartPunctuation TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline
link :: PandocMonad m => TWParser m B.Inlines
link :: TWParser m Inlines
link = TWParser m Inlines -> TWParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m Inlines -> TWParser m Inlines)
-> TWParser m Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
ParserState
st <- ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Sources ParserState m ())
-> Bool -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState -> Bool
stateAllowLinks ParserState
st
ParserState -> ParsecT Sources ParserState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState (ParserState -> ParsecT Sources ParserState m ())
-> ParserState -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState
st{ stateAllowLinks :: Bool
stateAllowLinks = Bool
False }
(Text
url, Text
title, Inlines
content) <- TWParser m (Text, Text, Inlines)
forall (m :: * -> *).
PandocMonad m =>
TWParser m (Text, Text, Inlines)
linkText
ParserState -> ParsecT Sources ParserState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState (ParserState -> ParsecT Sources ParserState m ())
-> ParserState -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState
st{ stateAllowLinks :: Bool
stateAllowLinks = Bool
True }
Inlines -> TWParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> TWParser m Inlines) -> Inlines -> TWParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link Text
url Text
title Inlines
content
linkText :: PandocMonad m => TWParser m (Text, Text, B.Inlines)
linkText :: TWParser m (Text, Text, Inlines)
linkText = do
String -> ParsecT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"[["
Text
url <- String -> Text
T.pack (String -> Text)
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Sources ParserState m Char
-> ParserT Sources ParserState m Char
-> ParsecT Sources ParserState m String
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 Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (Char -> ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']')
Inlines
content <- Inlines
-> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Text -> Inlines
B.str Text
url) ([Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m [Inlines]
linkContent)
Char -> ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']'
(Text, Text, Inlines) -> TWParser m (Text, Text, Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
url, Text
"", Inlines
content)
where
linkContent :: ParsecT Sources ParserState m [Inlines]
linkContent = Char -> ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'[' ParserT Sources ParserState m Char
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParserT Sources ParserState m Char
-> ParserT Sources ParserState m Char
-> ParsecT Sources ParserState m String
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 Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (Char -> ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']') ParsecT Sources ParserState m String
-> (String -> ParsecT Sources ParserState m [Inlines])
-> ParsecT Sources ParserState m [Inlines]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> ParsecT Sources ParserState m [Inlines]
parseLinkContent (Text -> ParsecT Sources ParserState m [Inlines])
-> (String -> Text)
-> String
-> ParsecT Sources ParserState m [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
parseLinkContent :: Text -> ParsecT Sources ParserState m [Inlines]
parseLinkContent = ParsecT Sources ParserState m [Inlines]
-> Text -> ParsecT Sources ParserState m [Inlines]
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParserT Sources u m a -> Text -> ParserT Sources u m a
parseFromString' (ParsecT Sources ParserState m [Inlines]
-> Text -> ParsecT Sources ParserState m [Inlines])
-> ParsecT Sources ParserState m [Inlines]
-> Text
-> ParsecT Sources ParserState m [Inlines]
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m [Inlines]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline