    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE LambdaCase #-}
    {- |
       Module      : Text.Pandoc.Readers.Txt2Tags
       Copyright   : Copyright (C) 2014 Matthew Pickering
       License     : GNU GPL, version 2 or above

       Maintainer  : Matthew Pickering <matthewtpickering@gmail.com>

    Conversion of txt2tags formatted plain text to 'Pandoc' document.
    -}
    module Text.Pandoc.Readers.Txt2Tags ( readTxt2Tags
                                        , getT2TMeta
                                        , T2TMeta (..)
                                        )
                                        where

    import Control.Monad (guard, void, when)
    import Control.Monad.Except (catchError, throwError)
    import Control.Monad.Reader (Reader, asks, runReader)
    import Data.Default
    import Data.List (intercalate, transpose)
    import Data.List.NonEmpty (nonEmpty)
    import Data.Maybe (fromMaybe)
    import Data.Text (Text)
    import qualified Data.Text as T
    import Data.Time.Format (formatTime)
    import Text.Pandoc.Builder (Blocks, Inlines, trimInlines)
    import qualified Text.Pandoc.Builder as B
    import Text.Pandoc.Class.PandocMonad (PandocMonad)
    import qualified Text.Pandoc.Class.PandocMonad as P
    import Data.Time (defaultTimeLocale)
    import Text.Pandoc.Definition
    import Text.Pandoc.Options
    import Text.Pandoc.Parsing hiding (space, spaces, uri)
    import Text.Pandoc.Shared (compactify, compactifyDL)
    import Text.Pandoc.URI (escapeURI)

    type T2T = ParsecT Sources ParserState (Reader T2TMeta)

    -- | An object for the T2T macros meta information
    -- the contents of each field is simply substituted verbatim into the file
    data  T2TMeta = T2TMeta {
                     T2TMeta -> Text
    date    :: Text -- ^ Current date
                   , T2TMeta -> Text
    mtime   :: Text -- ^ Last modification time of infile
                   , T2TMeta -> [Char]
    infile  :: FilePath -- ^ Input file
                   , T2TMeta -> [Char]
    outfile :: FilePath -- ^ Output file
                   } deriving Column -> T2TMeta -> ShowS
    [T2TMeta] -> ShowS
    T2TMeta -> [Char]
    (Column -> T2TMeta -> ShowS)
    -> (T2TMeta -> [Char]) -> ([T2TMeta] -> ShowS) -> Show T2TMeta
    forall a.
    (Column -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Column -> T2TMeta -> ShowS
    showsPrec :: Column -> T2TMeta -> ShowS
    $cshow :: T2TMeta -> [Char]
    show :: T2TMeta -> [Char]
    $cshowList :: [T2TMeta] -> ShowS
    showList :: [T2TMeta] -> ShowS
    Show

    instance Default T2TMeta where
        def :: T2TMeta
    def = Text -> Text -> [Char] -> [Char] -> T2TMeta
    T2TMeta Text
    "" Text
    "" [Char]
    "" [Char]
    ""

    -- | Get the meta information required by Txt2Tags macros
    getT2TMeta :: PandocMonad m => m T2TMeta
    getT2TMeta :: forall (m :: * -> *). PandocMonad m => m T2TMeta
    getT2TMeta = do
        inps <- m [[Char]]
    forall (m :: * -> *). PandocMonad m => m [[Char]]
    P.getInputFiles
        outp <- fromMaybe "" <$> P.getOutputFile
        curDate <- formatTime defaultTimeLocale "%F" <$> P.getZonedTime
        curMtime <- catchError
                     (mapM P.getModificationTime inps >>=
                       (\case
                           Maybe (NonEmpty UTCTime)
    Nothing ->
                             TimeLocale -> [Char] -> ZonedTime -> [Char]
    forall t. FormatTime t => TimeLocale -> [Char] -> t -> [Char]
    formatTime TimeLocale
    defaultTimeLocale [Char]
    "%T" (ZonedTime -> [Char]) -> m ZonedTime -> m [Char]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> m ZonedTime
    forall (m :: * -> *). PandocMonad m => m ZonedTime
    P.getZonedTime
                           Just NonEmpty UTCTime
    ts -> [Char] -> m [Char]
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([Char] -> m [Char]) -> [Char] -> m [Char]
    forall a b. (a -> b) -> a -> b
    $
                             TimeLocale -> [Char] -> UTCTime -> [Char]
    forall t. FormatTime t => TimeLocale -> [Char] -> t -> [Char]
    formatTime TimeLocale
    defaultTimeLocale [Char]
    "%T" (UTCTime -> [Char]) -> UTCTime -> [Char]
    forall a b. (a -> b) -> a -> b
    $ NonEmpty UTCTime -> UTCTime
    forall a. Ord a => NonEmpty a -> a
    forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
    maximum NonEmpty UTCTime
    ts)
                        . nonEmpty)
                    (const (return ""))
        return $ T2TMeta (T.pack curDate) (T.pack curMtime)
                         (intercalate ", " inps) outp

    -- | Read Txt2Tags from an input string returning a Pandoc document
    readTxt2Tags :: (PandocMonad m, ToSources a)
                 => ReaderOptions
                 -> a
                 -> m Pandoc
    readTxt2Tags :: forall (m :: * -> *) a.
    (PandocMonad m, ToSources a) =>
    ReaderOptions -> a -> m Pandoc
    readTxt2Tags ReaderOptions
    opts a
    s = do
      let sources :: Sources
    sources = Column -> Sources -> Sources
    ensureFinalNewlines Column
    2 (a -> Sources
    forall a. ToSources a => a -> Sources
    toSources a
    s)
      meta <- m T2TMeta
    forall (m :: * -> *). PandocMonad m => m T2TMeta
    getT2TMeta
      let parsed = (Reader T2TMeta (Either PandocError Pandoc)
     -> T2TMeta -> Either PandocError Pandoc)
    -> T2TMeta
    -> Reader T2TMeta (Either PandocError Pandoc)
    -> Either PandocError Pandoc
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip Reader T2TMeta (Either PandocError Pandoc)
    -> T2TMeta -> Either PandocError Pandoc
    forall r a. Reader r a -> r -> a
    runReader T2TMeta
    meta (Reader T2TMeta (Either PandocError Pandoc)
     -> Either PandocError Pandoc)
    -> Reader T2TMeta (Either PandocError Pandoc)
    -> Either PandocError Pandoc
    forall a b. (a -> b) -> a -> b
    $
            ParsecT Sources ParserState (Reader T2TMeta) Pandoc
    -> ParserState
    -> Sources
    -> Reader T2TMeta (Either PandocError Pandoc)
    forall (m :: * -> *) t st a.
    (Monad m, ToSources t) =>
    ParsecT Sources st m a -> st -> t -> m (Either PandocError a)
    readWithM ParsecT Sources ParserState (Reader T2TMeta) Pandoc
    parseT2T (ParserState
    forall a. Default a => a
    def {stateOptions = opts}) Sources
    sources
      case parsed of
        Right Pandoc
    result -> Pandoc -> m Pandoc
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Pandoc
    result
        Left PandocError
    e       -> PandocError -> m Pandoc
    forall a. PandocError -> m a
    forall e (m :: * -> *) a. MonadError e m => e -> m a
    throwError PandocError
    e

    -- | Read Txt2Tags (ignoring all macros) from an input string returning
    -- a Pandoc document
    -- readTxt2TagsNoMacros :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
    -- readTxt2TagsNoMacros = readTxt2Tags

    parseT2T :: T2T Pandoc
    parseT2T :: ParsecT Sources ParserState (Reader T2TMeta) Pandoc
    parseT2T = do
      -- Parse header if standalone flag is set
      standalone <- (ReaderOptions -> Bool)
    -> ParsecT Sources ParserState (Reader T2TMeta) Bool
    forall st s (m :: * -> *) t b.
    (HasReaderOptions st, Stream s m t) =>
    (ReaderOptions -> b) -> ParsecT s st m b
    forall s (m :: * -> *) t b.
    Stream s m t =>
    (ReaderOptions -> b) -> ParsecT s ParserState m b
    getOption ReaderOptions -> Bool
    readerStandalone
      when standalone parseHeader
      body <- mconcat <$>  manyTill block eof
      meta' <- stateMeta <$> getState
      return $ Pandoc meta' (B.toList body)

    parseHeader :: T2T ()
    parseHeader :: ParsecT Sources ParserState (Reader T2TMeta) ()
    parseHeader = do
      () ()
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a b.
    a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Sources ParserState (Reader T2TMeta) ()
    header
      meta <- ParserState -> Meta
    stateMeta (ParserState -> Meta)
    -> ParsecT Sources ParserState (Reader T2TMeta) ParserState
    -> ParsecT Sources ParserState (Reader T2TMeta) Meta
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      optional blanklines
      config <- manyTill setting (notFollowedBy setting)
      -- TODO: Handle settings better
      let settings = ((Text, Text) -> Meta -> Meta) -> Meta -> [(Text, Text)] -> Meta
    forall a b. (a -> b -> b) -> b -> [a] -> b
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr (\(Text
    k,Text
    v) -> Text -> MetaValue -> Meta -> Meta
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    forall b. ToMetaValue b => Text -> b -> Meta -> Meta
    B.setMeta Text
    k (Text -> MetaValue
    MetaString Text
    v)) Meta
    meta [(Text, Text)]
    config
      updateState (\ParserState
    s -> ParserState
    s {stateMeta = settings}) <* optional blanklines

    header :: T2T ()
    header :: ParsecT Sources ParserState (Reader T2TMeta) ()
    header = ParsecT Sources ParserState (Reader T2TMeta) ()
    titleline ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT Sources ParserState (Reader T2TMeta) ()
    authorline ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT Sources ParserState (Reader T2TMeta) ()
    dateline

    headerline :: B.ToMetaValue a => Text -> T2T a -> T2T ()
    headerline :: forall a.
    ToMetaValue a =>
    Text -> T2T a -> ParsecT Sources ParserState (Reader T2TMeta) ()
    headerline Text
    field T2T a
    p = (() ()
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a b.
    a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline)
                            ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> (T2T a
    p T2T a
    -> (a -> ParsecT Sources ParserState (Reader T2TMeta) ())
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> (a -> ParsecT Sources ParserState (Reader T2TMeta) b)
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (ParserState -> ParserState)
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState)
     -> ParsecT Sources ParserState (Reader T2TMeta) ())
    -> (a -> ParserState -> ParserState)
    -> a
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> a -> ParserState -> ParserState
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    forall b. ToMetaValue b => Text -> b -> ParserState -> ParserState
    B.setMeta Text
    field)

    titleline :: T2T ()
    titleline :: ParsecT Sources ParserState (Reader T2TMeta) ()
    titleline =
      Text
    -> T2T Inlines -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a.
    ToMetaValue a =>
    Text -> T2T a -> ParsecT Sources ParserState (Reader T2TMeta) ()
    headerline Text
    "title" (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 (Reader T2TMeta) [Inlines]
    -> T2T Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> T2T Inlines
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [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 T2T Inlines
    inline ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline)

    authorline :: T2T ()
    authorline :: ParsecT Sources ParserState (Reader T2TMeta) ()
    authorline =
      Text
    -> ParsecT Sources ParserState (Reader T2TMeta) [Inlines]
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a.
    ToMetaValue a =>
    Text -> T2T a -> ParsecT Sources ParserState (Reader T2TMeta) ()
    headerline Text
    "author" (T2T Inlines
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [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]
    sepBy T2T Inlines
    author (Char -> ParsecT Sources ParserState (Reader T2TMeta) 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 (Reader T2TMeta) [Inlines]
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [Inlines]
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline)
      where
        author :: T2T Inlines
    author = 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 (Reader T2TMeta) [Inlines]
    -> T2T Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> T2T Inlines
    -> ParsecT Sources ParserState (Reader T2TMeta) [Inlines]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    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 (Reader T2TMeta) 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 (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline) ParsecT Sources ParserState (Reader T2TMeta) ()
    -> T2T Inlines -> T2T Inlines
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> T2T Inlines
    inline)

    dateline :: T2T ()
    dateline :: ParsecT Sources ParserState (Reader T2TMeta) ()
    dateline = Text
    -> T2T Inlines -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a.
    ToMetaValue a =>
    Text -> T2T a -> ParsecT Sources ParserState (Reader T2TMeta) ()
    headerline Text
    "date" (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 (Reader T2TMeta) [Inlines]
    -> T2T Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> T2T Inlines
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [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 T2T Inlines
    inline ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline)

    type Keyword = Text
    type Value = Text

    setting :: T2T (Keyword, Value)
    setting :: ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    setting = do
      [Char] -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "%!"
      keyword <- ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    ignoreSpacesCap (ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m Text
    many1Char ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    alphaNum)
      char ':'
      value <- ignoreSpacesCap (manyTillChar anyChar newline)
      return (keyword, value)

    -- Blocks

    parseBlocks :: T2T Blocks
    parseBlocks :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    parseBlocks = [Blocks] -> Blocks
    forall a. Monoid a => [a] -> a
    mconcat ([Blocks] -> Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) [Blocks]
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) [Blocks]
    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 (Reader T2TMeta) Blocks
    block ParsecT Sources ParserState (Reader T2TMeta) ()
    forall s (m :: * -> *) t u.
    (Stream s m t, Show t) =>
    ParsecT s u m ()
    eof

    block :: T2T Blocks
    block :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    block =
      [ParsecT Sources ParserState (Reader T2TMeta) Blocks]
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice
        [ Blocks
    forall a. Monoid a => a
    mempty Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a b.
    a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Text
    blanklines
        , ParsecT Sources ParserState (Reader T2TMeta) Blocks
    quote
        , ParsecT Sources ParserState (Reader T2TMeta) Blocks
    hrule -- hrule must go above title
        , ParsecT Sources ParserState (Reader T2TMeta) Blocks
    title
        , ParsecT Sources ParserState (Reader T2TMeta) Blocks
    commentBlock
        , ParsecT Sources ParserState (Reader T2TMeta) Blocks
    verbatim
        , ParsecT Sources ParserState (Reader T2TMeta) Blocks
    rawBlock
        , ParsecT Sources ParserState (Reader T2TMeta) Blocks
    taggedBlock
        , ParsecT Sources ParserState (Reader T2TMeta) Blocks
    list
        , ParsecT Sources ParserState (Reader T2TMeta) Blocks
    table
        , ParsecT Sources ParserState (Reader T2TMeta) Blocks
    para
        ]

    title :: T2T Blocks
    title :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    title = ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) Blocks
     -> ParsecT Sources ParserState (Reader T2TMeta) Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a b. (a -> b) -> a -> b
    $ Char -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    balancedTitle Char
    '+' ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Char -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    balancedTitle Char
    '='

    balancedTitle :: Char -> T2T Blocks
    balancedTitle :: Char -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    balancedTitle Char
    c = ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) Blocks
     -> ParsecT Sources ParserState (Reader T2TMeta) Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Sources ParserState (Reader T2TMeta) Text
    spaces
      level <- [Char] -> Column
    forall a. [a] -> Column
    forall (t :: * -> *) a. Foldable t => t a -> Column
    length ([Char] -> Column)
    -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 (Char -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    c)
      guard (level <= 5) -- Max header level 5
      heading <- manyTillChar (noneOf "\n\r") (count level (char c))
      label <- optionMaybe (enclosed (char '[') (char ']') (alphaNum <|> oneOf "_-"))
      many spaceChar *> newline
      let attr = Attr -> ([Char] -> Attr) -> Maybe [Char] -> Attr
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Attr
    nullAttr (\[Char]
    x -> ([Char] -> Text
    T.pack [Char]
    x, [], [])) Maybe [Char]
    label
      return $ B.headerWith attr level (trimInlines $ B.text heading)

    para :: T2T Blocks
    para :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    para = ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) Blocks
     -> ParsecT Sources ParserState (Reader T2TMeta) Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      ils <- T2T Inlines
    parseInlines
      nl <- option False (True <$ newline)
      option (B.plain ils) (guard nl >> notFollowedBy listStart >> return (B.para ils))
      where
        listStart :: ParsecT Sources ParserState (Reader T2TMeta) Column
    listStart = ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ParsecT Sources ParserState (Reader T2TMeta) Column
    bulletListStart ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Sources ParserState (Reader T2TMeta) Column
    orderedListStart

    commentBlock :: T2T Blocks
    commentBlock :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    commentBlock = ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) Text
    -> (Text -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a.
    Monoid a =>
    T2T a
    -> (a -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    blockMarkupArea ParsecT Sources ParserState (Reader T2TMeta) Text
    forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
    anyLine (Blocks -> Text -> Blocks
    forall a b. a -> b -> a
    const Blocks
    forall a. Monoid a => a
    mempty) Text
    "%%%") ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a. Monoid a => T2T a
    comment

    -- Separator and Strong line treated the same
    hrule :: T2T Blocks
    hrule :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    hrule = ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) Blocks
     -> ParsecT Sources ParserState (Reader T2TMeta) Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Sources ParserState (Reader T2TMeta) Text
    spaces
      line <- ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ([Char] -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    "=-_")
      guard (length line >= 20)
      B.horizontalRule <$ blankline

    quote :: T2T Blocks
    quote :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    quote = ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) Blocks
     -> ParsecT Sources ParserState (Reader T2TMeta) Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead ParsecT Sources ParserState (Reader T2TMeta) Char
    tab
      rawQuote <-  ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) [Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 (ParsecT Sources ParserState (Reader T2TMeta) Char
    tab ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParsecT Sources ParserState (Reader T2TMeta) Text
    spaces ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
    anyLine)
      contents <- parseFromString' parseBlocks (T.intercalate "\n" rawQuote <> "\n\n")
      return $ B.blockQuote contents

    commentLine :: T2T Inlines
    commentLine :: T2T Inlines
    commentLine = T2T Inlines
    forall a. Monoid a => T2T a
    comment

    -- List Parsing code from Org Reader

    list :: T2T Blocks
    list :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    list = [ParsecT Sources ParserState (Reader T2TMeta) Blocks]
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice [ParsecT Sources ParserState (Reader T2TMeta) Blocks
    bulletList, ParsecT Sources ParserState (Reader T2TMeta) Blocks
    orderedList, ParsecT Sources ParserState (Reader T2TMeta) Blocks
    definitionList]

    bulletList :: T2T Blocks
    bulletList :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    bulletList = [Blocks] -> Blocks
    B.bulletList ([Blocks] -> Blocks)
    -> ([Blocks] -> [Blocks]) -> [Blocks] -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Blocks] -> [Blocks]
    compactify
                 ([Blocks] -> Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) [Blocks]
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) [Blocks]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 (ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a.
    ParsecT Sources ParserState (Reader T2TMeta) Column
    -> T2T a -> T2T a
    listItem ParsecT Sources ParserState (Reader T2TMeta) Column
    bulletListStart ParsecT Sources ParserState (Reader T2TMeta) Blocks
    parseBlocks)

    orderedList :: T2T Blocks
    orderedList :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    orderedList = [Blocks] -> Blocks
    B.orderedList ([Blocks] -> Blocks)
    -> ([Blocks] -> [Blocks]) -> [Blocks] -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Blocks] -> [Blocks]
    compactify
                  ([Blocks] -> Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) [Blocks]
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) [Blocks]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 (ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a.
    ParsecT Sources ParserState (Reader T2TMeta) Column
    -> T2T a -> T2T a
    listItem ParsecT Sources ParserState (Reader T2TMeta) Column
    orderedListStart ParsecT Sources ParserState (Reader T2TMeta) Blocks
    parseBlocks)

    definitionList :: T2T Blocks
    definitionList :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    definitionList = ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) Blocks
     -> ParsecT Sources ParserState (Reader T2TMeta) Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a b. (a -> b) -> a -> b
    $
      [(Inlines, [Blocks])] -> Blocks
    B.definitionList ([(Inlines, [Blocks])] -> Blocks)
    -> ([(Inlines, [Blocks])] -> [(Inlines, [Blocks])])
    -> [(Inlines, [Blocks])]
    -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
    compactifyDL ([(Inlines, [Blocks])] -> Blocks)
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Inlines, [Blocks])]
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
        ParsecT Sources ParserState (Reader T2TMeta) (Inlines, [Blocks])
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Inlines, [Blocks])]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 (ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) (Inlines, [Blocks])
    -> ParsecT Sources ParserState (Reader T2TMeta) (Inlines, [Blocks])
    forall a.
    ParsecT Sources ParserState (Reader T2TMeta) Column
    -> T2T a -> T2T a
    listItem ParsecT Sources ParserState (Reader T2TMeta) Column
    definitionListStart ParsecT Sources ParserState (Reader T2TMeta) (Inlines, [Blocks])
    definitionListEnd)

    definitionListEnd :: T2T (Inlines, [Blocks])
    definitionListEnd :: ParsecT Sources ParserState (Reader T2TMeta) (Inlines, [Blocks])
    definitionListEnd = (,) (Inlines -> [Blocks] -> (Inlines, [Blocks]))
    -> T2T Inlines
    -> ParsecT
         Sources
         ParserState
         (Reader T2TMeta)
         ([Blocks] -> (Inlines, [Blocks]))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ([Inlines] -> Inlines
    forall a. Monoid a => [a] -> a
    mconcat ([Inlines] -> Inlines)
    -> ParsecT Sources ParserState (Reader T2TMeta) [Inlines]
    -> T2T Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> T2T Inlines
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [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 T2T Inlines
    inline ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline) ParsecT
      Sources
      ParserState
      (Reader T2TMeta)
      ([Blocks] -> (Inlines, [Blocks]))
    -> ParsecT Sources ParserState (Reader T2TMeta) [Blocks]
    -> ParsecT Sources ParserState (Reader T2TMeta) (Inlines, [Blocks])
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) (a -> b)
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> ((Blocks -> [Blocks] -> [Blocks]
    forall a. a -> [a] -> [a]
    :[]) (Blocks -> [Blocks])
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) [Blocks]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    parseBlocks)

    genericListStart :: T2T Char
                     -> T2T Int
    genericListStart :: ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    genericListStart ParsecT Sources ParserState (Reader T2TMeta) Char
    listMarker = ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) Column
     -> ParsecT Sources ParserState (Reader T2TMeta) Column)
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    forall a b. (a -> b) -> a -> b
    $
      (Column
    2Column -> Column -> Column
    forall a. Num a => a -> a -> a
    +) (Column -> Column)
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ([Char] -> Column
    forall a. [a] -> Column
    forall (t :: * -> *) a. Foldable t => t a -> Column
    length ([Char] -> Column)
    -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    spaceChar
                ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources ParserState (Reader T2TMeta) Char
    listMarker ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources ParserState (Reader T2TMeta) Char
    space ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    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 (Reader T2TMeta) Char
    space)

    -- parses bullet list \start and returns its length (excl. following whitespace)
    bulletListStart :: T2T  Int
    bulletListStart :: ParsecT Sources ParserState (Reader T2TMeta) Column
    bulletListStart = ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    genericListStart (Char -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '-')

    orderedListStart :: T2T Int
    orderedListStart :: ParsecT Sources ParserState (Reader T2TMeta) Column
    orderedListStart = ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    genericListStart (Char -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '+' )

    definitionListStart :: T2T Int
    definitionListStart :: ParsecT Sources ParserState (Reader T2TMeta) Column
    definitionListStart = ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    genericListStart (Char -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    ':')

    -- parse raw text for one list item, excluding start marker and continuations
    listItem :: T2T Int
             -> T2T a
             -> T2T a
    listItem :: forall a.
    ParsecT Sources ParserState (Reader T2TMeta) Column
    -> T2T a -> T2T a
    listItem ParsecT Sources ParserState (Reader T2TMeta) Column
    start T2T a
    end = T2T a -> T2T a
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (T2T a -> T2T a) -> T2T a -> T2T a
    forall a b. (a -> b) -> a -> b
    $ do
      markerLength <- ParsecT Sources ParserState (Reader T2TMeta) Column
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ParsecT Sources ParserState (Reader T2TMeta) Column
    start
      firstLine <- anyLineNewline
      blank <- option "" ("\n" <$ blankline)
      rest <- T.concat <$> many (listContinuation markerLength)
      parseFromString' end $ firstLine <> blank <> rest

    -- continuation of a list item - indented and separated by blankline or endline.
    -- Note: nested lists are parsed as continuations.
    listContinuation :: Int
                     -> T2T Text
    listContinuation :: Column -> ParsecT Sources ParserState (Reader T2TMeta) Text
    listContinuation Column
    markerLength = ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) Text
     -> ParsecT Sources ParserState (Reader T2TMeta) Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall a b. (a -> b) -> a -> b
    $
      ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall b s (m :: * -> *) a st.
    (Show b, Stream s m a) =>
    ParsecT s st m b -> ParsecT s st m ()
    notFollowedBy' (ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline)
      ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> (Text -> Text -> Text
    forall a. Monoid a => a -> a -> a
    mappend (Text -> Text -> Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) (Text -> Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ([Text] -> Text
    T.concat ([Text] -> Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) [Text]
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) [Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Sources ParserState (Reader T2TMeta) Text
    listLine)
                  ParsecT Sources ParserState (Reader T2TMeta) (Text -> Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) (a -> b)
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m Text
    manyChar ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline)
     where listLine :: ParsecT Sources ParserState (Reader T2TMeta) Text
    listLine = ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) Text
     -> ParsecT Sources ParserState (Reader T2TMeta) Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall a b. (a -> b) -> a -> b
    $ Column -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char, HasReaderOptions st) =>
    Column -> ParsecT s st m Text
    indentWith Column
    markerLength ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
    anyLineNewline

    -- Table

    table :: T2T Blocks
    table :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    table = ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) Blocks
     -> ParsecT Sources ParserState (Reader T2TMeta) Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      tableHeader <- ((Alignment, Blocks) -> Blocks)
    -> [(Alignment, Blocks)] -> [Blocks]
    forall a b. (a -> b) -> [a] -> [b]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (Alignment, Blocks) -> Blocks
    forall a b. (a, b) -> b
    snd ([(Alignment, Blocks)] -> [Blocks])
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    -> ParsecT Sources ParserState (Reader T2TMeta) [Blocks]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [(Alignment, Blocks)]
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option [(Alignment, Blocks)]
    forall a. Monoid a => a
    mempty (ParsecT Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ParsecT Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    headerRow)
      rows <- many1 (many commentLine *> tableRow)
      let columns = [[(Alignment, Blocks)]] -> [[(Alignment, Blocks)]]
    forall a. [[a]] -> [[a]]
    transpose [[(Alignment, Blocks)]]
    rows
      let ncolumns = [[(Alignment, Blocks)]] -> Column
    forall a. [a] -> Column
    forall (t :: * -> *) a. Foldable t => t a -> Column
    length [[(Alignment, Blocks)]]
    columns
      let aligns = ([(Alignment, Blocks)] -> Alignment)
    -> [[(Alignment, Blocks)]] -> [Alignment]
    forall a b. (a -> b) -> [a] -> [b]
    map (Alignment -> Maybe Alignment -> Alignment
    forall a. a -> Maybe a -> a
    fromMaybe Alignment
    AlignDefault (Maybe Alignment -> Alignment)
    -> ([(Alignment, Blocks)] -> Maybe Alignment)
    -> [(Alignment, Blocks)]
    -> Alignment
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((Alignment, Blocks) -> Maybe Alignment -> Maybe Alignment)
    -> Maybe Alignment -> [(Alignment, Blocks)] -> Maybe Alignment
    forall a b. (a -> b -> b) -> b -> [a] -> b
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr (Alignment, Blocks) -> Maybe Alignment -> Maybe Alignment
    forall a. (Alignment, a) -> Maybe Alignment -> Maybe Alignment
    findAlign Maybe Alignment
    forall a. Maybe a
    Nothing) [[(Alignment, Blocks)]]
    columns
      let rows' = ([(Alignment, Blocks)] -> [Blocks])
    -> [[(Alignment, Blocks)]] -> [[Blocks]]
    forall a b. (a -> b) -> [a] -> [b]
    map (((Alignment, Blocks) -> Blocks)
    -> [(Alignment, Blocks)] -> [Blocks]
    forall a b. (a -> b) -> [a] -> [b]
    map (Alignment, Blocks) -> Blocks
    forall a b. (a, b) -> b
    snd) [[(Alignment, Blocks)]]
    rows
      let size = Column
    -> (NonEmpty Column -> Column) -> Maybe (NonEmpty Column) -> Column
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Column
    0 NonEmpty Column -> Column
    forall a. Ord a => NonEmpty a -> a
    forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
    maximum (Maybe (NonEmpty Column) -> Column)
    -> Maybe (NonEmpty Column) -> Column
    forall a b. (a -> b) -> a -> b
    $ [Column] -> Maybe (NonEmpty Column)
    forall a. [a] -> Maybe (NonEmpty a)
    nonEmpty ([Column] -> Maybe (NonEmpty Column))
    -> [Column] -> Maybe (NonEmpty Column)
    forall a b. (a -> b) -> a -> b
    $ ([Blocks] -> Column) -> [[Blocks]] -> [Column]
    forall a b. (a -> b) -> [a] -> [b]
    map [Blocks] -> Column
    forall a. [a] -> Column
    forall (t :: * -> *) a. Foldable t => t a -> Column
    length [[Blocks]]
    rows'
      let rowsPadded = ([Blocks] -> [Blocks]) -> [[Blocks]] -> [[Blocks]]
    forall a b. (a -> b) -> [a] -> [b]
    map (Column -> [Blocks] -> [Blocks]
    forall a. Monoid a => Column -> [a] -> [a]
    pad Column
    size) [[Blocks]]
    rows'
      let headerPadded = if [Blocks] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [Blocks]
    tableHeader then [Blocks]
    forall a. Monoid a => a
    mempty else Column -> [Blocks] -> [Blocks]
    forall a. Monoid a => Column -> [a] -> [a]
    pad Column
    size [Blocks]
    tableHeader
      let toRow = Attr -> [Cell] -> Row
    Row Attr
    nullAttr ([Cell] -> Row) -> ([Blocks] -> [Cell]) -> [Blocks] -> Row
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Blocks -> Cell) -> [Blocks] -> [Cell]
    forall a b. (a -> b) -> [a] -> [b]
    map Blocks -> Cell
    B.simpleCell
          toHeaderRow [Blocks]
    l = [[Blocks] -> Row
    toRow [Blocks]
    l | Bool -> Bool
    not ([Blocks] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [Blocks]
    l)]
      return $ B.table B.emptyCaption
                        (zip aligns (replicate ncolumns ColWidthDefault))
                          (TableHead nullAttr $ toHeaderRow headerPadded)
                          [TableBody nullAttr 0 [] $ map toRow rowsPadded]
                          (TableFoot nullAttr [])

    pad :: (Monoid a) => Int -> [a] -> [a]
    pad :: forall a. Monoid a => Column -> [a] -> [a]
    pad Column
    n [a]
    xs = [a]
    xs [a] -> [a] -> [a]
    forall a. [a] -> [a] -> [a]
    ++ Column -> a -> [a]
    forall a. Column -> a -> [a]
    replicate (Column
    n Column -> Column -> Column
    forall a. Num a => a -> a -> a
    - [a] -> Column
    forall a. [a] -> Column
    forall (t :: * -> *) a. Foldable t => t a -> Column
    length [a]
    xs) a
    forall a. Monoid a => a
    mempty

    findAlign :: (Alignment, a) -> Maybe Alignment -> Maybe Alignment
    findAlign :: forall a. (Alignment, a) -> Maybe Alignment -> Maybe Alignment
    findAlign (Alignment
    x,a
    _) (Just Alignment
    y)
      | Alignment
    x Alignment -> Alignment -> Bool
    forall a. Eq a => a -> a -> Bool
    == Alignment
    y = Alignment -> Maybe Alignment
    forall a. a -> Maybe a
    Just Alignment
    x
      | Bool
    otherwise = Alignment -> Maybe Alignment
    forall a. a -> Maybe a
    Just Alignment
    AlignDefault
    findAlign (Alignment
    x,a
    _) Maybe Alignment
    Nothing = Alignment -> Maybe Alignment
    forall a. a -> Maybe a
    Just Alignment
    x

    headerRow :: T2T [(Alignment, Blocks)]
    headerRow :: ParsecT Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    headerRow = ParsecT Sources ParserState (Reader T2TMeta) [Char]
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    forall a.
    T2T a
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    genericRow ([Char] -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "||")

    tableRow :: T2T [(Alignment, Blocks)]
    tableRow :: ParsecT Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    tableRow = ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    forall a.
    T2T a
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    genericRow (Char -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '|')

    genericRow :: T2T a -> T2T [(Alignment, Blocks)]
    genericRow :: forall a.
    T2T a
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    genericRow T2T a
    start = ParsecT Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
     -> ParsecT
          Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)])
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Sources ParserState (Reader T2TMeta) Text
    spaces ParsecT Sources ParserState (Reader T2TMeta) Text -> T2T a -> T2T a
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> T2T a
    start
      ParsecT Sources ParserState (Reader T2TMeta) (Alignment, Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    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 (Reader T2TMeta) (Alignment, Blocks)
    tableCell ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline ParsecT Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    -> [Char]
    -> ParsecT
         Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> [Char]
    "genericRow"

    tableCell :: T2T (Alignment, Blocks)
    tableCell :: ParsecT Sources ParserState (Reader T2TMeta) (Alignment, Blocks)
    tableCell = ParsecT Sources ParserState (Reader T2TMeta) (Alignment, Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) (Alignment, Blocks)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) (Alignment, Blocks)
     -> ParsecT
          Sources ParserState (Reader T2TMeta) (Alignment, Blocks))
    -> ParsecT Sources ParserState (Reader T2TMeta) (Alignment, Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) (Alignment, Blocks)
    forall a b. (a -> b) -> a -> b
    $ do
      leftSpaces <- [Char] -> Column
    forall a. [a] -> Column
    forall (t :: * -> *) a. Foldable t => t a -> Column
    length ([Char] -> Column)
    -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    -> ParsecT Sources ParserState (Reader T2TMeta) Column
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Sources ParserState (Reader T2TMeta) Char
    space) -- Case of empty cell means we must lookAhead
      content <- manyTill inline (try $ lookAhead cellEnd)
      rightSpaces <- length <$> many space
      let align =
            case Column -> Column -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare Column
    leftSpaces Column
    rightSpaces of
                  Ordering
    LT -> Alignment
    AlignLeft
                  Ordering
    EQ -> Alignment
    AlignCenter
                  Ordering
    GT -> Alignment
    AlignRight
      endOfCell
      return (align, B.plain (B.trimInlines $ mconcat content))
      where
        cellEnd :: ParsecT Sources ParserState (Reader T2TMeta) ()
    cellEnd = ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> (ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Sources ParserState (Reader T2TMeta) Char
    space ParsecT Sources ParserState (Reader T2TMeta) [Char]
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources ParserState (Reader T2TMeta) ()
    endOfCell)

    endOfCell :: T2T ()
    endOfCell :: ParsecT Sources ParserState (Reader T2TMeta) ()
    endOfCell = ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    skipMany1 (ParsecT Sources ParserState (Reader T2TMeta) Char
     -> ParsecT Sources ParserState (Reader T2TMeta) ())
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a b. (a -> b) -> a -> b
    $ Char -> ParsecT Sources ParserState (Reader T2TMeta) 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 (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ( () ()
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a b.
    a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline)

    -- Raw area

    verbatim :: T2T Blocks
    verbatim :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    verbatim = ParsecT Sources ParserState (Reader T2TMeta) Text
    -> (Text -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a.
    Monoid a =>
    T2T a
    -> (a -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    genericBlock ParsecT Sources ParserState (Reader T2TMeta) Text
    forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
    anyLineNewline Text -> Blocks
    B.codeBlock Text
    "```"

    rawBlock :: T2T Blocks
    rawBlock :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    rawBlock = ParsecT Sources ParserState (Reader T2TMeta) Text
    -> (Text -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a.
    Monoid a =>
    T2T a
    -> (a -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    genericBlock ParsecT Sources ParserState (Reader T2TMeta) Text
    forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
    anyLineNewline (Inlines -> Blocks
    B.para (Inlines -> Blocks) -> (Text -> Inlines) -> Text -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Inlines
    B.str) Text
    "\"\"\""

    taggedBlock :: T2T Blocks
    taggedBlock :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
    taggedBlock = do
      target <- ParsecT Sources ParserState (Reader T2TMeta) Text
    getTarget
      genericBlock anyLineNewline (B.rawBlock target) "'''"

    -- Generic

    genericBlock :: Monoid a => T2T a -> (a -> Blocks) -> Text -> T2T Blocks
    genericBlock :: forall a.
    Monoid a =>
    T2T a
    -> (a -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    genericBlock T2T a
    p a -> Blocks
    f Text
    s = T2T a
    -> (a -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a.
    Monoid a =>
    T2T a
    -> (a -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    blockMarkupArea T2T a
    p a -> Blocks
    f Text
    s ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> T2T a
    -> (a -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall a.
    T2T a
    -> (a -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    blockMarkupLine T2T a
    p a -> Blocks
    f Text
    s

    blockMarkupArea :: Monoid a => T2T a -> (a -> Blocks) -> Text -> T2T Blocks
    blockMarkupArea :: forall a.
    Monoid a =>
    T2T a
    -> (a -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    blockMarkupArea T2T a
    p a -> Blocks
    f Text
    s = ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (do
      Text -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) u.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s u m Text
    textStr Text
    s ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline
      a -> Blocks
    f (a -> Blocks) -> ([a] -> a) -> [a] -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [a] -> a
    forall a. Monoid a => [a] -> a
    mconcat ([a] -> Blocks)
    -> ParsecT Sources ParserState (Reader T2TMeta) [a]
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> T2T a
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) [a]
    forall s (m :: * -> *) t u a end.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
    manyTill T2T a
    p (ParsecT Sources ParserState (Reader T2TMeta) ()
    forall s (m :: * -> *) t u.
    (Stream s m t, Show t) =>
    ParsecT s u m ()
    eof ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void (Text -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) u.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s u m Text
    textStr Text
    s ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline)))

    blockMarkupLine :: T2T a -> (a -> Blocks) -> Text -> T2T Blocks
    blockMarkupLine :: forall a.
    T2T a
    -> (a -> Blocks)
    -> Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    blockMarkupLine T2T a
    p a -> Blocks
    f Text
    s = ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (a -> Blocks
    f (a -> Blocks)
    -> T2T a -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Text -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) u.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s u m Text
    textStr Text
    s ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources ParserState (Reader T2TMeta) Char
    space ParsecT Sources ParserState (Reader T2TMeta) Char -> T2T a -> T2T a
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> T2T a
    p))

    -- Can be in either block or inline position
    comment :: Monoid a => T2T a
    comment :: forall a. Monoid a => T2T a
    comment = ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) a
     -> ParsecT Sources ParserState (Reader T2TMeta) a)
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Sources ParserState (Reader T2TMeta) ()
    atStart
      T2T Inlines -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy T2T Inlines
    macro
      a
    forall a. Monoid a => a
    mempty a
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall a b.
    a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ (Char -> ParsecT Sources ParserState (Reader T2TMeta) 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 (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
    anyLine)

    -- Inline

    parseInlines :: T2T Inlines
    parseInlines :: T2T Inlines
    parseInlines = 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 (Reader T2TMeta) [Inlines]
    -> T2T Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> T2T Inlines
    -> ParsecT Sources ParserState (Reader T2TMeta) [Inlines]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 T2T Inlines
    inline

    inline :: T2T Inlines
    inline :: T2T Inlines
    inline =
      [T2T Inlines] -> T2T Inlines
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice
        [ T2T Inlines
    endline
        , T2T Inlines
    macro
        , T2T Inlines
    commentLine
        , T2T Inlines
    whitespace
        , T2T Inlines
    url
        , T2T Inlines
    link
        , T2T Inlines
    image
        , T2T Inlines
    bold
        , T2T Inlines
    underline
        , T2T Inlines
    code
        , T2T Inlines
    raw
        , T2T Inlines
    tagged
        , T2T Inlines
    strike
        , T2T Inlines
    italic
        , T2T Inlines
    code
        , T2T Inlines
    str
        , T2T Inlines
    symbol
        ]

    bold :: T2T Inlines
    bold :: T2T Inlines
    bold = T2T Inlines
    -> (Inlines -> Inlines) -> Char -> (Text -> Inlines) -> T2T Inlines
    forall a.
    Monoid a =>
    T2T a -> (a -> Inlines) -> Char -> (Text -> a) -> T2T Inlines
    inlineMarkup T2T Inlines
    inline Inlines -> Inlines
    B.strong Char
    '*' Text -> Inlines
    B.str

    underline :: T2T Inlines
    underline :: T2T Inlines
    underline = T2T Inlines
    -> (Inlines -> Inlines) -> Char -> (Text -> Inlines) -> T2T Inlines
    forall a.
    Monoid a =>
    T2T a -> (a -> Inlines) -> Char -> (Text -> a) -> T2T Inlines
    inlineMarkup T2T Inlines
    inline Inlines -> Inlines
    B.underline Char
    '_' Text -> Inlines
    B.str

    strike :: T2T Inlines
    strike :: T2T Inlines
    strike = T2T Inlines
    -> (Inlines -> Inlines) -> Char -> (Text -> Inlines) -> T2T Inlines
    forall a.
    Monoid a =>
    T2T a -> (a -> Inlines) -> Char -> (Text -> a) -> T2T Inlines
    inlineMarkup T2T Inlines
    inline Inlines -> Inlines
    B.strikeout Char
    '-' Text -> Inlines
    B.str

    italic :: T2T Inlines
    italic :: T2T Inlines
    italic = T2T Inlines
    -> (Inlines -> Inlines) -> Char -> (Text -> Inlines) -> T2T Inlines
    forall a.
    Monoid a =>
    T2T a -> (a -> Inlines) -> Char -> (Text -> a) -> T2T Inlines
    inlineMarkup T2T Inlines
    inline Inlines -> Inlines
    B.emph Char
    '/' Text -> Inlines
    B.str

    code :: T2T Inlines
    code :: T2T Inlines
    code = ParsecT Sources ParserState (Reader T2TMeta) Text
    -> (Text -> Inlines) -> Char -> (Text -> Text) -> T2T Inlines
    forall a.
    Monoid a =>
    T2T a -> (a -> Inlines) -> Char -> (Text -> a) -> T2T Inlines
    inlineMarkup (Char -> Text
    T.singleton (Char -> Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    anyChar) Text -> Inlines
    B.code Char
    '`' Text -> Text
    forall a. a -> a
    id

    raw :: T2T Inlines
    raw :: T2T Inlines
    raw = ParsecT Sources ParserState (Reader T2TMeta) Text
    -> (Text -> Inlines) -> Char -> (Text -> Text) -> T2T Inlines
    forall a.
    Monoid a =>
    T2T a -> (a -> Inlines) -> Char -> (Text -> a) -> T2T Inlines
    inlineMarkup (Char -> Text
    T.singleton (Char -> Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    anyChar) Text -> Inlines
    B.text Char
    '"' Text -> Text
    forall a. a -> a
    id

    tagged :: T2T Inlines
    tagged :: T2T Inlines
    tagged = do
      target <- ParsecT Sources ParserState (Reader T2TMeta) Text
    getTarget
      inlineMarkup (T.singleton <$> anyChar) (B.rawInline target) '\'' id

    -- Parsec for markup indicated by a double character.
    -- Inline markup is greedy and glued
    -- Greedy meaning ***a*** = Bold [Str "*a*"]
    -- Glued meaning that markup must be tight to content
    -- Markup can't pass newlines
    inlineMarkup :: Monoid a
                 => T2T a -- Content parser
                 -> (a -> Inlines) -- Constructor
                 -> Char -- Fence
                 -> (Text -> a) -- Special Case to handle ******
                 -> T2T Inlines
    inlineMarkup :: forall a.
    Monoid a =>
    T2T a -> (a -> Inlines) -> Char -> (Text -> a) -> T2T Inlines
    inlineMarkup T2T a
    p a -> Inlines
    f Char
    c Text -> a
    special = T2T Inlines -> T2T Inlines
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (T2T Inlines -> T2T Inlines) -> T2T Inlines -> T2T Inlines
    forall a b. (a -> b) -> a -> b
    $ do
      start <- ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m Text
    many1Char (Char -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    c)
      let l = Text -> Column
    T.length Text
    start
      guard (l >= 2)
      when (l == 2) (void $ notFollowedBy space)
      -- We must make sure that there is no space before the start of the
      -- closing tags
      body <-  optionMaybe (try $ manyTillChar (noneOf "\n\r")
                    (try $ lookAhead (noneOf " " >> string [c,c] )))
      case body of
        Just Text
    middle -> do
          lastChar <- ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    anyChar
          end <- many1Char (char c)
          let parser Text
    inp = T2T a -> Text -> T2T a
    forall (m :: * -> *) u a.
    (Monad m, HasLastStrPosition u) =>
    ParsecT Sources u m a -> Text -> ParsecT Sources u m a
    parseFromString' ([a] -> a
    forall a. Monoid a => [a] -> a
    mconcat ([a] -> a)
    -> ParsecT Sources ParserState (Reader T2TMeta) [a] -> T2T a
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> T2T a -> ParsecT Sources ParserState (Reader T2TMeta) [a]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many T2T a
    p) Text
    inp
          let start' = case Column -> Text -> Text
    T.drop Column
    2 Text
    start of
                              Text
    "" -> a
    forall a. Monoid a => a
    mempty
                              Text
    xs -> Text -> a
    special Text
    xs
          body' <- parser (middle <> T.singleton lastChar)
          let end' = case Column -> Text -> Text
    T.drop Column
    2 Text
    end of
                              Text
    "" -> a
    forall a. Monoid a => a
    mempty
                              Text
    xs -> Text -> a
    special Text
    xs
          return $ f (start' `mappend` body' `mappend` end')
        Maybe Text
    Nothing -> do -- Either bad or case such as *****
          Bool -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Column
    l Column -> Column -> Bool
    forall a. Ord a => a -> a -> Bool
    >= Column
    5)
          let body' :: Text
    body' = Column -> Text -> Text
    T.replicate (Column
    l Column -> Column -> Column
    forall a. Num a => a -> a -> a
    - Column
    4) (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Char -> Text
    T.singleton Char
    c
          Inlines -> T2T Inlines
    forall a. a -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Inlines -> T2T Inlines) -> Inlines -> T2T Inlines
    forall a b. (a -> b) -> a -> b
    $ a -> Inlines
    f (Text -> a
    special Text
    body')

    link :: T2T Inlines
    link :: T2T Inlines
    link = T2T Inlines -> T2T Inlines
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try T2T Inlines
    imageLink T2T Inlines -> T2T Inlines -> T2T Inlines
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> T2T Inlines
    titleLink

    -- Link with title
    titleLink :: T2T Inlines
    titleLink :: T2T Inlines
    titleLink = T2T Inlines -> T2T Inlines
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (T2T Inlines -> T2T Inlines) -> T2T Inlines -> T2T Inlines
    forall a b. (a -> b) -> a -> b
    $ do
      Char -> ParsecT Sources ParserState (Reader T2TMeta) 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 (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    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 (Reader T2TMeta) Char
    space
      tokens <- ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [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]
    sepBy1 (ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m Text
    manyChar (ParsecT Sources ParserState (Reader T2TMeta) Char
     -> ParsecT Sources ParserState (Reader T2TMeta) Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall a b. (a -> b) -> a -> b
    $ [Char] -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    noneOf [Char]
    " ]") ParsecT Sources ParserState (Reader T2TMeta) Char
    space
      guard (length tokens >= 2)
      char ']'
      let link' = [Text] -> Text
    forall a. HasCallStack => [a] -> a
    last [Text]
    tokens
      guard $ not $ T.null link'
      let tit = [Text] -> Text
    T.unwords ([Text] -> [Text]
    forall a. HasCallStack => [a] -> [a]
    init [Text]
    tokens)
      return $ B.link link' "" (B.text tit)

    -- Link with image
    imageLink :: T2T Inlines
    imageLink :: T2T Inlines
    imageLink = T2T Inlines -> T2T Inlines
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (T2T Inlines -> T2T Inlines) -> T2T Inlines -> T2T Inlines
    forall a b. (a -> b) -> a -> b
    $ do
      Char -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '['
      body <- T2T Inlines
    image
      many1 space
      l <- manyTillChar (noneOf "\n\r ") (char ']')
      return (B.link l "" body)

    macro :: T2T Inlines
    macro :: T2T Inlines
    macro = T2T Inlines -> T2T Inlines
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (T2T Inlines -> T2T Inlines) -> T2T Inlines -> T2T Inlines
    forall a b. (a -> b) -> a -> b
    $ do
      name <- [Char] -> ParsecT Sources ParserState (Reader T2TMeta) [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 (Reader T2TMeta) [Char]
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> [Text] -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    [Text] -> ParsecT s st m Text
    oneOfStringsCI (((Text, T2TMeta -> Text) -> Text)
    -> [(Text, T2TMeta -> Text)] -> [Text]
    forall a b. (a -> b) -> [a] -> [b]
    map (Text, T2TMeta -> Text) -> Text
    forall a b. (a, b) -> a
    fst [(Text, T2TMeta -> Text)]
    commands)
      optional (try $ enclosed (char '(') (char ')') anyChar)
      lookAhead (spaceChar <|> oneOf specialChars <|> newline)
      maybe (return mempty) (\T2TMeta -> Text
    f -> (T2TMeta -> Inlines) -> T2T Inlines
    forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    asks (Text -> Inlines
    B.str (Text -> Inlines) -> (T2TMeta -> Text) -> T2TMeta -> Inlines
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . T2TMeta -> Text
    f)) (lookup name commands)
      where
        commands :: [(Text, T2TMeta -> Text)]
    commands = [ (Text
    "date", T2TMeta -> Text
    date), (Text
    "mtime", T2TMeta -> Text
    mtime)
                   , (Text
    "infile", [Char] -> Text
    T.pack ([Char] -> Text) -> (T2TMeta -> [Char]) -> T2TMeta -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . T2TMeta -> [Char]
    infile), (Text
    "outfile", [Char] -> Text
    T.pack ([Char] -> Text) -> (T2TMeta -> [Char]) -> T2TMeta -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . T2TMeta -> [Char]
    outfile)]

    -- raw URLs in text are automatically linked
    url :: T2T Inlines
    url :: T2T Inlines
    url = T2T Inlines -> T2T Inlines
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (T2T Inlines -> T2T Inlines) -> T2T Inlines -> T2T Inlines
    forall a b. (a -> b) -> a -> b
    $ do
      (rawUrl, escapedUrl) <- ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    uri ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    emailAddress'
      return $ B.link rawUrl "" (B.str escapedUrl)

    emailAddress' :: T2T (Text, Text)
    emailAddress' :: ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    emailAddress' = do
      (base, mailURI) <- ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m (Text, Text)
    emailAddress
      query <- option "" emailQuery
      return (base <> query, mailURI <> query)

    emailQuery :: T2T Text
    emailQuery :: ParsecT Sources ParserState (Reader T2TMeta) Text
    emailQuery = do
      Char -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '?'
      parts <- ParsecT Sources ParserState (Reader T2TMeta) Text
    kv ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [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]
    `sepBy1` (Char -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '&')
      return $ "?" <> T.intercalate "&" parts

    kv :: T2T Text
    kv :: ParsecT Sources ParserState (Reader T2TMeta) Text
    kv = do
      k <- [Char] -> Text
    T.pack ([Char] -> Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    alphaNum
      char '='
      let vchar = ParsecT Sources u (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    alphaNum ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ([Char] -> ParsecT Sources u (Reader T2TMeta) 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 (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    forall a b.
    ParsecT Sources u (Reader T2TMeta) a
    -> ParsecT Sources u (Reader T2TMeta) b
    -> ParsecT Sources u (Reader T2TMeta) a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) 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 (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    alphaNum)
      v <- T.pack <$> many1 vchar
      return (k <> "=" <> v)

    uri :: T2T (Text, Text)
    uri :: ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    uri = ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
     -> ParsecT Sources ParserState (Reader T2TMeta) (Text, Text))
    -> ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    forall a b. (a -> b) -> a -> b
    $ do
      address <- ParsecT Sources ParserState (Reader T2TMeta) Text
    t2tURI
      return (address, escapeURI address)

    -- The definition of a URI in the T2T source differs from the
    -- actual definition. This is a transcription of the definition in
    -- the source of v2.6
    --isT2TURI :: String -> Bool
    --isT2TURI (parse t2tURI "" -> Right _) = True
    --isT2TURI _ = False

    t2tURI :: T2T Text
    t2tURI :: ParsecT Sources ParserState (Reader T2TMeta) Text
    t2tURI = do
      start <- ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    (<>) (Text -> Text -> Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) (Text -> Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall {st}. ParsecT Sources st (Reader T2TMeta) Text
    proto ParsecT Sources ParserState (Reader T2TMeta) (Text -> Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) (a -> b)
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall {st}. ParsecT Sources st (Reader T2TMeta) Text
    urlLogin) ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall {st}. ParsecT Sources st (Reader T2TMeta) Text
    guess
      domain <- many1Char chars
      sep <- manyChar (char '/')
      form' <- option mempty (T.cons <$> char '?' <*> many1Char form)
      anchor' <- option mempty (T.cons <$> char '#' <*> manyChar anchor)
      return (start <> domain <> sep <> form' <> anchor')
      where
        protos :: [Text]
    protos = [Text
    "http", Text
    "https", Text
    "ftp", Text
    "telnet", Text
    "gopher", Text
    "wais"]
        proto :: ParsecT Sources st (Reader T2TMeta) Text
    proto = Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    (<>) (Text -> Text -> Text)
    -> ParsecT Sources st (Reader T2TMeta) Text
    -> ParsecT Sources st (Reader T2TMeta) (Text -> Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [Text] -> ParsecT Sources st (Reader T2TMeta) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    [Text] -> ParsecT s st m Text
    oneOfStrings [Text]
    protos ParsecT Sources st (Reader T2TMeta) (Text -> Text)
    -> ParsecT Sources st (Reader T2TMeta) Text
    -> ParsecT Sources st (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources st (Reader T2TMeta) (a -> b)
    -> ParsecT Sources st (Reader T2TMeta) a
    -> ParsecT Sources st (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Text -> ParsecT Sources st (Reader T2TMeta) Text
    forall s (m :: * -> *) u.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s u m Text
    textStr Text
    "://"
        guess :: ParsecT Sources u (Reader T2TMeta) Text
    guess = Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    (<>) (Text -> Text -> Text)
    -> ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) (Text -> Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ((Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    (<>) (Text -> Text -> Text)
    -> ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) (Text -> Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> ParsecT Sources u (Reader T2TMeta) Text
    forall s (m :: * -> *) u.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s u m Text
    stringAnyCase Text
    "www" ParsecT Sources u (Reader T2TMeta) (Text -> Text)
    -> ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources u (Reader T2TMeta) (a -> b)
    -> ParsecT Sources u (Reader T2TMeta) a
    -> ParsecT Sources u (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option Text
    forall a. Monoid a => a
    mempty (Char -> Text
    T.singleton (Char -> Text)
    -> ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [Char] -> ParsecT Sources u (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    "23"))
                  ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Text -> ParsecT Sources u (Reader T2TMeta) Text
    forall s (m :: * -> *) u.
    (Stream s m Char, UpdateSourcePos s Char) =>
    Text -> ParsecT s u m Text
    stringAnyCase Text
    "ftp") ParsecT Sources u (Reader T2TMeta) (Text -> Text)
    -> ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources u (Reader T2TMeta) (a -> b)
    -> ParsecT Sources u (Reader T2TMeta) a
    -> ParsecT Sources u (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> (Char -> Text
    T.singleton (Char -> Text)
    -> ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Char -> ParsecT Sources u (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '.')
        login :: ParsecT Sources u (Reader T2TMeta) Char
    login = ParsecT Sources u (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    alphaNum ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> [Char] -> ParsecT Sources u (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    "_.-"
        pass :: ParsecT Sources st (Reader T2TMeta) Text
    pass = ParsecT Sources st (Reader T2TMeta) Char
    -> ParsecT Sources st (Reader T2TMeta) Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m Text
    manyChar ([Char] -> ParsecT Sources st (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    noneOf [Char]
    " @")
        chars :: ParsecT Sources u (Reader T2TMeta) Char
    chars = ParsecT Sources u (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    alphaNum ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> [Char] -> ParsecT Sources u (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    "%._/~:,=$@&+-"
        anchor :: ParsecT Sources u (Reader T2TMeta) Char
    anchor = ParsecT Sources u (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    alphaNum ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> [Char] -> ParsecT Sources u (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    "%._0"
        form :: ParsecT Sources u (Reader T2TMeta) Char
    form = ParsecT Sources u (Reader T2TMeta) Char
    forall {u}. ParsecT Sources u (Reader T2TMeta) Char
    chars ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> [Char] -> ParsecT Sources u (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    ";*"
        urlLogin :: ParsecT Sources u (Reader T2TMeta) Text
    urlLogin = Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option Text
    forall a. Monoid a => a
    mempty (ParsecT Sources u (Reader T2TMeta) Text
     -> ParsecT Sources u (Reader T2TMeta) Text)
    -> ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall a b. (a -> b) -> a -> b
    $ ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ((\Text
    x Text
    y Char
    z -> Text
    x Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    y Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Char -> Text
    T.singleton Char
    z) (Text -> Text -> Char -> Text)
    -> ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) (Text -> Char -> Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m Text
    many1Char ParsecT Sources u (Reader T2TMeta) Char
    forall {u}. ParsecT Sources u (Reader T2TMeta) Char
    login ParsecT Sources u (Reader T2TMeta) (Text -> Char -> Text)
    -> ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) (Char -> Text)
    forall a b.
    ParsecT Sources u (Reader T2TMeta) (a -> b)
    -> ParsecT Sources u (Reader T2TMeta) a
    -> ParsecT Sources u (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option Text
    forall a. Monoid a => a
    mempty (Char -> Text -> Text
    T.cons (Char -> Text -> Text)
    -> ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) (Text -> Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Char -> ParsecT Sources u (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    ':' ParsecT Sources u (Reader T2TMeta) (Text -> Text)
    -> ParsecT Sources u (Reader T2TMeta) Text
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources u (Reader T2TMeta) (a -> b)
    -> ParsecT Sources u (Reader T2TMeta) a
    -> ParsecT Sources u (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> ParsecT Sources u (Reader T2TMeta) Text
    forall {st}. ParsecT Sources st (Reader T2TMeta) Text
    pass) ParsecT Sources u (Reader T2TMeta) (Char -> Text)
    -> ParsecT Sources u (Reader T2TMeta) Char
    -> ParsecT Sources u (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources u (Reader T2TMeta) (a -> b)
    -> ParsecT Sources u (Reader T2TMeta) a
    -> ParsecT Sources u (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Char -> ParsecT Sources u (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '@')

    image :: T2T Inlines
    image :: T2T Inlines
    image =  T2T Inlines -> T2T Inlines
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (T2T Inlines -> T2T Inlines) -> T2T Inlines -> T2T Inlines
    forall a b. (a -> b) -> a -> b
    $ do
      -- List taken from txt2tags source
      let extensions :: [Text]
    extensions = [Text
    ".jpg", Text
    ".jpeg", Text
    ".gif", Text
    ".png", Text
    ".eps", Text
    ".bmp"]
      Char -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '['
      (path, ext) <- ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
    forall s u (m :: * -> *) b.
    ParsecT s u m Char -> ParsecT s u m b -> ParsecT s u m (Text, b)
    manyUntilChar ([Char] -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    noneOf [Char]
    "\n\t\r ") ([Text] -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    [Text] -> ParsecT s st m Text
    oneOfStrings [Text]
    extensions)
      char ']'
      return $ B.image (path <> ext) "" mempty

    -- Characters used in markup
    specialChars :: [Char]
    specialChars :: [Char]
    specialChars = [Char]
    "%*-_/|:+;"

    tab :: T2T Char
    tab :: ParsecT Sources ParserState (Reader T2TMeta) Char
    tab = Char -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '\t'

    space :: T2T Char
    space :: ParsecT Sources ParserState (Reader T2TMeta) Char
    space = Char -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    ' '

    spaces :: T2T Text
    spaces :: ParsecT Sources ParserState (Reader T2TMeta) Text
    spaces = ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m Text
    manyChar ParsecT Sources ParserState (Reader T2TMeta) Char
    space

    endline :: T2T Inlines
    endline :: T2T Inlines
    endline = T2T Inlines -> T2T Inlines
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (T2T Inlines -> T2T Inlines) -> T2T Inlines -> T2T Inlines
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline
      ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    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 (Reader T2TMeta) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    blankline
      ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    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 (Reader T2TMeta) Blocks
    hrule
      ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    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 (Reader T2TMeta) Blocks
    title
      ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    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 (Reader T2TMeta) Blocks
    verbatim
      ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    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 (Reader T2TMeta) Blocks
    rawBlock
      ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    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 (Reader T2TMeta) Blocks
    taggedBlock
      ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    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 (Reader T2TMeta) Blocks
    quote
      ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    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 (Reader T2TMeta) Blocks
    list
      ParsecT Sources ParserState (Reader T2TMeta) Blocks
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    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 (Reader T2TMeta) Blocks
    table
      Inlines -> T2T Inlines
    forall a. a -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Inlines
    B.softbreak

    str :: T2T Inlines
    str :: T2T Inlines
    str = T2T Inlines -> T2T Inlines
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (T2T Inlines -> T2T Inlines) -> T2T Inlines -> T2T Inlines
    forall a b. (a -> b) -> a -> b
    $ Text -> Inlines
    B.str (Text -> Inlines)
    -> ParsecT Sources ParserState (Reader T2TMeta) Text -> T2T Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) Char
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m Text
    many1Char ([Char] -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    noneOf ([Char] -> ParsecT Sources ParserState (Reader T2TMeta) Char)
    -> [Char] -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall a b. (a -> b) -> a -> b
    $ [Char]
    specialChars [Char] -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    "\n\r ")

    whitespace :: T2T Inlines
    whitespace :: T2T Inlines
    whitespace = T2T Inlines -> T2T Inlines
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (T2T Inlines -> T2T Inlines) -> T2T Inlines -> T2T Inlines
    forall a b. (a -> b) -> a -> b
    $ Inlines
    B.space Inlines
    -> ParsecT Sources ParserState (Reader T2TMeta) Char -> T2T Inlines
    forall a b.
    a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Sources ParserState (Reader T2TMeta) Char
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s st m Char
    spaceChar

    symbol :: T2T Inlines
    symbol :: T2T 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 (Reader T2TMeta) Char -> T2T Inlines
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [Char] -> ParsecT Sources ParserState (Reader T2TMeta) Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    specialChars

    -- Utility

    getTarget :: T2T Text
    getTarget :: ParsecT Sources ParserState (Reader T2TMeta) Text
    getTarget = do
      mv <- Text -> Meta -> Maybe MetaValue
    lookupMeta Text
    "target" (Meta -> Maybe MetaValue)
    -> (ParserState -> Meta) -> ParserState -> Maybe MetaValue
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ParserState -> Meta
    stateMeta (ParserState -> Maybe MetaValue)
    -> ParsecT Sources ParserState (Reader T2TMeta) ParserState
    -> ParsecT Sources ParserState (Reader T2TMeta) (Maybe MetaValue)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Sources ParserState (Reader T2TMeta) ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      return $ case mv of
                  Just (MetaString Text
    target)        -> Text
    target
                  Just (MetaInlines [Str Text
    target]) -> Text
    target
                  Maybe MetaValue
    _                               -> Text
    "html"

    atStart :: T2T ()
    atStart :: ParsecT Sources ParserState (Reader T2TMeta) ()
    atStart = ParsecT Sources ParserState (Reader T2TMeta) SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition ParsecT Sources ParserState (Reader T2TMeta) SourcePos
    -> (SourcePos -> ParsecT Sources ParserState (Reader T2TMeta) ())
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> (a -> ParsecT Sources ParserState (Reader T2TMeta) b)
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Bool -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Bool -> ParsecT Sources ParserState (Reader T2TMeta) ())
    -> (SourcePos -> Bool)
    -> SourcePos
    -> ParsecT Sources ParserState (Reader T2TMeta) ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Column -> Column -> Bool
    forall a. Eq a => a -> a -> Bool
    == Column
    1) (Column -> Bool) -> (SourcePos -> Column) -> SourcePos -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SourcePos -> Column
    sourceColumn

    ignoreSpacesCap :: T2T Text -> T2T Text
    ignoreSpacesCap :: ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    ignoreSpacesCap ParsecT Sources ParserState (Reader T2TMeta) Text
    p = Text -> Text
    T.toLower (Text -> Text)
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (ParsecT Sources ParserState (Reader T2TMeta) Text
    spaces ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources ParserState (Reader T2TMeta) Text
    p ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    -> ParsecT Sources ParserState (Reader T2TMeta) Text
    forall a b.
    ParsecT Sources ParserState (Reader T2TMeta) a
    -> ParsecT Sources ParserState (Reader T2TMeta) b
    -> ParsecT Sources ParserState (Reader T2TMeta) a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Sources ParserState (Reader T2TMeta) Text
    spaces)