{-# 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, isDigit, isUpper, isLower, isLetter)
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)
import Text.Pandoc.Readers.HTML (htmlTag, isCommentTag)
import Text.Pandoc.Shared (tshow)
import Text.Pandoc.XML (fromEntities)

-- | Read twiki from an input string and return a Pandoc document.
readTWiki :: (PandocMonad m, ToSources a)
          => ReaderOptions
          -> a
          -> m Pandoc
readTWiki :: forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readTWiki ReaderOptions
opts a
s = do
  let sources :: Sources
sources = Int -> Sources -> Sources
ensureFinalNewlines Int
2 (a -> Sources
forall a. ToSources a => a -> Sources
toSources a
s)
  res <- ParsecT Sources ParserState m Pandoc
-> ParserState -> Sources -> m (Either PandocError Pandoc)
forall (m :: * -> *) t st a.
(Monad m, ToSources t) =>
ParsecT Sources st m a -> st -> t -> m (Either PandocError a)
readWithM ParsecT Sources ParserState m Pandoc
forall (m :: * -> *). PandocMonad m => TWParser m Pandoc
parseTWiki ParserState
forall a. Default a => a
def{ stateOptions = opts } Sources
sources
  case res of
       Left PandocError
e  -> PandocError -> m Pandoc
forall a. PandocError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PandocError
e
       Right Pandoc
d -> Pandoc -> m Pandoc
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
d

type TWParser = ParsecT Sources ParserState

--
-- utility functions
--

tryMsg :: Text -> TWParser m a -> TWParser m a
tryMsg :: forall (m :: * -> *) a. 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

htmlElement :: PandocMonad m => Text -> TWParser m (Attr, Text)
htmlElement :: forall (m :: * -> *).
PandocMonad m =>
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 _ attr, _) <- (Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (Tag Text -> Tag Text -> Bool
forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Text -> [Attribute Text] -> Tag Text
forall str. str -> [Attribute str] -> Tag str
TagOpen Text
tag [])
  content <- T.pack <$> manyTill anyChar (endtag <|> endofinput)
  return (htmlAttrToPandoc attr, trim content)
  where
    endtag :: ParsecT Sources ParserState m ()
endtag     = ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Sources ParserState m (Tag Text, Text)
 -> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ (Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag (Tag Text -> Tag Text -> Bool
forall str t. (StringLike str, TagRep t) => Tag str -> t -> Bool
~== Text -> Tag Text
forall str. str -> Tag str
TagClose Text
tag)
    endofinput :: ParsecT Sources u m ()
endofinput = ParsecT Sources u m () -> ParsecT Sources u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
    trim :: Text -> Text
trim       = (Char -> Bool) -> Text -> Text
T.dropAround (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'\n')

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

parseHtmlContentWithAttrs :: PandocMonad m
                          => Text -> TWParser m a -> TWParser m (Attr, [a])
parseHtmlContentWithAttrs :: forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m (Attr, [a])
parseHtmlContentWithAttrs Text
tag TWParser m a
parser = do
  (attr, content) <- Text -> TWParser m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Attr, Text)
htmlElement Text
tag
  parsedContent <- try $ parseContent content
  return (attr, parsedContent)
  where
    parseContent :: Text -> ParsecT Sources ParserState m [a]
parseContent = ParsecT Sources ParserState m [a]
-> Text -> ParsecT Sources ParserState m [a]
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParsecT Sources u m a -> Text -> ParsecT Sources u m a
parseFromString' (ParsecT Sources ParserState m [a]
 -> Text -> ParsecT Sources ParserState m [a])
-> ParsecT Sources ParserState m [a]
-> Text
-> ParsecT Sources ParserState m [a]
forall a b. (a -> b) -> a -> b
$ TWParser m a
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [a]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill TWParser m a
parser ParsecT Sources ParserState m ()
forall {u}. ParsecT Sources u m ()
endOfContent
    endOfContent :: ParsecT Sources u m ()
endOfContent = ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof

parseCharHtmlContentWithAttrs :: PandocMonad m
                          => Text -> TWParser m Char -> TWParser m (Attr, Text)
parseCharHtmlContentWithAttrs :: forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m Char -> TWParser m (Attr, Text)
parseCharHtmlContentWithAttrs Text
tag = ((Attr, String) -> (Attr, Text))
-> ParsecT Sources ParserState m (Attr, String)
-> ParsecT Sources ParserState m (Attr, Text)
forall a b.
(a -> b)
-> ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Attr, String) -> (Attr, Text)
forall {a}. (a, String) -> (a, Text)
go (ParsecT Sources ParserState m (Attr, String)
 -> ParsecT Sources ParserState m (Attr, Text))
-> (ParsecT Sources ParserState m Char
    -> ParsecT Sources ParserState m (Attr, String))
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m (Attr, Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m (Attr, String)
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m (Attr, [a])
parseHtmlContentWithAttrs Text
tag
  where
    go :: (a, String) -> (a, Text)
go (a
x, String
y) = (a
x, String -> Text
T.pack String
y)

parseHtmlContent :: PandocMonad m => Text -> TWParser m a -> TWParser m [a]
parseHtmlContent :: forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m [a]
parseHtmlContent Text
tag TWParser m a
p = (Attr, [a]) -> [a]
forall a b. (a, b) -> b
snd ((Attr, [a]) -> [a])
-> ParsecT Sources ParserState m (Attr, [a])
-> ParsecT Sources ParserState m [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> TWParser m a -> ParsecT Sources ParserState m (Attr, [a])
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m (Attr, [a])
parseHtmlContentWithAttrs Text
tag TWParser m a
p

--
-- main parser
--

parseTWiki :: PandocMonad m => TWParser m Pandoc
parseTWiki :: forall (m :: * -> *). PandocMonad m => TWParser m Pandoc
parseTWiki =
  Many Block -> Pandoc
B.doc (Many Block -> Pandoc)
-> ([Many Block] -> Many Block) -> [Many Block] -> Pandoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Many Block] -> Many Block
forall a. Monoid a => [a] -> a
mconcat ([Many Block] -> Pandoc)
-> ParsecT Sources ParserState m [Many Block]
-> ParsecT Sources ParserState m Pandoc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m [Many Block]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
block ParsecT Sources ParserState m Pandoc
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Pandoc
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m ()
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces ParsecT Sources ParserState m Pandoc
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Pandoc
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof


--
-- block parsers
--

block :: PandocMonad m => TWParser m B.Blocks
block :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
block = do
  res <- Many Block
forall a. Monoid a => a
mempty Many Block
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Many Block)
forall a b.
a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
         ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m (Many Block)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
blockElements
         ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m (Many Block)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
para
  skipMany blankline
  trace (T.take 60 $ tshow $ B.toList res)
  return res

blockElements :: PandocMonad m => TWParser m B.Blocks
blockElements :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
blockElements = [ParsecT Sources ParserState m (Many Block)]
-> ParsecT Sources ParserState m (Many Block)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
separator
                       , ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
header
                       , ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
verbatim
                       , ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
literal
                       , Text -> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Many Block)
list Text
""
                       , ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
