{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns      #-}
{- |
   Module      : Text.Pandoc.Readers.Textile
   Copyright   : Copyright (C) 2010-2012 Paul Rivier
                               2010-2021 John MacFarlane
   License     : GNU GPL, version 2 or above

   Maintainer  : Paul Rivier <paul*rivier#demotera*com>
   Stability   : alpha
   Portability : portable

Conversion from Textile to 'Pandoc' document, based on the spec
available at https://www.promptworks.com/textile/.

Implemented and parsed:
 - Paragraphs
 - Code blocks
 - Lists
 - blockquote
 - Inlines : strong, emph, cite, code, deleted, superscript,
   subscript, links
 - footnotes
 - HTML-specific and CSS-specific attributes on headers

Left to be implemented:
 - dimension sign
 - all caps
 - continued blocks (ex bq..)

TODO : refactor common patterns across readers :
 - more ...

-}


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, foldl')
import Data.List.NonEmpty (NonEmpty(..), nonEmpty)
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.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)

-- | Parse a Textile text and return a Pandoc document.
readTextile :: (PandocMonad m, ToSources a)
            => ReaderOptions -- ^ Reader options
            -> a
            -> m Pandoc
readTextile :: 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)
  Either PandocError Pandoc
parsed <- ParserT Sources ParserState m Pandoc
-> ParserState -> Sources -> m (Either PandocError Pandoc)
forall (m :: * -> *) t st a.
(Monad m, ToSources t) =>
ParserT Sources st m a -> st -> t -> m (Either PandocError a)
readWithM ParserT Sources ParserState m Pandoc
forall (m :: * -> *). PandocMonad m => TextileParser m Pandoc
parseTextile ParserState
forall a. Default a => a
def{ stateOptions :: ReaderOptions
stateOptions = ReaderOptions
opts } Sources
sources
  case Either PandocError Pandoc
parsed of
     Right Pandoc
result -> Pandoc -> m Pandoc
forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
result
     Left PandocError
e       -> PandocError -> m Pandoc
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PandocError
e

type TextileParser = ParserT Sources ParserState

-- | Generate a Pandoc ADT from a textile document
parseTextile :: PandocMonad m => TextileParser m Pandoc
parseTextile :: 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) =>
ParserT s st m Char
blankline
  SourcePos
startPos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  -- go through once just to get list of reference keys and notes
  -- docMinusKeys is the raw document with blanks where the keys/notes were...
  let firstPassParser :: ParsecT Sources ParserState m (SourcePos, Text)
firstPassParser = do
        SourcePos
pos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
        Text
t <- TextileParser m Text
forall (m :: * -> *). PandocMonad m => TextileParser m Text
noteBlock TextileParser m Text
-> TextileParser m Text -> TextileParser m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TextileParser m Text
forall (m :: * -> *) st. Monad m => ParserT Sources st m Text
lineClump
        (SourcePos, Text)
