{-# LANGUAGE FlexibleContexts  #-}
{-# LANGUAGE OverloadedStrings #-}
{- |
   Module      : Text.Pandoc.Readers.TWiki
   Copyright   : Copyright (C) 2014 Alexander Sulfrian
   License     : GNU GPL, version 2 or above

   Maintainer  : Alexander Sulfrian <alexander.sulfrian@fu-berlin.de>
   Stability   : alpha
   Portability : portable

Conversion of twiki text to 'Pandoc' document.
-}
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 (crFilter, tshow)
import Text.Pandoc.XML (fromEntities)

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

type TWParser = ParserT Text ParserState

--
-- utility functions
--

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 Text ParserState m ParserState
-> ParsecT Text ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>  ParsecT Text ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Bool -> ParsecT Text ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text ParserState m ())
-> Bool -> ParsecT Text 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 Text ParserState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
-> (ParserState -> ParserState) -> ParsecT Text 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 Text ParserState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
-> (ParserState -> ParserState) -> ParsecT Text 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 Text ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParserT Text 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 Text ParserState m String
-> ParsecT Text ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m ()
-> ParsecT Text 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 Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParsecT Text ParserState m ()
endtag ParsecT Text ParserState m ()
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text ParserState m ()
forall u. ParsecT Text 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 Text ParserState m ()
endtag     = ParserT Text ParserState m (Tag Text, Text)
-> ParsecT Text ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParserT Text ParserState m (Tag Text, Text)
 -> ParsecT Text ParserState m ())
-> ParserT Text ParserState m (Tag Text, Text)
-> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ (Tag Text -> Bool) -> ParserT Text ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParserT Text 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 Text u m ()
endofinput = ParsecT Text u m () -> ParsecT Text u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Text u m () -> ParsecT Text u m ())
-> ParsecT Text u m () -> ParsecT Text u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Text u m () -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m () -> ParsecT Text u m ())
-> ParsecT Text u m () -> ParsecT Text u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Text u m Char -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
    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 Text ParserState m [a] -> ParsecT Text ParserState m [a]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m [a] -> ParsecT Text ParserState m [a])
-> ParsecT Text ParserState m [a] -> ParsecT Text ParserState m [a]
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Text 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 Text ParserState m [a]
parseContent = ParsecT Text ParserState m [a]
-> Text -> ParsecT Text ParserState m [a]
forall s (m :: * -> *) u a.
(Stream s m Char, IsString s, HasLastStrPosition u) =>
ParserT s u m a -> Text -> ParserT s u m a
parseFromString' (ParsecT Text ParserState m [a]
 -> Text -> ParsecT Text ParserState m [a])
-> ParsecT Text ParserState m [a]
-> Text
-> ParsecT Text ParserState m [a]
forall a b. (a -> b) -> a -> b
$ ParsecT Text ParserState m [a] -> ParsecT Text ParserState m [a]
forall (m :: * -> *) a.
PandocMonad m =>
TWParser m a -> TWParser m a
nested (ParsecT Text ParserState m [a] -> ParsecT Text ParserState m [a])
-> ParsecT Text ParserState m [a] -> ParsecT Text ParserState m [a]
forall a b. (a -> b) -> a -> b
$ TWParser m a
-> ParsecT Text ParserState m () -> ParsecT Text 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 Text ParserState m ()
forall u. ParsecT Text u m ()
endOfContent
    endOfContent :: ParsecT Text u m ()
endOfContent = ParsecT Text u m () -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m () -> ParsecT Text u m ())
-> ParsecT Text u m () -> ParsecT Text u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Text u m Char -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof

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 Text 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 Text ParserState m (Attr, String)
 -> TWParser m (Attr, Text))
-> (TWParser m Char -> ParsecT Text 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 Text 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 Text ParserState m (Attr, [a]) -> TWParser m [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> TWParser m a -> ParsecT Text ParserState m (Attr, [a])
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m (Attr, [a])
parseHtmlContentWithAttrs Text
tag TWParser m a
p

--
-- main parser
--

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 Text ParserState m [Blocks] -> TWParser m Pandoc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Blocks
-> ParsecT Text ParserState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text ParserState m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
block TWParser m Pandoc
-> ParsecT Text ParserState m () -> TWParser m Pandoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text ParserState m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
spaces TWParser m Pandoc
-> ParsecT Text ParserState m () -> TWParser m Pandoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text ParserState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof


--
-- block parsers
--

block :: PandocMonad m => TWParser m B.Blocks
block :: TWParser m Blocks
block = do
  Blocks
res <- Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT Text ParserState m () -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u 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 Text ParserState m Char -> ParsecT Text ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline
  Text -> ParsecT Text 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 Text ParserState m String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"---" ParsecT Text ParserState m String
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline ParsecT Text 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
header :: TWParser m Blocks
header = 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 Text ParserState m String
forall s (m :: * -> *) u.
Stream s m 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 Text ParserState m String
-> ParsecT Text ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Char
-> ParsecT Text 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 Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'+')
  Bool -> ParsecT Text ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text ParserState m ())
-> Bool -> ParsecT Text 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 Text ParserState m [Text]
-> ParsecT Text ParserState m [Text]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] (ParsecT Text ParserState m [Text]
 -> ParsecT Text ParserState m [Text])
-> ParsecT Text ParserState m [Text]
-> ParsecT Text ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ String -> ParsecT Text ParserState m String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"!!" ParsecT Text ParserState m String
-> ParsecT Text ParserState m [Text]
-> ParsecT Text ParserState m [Text]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Text] -> ParsecT Text ParserState m [Text]
forall (m :: * -> *) a. Monad m => a -> m a
return [Text
"unnumbered"]
  ParsecT Text ParserState m ()
forall s (m :: * -> *) st. Stream s m 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 Text ParserState m [Inlines]
-> ParsecT Text ParserState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Inlines
-> ParsecT Text ParserState m Char
-> ParsecT Text 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 Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline
  Attr
attr <- Attr -> Inlines -> ParserT Text 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 Text ParserState m (Attr, Text) -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> ParsecT Text ParserState m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Attr, Text)
htmlElement Text
"verbatim" ParsecT Text ParserState m (Attr, Text)
-> ParsecT Text ParserState m (Attr, Text)
-> ParsecT Text 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 Text 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 Text ParserState m (Attr, Text) -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT Text 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 Text ParserState m [Text]
-> ParsecT Text 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 Text ParserState m [Text]
 -> ParsecT Text ParserState m [Text])
-> ParsecT Text ParserState m [Text]
-> ParsecT Text ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Text ParserState m Text
-> ParsecT Text ParserState m [Text]
-> ParsecT Text ParserState m [Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text ParserState m Text
-> ParsecT Text 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 Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
"   ") ParsecT Text ParserState m [Text]
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m [Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
"$ "
  [(Inlines, [Blocks])]
elements <- ParsecT Text ParserState m (Inlines, [Blocks])
-> ParsecT Text ParserState m [(Inlines, [Blocks])]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Text ParserState m (Inlines, [Blocks])
 -> ParsecT Text ParserState m [(Inlines, [Blocks])])
-> ParsecT Text ParserState m (Inlines, [Blocks])
-> ParsecT Text ParserState m [(Inlines, [Blocks])]
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Text 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 Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr (Text
indent Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"$ ") ParsecT Text ParserState m Text
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces
      [Inlines]
term <- ParserT Text ParserState m Inlines
-> ParserT Text ParserState m String
-> ParserT Text ParserState m [Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till ParserT Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline (ParserT Text ParserState m String
 -> ParserT Text ParserState m [Inlines])
-> ParserT Text ParserState m String
-> ParserT Text ParserState m [Inlines]
forall a b. (a -> b) -> a -> b
$ String -> ParserT Text ParserState m String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
": "
      Blocks
line <- Text -> ParserT Text ParserState m String -> TWParser m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Show a) =>
Text -> TWParser m a -> TWParser m Blocks
listItemLine Text
indent (ParserT Text ParserState m String -> TWParser m Blocks)
-> ParserT Text ParserState m String -> TWParser m Blocks
forall a b. (a -> b) -> a -> b
$ String -> ParserT Text ParserState m String
forall s (m :: * -> *) u.
Stream s m 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 s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'*') (Char -> TWParser m Char
forall s (m :: * -> *) u.
Stream s m 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 s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
"1iIaA") (String -> TWParser m String
forall s (m :: * -> *) u.
Stream s m 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 Text ParserState m (Text, Char)
-> ParsecT Text 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 Text ParserState m (Text, Char)
 -> ParsecT Text ParserState m (Text, Char))