table
                       , ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
blockQuote
                       , ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
noautolink
                       ]

separator :: PandocMonad m => TWParser m B.Blocks
separator :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
separator = Text -> TWParser m (Many Block) -> TWParser m (Many Block)
forall (m :: * -> *) a. Text -> TWParser m a -> TWParser m a
tryMsg Text
"separator" (TWParser m (Many Block) -> TWParser m (Many Block))
-> TWParser m (Many Block) -> TWParser m (Many Block)
forall a b. (a -> b) -> a -> b
$ String -> ParsecT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"---" ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline ParsecT Sources ParserState m Char
-> TWParser m (Many Block) -> TWParser m (Many Block)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Many Block -> TWParser m (Many Block)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Block
B.horizontalRule

header :: PandocMonad m => TWParser m B.Blocks
header :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
header = Text -> TWParser m (Many Block) -> TWParser m (Many Block)
forall (m :: * -> *) a. Text -> TWParser m a -> TWParser m a
tryMsg Text
"header" (TWParser m (Many Block) -> TWParser m (Many Block))
-> TWParser m (Many Block) -> TWParser m (Many Block)
forall a b. (a -> b) -> a -> b
$ do
  String -> ParsecT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"---"
  level <- String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (String -> Int)
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'+')
  guard $ level <= 6
  classes <- option [] $ string "!!" >> return ["unnumbered"]
  skipSpaces
  content <- B.trimInlines . mconcat <$> manyTill inline newline
  attr <- registerHeader ("", classes, []) content
  return $ B.headerWith attr level content

verbatim :: PandocMonad m => TWParser m B.Blocks
verbatim :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
verbatim = (Attr -> Text -> Many Block) -> (Attr, Text) -> Many Block
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Attr -> Text -> Many Block
B.codeBlockWith ((Attr, Text) -> Many Block)
-> ParsecT Sources ParserState m (Attr, Text)
-> ParsecT Sources ParserState m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> ParsecT Sources ParserState m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Attr, Text)
htmlElement Text
"verbatim" ParsecT Sources ParserState m (Attr, Text)
-> ParsecT Sources ParserState m (Attr, Text)
-> ParsecT Sources ParserState m (Attr, Text)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> ParsecT Sources ParserState m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Attr, Text)
htmlElement Text
"pre")

literal :: PandocMonad m => TWParser m B.Blocks
literal :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
literal = (Attr, Text) -> Many Block
forall {a} {a} {b}.
(Eq a, IsString a) =>
((a, b, [(a, Text)]), Text) -> Many Block
rawBlock ((Attr, Text) -> Many Block)
-> ParsecT Sources ParserState m (Attr, Text)
-> ParsecT Sources ParserState m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT Sources ParserState m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Attr, Text)
htmlElement Text
"literal"
  where
    format :: (a, b, [(a, b)]) -> b
format (a
_, b
_, [(a, b)]
kvs)        = b -> Maybe b -> b
forall a. a -> Maybe a -> a
fromMaybe b
"html" (Maybe b -> b) -> Maybe b -> b
forall a b. (a -> b) -> a -> b
$ a -> [(a, b)] -> Maybe b
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup a
"format" [(a, b)]
kvs
    rawBlock :: ((a, b, [(a, Text)]), Text) -> Many Block
rawBlock ((a, b, [(a, Text)])
attrs, Text
content) = Text -> Text -> Many Block
B.rawBlock ((a, b, [(a, Text)]) -> Text
forall {a} {b} {a} {b}.
(Eq a, IsString b, IsString a) =>
(a, b, [(a, b)]) -> b
format (a, b, [(a, Text)])
attrs) Text
content

list :: PandocMonad m => Text -> TWParser m B.Blocks
list :: forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Many Block)
list Text
prefix = [ParsecT Sources ParserState m (Many Block)]
-> ParsecT Sources ParserState m (Many Block)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ Text -> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Many Block)
bulletList Text
prefix
                     , Text -> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Many Block)
orderedList Text
prefix
                     , Text -> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Many Block)
definitionList Text
prefix]

definitionList :: PandocMonad m => Text -> TWParser m B.Blocks
definitionList :: forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Many Block)
definitionList Text
prefix = Text -> TWParser m (Many Block) -> TWParser m (Many Block)
forall (m :: * -> *) a. Text -> TWParser m a -> TWParser m a
tryMsg Text
"definitionList" (TWParser m (Many Block) -> TWParser m (Many Block))
-> TWParser m (Many Block) -> TWParser m (Many Block)
forall a b. (a -> b) -> a -> b
$ do
  indent <- ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources ParserState m [Text]
 -> ParsecT Sources ParserState m [Text])
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m [Text]
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
"   ") ParsecT Sources ParserState m [Text]
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
"$ "
  elements <- many $ parseDefinitionListItem (prefix <> T.concat indent)
  return $ B.definitionList elements
  where
    parseDefinitionListItem :: PandocMonad m
                            => Text -> TWParser m (B.Inlines, [B.Blocks])
    parseDefinitionListItem :: forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Many Inline, [Many Block])
parseDefinitionListItem Text
indent = do
      Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr (Text
indent Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"$ ") ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
      term <- ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m [Many Inline]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
inline (ParsecT Sources ParserState m String
 -> ParsecT Sources ParserState m [Many Inline])
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m [Many Inline]
forall a b. (a -> b) -> a -> b
$ String -> ParsecT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
": "
      line <- listItemLine indent $ string "$ "
      return (mconcat term, [line])

bulletList :: PandocMonad m => Text -> TWParser m B.Blocks
bulletList :: forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Many Block)
bulletList Text
prefix = Text -> TWParser m (Many Block) -> TWParser m (Many Block)
forall (m :: * -> *) a. Text -> TWParser m a -> TWParser m a
tryMsg Text
"bulletList" (TWParser m (Many Block) -> TWParser m (Many Block))
-> TWParser m (Many Block) -> TWParser m (Many Block)
forall a b. (a -> b) -> a -> b
$
                    Text
-> TWParser m Char -> TWParser m Char -> TWParser m (Many Block)
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m Char -> TWParser m a -> TWParser m (Many Block)
parseList Text
prefix (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'*') (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
' ')

orderedList :: PandocMonad m => Text -> TWParser m B.Blocks
orderedList :: forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Many Block)
orderedList Text
prefix = Text -> TWParser m (Many Block) -> TWParser m (Many Block)
forall (m :: * -> *) a. Text -> TWParser m a -> TWParser m a
tryMsg Text
"orderedList" (TWParser m (Many Block) -> TWParser m (Many Block))
-> TWParser m (Many Block) -> TWParser m (Many Block)
forall a b. (a -> b) -> a -> b
$
                     Text
-> TWParser m Char -> TWParser m String -> TWParser m (Many Block)
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m Char -> TWParser m a -> TWParser m (Many Block)
parseList Text
prefix (String -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
oneOf String
"1iIaA") (String -> TWParser m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
". ")

parseList :: PandocMonad m
          => Text -> TWParser m Char -> TWParser m a -> TWParser m B.Blocks