-> ParsecT Sources ParserState m (SourcePos, Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (SourcePos
pos, Text
t)
  ParsecT Sources ParserState m (SourcePos, Text)
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [(SourcePos, 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 (SourcePos, Text)
firstPassParser ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParsecT Sources ParserState m [(SourcePos, Text)]
-> ([(SourcePos, Text)] -> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Sources -> ParsecT Sources ParserState m ()
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput (Sources -> ParsecT Sources ParserState m ())
-> ([(SourcePos, Text)] -> Sources)
-> [(SourcePos, Text)]
-> ParsecT Sources ParserState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(SourcePos, Text)] -> Sources
Sources
  SourcePos -> ParsecT Sources ParserState m ()
forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
setPosition SourcePos
startPos
  ParserState
st' <- ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let reversedNotes :: NoteTable
reversedNotes = ParserState -> NoteTable
stateNotes ParserState
st'
  (ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((ParserState -> ParserState) -> ParsecT Sources ParserState m ())
-> (ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ \ParserState
s -> ParserState
s { stateNotes :: NoteTable
stateNotes = NoteTable -> NoteTable
forall a. [a] -> [a]
reverse NoteTable
reversedNotes }
  -- now parse it for real...
  Meta -> [Block] -> Pandoc
Pandoc Meta
nullMeta ([Block] -> Pandoc)
-> (Many Block -> [Block]) -> Many Block -> Pandoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Many Block -> [Block]
forall a. Many a -> [a]
B.toList (Many Block -> Pandoc)
-> ParsecT Sources ParserState m (Many Block)
-> TextileParser m Pandoc
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)
parseBlocks -- FIXME

noteMarker :: PandocMonad m => TextileParser m Text
noteMarker :: TextileParser m Text
noteMarker = ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m [Char]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> ParsecT Sources ParserState m [Char]
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"fn" ParsecT Sources ParserState m [Char]
-> TextileParser m Text -> TextileParser m Text
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> Text
T.pack ([Char] -> Text)
-> ParsecT Sources ParserState m [Char] -> TextileParser 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
char Char
'.')

noteBlock :: PandocMonad m => TextileParser m Text
noteBlock :: TextileParser m Text
noteBlock = TextileParser m Text -> TextileParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Text -> TextileParser m Text)
-> TextileParser m Text -> TextileParser m Text
forall a b. (a -> b) -> a -> b
$ do
  SourcePos
startPos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  Text
ref <- TextileParser m Text
forall (m :: * -> *). PandocMonad m => TextileParser m Text
noteMarker
  ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
blankline
  Text
contents <- [Text] -> Text
T.unlines ([Text] -> Text)
-> ParsecT Sources ParserState m [Text] -> TextileParser m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TextileParser m Text
-> TextileParser m Text -> ParsecT Sources ParserState m [Text]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till TextileParser m Text
forall (m :: * -> *) st. Monad m => ParserT Sources st m Text
anyLine (TextileParser m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Text
blanklines TextileParser m Text
-> TextileParser m Text -> TextileParser m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TextileParser m Text
forall (m :: * -> *). PandocMonad m => TextileParser m Text
noteBlock)
  SourcePos
endPos <- ParsecT Sources ParserState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  let newnote :: (Text, Text)
newnote = (Text
ref, Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n")
  ParserState
st <- ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let oldnotes :: NoteTable
oldnotes = ParserState -> NoteTable
stateNotes ParserState
st
  (ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((ParserState -> ParserState) -> ParsecT Sources ParserState m ())
-> (ParserState -> ParserState) -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ \ParserState
s -> ParserState
s { stateNotes :: NoteTable
stateNotes = (Text, Text)
newnote (Text, Text) -> NoteTable -> NoteTable
forall a. a -> [a] -> [a]
: NoteTable
oldnotes }
  -- return blanks so line count isn't affected
  Text -> TextileParser m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> TextileParser m Text) -> Text -> TextileParser m Text
forall a b. (a -> b) -> a -> b
$ Int -> Text -> Text
T.replicate (SourcePos -> Int
sourceLine SourcePos
endPos Int -> Int -> Int
forall a. Num a => a -> a -> a
- SourcePos -> Int
sourceLine SourcePos
startPos) Text
"\n"

-- | Parse document blocks
parseBlocks :: PandocMonad m => TextileParser m Blocks
parseBlocks :: 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]
-> TextileParser m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TextileParser 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 TextileParser 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

-- | Block parsers list tried in definition order
blockParsers :: PandocMonad m => [TextileParser m Blocks]
blockParsers :: [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)
maybeExplicitBlock Text
"p" 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 (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) =>
ParserT s st m Text
blanklines
               ]

-- | Any block in the order of definition of blockParsers
block :: PandocMonad m => TextileParser m Blocks
block :: TextileParser m (Many Block)
block = do
  Many Block
res <- [TextileParser m (Many Block)] -> TextileParser m (Many Block)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [TextileParser m (Many Block)]
forall (m :: * -> *).
PandocMonad m =>
[TextileParser m (Many Block)]
blockParsers TextileParser m (Many Block)
-> [Char] -> TextileParser m (Many Block)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"block"
  Text -> ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => Text -> m ()
trace (Int -> Text -> Text
T.take Int
60 (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ [Block] -> Text
forall a. Show a => a -> Text
tshow ([Block] -> Text) -> [Block] -> Text
forall a b. (a -> b) -> a -> b
$ Many Block -> [Block]
forall a. Many a -> [a]
B.toList Many Block
res)
  Many Block -> TextileParser m (Many Block)
forall (m :: * -> *) a. Monad m => a -> m a
return Many Block
res

commentBlock :: PandocMonad m => TextileParser m Blocks
commentBlock :: TextileParser m (Many Block)
commentBlock = 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
  [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 => ParserT Sources st m Text
anyLine ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Text
blanklines
  Many Block -> TextileParser m (Many Block)
forall (m :: * -> *) a. Monad m => a -> m a
return Many Block
forall a. Monoid a => a
mempty

codeBlock :: PandocMonad m => TextileParser m Blocks
codeBlock :: 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 :: TextileParser m (Many Block)
codeBlockTextile = 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
  [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."
  Bool
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 (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 -> 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 starts :: [Text]
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 ()
ender = [ParsecT Sources ParserState m ()]
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([ParsecT Sources ParserState m ()]
 -> ParsecT Sources ParserState m ())
-> [ParsecT Sources ParserState m ()]
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ (Text -> ParsecT Sources ParserState m ())
-> [Text] -> [ParsecT Sources ParserState m ()]
forall a b. (a -> b) -> [a] -> [b]
map Text -> ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => Text -> TextileParser m ()
explicitBlockStart [Text]
starts
  [Text]
contents <- if Bool
extended
                 then do
                   Text
f <- ParserT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParserT Sources st m Text
anyLine
                   [Text]
rest <- ParserT Sources ParserState m Text
-> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (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 ()
ender ParsecT Sources ParserState m ()
-> ParserT Sources ParserState m Text
-> ParserT Sources ParserState m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParserT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParserT Sources st m Text
anyLine)
                   [Text] -> ParsecT Sources ParserState m [Text]
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
fText -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:[Text]
rest)
                 else ParserT Sources ParserState m Text
-> ParserT 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 ParserT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParserT Sources st m Text
anyLine ParserT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Text
blanklines
  Many Block -> TextileParser m (Many Block)
forall (m :: * -> *) a. Monad m => a -> m a
return (Many Block -> TextileParser m (Many Block))
-> Many Block -> TextileParser m (Many Block)
forall a b. (a -> b) -> a -> b
$ Text -> Many Block
B.codeBlock (Text -> Text
trimTrailingNewlines ([Text] -> Text
T.unlines [Text]
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')

-- | Code Blocks in Textile are between <pre> and </pre>
codeBlockHtml :: PandocMonad m => TextileParser m Blocks
codeBlockHtml :: TextileParser m (Many Block)
codeBlockHtml = 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
  (t :: Tag Text
t@(TagOpen Text
_ NoteTable
attrs),Text
_) <- (Tag Text -> Bool)
-> ParserT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParserT Sources st m (Tag Text, Text)
htmlTag ((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))
  Text
result' <- [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
-> ParserT 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 :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar ((Tag Text -> Bool)
-> ParserT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParserT Sources st m (Tag Text, Text)
htmlTag ((Text -> Bool) -> Tag Text -> Bool
forall str. (str -> Bool) -> Tag str -> Bool
tagClose (Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
==Text
"pre")))
  -- drop leading newline if any
  let result'' :: Text
result'' = case Text -> Maybe (Char, Text)
T.uncons Text
result' of
                   Just (Char
'\n', Text
xs) -> Text
xs
                   Maybe (Char, Text)
_               -> Text
result'
  -- drop trailing newline if any
  let result''' :: Text
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]
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
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 :: NoteTable
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"]
  Many Block -> TextileParser m (Many Block)
forall (m :: * -> *) a. Monad m => a -> m a
return (Many Block -> TextileParser m (Many Block))
-> Many Block -> TextileParser m (Many Block)
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Many Block
B.codeBlockWith (Text
ident,[Text]
classes,NoteTable
kvs) Text
result'''

-- | Header of the form "hN. content" with N in 1..6
header :: PandocMonad m => TextileParser m Blocks
header :: TextileParser m (Many Block)
header = 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
  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'
  Int
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
attr <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
  Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.'
  ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
whitespace
  Inlines
name <- Inlines -> Inlines
trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
inline
  Attr
attr' <- Attr -> Inlines -> TextileParser m Attr
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st, HasLogMessages st,
 HasIdentifierList st) =>
Attr -> Inlines -> ParserT s st m Attr
registerHeader Attr
attr Inlines
name
  Many Block -> TextileParser m (Many Block)
forall (m :: * -> *) a. Monad m => a -> m a
return (Many Block -> TextileParser m (Many Block))
-> Many Block -> TextileParser m (Many Block)
forall a b. (a -> b) -> a -> b
$ Attr -> Int -> Inlines -> Many Block
B.headerWith Attr
attr' Int
level Inlines
name

-- | Blockquote of the form "bq. content"
blockQuote :: PandocMonad m => TextileParser m Blocks
blockQuote :: TextileParser m (Many Block)
blockQuote = 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
  [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 (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 (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 Inlines
-> ParsecT Sources ParserState m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
whitespace
  Many Block -> Many Block
B.blockQuote (Many Block -> Many Block)
-> TextileParser m (Many Block) -> TextileParser m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
para

-- Horizontal rule

hrule :: PandocMonad m => TextileParser m Blocks
hrule :: TextileParser m (Many Block)
hrule = 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
  ParserT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m ()
skipSpaces
  Char
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]
"-*"
  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
2 (ParserT Sources ParserState m ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m ()
skipSpaces ParserT Sources ParserState m ()
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
start)
  ParsecT Sources ParserState m Char
-> ParserT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
start)
  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 Text
-> ParserT 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 Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Text
blanklines
  Many Block -> TextileParser m (Many Block)
forall (m :: * -> *) a. Monad m => a -> m a
return Many Block
B.horizontalRule

-- Lists handling

-- | Can be a bullet list or an ordered list. This implementation is
-- strict in the nesting, sublist must start at exactly "parent depth
-- plus one"
anyList :: PandocMonad m => TextileParser m Blocks
anyList :: TextileParser m (Many Block)
anyList = 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
$ Int -> TextileParser m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
anyListAtDepth Int
1 TextileParser m (Many Block)
-> ParsecT Sources ParserState m Text
-> TextileParser m (Many Block)
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) =>
ParserT s st m Text
blanklines

-- | This allow one type of list to be nested into an other type,
-- provided correct nesting
anyListAtDepth :: PandocMonad m => Int -> TextileParser m Blocks
anyListAtDepth :: Int -> TextileParser m (Many Block)
anyListAtDepth Int
depth = [TextileParser m (Many Block)] -> TextileParser 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 -> TextileParser m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
bulletListAtDepth Int
depth,
                                Int -> TextileParser m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
orderedListAtDepth Int
depth,
                                TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
definitionList ]

-- | Bullet List of given depth, depth being the number of leading '*'
bulletListAtDepth :: PandocMonad m => Int -> TextileParser m Blocks
bulletListAtDepth :: Int -> TextileParser m (Many Block)
bulletListAtDepth Int
depth = 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
$ [Many Block] -> Many Block
B.bulletList  ([Many Block] -> Many Block)
-> ParsecT Sources ParserState m [Many Block]
-> TextileParser m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TextileParser 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]
many1 (Int -> TextileParser m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
bulletListItemAtDepth Int
depth)

-- | Bullet List Item of given depth, depth being the number of
-- leading '*'
bulletListItemAtDepth :: PandocMonad m => Int -> TextileParser m Blocks
bulletListItemAtDepth :: Int -> TextileParser m (Many Block)
bulletListItemAtDepth = Char -> Int -> TextileParser m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Char -> Int -> TextileParser m (Many Block)
genericListItemAtDepth Char
'*'

-- | Ordered List of given depth, depth being the number of
-- leading '#'
orderedListAtDepth :: PandocMonad m => Int -> TextileParser m Blocks
orderedListAtDepth :: Int -> TextileParser m (Many Block)
orderedListAtDepth Int
depth = 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
  [Many Block]
items <- TextileParser 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]
many1 (Int -> TextileParser m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
orderedListItemAtDepth Int
depth)
  Many Block -> TextileParser m (Many Block)
forall (m :: * -> *) a. Monad m => a -> m a
return (Many Block -> TextileParser m (Many Block))
-> Many Block -> TextileParser m (Many Block)
forall a b. (a -> b) -> a -> b
$ [Many Block] -> Many Block
B.orderedList [Many Block]
items

-- | Ordered List Item of given depth, depth being the number of
-- leading '#'
orderedListItemAtDepth :: PandocMonad m => Int -> TextileParser m Blocks
orderedListItemAtDepth :: Int -> TextileParser m (Many Block)
orderedListItemAtDepth = Char -> Int -> TextileParser m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Char -> Int -> TextileParser m (Many Block)
genericListItemAtDepth Char
'#'

-- | Common implementation of list items
genericListItemAtDepth :: PandocMonad m => Char -> Int -> TextileParser m Blocks
genericListItemAtDepth :: Char -> Int -> TextileParser m (Many Block)
genericListItemAtDepth Char
c Int
depth = 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
  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
c) ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m Attr
-> ParsecT Sources ParserState m Attr
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 Inlines
-> ParsecT Sources ParserState m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
whitespace
  Many Block
contents <- [Many Block] -> Many Block
forall a. Monoid a => [a] -> a
mconcat ([Many Block] -> Many Block)
-> ParsecT Sources ParserState m [Many Block]
-> TextileParser m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TextileParser 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 ((Inlines -> Many Block
B.plain (Inlines -> Many Block)
-> ([Inlines] -> Inlines) -> [Inlines] -> Many Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Many Block)
-> ParsecT Sources ParserState m [Inlines]
-> TextileParser m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m [Inlines]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
inline) 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) -> TextileParser 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
-> TextileParser m (Many Block) -> TextileParser m (Many Block)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TextileParser m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
codeBlockHtml))
  ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
  Many Block
sublist <- Many Block
-> TextileParser m (Many Block) -> TextileParser m (Many Block)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Many Block
forall a. Monoid a => a
mempty (Int -> TextileParser m (Many Block)
forall (m :: * -> *).
PandocMonad m =>
Int -> TextileParser m (Many Block)
anyListAtDepth (Int
depth Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1))
  Many Block -> TextileParser m (Many Block)
forall (m :: * -> *) a. Monad m => a -> m a
return (Many Block -> TextileParser m (Many Block))
-> Many Block -> TextileParser m (Many Block)
forall a b. (a -> b) -> a -> b
$ Many Block
contents Many Block -> Many Block -> Many Block
forall a. Semigroup a => a -> a -> a
<> Many Block
sublist

-- | A definition list is a set of consecutive definition items
definitionList :: PandocMonad m => TextileParser m Blocks
definitionList :: TextileParser m (Many Block)
definitionList = 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
$ [(Inlines, [Many Block])] -> Many Block
B.definitionList ([(Inlines, [Many Block])] -> Many Block)
-> ParsecT Sources ParserState m [(Inlines, [Many Block])]
-> TextileParser m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m (Inlines, [Many Block])
-> ParsecT Sources ParserState m [(Inlines, [Many Block])]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m (Inlines, [Many Block])
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Inlines, [Many Block])
definitionListItem

-- | List start character.
listStart :: PandocMonad m => TextileParser m ()
listStart :: 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 (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ 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
<|> () () -> ParsecT Sources ParserState m Inlines -> TextileParser m ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
definitionListStart

genericListStart :: PandocMonad m => Char -> TextileParser m ()
genericListStart :: Char -> TextileParser m ()
genericListStart Char
c = () () -> ParsecT Sources ParserState m Inlines -> TextileParser m ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
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 Inlines
-> ParsecT Sources ParserState m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
whitespace)

basicDLStart :: PandocMonad m => TextileParser m ()
basicDLStart :: 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 Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
whitespace
  ParsecT Sources ParserState m Char -> TextileParser 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 :: TextileParser m Inlines
definitionListStart = TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Inlines -> TextileParser m Inlines)
-> TextileParser m Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
  TextileParser m ()
forall (m :: * -> *). PandocMonad m => TextileParser m ()
basicDLStart
  Inlines -> Inlines
trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Sources ParserState m [Inlines]
-> TextileParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    TextileParser m Inlines
-> TextileParser m () -> ParsecT Sources ParserState m [Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
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 (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 (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]
":="))
     )

-- | A definition list item in textile begins with '- ', followed by
-- the term defined, then spaces and ":=". The definition follows, on
-- the same single line, or spaned on multiple line, after a line
-- break.
definitionListItem :: PandocMonad m => TextileParser m (Inlines, [Blocks])
definitionListItem :: TextileParser m (Inlines, [Many Block])
definitionListItem = TextileParser m (Inlines, [Many Block])
-> TextileParser m (Inlines, [Many Block])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m (Inlines, [Many Block])
 -> TextileParser m (Inlines, [Many Block]))
-> TextileParser m (Inlines, [Many Block])
-> TextileParser m (Inlines, [Many Block])
forall a b. (a -> b) -> a -> b
$ do
  Inlines
term <- [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ([Inlines] -> [Inlines]) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse Inlines
B.linebreak ([Inlines] -> Inlines)
-> ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m [Inlines]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
definitionListStart
  [Many Block]
def' <- [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 ()
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m Inlines
-> 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 Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
whitespace ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [Many Block]
-> ParsecT Sources ParserState m [Many Block]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (ParsecT Sources ParserState m [Many Block]
forall (m :: * -> *). PandocMonad m => TextileParser m [Many Block]
multilineDef ParsecT Sources ParserState m [Many Block]
-> ParsecT Sources ParserState m [Many Block]
-> ParsecT Sources ParserState m [Many Block]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources ParserState m [Many Block]
forall (m :: * -> *). PandocMonad m => TextileParser m [Many Block]
inlineDef)
  (Inlines, [Many Block]) -> TextileParser m (Inlines, [Many Block])
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines
term, [Many Block]
def')
  where inlineDef :: PandocMonad m => TextileParser m [Blocks]
        inlineDef :: TextileParser m [Many Block]
inlineDef = (Inlines -> [Many Block])
-> ParsecT Sources ParserState m Inlines
-> TextileParser m [Many Block]
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\Inlines
d -> [Inlines -> Many Block
B.plain Inlines
d])
                    (ParsecT Sources ParserState m Inlines
 -> TextileParser m [Many Block])
-> ParsecT Sources ParserState m Inlines
-> TextileParser m [Many Block]
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Inlines
-> 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 Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
whitespace ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (Inlines -> Inlines
trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
inline) ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Inlines
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 :: TextileParser m [Many Block]
multilineDef = 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
          ParsecT Sources ParserState m Inlines
-> 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 Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
whitespace ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
          Text
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) =>
ParserT s st m a -> ParserT s st m end -> ParserT 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 (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))
          -- this <> "\n\n" does not look very good
          Many Block
ds <- ParserT Sources ParserState m (Many Block)
-> Text -> ParserT Sources ParserState m (Many Block)
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParserT Sources u m a -> Text -> ParserT Sources u m a
parseFromString' ParserT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
parseBlocks (Text
s Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n\n")
          [Many Block] -> TextileParser m [Many Block]
forall (m :: * -> *) a. Monad m => a -> m a
return [Many Block
ds]

-- raw content

-- | A raw Html Block, optionally followed by blanklines
rawHtmlBlock :: PandocMonad m => TextileParser m Blocks
rawHtmlBlock :: TextileParser m (Many Block)
rawHtmlBlock = 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
  ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar
  (Tag Text
_,Text
b) <- (Tag Text -> Bool)
-> ParserT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParserT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isBlockTag
  ParsecT Sources ParserState m Text
-> 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 Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Text
blanklines
  Many Block -> TextileParser m (Many Block)
forall (m :: * -> *) a. Monad m => a -> m a
return (Many Block -> TextileParser m (Many Block))
-> Many Block -> TextileParser m (Many Block)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Many Block
B.rawBlock Text
"html" Text
b

-- | Raw block of LaTeX content
rawLaTeXBlock' :: PandocMonad m => TextileParser m Blocks
rawLaTeXBlock' :: TextileParser m (Many Block)
rawLaTeXBlock' = do
  Extension -> ParserT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_raw_tex
  Text -> Text -> Many Block
B.rawBlock Text
"latex" (Text -> Many Block)
-> ParsecT Sources ParserState m Text
-> TextileParser 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) =>
ParserT Sources s m Text
rawLaTeXBlock ParsecT Sources ParserState m Text
-> ParserT Sources ParserState m ()
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParserT Sources ParserState m ()
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces)


-- | In textile, paragraphs are separated by blank lines.
para :: PandocMonad m => TextileParser m Blocks
para :: TextileParser m (Many Block)
para = Inlines -> Many Block
B.para (Inlines -> Many Block)
-> ([Inlines] -> Inlines) -> [Inlines] -> Many Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Many Block)
-> ParsecT Sources ParserState m [Inlines]
-> TextileParser m (Many Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m [Inlines]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
inline

-- Tables

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 :: TextileParser m (Bool, Alignment)
cellAttributes = TextileParser m (Bool, Alignment)
-> TextileParser m (Bool, Alignment)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m (Bool, Alignment)
 -> TextileParser m (Bool, Alignment))
-> TextileParser m (Bool, Alignment)
-> TextileParser m (Bool, Alignment)
forall a b. (a -> b) -> a -> b
$ do
  Bool
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 (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
'_')
  -- we just ignore colspan and rowspan markers:
  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
$ [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]
"/\\" ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m [Char]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
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
  -- we pay attention to alignments:
  Alignment
alignment <- Alignment
-> ParsecT Sources ParserState m Alignment
-> ParsecT Sources ParserState m Alignment
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Alignment
AlignDefault (ParsecT Sources ParserState m Alignment
 -> ParsecT Sources ParserState m Alignment)
-> ParsecT Sources ParserState m Alignment
-> ParsecT Sources ParserState m Alignment
forall a b. (a -> b) -> a -> b
$ Char -> Alignment
toAlignment (Char -> Alignment)
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Alignment
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]
"<>="
  -- ignore other attributes for now:
  Attr
_ <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
  Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.'
  (Bool, Alignment) -> TextileParser m (Bool, Alignment)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
isHeader, Alignment
alignment)

-- | A table cell spans until a pipe |
tableCell :: PandocMonad m => TextileParser m ((Bool, Alignment), Blocks)
tableCell :: TextileParser m ((Bool, Alignment), Many Block)
tableCell = TextileParser m ((Bool, Alignment), Many Block)
-> TextileParser m ((Bool, Alignment), Many Block)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m ((Bool, Alignment), Many Block)
 -> TextileParser m ((Bool, Alignment), Many Block))
-> TextileParser m ((Bool, Alignment), Many Block)
-> TextileParser 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
'|'
  (Bool
isHeader, Alignment
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
  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) =>
ParserT s st m Char
blankline
  Text
raw <- Text -> Text
trim (Text -> Text) -> ([Char] -> Text) -> [Char] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [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]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ([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]
"|\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 (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) =>
ParserT s st m Char
blankline))
  Inlines
content <- [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m [Inlines]
-> Text -> ParsecT Sources ParserState m [Inlines]
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParserT Sources u m a -> Text -> ParserT Sources u m a
parseFromString' (ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
inline) Text
raw
  ((Bool, Alignment), Many Block)
-> TextileParser m ((Bool, Alignment), Many Block)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Bool
isHeader, Alignment
alignment), Inlines -> Many Block
B.plain Inlines
content)

-- | A table row is made of many table cells
tableRow :: PandocMonad m => TextileParser m [((Bool, Alignment), Blocks)]
tableRow :: TextileParser m [((Bool, Alignment), Many Block)]
tableRow = TextileParser m [((Bool, Alignment), Many Block)]
-> TextileParser m [((Bool, Alignment), Many Block)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m [((Bool, Alignment), Many Block)]
 -> TextileParser m [((Bool, Alignment), Many Block)])
-> TextileParser m [((Bool, Alignment), Many Block)]
-> TextileParser m [((Bool, Alignment), Many Block)]
forall a b. (a -> b) -> a -> b
$ do
  -- skip optional row attributes
  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
    Attr
_ <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
    Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.'
    ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar
  ParsecT Sources ParserState m ((Bool, Alignment), Many Block)
-> TextileParser m [((Bool, Alignment), Many Block)]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m ((Bool, Alignment), Many Block)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m ((Bool, Alignment), Many Block)
tableCell TextileParser m [((Bool, Alignment), Many Block)]
-> ParsecT Sources ParserState m Char
-> TextileParser m [((Bool, Alignment), Many Block)]
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
'|' TextileParser m [((Bool, Alignment), Many Block)]
-> ParsecT Sources ParserState m Char
-> TextileParser m [((Bool, Alignment), Many Block)]
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) =>
ParserT s st m Char
blankline

-- | A table with an optional header.
table :: PandocMonad m => TextileParser m Blocks
table :: TextileParser m (Many Block)
table = 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
  -- ignore table attributes
  Inlines
caption <- Inlines
-> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Inlines
forall a. Monoid a => a
mempty (ParsecT Sources ParserState m Inlines
 -> ParsecT Sources ParserState m Inlines)
-> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m Inlines
 -> ParsecT Sources ParserState m Inlines)
-> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m Inlines
forall a b. (a -> b) -> a -> b
$ do
    [Char] -> ParsecT Sources ParserState m [Char]
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"table"
    Attr
_ <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
    Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.'
    Text
rawcapt <- Text -> Text
trim (Text -> Text)
-> ParsecT Sources ParserState m Text
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParserT Sources st m Text
anyLine
    ParsecT Sources ParserState m Inlines
-> Text -> ParsecT Sources ParserState m Inlines
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParserT Sources u m a -> Text -> ParserT Sources u m a
parseFromString' ([Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Inlines
-> ParsecT Sources ParserState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
inline) Text
rawcapt
  [[((Bool, Alignment), Many Block)]]