-> ParsecT Text ParserState m (Text, Char)
-> ParsecT Text ParserState m (Text, Char)
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Text ParserState m Text
-> ParsecT Text ParserState m (Text, Char)
-> ParsecT Text ParserState m (Text, Char)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text ParserState m (Text, Char)
listStyle ParsecT Text ParserState m (Text, Char)
-> TWParser m a -> ParsecT Text 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 Text ParserState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (TWParser m Blocks -> ParsecT Text ParserState m [Blocks])
-> TWParser m Blocks -> ParsecT Text 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 s (m :: * -> *) u.
Stream s m 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 Text ParserState m (Text, Char)
listStyle = do
      [Text]
indent <- ParsecT Text ParserState m Text
-> ParsecT Text 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 Text ParserState m Text
 -> ParsecT Text ParserState m [Text])
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
"   "
      Char
style <- TWParser m Char
marker
      (Text, Char) -> ParsecT Text 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 Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Text 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 Text ParserState m [Blocks] -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Text ParserState m Text
lineContent ParsecT Text ParserState m Text
-> (Text -> ParsecT Text ParserState m [Blocks])
-> ParsecT Text ParserState m [Blocks]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> ParsecT Text ParserState m [Blocks]
parseContent)
  where
    lineContent :: ParsecT Text ParserState m Text
lineContent = do
      Text
content <- ParsecT Text ParserState m Text
forall (m :: * -> *) st. Monad m => ParserT Text st m Text
anyLine
      Maybe Text
continuation <- ParsecT Text ParserState m Text
-> ParsecT Text 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 Text ParserState m Text
listContinuation
      Text -> ParsecT Text ParserState m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> ParsecT Text ParserState m Text)
-> Text -> ParsecT Text 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 Text ParserState m Text
listContinuation = TWParser m a -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Text -> ParsecT Text ParserState m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Text 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 Text ParserState m ()
-> ParsecT Text ParserState m String
-> ParsecT Text ParserState m String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
                       String -> ParsecT Text ParserState m String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"   " ParsecT Text ParserState m String
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Text
lineContent
    parseContent :: Text -> ParsecT Text ParserState m [Blocks]
parseContent = ParsecT Text ParserState m [Blocks]
-> Text -> ParsecT Text ParserState m [Blocks]
forall s (m :: * -> *) u a.
(Stream s m Char, IsString s, HasLastStrPosition u) =>
ParserT s u m a -> Text -> ParserT s u m a
parseFromString' (ParsecT Text ParserState m [Blocks]
 -> Text -> ParsecT Text ParserState m [Blocks])
-> ParsecT Text ParserState m [Blocks]
-> Text
-> ParsecT Text ParserState m [Blocks]
forall a b. (a -> b) -> a -> b
$ TWParser m Blocks -> ParsecT Text ParserState m [Blocks]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (TWParser m Blocks -> ParsecT Text ParserState m [Blocks])
-> TWParser m Blocks -> ParsecT Text 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 Text ParserState m [Inlines] -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text ParserState m Inlines
-> ParserT Text ParserState m Char
-> ParsecT Text ParserState m [Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till ParserT Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline (ParserT Text ParserState m Char
forall u. ParsecT Text u m Char
lastNewline ParserT Text ParserState m Char
-> ParserT Text ParserState m Char
-> ParserT Text ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text 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 Text u m Char
lastNewline = ParsecT Text u m Char -> ParsecT Text u m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m Char -> ParsecT Text u m Char)
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Text u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\n' ParsecT Text u m Char
-> ParsecT Text u m () -> ParsecT Text u m Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
    newlineBeforeNestedList :: ParserT Text ParserState m Char
newlineBeforeNestedList = ParserT Text ParserState m Char -> ParserT Text ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParserT Text ParserState m Char
 -> ParserT Text ParserState m Char)
-> ParserT Text ParserState m Char
-> ParserT Text ParserState m Char
forall a b. (a -> b) -> a -> b
$ Char -> ParserT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\n' ParserT Text ParserState m Char
-> TWParser m Blocks -> ParserT Text 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 Text ParserState m ([(Alignment, ColWidth)], [Blocks])
-> ParsecT
     Text 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 Text ParserState m [((Alignment, ColWidth), Blocks)]
-> ParsecT Text ParserState m ([(Alignment, ColWidth)], [Blocks])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text ParserState m ((Alignment, ColWidth), Blocks)
-> ParserT Text ParserState m Char
-> ParsecT Text 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 Text ParserState m ((Alignment, ColWidth), Blocks)
forall (m :: * -> *).
PandocMonad m =>
TWParser m ((Alignment, ColWidth), Blocks)
tableParseHeader ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline)
  [[Blocks]]
rows <- ParsecT Text ParserState m [Blocks]
-> ParsecT Text ParserState m [[Blocks]]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Text ParserState m [Blocks]
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)
tableParseHeader :: TWParser m ((Alignment, ColWidth), Blocks)
tableParseHeader = 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 Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m 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 Text ParserState m String
-> ParsecT Text ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
  Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'*'
  Blocks
content <- ParsecT Text ParserState m Char -> TWParser m Blocks
forall (m :: * -> *) a.
PandocMonad m =>
TWParser m a -> TWParser m Blocks
tableColumnContent (Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'*' ParsecT Text ParserState m Char
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParsecT Text ParserState m ()
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|')
  Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m 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 Text ParserState m String
-> ParsecT Text ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar
  ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Text 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 Text ParserState m Blocks
-> ParserT Text 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 Text ParserState m Blocks
forall (m :: * -> *). PandocMonad m => TWParser m Blocks
tableParseColumn ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline

tableParseColumn :: PandocMonad m => TWParser m B.Blocks
tableParseColumn :: TWParser m Blocks
tableParseColumn = Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|' ParsecT Text ParserState m Char
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text ParserState m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParsecT Text ParserState m ()
-> TWParser m Blocks -> TWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                   ParsecT Text ParserState m Char -> TWParser m Blocks
forall (m :: * -> *) a.
PandocMonad m =>
TWParser m a -> TWParser m Blocks
tableColumnContent (ParsecT Text ParserState m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParsecT Text ParserState m ()
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|')
                   TWParser m Blocks
-> ParsecT Text ParserState m () -> TWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text ParserState m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces TWParser m Blocks
-> ParsecT Text ParserState m () -> TWParser m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Text 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 s (m :: * -> *) u.
Stream s m 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 s (m :: * -> *) u.
Stream s m 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 s (m :: * -> *) u.
Stream s m 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 Text ParserState m [Inlines] -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m Inlines
-> TWParser m a -> ParsecT Text 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 Text 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 Text ParserState m Inlines
content = ParsecT Text ParserState m Inlines
forall u. ParsecT Text u m Inlines
continuation ParsecT Text ParserState m Inlines
-> ParsecT Text ParserState m Inlines
-> ParsecT Text ParserState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline
    continuation :: ParsecT Text u m Inlines
continuation = ParsecT Text u m Inlines -> ParsecT Text u m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m Inlines -> ParsecT Text u m Inlines)
-> ParsecT Text u m Inlines -> ParsecT Text u m Inlines
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Text u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\\' ParsecT Text u m Char
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline ParsecT Text u m Char
-> ParsecT Text u m Inlines -> ParsecT Text u m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> ParsecT Text u m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty

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 Text ParserState m [Blocks] -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> TWParser m Blocks -> ParsecT Text 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 Text ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  ParserState -> ParsecT Text ParserState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState (ParserState -> ParsecT Text ParserState m ())
-> ParserState -> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState
st{ stateAllowLinks :: Bool
stateAllowLinks = Bool
False }
  [Blocks]
blocks <- ParsecT Text ParserState m [Blocks]
-> ParsecT Text ParserState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m [Blocks]
 -> ParsecT Text ParserState m [Blocks])
-> ParsecT Text ParserState m [Blocks]
-> ParsecT Text ParserState m [Blocks]
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Text ParserState m [Blocks]
parseContent Text
content
  ParserState -> ParsecT Text ParserState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState (ParserState -> ParsecT Text ParserState m ())