parseList :: forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m Char -> TWParser m a -> TWParser m (Many Block)
parseList Text
prefix TWParser m Char
marker TWParser m a
delim = do
  (indent, style) <- ParsecT Sources ParserState m (Text, Char)
-> ParsecT Sources ParserState m (Text, Char)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources ParserState m (Text, Char)
 -> ParsecT Sources ParserState m (Text, Char))
-> ParsecT Sources ParserState m (Text, Char)
-> ParsecT Sources ParserState m (Text, Char)
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (Text, Char)
-> ParsecT Sources ParserState m (Text, Char)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m (Text, Char)
listStyle ParsecT Sources ParserState m (Text, Char)
-> TWParser m a -> ParsecT Sources ParserState m (Text, Char)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* TWParser m a
delim
  blocks <- many $ parseListItem (prefix <> indent) (char style <* delim)
  return $ case style of
    Char
'1' -> ListAttributes -> [Many Block] -> Many Block
B.orderedListWith (Int
1, ListNumberStyle
DefaultStyle, ListNumberDelim
DefaultDelim) [Many Block]
blocks
    Char
'i' -> ListAttributes -> [Many Block] -> Many Block
B.orderedListWith (Int
1, ListNumberStyle
LowerRoman, ListNumberDelim
DefaultDelim) [Many Block]
blocks
    Char
'I' -> ListAttributes -> [Many Block] -> Many Block
B.orderedListWith (Int
1, ListNumberStyle
UpperRoman, ListNumberDelim
DefaultDelim) [Many Block]
blocks
    Char
'a' -> ListAttributes -> [Many Block] -> Many Block
B.orderedListWith (Int
1, ListNumberStyle
LowerAlpha, ListNumberDelim
DefaultDelim) [Many Block]
blocks
    Char
'A' -> ListAttributes -> [Many Block] -> Many Block
B.orderedListWith (Int
1, ListNumberStyle
UpperAlpha, ListNumberDelim
DefaultDelim) [Many Block]
blocks
    Char
_   -> [Many Block] -> Many Block
B.bulletList [Many Block]
blocks
  where
    listStyle :: ParsecT Sources ParserState m (Text, Char)
listStyle = do
      indent <- ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState m Text
 -> ParsecT Sources ParserState m [Text])
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
"   "
      style <- marker
      return (T.concat indent, style)

parseListItem :: (PandocMonad m, Show a)
              => Text -> TWParser m a -> TWParser m B.Blocks
parseListItem :: forall (m :: * -> *) a.
(PandocMonad m, Show a) =>
Text -> TWParser m a -> TWParser m (Many Block)
parseListItem Text
prefix TWParser m a
marker = Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Sources ParserState m Text -> TWParser m a -> TWParser m a
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m a
marker TWParser m a
-> ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m (Many Block)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Text -> TWParser m a -> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *) a.
(PandocMonad m, Show a) =>
Text -> TWParser m a -> TWParser m (Many Block)
listItemLine Text
prefix TWParser m a
marker

listItemLine :: (PandocMonad m, Show a)
             => Text -> TWParser m a -> TWParser m B.Blocks
listItemLine :: forall (m :: * -> *) a.
(PandocMonad m, Show a) =>
Text -> TWParser m a -> TWParser m (Many Block)
listItemLine Text
prefix TWParser m a
marker = [Many Block] -> Many Block
forall a. Monoid a => [a] -> a
mconcat ([Many Block] -> Many Block)
-> ParsecT Sources ParserState m [Many Block]
-> ParsecT Sources ParserState m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Sources ParserState m Text
lineContent ParsecT Sources ParserState m Text
-> (Text -> ParsecT Sources ParserState m [Many Block])
-> ParsecT Sources ParserState m [Many Block]
forall a b.
ParsecT Sources ParserState m a
-> (a -> ParsecT Sources ParserState m b)
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> ParsecT Sources ParserState m [Many Block]
parseContent)
  where
    lineContent :: ParsecT Sources ParserState m Text
lineContent = do
      content <- ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine
      continuation <- optionMaybe listContinuation
      return $ filterSpaces content <> "\n" <> maybe "" ("   " <>) continuation
    filterSpaces :: Text -> Text
filterSpaces = (Char -> Bool) -> Text -> Text
T.dropWhileEnd (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ')
    listContinuation :: ParsecT Sources ParserState m Text
listContinuation = TWParser m a -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Text -> ParsecT Sources ParserState m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
prefix ParsecT Sources ParserState m Text -> TWParser m a -> TWParser m a
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m a
marker) ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m String
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
                       String -> ParsecT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"   " ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Text
lineContent
    parseContent :: Text -> ParsecT Sources ParserState m [Many Block]
parseContent = ParsecT Sources ParserState m [Many Block]
-> Text -> ParsecT Sources ParserState m [Many Block]
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParsecT Sources u m a -> Text -> ParsecT Sources u m a
parseFromString' (ParsecT Sources ParserState m [Many Block]
 -> Text -> ParsecT Sources ParserState m [Many Block])
-> ParsecT Sources ParserState m [Many Block]
-> Text
-> ParsecT Sources ParserState m [Many Block]
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m [Many Block]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState m (Many Block)
 -> ParsecT Sources ParserState m [Many Block])
-> ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m [Many Block]
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m (Many Block)
nestedList ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m (Many Block)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Many Block)
parseInline
    parseInline :: ParsecT Sources ParserState m (Many Block)
parseInline = Many Inline -> Many Block
B.plain (Many Inline -> Many Block)
-> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Many Inline] -> Many Inline
forall a. Monoid a => [a] -> a
mconcat ([Many Inline] -> Many Block)
-> ParsecT Sources ParserState m [Many Inline]
-> ParsecT Sources ParserState m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Many Inline]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
inline (ParsecT Sources ParserState m Char
forall {u}. ParsecT Sources u m Char
lastNewline ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Char
newlineBeforeNestedList)
    nestedList :: ParsecT Sources ParserState m (Many Block)
nestedList = Text -> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Many Block)
list Text
prefix
    lastNewline :: ParsecT Sources u m Char
lastNewline = ParsecT Sources u m Char -> ParsecT Sources u m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m Char -> ParsecT Sources u m Char)
-> ParsecT Sources u m Char -> ParsecT Sources u m Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\n' ParsecT Sources u m Char
-> ParsecT Sources u m () -> ParsecT Sources u m Char
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
    newlineBeforeNestedList :: ParsecT Sources ParserState m Char
newlineBeforeNestedList = ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Char
 -> ParsecT Sources ParserState m Char)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\n' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m (Many Block)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Sources ParserState m (Many Block)
nestedList

table :: PandocMonad m => TWParser m B.Blocks
table :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
table = ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m (Many Block)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Block)
 -> ParsecT Sources ParserState m (Many Block))
-> ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m (Many Block)
forall a b. (a -> b) -> a -> b
$ do
  thead <- ParsecT
  Sources ParserState m ([(Alignment, ColWidth)], [Many Block])
-> ParsecT
     Sources
     ParserState
     m
     (Maybe ([(Alignment, ColWidth)], [Many Block]))
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ([((Alignment, ColWidth), Many Block)]
-> ([(Alignment, ColWidth)], [Many Block])
forall a b. [(a, b)] -> ([a], [b])
unzip ([((Alignment, ColWidth), Many Block)]
 -> ([(Alignment, ColWidth)], [Many Block]))
-> ParsecT
     Sources ParserState m [((Alignment, ColWidth), Many Block)]
-> ParsecT
     Sources ParserState m ([(Alignment, ColWidth)], [Many Block])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m ((Alignment, ColWidth), Many Block)
-> ParsecT Sources ParserState m Char
-> ParsecT
     Sources ParserState m [((Alignment, ColWidth), Many Block)]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till ParsecT Sources ParserState m ((Alignment, ColWidth), Many Block)
forall (m :: * -> *).
PandocMonad m =>
TWParser m ((Alignment, ColWidth), Many Block)
tableParseHeader ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline)
  rows <- many1 tableParseRow
  return $ buildTable mempty rows $ fromMaybe (align rows, columns rows) thead
  where
    buildTable :: Many Inline
-> [[Many Block]]
-> ([(Alignment, ColWidth)], [Many Block])
-> Many Block
buildTable Many Inline
caption [[Many Block]]
rows ([(Alignment, ColWidth)]
aligns, [Many Block]
heads)
                    = Caption
-> [(Alignment, ColWidth)]
-> TableHead
-> [TableBody]
-> TableFoot
-> Many Block
B.table (Many Block -> Caption
B.simpleCaption (Many Block -> Caption) -> Many Block -> Caption
forall a b. (a -> b) -> a -> b
$ Many Inline -> Many Block
B.plain Many Inline
caption)
                              [(Alignment, ColWidth)]
aligns
                              (Attr -> [Row] -> TableHead
TableHead Attr
nullAttr ([Row] -> TableHead) -> [Row] -> TableHead
forall a b. (a -> b) -> a -> b
$ [Many Block] -> [Row]
toHeaderRow [Many Block]
heads)
                              [Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody Attr
nullAttr RowHeadColumns
0 [] ([Row] -> TableBody) -> [Row] -> TableBody
forall a b. (a -> b) -> a -> b
$ ([Many Block] -> Row) -> [[Many Block]] -> [Row]
forall a b. (a -> b) -> [a] -> [b]
map [Many Block] -> Row
toRow [[Many Block]]
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
columnCount [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
columnCount [t a]
rows) a
forall a. Monoid a => a
mempty
    columnCount :: [t a] -> Int
columnCount (t a
r:[t a]
_) = t a -> Int
forall a. t a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length t a
r
    columnCount []  = Int
0
    toRow :: [Many Block] -> Row
toRow           = Attr -> [Cell] -> Row
Row Attr
nullAttr ([Cell] -> Row) -> ([Many Block] -> [Cell]) -> [Many Block] -> Row
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Many Block -> Cell) -> [Many Block] -> [Cell]
forall a b. (a -> b) -> [a] -> [b]
map Many Block -> Cell
B.simpleCell
    toHeaderRow :: [Many Block] -> [Row]
toHeaderRow [Many Block]
l = [[Many Block] -> Row
toRow [Many Block]
l | Bool -> Bool
not ([Many Block] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Many Block]
l)]

tableParseHeader :: PandocMonad m => TWParser m ((Alignment, ColWidth), B.Blocks)
tableParseHeader :: forall (m :: * -> *).
PandocMonad m =>
TWParser m ((Alignment, ColWidth), Many Block)
tableParseHeader = ParsecT Sources ParserState m ((Alignment, ColWidth), Many Block)
-> ParsecT
     Sources ParserState m ((Alignment, ColWidth), Many Block)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m ((Alignment, ColWidth), Many Block)
 -> ParsecT
      Sources ParserState m ((Alignment, ColWidth), Many Block))
-> ParsecT
     Sources ParserState m ((Alignment, ColWidth), Many Block)
-> ParsecT
     Sources ParserState m ((Alignment, ColWidth), Many Block)
forall a b. (a -> b) -> a -> b
$ do
  Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|'
  leftSpaces <- String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (String -> Int)
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
  char '*'
  content <- tableColumnContent (char '*' >> skipSpaces >> char '|')
  char '*'
  rightSpaces <- length <$> many spaceChar
  optional tableEndOfRow
  return (tableAlign leftSpaces rightSpaces, 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 :: forall (m :: * -> *). PandocMonad m => TWParser m [Many Block]
tableParseRow = ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Many Block]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
tableParseColumn ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline

tableParseColumn :: PandocMonad m => TWParser m B.Blocks
tableParseColumn :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
tableParseColumn = Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m (Many Block)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                   ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *) a.
PandocMonad m =>
TWParser m a -> TWParser m (Many Block)
tableColumnContent (ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|')
                   ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Many Block)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Many Block)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => TWParser m Char
tableEndOfRow

tableEndOfRow :: PandocMonad m => TWParser m Char
tableEndOfRow :: forall (m :: * -> *). PandocMonad m => TWParser m Char
tableEndOfRow = ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Char
 -> ParsecT Sources ParserState m Char)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\n') ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|'

tableColumnContent :: PandocMonad m => TWParser m a -> TWParser m B.Blocks
tableColumnContent :: forall (m :: * -> *) a.
PandocMonad m =>
TWParser m a -> TWParser m (Many Block)
tableColumnContent TWParser m a
end = Many Inline -> Many Block
B.plain (Many Inline -> Many Block)
-> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Many Inline] -> Many Inline
forall a. Monoid a => [a] -> a
mconcat ([Many Inline] -> Many Block)
-> ParsecT Sources ParserState m [Many Inline]
-> ParsecT Sources ParserState m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (Many Inline)
-> TWParser m a -> ParsecT Sources ParserState m [Many Inline]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Sources ParserState m (Many Inline)
content (TWParser m a -> TWParser m a
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (TWParser m a -> TWParser m a) -> TWParser m a -> TWParser m a
forall a b. (a -> b) -> a -> b
$ TWParser m a -> TWParser m a
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try TWParser m a
end)
  where
    content :: ParsecT Sources ParserState m (Many Inline)
content = ParsecT Sources ParserState m (Many Inline)
forall {u}. ParsecT Sources u m (Many Inline)
continuation ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
inline
    continuation :: ParsecT Sources u m (Many Inline)
continuation = ParsecT Sources u m (Many Inline)
-> ParsecT Sources u m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m (Many Inline)
 -> ParsecT Sources u m (Many Inline))
-> ParsecT Sources u m (Many Inline)
-> ParsecT Sources u m (Many Inline)
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\' ParsecT Sources u m Char
-> ParsecT Sources u m Char -> ParsecT Sources u m Char
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline ParsecT Sources u m Char
-> ParsecT Sources u m (Many Inline)
-> ParsecT Sources u m (Many Inline)
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Many Inline -> ParsecT Sources u m (Many Inline)
forall a. a -> ParsecT Sources u m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Inline
forall a. Monoid a => a
mempty

blockQuote :: PandocMonad m => TWParser m B.Blocks
blockQuote :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
blockQuote = Many Block -> Many Block
B.blockQuote (Many Block -> Many Block)
-> ([Many Block] -> Many Block) -> [Many Block] -> Many Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Many Block] -> Many Block
forall a. Monoid a => [a] -> a
mconcat ([Many Block] -> Many Block)
-> ParsecT Sources ParserState m [Many Block]
-> ParsecT Sources ParserState m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m [Many Block]
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m [a]
parseHtmlContent Text
"blockquote" ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
block

noautolink :: PandocMonad m => TWParser m B.Blocks
noautolink :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
noautolink = do
  (_, content) <- Text -> TWParser m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m (Attr, Text)
htmlElement Text
"noautolink"
  st <- getState
  setState $ st{ stateAllowLinks = False }
  blocks <- try $ parseContent content
  setState $ st{ stateAllowLinks = True }
  return $ mconcat blocks
  where
    parseContent :: Text -> ParsecT Sources ParserState m [Many Block]
parseContent = ParsecT Sources ParserState m [Many Block]
-> Text -> ParsecT Sources ParserState m [Many Block]
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParsecT Sources u m a -> Text -> ParsecT Sources u m a
parseFromString' (ParsecT Sources ParserState m [Many Block]
 -> Text -> ParsecT Sources ParserState m [Many Block])
-> ParsecT Sources ParserState m [Many Block]
-> Text
-> ParsecT Sources ParserState m [Many Block]
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m [Many Block]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
block

para :: PandocMonad m => TWParser m B.Blocks
para :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
para = Many Inline -> Many Block
result (Many Inline -> Many Block)
-> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Many Inline] -> Many Inline
forall a. Monoid a => [a] -> a
mconcat ([Many Inline] -> Many Block)
-> ParsecT Sources ParserState m [Many Inline]
-> ParsecT Sources ParserState m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [Many Inline]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
inline ParsecT Sources ParserState m ()
endOfParaElement
 where
   endOfParaElement :: ParsecT Sources ParserState m ()
endOfParaElement = ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources ParserState m ()
 -> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m ()
forall {u}. ParsecT Sources u m ()
endOfInput ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m ()
forall {u}. ParsecT Sources u m ()
endOfPara ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m ()
newBlockElement
   endOfInput :: ParsecT Sources u m ()
endOfInput       = ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
   endOfPara :: ParsecT Sources u m ()
endOfPara        = ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline ParsecT Sources u m Char
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
   newBlockElement :: ParsecT Sources ParserState m ()
newBlockElement  = ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m ()
 -> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Block)
blockElements
   result :: Many Inline -> Many Block
result Many Inline
content   = if (Inline -> Bool) -> Many Inline -> 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) Many Inline
content
                      then Many Block
forall a. Monoid a => a
mempty
                      else Many Inline -> Many Block
B.para (Many Inline -> Many Block) -> Many Inline -> Many Block
forall a b. (a -> b) -> a -> b
$ Many Inline -> Many Inline
B.trimInlines Many Inline
content


--
-- inline parsers
--

inline :: PandocMonad m => TWParser m B.Inlines
inline :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
inline = [ParsecT Sources ParserState m (Many Inline)]
-> ParsecT Sources ParserState m (Many Inline)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
whitespace
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
br
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
macro
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
strong
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
strongHtml
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
strongAndEmph
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
emph
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
emphHtml
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
boldCode
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
smart
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
link
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
htmlComment
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
code
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
codeHtml
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
nop
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
autoLink
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
str
                , ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
symbol
                ] ParsecT Sources ParserState m (Many Inline)
-> String -> ParsecT Sources ParserState m (Many Inline)
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 :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
whitespace = ParsecT Sources ParserState m (Many Inline)
lb ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Many Inline)
forall {u}. ParsecT Sources u m (Many Inline)
regsp
  where lb :: ParsecT Sources ParserState m (Many Inline)
lb = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline)
 -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
linebreak ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Many Inline -> ParsecT Sources ParserState m (Many Inline)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Inline
B.space
        regsp :: ParsecT Sources u m (Many Inline)
regsp = ParsecT Sources u m (Many Inline)
-> ParsecT Sources u m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources u m (Many Inline)
 -> ParsecT Sources u m (Many Inline))
-> ParsecT Sources u m (Many Inline)
-> ParsecT Sources u m (Many Inline)
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar ParsecT Sources u m ()
-> ParsecT Sources u m (Many Inline)
-> ParsecT Sources u m (Many Inline)
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Many Inline -> ParsecT Sources u m (Many Inline)
forall a. a -> ParsecT Sources u m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Inline
B.space

br :: PandocMonad m => TWParser m B.Inlines
br :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
br = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline)
 -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ String -> ParsecT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"%BR%" ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Many Inline -> ParsecT Sources ParserState m (Many Inline)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Inline
B.linebreak

linebreak :: PandocMonad m => TWParser m B.Inlines
linebreak :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
linebreak = ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (ParsecT Sources ParserState m (Many Inline)
forall {u}. ParsecT Sources u m (Many Inline)
lastNewline ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Many Inline)
innerNewline)
  where lastNewline :: ParsecT Sources u m (Many Inline)
lastNewline  = ParsecT Sources u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParsecT Sources u m ()
-> ParsecT Sources u m (Many Inline)
-> ParsecT Sources u m (Many Inline)
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Many Inline -> ParsecT Sources u m (Many Inline)
forall a. a -> ParsecT Sources u m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Inline
forall a. Monoid a => a
mempty
        innerNewline :: ParsecT Sources ParserState m (Many Inline)
innerNewline = Many Inline -> ParsecT Sources ParserState m (Many Inline)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Inline
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 :: 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
start TWParser m b
end TWParser m b -> TWParser m c
p =
  [c] -> c
forall a. Monoid a => [a] -> a
mconcat ([c] -> c) -> ParsecT Sources ParserState m [c] -> TWParser m c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m [c]
-> ParsecT Sources ParserState m [c]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m a
start TWParser m a
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
whitespace ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [c]
-> ParsecT Sources ParserState m [c]
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m c -> TWParser m b -> ParsecT Sources ParserState m [c]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT 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 :: forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed TWParser m a
sep TWParser m a -> TWParser m b
p = TWParser m a
-> TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
forall c (m :: * -> *) b a.
(Monoid c, PandocMonad m, Show b) =>
TWParser m a
-> TWParser m b -> (TWParser m b -> TWParser m c) -> TWParser m c
between TWParser m a
sep (TWParser m a -> TWParser m a
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TWParser m a -> TWParser m a) -> TWParser m a -> TWParser m a
forall a b. (a -> b) -> a -> b
$ TWParser m a
sep TWParser m a -> ParsecT Sources ParserState m () -> TWParser m a
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m ()
forall {u}. ParsecT Sources u m ()
endMarker) TWParser m a -> TWParser m b
p
  where
    endMarker :: ParsecT Sources u m ()