rawrows <- ParsecT Sources ParserState m [((Bool, Alignment), Many Block)]
-> ParsecT
     Sources ParserState m [[((Bool, Alignment), Many Block)]]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState m [((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
$ ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => TextileParser m ()
ignorableRow ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m [((Bool, Alignment), Many Block)]
-> ParsecT Sources ParserState m [((Bool, Alignment), Many Block)]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m [((Bool, Alignment), Many Block)]
forall (m :: * -> *).
PandocMonad m =>
TextileParser m [((Bool, Alignment), Many Block)]
tableRow
  ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => TextileParser m ()
ignorableRow
  ParsecT Sources ParserState m Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Text
blanklines
  let ([((Bool, Alignment), Many Block)]
headers, [[((Bool, Alignment), Many Block)]]
rows) = case [[((Bool, Alignment), Many Block)]]
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 :: Int
nbOfCols = NonEmpty Int -> Int
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 (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [((Bool, Alignment), Many Block)] -> 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]
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 (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 :: [Many Block] -> Row
toRow = Attr -> [Cell] -> Row
Row Attr
nullAttr ([Cell] -> Row) -> ([Many Block] -> [Cell]) -> [Many Block] -> Row
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Many Block -> Cell) -> [Many Block] -> [Cell]
forall a b. (a -> b) -> [a] -> [b]
map Many Block -> Cell
B.simpleCell
      toHeaderRow :: [Many Block] -> [Row]
toHeaderRow [Many Block]
l = [[Many Block] -> Row
toRow [Many Block]
l | Bool -> Bool
not ([Many Block] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Many Block]
l)]
  Many Block -> TextileParser m (Many Block)
forall (m :: * -> *) a. Monad m => a -> m a
return (Many Block -> TextileParser m (Many Block))
-> Many Block -> TextileParser m (Many Block)
forall a b. (a -> b) -> a -> b
$ Caption
-> [ColSpec] -> TableHead -> [TableBody] -> TableFoot -> Many Block
B.table (Many Block -> Caption
B.simpleCaption (Many Block -> Caption) -> Many Block -> Caption
forall a b. (a -> b) -> a -> b
$ Inlines -> Many Block
B.plain Inlines
caption)
    ([Alignment] -> [ColWidth] -> [ColSpec]
forall a b. [a] -> [b] -> [(a, b)]
zip [Alignment]
aligns (Int -> ColWidth -> [ColWidth]
forall a. Int -> a -> [a]
replicate Int
nbOfCols ColWidth
ColWidthDefault))
    (Attr -> [Row] -> TableHead
TableHead Attr
nullAttr ([Row] -> TableHead) -> [Row] -> TableHead
forall a b. (a -> b) -> a -> b
$ [Many Block] -> [Row]
toHeaderRow ([Many Block] -> [Row]) -> [Many Block] -> [Row]
forall a b. (a -> b) -> a -> b
$ (((Bool, Alignment), Many Block) -> Many Block)
-> [((Bool, Alignment), Many Block)] -> [Many Block]
forall a b. (a -> b) -> [a] -> [b]
map ((Bool, Alignment), Many Block) -> Many Block
forall a b. (a, b) -> b
snd [((Bool, Alignment), Many Block)]
headers)
    [Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody Attr
nullAttr RowHeadColumns
0 [] ([Row] -> TableBody) -> [Row] -> TableBody
forall a b. (a -> b) -> a -> b
$ ([((Bool, Alignment), Many Block)] -> Row)
-> [[((Bool, Alignment), Many Block)]] -> [Row]
forall a b. (a -> b) -> [a] -> [b]
map ([Many Block] -> Row
toRow ([Many Block] -> Row)
-> ([((Bool, Alignment), Many Block)] -> [Many Block])
-> [((Bool, Alignment), Many Block)]
-> Row
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (((Bool, Alignment), Many Block) -> Many Block)
-> [((Bool, Alignment), Many Block)] -> [Many Block]
forall a b. (a -> b) -> [a] -> [b]
map ((Bool, Alignment), Many Block) -> Many Block
forall a b. (a, b) -> b
snd) [[((Bool, Alignment), Many Block)]]
rows]
    (Attr -> [Row] -> TableFoot
TableFoot Attr
nullAttr [])

-- | Ignore markers for cols, thead, tfoot.
ignorableRow :: PandocMonad m => TextileParser m ()
ignorableRow :: TextileParser m ()
ignorableRow = TextileParser m () -> TextileParser m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m () -> TextileParser m ())
-> TextileParser m () -> TextileParser 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]
":^-~"
  Attr
_ <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
  Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.'
  Text
_ <- ParserT Sources ParserState m Text
forall (m :: * -> *) st. Monad m => ParserT Sources st m Text
anyLine
  () -> TextileParser m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

explicitBlockStart :: PandocMonad m => Text -> TextileParser m ()
explicitBlockStart :: Text -> TextileParser m ()
explicitBlockStart Text
name = TextileParser m () -> TextileParser m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m () -> TextileParser m ())
-> TextileParser m () -> TextileParser 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]
string (Text -> [Char]
T.unpack Text
name)
  TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
  Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.'
  ParsecT Sources ParserState m Inlines -> TextileParser 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 Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
whitespace
  ParsecT Sources ParserState m Inlines -> TextileParser 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 Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
endline

-- | Blocks like 'p' and 'table' do not need explicit block tag.
-- However, they can be used to set HTML/CSS attributes when needed.
maybeExplicitBlock :: PandocMonad m
                   => Text  -- ^ block tag name
                   -> TextileParser m Blocks -- ^ implicit block
                   -> TextileParser m Blocks
maybeExplicitBlock :: Text
-> TextileParser m (Many Block) -> TextileParser m (Many Block)
maybeExplicitBlock 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
  ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (ParsecT Sources ParserState m ()
 -> ParsecT Sources ParserState m ())
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Sources ParserState m ()
forall (m :: * -> *). PandocMonad m => Text -> TextileParser m ()
explicitBlockStart Text
name
  TextileParser m (Many Block)
blk



----------
-- Inlines
----------


-- | Any inline element
inline :: PandocMonad m => TextileParser m Inlines
inline :: TextileParser m Inlines
inline = [TextileParser m Inlines] -> TextileParser m Inlines
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [TextileParser m Inlines]
forall (m :: * -> *). PandocMonad m => [TextileParser m Inlines]
inlineParsers TextileParser m Inlines -> [Char] -> TextileParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"inline"

-- | Inline parsers tried in order
inlineParsers :: PandocMonad m => [TextileParser m Inlines]
inlineParsers :: [TextileParser m Inlines]
inlineParsers = [ TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
str
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
whitespace
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
endline
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
code
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
escapedInline
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
inlineMarkup
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
groupedInlineMarkup
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
rawHtmlInline
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
rawLaTeXInline'
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
note
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
link
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
image
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
mark
                , Text -> Inlines
B.str (Text -> Inlines) -> (Char -> Text) -> Char -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton (Char -> Inlines)
-> ParsecT Sources ParserState m Char -> TextileParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
characterReference
                , TextileParser m Inlines -> TextileParser m Inlines
forall st (m :: * -> *) s.
(HasReaderOptions st, HasLastStrPosition st, HasQuoteContext st m,
 Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Inlines -> ParserT s st m Inlines
smartPunctuation TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
inline
                , TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
symbol
                ]

-- | Inline markups
inlineMarkup :: PandocMonad m => TextileParser m Inlines
inlineMarkup :: TextileParser m Inlines
inlineMarkup = [TextileParser m Inlines] -> TextileParser m Inlines
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ TextileParser m [Char]
-> (Inlines -> Inlines) -> TextileParser m Inlines
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Inlines -> Inlines) -> TextileParser m Inlines
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] -> Inlines -> Inlines
B.cite [])
                      , TextileParser m [Char]
-> (Inlines -> Inlines) -> TextileParser m Inlines
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Inlines -> Inlines) -> TextileParser m Inlines
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]
"**") Inlines -> Inlines
B.strong
                      , TextileParser m [Char]
-> (Inlines -> Inlines) -> TextileParser m Inlines
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Inlines -> Inlines) -> TextileParser m Inlines
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]
"__") Inlines -> Inlines
B.emph
                      , TextileParser m Char
-> (Inlines -> Inlines) -> TextileParser m Inlines
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Inlines -> Inlines) -> TextileParser m Inlines
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
'*') Inlines -> Inlines
B.strong
                      , TextileParser m Char
-> (Inlines -> Inlines) -> TextileParser m Inlines
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Inlines -> Inlines) -> TextileParser m Inlines
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
'_') Inlines -> Inlines
B.emph
                      , TextileParser m Char
-> (Inlines -> Inlines) -> TextileParser m Inlines
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Inlines -> Inlines) -> TextileParser m Inlines
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
'+') Inlines -> Inlines
B.underline
                      , TextileParser m Char
-> (Inlines -> Inlines) -> TextileParser m Inlines
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Inlines -> Inlines) -> TextileParser m Inlines
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 (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
'-')) Inlines -> Inlines
B.strikeout
                      , TextileParser m Char
-> (Inlines -> Inlines) -> TextileParser m Inlines
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Inlines -> Inlines) -> TextileParser m Inlines
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
'^') Inlines -> Inlines
B.superscript
                      , TextileParser m Char
-> (Inlines -> Inlines) -> TextileParser m Inlines
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Inlines -> Inlines) -> TextileParser m Inlines
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
'~') Inlines -> Inlines
B.subscript
                      , TextileParser m Char
-> (Inlines -> Inlines) -> TextileParser m Inlines
forall (m :: * -> *) t.
PandocMonad m =>
TextileParser m t
-> (Inlines -> Inlines) -> TextileParser m Inlines
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
'%') Inlines -> Inlines
forall a. a -> a
id
                      ]

