{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}
module Text.Pandoc.Readers.Textile ( readTextile) where
import Control.Monad (guard, liftM)
import Control.Monad.Except (throwError)
import Data.Char (digitToInt, isUpper)
import Data.List (intersperse, transpose)
import qualified Data.List as L
import Data.List.NonEmpty (NonEmpty(..), nonEmpty)
import qualified Data.Map as M
import Data.Text (Text)
import qualified Data.Text as T
import Text.HTML.TagSoup (Tag (..), fromAttrib)
import Text.HTML.TagSoup.Match
import Text.Pandoc.Builder (Blocks, Inlines, trimInlines)
import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
import Text.Pandoc.CSS
import Text.Pandoc.Definition
import Text.Pandoc.Logging
import Text.Pandoc.Options
import Text.Pandoc.Parsing
import Text.Pandoc.Readers.HTML (htmlTag, isBlockTag, isInlineTag)
import Text.Pandoc.Readers.LaTeX (rawLaTeXBlock, rawLaTeXInline)
import Text.Pandoc.Shared (trim, tshow)
import Text.Read (readMaybe)
readTextile :: (PandocMonad m, ToSources a)
=> ReaderOptions
-> a
-> m Pandoc
readTextile :: forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readTextile 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)
parsed <- 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 => TextileParser m Pandoc
parseTextile ParserState
forall a. Default a => a
def{ stateOptions = opts } Sources
sources
case parsed of
Right Pandoc
result -> Pandoc -> m Pandoc
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
result
Left PandocError
e -> PandocError -> m Pandoc
forall a. PandocError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PandocError
e
type TextileParser = ParsecT Sources ParserState
parseTextile :: PandocMonad m => TextileParser m Pandoc
parseTextile :: forall (m :: * -> *). PandocMonad m => TextileParser m Pandoc
parseTextile = do
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]
many ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
startPos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
let firstPassParser = do
pos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
t <- noteBlock <|> referenceKey <|> lineClump
return (pos, t)
manyTill firstPassParser eof >>= setInput . Sources
setPosition startPos
st' <- getState
let reversedNotes = ParserState -> NoteTable
stateNotes ParserState
st'
updateState $ \ParserState
s -> ParserState
s { stateNotes = reverse reversedNotes }
Pandoc nullMeta . B.toList <$> parseBlocks
noteMarker :: PandocMonad m => TextileParser m Text
noteMarker :: forall (m :: * -> *). PandocMonad m => TextileParser m Text
noteMarker = do
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
[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]
string [Char]
"fn"
[Char] -> Text
T.pack ([Char] -> Text)
-> ParsecT Sources ParserState m [Char]
-> 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 [Char]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit ([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]
string [Char]
"." 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]
-> ParsecT Sources ParserState m [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([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]
string [Char]
"^."))
noteBlock :: PandocMonad m => TextileParser m Text
noteBlock :: forall (m :: * -> *). PandocMonad m => TextileParser m Text
noteBlock = 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
$ do
startPos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ref <- noteMarker
optional blankline
contents <- T.unlines <$> many1Till anyLine (blanklines <|> noteBlock)
endPos <- getPosition
let newnote = (Text
ref, Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n")
st <- getState
let oldnotes = ParserState -> NoteTable
stateNotes ParserState
st
updateState $ \ParserState
s -> ParserState
s { stateNotes = newnote : oldnotes }
return $ T.replicate (sourceLine endPos - sourceLine startPos) "\n"
referenceKey :: PandocMonad m => TextileParser m Text
referenceKey :: forall (m :: * -> *). PandocMonad m => TextileParser m Text
referenceKey = 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
$ do
pos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
char '['
refName <- T.pack <$> many1Till nonspaceChar (char ']')
refDestination <- T.pack <$> many1Till anyChar newline
st <- getState
let oldKeys = ParserState -> KeyTable
stateKeys ParserState
st
let key = Text -> Key
toKey Text
refName
let target = (Text
refDestination, Text
"")
case M.lookup key oldKeys of
Just ((Text, Text)
t, Attr
_) | Bool -> Bool
not ((Text, Text)
t (Text, Text) -> (Text, Text) -> Bool
forall a. Eq a => a -> a -> Bool
== (Text, Text)
target) ->
LogMessage -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasLogMessages st) =>
LogMessage -> ParsecT s st m ()
logMessage (LogMessage -> ParsecT Sources ParserState m ())
-> LogMessage -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
DuplicateLinkReference Text
refName SourcePos
pos
Maybe ((Text, Text), Attr)
_ -> () -> ParsecT Sources ParserState m ()
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
updateState $ \ParserState
s -> ParserState
s {stateKeys = M.insert key (target, nullAttr) oldKeys }
return "\n"
parseBlocks :: PandocMonad m => TextileParser m Blocks
parseBlocks :: forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
parseBlocks = [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 (Many Block)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [Many Block]
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 Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
block ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
blockParsers :: PandocMonad m => [TextileParser m Blocks]
blockParsers :: forall (m :: * -> *).
PandocMonad m =>
[TextileParser m (Many Block)]
blockParsers = [ TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
codeBlock
, TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
header
, TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
blockQuote
, TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
hrule
, TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
commentBlock
, TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
anyList
, TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
rawHtmlBlock
, TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
rawLaTeXBlock'
, TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
table
, Text
-> TextileParser m (Many Block) -> TextileParser m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Text
-> TextileParser m (Many Block) -> TextileParser m (Many Block)
explicitBlock Text
"p" (TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
para TextileParser m (Many Block)
-> TextileParser m (Many Block) -> TextileParser m (Many Block)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Many Block -> TextileParser m (Many Block)
forall a. a -> ParsecT Sources ParserState m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Many Inline -> Many Block
B.para Many Inline
forall a. Monoid a => a
mempty))
, TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
para
, Many Block
forall a. Monoid a => a
mempty Many Block
-> ParsecT Sources ParserState m Text
-> TextileParser 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 Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines
]
block :: PandocMonad m => TextileParser m Blocks
block :: forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
block = do
res <- [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 =>
[TextileParser m (Many Block)]
blockParsers ParsecT Sources ParserState m (Many Block)
-> [Char] -> ParsecT Sources ParserState m (Many Block)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"block"
trace (T.take 60 $ tshow $ B.toList res)
return res
commentBlock :: PandocMonad m => TextileParser m Blocks
= 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
[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]
string [Char]
"###."
ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines
Many Block -> ParsecT Sources ParserState m (Many Block)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Block
forall a. Monoid a => a
mempty
codeBlock :: PandocMonad m => TextileParser m Blocks
codeBlock :: forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
codeBlock = TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
codeBlockTextile TextileParser m (Many Block)
-> TextileParser m (Many Block) -> TextileParser m (Many Block)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
codeBlockHtml
codeBlockTextile :: PandocMonad m => TextileParser m Blocks
codeBlockTextile :: forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
codeBlockTextile = 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
[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]
string [Char]
"bc." ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m [Char]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [Char] -> ParsecT Sources ParserState m [Char]
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"pre."
extended <- Bool
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (Bool
True Bool
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Bool
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
<$ 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 ' '
let starts = [Text
"p", Text
"table", Text
"bq", Text
"bc", Text
"pre", Text
"h1", Text
"h2", Text
"h3",
Text
"h4", Text
"h5", Text
"h6", Text
"pre", Text
"###", Text
"notextile"]
let ender = () ()
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m ()
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 Attr]
-> ParsecT Sources ParserState m Attr
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 Attr)
-> [Text] -> [ParsecT Sources ParserState m Attr]
forall a b. (a -> b) -> [a] -> [b]
map Text -> ParsecT Sources ParserState m Attr
forall (m :: * -> *). PandocMonad m => Text -> TextileParser m Attr
explicitBlockStart [Text]
starts)
contents <- if extended
then do
f <- anyLine
rest <- many (notFollowedBy ender *> anyLine)
return (f:rest)
else manyTill anyLine blanklines
return $ B.codeBlock (trimTrailingNewlines (T.unlines contents))
trimTrailingNewlines :: Text -> Text
trimTrailingNewlines :: Text -> Text
trimTrailingNewlines = (Char -> Bool) -> Text -> Text
T.dropWhileEnd (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'\n')
codeBlockHtml :: PandocMonad m => TextileParser m Blocks
codeBlockHtml :: forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
codeBlockHtml = 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
(t@(TagOpen _ attrs),_) <- (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 ((Text -> Bool) -> (NoteTable -> Bool) -> Tag Text -> Bool
forall str.
(str -> Bool) -> ([Attribute str] -> Bool) -> Tag str -> Bool
tagOpen (Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
==Text
"pre") (Bool -> NoteTable -> Bool
forall a b. a -> b -> a
const Bool
True))
result' <- T.pack <$> manyTill anyChar (htmlTag (tagClose (=="pre")))
let result'' = case Text -> Maybe (Char, Text)
T.uncons Text
result' of
Just (Char
'\n', Text
xs) -> Text
xs
Maybe (Char, Text)
_ -> Text
result'
let result''' = case Text -> Maybe (Text, Char)
T.unsnoc Text
result'' of
Just (Text
xs, Char
'\n') -> Text
xs
Maybe (Text, Char)
_ -> Text
result''
let classes = Text -> [Text]
T.words (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> Tag Text -> Text
forall str.
(Show str, Eq str, StringLike str) =>
str -> Tag str -> str
fromAttrib Text
"class" Tag Text
t
let ident = Text -> Tag Text -> Text
forall str.
(Show str, Eq str, StringLike str) =>
str -> Tag str -> str
fromAttrib Text
"id" Tag Text
t
let kvs = [(Text
k,Text
v) | (Text
k,Text
v) <- NoteTable
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"]
return $ B.codeBlockWith (ident,classes,kvs) result'''
header :: PandocMonad m => TextileParser m Blocks
= 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
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
'h'
level <- Char -> Int
digitToInt (Char -> Int)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Int
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
oneOf [Char]
"123456"
attr <- attributes
char '.'
lookAhead whitespace
name <- trimInlines . mconcat <$> many inline
attr' <- registerHeader attr name
return $ B.headerWith attr' level name
blockQuote :: PandocMonad m => TextileParser m Blocks
blockQuote :: forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
blockQuote = 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
[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]
string [Char]
"bq" ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
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 Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes ParsecT Sources ParserState m Attr
-> 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 Char
-> 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 =>
TextileParser m (Many Inline)
whitespace
Many Block -> Many Block
B.blockQuote (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 (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
para
hrule :: PandocMonad m => TextileParser m Blocks
hrule :: forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
hrule = 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
ParsecT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
start <- [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
oneOf [Char]
"-*"
count 2 (skipSpaces >> char start)
skipMany (spaceChar <|> char start)
newline
optional blanklines
return B.horizontalRule
anyList :: PandocMonad m => TextileParser m Blocks
anyList :: forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
anyList = 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
$ Int -> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
anyListAtDepth Int
1 ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m Text
-> 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 Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
blanklines
anyListAtDepth :: PandocMonad m => Int -> TextileParser m Blocks
anyListAtDepth :: forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
anyListAtDepth Int
depth = [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 [ Int -> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
bulletListAtDepth Int
depth,
Int -> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
orderedListAtDepth Int
depth,
ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
definitionList ]
bulletListAtDepth :: PandocMonad m => Int -> TextileParser m Blocks
bulletListAtDepth :: forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
bulletListAtDepth Int
depth = 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
$ [Many Block] -> Many Block
B.bulletList ([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 (Many Block)
-> ParsecT Sources ParserState m [Many Block]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (Int -> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
bulletListItemAtDepth Int
depth)
bulletListItemAtDepth :: PandocMonad m => Int -> TextileParser m Blocks
bulletListItemAtDepth :: forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
bulletListItemAtDepth Int
depth = 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
Int -> TextileParser m ()
forall (m :: * -> *). PandocMonad m => Int -> TextileParser m ()
bulletListStartAtDepth Int
depth
Int -> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
genericListItemContentsAtDepth Int
depth
orderedListAtDepth :: PandocMonad m => Int -> TextileParser m Blocks
orderedListAtDepth :: forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
orderedListAtDepth Int
depth = 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
(startNum, firstItem) <- Int -> TextileParser m (Int, Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Int, Many Block)
firstOrderedListItemAtDepth Int
depth
moreItems <- many (orderedListItemAtDepth depth)
let listItems = Many Block
firstItem Many Block -> [Many Block] -> [Many Block]
forall a. a -> [a] -> [a]
: [Many Block]
moreItems
return $ B.orderedListWith (startNum, DefaultStyle, DefaultDelim) listItems
firstOrderedListItemAtDepth :: PandocMonad m => Int
-> TextileParser m (Int, Blocks)
firstOrderedListItemAtDepth :: forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Int, Many Block)
firstOrderedListItemAtDepth Int
depth = ParsecT Sources ParserState m (Int, Many Block)
-> ParsecT Sources ParserState m (Int, Many Block)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Int, Many Block)
-> ParsecT Sources ParserState m (Int, Many Block))
-> ParsecT Sources ParserState m (Int, Many Block)
-> ParsecT Sources ParserState m (Int, Many Block)
forall a b. (a -> b) -> a -> b
$ do
startNum <- Int -> TextileParser m Int
forall (m :: * -> *). PandocMonad m => Int -> TextileParser m Int
orderedListStartAtDepth Int
depth
contents <- genericListItemContentsAtDepth depth
return (startNum, contents)
orderedListItemAtDepth :: PandocMonad m => Int -> TextileParser m Blocks
orderedListItemAtDepth :: forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
orderedListItemAtDepth Int
depth = 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
Int -> TextileParser m Int
forall (m :: * -> *). PandocMonad m => Int -> TextileParser m Int
orderedListStartAtDepth Int
depth
Int -> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
genericListItemContentsAtDepth Int
depth
orderedListStartAtDepth :: PandocMonad m => Int -> TextileParser m Int
orderedListStartAtDepth :: forall (m :: * -> *). PandocMonad m => Int -> TextileParser m Int
orderedListStartAtDepth Int
depth = Int
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
depth (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 Int
-> ParsecT Sources ParserState m Int
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 Int
-> ParsecT Sources ParserState m Int
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState m Int
forall (m :: * -> *). PandocMonad m => TextileParser m Int
orderedListStartAttr ParsecT Sources ParserState m Int
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m Int
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
<* (TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes TextileParser m Attr
-> 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 =>
TextileParser m (Many Inline)
whitespace)
bulletListStartAtDepth :: PandocMonad m => Int -> TextileParser m ()
bulletListStartAtDepth :: forall (m :: * -> *). PandocMonad m => Int -> TextileParser m ()
bulletListStartAtDepth Int
depth = () ()
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m ()
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
<$ (Int
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
depth (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 Attr
-> ParsecT Sources ParserState m Attr
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 Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes ParsecT Sources ParserState m Attr
-> 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 =>
TextileParser m (Many Inline)
whitespace)
genericListItemContentsAtDepth :: PandocMonad m => Int
-> TextileParser m Blocks
genericListItemContentsAtDepth :: forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
genericListItemContentsAtDepth Int
depth = do
contents <- [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 (Many Block)
-> ParsecT Sources ParserState m [Many Block]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ((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 [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 =>
TextileParser m (Many Inline)
inline) 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)
-> 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 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 (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
>> ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
codeBlockHtml))
newline
sublist <- option mempty (anyListAtDepth (depth + 1))
return $ contents <> sublist
definitionList :: PandocMonad m => TextileParser m Blocks
definitionList :: forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
definitionList = 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
$ [(Many Inline, [Many Block])] -> Many Block
B.definitionList ([(Many Inline, [Many Block])] -> Many Block)
-> ParsecT Sources ParserState m [(Many Inline, [Many Block])]
-> ParsecT Sources ParserState m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (Many Inline, [Many Block])
-> ParsecT Sources ParserState m [(Many Inline, [Many Block])]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m (Many Inline, [Many Block])
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline, [Many Block])
definitionListItem
listStart :: PandocMonad m => TextileParser m ()
listStart :: forall (m :: * -> *). PandocMonad m => TextileParser m ()
listStart = Char -> TextileParser m ()
forall (m :: * -> *). PandocMonad m => Char -> TextileParser m ()
genericListStart Char
'*'
TextileParser m () -> TextileParser m () -> TextileParser m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () () -> TextileParser m () -> TextileParser m ()
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
<$ TextileParser m ()
forall (m :: * -> *). PandocMonad m => TextileParser m ()
orderedListStart
TextileParser m () -> TextileParser m () -> TextileParser 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 (Many Inline)
-> TextileParser m ()
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 (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
definitionListStart
genericListStart :: PandocMonad m => Char -> TextileParser m ()
genericListStart :: forall (m :: * -> *). PandocMonad m => Char -> TextileParser m ()
genericListStart Char
c = () ()
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m ()
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 (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 Char
-> ParsecT Sources ParserState m [Char]
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
c) ParsecT Sources ParserState m [Char]
-> 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 =>
TextileParser m (Many Inline)
whitespace)
orderedListStart :: PandocMonad m => TextileParser m ()
orderedListStart :: forall (m :: * -> *). PandocMonad m => TextileParser m ()
orderedListStart = () ()
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m ()
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 (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 Char
-> ParsecT Sources ParserState m [Char]
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
'#') ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m Int
-> ParsecT Sources ParserState m Int
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 Int
-> ParsecT Sources ParserState m Int
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState m Int
forall (m :: * -> *). PandocMonad m => TextileParser m Int
orderedListStartAttr ParsecT Sources ParserState m Int
-> 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 =>
TextileParser m (Many Inline)
whitespace)
basicDLStart :: PandocMonad m => TextileParser m ()
basicDLStart :: forall (m :: * -> *). PandocMonad m => TextileParser m ()
basicDLStart = 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
'-'
TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
whitespace
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
definitionListStart :: PandocMonad m => TextileParser m Inlines
definitionListStart :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
definitionListStart = 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
TextileParser m ()
forall (m :: * -> *). PandocMonad m => TextileParser m ()
basicDLStart
Many Inline -> Many Inline
trimInlines (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
<$>
ParsecT Sources ParserState m (Many Inline)
-> TextileParser 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 =>
TextileParser m (Many Inline)
inline
( TextileParser m () -> TextileParser m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (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
-> TextileParser m () -> TextileParser 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
*> TextileParser m () -> TextileParser m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead TextileParser m ()
forall (m :: * -> *). PandocMonad m => TextileParser m ()
basicDLStart)
TextileParser m () -> TextileParser m () -> TextileParser m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TextileParser m () -> TextileParser m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m () -> TextileParser 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 [Char] -> TextileParser m ()
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
<$ [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]
string [Char]
":="))
)
definitionListItem :: PandocMonad m => TextileParser m (Inlines, [Blocks])
definitionListItem :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline, [Many Block])
definitionListItem = ParsecT Sources ParserState m (Many Inline, [Many Block])
-> ParsecT Sources ParserState m (Many Inline, [Many Block])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Many Inline, [Many Block])
-> ParsecT Sources ParserState m (Many Inline, [Many Block]))
-> ParsecT Sources ParserState m (Many Inline, [Many Block])
-> ParsecT Sources ParserState m (Many Inline, [Many Block])
forall a b. (a -> b) -> a -> b
$ do
term <- [Many Inline] -> Many Inline
forall a. Monoid a => [a] -> a
mconcat ([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] -> [Many Inline]
forall a. a -> [a] -> [a]
intersperse Many Inline
B.linebreak ([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
<$> 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 =>
TextileParser m (Many Inline)
definitionListStart
def' <- string ":=" *> optional whitespace *> (multilineDef <|> inlineDef)
return (term, def')
where inlineDef :: PandocMonad m => TextileParser m [Blocks]
inlineDef :: forall (m :: * -> *). PandocMonad m => TextileParser m [Many Block]
inlineDef = (Many Inline -> [Many Block])
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m [Many Block]
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\Many Inline
d -> [Many Inline -> Many Block
B.plain Many Inline
d])
(ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m [Many Block])
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m [Many Block]
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m (Many Inline)
-> 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 (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser 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
>> (Many Inline -> Many Inline
trimInlines (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
<$> 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]
many ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
inline) ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m Char
-> 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
<* ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
multilineDef :: PandocMonad m => TextileParser m [Blocks]
multilineDef :: forall (m :: * -> *). PandocMonad m => TextileParser m [Many Block]
multilineDef = 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
ParsecT Sources ParserState m (Many Inline)
-> 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 (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
whitespace 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
>> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
s <- [Char] -> Text
T.pack ([Char] -> Text)
-> ParsecT Sources ParserState m [Char]
-> 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 [Char]
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 (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 ([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]
string [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
>> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline))
ds <- parseFromString' parseBlocks (s <> "\n\n")
return [ds]
rawHtmlBlock :: PandocMonad m => TextileParser m Blocks
rawHtmlBlock :: forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
rawHtmlBlock = 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
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
(_,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 -> Bool
isBlockTag
optional blanklines
return $ B.rawBlock "html" b
rawLaTeXBlock' :: PandocMonad m => TextileParser m Blocks
rawLaTeXBlock' :: forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
rawLaTeXBlock' = do
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_raw_tex
Text -> Text -> Many Block
B.rawBlock Text
"latex" (Text -> Many Block)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Sources ParserState m Text
forall (m :: * -> *) s.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
ParsecT Sources s m Text
rawLaTeXBlock 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
<* ParsecT Sources ParserState m ()
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces)
para :: PandocMonad m => TextileParser m Blocks
para :: forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
para = Many Inline -> Many Block
B.para (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
trimInlines (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 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 [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 =>
TextileParser m (Many Inline)
inline
toAlignment :: Char -> Alignment
toAlignment :: Char -> Alignment
toAlignment Char
'<' = Alignment
AlignLeft
toAlignment Char
'>' = Alignment
AlignRight
toAlignment Char
'=' = Alignment
AlignCenter
toAlignment Char
_ = Alignment
AlignDefault
cellAttributes :: PandocMonad m => TextileParser m (Bool, Alignment)
cellAttributes :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Bool, Alignment)
cellAttributes = ParsecT Sources ParserState m (Bool, Alignment)
-> ParsecT Sources ParserState m (Bool, Alignment)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Bool, Alignment)
-> ParsecT Sources ParserState m (Bool, Alignment))
-> ParsecT Sources ParserState m (Bool, Alignment)
-> ParsecT Sources ParserState m (Bool, Alignment)
forall a b. (a -> b) -> a -> b
$ do
isHeader <- Bool
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (Bool
True Bool
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Bool
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
<$ 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
'_')
optional $ try $ oneOf "/\\" >> many1 digit
alignment <- option AlignDefault $ toAlignment <$> oneOf "<>="
_ <- attributes
char '.'
return (isHeader, alignment)
tableCell :: PandocMonad m => TextileParser m ((Bool, Alignment), Blocks)
tableCell :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m ((Bool, Alignment), Many Block)
tableCell = ParsecT Sources ParserState m ((Bool, Alignment), Many Block)
-> ParsecT Sources ParserState m ((Bool, Alignment), Many Block)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m ((Bool, Alignment), Many Block)
-> ParsecT Sources ParserState m ((Bool, Alignment), Many Block))
-> ParsecT Sources ParserState m ((Bool, Alignment), Many Block)
-> ParsecT Sources ParserState m ((Bool, Alignment), 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
'|'
(isHeader, alignment) <- (Bool, Alignment)
-> ParsecT Sources ParserState m (Bool, Alignment)
-> ParsecT Sources ParserState m (Bool, Alignment)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Bool
False, Alignment
AlignDefault) ParsecT Sources ParserState m (Bool, Alignment)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Bool, Alignment)
cellAttributes
notFollowedBy blankline
raw <- trim . T.pack <$>
many (noneOf "|\n" <|> try (char '\n' <* notFollowedBy blankline))
content <- parseFromString' parseBlocks (raw <> "\n\n")
let content' = case Many Block -> [Block]
forall a. Many a -> [a]
B.toList Many Block
content of
[Para [Inline]
ils] -> Many Inline -> Many Block
B.plain ([Inline] -> Many Inline
forall a. [a] -> Many a
B.fromList [Inline]
ils)
[Block]
_ -> Many Block
content
return ((isHeader, alignment), content')
tableRow :: PandocMonad m => TextileParser m [((Bool, Alignment), Blocks)]
tableRow :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m [((Bool, Alignment), Many Block)]
tableRow = ParsecT Sources ParserState m [((Bool, Alignment), Many Block)]
-> ParsecT Sources ParserState m [((Bool, Alignment), Many Block)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m [((Bool, Alignment), Many Block)]
-> ParsecT Sources ParserState m [((Bool, Alignment), Many Block)])
-> ParsecT Sources ParserState m [((Bool, Alignment), Many Block)]
-> ParsecT Sources ParserState m [((Bool, Alignment), Many Block)]
forall a b. (a -> b) -> a -> b
$ do
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]
-> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ 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
$ do
_ <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
char '.'
many1 spaceChar
ParsecT Sources ParserState m ((Bool, Alignment), Many Block)
-> ParsecT Sources ParserState m [((Bool, Alignment), Many Block)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m ((Bool, Alignment), Many Block)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m ((Bool, Alignment), Many Block)
tableCell ParsecT Sources ParserState m [((Bool, Alignment), Many Block)]
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [((Bool, Alignment), 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
<* 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 [((Bool, Alignment), Many Block)]
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [((Bool, Alignment), 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
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
table :: PandocMonad m => TextileParser m Blocks
table :: forall (m :: * -> *). PandocMonad m => TextileParser 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
caption <- Many Inline
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Many Inline
forall a. Monoid a => a
mempty (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)
-> 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]
string [Char]
"table"
_ <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
char '.'
rawcapt <- trim <$> anyLine
parseFromString' (mconcat <$> many inline) rawcapt
rawrows <- many1 $ skipMany ignorableRow >> tableRow
skipMany ignorableRow
blanklines
let (headers, rows) = case rawrows of
([((Bool, Alignment), Many Block)]
toprow:[[((Bool, Alignment), Many Block)]]
rest) | (((Bool, Alignment), Many Block) -> Bool)
-> [((Bool, Alignment), Many Block)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any ((Bool, Alignment) -> Bool
forall a b. (a, b) -> a
fst ((Bool, Alignment) -> Bool)
-> (((Bool, Alignment), Many Block) -> (Bool, Alignment))
-> ((Bool, Alignment), Many Block)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Bool, Alignment), Many Block) -> (Bool, Alignment)
forall a b. (a, b) -> a
fst) [((Bool, Alignment), Many Block)]
toprow ->
([((Bool, Alignment), Many Block)]
toprow, [[((Bool, Alignment), Many Block)]]
rest)
[[((Bool, Alignment), Many Block)]]
_ -> ([((Bool, Alignment), Many Block)]
forall a. Monoid a => a
mempty, [[((Bool, Alignment), Many Block)]]
rawrows)
let nbOfCols = NonEmpty Int -> Int
forall a. Ord a => NonEmpty a -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum (NonEmpty Int -> Int) -> NonEmpty Int -> Int
forall a b. (a -> b) -> a -> b
$ ([((Bool, Alignment), Many Block)] -> Int)
-> NonEmpty [((Bool, Alignment), Many Block)] -> NonEmpty Int
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [((Bool, Alignment), Many Block)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([((Bool, Alignment), Many Block)]
headers [((Bool, Alignment), Many Block)]
-> [[((Bool, Alignment), Many Block)]]
-> NonEmpty [((Bool, Alignment), Many Block)]
forall a. a -> [a] -> NonEmpty a
:| [[((Bool, Alignment), Many Block)]]
rows)
let aligns = ([Alignment] -> Alignment) -> [[Alignment]] -> [Alignment]
forall a b. (a -> b) -> [a] -> [b]
map (Alignment
-> (NonEmpty Alignment -> Alignment)
-> Maybe (NonEmpty Alignment)
-> Alignment
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Alignment
AlignDefault NonEmpty Alignment -> Alignment
forall a. Ord a => NonEmpty a -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum (Maybe (NonEmpty Alignment) -> Alignment)
-> ([Alignment] -> Maybe (NonEmpty Alignment))
-> [Alignment]
-> Alignment
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Alignment] -> Maybe (NonEmpty Alignment)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty) ([[Alignment]] -> [Alignment]) -> [[Alignment]] -> [Alignment]
forall a b. (a -> b) -> a -> b
$
[[Alignment]] -> [[Alignment]]
forall a. [[a]] -> [[a]]
transpose ([[Alignment]] -> [[Alignment]]) -> [[Alignment]] -> [[Alignment]]
forall a b. (a -> b) -> a -> b
$ ([((Bool, Alignment), Many Block)] -> [Alignment])
-> [[((Bool, Alignment), Many Block)]] -> [[Alignment]]
forall a b. (a -> b) -> [a] -> [b]
map ((((Bool, Alignment), Many Block) -> Alignment)
-> [((Bool, Alignment), Many Block)] -> [Alignment]
forall a b. (a -> b) -> [a] -> [b]
map ((Bool, Alignment) -> Alignment
forall a b. (a, b) -> b
snd ((Bool, Alignment) -> Alignment)
-> (((Bool, Alignment), Many Block) -> (Bool, Alignment))
-> ((Bool, Alignment), Many Block)
-> Alignment
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Bool, Alignment), Many Block) -> (Bool, Alignment)
forall a b. (a, b) -> a
fst)) ([((Bool, Alignment), Many Block)]
headers[((Bool, Alignment), Many Block)]
-> [[((Bool, Alignment), Many Block)]]
-> [[((Bool, Alignment), Many Block)]]
forall a. a -> [a] -> [a]
:[[((Bool, Alignment), Many Block)]]
rows)
let 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]
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)]
return $ B.table (B.simpleCaption $ B.plain caption)
(zip aligns (replicate nbOfCols ColWidthDefault))
(TableHead nullAttr $ toHeaderRow $ map snd headers)
[TableBody nullAttr 0 [] $ map (toRow . map snd) rows]
(TableFoot nullAttr [])
ignorableRow :: PandocMonad m => TextileParser m ()
ignorableRow :: forall (m :: * -> *). PandocMonad m => TextileParser m ()
ignorableRow = 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
$ 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
'|'
[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
oneOf [Char]
":^-~"
_ <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
char '.'
_ <- anyLine
return ()
explicitBlockStart :: PandocMonad m => Text -> TextileParser m Attr
explicitBlockStart :: forall (m :: * -> *). PandocMonad m => Text -> TextileParser m Attr
explicitBlockStart Text
name = ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr)
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
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]
string (Text -> [Char]
T.unpack Text
name)
attr <- ParsecT Sources ParserState m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
char '.'
optional whitespace
optional endline
return attr
explicitBlock :: PandocMonad m
=> Text
-> TextileParser m Blocks
-> TextileParser m Blocks
explicitBlock :: forall (m :: * -> *).
PandocMonad m =>
Text
-> TextileParser m (Many Block) -> TextileParser m (Many Block)
explicitBlock Text
name TextileParser m (Many Block)
blk = TextileParser m (Many Block) -> TextileParser m (Many Block)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m (Many Block) -> TextileParser m (Many Block))
-> TextileParser m (Many Block) -> TextileParser m (Many Block)
forall a b. (a -> b) -> a -> b
$ do
attr <- Text -> TextileParser m Attr
forall (m :: * -> *). PandocMonad m => Text -> TextileParser m Attr
explicitBlockStart Text
name
contents <- blk
return $ if attr == nullAttr
then contents
else B.divWith attr contents
inline :: PandocMonad m => TextileParser m Inlines
inline :: forall (m :: * -> *).
PandocMonad m =>
TextileParser 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 =>
[TextileParser m (Many Inline)]
inlineParsers ParsecT Sources ParserState m (Many Inline)
-> [Char] -> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"inline"
inlineParsers :: PandocMonad m => [TextileParser m Inlines]
inlineParsers :: forall (m :: * -> *).
PandocMonad m =>
[TextileParser m (Many Inline)]
inlineParsers = [ TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
str
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
whitespace
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
endline
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
code
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
escapedInline
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
spanGroup
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
inlineMarkup
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
groupedInlineMarkup
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
rawHtmlInline
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
rawLaTeXInline'
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
note
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
link
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
image
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
mark
, Text -> Many Inline
B.str (Text -> Many Inline)
-> ParsecT Sources ParserState m Text
-> TextileParser m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
characterReference
, TextileParser m (Many Inline) -> TextileParser 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 TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
inline
, TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
symbol
]
inlineMarkup :: PandocMonad m => TextileParser m Inlines
inlineMarkup :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
inlineMarkup = [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 [ TextileParser m [Char]
-> (Many Inline -> Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Many Inline -> Many Inline) -> TextileParser m (Many Inline)
simpleInline ([Char] -> TextileParser m [Char]
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"??") ([Citation] -> Many Inline -> Many Inline
B.cite [])
, TextileParser m [Char]
-> (Many Inline -> Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Many Inline -> Many Inline) -> TextileParser m (Many Inline)
simpleInline ([Char] -> TextileParser m [Char]
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"**") Many Inline -> Many Inline
B.strong
, TextileParser m [Char]
-> (Many Inline -> Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Many Inline -> Many Inline) -> TextileParser m (Many Inline)
simpleInline ([Char] -> TextileParser m [Char]
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"__") Many Inline -> Many Inline
B.emph
, TextileParser m Char
-> (Many Inline -> Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Many Inline -> Many Inline) -> TextileParser m (Many Inline)
simpleInline (Char -> TextileParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'*') Many Inline -> Many Inline
B.strong
, TextileParser m Char
-> (Many Inline -> Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Many Inline -> Many Inline) -> TextileParser m (Many Inline)
simpleInline (Char -> TextileParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'_') Many Inline -> Many Inline
B.emph
, TextileParser m Char
-> (Many Inline -> Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Many Inline -> Many Inline) -> TextileParser m (Many Inline)
simpleInline (Char -> TextileParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'+') Many Inline -> Many Inline
B.underline
, TextileParser m Char
-> (Many Inline -> Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Many Inline -> Many Inline) -> TextileParser m (Many Inline)
simpleInline (Char -> TextileParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-' TextileParser m Char
-> ParsecT Sources ParserState m () -> TextileParser 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
<* TextileParser 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 -> TextileParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-')) Many Inline -> Many Inline
B.strikeout
, TextileParser m Char
-> (Many Inline -> Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Many Inline -> Many Inline) -> TextileParser m (Many Inline)
simpleInline (Char -> TextileParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'^') Many Inline -> Many Inline
B.superscript
, TextileParser m Char
-> (Many Inline -> Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Many Inline -> Many Inline) -> TextileParser m (Many Inline)
simpleInline (Char -> TextileParser m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'~') Many Inline -> Many Inline
B.subscript
]
spanGroup :: PandocMonad m => TextileParser m Inlines
spanGroup :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
spanGroup = 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
ParsecT Sources ParserState m Bool
forall s (m :: * -> *) a st.
(Stream s m a, HasLastStrPosition st) =>
ParsecT s st m Bool
notAfterString ParsecT Sources ParserState m Bool
-> (Bool -> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
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
>>= Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard
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 (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 =>
TextileParser m (Many Inline)
whitespace
attr <- Attr
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Attr
nullAttr ParsecT Sources ParserState m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
contents <- mconcat <$> manyTill
(try (((B.space <>) <$> try (whitespace *> notFollowedBy newline *> inline))
<|> try (notFollowedBy newline *> inline)))
(try (char '%' <* lookAhead (newline <|> ' ' <$ whitespace)))
pure $ B.spanWith attr contents
mark :: PandocMonad m => TextileParser m Inlines
mark :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
mark = 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
$ 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 (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)
-> 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)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
tm 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)
-> 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)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
reg 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 =>
TextileParser m (Many Inline)
copy)
reg :: PandocMonad m => TextileParser m Inlines
reg :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
reg = 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
oneOf [Char]
"Rr"
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
')'
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 -> ParsecT Sources ParserState m (Many Inline))
-> Many Inline -> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ Text -> Many Inline
B.str Text
"\174"
tm :: PandocMonad m => TextileParser m Inlines
tm :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
tm = 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
oneOf [Char]
"Tt"
[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
oneOf [Char]
"Mm"
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
')'
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 -> ParsecT Sources ParserState m (Many Inline))
-> Many Inline -> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ Text -> Many Inline
B.str Text
"\8482"
copy :: PandocMonad m => TextileParser m Inlines
copy :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
copy = 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
oneOf [Char]
"Cc"
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
')'
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 -> ParsecT Sources ParserState m (Many Inline))
-> Many Inline -> ParsecT Sources ParserState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ Text -> Many Inline
B.str Text
"\169"
note :: PandocMonad m => TextileParser m Inlines
note :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
note = 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
ref <- 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 (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> 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]
many1 ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit 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 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
']'
notes <- stateNotes <$> getState
case lookup (T.pack ref) notes of
Maybe Text
Nothing -> [Char] -> ParsecT Sources ParserState m (Many Inline)
forall a. HasCallStack => [Char] -> ParsecT Sources ParserState m a
forall (m :: * -> *) a.
(MonadFail m, HasCallStack) =>
[Char] -> m a
Prelude.fail [Char]
"note not found"
Just Text
raw -> Many Block -> Many Inline
B.note (Many Block -> Many Inline)
-> ParsecT Sources ParserState m (Many Block)
-> ParsecT Sources ParserState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
parseBlocks Text
raw
markupChars :: [Char]
markupChars :: [Char]
markupChars = [Char]
"\\*#_@~-+^|%=[]&"
stringBreakers :: [Char]
stringBreakers :: [Char]
stringBreakers = [Char]
" \t\n\r.,\"'?!;:<>«»„“”‚‘’()[]"
wordBoundaries :: [Char]
wordBoundaries :: [Char]
wordBoundaries = [Char]
markupChars [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
stringBreakers
hyphenedWords :: PandocMonad m => TextileParser m Text
hyphenedWords :: forall (m :: * -> *). PandocMonad m => TextileParser m Text
hyphenedWords = do
x <- TextileParser m Text
forall (m :: * -> *). PandocMonad m => TextileParser m Text
wordChunk
xs <- many (try $ char '-' >> wordChunk)
return $ T.intercalate "-" (x:xs)
wordChunk :: PandocMonad m => TextileParser m Text
wordChunk :: forall (m :: * -> *). PandocMonad m => TextileParser m Text
wordChunk = 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
$ do
hd <- [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
noneOf [Char]
wordBoundaries
tl <- many ( noneOf wordBoundaries <|>
try (notFollowedBy' note *> oneOf markupChars
<* lookAhead (noneOf wordBoundaries) ) )
return $ T.pack $ hd:tl
str :: PandocMonad m => TextileParser m Inlines
str :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
str = do
baseStr <- TextileParser m Text
forall (m :: * -> *). PandocMonad m => TextileParser m Text
hyphenedWords
fullStr <- option baseStr $ try $ do
guard $ T.all isUpper baseStr
acro <- T.pack <$> enclosed (char '(') (char ')') anyChar'
return $ T.concat [baseStr, " (", acro, ")"]
updateLastStrPos
return $ B.str fullStr
whitespace :: PandocMonad m => TextileParser m Inlines
whitespace :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
whitespace = 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]
many1 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 [Char]
-> 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 ParsecT Sources ParserState m (Many Inline)
-> [Char] -> ParsecT Sources ParserState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"whitespace"
endline :: PandocMonad m => TextileParser m Inlines
endline :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
endline = 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
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 ()
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 s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
ParsecT Sources ParserState m ()
-> 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 ()
forall (m :: * -> *). PandocMonad m => TextileParser m ()
listStart
ParsecT Sources ParserState m (Many Block)
-> 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 Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
rawHtmlBlock
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
rawHtmlInline :: PandocMonad m => TextileParser m Inlines
rawHtmlInline :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
rawHtmlInline = Text -> Text -> Many Inline
B.rawInline Text
"html" (Text -> Many Inline)
-> ((Tag Text, Text) -> Text) -> (Tag Text, Text) -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tag Text, Text) -> Text
forall a b. (a, b) -> b
snd ((Tag Text, Text) -> Many Inline)
-> ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f 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 -> Bool
isInlineTag
rawLaTeXInline' :: PandocMonad m => TextileParser m Inlines
rawLaTeXInline' :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
rawLaTeXInline' = 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
Extension -> ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_raw_tex
Text -> Text -> Many Inline
B.rawInline Text
"latex" (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 Text
forall (m :: * -> *) s.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
ParsecT Sources s m Text
rawLaTeXInline
link :: PandocMonad m => TextileParser m Inlines
link :: forall (m :: * -> *).
PandocMonad m =>
TextileParser 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
bracketed <- (Bool
True Bool
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Bool
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
<$ 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 Bool
-> ParsecT Sources ParserState m Bool
-> ParsecT Sources ParserState m Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool -> ParsecT Sources ParserState m Bool
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
char '"' *> notFollowedBy (oneOf " \t\n\r")
attr <- attributes
name <- trimInlines . mconcat <$>
withQuoteContext InDoubleQuote (many1Till inline (char '"'))
url <- linkUrl bracketed
let name' = if Many Inline -> [Inline]
forall a. Many a -> [a]
B.toList Many Inline
name [Inline] -> [Inline] -> Bool
forall a. Eq a => a -> a -> Bool
== [Text -> Inline
Str Text
"$"] then Text -> Many Inline
B.str Text
url else Many Inline
name
return $ if attr == nullAttr
then B.link url "" name'
else B.spanWith attr $ B.link url "" name'
linkUrl :: PandocMonad m => Bool -> TextileParser m Text
linkUrl :: forall (m :: * -> *). PandocMonad m => Bool -> TextileParser m Text
linkUrl Bool
bracketed = 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
':'
let stop :: ParsecT Sources u m Char
stop = if Bool
bracketed
then 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
']'
else ParsecT Sources u m Char -> ParsecT Sources u m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT 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
$ ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
space 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. Monad m => ParsecT Sources s m Char
eof' 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
<|> [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
oneOf [Char]
"[]" 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 -> ParsecT Sources u m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([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
oneOf [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 (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
(ParsecT Sources u m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
space 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 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. Monad m => ParsecT Sources s m Char
eof'))
rawLink <- [Char] -> Text
T.pack ([Char] -> Text)
-> ParsecT Sources ParserState m [Char]
-> 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 [Char]
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 s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar ParsecT Sources ParserState m Char
forall {u}. ParsecT Sources u m Char
stop
st <- getState
return $ case M.lookup (toKey rawLink) (stateKeys st) of
Maybe ((Text, Text), Attr)
Nothing -> Text
rawLink
Just ((Text
src, Text
_), Attr
_) -> Text
src
image :: PandocMonad m => TextileParser m Inlines
image :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
image = 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
'!' 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
space
(ident, cls, kvs) <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
let attr = case Text -> NoteTable -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"style" NoteTable
kvs of
Just Text
stls -> (Text
ident, [Text]
cls, [Text] -> Text -> NoteTable
pickStylesToKVs [Text
"width", Text
"height"] Text
stls)
Maybe Text
Nothing -> (Text
ident, [Text]
cls, NoteTable
kvs)
src <- T.pack <$> many1 (noneOf " \t\n\r!(")
alt <- fmap T.pack $ option "" $ try $ char '(' *> manyTill anyChar (char ')')
char '!'
let img = Attr -> Text -> Text -> Many Inline -> Many Inline
B.imageWith Attr
attr Text
src Text
alt (Text -> Many Inline
B.str Text
alt)
try (do
url <- linkUrl False
return (B.link url "" img))
<|> return img
escapedInline :: PandocMonad m => TextileParser m Inlines
escapedInline :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
escapedInline = TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
escapedEqs TextileParser m (Many Inline)
-> TextileParser m (Many Inline) -> TextileParser m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
escapedTag
escapedEqs :: PandocMonad m => TextileParser m Inlines
escapedEqs :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
escapedEqs = Text -> Many Inline
B.str (Text -> Many Inline) -> ([Char] -> Text) -> [Char] -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack ([Char] -> Many Inline)
-> ParsecT Sources ParserState m [Char]
-> 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 [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([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]
string [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 (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m [Char]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => TextileParser m Char
anyChar' (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]
string [Char]
"=="))
escapedTag :: PandocMonad m => TextileParser m Inlines
escapedTag :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
escapedTag = Text -> Many Inline
B.str (Text -> Many Inline) -> ([Char] -> Text) -> [Char] -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack ([Char] -> Many Inline)
-> ParsecT Sources ParserState m [Char]
-> 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 [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([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]
string [Char]
"<notextile>" 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 (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m [Char]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => TextileParser m Char
anyChar' (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]
string [Char]
"</notextile>"))
symbol :: PandocMonad m => TextileParser m Inlines
symbol :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
symbol = do
c <- 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 ()
-> 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 (Many Block)
-> 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 Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
rawHtmlBlock 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 (f :: * -> *) a b. Applicative f => f a -> f b -> 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
oneOf [Char]
wordBoundaries
updateLastStrPos
pure $ B.str . T.singleton $ c
code :: PandocMonad m => TextileParser m Inlines
code :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
code = TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
code1 TextileParser m (Many Inline)
-> TextileParser m (Many Inline) -> TextileParser m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TextileParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
code2
anyChar' :: PandocMonad m => TextileParser m Char
anyChar' :: forall (m :: * -> *). PandocMonad m => TextileParser m Char
anyChar' =
(Char -> Bool) -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=Char
'\n') 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
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (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 ()
-> 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 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 s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline)
code1 :: PandocMonad m => TextileParser m Inlines
code1 :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
code1 = Text -> Many Inline
B.code (Text -> Many Inline) -> ([Char] -> Text) -> [Char] -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack ([Char] -> Many Inline)
-> ParsecT Sources ParserState m [Char]
-> 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 Char
-> ParsecT Sources ParserState m [Char]
forall (m :: * -> *) t st a.
(PandocMonad m, Show t) =>
ParsecT Sources st m t
-> ParsecT Sources st m a -> ParsecT Sources st m [a]
surrounded (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
forall (m :: * -> *). PandocMonad m => TextileParser m Char
anyChar'
code2 :: PandocMonad m => TextileParser m Inlines
code2 :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
code2 = do
(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 ((Text -> Bool) -> (NoteTable -> Bool) -> Tag Text -> Bool
forall str.
(str -> Bool) -> ([Attribute str] -> Bool) -> Tag str -> Bool
tagOpen (Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
==Text
"tt") NoteTable -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null)
Text -> Many Inline
B.code (Text -> Many Inline) -> ([Char] -> Text) -> [Char] -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack ([Char] -> Many Inline)
-> ParsecT Sources ParserState m [Char]
-> 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 (Tag Text, Text)
-> ParsecT Sources ParserState m [Char]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => TextileParser m Char
anyChar' (ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m (Tag Text, Text))
-> ParsecT Sources ParserState m (Tag Text, Text)
-> ParsecT Sources ParserState m (Tag Text, Text)
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 -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text))
-> (Tag Text -> Bool)
-> ParsecT Sources ParserState m (Tag Text, Text)
forall a b. (a -> b) -> a -> b
$ (Text -> Bool) -> Tag Text -> Bool
forall str. (str -> Bool) -> Tag str -> Bool
tagClose (Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
==Text
"tt"))
orderedListStartAttr :: PandocMonad m => TextileParser m Int
orderedListStartAttr :: forall (m :: * -> *). PandocMonad m => TextileParser m Int
orderedListStartAttr = do
digits <- 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]
many ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit
case readMaybe digits :: Maybe Int of
Maybe Int
Nothing -> Int -> ParsecT Sources ParserState m Int
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Int
1
Just Int
n -> Int -> ParsecT Sources ParserState m Int
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Int
n
attributes :: PandocMonad m => TextileParser m Attr
attributes :: forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes = (Attr -> (Attr -> Attr) -> Attr) -> Attr -> [Attr -> Attr] -> Attr
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
L.foldl' (((Attr -> Attr) -> Attr -> Attr) -> Attr -> (Attr -> Attr) -> Attr
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Attr -> Attr) -> Attr -> Attr
forall a b. (a -> b) -> a -> b
($)) (Text
"",[],[]) ([Attr -> Attr] -> Attr)
-> ParsecT Sources ParserState m [Attr -> Attr]
-> ParsecT Sources ParserState m Attr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ParsecT Sources ParserState m [Attr -> Attr]
-> ParsecT Sources ParserState m [Attr -> Attr]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (do special <- (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Attr -> Attr
forall a. a -> a
id ParsecT Sources ParserState m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
specialAttribute
attrs <- many attribute
return (special : attrs))
specialAttribute :: PandocMonad m => TextileParser m (Attr -> Attr)
specialAttribute :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
specialAttribute = do
alignStr <- ([Char]
"center" [Char]
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
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
<$ 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 s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
([Char]
"justify" [Char]
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m [Char]
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 [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([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]
string [Char]
"<>")) ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m [Char]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
([Char]
"right" [Char]
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
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
<$ 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 s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
([Char]
"left" [Char]
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
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
<$ 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
'<')
notFollowedBy spaceChar
return $ addStyle $ T.pack $ "text-align:" ++ alignStr
attribute :: PandocMonad m => TextileParser m (Attr -> Attr)
attribute :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
attribute = ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr))
-> ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$
(ParsecT Sources ParserState m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
classIdAttr ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
styleAttr ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
langAttr) ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m (Attr -> Attr)
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 a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
classIdAttr :: PandocMonad m => TextileParser m (Attr -> Attr)
classIdAttr :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
classIdAttr = ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr))
-> ParsecT Sources ParserState m (Attr -> Attr)
-> ParsecT Sources ParserState m (Attr -> Attr)
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
'('
ws <- Text -> [Text]
T.words (Text -> [Text]) -> ([Char] -> Text) -> [Char] -> [Text]
forall a b. (a -> b) -> ([Char] -> a) -> [Char] -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` [Char] -> Text
T.pack ([Char] -> [Text])
-> ParsecT Sources ParserState m [Char]
-> 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 [Char]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => TextileParser 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
')')
case reverse ws of
[]
-> (Attr -> Attr) -> ParsecT Sources ParserState m (Attr -> Attr)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Attr -> Attr) -> ParsecT Sources ParserState m (Attr -> Attr))
-> (Attr -> Attr) -> ParsecT Sources ParserState m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$ \(Text
_,[Text]
_,NoteTable
keyvals) -> (Text
"",[],NoteTable
keyvals)
((Text -> Maybe (Char, Text)
T.uncons -> Just (Char
'#', Text
ident')):[Text]
classes')
-> (Attr -> Attr) -> ParsecT Sources ParserState m (Attr -> Attr)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Attr -> Attr) -> ParsecT Sources ParserState m (Attr -> Attr))
-> (Attr -> Attr) -> ParsecT Sources ParserState m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$ \(Text
_,[Text]
_,NoteTable
keyvals) -> (Text
ident',[Text]
classes',NoteTable
keyvals)
[Text]
classes'
-> (Attr -> Attr) -> ParsecT Sources ParserState m (Attr -> Attr)
forall a. a -> ParsecT Sources ParserState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Attr -> Attr) -> ParsecT Sources ParserState m (Attr -> Attr))
-> (Attr -> Attr) -> ParsecT Sources ParserState m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$ \(Text
_,[Text]
_,NoteTable
keyvals) -> (Text
"",[Text]
classes',NoteTable
keyvals)
styleAttr :: PandocMonad m => TextileParser m (Attr -> Attr)
styleAttr :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
styleAttr = do
style <- 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
$ ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
forall end s (m :: * -> *) st t a.
(Show end, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m t
-> ParsecT s st m end -> ParsecT s st m a -> ParsecT s st m [a]
enclosed (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
forall (m :: * -> *). PandocMonad m => TextileParser m Char
anyChar'
return $ addStyle $ T.pack style
addStyle :: Text -> Attr -> Attr
addStyle :: Text -> Attr -> Attr
addStyle Text
style (Text
id',[Text]
classes,NoteTable
keyvals) =
(Text
id',[Text]
classes,NoteTable
keyvals')
where keyvals' :: NoteTable
keyvals' = (Text
"style", Text
style') (Text, Text) -> NoteTable -> NoteTable
forall a. a -> [a] -> [a]
: [(Text
k,Text
v) | (Text
k,Text
v) <- NoteTable
keyvals, Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"style"]
style' :: Text
style' = Text
style Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
";" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
T.concat [Text
v | (Text
"style",Text
v) <- NoteTable
keyvals]
langAttr :: PandocMonad m => TextileParser m (Attr -> Attr)
langAttr :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
langAttr = do
lang <- 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
$ ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
forall end s (m :: * -> *) st t a.
(Show end, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m t
-> ParsecT s st m end -> ParsecT s st m a -> ParsecT s st m [a]
enclosed (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
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum
return $ \(Text
id',[Text]
classes,NoteTable
keyvals) -> (Text
id',[Text]
classes,(Text
"lang",[Char] -> Text
T.pack [Char]
lang)(Text, Text) -> NoteTable -> NoteTable
forall a. a -> [a] -> [a]
:NoteTable
keyvals)
surrounded :: (PandocMonad m, Show t)
=> ParsecT Sources st m t
-> ParsecT Sources st m a
-> ParsecT Sources st m [a]
surrounded :: forall (m :: * -> *) t st a.
(PandocMonad m, Show t) =>
ParsecT Sources st m t
-> ParsecT Sources st m a -> ParsecT Sources st m [a]
surrounded ParsecT Sources st m t
border =
ParsecT Sources st m ()
-> ParsecT Sources st m t
-> ParsecT Sources st m a
-> ParsecT Sources st m [a]
forall end s (m :: * -> *) st t a.
(Show end, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m t
-> ParsecT s st m end -> ParsecT s st m a -> ParsecT s st m [a]
enclosed (ParsecT Sources st m t
border ParsecT Sources st m t
-> ParsecT Sources st m () -> ParsecT Sources st m ()
forall a b.
ParsecT Sources st m a
-> ParsecT Sources st m b -> ParsecT Sources st m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources st m Char -> ParsecT Sources st m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ([Char] -> ParsecT Sources st m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
" \t\n\r")) (ParsecT Sources st m t -> ParsecT Sources st m t
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources st m t
border)
simpleInline :: PandocMonad m
=> TextileParser m t
-> (Inlines -> Inlines)
-> TextileParser m Inlines
simpleInline :: forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Many Inline -> Many Inline) -> TextileParser m (Many Inline)
simpleInline TextileParser m t
border Many Inline -> Many Inline
construct = 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
ParsecT Sources ParserState m Bool
forall s (m :: * -> *) a st.
(Stream s m a, HasLastStrPosition st) =>
ParsecT s st m Bool
notAfterString ParsecT Sources ParserState m Bool
-> (Bool -> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
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
>>= Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard
TextileParser m t
border TextileParser m t
-> 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 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] -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
" \t\n\r")
attr <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
body <- trimInlines . mconcat <$>
withQuoteContext InSingleQuote
(manyTill (((B.space <>) <$>
try (whitespace *> notFollowedBy newline >> inline))
<|> try (notFollowedBy newline >> inline))
(try border <* notFollowedBy alphaNum))
return $ construct $
if attr == nullAttr
then body
else B.spanWith attr body
groupedInlineMarkup :: PandocMonad m => TextileParser m Inlines
groupedInlineMarkup :: forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
groupedInlineMarkup = 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
'['
sp1 <- Many Inline
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Many Inline
forall a. Monoid a => a
mempty (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
B.space Many Inline
-> ParsecT Sources ParserState m (Many Inline)
-> ParsecT Sources ParserState m (Many Inline)
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 (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Many Inline)
whitespace
result <- withQuoteContext InSingleQuote inlineMarkup
sp2 <- option mempty $ B.space <$ whitespace
char ']'
return $ sp1 <> result <> sp2
eof' :: Monad m => ParsecT Sources s m Char
eof' :: forall (m :: * -> *) s. Monad m => ParsecT Sources s m Char
eof' = Char
'\n' Char -> ParsecT Sources s m () -> ParsecT Sources s m Char
forall a b. a -> ParsecT Sources s m b -> ParsecT Sources s m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources s m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof