{-# 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]
forall a.
(Column -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [T2TMeta] -> ShowS
$cshowList :: [T2TMeta] -> ShowS
show :: T2TMeta -> [Char]
$cshow :: T2TMeta -> [Char]
showsPrec :: Column -> T2TMeta -> ShowS
$cshowsPrec :: Column -> 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
    [[Char]]
inps <- forall (m :: * -> *). PandocMonad m => m [[Char]]
P.getInputFiles
    [Char]
outp <- forall a. a -> Maybe a -> a
fromMaybe [Char]
"" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => m (Maybe [Char])
P.getOutputFile
    [Char]
curDate <- forall t. FormatTime t => TimeLocale -> [Char] -> t -> [Char]
formatTime TimeLocale
defaultTimeLocale [Char]
"%F" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => m ZonedTime
P.getZonedTime
    [Char]
curMtime <- forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
catchError
                 (forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall (m :: * -> *). PandocMonad m => [Char] -> m UTCTime
P.getModificationTime [[Char]]
inps forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
                   (\case
                       Maybe (NonEmpty UTCTime)
Nothing ->
                         forall t. FormatTime t => TimeLocale -> [Char] -> t -> [Char]
formatTime TimeLocale
defaultTimeLocale [Char]
"%T" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => m ZonedTime
P.getZonedTime
                       Just NonEmpty UTCTime
ts -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
                         forall t. FormatTime t => TimeLocale -> [Char] -> t -> [Char]
formatTime TimeLocale
defaultTimeLocale [Char]
"%T" forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum NonEmpty UTCTime
ts)
                    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Maybe (NonEmpty a)
nonEmpty)
                (forall a b. a -> b -> a
const (forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
""))
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text -> [Char] -> [Char] -> T2TMeta
T2TMeta ([Char] -> Text
T.pack [Char]
curDate) ([Char] -> Text
T.pack [Char]
curMtime)
                     (forall a. [a] -> [[a]] -> [a]
intercalate [Char]
", " [[Char]]
inps) [Char]
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 (forall a. ToSources a => a -> Sources
toSources a
s)
  T2TMeta
meta <- forall (m :: * -> *). PandocMonad m => m T2TMeta
getT2TMeta
  let parsed :: Either PandocError Pandoc
parsed = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall r a. Reader r a -> r -> a
runReader T2TMeta
meta forall a b. (a -> b) -> a -> b
$
        forall (m :: * -> *) t st a.
(Monad m, ToSources t) =>
ParsecT Sources st m a -> st -> t -> m (Either PandocError a)
readWithM T2T Pandoc
parseT2T (forall a. Default a => a
def {stateOptions :: ReaderOptions
stateOptions = ReaderOptions
opts}) Sources
sources
  case Either PandocError Pandoc
parsed of
    Right Pandoc
result -> forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
result
    Left PandocError
e       -> 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 :: T2T Pandoc
parseT2T = do
  -- Parse header if standalone flag is set
  Bool
standalone <- forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
getOption ReaderOptions -> Bool
readerStandalone
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
standalone T2T ()
parseHeader
  Blocks
body <- forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>  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 forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
  Meta
meta' <- ParserState -> Meta
stateMeta forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Meta -> [Block] -> Pandoc
Pandoc Meta
meta' (forall a. Many a -> [a]
B.toList Blocks
body)

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

header :: T2T ()
header :: T2T ()
header = T2T ()
titleline forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> T2T ()
authorline forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> T2T ()
dateline

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

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

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

dateline :: T2T ()
dateline :: T2T ()
dateline = forall a. ToMetaValue a => Text -> T2T a -> T2T ()
headerline Text
"date" (Inlines -> Inlines
trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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) Inlines
inline 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 :: T2T (Text, Text)
setting = do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"%!"
  Text
keyword <- T2T Text -> T2T Text
ignoreSpacesCap (forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum)
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':'
  Text
value <- T2T Text -> T2T Text
ignoreSpacesCap (forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline)
  forall (m :: * -> *) a. Monad m => a -> m a
return (Text
keyword, Text
value)

-- Blocks

parseBlocks :: T2T Blocks
parseBlocks :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
parseBlocks = forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 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 =
  forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
    [ forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
balancedTitle Char
'+' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
balancedTitle Char
'='

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

para :: T2T Blocks
para :: ParsecT Sources ParserState (Reader T2TMeta) Blocks
para = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Inlines
ils <- ParsecT Sources ParserState (Reader T2TMeta) Inlines
parseInlines
  Bool
nl <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (Bool
True forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline)
  forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Inlines -> Blocks
B.plain Inlines
ils) (forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
nl forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> 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) Column
listStart forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Blocks
B.para Inlines
ils))
  where
    listStart :: ParsecT Sources ParserState (Reader T2TMeta) Column