-- | Trademark, registered, copyright
mark :: PandocMonad m => TextileParser m Inlines
mark :: TextileParser m Inlines
mark = TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Inlines -> TextileParser m Inlines)
-> TextileParser m Inlines -> TextileParser m Inlines
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
-> TextileParser m Inlines -> TextileParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
tm TextileParser m Inlines
-> TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
reg TextileParser m Inlines
-> TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
copy)

reg :: PandocMonad m => TextileParser m Inlines
reg :: TextileParser m Inlines
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
')'
  Inlines -> TextileParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> TextileParser m Inlines)
-> Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
"\174"

tm :: PandocMonad m => TextileParser m Inlines
tm :: TextileParser m Inlines
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
')'
  Inlines -> TextileParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> TextileParser m Inlines)
-> Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
"\8482"

copy :: PandocMonad m => TextileParser m Inlines
copy :: TextileParser m Inlines
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
')'
  Inlines -> TextileParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> TextileParser m Inlines)
-> Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
"\169"

note :: PandocMonad m => TextileParser m Inlines
note :: TextileParser m Inlines
note = TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Inlines -> TextileParser m Inlines)
-> TextileParser m Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
  [Char]
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 (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
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 (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
']'
  NoteTable
notes <- ParserState -> NoteTable
stateNotes (ParserState -> NoteTable)
-> ParsecT Sources ParserState m ParserState
-> ParsecT Sources ParserState m NoteTable
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m ParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  case Text -> NoteTable -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ([Char] -> Text
T.pack [Char]
ref) NoteTable
notes of
    Maybe Text
Nothing  -> [Char] -> TextileParser m Inlines
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
Prelude.fail [Char]
"note not found"
    Just Text
raw -> Many Block -> Inlines
B.note (Many Block -> Inlines)
-> ParsecT Sources ParserState m (Many Block)
-> TextileParser m Inlines
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) =>
ParserT Sources u m a -> Text -> ParserT Sources u m a
parseFromString' ParsecT Sources ParserState m (Many Block)
forall (m :: * -> *). PandocMonad m => TextileParser m (Many Block)
parseBlocks Text
raw

-- | Special chars
markupChars :: [Char]
markupChars :: [Char]
markupChars = [Char]
"\\*#_@~-+^|%=[]&"

-- | Break strings on following chars. Space tab and newline break for
--  inlines breaking. Open paren breaks for mark. Quote, dash and dot
--  break for smart punctuation. Punctuation breaks for regular
--  punctuation. Double quote breaks for named links. > and < break
--  for inline html.
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

-- | Parse a hyphened sequence of words
hyphenedWords :: PandocMonad m => TextileParser m Text
hyphenedWords :: TextileParser m Text
hyphenedWords = do
  Text
x <- TextileParser m Text
forall (m :: * -> *). PandocMonad m => TextileParser m Text
wordChunk
  [Text]
xs <-  TextileParser m Text -> ParsecT Sources ParserState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (TextileParser m Text -> TextileParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Text -> TextileParser m Text)
-> TextileParser m Text -> TextileParser m Text
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
-> TextileParser m Text -> TextileParser m Text
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TextileParser m Text
forall (m :: * -> *). PandocMonad m => TextileParser m Text
wordChunk)
  Text -> TextileParser m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> TextileParser m Text) -> Text -> TextileParser m Text
forall a b. (a -> b) -> a -> b
$ Text -> [Text] -> Text
T.intercalate Text
"-" (Text
xText -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:[Text]
xs)

wordChunk :: PandocMonad m => TextileParser m Text
wordChunk :: TextileParser m Text
wordChunk = TextileParser m Text -> TextileParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Text -> TextileParser m Text)
-> TextileParser m Text -> TextileParser m Text
forall a b. (a -> b) -> a -> b
$ do
  Char
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
  [Char]
tl <- 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 ( [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 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 (ParserT Sources ParserState m Inlines
-> ParserT Sources ParserState m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParserT s st m b -> ParserT s st m ()
notFollowedBy' ParserT Sources ParserState m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
note ParserT Sources ParserState m ()
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
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]
markupChars
                     ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ([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) ) )
  Text -> TextileParser m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> TextileParser m Text) -> Text -> TextileParser m Text
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack ([Char] -> Text) -> [Char] -> Text
forall a b. (a -> b) -> a -> b
$ Char
hdChar -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:[Char]
tl

-- | Any string
str :: PandocMonad m => TextileParser m Inlines
str :: TextileParser m Inlines
str = do
  Text
baseStr <- TextileParser m Text
forall (m :: * -> *). PandocMonad m => TextileParser m Text
hyphenedWords
  -- RedCloth compliance : if parsed word is uppercase and immediately
  -- followed by parens, parens content is unconditionally word acronym
  Text
fullStr <- Text -> TextileParser m Text -> TextileParser m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
baseStr (TextileParser m Text -> TextileParser m Text)
-> TextileParser m Text -> TextileParser m Text
forall a b. (a -> b) -> a -> b
$ TextileParser m Text -> TextileParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Text -> TextileParser m Text)
-> TextileParser m Text -> TextileParser m Text
forall a b. (a -> b) -> a -> b
$ do
    Bool -> ParsecT Sources ParserState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Sources ParserState m ())
-> Bool -> ParsecT Sources ParserState m ()
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isUpper Text
baseStr
    Text
acro <- [Char] -> Text
T.pack ([Char] -> Text)
-> ParsecT Sources ParserState m [Char] -> TextileParser m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Sources ParserState m Char
-> ParserT Sources ParserState m Char
-> ParserT 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) =>
ParserT s st m t
-> ParserT s st m end -> ParserT s st m a -> ParserT s st m [a]
enclosed (Char -> ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'(') (Char -> ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
')') ParserT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => TextileParser m Char
anyChar'
    Text -> TextileParser m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> TextileParser m Text) -> Text -> TextileParser m Text
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
T.concat [Text
baseStr, Text
" (", Text
acro, Text
")"]
  ParsecT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasLastStrPosition st) =>
ParserT s st m ()
updateLastStrPos
  Inlines -> TextileParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> TextileParser m Inlines)
-> Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
fullStr

-- | Some number of space chars
whitespace :: PandocMonad m => TextileParser m Inlines
whitespace :: TextileParser m Inlines
whitespace = ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar ParsecT Sources ParserState m [Char]
-> TextileParser m Inlines -> TextileParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> TextileParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.space TextileParser m Inlines -> [Char] -> TextileParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"whitespace"

-- | In Textile, an isolated endline character is a line break
endline :: PandocMonad m => TextileParser m Inlines
endline :: TextileParser m Inlines
endline = TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Inlines -> TextileParser m Inlines)
-> TextileParser m Inlines -> TextileParser m Inlines
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) =>
ParserT 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
  Inlines -> TextileParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.linebreak

rawHtmlInline :: PandocMonad m => TextileParser m Inlines
rawHtmlInline :: TextileParser m Inlines
rawHtmlInline = Text -> Text -> Inlines
B.rawInline Text
"html" (Text -> Inlines)
-> ((Tag Text, Text) -> Text) -> (Tag Text, Text) -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tag Text, Text) -> Text
forall a b. (a, b) -> b
snd ((Tag Text, Text) -> Inlines)
-> ParsecT Sources ParserState m (Tag Text, Text)
-> TextileParser m Inlines
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) -> ParserT Sources st m (Tag Text, Text)
htmlTag Tag Text -> Bool
isInlineTag

-- | Raw LaTeX Inline
rawLaTeXInline' :: PandocMonad m => TextileParser m Inlines
rawLaTeXInline' :: TextileParser m Inlines
rawLaTeXInline' = TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Inlines -> TextileParser m Inlines)
-> TextileParser m Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
  Extension -> ParserT Sources ParserState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_raw_tex
  Text -> Text -> Inlines
B.rawInline Text
"latex" (Text -> Inlines)
-> ParsecT Sources ParserState m Text -> TextileParser m Inlines
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) =>
ParserT Sources s m Text
rawLaTeXInline