-> ParserState -> ParsecT Text 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 Text ParserState m [Blocks]
parseContent = ParsecT Text ParserState m [Blocks]
-> Text -> ParsecT Text ParserState m [Blocks]
forall s (m :: * -> *) u a.
(Stream s m Char, IsString s, HasLastStrPosition u) =>
ParserT s u m a -> Text -> ParserT s u m a
parseFromString' (ParsecT Text ParserState m [Blocks]
 -> Text -> ParsecT Text ParserState m [Blocks])
-> ParsecT Text ParserState m [Blocks]
-> Text
-> ParsecT Text ParserState m [Blocks]
forall a b. (a -> b) -> a -> b
$ TWParser m Blocks -> ParsecT Text 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 Text ParserState m [Inlines] -> TWParser m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text ParserState m Inlines
-> ParserT Text ParserState m ()
-> ParsecT Text ParserState m [Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till ParserT Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline ParserT Text ParserState m ()
endOfParaElement
 where
   endOfParaElement :: ParserT Text ParserState m ()
endOfParaElement = ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParserT Text ParserState m () -> ParserT Text ParserState m ())
-> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserT Text ParserState m ()
forall u. ParsecT Text u m ()
endOfInput ParserT Text ParserState m ()
-> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text ParserState m ()
forall u. ParsecT Text u m ()
endOfPara ParserT Text ParserState m ()
-> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text ParserState m ()
newBlockElement
   endOfInput :: ParsecT Text u m ()
endOfInput       = ParsecT Text u m () -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m () -> ParsecT Text u m ())
-> ParsecT Text u m () -> ParsecT Text u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Text u m Char -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
   endOfPara :: ParsecT Text u m ()
endOfPara        = ParsecT Text u m () -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m () -> ParsecT Text u m ())
-> ParsecT Text u m () -> ParsecT Text u m ()
forall a b. (a -> b) -> a -> b
$ ParserT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParserT Text u m Char -> ParsecT Text u m () -> ParsecT Text u m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParserT Text u m Char -> ParsecT Text u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParserT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline
   newBlockElement :: ParserT Text ParserState m ()
newBlockElement  = ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParserT Text ParserState m () -> ParserT Text ParserState m ())
-> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
blankline ParserT Text ParserState m Char
-> ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m Blocks -> ParserT Text 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 parsers
--

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 Text 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 Text ParserState m Char -> ParsecT Text ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text 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 Text u m Inlines
regsp = ParsecT Text u m Inlines -> ParsecT Text u m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u m Inlines -> ParsecT Text u m Inlines)
-> ParsecT Text u m Inlines -> ParsecT Text u m Inlines
forall a b. (a -> b) -> a -> b
$ ParsecT Text u m Char -> ParsecT Text u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text u m ()
-> ParsecT Text u m Inlines -> ParsecT Text u m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> ParsecT Text u m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.space

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 Text ParserState m String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"%BR%" ParsecT Text 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 Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline ParsecT Text ParserState m Char
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline ParsecT Text 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 Text 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 Text u m Inlines
lastNewline  = ParsecT Text u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParsecT Text u m ()
-> ParsecT Text u m Inlines -> ParsecT Text u m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> ParsecT Text u m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
        innerNewline :: 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 Text ParserState m [c] -> TWParser m c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m [c] -> ParsecT Text 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 Text ParserState m () -> ParsecT Text ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Inlines -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
whitespace ParsecT Text ParserState m ()
-> ParsecT Text ParserState m [c] -> ParsecT Text ParserState m [c]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m c -> TWParser m b -> ParsecT Text 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 Text ParserState m () -> TWParser m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text ParserState m ()
forall u. ParsecT Text u m ()
endMarker) TWParser m a -> TWParser m b
p
  where
    endMarker :: ParsecT Text u m ()
endMarker   = ParsecT Text u m () -> ParsecT Text u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Text u m () -> ParsecT Text u m ())
-> ParsecT Text u m () -> ParsecT Text u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Text u m Inlines -> ParsecT Text u m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Text u m Inlines
forall u. ParsecT Text u m Inlines
endSpace ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text u m Char -> ParsecT Text u m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (String -> ParsecT Text u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
".,!?:)|") ParsecT Text u m () -> ParsecT Text u m () -> ParsecT Text u m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
    endSpace :: ParsecT Text u m Inlines