endMarker   = ParsecT Sources u m () -> ParsecT Sources u m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Sources u m () -> ParsecT Sources u m ())
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources u m (Many Inline) -> ParsecT Sources u m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Sources u m (Many Inline)
forall {u}. ParsecT Sources u m (Many Inline)
endSpace ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources u m Char -> ParsecT Sources u m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (String -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
oneOf String
".,!?:)|") ParsecT Sources u m ()
-> ParsecT Sources u m () -> ParsecT Sources u m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources u m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
    endSpace :: ParsecT Sources u m (Many Inline)
endSpace    = (ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar ParsecT Sources u m Char
-> ParsecT Sources u m Char -> ParsecT Sources u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline) ParsecT Sources u m Char
-> ParsecT Sources u m (Many Inline)
-> ParsecT Sources u m (Many Inline)
forall a b.
ParsecT Sources u m a
-> ParsecT Sources u m b -> ParsecT Sources u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Many Inline -> ParsecT Sources u m (Many Inline)
forall a. a -> ParsecT Sources u m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Inline
B.space

macro :: PandocMonad m => TWParser m B.Inlines
macro :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
macro = TWParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
macroWithParameters TWParser m (Many Inline)
-> TWParser m (Many Inline) -> TWParser m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TWParser m (Many Inline)
withoutParameters
  where
    withoutParameters :: TWParser m (Many Inline)
withoutParameters = Text -> Many Inline
emptySpan (Text -> Many Inline)
-> ParsecT Sources ParserState m Text -> TWParser m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m Char
-> (TWParser m Char -> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'%') (ParsecT Sources ParserState m Text
-> TWParser m Char -> ParsecT Sources ParserState m Text
forall a b. a -> b -> a
const ParsecT Sources ParserState m Text
forall (m :: * -> *). PandocMonad m => TWParser m Text
macroName)
    emptySpan :: Text -> Many Inline
emptySpan Text
name = Text -> [Attribute Text] -> Many Inline -> Many Inline
buildSpan Text
name [] Many Inline
forall a. Monoid a => a
mempty

macroWithParameters :: PandocMonad m => TWParser m B.Inlines
macroWithParameters :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
macroWithParameters = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline)
 -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ do
  Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'%'
  name <- TWParser m Text
forall (m :: * -> *). PandocMonad m => TWParser m Text
macroName
  (content, kvs) <- attributes
  char '%'
  return $ buildSpan name kvs $ B.str content

buildSpan :: Text -> [(Text, Text)] -> B.Inlines -> B.Inlines
buildSpan :: Text -> [Attribute Text] -> Many Inline -> Many Inline
buildSpan Text
className [Attribute Text]
kvs = Attr -> Many Inline -> Many Inline
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 :: forall (m :: * -> *). PandocMonad m => TWParser m Text
macroName = do
  first <- ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
letter
  rest <- many $ alphaNum <|> char '_'
  return $ T.pack $ first:rest

attributes :: PandocMonad m => TWParser m (Text, [(Text, Text)])
attributes :: forall (m :: * -> *).
PandocMonad m =>
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 a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((Text -> (Text, [Attribute Text]) -> (Text, [Attribute Text]))
-> (Attribute Text
    -> (Text, [Attribute Text]) -> (Text, [Attribute Text]))
-> Either Text (Attribute Text)
-> (Text, [Attribute Text])
-> (Text, [Attribute Text])
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Text -> (Text, [Attribute Text]) -> (Text, [Attribute Text])
forall {a} {b}.
(Eq a, IsString a, Semigroup a) =>
a -> (a, b) -> (a, b)
mkContent Attribute Text
-> (Text, [Attribute Text]) -> (Text, [Attribute Text])
forall {a} {a}. a -> (a, [a]) -> (a, [a])
mkKvs) (Text
"", [])
  ([Either Text (Attribute Text)] -> (Text, [Attribute Text]))
-> ParsecT Sources ParserState m [Either Text (Attribute Text)]
-> ParsecT Sources ParserState m (Text, [Attribute Text])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'{' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m ()
forall {u}. ParsecT Sources u m ()
spnl ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [Either Text (Attribute Text)]
-> ParsecT Sources ParserState m [Either Text (Attribute Text)]
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m (Either Text (Attribute Text))
-> ParsecT Sources ParserState m [Either Text (Attribute Text)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Sources ParserState m (Either Text (Attribute Text))
forall (m :: * -> *).
PandocMonad m =>
TWParser m (Either Text (Attribute Text))
attribute ParsecT Sources ParserState m (Either Text (Attribute Text))
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Either Text (Attribute Text))
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m ()
forall {u}. ParsecT Sources u m ()
spnl) ParsecT Sources ParserState m [Either Text (Attribute Text)]
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Either Text (Attribute Text)]
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'}')
  where
    spnl :: ParsecT Sources u m ()
spnl                      = ParsecT Sources u m Char -> ParsecT Sources u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (ParsecT Sources u m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar ParsecT Sources u m Char
-> ParsecT Sources u m Char -> ParsecT Sources u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline)
    mkContent :: a -> (a, b) -> (a, b)
mkContent a
c  (a
"", b
kvs)    = (a
c, b
kvs)
    mkContent a
c  (a
rest, b
kvs)  = (a
c a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
" " a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
rest, b
kvs)
    mkKvs :: a -> (a, [a]) -> (a, [a])
mkKvs     a
kv (a
cont, [a]
rest) = (a
cont, a
kv a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
rest)

attribute :: PandocMonad m => TWParser m (Either Text (Text, Text))
attribute :: forall (m :: * -> *).
PandocMonad m =>
TWParser m (Either Text (Attribute Text))
attribute = ParsecT Sources ParserState m (Either Text (Attribute Text))
forall {a}.
ParsecT Sources ParserState m (Either a (Attribute Text))
withKey ParsecT Sources ParserState m (Either Text (Attribute Text))
-> ParsecT Sources ParserState m (Either Text (Attribute Text))
-> ParsecT Sources ParserState m (Either Text (Attribute Text))
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Either Text (Attribute Text))
forall {b}. ParsecT Sources ParserState m (Either Text b)
withoutKey
  where
    withKey :: ParsecT Sources ParserState m (Either a (Attribute Text))
withKey = ParsecT Sources ParserState m (Either a (Attribute Text))
-> ParsecT Sources ParserState m (Either a (Attribute Text))
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Either a (Attribute Text))
 -> ParsecT Sources ParserState m (Either a (Attribute Text)))
-> ParsecT Sources ParserState m (Either a (Attribute Text))
-> ParsecT Sources ParserState m (Either a (Attribute Text))
forall a b. (a -> b) -> a -> b
$ do
      key <- TWParser m Text
forall (m :: * -> *). PandocMonad m => TWParser m Text
macroName
      char '='
      curry Right key <$> parseValue False
    withoutKey :: ParsecT Sources ParserState m (Either Text b)
withoutKey = ParsecT Sources ParserState m (Either Text b)
-> ParsecT Sources ParserState m (Either Text b)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Either Text b)
 -> ParsecT Sources ParserState m (Either Text b))