-- | Textile standard link syntax is "label":target. But we
-- can also have ["label":target].
link :: PandocMonad m => TextileParser m Inlines
link :: TextileParser m Inlines
link = TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Inlines -> TextileParser m Inlines)
-> TextileParser m Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
  Bool
bracketed <- (Bool
True Bool
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m Bool
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 (m :: * -> *) a. Monad m => a -> m a
return Bool
False
  Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState m 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
attr <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
  Inlines
name <- Inlines -> Inlines
trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Sources ParserState m [Inlines]
-> TextileParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          QuoteContext
-> ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m [Inlines]
forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InDoubleQuote (TextileParser m Inlines
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
inline (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
':'
  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 => ParserT 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
<|>
                       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 (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 => ParserT Sources s m Char
eof'))
  Text
url <- [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) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till ParsecT Sources ParserState m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
nonspaceChar ParsecT Sources ParserState m Char
forall u. ParsecT Sources u m Char
stop
  let name' :: Inlines
name' = if Inlines -> [Inline]
forall a. Many a -> [a]
B.toList Inlines
name [Inline] -> [Inline] -> Bool
forall a. Eq a => a -> a -> Bool
== [Text -> Inline
Str Text
"$"] then Text -> Inlines
B.str Text
url else Inlines
name
  Inlines -> TextileParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> TextileParser m Inlines)
-> Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ if Attr
attr Attr -> Attr -> Bool
forall a. Eq a => a -> a -> Bool
== Attr
nullAttr
              then Text -> Text -> Inlines -> Inlines
B.link Text
url Text
"" Inlines
name'
              else Attr -> Inlines -> Inlines
B.spanWith Attr
attr (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link Text
url Text
"" Inlines
name'

-- | image embedding
image :: PandocMonad m => TextileParser m Inlines
image :: TextileParser m Inlines
image = TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Inlines -> TextileParser m Inlines)
-> TextileParser m Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
  Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'!' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
space
  (Text
ident, [Text]
cls, NoteTable
kvs) <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
  let attr :: Attr
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)
  Text
src <- [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]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ([Char] -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
" \t\n\r!(")
  Text
alt <- ([Char] -> Text)
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Char] -> Text
T.pack (ParsecT Sources ParserState m [Char]
 -> ParsecT Sources ParserState m Text)
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m Text
forall a b. (a -> b) -> a -> b
$ [Char]
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m [Char]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [Char]
"" (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]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState m [Char]
 -> ParsecT Sources ParserState m [Char])
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m [Char]
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'(' ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
-> ParsecT Sources ParserState m [Char]
forall (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 :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
')')
  Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'!'
  Inlines -> TextileParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> TextileParser m Inlines)
-> Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Text -> Inlines -> Inlines
B.imageWith Attr
attr Text
src Text
alt (Text -> Inlines
B.str Text
alt)

escapedInline :: PandocMonad m => TextileParser m Inlines
escapedInline :: TextileParser m Inlines
escapedInline = TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
escapedEqs TextileParser m Inlines
-> TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
escapedTag

escapedEqs :: PandocMonad m => TextileParser m Inlines
escapedEqs :: TextileParser m Inlines
escapedEqs = Text -> Inlines
B.str (Text -> Inlines) -> ([Char] -> Text) -> [Char] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack ([Char] -> Inlines)
-> ParsecT Sources ParserState m [Char] -> TextileParser m Inlines
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 (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]
"=="))

-- | literal text escaped btw <notextile> tags
escapedTag :: PandocMonad m => TextileParser m Inlines
escapedTag :: TextileParser m Inlines
escapedTag = Text -> Inlines
B.str (Text -> Inlines) -> ([Char] -> Text) -> [Char] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack ([Char] -> Inlines)
-> ParsecT Sources ParserState m [Char] -> TextileParser m Inlines
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 (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>"))

-- | Any special symbol defined in wordBoundaries
symbol :: PandocMonad m => TextileParser m Inlines
symbol :: TextileParser m Inlines
symbol = Text -> Inlines
B.str (Text -> Inlines) -> (Char -> Text) -> Char -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton (Char -> Inlines)
-> ParsecT Sources ParserState m Char -> TextileParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> 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 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 (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 (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)

-- | Inline code
code :: PandocMonad m => TextileParser m Inlines
code :: TextileParser m Inlines
code = TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
code1 TextileParser m Inlines
-> TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
code2

-- any character except a newline before a blank line
anyChar' :: PandocMonad m => TextileParser m Char
anyChar' :: TextileParser m Char
anyChar' =
  (Char -> Bool) -> TextileParser 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') TextileParser m Char
-> TextileParser m Char -> TextileParser m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
  TextileParser m Char -> TextileParser m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (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
'\n' TextileParser m Char
-> ParsecT Sources ParserState m () -> TextileParser m Char
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 TextileParser m Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
blankline)

code1 :: PandocMonad m => TextileParser m Inlines
code1 :: TextileParser m Inlines
code1 = Text -> Inlines
B.code (Text -> Inlines) -> ([Char] -> Text) -> [Char] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack ([Char] -> Inlines)
-> ParsecT Sources ParserState m [Char] -> TextileParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Sources ParserState m Char
-> ParserT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
forall (m :: * -> *) t st a.
(PandocMonad m, Show t) =>
ParserT Sources st m t
-> ParserT Sources st m a -> ParserT Sources st m [a]
surrounded (Char -> ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'@') ParserT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => TextileParser m Char
anyChar'

code2 :: PandocMonad m => TextileParser m Inlines
code2 :: TextileParser m Inlines
code2 = do
  (Tag Text -> Bool)
-> ParserT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParserT Sources st m (Tag Text, Text)
htmlTag ((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 (t :: * -> *) a. Foldable t => t a -> Bool
null)
  Text -> Inlines
B.code (Text -> Inlines) -> ([Char] -> Text) -> [Char] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack ([Char] -> Inlines)
-> ParsecT Sources ParserState m [Char] -> TextileParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState m Char
-> ParserT 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' (ParserT Sources ParserState m (Tag Text, Text)
-> ParserT Sources ParserState m (Tag Text, Text)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParserT Sources ParserState m (Tag Text, Text)
 -> ParserT Sources ParserState m (Tag Text, Text))
-> ParserT Sources ParserState m (Tag Text, Text)
-> ParserT Sources ParserState m (Tag Text, Text)
forall a b. (a -> b) -> a -> b
$ (Tag Text -> Bool)
-> ParserT Sources ParserState m (Tag Text, Text)
forall st (m :: * -> *).
(HasReaderOptions st, Monad m) =>
(Tag Text -> Bool) -> ParserT Sources st m (Tag Text, Text)
htmlTag ((Tag Text -> Bool)
 -> ParserT Sources ParserState m (Tag Text, Text))
-> (Tag Text -> Bool)
-> ParserT 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"))

-- | Html / CSS attributes
attributes :: PandocMonad m => TextileParser m Attr
attributes :: TextileParser m Attr
attributes = (Attr -> (Attr -> Attr) -> Attr) -> Attr -> [Attr -> Attr] -> Attr
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
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]
-> TextileParser 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 Attr -> Attr
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
          [Attr -> Attr]
attrs <- 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]
many ParsecT Sources ParserState m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
attribute
          [Attr -> Attr] -> ParsecT Sources ParserState m [Attr -> Attr]
forall (m :: * -> *) a. Monad m => a -> m a
return (Attr -> Attr
special (Attr -> Attr) -> [Attr -> Attr] -> [Attr -> Attr]
forall a. a -> [a] -> [a]
: [Attr -> Attr]
attrs))

specialAttribute :: PandocMonad m => TextileParser m (Attr -> Attr)
specialAttribute :: TextileParser m (Attr -> Attr)
specialAttribute = do
  [Char]