endSpace    = (ParserT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParserT Text u m Char
-> ParserT Text u m Char -> ParserT Text u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline) ParserT Text u m Char
-> ParsecT Text u m Inlines -> ParsecT Text u m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> ParsecT Text u m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.space

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 Text 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 Text ParserState m Text)
-> ParsecT Text 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 s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'%') (ParsecT Text ParserState m Text
-> TWParser m Char -> ParsecT Text ParserState m Text
forall a b. a -> b -> a
const ParsecT Text 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 Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m 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 Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m 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 Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter
  String
rest <- ParsecT Text ParserState m Char
-> ParsecT Text ParserState m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Text ParserState m Char
 -> ParsecT Text ParserState m String)
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m String
forall a b. (a -> b) -> a -> b
$ ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m 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 Text 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 Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'{' ParsecT Text ParserState m Char
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text ParserState m ()
forall u. ParsecT Text u m ()
spnl ParsecT Text ParserState m ()
-> ParsecT Text ParserState m [Either Text (Attribute Text)]
-> ParsecT Text ParserState m [Either Text (Attribute Text)]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text ParserState m (Either Text (Attribute Text))
-> ParsecT Text ParserState m [Either Text (Attribute Text)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Text ParserState m (Either Text (Attribute Text))
forall (m :: * -> *).
PandocMonad m =>
TWParser m (Either Text (Attribute Text))
attribute ParsecT Text ParserState m (Either Text (Attribute Text))
-> ParsecT Text ParserState m ()
-> ParsecT Text ParserState m (Either Text (Attribute Text))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text ParserState m ()
forall u. ParsecT Text u m ()
spnl) ParsecT Text ParserState m [Either Text (Attribute Text)]
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m [Either Text (Attribute Text)]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'}')
  where
    spnl :: ParsecT Text u m ()
spnl                      = ParsecT Text u m Char -> ParsecT Text u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (ParsecT Text u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar ParsecT Text u m Char
-> ParsecT Text u m Char -> ParsecT Text u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text u m Char
forall s (m :: * -> *) u. Stream s m 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 Text 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 Text ParserState m (Either Text b)
withoutKey
  where
    withKey :: ParsecT Text ParserState m (Either a (Attribute Text))
withKey = ParsecT Text ParserState m (Either a (Attribute Text))
-> ParsecT Text ParserState m (Either a (Attribute Text))
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m (Either a (Attribute Text))
 -> ParsecT Text ParserState m (Either a (Attribute Text)))
-> ParsecT Text ParserState m (Either a (Attribute Text))
-> ParsecT Text 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 Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m 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 Text 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 Text ParserState m (Either Text b)
withoutKey = ParsecT Text ParserState m (Either Text b)
-> ParsecT Text ParserState m (Either Text b)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text ParserState m (Either Text b)
 -> ParsecT Text ParserState m (Either Text b))
-> ParsecT Text ParserState m (Either Text b)
-> ParsecT Text 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 Text 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 =>
Bool -> ParserT s st m Text
withoutQuotes Bool
allowSpaces)
    withQuotes :: TWParser m Text