listStart = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState (Reader T2TMeta) Column
bulletListStart 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall a.
Monoid a =>
T2T a
-> (a -> Blocks)
-> Text
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
blockMarkupArea forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine (forall a b. a -> b -> a
const forall a. Monoid a => a
mempty) Text
"%%%") forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  T2T Text
spaces
  [Char]
line <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
"=-_")
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard (forall (t :: * -> *) a. Foldable t => t a -> Column
length [Char]
line forall a. Ord a => a -> a -> Bool
>= Column
20)
  Blocks
B.horizontalRule forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline

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

commentLine :: T2T Inlines
commentLine :: ParsecT Sources ParserState (Reader T2TMeta) Inlines
commentLine = forall a. Monoid a => T2T a
comment

-- List Parsing code from Org Reader

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

definitionListEnd :: T2T (Inlines, [Blocks])
definitionListEnd :: T2T (Inlines, [Blocks])
definitionListEnd = (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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) Inlines
inline forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((forall a. a -> [a] -> [a]
:[]) 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  (Column
2forall a. Num a => a -> a -> a
+) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (t :: * -> *) a. Foldable t => t a -> Column
length forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
            forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState (Reader T2TMeta) Char
listMarker forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState (Reader T2TMeta) Char
space forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* 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 (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 (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 (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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Column
markerLength <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState (Reader T2TMeta) Column
start
  Text
firstLine <- forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLineNewline
  Text
blank <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" (Text
"\n" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline)
  Text
rest <- [Text] -> Text
T.concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (Column -> T2T Text
listContinuation Column
markerLength)
  forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParsecT Sources u m a -> Text -> ParsecT Sources u m a
parseFromString' T2T a
end forall a b. (a -> b) -> a -> b
$ Text
firstLine forall a. Semigroup a => a -> a -> a
<> Text
blank forall a. Semigroup a => a -> a -> a
<> Text
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 -> T2T Text
listContinuation Column
markerLength = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline)
  forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (forall a. Monoid a => a -> a -> a
mappend forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Text] -> Text
T.concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 T2T Text
listLine)
              forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline)
 where listLine :: T2T Text
listLine = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, HasReaderOptions st) =>
Column -> ParsecT s st m Text
indentWith Column
markerLength forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLineNewline

-- Table

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

pad :: (Monoid a) => Int -> [a] -> [a]
pad :: forall a. Monoid a => Column -> [a] -> [a]
pad Column
n [a]
xs = [a]
xs forall a. [a] -> [a] -> [a]
++ forall a. Column -> a -> [a]
replicate (Column
n forall a. Num a => a -> a -> a
- forall (t :: * -> *) a. Foldable t => t a -> Column
length [a]
xs) 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 forall a. Eq a => a -> a -> Bool
== Alignment
y = forall a. a -> Maybe a
Just Alignment
x
  | Bool
otherwise = forall a. a -> Maybe a
Just Alignment
AlignDefault
findAlign (Alignment
x,a
_) Maybe Alignment
Nothing = forall a. a -> Maybe a
Just Alignment
x

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


tableCell :: T2T (Alignment, Blocks)
tableCell :: T2T (Alignment, Blocks)
tableCell = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Column
leftSpaces <- forall (t :: * -> *) a. Foldable t => t a -> Column
length forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall s (m :: * -> *) t u a.
Stream s m t =>
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
  [Inlines]
content <- 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) Inlines
inline (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead T2T ()
cellEnd)
  Column
rightSpaces <- forall (t :: * -> *) a. Foldable t => t a -> Column
length forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT Sources ParserState (Reader T2TMeta) Char
space
  let align :: Alignment
align =
        case 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
  T2T ()
endOfCell
  forall (m :: * -> *) a. Monad m => a -> m a
return (Alignment
align, Inlines -> Blocks
B.plain (Inlines -> Inlines
B.trimInlines forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat [Inlines]
content))
  where
    cellEnd :: T2T ()
cellEnd = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState (Reader T2TMeta) Char
space forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> T2T ()
endOfCell)