alignStr <- ([Char]
"center" [Char]
-> ParsecT Sources ParserState m Char
-> ParsecT Sources ParserState m [Char]
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 (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 (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 (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 ()
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) =>
ParserT s st m Char
spaceChar
  (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Attr -> Attr) -> TextileParser m (Attr -> Attr))
-> (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$ Text -> Attr -> Attr
addStyle (Text -> Attr -> Attr) -> Text -> Attr -> Attr
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack ([Char] -> Text) -> [Char] -> Text
forall a b. (a -> b) -> a -> b
$ [Char]
"text-align:" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
alignStr

attribute :: PandocMonad m => TextileParser m (Attr -> Attr)
attribute :: TextileParser m (Attr -> Attr)
attribute = TextileParser m (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m (Attr -> Attr) -> TextileParser m (Attr -> Attr))
-> TextileParser m (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$
  (TextileParser m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
classIdAttr TextileParser m (Attr -> Attr)
-> TextileParser m (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TextileParser m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
styleAttr TextileParser m (Attr -> Attr)
-> TextileParser m (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> TextileParser m (Attr -> Attr)
forall (m :: * -> *).
PandocMonad m =>
TextileParser m (Attr -> Attr)
langAttr) TextileParser m (Attr -> Attr)
-> ParsecT Sources ParserState m ()
-> TextileParser m (Attr -> Attr)
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) =>
ParserT s st m Char
spaceChar

classIdAttr :: PandocMonad m => TextileParser m (Attr -> Attr)
classIdAttr :: TextileParser m (Attr -> Attr)
classIdAttr = TextileParser m (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m (Attr -> Attr) -> TextileParser m (Attr -> Attr))
-> TextileParser m (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$ do -- (class class #id)
  Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'('
  [Text]
ws <- Text -> [Text]
T.words (Text -> [Text]) -> ([Char] -> Text) -> [Char] -> [Text]
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 [Text] -> [Text]
forall a. [a] -> [a]
reverse [Text]
ws of
       []
         -> (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Attr -> Attr) -> TextileParser m (Attr -> Attr))
-> (Attr -> Attr) -> TextileParser 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) -> TextileParser m (Attr -> Attr)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Attr -> Attr) -> TextileParser m (Attr -> Attr))
-> (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$ \(Text
_,[Text]
_,NoteTable
keyvals) -> (Text
ident',[Text]
classes',NoteTable
keyvals)
       [Text]
classes'
         -> (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Attr -> Attr) -> TextileParser m (Attr -> Attr))
-> (Attr -> Attr) -> TextileParser 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 :: TextileParser m (Attr -> Attr)
styleAttr = do
  [Char]
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
$ ParserT Sources ParserState m Char
-> ParserT Sources ParserState m Char
-> ParserT 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) =>
ParserT s st m t
-> ParserT s st m end -> ParserT s st m a -> ParserT s st m [a]
enclosed (Char -> ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'{') (Char -> ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'}') ParserT Sources ParserState m Char
forall (m :: * -> *). PandocMonad m => TextileParser m Char
anyChar'
  (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Attr -> Attr) -> TextileParser m (Attr -> Attr))
-> (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$ Text -> Attr -> Attr
addStyle (Text -> Attr -> Attr) -> Text -> Attr -> Attr
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack [Char]
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 :: TextileParser m (Attr -> Attr)
langAttr = do
  [Char]
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
$ ParserT Sources ParserState m Char
-> ParserT Sources ParserState m Char
-> ParserT 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) =>
ParserT s st m t
-> ParserT s st m end -> ParserT s st m a -> ParserT s st m [a]
enclosed (Char -> ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'[') (Char -> ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']') ParserT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum
  (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Attr -> Attr) -> TextileParser m (Attr -> Attr))
-> (Attr -> Attr) -> TextileParser m (Attr -> Attr)
forall a b. (a -> b) -> a -> b
$ \(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)

-- | Parses material surrounded by a parser.
surrounded :: (PandocMonad m, Show t)
           => ParserT Sources st m t   -- ^ surrounding parser
           -> ParserT Sources st m a   -- ^ content parser (to be used repeatedly)
           -> ParserT Sources st m [a]
surrounded :: ParserT Sources st m t
-> ParserT Sources st m a -> ParserT Sources st m [a]
surrounded ParserT Sources st m t
border =
  ParserT Sources st m ()
-> ParserT Sources st m t
-> ParserT Sources st m a
-> ParserT Sources st m [a]
forall end s (m :: * -> *) st t a.
(Show end, Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m t
-> ParserT s st m end -> ParserT s st m a -> ParserT s st m [a]
enclosed (ParserT Sources st m t
border ParserT Sources st m t
-> ParserT Sources st m () -> ParserT Sources st m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources st m Char -> ParserT 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")) (ParserT Sources st m t -> ParserT Sources st m t
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParserT Sources st m t
border)

simpleInline :: PandocMonad m
             => TextileParser m t        -- ^ surrounding parser
             -> (Inlines -> Inlines)                  -- ^ Inline constructor
             -> TextileParser m Inlines  -- ^ content parser (to be used repeatedly)
simpleInline :: TextileParser m t
-> (Inlines -> Inlines) -> TextileParser m Inlines
simpleInline TextileParser m t
border Inlines -> Inlines
construct = TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Inlines -> TextileParser m Inlines)
-> TextileParser m Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
  ParserT Sources ParserState m Bool
forall s (m :: * -> *) a st.
(Stream s m a, HasLastStrPosition st) =>
ParserT s st m Bool
notAfterString
  TextileParser m t
border TextileParser m t
-> ParsecT Sources ParserState m ()
-> ParsecT Sources ParserState m ()
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
attr <- TextileParser m Attr
forall (m :: * -> *). PandocMonad m => TextileParser m Attr
attributes
  Inlines
body <- Inlines -> Inlines
trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Sources ParserState m [Inlines]
-> TextileParser m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          QuoteContext
-> ParsecT Sources ParserState m [Inlines]
-> ParsecT Sources ParserState m [Inlines]
forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InSingleQuote
            (TextileParser m Inlines
-> TextileParser m t -> ParsecT Sources ParserState m [Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill (ParsecT Sources ParserState m 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 ()
-> TextileParser m Inlines -> TextileParser m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
inline)
             (TextileParser m t -> TextileParser m t
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try TextileParser m t
border TextileParser m t
-> ParsecT Sources ParserState m () -> TextileParser m t
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 (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum))
  Inlines -> TextileParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> TextileParser m Inlines)
-> Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
construct (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$
        if Attr
attr Attr -> Attr -> Bool
forall a. Eq a => a -> a -> Bool
== Attr
nullAttr
           then Inlines
body
           else Attr -> Inlines -> Inlines
B.spanWith Attr
attr Inlines
body

groupedInlineMarkup :: PandocMonad m => TextileParser m Inlines
groupedInlineMarkup :: TextileParser m Inlines
groupedInlineMarkup = TextileParser m Inlines -> TextileParser m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (TextileParser m Inlines -> TextileParser m Inlines)
-> TextileParser m Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ do
    Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'['
    Inlines
sp1 <- Inlines -> TextileParser m Inlines -> TextileParser m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Inlines
forall a. Monoid a => a
mempty (TextileParser m Inlines -> TextileParser m Inlines)
-> TextileParser m Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines
B.space Inlines -> TextileParser m Inlines -> TextileParser m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
whitespace
    Inlines
result <- QuoteContext -> TextileParser m Inlines -> TextileParser m Inlines
forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InSingleQuote TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
inlineMarkup
    Inlines
sp2 <- Inlines -> TextileParser m Inlines -> TextileParser m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Inlines
forall a. Monoid a => a
mempty (TextileParser m Inlines -> TextileParser m Inlines)
-> TextileParser m Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines
B.space Inlines -> TextileParser m Inlines -> TextileParser m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ TextileParser m Inlines
forall (m :: * -> *). PandocMonad m => TextileParser m Inlines
whitespace
    Char -> ParsecT Sources ParserState m Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']'
    Inlines -> TextileParser m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> TextileParser m Inlines)
-> Inlines -> TextileParser m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines
sp1 Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
result Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
sp2

eof' :: Monad m => ParserT Sources s m Char
eof' :: ParserT Sources s m Char
eof' = Char
'\n' Char -> ParsecT Sources s m () -> ParserT Sources s m Char
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