withQuotes             = ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
-> (ParsecT Text 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 Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'"') (Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'"') (\ParsecT Text ParserState m Char
_ -> Int -> ParsecT Text ParserState m Char -> TWParser m Text
forall s (m :: * -> *) st.
(Stream s m Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 (ParsecT Text ParserState m Char -> TWParser m Text)
-> ParsecT Text ParserState m Char -> TWParser m Text
forall a b. (a -> b) -> a -> b
$ String -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m 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 s (m :: * -> *) u.
Stream s m 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 s (m :: * -> *) u.
Stream s m 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 Text ParserState m () -> TWParser m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* TWParser m a -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy TWParser m a
end
    nestedInline :: TWParser m Inlines
nestedInline = TWParser m Inlines -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
whitespace ParsecT Text 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 s (m :: * -> *) u.
Stream s m 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 Text ParserState m [Inlines] -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> TWParser m Inlines -> ParsecT Text 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 Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> TWParser m Inlines -> ParsecT Text 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 s (m :: * -> *) u.
Stream s m 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 s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'_')
                        (\TWParser m Char
p -> TWParser m Char -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> TWParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|') ParsecT Text 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)
-- emphasis closers can't cross table cell boundaries, see #3921

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 Text ParserState m [Inlines] -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> TWParser m Inlines -> ParsecT Text 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 Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
-> ParsecT Text ParserState m [Inlines]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> TWParser m Inlines -> ParsecT Text 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 Text ParserState m Char -> TWParser m Text
forall s (m :: * -> *) st.
(Stream s m Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u 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 Text 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 Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
spaceChar TWParser m Text -> ParsecT Text ParserState m () -> TWParser m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* TWParser m a -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy 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 Text 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 Text ParserState m Text)
-> ParsecT Text 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 s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"==") TWParser m String -> ParsecT Text ParserState m Text
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m Text
nestedString

htmlComment :: PandocMonad m => TWParser m B.Inlines
htmlComment :: TWParser m Inlines
htmlComment = (Tag Text -> Bool) -> ParserT Text ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParserT Text st m (Tag Text, Text)
htmlTag Tag Text -> Bool
forall a. Tag a -> Bool
isCommentTag ParserT Text 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 Text 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 Text ParserState m Text)
-> ParsecT Text 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 s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'=') TWParser m Char -> ParsecT Text 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 s (m :: * -> *) u. Stream s m 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 Text ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Bool -> ParsecT Text ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text ParserState m ())
-> Bool -> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState -> Bool
stateAllowLinks ParserState
state
  (Text
text, Text
url) <- ParsecT Text ParserState m (Attribute Text)
parseLink
  Bool -> ParsecT Text ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text ParserState m ())
-> Bool -> ParsecT Text 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 Text ParserState m (Attribute Text)
parseLink            = TWParser m Inlines -> ParsecT Text ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
nop ParsecT Text ParserState m ()
-> ParsecT Text ParserState m (Attribute Text)
-> ParsecT Text ParserState m (Attribute Text)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (ParsecT Text ParserState m (Attribute Text)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (Attribute Text)
uri ParsecT Text ParserState m (Attribute Text)
-> ParsecT Text ParserState m (Attribute Text)
-> ParsecT Text 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 Text ParserState m (Attribute Text)
forall s (m :: * -> *) st.
Stream s m 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 Text ParserState m Text -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParserT Text ParserState m Char -> ParsecT Text ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
-> ParsecT Text ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int
-> ParserT Text ParserState m Char
-> ParsecT Text ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 ParserT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u 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 Text ParserState m Char -> ParsecT Text ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Text ParserState m Char
forall u. ParsecT Text u m Char
exclamation ParsecT Text ParserState m ()
-> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text ParserState m Text -> ParsecT Text ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Text ParserState m Text
forall st. ParserT Text st m Text
nopTag) ParsecT Text 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 Text st m Inlines
followContent
  where
    exclamation :: ParsecT Text u m Char
exclamation   = Char -> ParsecT Text u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'!'
    nopTag :: ParserT Text st m Text
nopTag        = Text -> ParserT Text st m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
stringAnyCase Text
"<nop>"
    followContent :: ParsecT Text 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 Text st m Text -> ParsecT Text st m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text st m Char -> ParsecT Text st m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParserT Text st m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
nonspaceChar

symbol :: PandocMonad m => TWParser m B.Inlines
symbol :: TWParser m Inlines
symbol = Text -> Inlines
B.str (Text -> Inlines)
-> ParsecT Text ParserState m Text -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
nonspaceChar

smart :: PandocMonad m => TWParser m B.Inlines
smart :: TWParser m Inlines
smart = do
  Extension -> ParserT Text ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_smart
  TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
doubleQuoted 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 (m :: * -> *). PandocMonad m => TWParser m Inlines
singleQuoted 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] -> 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 s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m Inlines
apostrophe
           , TWParser m Inlines
forall st s (m :: * -> *).
(HasReaderOptions st, Stream s m Char) =>
ParserT s st m Inlines
dash
           , TWParser m Inlines
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m Inlines
ellipses
           ]