endOfCell :: T2T ()
endOfCell :: T2T ()
endOfCell = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'|') forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ( () forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead 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 = forall a.
Monoid a =>
T2T a
-> (a -> Blocks)
-> Text
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
genericBlock 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 = forall a.
Monoid a =>
T2T a
-> (a -> Blocks)
-> Text
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
genericBlock forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLineNewline (Inlines -> Blocks
B.para 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
  Text
target <- T2T Text
getTarget
  forall a.
Monoid a =>
T2T a
-> (a -> Blocks)
-> Text
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
genericBlock forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLineNewline (Text -> Text -> Blocks
B.rawBlock Text
target) Text
"'''"

-- 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 = forall a.
Monoid a =>
T2T a
-> (a -> Blocks)
-> Text
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
blockMarkupArea T2T a
p a -> Blocks
f Text
s forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (do
  forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
s forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
  a -> Blocks
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 (forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (f :: * -> *) a. Functor f => f a -> f ()
void (forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
s forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (a -> Blocks
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
s forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState (Reader T2TMeta) Char
space 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 = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  T2T ()
atStart
  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) Inlines
macro
  forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'%' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
anyLine)

-- Inline

parseInlines :: T2T Inlines
parseInlines :: ParsecT Sources ParserState (Reader T2TMeta) Inlines
parseInlines = Inlines -> Inlines
trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Sources ParserState (Reader T2TMeta) Inlines
inline

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

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

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

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

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

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

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

tagged :: T2T Inlines
tagged :: ParsecT Sources ParserState (Reader T2TMeta) Inlines
tagged = do
  Text
target <- T2T Text
getTarget
  forall a.
Monoid a =>
T2T a
-> (a -> Inlines)
-> Char
-> (Text -> a)
-> ParsecT Sources ParserState (Reader T2TMeta) Inlines
inlineMarkup (Char -> Text
T.singleton forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar) (Text -> Text -> Inlines
B.rawInline Text
target) Char
'\'' forall a. a -> a
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)
-> ParsecT Sources ParserState (Reader T2TMeta) Inlines
inlineMarkup T2T a
p a -> Inlines
f Char
c Text -> a
special = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Text
start <- forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c)
  let l :: Column
l = Text -> Column
T.length Text
start
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Column
l forall a. Ord a => a -> a -> Bool
>= Column
2)
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Column
l forall a. Eq a => a -> a -> Bool
== Column
2) (forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ 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)
  -- We must make sure that there is no space before the start of the
  -- closing tags
  Maybe Text
body <-  forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r")
                (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
" " forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char
c,Char
c] )))
  case Maybe Text
body of
    Just Text
middle -> do
      Char
lastChar <- forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar
      Text
end <- forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c)
      let parser :: Text -> T2T a
parser Text
inp = forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParsecT Sources u m a -> Text -> ParsecT Sources u m a
parseFromString' (forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many T2T a
p) Text
inp
      let start' :: a
start' = case Column -> Text -> Text
T.drop Column
2 Text
start of
                          Text
"" -> forall a. Monoid a => a
mempty
                          Text
xs -> Text -> a
special Text
xs
      a
body' <- Text -> T2T a
parser (Text
middle forall a. Semigroup a => a -> a -> a
<> Char -> Text
T.singleton Char
lastChar)
      let end' :: a
end' = case Column -> Text -> Text
T.drop Column
2 Text
end of
                          Text
"" -> forall a. Monoid a => a
mempty
                          Text
xs -> Text -> a
special Text
xs
      forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ a -> Inlines
f (a
start' forall a. Monoid a => a -> a -> a
`mappend` a
body' forall a. Monoid a => a -> a -> a
`mappend` a
end')
    Maybe Text
Nothing -> do -- Either bad or case such as *****
      forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Column
l forall a. Ord a => a -> a -> Bool
>= Column
5)
      let body' :: Text
body' = Column -> Text -> Text
T.replicate (Column
l forall a. Num a => a -> a -> a
- Column
4) forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton Char
c
      forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ a -> Inlines
f (Text -> a
special Text
body')

link :: T2T Inlines
link :: ParsecT Sources ParserState (Reader T2TMeta) Inlines
link = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState (Reader T2TMeta) Inlines
imageLink 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) Inlines
titleLink

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

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

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

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

emailAddress' :: T2T (Text, Text)
emailAddress' :: T2T (Text, Text)
emailAddress' = do
  (Text
base, Text
mailURI) <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (Text, Text)
emailAddress
  Text