-> ParsecT Sources ParserState m (Either Text b)
-> ParsecT Sources ParserState m (Either Text b)
forall a b. (a -> b) -> a -> b
$ Text -> Either Text b
forall a b. a -> Either a b
Left (Text -> Either Text b)
-> TWParser m Text -> ParsecT Sources ParserState m (Either Text b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> TWParser m Text
parseValue Bool
True
    parseValue :: Bool -> TWParser m Text
parseValue Bool
allowSpaces = Text -> Text
fromEntities (Text -> Text) -> TWParser m Text -> TWParser m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (TWParser m Text
withQuotes TWParser m Text -> TWParser m Text -> TWParser m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool -> TWParser m Text
forall {s} {m :: * -> *} {st}.
(UpdateSourcePos s Char, Stream s m Char) =>
Bool -> ParsecT s st m Text
withoutQuotes Bool
allowSpaces)
    withQuotes :: TWParser m Text
withQuotes             = ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> (ParsecT Sources ParserState m Char -> TWParser m Text)
-> TWParser m Text
forall c (m :: * -> *) b a.
(Monoid c, PandocMonad m, Show b) =>
TWParser m a
-> TWParser m b -> (TWParser m b -> TWParser m c) -> TWParser m c
between (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"') (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"') (\ParsecT Sources ParserState m Char
_ -> Int -> ParsecT Sources ParserState m Char -> TWParser m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 (ParsecT Sources ParserState m Char -> TWParser m Text)
-> ParsecT Sources ParserState m Char -> TWParser m Text
forall a b. (a -> b) -> a -> b
$ String -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf [Char
'"'])
    withoutQuotes :: Bool -> ParsecT s st m Text
withoutQuotes Bool
allowSpaces
      | Bool
allowSpaces = ParsecT s st m Char -> ParsecT s st m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (ParsecT s st m Char -> ParsecT s st m Text)
-> ParsecT s st m Char -> ParsecT s st m Text
forall a b. (a -> b) -> a -> b
$ String -> ParsecT s st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf String
"}"
      | Bool
otherwise   = ParsecT s st m Char -> ParsecT s st m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (ParsecT s st m Char -> ParsecT s st m Text)
-> ParsecT s st m Char -> ParsecT s st m Text
forall a b. (a -> b) -> a -> b
$ String -> ParsecT s st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf String
" }"

nestedInlines :: (Show a, PandocMonad m)
              => TWParser m a -> TWParser m B.Inlines
nestedInlines :: forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m (Many Inline)
nestedInlines TWParser m a
end = ParsecT Sources ParserState m (Many Inline)
innerSpace ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Many Inline)
nestedInline
  where
    innerSpace :: ParsecT Sources ParserState m (Many Inline)
innerSpace   = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline)
 -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
whitespace ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Many Inline)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* TWParser m a -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy TWParser m a
end
    nestedInline :: ParsecT Sources ParserState m (Many Inline)
nestedInline = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
whitespace ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
inline

strong :: PandocMonad m => TWParser m B.Inlines
strong :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
strong = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline)
 -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ Many Inline -> Many Inline
B.strong (Many Inline -> Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m Char
-> (TWParser m Char -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'*') TWParser m Char -> ParsecT Sources ParserState m (Many Inline)
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m (Many Inline)
nestedInlines

strongHtml :: PandocMonad m => TWParser m B.Inlines
strongHtml :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
strongHtml = Many Inline -> Many Inline
B.strong (Many Inline -> Many Inline)
-> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Many Inline] -> Many Inline
forall a. Monoid a => [a] -> a
mconcat ([Many Inline] -> Many Inline)
-> ParsecT Sources ParserState m [Many Inline]
-> ParsecT Sources ParserState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m [Many Inline]
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m [a]
parseHtmlContent Text
"strong" ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
inline ParsecT Sources ParserState m [Many Inline]
-> ParsecT Sources ParserState m [Many Inline]
-> ParsecT Sources ParserState m [Many Inline]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m [Many Inline]
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m [a]
parseHtmlContent Text
"b" ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
inline)

strongAndEmph :: PandocMonad m => TWParser m B.Inlines
strongAndEmph :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
strongAndEmph = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline)
 -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ Many Inline -> Many Inline
B.emph (Many Inline -> Many Inline)
-> (Many Inline -> Many Inline) -> Many Inline -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Many Inline -> Many Inline
B.strong (Many Inline -> Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m String
-> (TWParser m String
    -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed (String -> TWParser m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"__") TWParser m String -> ParsecT Sources ParserState m (Many Inline)
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m (Many Inline)
nestedInlines

emph :: PandocMonad m => TWParser m B.Inlines
emph :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
emph = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline)
 -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ Many Inline -> Many Inline
B.emph (Many Inline -> Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m Char
-> (TWParser m Char -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'_')
                        (\TWParser m Char
p -> TWParser m Char -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|') ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TWParser m Char -> ParsecT Sources ParserState m (Many Inline)
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m (Many Inline)
nestedInlines TWParser m Char
p)
-- emphasis closers can't cross table cell boundaries, see #3921

emphHtml :: PandocMonad m => TWParser m B.Inlines
emphHtml :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
emphHtml = Many Inline -> Many Inline
B.emph (Many Inline -> Many Inline)
-> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Many Inline] -> Many Inline
forall a. Monoid a => [a] -> a
mconcat ([Many Inline] -> Many Inline)
-> ParsecT Sources ParserState m [Many Inline]
-> ParsecT Sources ParserState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m [Many Inline]
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m [a]
parseHtmlContent Text
"em" ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
inline ParsecT Sources ParserState m [Many Inline]
-> ParsecT Sources ParserState m [Many Inline]
-> ParsecT Sources ParserState m [Many Inline]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m [Many Inline]
forall (m :: * -> *) a.
PandocMonad m =>
Text -> TWParser m a -> TWParser m [a]
parseHtmlContent Text
"i" ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
inline)

nestedString :: (Show a, PandocMonad m)
             => TWParser m a -> TWParser m Text
nestedString :: forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m Text
nestedString TWParser m a
end = ParsecT Sources ParserState m Text
innerSpace ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar
  where
    innerSpace :: ParsecT Sources ParserState m Text
innerSpace = ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Text
 -> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Text
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* TWParser m a -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy TWParser m a
end

boldCode :: PandocMonad m => TWParser m B.Inlines
boldCode :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
boldCode = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline)
 -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ Many Inline -> Many Inline