singleQuoted :: PandocMonad m => TWParser m B.Inlines
singleQuoted :: TWParser m Inlines
singleQuoted = 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
  ParserT Text ParserState m ()
forall st (m :: * -> *) s.
(HasLastStrPosition st, HasQuoteContext st m, Stream s m Char) =>
ParserT s st m ()
singleQuoteStart
  QuoteContext -> TWParser m Inlines -> TWParser m Inlines
forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InSingleQuote
    (Inlines -> Inlines
B.singleQuoted (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Text ParserState m [Inlines] -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m Inlines
-> ParserT Text ParserState m ()
-> ParsecT Text ParserState m [Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till TWParser m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline ParserT Text ParserState m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
singleQuoteEnd)

doubleQuoted :: PandocMonad m => TWParser m B.Inlines
doubleQuoted :: TWParser m Inlines
doubleQuoted = 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
  ParserT Text ParserState m ()
forall st (m :: * -> *) s.
(HasQuoteContext st m, Stream s m Char) =>
ParserT s st m ()
doubleQuoteStart
  Inlines
contents <- [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Text ParserState m [Inlines] -> TWParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m Inlines -> ParsecT Text ParserState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (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
$ ParserT Text ParserState m () -> ParserT Text ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParserT Text ParserState m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
doubleQuoteEnd ParserT Text 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
inline)
  QuoteContext -> TWParser m Inlines -> TWParser m Inlines
forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InDoubleQuote (ParserT Text ParserState m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
doubleQuoteEnd ParserT Text ParserState m ()
-> 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 -> Inlines
B.doubleQuoted (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
B.trimInlines Inlines
contents))
   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
<|> Inlines -> TWParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
B.str Text
"\8220" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
B.<> Inlines
contents)

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 Text ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Bool -> ParsecT Text ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text ParserState m ())
-> Bool -> ParsecT Text ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParserState -> Bool
stateAllowLinks ParserState
st
  ParserState -> ParsecT Text ParserState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState (ParserState -> ParsecT Text ParserState m ())
-> ParserState -> ParsecT Text 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 Text ParserState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState (ParserState -> ParsecT Text ParserState m ())
-> ParserState -> ParsecT Text 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 Text ParserState m String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"[["
  Text
url <- String -> Text
T.pack (String -> Text)
-> ParsecT Text ParserState m String
-> ParsecT Text ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text ParserState m Char
-> ParserT Text ParserState m Char
-> ParsecT Text 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 Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (Char -> ParserT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']')
  Inlines
content <- Inlines
-> ParsecT Text ParserState m Inlines
-> ParsecT Text 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 Text ParserState m [Inlines]
-> ParsecT Text ParserState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text ParserState m [Inlines]
linkContent)
  Char -> ParserT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m 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 Text ParserState m [Inlines]
linkContent      = Char -> ParserT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'[' ParserT Text ParserState m Char
-> ParsecT Text ParserState m String
-> ParsecT Text ParserState m String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParserT Text ParserState m Char
-> ParserT Text ParserState m Char
-> ParsecT Text ParserState m 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 Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (Char -> ParserT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']') ParsecT Text ParserState m String
-> (String -> ParsecT Text ParserState m [Inlines])
-> ParsecT Text ParserState m [Inlines]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> ParsecT Text ParserState m [Inlines]
parseLinkContent (Text -> ParsecT Text ParserState m [Inlines])
-> (String -> Text)
-> String
-> ParsecT Text ParserState m [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
    parseLinkContent :: Text -> ParsecT Text ParserState m [Inlines]
parseLinkContent = ParsecT Text ParserState m [Inlines]
-> Text -> ParsecT Text ParserState m [Inlines]
forall s (m :: * -> *) u a.
(Stream s m Char, IsString s, HasLastStrPosition u) =>
ParserT s u m a -> Text -> ParserT s u m a
parseFromString' (ParsecT Text ParserState m [Inlines]
 -> Text -> ParsecT Text ParserState m [Inlines])
-> ParsecT Text ParserState m [Inlines]
-> Text
-> ParsecT Text ParserState m [Inlines]
forall a b. (a -> b) -> a -> b
$ ParsecT Text ParserState m Inlines
-> ParsecT Text 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 Text ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TWParser m Inlines
inline