query <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" T2T Text
emailQuery
  forall (m :: * -> *) a. Monad m => a -> m a
return (Text
base forall a. Semigroup a => a -> a -> a
<> Text
query, Text
mailURI forall a. Semigroup a => a -> a -> a
<> Text
query)

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

kv :: T2T Text
kv :: T2T Text
kv = do
  Text
k <- [Char] -> Text
T.pack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'='
  let vchar :: ParsecT Sources u (Reader T2TMeta) Char
vchar = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
"%._/~:,=$@&+-;*" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum)
  Text
v <- [Char] -> Text
T.pack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall {u}. ParsecT Sources u (Reader T2TMeta) Char
vchar
  forall (m :: * -> *) a. Monad m => a -> m a
return (Text
k forall a. Semigroup a => a -> a -> a
<> Text
"=" forall a. Semigroup a => a -> a -> a
<> Text
v)

uri :: T2T (Text, Text)
uri :: T2T (Text, Text)
uri = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Text
address <- T2T Text
t2tURI
  forall (m :: * -> *) a. Monad m => a -> m a
return (Text
address, Text -> Text
escapeURI Text
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 :: T2T Text
t2tURI = do
  Text
start <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall a. Semigroup a => a -> a -> a
(<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall {st}. ParsecT Sources st (Reader T2TMeta) Text
proto forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall {st}. ParsecT Sources st (Reader T2TMeta) Text
urlLogin) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {st}. ParsecT Sources st (Reader T2TMeta) Text
guess
  Text
domain <- forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall {u}. ParsecT Sources u (Reader T2TMeta) Char
chars
  Text
sep <- forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'/')
  Text
form' <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option forall a. Monoid a => a
mempty (Char -> Text -> Text
T.cons forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'?' forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall {u}. ParsecT Sources u (Reader T2TMeta) Char
form)
  Text
anchor' <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option forall a. Monoid a => a
mempty (Char -> Text -> Text
T.cons forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'#' forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar forall {u}. ParsecT Sources u (Reader T2TMeta) Char
anchor)
  forall (m :: * -> *) a. Monad m => a -> m a
return (Text
start forall a. Semigroup a => a -> a -> a
<> Text
domain forall a. Semigroup a => a -> a -> a
<> Text
sep forall a. Semigroup a => a -> a -> a
<> Text
form' forall a. Semigroup a => a -> a -> a
<> Text
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 = forall a. Semigroup a => a -> a -> a
(<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
[Text] -> ParsecT s st m Text
oneOfStrings [Text]
protos forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> 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 = forall a. Semigroup a => a -> a -> a
(<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((forall a. Semigroup a => a -> a -> a
(<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
stringAnyCase Text
"www" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option forall a. Monoid a => a
mempty (Char -> Text
T.singleton forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
"23"))
              forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
stringAnyCase Text
"ftp") forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> Text
T.singleton forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> 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 = forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar (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 = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> 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 = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> 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 = forall {u}. ParsecT Sources u (Reader T2TMeta) Char
chars forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> 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 = forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option forall a. Monoid a => a
mempty forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ((\Text
x Text
y Char
z -> Text
x forall a. Semigroup a => a -> a -> a
<> Text
y forall a. Semigroup a => a -> a -> a
<> Char -> Text
T.singleton Char
z) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall {u}. ParsecT Sources u (Reader T2TMeta) Char
login forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option forall a. Monoid a => a
mempty (Char -> Text -> Text
T.cons forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':' forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall {st}. ParsecT Sources st (Reader T2TMeta) Text
pass) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> 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 :: ParsecT Sources ParserState (Reader T2TMeta) Inlines
image =  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try 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"]
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'['
  (Text
path, Text
ext) <- forall s u (m :: * -> *) b.
ParsecT s u m Char -> ParsecT s u m b -> ParsecT s u m (Text, b)
manyUntilChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\t\r ") (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
[Text] -> ParsecT s st m Text
oneOfStrings [Text]
extensions)
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']'
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.image (Text
path forall a. Semigroup a => a -> a -> a
<> Text
ext) Text
"" forall a. Monoid a => a
mempty

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

tab :: T2T Char
tab :: ParsecT Sources ParserState (Reader T2TMeta) Char
tab = 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 = 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 :: T2T Text
spaces = 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 :: ParsecT Sources ParserState (Reader T2TMeta) Inlines
endline = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
  forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline
  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
  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
  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
  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
  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
  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
  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
  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
  forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.softbreak

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

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

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

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

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