B.strong (Many Inline -> Many Inline)
-> (Text -> Many Inline) -> Text -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Many Inline
B.code (Text -> Many Inline) -> (Text -> Text) -> Text -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
fromEntities (Text -> Many Inline)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m String
-> (TWParser m String -> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed (String -> TWParser m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"==") TWParser m String -> ParsecT Sources ParserState m Text
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m Text
nestedString

htmlComment :: PandocMonad m => TWParser m B.Inlines
htmlComment :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
htmlComment = (Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParsecT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isCommentTag ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Many Inline -> ParsecT Sources ParserState m (Many Inline)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Inline
forall a. Monoid a => a
mempty

code :: PandocMonad m => TWParser m B.Inlines
code :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
code = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline)
 -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ Text -> Many Inline
B.code (Text -> Many Inline) -> (Text -> Text) -> Text -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
fromEntities (Text -> Many Inline)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TWParser m Char
-> (TWParser m Char -> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m Text
forall b (m :: * -> *) a.
(Monoid b, PandocMonad m, Show a) =>
TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
enclosed (Char -> TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'=') TWParser m Char -> ParsecT Sources ParserState m Text
forall a (m :: * -> *).
(Show a, PandocMonad m) =>
TWParser m a -> TWParser m Text
nestedString

codeHtml :: PandocMonad m => TWParser m B.Inlines
codeHtml :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
codeHtml = do
  (attrs, content) <- Text -> TWParser m Char -> TWParser m (Attr, Text)
forall (m :: * -> *).
PandocMonad m =>
Text -> TWParser m Char -> TWParser m (Attr, Text)
parseCharHtmlContentWithAttrs Text
"code" TWParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar
  return $ B.codeWith attrs $ fromEntities content

autoLink :: PandocMonad m => TWParser m B.Inlines
autoLink :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
autoLink = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline)
 -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ do
  state <- ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  guard $ stateAllowLinks state
  (text, url) <- parseLink
  guard $ checkLink (T.last url)
  return $ makeLink (text, url)
  where
    parseLink :: ParsecT Sources ParserState m (Attribute Text)
parseLink            = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
nop ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Attribute Text)
-> ParsecT Sources ParserState m (Attribute Text)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (ParsecT Sources ParserState m (Attribute Text)
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (Attribute Text)
uri ParsecT Sources ParserState m (Attribute Text)
-> ParsecT Sources ParserState m (Attribute Text)
-> ParsecT Sources ParserState m (Attribute Text)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Attribute Text)
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (Attribute Text)
emailAddress)
    makeLink :: Attribute Text -> Many Inline
makeLink (Text
text, Text
url) = Text -> Text -> Many Inline -> Many Inline
B.link Text
url Text
"" (Many Inline -> Many Inline) -> Many Inline -> Many Inline
forall a b. (a -> b) -> a -> b
$ Text -> Many Inline
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 :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
str = Text -> Many Inline
B.str (Text -> Many Inline)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
characterReference)

nop :: PandocMonad m => TWParser m B.Inlines
nop :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
nop = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline)
 -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Sources ParserState m Char
forall {u}. ParsecT Sources u m Char
exclamation ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Sources ParserState m Text
forall {st}. ParsecT Sources st m Text
nopTag) ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m (Many Inline)
forall {st}. ParsecT Sources st m (Many Inline)
followContent
  where
    exclamation :: ParsecT Sources u m Char
exclamation   = Char -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'!'
    nopTag :: ParsecT Sources st m Text
nopTag        = Text -> ParsecT Sources st m Text
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
stringAnyCase Text
"<nop>"
    followContent :: ParsecT Sources st m (Many Inline)
followContent = Text -> Many Inline
B.str (Text -> Many Inline) -> (Text -> Text) -> Text -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
fromEntities (Text -> Many Inline)
-> ParsecT Sources st m Text -> ParsecT Sources st m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources st m Char -> ParsecT Sources st m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char ParsecT Sources st m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar

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

smart :: PandocMonad m => TWParser m B.Inlines
smart :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
smart = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall st (m :: * -> *) s.
(HasReaderOptions st, HasLastStrPosition st, HasQuoteContext st m,
 Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (Many Inline) -> ParsecT s st m (Many Inline)
smartPunctuation ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
inline

link :: PandocMonad m => TWParser m B.Inlines
link :: forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
link = ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline)
 -> ParsecT Sources ParserState m (Many Inline))
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ do
  st <- ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  guard $ stateAllowLinks st
  setState $ st{ stateAllowLinks = False }
  (url, title, classes, content) <- linkText <|> simpleWikiLink
  setState $ st{ stateAllowLinks = True }
  return $ B.linkWith ("",classes,[]) url title content

linkText :: PandocMonad m => TWParser m (Text, Text, [Text], B.Inlines)
linkText :: forall (m :: * -> *).
PandocMonad m =>
TWParser m (Text, Text, [Text], Many Inline)
linkText = do
  String -> ParsecT Sources ParserState m String
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"[["
  url <- String -> Text
T.pack (String -> Text)
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m String
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']')
  content <- option (B.str url) (mconcat <$> linkContent)
  char ']'
  return (url, "", [], content)
  where
    linkContent :: ParsecT Sources ParserState m [Many Inline]
linkContent      = Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'[' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m String
-> ParsecT Sources ParserState m String
forall a b.
ParsecT Sources ParserState m a
-> ParsecT Sources ParserState m b
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m String
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']') ParsecT Sources ParserState m String
-> (String -> ParsecT Sources ParserState m [Many Inline])
-> ParsecT Sources ParserState m [Many Inline]
forall a b.
ParsecT Sources ParserState m a
-> (a -> ParsecT Sources ParserState m b)
-> ParsecT Sources ParserState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> ParsecT Sources ParserState m [Many Inline]
parseLinkContent (Text -> ParsecT Sources ParserState m [Many Inline])
-> (String -> Text)
-> String
-> ParsecT Sources ParserState m [Many Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
    parseLinkContent :: Text -> ParsecT Sources ParserState m [Many Inline]
parseLinkContent = ParsecT Sources ParserState m [Many Inline]
-> Text -> ParsecT Sources ParserState m [Many Inline]
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParsecT Sources u m a -> Text -> ParsecT Sources u m a
parseFromString' (ParsecT Sources ParserState m [Many Inline]
 -> Text -> ParsecT Sources ParserState m [Many Inline])
-> ParsecT Sources ParserState m [Many Inline]
-> Text
-> ParsecT Sources ParserState m [Many Inline]
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m [Many Inline]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *). PandocMonad m => TWParser m (Many Inline)
inline

simpleWikiLink :: PandocMonad m => TWParser m (Text, Text, [Text], B.Inlines)
simpleWikiLink :: forall (m :: * -> *).
PandocMonad m =>
TWParser m (Text, Text, [Text], Many Inline)
simpleWikiLink = do
  w <- ParsecT Sources ParserState m Text
forall {u}. ParsecT Sources u m Text
wikiWord
  return (w, "", ["wikilink"], B.str w)
 where
   wikiWord :: ParsecT Sources u m Text
wikiWord = do
     cs <- ParsecT Sources u m Char -> ParsecT Sources u m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources u m Char -> ParsecT Sources u m String)
-> ParsecT Sources u m Char -> ParsecT Sources u m String
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (\Char
x -> Char -> Bool
isLetter Char
x Bool -> Bool -> Bool
&& Char -> Bool
isUpper Char
x)
     ds <- many1 $ satisfy (\Char
x -> Char -> Bool
isDigit Char
x Bool -> Bool -> Bool
|| (Char -> Bool
isLetter Char
x Bool -> Bool -> Bool
&& Char -> Bool
isLower Char
x))
     es <- many1 $ satisfy (\Char
x -> Char -> Bool
isLetter Char
x Bool -> Bool -> Bool
&& Char -> Bool
isUpper Char
x)
     fs <- many $ satisfy isAlphaNum
     return $ T.pack $ cs ++ ds ++ es ++ fs