{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}
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, escapeURI)
type T2T = ParserT Sources ParserState (Reader T2TMeta)
data T2TMeta = T2TMeta {
T2TMeta -> Text
date :: Text
, T2TMeta -> Text
mtime :: Text
, T2TMeta -> FilePath
infile :: FilePath
, T2TMeta -> FilePath
outfile :: FilePath
} deriving Int -> T2TMeta -> ShowS
[T2TMeta] -> ShowS
T2TMeta -> FilePath
(Int -> T2TMeta -> ShowS)
-> (T2TMeta -> FilePath) -> ([T2TMeta] -> ShowS) -> Show T2TMeta
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [T2TMeta] -> ShowS
$cshowList :: [T2TMeta] -> ShowS
show :: T2TMeta -> FilePath
$cshow :: T2TMeta -> FilePath
showsPrec :: Int -> T2TMeta -> ShowS
$cshowsPrec :: Int -> T2TMeta -> ShowS
Show
instance Default T2TMeta where
def :: T2TMeta
def = Text -> Text -> FilePath -> FilePath -> T2TMeta
T2TMeta Text
"" Text
"" FilePath
"" FilePath
""
getT2TMeta :: PandocMonad m => m T2TMeta
getT2TMeta :: m T2TMeta
getT2TMeta = do
[FilePath]
inps <- m [FilePath]
forall (m :: * -> *). PandocMonad m => m [FilePath]
P.getInputFiles
FilePath
outp <- FilePath -> Maybe FilePath -> FilePath
forall a. a -> Maybe a -> a
fromMaybe FilePath
"" (Maybe FilePath -> FilePath) -> m (Maybe FilePath) -> m FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Maybe FilePath)
forall (m :: * -> *). PandocMonad m => m (Maybe FilePath)
P.getOutputFile
FilePath
curDate <- TimeLocale -> FilePath -> ZonedTime -> FilePath
forall t. FormatTime t => TimeLocale -> FilePath -> t -> FilePath
formatTime TimeLocale
defaultTimeLocale FilePath
"%F" (ZonedTime -> FilePath) -> m ZonedTime -> m FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m ZonedTime
forall (m :: * -> *). PandocMonad m => m ZonedTime
P.getZonedTime
FilePath
curMtime <- m FilePath -> (PandocError -> m FilePath) -> m FilePath
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
catchError
((FilePath -> m UTCTime) -> [FilePath] -> m [UTCTime]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM FilePath -> m UTCTime
forall (m :: * -> *). PandocMonad m => FilePath -> m UTCTime
P.getModificationTime [FilePath]
inps m [UTCTime] -> ([UTCTime] -> m FilePath) -> m FilePath
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\case
Maybe (NonEmpty UTCTime)
Nothing ->
TimeLocale -> FilePath -> ZonedTime -> FilePath
forall t. FormatTime t => TimeLocale -> FilePath -> t -> FilePath
formatTime TimeLocale
defaultTimeLocale FilePath
"%T" (ZonedTime -> FilePath) -> m ZonedTime -> m FilePath
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 -> FilePath -> m FilePath
forall (m :: * -> *) a. Monad m => a -> m a
return (FilePath -> m FilePath) -> FilePath -> m FilePath
forall a b. (a -> b) -> a -> b
$
TimeLocale -> FilePath -> UTCTime -> FilePath
forall t. FormatTime t => TimeLocale -> FilePath -> t -> FilePath
formatTime TimeLocale
defaultTimeLocale FilePath
"%T" (UTCTime -> FilePath) -> UTCTime -> FilePath
forall a b. (a -> b) -> a -> b
$ NonEmpty UTCTime -> UTCTime
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum NonEmpty UTCTime
ts)
(Maybe (NonEmpty UTCTime) -> m FilePath)
-> ([UTCTime] -> Maybe (NonEmpty UTCTime))
-> [UTCTime]
-> m FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [UTCTime] -> Maybe (NonEmpty UTCTime)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty)
(m FilePath -> PandocError -> m FilePath
forall a b. a -> b -> a
const (FilePath -> m FilePath
forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
""))
T2TMeta -> m T2TMeta
forall (m :: * -> *) a. Monad m => a -> m a
return (T2TMeta -> m T2TMeta) -> T2TMeta -> m T2TMeta
forall a b. (a -> b) -> a -> b
$ Text -> Text -> FilePath -> FilePath -> T2TMeta
T2TMeta (FilePath -> Text
T.pack FilePath
curDate) (FilePath -> Text
T.pack FilePath
curMtime)
(FilePath -> [FilePath] -> FilePath
forall a. [a] -> [[a]] -> [a]
intercalate FilePath
", " [FilePath]
inps) FilePath
outp
readTxt2Tags :: (PandocMonad m, ToSources a)
=> ReaderOptions
-> a
-> m Pandoc
readTxt2Tags :: ReaderOptions -> a -> m Pandoc
readTxt2Tags ReaderOptions
opts a
s = do
let sources :: Sources
sources = Int -> Sources -> Sources
ensureFinalNewlines Int
2 (a -> Sources
forall a. ToSources a => a -> Sources
toSources a
s)
T2TMeta
meta <- m T2TMeta
forall (m :: * -> *). PandocMonad m => m T2TMeta
getT2TMeta
let parsed :: Either PandocError Pandoc
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
$
ParserT Sources ParserState (Reader T2TMeta) Pandoc
-> ParserState
-> Sources
-> Reader T2TMeta (Either PandocError Pandoc)
forall (m :: * -> *) t st a.
(Monad m, ToSources t) =>
ParserT Sources st m a -> st -> t -> m (Either PandocError a)
readWithM ParserT Sources ParserState (Reader T2TMeta) Pandoc
parseT2T (ParserState
forall a. Default a => a
def {stateOptions :: ReaderOptions
stateOptions = ReaderOptions
opts}) Sources
sources
case Either PandocError Pandoc
parsed of
Right Pandoc
result -> Pandoc -> m Pandoc
forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
result
Left PandocError
e -> PandocError -> m Pandoc
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PandocError
e
parseT2T :: T2T Pandoc
parseT2T :: ParserT Sources ParserState (Reader T2TMeta) Pandoc
parseT2T = do
Bool
standalone <- (ReaderOptions -> Bool)
-> ParserT Sources ParserState (Reader T2TMeta) Bool
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParserT s st m b
getOption ReaderOptions -> Bool
readerStandalone
Bool
-> ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
standalone ParsecT Sources ParserState (Reader T2TMeta) ()
parseHeader
Blocks
body <- [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
Meta
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
Pandoc -> ParserT Sources ParserState (Reader T2TMeta) Pandoc
forall (m :: * -> *) a. Monad m => a -> m a
return (Pandoc -> ParserT Sources ParserState (Reader T2TMeta) Pandoc)
-> Pandoc -> ParserT Sources ParserState (Reader T2TMeta) Pandoc
forall a b. (a -> b) -> a -> b
$ Meta -> [Block] -> Pandoc
Pandoc Meta
meta' (Blocks -> [Block]
forall a. Many a -> [a]
B.toList Blocks
body)
parseHeader :: T2T ()
= do
() ()
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) ()
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) =>
ParserT 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
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
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
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Text
blanklines
[(Text, Text)]
config <- ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
-> ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) [(Text, Text)]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
setting (ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
-> 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) (Text, Text)
setting)
let settings :: Meta
settings = ((Text, Text) -> Meta -> Meta) -> Meta -> [(Text, Text)] -> Meta
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
B.setMeta Text
k (Text -> MetaValue
MetaString Text
v)) Meta
meta [(Text, Text)]
config
(ParserState -> ParserState)
-> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState (\ParserState
s -> ParserState
s {stateMeta :: Meta
stateMeta = Meta
settings}) ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* 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
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Text
blanklines
header :: T2T ()
= ParsecT Sources ParserState (Reader T2TMeta) ()
titleline ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
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 (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 ()
Text
field T2T a
p = (() ()
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) ()
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) =>
ParserT 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 (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
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 (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 (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
FilePath -> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string FilePath
"%!"
Text
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 =>
ParserT s st m Char -> ParserT 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 -> 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
':'
Text
value <- ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (Reader T2TMeta) Text
ignoreSpacesCap (ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar 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 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)
(Text, Text)
-> ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
keyword, Text
value)
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 (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) =>
ParserT s st m Text
blanklines
, ParsecT Sources ParserState (Reader T2TMeta) Blocks
quote
, ParsecT Sources ParserState (Reader T2TMeta) Blocks
hrule
, 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
Int
level <- FilePath -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (FilePath -> Int)
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT Sources ParserState (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)
Bool -> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Int
level Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
5)
Text
heading <- ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar (FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
noneOf FilePath
"\n\r") (Int
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
level (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))
Maybe FilePath
label <- ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) (Maybe FilePath)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall end s (m :: * -> *) st t a.
(Show end, Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m t
-> ParserT s st m end -> ParserT s st m a -> ParserT s st m [a]
enclosed (Char -> 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
'[') (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
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum 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
<|> FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
"_-"))
ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
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) =>
ParserT s st m Char
spaceChar ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> 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
newline
let attr :: Attr
attr = Attr -> (FilePath -> Attr) -> Maybe FilePath -> Attr
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Attr
nullAttr (\FilePath
x -> (FilePath -> Text
T.pack FilePath
x, [], [])) Maybe FilePath
label
Blocks -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> ParsecT Sources ParserState (Reader T2TMeta) Blocks)
-> Blocks -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
forall a b. (a -> b) -> a -> b
$ Attr -> Int -> Inlines -> Blocks
B.headerWith Attr
attr Int
level (Inlines -> Inlines
trimInlines (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.text 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
Inlines
ils <- T2T Inlines
parseInlines
Bool
nl <- Bool
-> ParserT Sources ParserState (Reader T2TMeta) Bool
-> ParserT Sources ParserState (Reader T2TMeta) Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (Bool
True Bool
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParserT Sources ParserState (Reader T2TMeta) Bool
forall (f :: * -> *) a b. Functor 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)
Blocks
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
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) (Bool -> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
nl ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Sources ParserState (Reader T2TMeta) Int
-> 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) Int
listStart ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Blocks
B.para Inlines
ils))
where
listStart :: ParsecT Sources ParserState (Reader T2TMeta) Int
listStart = ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) Int
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState (Reader T2TMeta) Int
bulletListStart ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) Int
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) Int
orderedListStart
commentBlock :: T2T 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
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 => ParserT 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
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
FilePath
line <- ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
"=-_")
Bool -> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (FilePath -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length FilePath
line Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
20)
Blocks
B.horizontalRule Blocks
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
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) =>
ParserT s st m Char
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
[Text]
rawQuote <- ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (Reader T2TMeta) [Text]
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 ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
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 (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState (Reader T2TMeta) Text
forall (m :: * -> *) st. Monad m => ParserT Sources st m Text
anyLine)
Blocks
contents <- ParsecT Sources ParserState (Reader T2TMeta) Blocks
-> Text -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParserT Sources u m a -> Text -> ParserT Sources u m a
parseFromString' ParsecT Sources ParserState (Reader T2TMeta) Blocks
parseBlocks (Text -> [Text] -> Text
T.intercalate Text
"\n" [Text]
rawQuote Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n\n")
Blocks -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> ParsecT Sources ParserState (Reader T2TMeta) Blocks)
-> Blocks -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
forall a b. (a -> b) -> a -> b
$ Blocks -> Blocks
B.blockQuote Blocks
contents
commentLine :: T2T Inlines
= T2T Inlines
forall a. Monoid a => T2T a
comment
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 (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
forall a.
ParsecT Sources ParserState (Reader T2TMeta) Int -> T2T a -> T2T a
listItem ParsecT Sources ParserState (Reader T2TMeta) Int
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 (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
-> ParsecT Sources ParserState (Reader T2TMeta) Blocks
forall a.
ParsecT Sources ParserState (Reader T2TMeta) Int -> T2T a -> T2T a
listItem ParsecT Sources ParserState (Reader T2TMeta) Int
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 (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) (Inlines, [Blocks])
-> ParsecT Sources ParserState (Reader T2TMeta) (Inlines, [Blocks])
forall a.
ParsecT Sources ParserState (Reader T2TMeta) Int -> T2T a -> T2T a
listItem ParsecT Sources ParserState (Reader T2TMeta) Int
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 (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) Int
genericListStart ParsecT Sources ParserState (Reader T2TMeta) Char
listMarker = ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) Int
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) Int)
-> ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) Int
forall a b. (a -> b) -> a -> b
$
(Int
2Int -> Int -> Int
forall a. Num a => a -> a -> a
+) (Int -> Int)
-> ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FilePath -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (FilePath -> Int)
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
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) =>
ParserT s st m Char
spaceChar
ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState (Reader T2TMeta) Char
listMarker ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState (Reader T2TMeta) Char
space ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) Int
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)
bulletListStart :: T2T Int
bulletListStart :: ParsecT Sources ParserState (Reader T2TMeta) Int
bulletListStart = ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Int
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) Int
orderedListStart = ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Int
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) Int
definitionListStart = ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Int
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
':')
listItem :: T2T Int
-> T2T a
-> T2T a
listItem :: ParsecT Sources ParserState (Reader T2TMeta) Int -> T2T a -> T2T a
listItem ParsecT Sources ParserState (Reader T2TMeta) Int
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
Int
markerLength <- ParsecT Sources ParserState (Reader T2TMeta) Int
-> ParsecT Sources ParserState (Reader T2TMeta) Int
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources ParserState (Reader T2TMeta) Int
start
Text
firstLine <- ParsecT Sources ParserState (Reader T2TMeta) Text
forall (m :: * -> *) st. Monad m => ParserT Sources st m Text
anyLineNewline
Text
blank <- Text
-> ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (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
"" (Text
"\n" Text
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Text
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) =>
ParserT s st m Char
blankline)
Text
rest <- [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]
many (Int -> ParsecT Sources ParserState (Reader T2TMeta) Text
listContinuation Int
markerLength)
T2T a -> Text -> T2T a
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParserT Sources u m a -> Text -> ParserT Sources u m a
parseFromString' T2T a
end (Text -> T2T a) -> Text -> T2T a
forall a b. (a -> b) -> a -> b
$ Text
firstLine Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
blank Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
rest
listContinuation :: Int
-> T2T Text
listContinuation :: Int -> ParsecT Sources ParserState (Reader T2TMeta) Text
listContinuation Int
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) =>
ParserT s st m b -> ParserT s st m ()
notFollowedBy' (ParsecT Sources ParserState (Reader T2TMeta) Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
blankline ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Char
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) =>
ParserT s st m Char
blankline)
ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (Reader T2TMeta) Text
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 (m :: * -> *) t u a.
Stream s m t =>
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 (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 =>
ParserT s st m Char -> ParserT s st m Text
manyChar ParsecT Sources ParserState (Reader T2TMeta) Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT 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
$ Int -> ParsecT Sources ParserState (Reader T2TMeta) Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, HasReaderOptions st) =>
Int -> ParserT s st m Text
indentWith Int
markerLength ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (Reader T2TMeta) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState (Reader T2TMeta) Text
forall (m :: * -> *) st. Monad m => ParserT Sources st m Text
anyLineNewline
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
[Blocks]
tableHeader <- ((Alignment, Blocks) -> Blocks)
-> [(Alignment, Blocks)] -> [Blocks]
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)
[[(Alignment, Blocks)]]
rows <- ParsecT Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
-> ParsecT
Sources ParserState (Reader T2TMeta) [[(Alignment, Blocks)]]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (T2T Inlines
-> ParsecT Sources ParserState (Reader T2TMeta) [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many T2T Inlines
commentLine ParsecT Sources ParserState (Reader T2TMeta) [Inlines]
-> ParsecT
Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
-> ParsecT
Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
tableRow)
let columns :: [[(Alignment, Blocks)]]
columns = [[(Alignment, Blocks)]] -> [[(Alignment, Blocks)]]
forall a. [[a]] -> [[a]]
transpose [[(Alignment, Blocks)]]
rows
let ncolumns :: Int
ncolumns = [[(Alignment, Blocks)]] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[(Alignment, Blocks)]]
columns
let aligns :: [Alignment]
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 (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' :: [[Blocks]]
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 :: Int
size = Int -> (NonEmpty Int -> Int) -> Maybe (NonEmpty Int) -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 NonEmpty Int -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum (Maybe (NonEmpty Int) -> Int) -> Maybe (NonEmpty Int) -> Int
forall a b. (a -> b) -> a -> b
$ [Int] -> Maybe (NonEmpty Int)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty ([Int] -> Maybe (NonEmpty Int)) -> [Int] -> Maybe (NonEmpty Int)
forall a b. (a -> b) -> a -> b
$ ([Blocks] -> Int) -> [[Blocks]] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map [Blocks] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[Blocks]]
rows'
let rowsPadded :: [[Blocks]]
rowsPadded = ([Blocks] -> [Blocks]) -> [[Blocks]] -> [[Blocks]]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> [Blocks] -> [Blocks]
forall a. Monoid a => Int -> [a] -> [a]
pad Int
size) [[Blocks]]
rows'
let headerPadded :: [Blocks]
headerPadded = if [Blocks] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Blocks]
tableHeader then [Blocks]
forall a. Monoid a => a
mempty else Int -> [Blocks] -> [Blocks]
forall a. Monoid a => Int -> [a] -> [a]
pad Int
size [Blocks]
tableHeader
let toRow :: [Blocks] -> Row
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] -> [Row]
toHeaderRow [Blocks]
l = [[Blocks] -> Row
toRow [Blocks]
l | Bool -> Bool
not ([Blocks] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Blocks]
l)]
Blocks -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> ParsecT Sources ParserState (Reader T2TMeta) Blocks)
-> Blocks -> ParsecT Sources ParserState (Reader T2TMeta) Blocks
forall a b. (a -> b) -> a -> b
$ Caption
-> [ColSpec] -> TableHead -> [TableBody] -> TableFoot -> Blocks
B.table Caption
B.emptyCaption
([Alignment] -> [ColWidth] -> [ColSpec]
forall a b. [a] -> [b] -> [(a, b)]
zip [Alignment]
aligns (Int -> ColWidth -> [ColWidth]
forall a. Int -> a -> [a]
replicate Int
ncolumns ColWidth
ColWidthDefault))
(Attr -> [Row] -> TableHead
TableHead Attr
nullAttr ([Row] -> TableHead) -> [Row] -> TableHead
forall a b. (a -> b) -> a -> b
$ [Blocks] -> [Row]
toHeaderRow [Blocks]
headerPadded)
[Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody Attr
nullAttr RowHeadColumns
0 [] ([Row] -> TableBody) -> [Row] -> TableBody
forall a b. (a -> b) -> a -> b
$ ([Blocks] -> Row) -> [[Blocks]] -> [Row]
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 :: Int -> [a] -> [a]
pad Int
n [a]
xs = [a]
xs [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ Int -> a -> [a]
forall a. Int -> a -> [a]
replicate (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs) a
forall a. Monoid a => a
mempty
findAlign :: (Alignment, a) -> Maybe Alignment -> Maybe Alignment
findAlign :: (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)]
= ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT
Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
forall a.
T2T a
-> ParsecT
Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
genericRow (FilePath -> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string FilePath
"||")
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 :: 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 (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)]
-> FilePath
-> ParsecT
Sources ParserState (Reader T2TMeta) [(Alignment, Blocks)]
forall s u (m :: * -> *) a.
ParsecT s u m a -> FilePath -> ParsecT s u m a
<?> FilePath
"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
Int
leftSpaces <- FilePath -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (FilePath -> Int)
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
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) FilePath
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)
[Inlines]
content <- T2T Inlines
-> ParsecT Sources ParserState (Reader T2TMeta) ()
-> 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) ()
-> 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) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ())
-> ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
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) ()
cellEnd)
Int
rightSpaces <- FilePath -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (FilePath -> Int)
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
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 Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
leftSpaces Int
rightSpaces of
Ordering
LT -> Alignment
AlignLeft
Ordering
EQ -> Alignment
AlignCenter
Ordering
GT -> Alignment
AlignRight
ParsecT Sources ParserState (Reader T2TMeta) ()
endOfCell
(Alignment, Blocks)
-> ParsecT Sources ParserState (Reader T2TMeta) (Alignment, Blocks)
forall (m :: * -> *) a. Monad m => a -> m a
return (Alignment
align, Inlines -> Blocks
B.plain (Inlines -> Inlines
B.trimInlines (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat [Inlines]
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) FilePath
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 ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
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 (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)
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 => ParserT 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 => ParserT 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
Text
target <- ParsecT Sources ParserState (Reader T2TMeta) Text
getTarget
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 => ParserT Sources st m Text
anyLineNewline (Text -> Text -> Blocks
B.rawBlock Text
target) Text
"'''"
genericBlock :: Monoid a => T2T a -> (a -> Blocks) -> Text -> T2T Blocks
genericBlock :: 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 :: 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 (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) =>
ParserT 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 (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) =>
ParserT s st m Char
blankline)))
blockMarkupLine :: T2T a -> (a -> Blocks) -> Text -> T2T Blocks
blockMarkupLine :: 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 (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 (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> T2T a
p))
comment :: Monoid a => T2T a
= 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
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 -> T2T 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 (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources ParserState (Reader T2TMeta) Text
forall (m :: * -> *) st. Monad m => ParserT Sources st m Text
anyLine)
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 (m :: * -> *) t u a.
Stream s m t =>
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
Text
target <- ParsecT Sources ParserState (Reader T2TMeta) Text
getTarget
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 -> Text -> Inlines
B.rawInline Text
target) Char
'\'' Text -> Text
forall a. a -> a
id
inlineMarkup :: Monoid a
=> T2T a
-> (a -> Inlines)
-> Char
-> (Text -> a)
-> T2T Inlines
inlineMarkup :: 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
Text
start <- ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT 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 :: Int
l = Text -> Int
T.length Text
start
Bool -> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Int
l Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
2)
Bool
-> ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
l Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2) (ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ())
-> ParsecT Sources ParserState (Reader T2TMeta) ()
-> ParsecT Sources ParserState (Reader T2TMeta) ()
forall a b. (a -> b) -> a -> b
$ 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)
Maybe Text
body <- ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (Reader T2TMeta) (Maybe Text)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (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) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar (FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
noneOf FilePath
"\n\r")
(ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath)
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
noneOf FilePath
" " ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FilePath -> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string [Char
c,Char
c] )))
case Maybe Text
body of
Just Text
middle -> do
Char
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
Text
end <- ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT 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 parser :: Text -> T2T a
parser Text
inp = T2T a -> Text -> T2T a
forall (m :: * -> *) u a.
(Monad m, HasLastStrPosition u) =>
ParserT Sources u m a -> Text -> ParserT 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' :: a
start' = case Int -> Text -> Text
T.drop Int
2 Text
start of
Text
"" -> a
forall a. Monoid a => a
mempty
Text
xs -> Text -> a
special Text
xs
a
body' <- Text -> T2T a
parser (Text
middle Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Char -> Text
T.singleton Char
lastChar)
let end' :: a
end' = case Int -> Text -> Text
T.drop Int
2 Text
end of
Text
"" -> a
forall a. Monoid a => a
mempty
Text
xs -> Text -> a
special Text
xs
Inlines -> T2T Inlines
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 (a
start' a -> a -> a
forall a. Monoid a => a -> a -> a
`mappend` a
body' a -> a -> a
forall a. Monoid a => a -> a -> a
`mappend` a
end')
Maybe Text
Nothing -> do
Bool -> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Int
l Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
5)
let body' :: Text
body' = Int -> Text -> Text
T.replicate (Int
l Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
4) (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton Char
c
Inlines -> T2T Inlines
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
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
[Text]
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 =>
ParserT s st m Char -> ParserT 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
$ FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
noneOf FilePath
" ]") ParsecT Sources ParserState (Reader T2TMeta) Char
space
Bool -> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard ([Text] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Text]
tokens Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
2)
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
']'
let link' :: Text
link' = [Text] -> Text
forall a. [a] -> a
last [Text]
tokens
Bool -> ParsecT Sources ParserState (Reader T2TMeta) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Sources ParserState (Reader T2TMeta) ())
-> Bool -> ParsecT Sources ParserState (Reader T2TMeta) ()
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Text -> Bool
T.null Text
link'
let tit :: Text
tit = [Text] -> Text
T.unwords ([Text] -> [Text]
forall a. [a] -> [a]
init [Text]
tokens)
Inlines -> T2T Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> T2T Inlines) -> Inlines -> T2T Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link Text
link' Text
"" (Text -> Inlines
B.text Text
tit)
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
'['
Inlines
body <- T2T Inlines
image
ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
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 <- ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar (FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
noneOf FilePath
"\n\r ") (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
']')
Inlines -> T2T Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Text -> Inlines -> Inlines
B.link Text
l Text
"" Inlines
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
Text
name <- FilePath -> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m FilePath
string FilePath
"%%" ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (Reader T2TMeta) Text
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] -> ParserT 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)
ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> 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) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath)
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall a b. (a -> b) -> a -> b
$ ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
forall end s (m :: * -> *) st t a.
(Show end, Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m t
-> ParserT s st m end -> ParserT s st m a -> ParserT s st m [a]
enclosed (Char -> 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
'(') (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
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar)
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 s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m Char
spaceChar 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
<|> FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
specialChars 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)
T2T Inlines
-> ((T2TMeta -> Text) -> T2T Inlines)
-> Maybe (T2TMeta -> Text)
-> T2T Inlines
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Inlines -> T2T Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
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)) (Text -> [(Text, T2TMeta -> Text)] -> Maybe (T2TMeta -> Text)
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", FilePath -> Text
T.pack (FilePath -> Text) -> (T2TMeta -> FilePath) -> T2TMeta -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T2TMeta -> FilePath
infile), (Text
"outfile", FilePath -> Text
T.pack (FilePath -> Text) -> (T2TMeta -> FilePath) -> T2TMeta -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T2TMeta -> FilePath
outfile)]
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
(Text
rawUrl, Text
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'
Inlines -> T2T Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> T2T Inlines) -> Inlines -> T2T Inlines
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' :: ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
emailAddress' = do
(Text
base, Text
mailURI) <- ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParserT s st m (Text, Text)
emailAddress
Text
query <- Text
-> ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (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
"" ParsecT Sources ParserState (Reader T2TMeta) Text
emailQuery
(Text, Text)
-> ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
base Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
query, Text
mailURI Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
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
'?'
[Text]
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
'&')
Text -> ParsecT Sources ParserState (Reader T2TMeta) Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> ParsecT Sources ParserState (Reader T2TMeta) Text)
-> Text -> ParsecT Sources ParserState (Reader T2TMeta) Text
forall a b. (a -> b) -> a -> b
$ Text
"?" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
T.intercalate Text
"&" [Text]
parts
kv :: T2T Text
kv :: ParsecT Sources ParserState (Reader T2TMeta) Text
kv = do
Text
k <- FilePath -> Text
T.pack (FilePath -> Text)
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> 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) FilePath
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
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum
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
'='
let vchar :: ParsecT Sources u (Reader T2TMeta) Char
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 (FilePath -> ParsecT Sources u (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
"%._/~:,=$@&+-;*" ParsecT Sources u (Reader T2TMeta) Char
-> ParsecT Sources u (Reader T2TMeta) Char
-> ParsecT Sources u (Reader T2TMeta) Char
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)
Text
v <- FilePath -> Text
T.pack (FilePath -> Text)
-> ParsecT Sources ParserState (Reader T2TMeta) FilePath
-> 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) FilePath
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
forall u. ParsecT Sources u (Reader T2TMeta) Char
vchar
Text -> ParsecT Sources ParserState (Reader T2TMeta) Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
k Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"=" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
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
Text
address <- ParsecT Sources ParserState (Reader T2TMeta) Text
t2tURI
(Text, Text)
-> ParsecT Sources ParserState (Reader T2TMeta) (Text, Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
address, Text -> Text
escapeURI Text
address)
t2tURI :: T2T Text
t2tURI :: ParsecT Sources ParserState (Reader T2TMeta) Text
t2tURI = do
Text
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 (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
Text
domain <- ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParsecT Sources ParserState (Reader T2TMeta) Char
forall u. ParsecT Sources u (Reader T2TMeta) Char
chars
Text
sep <- ParsecT Sources ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
manyChar (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
'/')
Text
form' <- Text
-> ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (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 ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) (Text -> Text)
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
char Char
'?' ParsecT Sources ParserState (Reader T2TMeta) (Text -> Text)
-> ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (Reader T2TMeta) Text
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 =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParsecT Sources ParserState (Reader T2TMeta) Char
forall u. ParsecT Sources u (Reader T2TMeta) Char
form)
Text
anchor' <- Text
-> ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (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 ParserState (Reader T2TMeta) Char
-> ParsecT Sources ParserState (Reader T2TMeta) (Text -> Text)
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
char Char
'#' ParsecT Sources ParserState (Reader T2TMeta) (Text -> Text)
-> ParsecT Sources ParserState (Reader T2TMeta) Text
-> ParsecT Sources ParserState (Reader T2TMeta) Text
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 =>
ParserT s st m Char -> ParserT s st m Text
manyChar ParsecT Sources ParserState (Reader T2TMeta) Char
forall u. ParsecT Sources u (Reader T2TMeta) Char
anchor)
Text -> ParsecT Sources ParserState (Reader T2TMeta) Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
start Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
domain Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
sep Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
form' Text -> Text -> Text
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 = 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] -> ParserT 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 (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 (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
<$> FilePath -> ParsecT Sources u (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
"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 (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
<|> FilePath -> ParsecT Sources u (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
"_.-"
pass :: ParserT Sources st (Reader T2TMeta) Text
pass = ParserT Sources st (Reader T2TMeta) Char
-> ParserT Sources st (Reader T2TMeta) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
manyChar (FilePath -> ParserT Sources st (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
noneOf FilePath
" @")
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
<|> FilePath -> ParsecT Sources u (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
"%._/~:,=$@&+-"
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
<|> FilePath -> ParsecT Sources u (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
"%._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
<|> FilePath -> ParsecT Sources u (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
";*"
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
<$> ParserT Sources u (Reader T2TMeta) Char
-> ParsecT Sources u (Reader T2TMeta) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParserT 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 (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)
-> ParserT 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 -> ParserT 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 (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)
-> ParserT Sources u (Reader T2TMeta) Char
-> ParsecT Sources u (Reader T2TMeta) Text
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Char -> ParserT 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
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
'['
(Text
path, Text
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.
ParserT s u m Char -> ParserT s u m b -> ParserT s u m (Text, b)
manyUntilChar (FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
noneOf FilePath
"\n\t\r ") ([Text] -> ParsecT Sources ParserState (Reader T2TMeta) Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
[Text] -> ParserT s st m Text
oneOfStrings [Text]
extensions)
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
']'
Inlines -> T2T Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> T2T Inlines) -> Inlines -> T2T Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.image (Text
path Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ext) Text
"" Inlines
forall a. Monoid a => a
mempty
specialChars :: [Char]
specialChars :: FilePath
specialChars = FilePath
"%*-_/|:+;"
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 =>
ParserT s st m Char -> ParserT 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) =>
ParserT 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 (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 =>
ParserT s st m Char -> ParserT s st m Text
many1Char (FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
noneOf (FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char)
-> FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char
forall a b. (a -> b) -> a -> b
$ FilePath
specialChars FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\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 (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) =>
ParserT 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
<$> FilePath -> ParsecT Sources ParserState (Reader T2TMeta) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
FilePath -> ParsecT s u m Char
oneOf FilePath
specialChars
getTarget :: T2T Text
getTarget :: ParsecT Sources ParserState (Reader T2TMeta) Text
getTarget = do
Maybe MetaValue
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
Text -> ParsecT Sources ParserState (Reader T2TMeta) Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> ParsecT Sources ParserState (Reader T2TMeta) Text)
-> Text -> ParsecT Sources ParserState (Reader T2TMeta) Text
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 :: 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 (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
. (Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1) (Int -> Bool) -> (SourcePos -> Int) -> SourcePos -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourcePos -> Int
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 (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 (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources ParserState (Reader T2TMeta) Text
spaces)